diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/pdfium/fpdfsdk | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/pdfium/fpdfsdk')
98 files changed, 1487 insertions, 911 deletions
diff --git a/chromium/third_party/pdfium/fpdfsdk/BUILD.gn b/chromium/third_party/pdfium/fpdfsdk/BUILD.gn index e0a99833d9a..081152efd5f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/BUILD.gn +++ b/chromium/third_party/pdfium/fpdfsdk/BUILD.gn @@ -109,11 +109,9 @@ source_set("fpdfsdk") { pdfium_unittest_source_set("unittests") { sources = [ "cpdfsdk_helpers_unittest.cpp", - "fpdf_annot_unittest.cpp", "fpdf_catalog_unittest.cpp", "fpdf_doc_unittest.cpp", "fpdf_edit_unittest.cpp", - "fpdf_editimg_unittest.cpp", "fpdf_view_unittest.cpp", ] deps = [ @@ -137,6 +135,7 @@ pdfium_embeddertest_source_set("embeddertests") { "fpdf_dataavail_embeddertest.cpp", "fpdf_doc_embeddertest.cpp", "fpdf_edit_embeddertest.cpp", + "fpdf_editimg_embeddertest.cpp", "fpdf_editpage_embeddertest.cpp", "fpdf_editpath_embeddertest.cpp", "fpdf_ext_embeddertest.cpp", diff --git a/chromium/third_party/pdfium/fpdfsdk/PRESUBMIT.py b/chromium/third_party/pdfium/fpdfsdk/PRESUBMIT.py index 17f7c6abc98..dee2035e768 100644 --- a/chromium/third_party/pdfium/fpdfsdk/PRESUBMIT.py +++ b/chromium/third_party/pdfium/fpdfsdk/PRESUBMIT.py @@ -32,11 +32,11 @@ def _CheckApiTestFile(input_api, output_api): def CheckChangeOnUpload(input_api, output_api): results = [] - results += _CheckApiTestFile(input_api, output_api) + results.extend(_CheckApiTestFile(input_api, output_api)) return results def CheckChangeOnCommit(input_api, output_api): results = [] - results += _CheckApiTestFile(input_api, output_api) + results.extend(_CheckApiTestFile(input_api, output_api)) return results diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.cpp index 356cc1432af..ebcac3bfec3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.cpp @@ -105,7 +105,7 @@ bool CPDFSDK_ActionHandler::DoAction_Destination( bool CPDFSDK_ActionHandler::DoAction_Page( const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, + CPDF_AAction::AActionType eType, CPDFSDK_FormFillEnvironment* pFormFillEnv) { std::set<const CPDF_Dictionary*> visited; return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); @@ -113,7 +113,7 @@ bool CPDFSDK_ActionHandler::DoAction_Page( bool CPDFSDK_ActionHandler::DoAction_Document( const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, + CPDF_AAction::AActionType eType, CPDFSDK_FormFillEnvironment* pFormFillEnv) { std::set<const CPDF_Dictionary*> visited; return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited); @@ -135,7 +135,7 @@ bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction( CPDFSDK_FormFillEnvironment* pFormFillEnv, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) return false; visited->insert(pDict); @@ -167,7 +167,7 @@ bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction( CPDFSDK_FormFillEnvironment* pFormFillEnv, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) return false; visited->insert(pDict); @@ -212,7 +212,7 @@ bool CPDFSDK_ActionHandler::ExecuteFieldAction( CPDFSDK_FieldAction* data, std::set<const CPDF_Dictionary*>* visited) { const CPDF_Dictionary* pDict = action.GetDict(); - if (pdfium::ContainsKey(*visited, pDict)) + if (pdfium::Contains(*visited, pDict)) return false; visited->insert(pDict); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.h index c4a8bbee65c..cbf9eb80e32 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_actionhandler.h @@ -29,10 +29,10 @@ class CPDFSDK_ActionHandler { WideString csJSName, CPDFSDK_FormFillEnvironment* pFormFillEnv); bool DoAction_Page(const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, + CPDF_AAction::AActionType eType, CPDFSDK_FormFillEnvironment* pFormFillEnv); bool DoAction_Document(const CPDF_Action& action, - enum CPDF_AAction::AActionType eType, + CPDF_AAction::AActionType eType, CPDFSDK_FormFillEnvironment* pFormFillEnv); bool DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp index d5792987152..790ba15bcd3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -21,7 +21,6 @@ #include "fpdfsdk/cpdfsdk_widgethandler.h" #include "fpdfsdk/pwl/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" @@ -94,6 +93,10 @@ void CPDFSDK_AnnotHandlerMgr::Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, GetAnnotHandler(pAnnot)->ReplaceSelection(pAnnot, text); } +bool CPDFSDK_AnnotHandlerMgr::Annot_SelectAllText(CPDFSDK_Annot* pAnnot) { + return GetAnnotHandler(pAnnot)->SelectAllText(pAnnot); +} + bool CPDFSDK_AnnotHandlerMgr::Annot_CanUndo(CPDFSDK_Annot* pAnnot) { return GetAnnotHandler(pAnnot)->CanUndo(pAnnot); } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h index dd01348ddb8..c7dea7809ed 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annothandlermgr.h @@ -49,6 +49,7 @@ class CPDFSDK_AnnotHandlerMgr { WideString Annot_GetText(CPDFSDK_Annot* pAnnot); WideString Annot_GetSelectedText(CPDFSDK_Annot* pAnnot); void Annot_ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text); + bool Annot_SelectAllText(CPDFSDK_Annot* pAnnot); bool Annot_CanUndo(CPDFSDK_Annot* pAnnot); bool Annot_CanRedo(CPDFSDK_Annot* pAnnot); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiteration.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiteration.cpp index d2569506584..fa9a5ea405d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiteration.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiteration.cpp @@ -37,4 +37,4 @@ CPDFSDK_AnnotIteration::CPDFSDK_AnnotIteration(CPDFSDK_PageView* pPageView, m_List.emplace_back(pAnnot); } -CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() {} +CPDFSDK_AnnotIteration::~CPDFSDK_AnnotIteration() = default; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiterator.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiterator.cpp index 36a13bbf79b..5827a42739f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiterator.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_annotiterator.cpp @@ -84,7 +84,7 @@ CPDFSDK_Annot* CPDFSDK_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { void CPDFSDK_AnnotIterator::CollectAnnots(std::vector<CPDFSDK_Annot*>* pArray) { for (auto* pAnnot : m_pPageView->GetAnnotList()) { - if (pdfium::ContainsValue(m_subtypes, pAnnot->GetAnnotSubtype()) && + if (pdfium::Contains(m_subtypes, pAnnot->GetAnnotSubtype()) && !pAnnot->IsSignatureWidget()) { pArray->push_back(pAnnot); } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_appstream.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_appstream.cpp index e45197746e5..66e8768ffca 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_appstream.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_appstream.cpp @@ -6,6 +6,7 @@ #include "fpdfsdk/cpdfsdk_appstream.h" +#include <memory> #include <utility> #include "constants/form_flags.h" @@ -30,7 +31,7 @@ #include "fpdfsdk/pwl/cpwl_edit_impl.h" #include "fpdfsdk/pwl/cpwl_icon.h" #include "fpdfsdk/pwl/cpwl_wnd.h" -#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" namespace { @@ -153,8 +154,8 @@ ByteString GetAP_Check(const CFX_FloatRect& crBBox) { {CFX_PointF(0.40f, 0.60f), CFX_PointF(0.28f, 0.66f), CFX_PointF(0.30f, 0.56f)}}; - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - for (size_t j = 0; j < FX_ArraySize(pts[0]); ++j) { + for (size_t i = 0; i < pdfium::size(pts); ++i) { + for (size_t j = 0; j < pdfium::size(pts[0]); ++j) { pts[i][j].x = pts[i][j].x * fWidth + crBBox.left; pts[i][j].y *= pts[i][j].y * fHeight + crBBox.bottom; } @@ -163,8 +164,8 @@ ByteString GetAP_Check(const CFX_FloatRect& crBBox) { std::ostringstream csAP; csAP << pts[0][0].x << " " << pts[0][0].y << " " << kMoveToOperator << "\n"; - for (size_t i = 0; i < FX_ArraySize(pts); ++i) { - size_t nNext = i < FX_ArraySize(pts) - 1 ? i + 1 : 0; + for (size_t i = 0; i < pdfium::size(pts); ++i) { + size_t nNext = i < pdfium::size(pts) - 1 ? i + 1 : 0; float px1 = pts[i][1].x - pts[i][0].x; float py1 = pts[i][1].y - pts[i][0].y; @@ -433,8 +434,8 @@ ByteString GetCircleBorderAppStream(const CFX_FloatRect& rect, CFX_FloatRect rect_by_75 = rect.GetDeflated(div, div); switch (nStyle) { default: - case BorderStyle::SOLID: - case BorderStyle::UNDERLINE: { + case BorderStyle::kSolid: + case BorderStyle::kUnderline: { sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { AutoClosedQCommand q2(&sAppStream); @@ -443,7 +444,7 @@ ByteString GetCircleBorderAppStream(const CFX_FloatRect& rect, << kStrokeOperator << "\n"; } } break; - case BorderStyle::DASH: { + case BorderStyle::kDash: { sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { AutoClosedQCommand q2(&sAppStream); @@ -454,7 +455,7 @@ ByteString GetCircleBorderAppStream(const CFX_FloatRect& rect, << kStrokeOperator << "\n"; } } break; - case BorderStyle::BEVELED: { + case BorderStyle::kBeveled: { sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { AutoClosedQCommand q2(&sAppStream); @@ -479,7 +480,7 @@ ByteString GetCircleBorderAppStream(const CFX_FloatRect& rect, << " " << kStrokeOperator << "\n"; } } break; - case BorderStyle::INSET: { + case BorderStyle::kInset: { sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { AutoClosedQCommand q2(&sAppStream); @@ -690,7 +691,7 @@ ByteString GenerateIconAppStream(CPDF_IconFit& fit, CPWL_Wnd::CreateParams cp; cp.dwFlags = PWS_VISIBLE; - CPWL_Icon icon(cp, pdfium::MakeUnique<CPDF_Icon>(pIconStream), &fit); + CPWL_Icon icon(cp, std::make_unique<CPDF_Icon>(pIconStream), &fit); icon.Realize(); if (!icon.Move(rcIcon, false, false)) return ByteString(); @@ -742,7 +743,7 @@ ByteString GetPushButtonAppStream(const CFX_FloatRect& rcBBox, ButtonStyle nLayOut) { const float fAutoFontScale = 1.0f / 3.0f; - auto pEdit = pdfium::MakeUnique<CPWL_EditImpl>(); + auto pEdit = std::make_unique<CPWL_EditImpl>(); pEdit->SetFontMap(pFontMap); pEdit->SetAlignmentH(1, true); pEdit->SetAlignmentV(1, true); @@ -944,7 +945,7 @@ ByteString GetBorderAppStreamInternal(const CFX_FloatRect& rect, switch (nStyle) { default: - case BorderStyle::SOLID: + case BorderStyle::kSolid: sColor = GetColorAppStream(color, true); if (sColor.GetLength() > 0) { sAppStream << sColor; @@ -957,7 +958,7 @@ ByteString GetBorderAppStreamInternal(const CFX_FloatRect& rect, sAppStream << kFillEvenOddOperator << "\n"; } break; - case BorderStyle::DASH: + case BorderStyle::kDash: sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { sAppStream << sColor; @@ -976,8 +977,8 @@ ByteString GetBorderAppStreamInternal(const CFX_FloatRect& rect, << kLineToOperator << " " << kStrokeOperator << "\n"; } break; - case BorderStyle::BEVELED: - case BorderStyle::INSET: + case BorderStyle::kBeveled: + case BorderStyle::kInset: sColor = GetColorAppStream(crLeftTop, true); if (sColor.GetLength() > 0) { sAppStream << sColor; @@ -1027,7 +1028,7 @@ ByteString GetBorderAppStreamInternal(const CFX_FloatRect& rect, << "\n"; } break; - case BorderStyle::UNDERLINE: + case BorderStyle::kUnderline: sColor = GetColorAppStream(color, false); if (sColor.GetLength() > 0) { sAppStream << sColor; @@ -1065,7 +1066,7 @@ ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { sAppStream << GetBorderAppStreamInternal( rcBBox, 2, CFX_Color(CFX_Color::kGray, 0), CFX_Color(CFX_Color::kGray, 1), CFX_Color(CFX_Color::kGray, 0.5), - BorderStyle::BEVELED, CPWL_Dash(3, 0, 0)); + BorderStyle::kBeveled, CPWL_Dash(3, 0, 0)); } CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, @@ -1144,7 +1145,7 @@ CPDFSDK_AppStream::CPDFSDK_AppStream(CPDFSDK_Widget* widget, CPDF_Dictionary* dict) : widget_(widget), dict_(dict) {} -CPDFSDK_AppStream::~CPDFSDK_AppStream() {} +CPDFSDK_AppStream::~CPDFSDK_AppStream() = default; void CPDFSDK_AppStream::SetAsPushButton() { CPDF_FormControl* pControl = widget_->GetFormControl(); @@ -1193,15 +1194,15 @@ void CPDFSDK_AppStream::SetAsPushButton() { BorderStyle nBorderStyle = widget_->GetBorderStyle(); switch (nBorderStyle) { - case BorderStyle::DASH: + case BorderStyle::kDash: dsBorder = CPWL_Dash(3, 3, 0); break; - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; - case BorderStyle::INSET: + case BorderStyle::kInset: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); @@ -1300,13 +1301,13 @@ void CPDFSDK_AppStream::SetAsPushButton() { } switch (nBorderStyle) { - case BorderStyle::BEVELED: { + case BorderStyle::kBeveled: { CFX_Color crTemp = crLeftTop; crLeftTop = crRightBottom; crRightBottom = crTemp; break; } - case BorderStyle::INSET: { + case BorderStyle::kInset: { crLeftTop = CFX_Color(CFX_Color::kGray, 0); crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; @@ -1354,15 +1355,15 @@ void CPDFSDK_AppStream::SetAsCheckBox() { BorderStyle nBorderStyle = widget_->GetBorderStyle(); switch (nBorderStyle) { - case BorderStyle::DASH: + case BorderStyle::kDash: dsBorder = CPWL_Dash(3, 3, 0); break; - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; - case BorderStyle::INSET: + case BorderStyle::kInset: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); @@ -1390,13 +1391,13 @@ void CPDFSDK_AppStream::SetAsCheckBox() { ByteString csAP_N_OFF = csAP_N_ON; switch (nBorderStyle) { - case BorderStyle::BEVELED: { + case BorderStyle::kBeveled: { CFX_Color crTemp = crLeftTop; crLeftTop = crRightBottom; crRightBottom = crTemp; break; } - case BorderStyle::INSET: { + case BorderStyle::kInset: { crLeftTop = CFX_Color(CFX_Color::kGray, 0); crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; @@ -1448,15 +1449,15 @@ void CPDFSDK_AppStream::SetAsRadioButton() { CFX_Color crRightBottom; BorderStyle nBorderStyle = widget_->GetBorderStyle(); switch (nBorderStyle) { - case BorderStyle::DASH: + case BorderStyle::kDash: dsBorder = CPWL_Dash(3, 3, 0); break; - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; - case BorderStyle::INSET: + case BorderStyle::kInset: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); @@ -1480,10 +1481,10 @@ void CPDFSDK_AppStream::SetAsRadioButton() { ByteString csAP_N_ON; CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f); if (nStyle == CheckStyle::kCircle) { - if (nBorderStyle == BorderStyle::BEVELED) { + if (nBorderStyle == BorderStyle::kBeveled) { crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground - 0.25f; - } else if (nBorderStyle == BorderStyle::INSET) { + } else if (nBorderStyle == BorderStyle::kInset) { crLeftTop = CFX_Color(CFX_Color::kGray, 0.5f); crRightBottom = CFX_Color(CFX_Color::kGray, 0.75f); } @@ -1502,13 +1503,13 @@ void CPDFSDK_AppStream::SetAsRadioButton() { ByteString csAP_N_OFF = csAP_N_ON; switch (nBorderStyle) { - case BorderStyle::BEVELED: { + case BorderStyle::kBeveled: { CFX_Color crTemp = crLeftTop; crLeftTop = crRightBottom; crRightBottom = crTemp; break; } - case BorderStyle::INSET: { + case BorderStyle::kInset: { crLeftTop = CFX_Color(CFX_Color::kGray, 0); crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; @@ -1521,11 +1522,11 @@ void CPDFSDK_AppStream::SetAsRadioButton() { if (nStyle == CheckStyle::kCircle) { CFX_Color crBK = crBackground - 0.25f; - if (nBorderStyle == BorderStyle::BEVELED) { + if (nBorderStyle == BorderStyle::kBeveled) { crLeftTop = crBackground - 0.25f; crRightBottom = CFX_Color(CFX_Color::kGray, 1); crBK = crBackground; - } else if (nBorderStyle == BorderStyle::INSET) { + } else if (nBorderStyle == BorderStyle::kInset) { crLeftTop = CFX_Color(CFX_Color::kGray, 0); crRightBottom = CFX_Color(CFX_Color::kGray, 1); } @@ -1572,7 +1573,7 @@ void CPDFSDK_AppStream::SetAsComboBox(Optional<WideString> sValue) { CBA_FontMap font_map(widget_->GetPDFPage()->GetDocument(), widget_->GetPDFAnnot()->GetAnnotDict()); - auto pEdit = pdfium::MakeUnique<CPWL_EditImpl>(); + auto pEdit = std::make_unique<CPWL_EditImpl>(); pEdit->EnableRefresh(false); pEdit->SetFontMap(&font_map); @@ -1638,7 +1639,7 @@ void CPDFSDK_AppStream::SetAsListBox() { CBA_FontMap font_map(widget_->GetPDFPage()->GetDocument(), widget_->GetPDFAnnot()->GetAnnotDict()); - auto pEdit = pdfium::MakeUnique<CPWL_EditImpl>(); + auto pEdit = std::make_unique<CPWL_EditImpl>(); pEdit->EnableRefresh(false); pEdit->SetFontMap(&font_map); pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); @@ -1722,7 +1723,7 @@ void CPDFSDK_AppStream::SetAsTextField(Optional<WideString> sValue) { CBA_FontMap font_map(widget_->GetPDFPage()->GetDocument(), widget_->GetPDFAnnot()->GetAnnotDict()); - auto pEdit = pdfium::MakeUnique<CPWL_EditImpl>(); + auto pEdit = std::make_unique<CPWL_EditImpl>(); pEdit->EnableRefresh(false); pEdit->SetFontMap(&font_map); @@ -1802,7 +1803,7 @@ void CPDFSDK_AppStream::SetAsTextField(Optional<WideString> sValue) { if (bCharArray) { switch (widget_->GetBorderStyle()) { - case BorderStyle::SOLID: { + case BorderStyle::kSolid: { ByteString sColor = GetColorAppStream(widget_->GetBorderPWLColor(), false); if (sColor.GetLength() > 0) { @@ -1825,7 +1826,7 @@ void CPDFSDK_AppStream::SetAsTextField(Optional<WideString> sValue) { } break; } - case BorderStyle::DASH: { + case BorderStyle::kDash: { ByteString sColor = GetColorAppStream(widget_->GetBorderPWLColor(), false); if (sColor.GetLength() > 0) { @@ -1945,15 +1946,15 @@ ByteString CPDFSDK_AppStream::GetBorderAppStream() const { BorderStyle nBorderStyle = widget_->GetBorderStyle(); switch (nBorderStyle) { - case BorderStyle::DASH: + case BorderStyle::kDash: dsBorder = CPWL_Dash(3, 3, 0); break; - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; - case BorderStyle::INSET: + case BorderStyle::kInset: fBorderWidth *= 2; crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp index 524eccdc9ce..4133b361162 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannot.cpp @@ -25,7 +25,7 @@ CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) : CPDFSDK_Annot(pPageView), m_pAnnot(pAnnot) {} -CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() {} +CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot() = default; CPDFSDK_BAAnnot* CPDFSDK_BAAnnot::AsBAAnnot() { return this; @@ -142,19 +142,19 @@ void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) { const char* name = nullptr; switch (nStyle) { - case BorderStyle::SOLID: + case BorderStyle::kSolid: name = "S"; break; - case BorderStyle::DASH: + case BorderStyle::kDash: name = "D"; break; - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: name = "B"; break; - case BorderStyle::INSET: + case BorderStyle::kInset: name = "I"; break; - case BorderStyle::UNDERLINE: + case BorderStyle::kUnderline: name = "U"; break; default: @@ -168,15 +168,15 @@ BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { if (pBSDict) { ByteString sBorderStyle = pBSDict->GetStringFor("S", "S"); if (sBorderStyle == "S") - return BorderStyle::SOLID; + return BorderStyle::kSolid; if (sBorderStyle == "D") - return BorderStyle::DASH; + return BorderStyle::kDash; if (sBorderStyle == "B") - return BorderStyle::BEVELED; + return BorderStyle::kBeveled; if (sBorderStyle == "I") - return BorderStyle::INSET; + return BorderStyle::kInset; if (sBorderStyle == "U") - return BorderStyle::UNDERLINE; + return BorderStyle::kUnderline; } const CPDF_Array* pBorder = @@ -185,11 +185,11 @@ BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const { if (pBorder->size() >= 4) { const CPDF_Array* pDP = pBorder->GetArrayAt(3); if (pDP && pDP->size() > 0) - return BorderStyle::DASH; + return BorderStyle::kDash; } } - return BorderStyle::SOLID; + return BorderStyle::kSolid; } bool CPDFSDK_BAAnnot::IsVisible() const { diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp index a3981b146a0..91c3e7db0fc 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.cpp @@ -20,7 +20,6 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -42,7 +41,7 @@ void UpdateAnnotRects(CPDFSDK_PageView* pPageView, CPDFSDK_BAAnnot* pBAAnnot) { CPDFSDK_BAAnnotHandler::CPDFSDK_BAAnnotHandler() {} -CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() {} +CPDFSDK_BAAnnotHandler::~CPDFSDK_BAAnnotHandler() = default; void CPDFSDK_BAAnnotHandler::SetFormFillEnvironment( CPDFSDK_FormFillEnvironment* pFormFillEnv) { @@ -56,7 +55,7 @@ bool CPDFSDK_BAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { std::unique_ptr<CPDFSDK_Annot> CPDFSDK_BAAnnotHandler::NewAnnot( CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) { - return pdfium::MakeUnique<CPDFSDK_BAAnnot>(pAnnot, pPageView); + return std::make_unique<CPDFSDK_BAAnnot>(pAnnot, pPageView); } void CPDFSDK_BAAnnotHandler::ReleaseAnnot( @@ -211,8 +210,8 @@ bool CPDFSDK_BAAnnotHandler::IsFocusableAnnot( const CPDF_Annot::Subtype& annot_type) const { ASSERT(annot_type != CPDF_Annot::Subtype::WIDGET); - return pdfium::ContainsValue( - form_fill_environment_->GetFocusableAnnotSubtypes(), annot_type); + return pdfium::Contains(form_fill_environment_->GetFocusableAnnotSubtypes(), + annot_type); } void CPDFSDK_BAAnnotHandler::InvalidateRect(CPDFSDK_Annot* annot) { @@ -275,6 +274,10 @@ WideString CPDFSDK_BAAnnotHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { void CPDFSDK_BAAnnotHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) {} +bool CPDFSDK_BAAnnotHandler::SelectAllText(CPDFSDK_Annot* pAnnot) { + return false; +} + bool CPDFSDK_BAAnnotHandler::CanUndo(CPDFSDK_Annot* pAnnot) { return false; } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h index 3eaf4465e0c..90e0f736136 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_baannothandler.h @@ -37,6 +37,7 @@ class CPDFSDK_BAAnnotHandler final : public IPDFSDK_AnnotHandler { WideString GetText(CPDFSDK_Annot* pAnnot) override; WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override; + bool SelectAllText(CPDFSDK_Annot* pAnnot) override; bool CanUndo(CPDFSDK_Annot* pAnnot) override; bool CanRedo(CPDFSDK_Annot* pAnnot) override; bool Undo(CPDFSDK_Annot* pAnnot) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_customaccess.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_customaccess.h index 76940ce583d..8037bff6de9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_customaccess.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_customaccess.h @@ -12,8 +12,7 @@ class CPDFSDK_CustomAccess final : public IFX_SeekableReadStream { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CONSTRUCT_VIA_MAKE_RETAIN; // IFX_SeekableReadStream FX_FILESIZE GetSize() override; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.cpp index 39a69a5982d..2583e68cfb3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.cpp @@ -11,7 +11,7 @@ CPDFSDK_FileWriteAdapter::CPDFSDK_FileWriteAdapter(FPDF_FILEWRITE* file_write) ASSERT(file_write_); } -CPDFSDK_FileWriteAdapter::~CPDFSDK_FileWriteAdapter() {} +CPDFSDK_FileWriteAdapter::~CPDFSDK_FileWriteAdapter() = default; bool CPDFSDK_FileWriteAdapter::WriteBlock(const void* data, size_t size) { return file_write_->WriteBlock(file_write_.Get(), data, size) != 0; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.h index fc42b7f416d..0a05422d3d8 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_filewriteadapter.h @@ -14,8 +14,7 @@ class CPDFSDK_FileWriteAdapter final : public IFX_RetainableWriteStream { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CONSTRUCT_VIA_MAKE_RETAIN; // IFX_WriteStream: bool WriteBlock(const void* data, size_t size) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 059140876f2..d74ac22f6e7 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -24,7 +24,6 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fxjs/ijs_runtime.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" FPDF_WIDESTRING AsFPDFWideString(ByteString* bsUTF16LE) { @@ -325,14 +324,14 @@ CPDFSDK_AnnotHandlerMgr* CPDFSDK_FormFillEnvironment::GetAnnotHandlerMgr() { CPDFSDK_ActionHandler* CPDFSDK_FormFillEnvironment::GetActionHandler() { if (!m_pActionHandler) - m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>(); + m_pActionHandler = std::make_unique<CPDFSDK_ActionHandler>(); return m_pActionHandler.get(); } CFFL_InteractiveFormFiller* CPDFSDK_FormFillEnvironment::GetInteractiveFormFiller() { if (!m_pFormFiller) - m_pFormFiller = pdfium::MakeUnique<CFFL_InteractiveFormFiller>(this); + m_pFormFiller = std::make_unique<CFFL_InteractiveFormFiller>(this); return m_pFormFiller.get(); } @@ -577,7 +576,7 @@ CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( if (!renew) return nullptr; - auto pNew = pdfium::MakeUnique<CPDFSDK_PageView>(this, pUnderlyingPage); + auto pNew = std::make_unique<CPDFSDK_PageView>(this, pUnderlyingPage); CPDFSDK_PageView* pPageView = pNew.get(); m_PageMap[pUnderlyingPage] = std::move(pNew); @@ -666,7 +665,7 @@ IPDF_Page* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { CPDFSDK_InteractiveForm* CPDFSDK_FormFillEnvironment::GetInteractiveForm() { if (!m_pInteractiveForm) - m_pInteractiveForm = pdfium::MakeUnique<CPDFSDK_InteractiveForm>(this); + m_pInteractiveForm = std::make_unique<CPDFSDK_InteractiveForm>(this); return m_pInteractiveForm.get(); } @@ -777,7 +776,7 @@ void CPDFSDK_FormFillEnvironment::SendOnFocusChange( CPDF_Dictionary* annot_dict = (*pAnnot)->GetPDFAnnot()->GetAnnotDict(); - auto focused_annot = pdfium::MakeUnique<CPDF_AnnotContext>(annot_dict, page); + auto focused_annot = std::make_unique<CPDF_AnnotContext>(annot_dict, page); FPDF_ANNOTATION fpdf_annot = FPDFAnnotationFromCPDFAnnotContext(focused_annot.get()); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h index 3841d55f99e..3528168658a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -166,9 +166,7 @@ class CPDFSDK_FormFillEnvironment final : public Observable, void GotoURL(const WideString& wsURL); FS_RECTF GetPageViewRect(IPDF_Page* page); - bool PopupMenu(IPDF_Page* page, - int menuFlag, - const CFX_PointF& pt); + bool PopupMenu(IPDF_Page* page, int menuFlag, const CFX_PointF& pt); void EmailTo(FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING pTo, FPDF_WIDESTRING pSubject, diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_helpers.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_helpers.cpp index 33d27adf5f3..ef0222253fb 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_helpers.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_helpers.cpp @@ -71,8 +71,7 @@ unsigned long GetStreamMaybeCopyAndReturnLengthImpl(const CPDF_Stream* stream, #ifdef PDF_ENABLE_XFA class FPDF_FileHandlerContext final : public IFX_SeekableStream { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CONSTRUCT_VIA_MAKE_RETAIN; // IFX_SeekableStream: FX_FILESIZE GetSize() override; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interactiveform.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interactiveform.cpp index c724af55d34..c9e94753ceb 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interactiveform.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_interactiveform.cpp @@ -9,7 +9,6 @@ #include <algorithm> #include <memory> #include <sstream> -#include <string> #include <utility> #include <vector> @@ -36,7 +35,6 @@ #include "fpdfsdk/ipdfsdk_annothandler.h" #include "fxjs/ijs_event_context.h" #include "fxjs/ijs_runtime.h" -#include "third_party/base/ptr_util.h" namespace { @@ -114,7 +112,7 @@ bool FDFToURLEncodedData( CPDFSDK_InteractiveForm::CPDFSDK_InteractiveForm( CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), - m_pInteractiveForm(pdfium::MakeUnique<CPDF_InteractiveForm>( + m_pInteractiveForm(std::make_unique<CPDF_InteractiveForm>( m_pFormFillEnv->GetPDFDocument())) { m_pInteractiveForm->SetNotifierIface(this); RemoveAllHighLights(); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp index e5d0d63baf8..52215ef7283 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.cpp @@ -228,6 +228,15 @@ void CPDFSDK_PageView::ReplaceSelection(const WideString& text) { } } +bool CPDFSDK_PageView::SelectAllText() { + CPDFSDK_Annot* annot = GetFocusAnnot(); + if (!annot) + return false; + + CPDFSDK_AnnotHandlerMgr* handler = m_pFormFillEnv->GetAnnotHandlerMgr(); + return handler->Annot_SelectAllText(annot); +} + bool CPDFSDK_PageView::CanUndo() { if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = @@ -510,7 +519,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { bool bUpdateAP = CPDF_InteractiveForm::IsUpdateAPEnabled(); // Disable the default AP construction. CPDF_InteractiveForm::SetUpdateAP(false); - m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); + m_pAnnotList = std::make_unique<CPDF_AnnotList>(pPage); CPDF_InteractiveForm::SetUpdateAP(bUpdateAP); const size_t nCount = m_pAnnotList->Count(); @@ -562,7 +571,7 @@ bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const { if (!p) return false; - return pdfium::ContainsValue(m_SDKAnnotArray, p); + return pdfium::Contains(m_SDKAnnotArray, p); } CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h index 1c947b9d3a1..50680f3828b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_pageview.h @@ -57,6 +57,7 @@ class CPDFSDK_PageView final : public CPDF_Page::View { WideString GetFocusedFormText(); WideString GetSelectedText(); void ReplaceSelection(const WideString& text); + bool SelectAllText(); bool CanUndo(); bool CanRedo(); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_renderpage.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_renderpage.cpp index ae2fdfa0895..ab3ce611b5d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_renderpage.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_renderpage.cpp @@ -6,6 +6,7 @@ #include "fpdfsdk/cpdfsdk_renderpage.h" +#include <memory> #include <utility> #include "core/fpdfapi/render/cpdf_pagerendercache.h" @@ -16,7 +17,6 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_pauseadapter.h" -#include "third_party/base/ptr_util.h" namespace { @@ -29,7 +29,7 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext, bool need_to_restore, CPDFSDK_PauseAdapter* pause) { if (!pContext->m_pOptions) - pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); + pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>(); auto& options = pContext->m_pOptions->GetOptions(); options.bClearType = !!(flags & FPDF_LCD_TEXT); @@ -58,14 +58,14 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext, pContext->m_pDevice->SaveState(); pContext->m_pDevice->SetBaseClip(clipping_rect); pContext->m_pDevice->SetClip_Rect(clipping_rect); - pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>( + pContext->m_pContext = std::make_unique<CPDF_RenderContext>( pPage->GetDocument(), pPage->m_pPageResources.Get(), static_cast<CPDF_PageRenderCache*>(pPage->GetRenderCache())); pContext->m_pContext->AppendLayer(pPage, &matrix); if (flags & FPDF_ANNOT) { - auto pOwnedList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); + auto pOwnedList = std::make_unique<CPDF_AnnotList>(pPage); CPDF_AnnotList* pList = pOwnedList.get(); pContext->m_pAnnots = std::move(pOwnedList); bool bPrinting = @@ -74,7 +74,7 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext, false, nullptr); } - pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( + pContext->m_pRenderer = std::make_unique<CPDF_ProgressiveRenderer>( pContext->m_pContext.get(), pContext->m_pDevice.get(), pContext->m_pOptions.get()); pContext->m_pRenderer->Start(pause); diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp index 4ecc705f67a..7b25d62eb19 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.cpp @@ -464,6 +464,11 @@ WideString CPDFSDK_Widget::GetDefaultValue() const { return pFormField->GetDefaultValue(); } +WideString CPDFSDK_Widget::GetExportValue() const { + CPDF_FormControl* pFormCtrl = GetFormControl(); + return pFormCtrl->GetExportValue(); +} + WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { CPDF_FormField* pFormField = GetFormField(); return pFormField->GetOptionLabel(nIndex); @@ -693,8 +698,8 @@ CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { CFX_FloatRect rcWindow = GetRotatedRect(); float fBorderWidth = GetBorderWidth(); switch (GetBorderStyle()) { - case BorderStyle::BEVELED: - case BorderStyle::INSET: + case BorderStyle::kBeveled: + case BorderStyle::kInset: fBorderWidth *= 2.0f; break; default: diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h index 8214e080f25..56ce8c8076e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widget.h @@ -68,6 +68,7 @@ class CPDFSDK_Widget final : public CPDFSDK_BAAnnot { int GetSelectedIndex(int nIndex) const; WideString GetValue() const; WideString GetDefaultValue() const; + WideString GetExportValue() const; WideString GetOptionLabel(int nIndex) const; int CountOptions() const; bool IsOptionSelected(int nIndex) const; diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp index a4222cf8cf6..63d0edf9f6f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -7,7 +7,6 @@ #include "fpdfsdk/cpdfsdk_widgethandler.h" #include <memory> -#include <vector> #include "constants/access_permissions.h" #include "constants/form_flags.h" @@ -20,7 +19,6 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler() = default; @@ -63,7 +61,7 @@ std::unique_ptr<CPDFSDK_Annot> CPDFSDK_WidgetHandler::NewAnnot( if (!pCtrl) return nullptr; - auto pWidget = pdfium::MakeUnique<CPDFSDK_Widget>(pAnnot, pPageView, pForm); + auto pWidget = std::make_unique<CPDFSDK_Widget>(pAnnot, pPageView, pForm); pForm->AddMap(pCtrl, pWidget.get()); if (pPDFForm->NeedConstructAP()) pWidget->ResetAppearance(pdfium::nullopt, false); @@ -278,6 +276,10 @@ void CPDFSDK_WidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, m_pFormFiller->ReplaceSelection(pAnnot, text); } +bool CPDFSDK_WidgetHandler::SelectAllText(CPDFSDK_Annot* pAnnot) { + return !pAnnot->IsSignatureWidget() && m_pFormFiller->SelectAllText(pAnnot); +} + bool CPDFSDK_WidgetHandler::CanUndo(CPDFSDK_Annot* pAnnot) { return !pAnnot->IsSignatureWidget() && m_pFormFiller->CanUndo(pAnnot); } @@ -306,6 +308,6 @@ bool CPDFSDK_WidgetHandler::IsFocusableAnnot( const CPDF_Annot::Subtype& annot_type) const { ASSERT(annot_type == CPDF_Annot::Subtype::WIDGET); - return pdfium::ContainsValue(m_pFormFillEnv->GetFocusableAnnotSubtypes(), - annot_type); + return pdfium::Contains(m_pFormFillEnv->GetFocusableAnnotSubtypes(), + annot_type); } diff --git a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h index afbbc0d8639..5e2236e52e1 100644 --- a/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/cpdfsdk_widgethandler.h @@ -37,6 +37,7 @@ class CPDFSDK_WidgetHandler final : public IPDFSDK_AnnotHandler { WideString GetText(CPDFSDK_Annot* pAnnot) override; WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override; + bool SelectAllText(CPDFSDK_Annot* pAnnot) override; bool CanUndo(CPDFSDK_Annot* pAnnot) override; bool CanRedo(CPDFSDK_Annot* pAnnot) override; bool Undo(CPDFSDK_Annot* pAnnot) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp index 1ab48a16a0f..fcc6154cbc4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_button.cpp @@ -14,7 +14,7 @@ CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pFormFillEnv, m_bMouseIn(false), m_bMouseDown(false) {} -CFFL_Button::~CFFL_Button() {} +CFFL_Button::~CFFL_Button() = default; void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView) { m_bMouseIn = true; diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp index b0e60e2b05f..c8f114896a1 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_checkbox.cpp @@ -14,18 +14,17 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/pwl/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) : CFFL_Button(pApp, pWidget) {} -CFFL_CheckBox::~CFFL_CheckBox() {} +CFFL_CheckBox::~CFFL_CheckBox() = default; std::unique_ptr<CPWL_Wnd> CFFL_CheckBox::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = pdfium::MakeUnique<CPWL_CheckBox>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_CheckBox>(cp, std::move(pAttachedData)); pWnd->Realize(); pWnd->SetCheck(m_pWidget->IsChecked()); return std::move(pWnd); @@ -64,7 +63,7 @@ bool CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true); - if (pWnd) { + if (pWnd && !pWnd->IsReadOnly()) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); pWnd->SetCheck(!pWidget->IsChecked()); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp index 5d6dd618381..a759b537d36 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_combobox.cpp @@ -14,12 +14,10 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/pwl/cpwl_combo_box.h" -#include "third_party/base/ptr_util.h" CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) - : CFFL_TextObject(pApp, pWidget) { -} + : CFFL_TextObject(pApp, pWidget) {} CFFL_ComboBox::~CFFL_ComboBox() { for (const auto& it : m_Maps) @@ -44,7 +42,7 @@ CPWL_Wnd::CreateParams CFFL_ComboBox::GetCreateParam() { std::unique_ptr<CPWL_Wnd> CFFL_ComboBox::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = pdfium::MakeUnique<CPWL_ComboBox>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_ComboBox>(cp, std::move(pAttachedData)); pWnd->AttachFFLData(this); pWnd->Realize(); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp index 2cfedeaf79d..7856254eaeb 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -14,7 +14,6 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" -#include "third_party/base/ptr_util.h" CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, CPDFSDK_Widget* pWidget) @@ -214,6 +213,14 @@ void CFFL_FormFiller::ReplaceSelection(const WideString& text) { pWnd->ReplaceSelection(text); } +bool CFFL_FormFiller::SelectAllText() { + if (!IsValid()) + return false; + + CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false); + return pWnd && pWnd->SelectAllText(); +} + bool CFFL_FormFiller::CanUndo() { if (!IsValid()) return false; @@ -314,11 +321,11 @@ CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() { cp.nBorderStyle = m_pWidget->GetBorderStyle(); switch (cp.nBorderStyle) { - case BorderStyle::DASH: + case BorderStyle::kDash: cp.sDash = CPWL_Dash(3, 3, 0); break; - case BorderStyle::BEVELED: - case BorderStyle::INSET: + case BorderStyle::kBeveled: + case BorderStyle::kInset: cp.dwBorderWidth *= 2; break; default: @@ -343,7 +350,7 @@ CPWL_Wnd* CFFL_FormFiller::GetPWLWindow(CPDFSDK_PageView* pPageView, return nullptr; CPWL_Wnd::CreateParams cp = GetCreateParam(); - auto pPrivateData = pdfium::MakeUnique<CFFL_PrivateData>(); + auto pPrivateData = std::make_unique<CFFL_PrivateData>(); pPrivateData->pWidget.Reset(m_pWidget.Get()); pPrivateData->pPageView = pPageView; pPrivateData->nWidgetAppearanceAge = m_pWidget->GetAppearanceAge(); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h index ba0f753d460..31860f78f7c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_formfiller.h @@ -76,6 +76,7 @@ class CFFL_FormFiller : public CPWL_Wnd::ProviderIface, WideString GetText(); WideString GetSelectedText(); void ReplaceSelection(const WideString& text); + bool SelectAllText(); bool CanUndo(); bool CanRedo(); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index 8681c30f64b..841c1afa68b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -23,7 +23,6 @@ #include "fpdfsdk/formfiller/cffl_radiobutton.h" #include "fpdfsdk/formfiller/cffl_textfield.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" CFFL_InteractiveFormFiller::CFFL_InteractiveFormFiller( @@ -477,27 +476,27 @@ CFFL_FormFiller* CFFL_InteractiveFormFiller::GetOrCreateFormFiller( switch (pWidget->GetFieldType()) { case FormFieldType::kPushButton: pFormFiller = - pdfium::MakeUnique<CFFL_PushButton>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_PushButton>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kCheckBox: pFormFiller = - pdfium::MakeUnique<CFFL_CheckBox>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_CheckBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kRadioButton: pFormFiller = - pdfium::MakeUnique<CFFL_RadioButton>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_RadioButton>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kTextField: pFormFiller = - pdfium::MakeUnique<CFFL_TextField>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_TextField>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kListBox: pFormFiller = - pdfium::MakeUnique<CFFL_ListBox>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_ListBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kComboBox: pFormFiller = - pdfium::MakeUnique<CFFL_ComboBox>(m_pFormFillEnv.Get(), pWidget); + std::make_unique<CFFL_ComboBox>(m_pFormFillEnv.Get(), pWidget); break; case FormFieldType::kUnknown: default: @@ -531,6 +530,12 @@ void CFFL_InteractiveFormFiller::ReplaceSelection(CPDFSDK_Annot* pAnnot, pFormFiller->ReplaceSelection(text); } +bool CFFL_InteractiveFormFiller::SelectAllText(CPDFSDK_Annot* pAnnot) { + ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); + CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot); + return pAnnot && pFormFiller->SelectAllText(); +} + bool CFFL_InteractiveFormFiller::CanUndo(CPDFSDK_Annot* pAnnot) { ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot); @@ -976,5 +981,5 @@ CFFL_PrivateData::~CFFL_PrivateData() = default; std::unique_ptr<IPWL_SystemHandler::PerWindowData> CFFL_PrivateData::Clone() const { - return pdfium::MakeUnique<CFFL_PrivateData>(*this); + return std::make_unique<CFFL_PrivateData>(*this); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h index d614b24c249..d663100a3e3 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -89,6 +89,7 @@ class CFFL_InteractiveFormFiller final : public IPWL_Filler_Notify { WideString GetText(CPDFSDK_Annot* pAnnot); WideString GetSelectedText(CPDFSDK_Annot* pAnnot); void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text); + bool SelectAllText(CPDFSDK_Annot* pAnnot); bool CanUndo(CPDFSDK_Annot* pAnnot); bool CanRedo(CPDFSDK_Annot* pAnnot); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp index b8339a2198c..f5990d18c3b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_listbox.cpp @@ -14,7 +14,6 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/pwl/cpwl_list_box.h" -#include "third_party/base/ptr_util.h" CFFL_ListBox::CFFL_ListBox(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) @@ -42,7 +41,7 @@ CPWL_Wnd::CreateParams CFFL_ListBox::GetCreateParam() { std::unique_ptr<CPWL_Wnd> CFFL_ListBox::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = pdfium::MakeUnique<CPWL_ListBox>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_ListBox>(cp, std::move(pAttachedData)); pWnd->AttachFFLData(this); pWnd->Realize(); pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp index e9872f6b24f..e6a0b5eecb4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_pushbutton.cpp @@ -10,7 +10,6 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/pwl/cpwl_special_button.h" -#include "third_party/base/ptr_util.h" CFFL_PushButton::CFFL_PushButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) @@ -21,7 +20,7 @@ CFFL_PushButton::~CFFL_PushButton() = default; std::unique_ptr<CPWL_Wnd> CFFL_PushButton::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = pdfium::MakeUnique<CPWL_PushButton>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_PushButton>(cp, std::move(pAttachedData)); pWnd->Realize(); return std::move(pWnd); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp index b7cf32d4595..0d167b4bb38 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_radiobutton.cpp @@ -14,19 +14,17 @@ #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/pwl/cpwl_special_button.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" CFFL_RadioButton::CFFL_RadioButton(CPDFSDK_FormFillEnvironment* pApp, CPDFSDK_Widget* pWidget) : CFFL_Button(pApp, pWidget) {} -CFFL_RadioButton::~CFFL_RadioButton() {} +CFFL_RadioButton::~CFFL_RadioButton() = default; std::unique_ptr<CPWL_Wnd> CFFL_RadioButton::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = - pdfium::MakeUnique<CPWL_RadioButton>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_RadioButton>(cp, std::move(pAttachedData)); pWnd->Realize(); pWnd->SetCheck(m_pWidget->IsChecked()); return std::move(pWnd); @@ -60,7 +58,7 @@ bool CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true); - if (pWnd) + if (pWnd && !pWnd->IsReadOnly()) pWnd->SetCheck(true); return CommitData(pPageView, nFlags); } diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp index a0d352b2d37..93ec9fe1e72 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textfield.cpp @@ -13,7 +13,6 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" namespace { @@ -84,7 +83,7 @@ CPWL_Wnd::CreateParams CFFL_TextField::GetCreateParam() { std::unique_ptr<CPWL_Wnd> CFFL_TextField::NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) { - auto pWnd = pdfium::MakeUnique<CPWL_Edit>(cp, std::move(pAttachedData)); + auto pWnd = std::make_unique<CPWL_Edit>(cp, std::move(pAttachedData)); pWnd->AttachFFLData(this); pWnd->Realize(); pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); diff --git a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textobject.cpp b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textobject.cpp index 6d84960767a..161b1dabd89 100644 --- a/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textobject.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/formfiller/cffl_textobject.cpp @@ -8,7 +8,6 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfdoc/cba_fontmap.h" -#include "third_party/base/ptr_util.h" CPWL_Wnd* CFFL_TextObject::ResetPWLWindow(CPDFSDK_PageView* pPageView, bool bRestoreValue) { @@ -36,9 +35,9 @@ CFFL_TextObject::~CFFL_TextObject() { CBA_FontMap* CFFL_TextObject::MaybeCreateFontMap() { if (!m_pFontMap) { - m_pFontMap = pdfium::MakeUnique<CBA_FontMap>( - m_pWidget->GetPDFPage()->GetDocument(), - m_pWidget->GetPDFAnnot()->GetAnnotDict()); + m_pFontMap = + std::make_unique<CBA_FontMap>(m_pWidget->GetPDFPage()->GetDocument(), + m_pWidget->GetPDFAnnot()->GetAnnotDict()); } return m_pFontMap.get(); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_annot.cpp index b414c8fe272..98b3e4f0a15 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_annot.cpp @@ -272,6 +272,27 @@ CPDF_FormField* GetFormField(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { return pPDFForm->GetFieldByDict(pAnnotDict); } +CPDFSDK_Widget* GetRadioButtonOrCheckBoxWidget(FPDF_FORMHANDLE hHandle, + FPDF_ANNOTATION annot) { + CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); + if (!pAnnotDict) + return nullptr; + + CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); + if (!pForm) + return nullptr; + + CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); + CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict); + if (!pFormField || (pFormField->GetType() != CPDF_FormField::kCheckBox && + pFormField->GetType() != CPDF_FormField::kRadioButton)) { + return nullptr; + } + + CPDF_FormControl* pFormControl = pPDFForm->GetControlByDict(pAnnotDict); + return pFormControl ? pForm->GetWidget(pFormControl) : nullptr; +} + } // namespace FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV @@ -296,7 +317,7 @@ FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype) { pDict->SetNewFor<CPDF_Name>(pdfium::annotation::kSubtype, CPDF_Annot::AnnotSubtypeToString( static_cast<CPDF_Annot::Subtype>(subtype))); - auto pNewAnnot = pdfium::MakeUnique<CPDF_AnnotContext>( + auto pNewAnnot = std::make_unique<CPDF_AnnotContext>( pDict.Get(), IPDFPageFromFPDFPage(page)); CPDF_Array* pAnnotList = pPage->GetDict()->GetArrayFor("Annots"); @@ -332,7 +353,7 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page, return nullptr; auto pNewAnnot = - pdfium::MakeUnique<CPDF_AnnotContext>(pDict, IPDFPageFromFPDFPage(page)); + std::make_unique<CPDF_AnnotContext>(pDict, IPDFPageFromFPDFPage(page)); // Caller takes ownership. return FPDFAnnotationFromCPDFAnnotContext(pNewAnnot.release()); @@ -389,7 +410,7 @@ FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot) { return FPDF_ANNOT_UNKNOWN; return static_cast<FPDF_ANNOTATION_SUBTYPE>(CPDF_Annot::StringToAnnotSubtype( - pAnnotDict->GetStringFor(pdfium::annotation::kSubtype))); + pAnnotDict->GetNameFor(pdfium::annotation::kSubtype))); } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV @@ -638,7 +659,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetColor(FPDF_ANNOTATION annot, // Use default color. The default colors must be consistent with the ones // used to generate AP. See calls to GetColorStringWithDefault() in // CPVT_GenerateAP::Generate*AP(). - if (pAnnotDict->GetStringFor(pdfium::annotation::kSubtype) == "Highlight") { + if (pAnnotDict->GetNameFor(pdfium::annotation::kSubtype) == "Highlight") { *R = 255; *G = 255; *B = 0; @@ -858,7 +879,7 @@ FPDFAnnot_SetAP(FPDF_ANNOTATION annot, static constexpr const char* kModeKeyForMode[] = {"N", "R", "D"}; static_assert( - FX_ArraySize(kModeKeyForMode) == FPDF_ANNOT_APPEARANCEMODE_COUNT, + pdfium::size(kModeKeyForMode) == FPDF_ANNOT_APPEARANCEMODE_COUNT, "length of kModeKeyForMode should be equal to " "FPDF_ANNOT_APPEARANCEMODE_COUNT"); const char* modeKey = kModeKeyForMode[appearanceMode]; @@ -947,11 +968,11 @@ FPDFAnnot_GetLinkedAnnot(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) { return nullptr; CPDF_Dictionary* pLinkedDict = pAnnot->GetAnnotDict()->GetDictFor(key); - if (!pLinkedDict || pLinkedDict->GetStringFor("Type") != "Annot") + if (!pLinkedDict || pLinkedDict->GetNameFor("Type") != "Annot") return nullptr; auto pLinkedAnnot = - pdfium::MakeUnique<CPDF_AnnotContext>(pLinkedDict, pAnnot->GetPage()); + std::make_unique<CPDF_AnnotContext>(pLinkedDict, pAnnot->GetPage()); // Caller takes ownership. return FPDFAnnotationFromCPDFAnnotContext(pLinkedAnnot.release()); @@ -1105,29 +1126,7 @@ FPDFAnnot_GetFontSize(FPDF_FORMHANDLE hHandle, FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_IsChecked(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { - CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); - if (!pForm) - return false; - - CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); - if (!pAnnotDict) - return false; - - CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); - CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict); - if (!pFormField) - return false; - - if (pFormField->GetType() != CPDF_FormField::kCheckBox && - pFormField->GetType() != CPDF_FormField::kRadioButton) { - return false; - } - - CPDF_FormControl* pFormControl = pPDFForm->GetControlByDict(pAnnotDict); - if (!pFormControl) - return false; - - CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); + CPDFSDK_Widget* pWidget = GetRadioButtonOrCheckBoxWidget(hHandle, annot); return pWidget && pWidget->IsChecked(); } @@ -1199,3 +1198,38 @@ FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFAnnot_GetLink(FPDF_ANNOTATION annot) { return FPDFLinkFromCPDFDictionary( CPDFAnnotContextFromFPDFAnnotation(annot)->GetAnnotDict()); } + +FPDF_EXPORT int FPDF_CALLCONV +FPDFAnnot_GetFormControlCount(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { + CPDF_FormField* pFormField = GetFormField(hHandle, annot); + return pFormField ? pFormField->CountControls() : -1; +} + +FPDF_EXPORT int FPDF_CALLCONV +FPDFAnnot_GetFormControlIndex(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot) { + CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot); + if (!pAnnotDict) + return -1; + + CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle); + if (!pForm) + return -1; + + CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm(); + CPDF_FormField* pFormField = pPDFForm->GetFieldByDict(pAnnotDict); + CPDF_FormControl* pFormControl = pPDFForm->GetControlByDict(pAnnotDict); + return pFormField ? pFormField->GetControlIndex(pFormControl) : -1; +} + +FPDF_EXPORT unsigned long FPDF_CALLCONV +FPDFAnnot_GetFormFieldExportValue(FPDF_FORMHANDLE hHandle, + FPDF_ANNOTATION annot, + FPDF_WCHAR* buffer, + unsigned long buflen) { + CPDFSDK_Widget* pWidget = GetRadioButtonOrCheckBoxWidget(hHandle, annot); + if (!pWidget) + return 0; + + return Utf16EncodeMaybeCopyAndReturnLength(pWidget->GetExportValue(), buffer, + buflen); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_embeddertest.cpp index 1869e348ab7..4dfee27c097 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_embeddertest.cpp @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "public/fpdf_annot.h" + +#include <limits.h> + #include <algorithm> #include <cwchar> #include <memory> @@ -10,10 +14,13 @@ #include "build/build_config.h" #include "constants/annotation_common.h" -#include "core/fxcrt/fx_memory.h" +#include "core/fpdfapi/page/cpdf_annotcontext.h" +#include "core/fpdfapi/page/cpdf_pagemodule.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fxcrt/fx_system.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_scopers.h" -#include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdf_formfill.h" #include "public/fpdfview.h" @@ -28,6 +35,13 @@ namespace { +const wchar_t kStreamData[] = + L"/GS gs 0.0 0.0 0.0 RG 4 w 211.8 747.6 m 211.8 744.8 " + L"212.6 743.0 214.2 740.8 " + L"c 215.4 739.0 216.8 737.1 218.9 736.1 c 220.8 735.1 221.4 733.0 " + L"223.7 732.4 c 232.6 729.9 242.0 730.8 251.2 730.8 c 257.5 730.8 " + L"263.0 732.9 269.0 734.4 c S"; + #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) #if defined(OS_LINUX) const char kAnnotationStampWithApChecksum[] = @@ -83,8 +97,8 @@ void VerifyAnnotationSubtypesAndFocusability( ASSERT_TRUE(annot); EXPECT_EQ(expected_subtypes[i], FPDFAnnot_GetSubtype(annot.get())); - bool expected_focusable = pdfium::ContainsValue(expected_focusable_subtypes, - expected_subtypes[i]); + bool expected_focusable = + pdfium::Contains(expected_focusable_subtypes, expected_subtypes[i]); EXPECT_EQ(expected_focusable, FORM_SetFocusedAnnot(form_handle, annot.get())); @@ -97,6 +111,235 @@ void VerifyAnnotationSubtypesAndFocusability( class FPDFAnnotEmbedderTest : public EmbedderTest {}; +TEST_F(FPDFAnnotEmbedderTest, SetAP) { + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ASSERT_TRUE(doc); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); + ASSERT_TRUE(page); + ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData); + ASSERT_TRUE(ap_stream); + + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); + ASSERT_TRUE(annot); + + // Negative case: FPDFAnnot_SetAP() should fail if bounding rect is not yet + // set on the annotation. + EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, + ap_stream.get())); + + const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f}; + EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect)); + + ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, + /*R=*/255, /*G=*/0, /*B=*/0, /*A=*/255)); + + EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, + ap_stream.get())); + + // Verify that appearance stream is created as form XObject + CPDF_AnnotContext* context = CPDFAnnotContextFromFPDFAnnotation(annot.get()); + ASSERT_TRUE(context); + CPDF_Dictionary* annot_dict = context->GetAnnotDict(); + ASSERT_TRUE(annot_dict); + CPDF_Dictionary* ap_dict = annot_dict->GetDictFor(pdfium::annotation::kAP); + ASSERT_TRUE(ap_dict); + CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N"); + ASSERT_TRUE(stream_dict); + // Check for non-existence of resources dictionary in case of opaque color + CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources"); + ASSERT_FALSE(resources_dict); + ByteString type = stream_dict->GetStringFor(pdfium::annotation::kType); + EXPECT_EQ("XObject", type); + ByteString sub_type = stream_dict->GetStringFor(pdfium::annotation::kSubtype); + EXPECT_EQ("Form", sub_type); + + // Check that the appearance stream is same as we just set. + const uint32_t kStreamDataSize = + pdfium::size(kStreamData) * sizeof(FPDF_WCHAR); + unsigned long normal_length_bytes = FPDFAnnot_GetAP( + annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0); + ASSERT_EQ(kStreamDataSize, normal_length_bytes); + std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes); + EXPECT_EQ(kStreamDataSize, + FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, + buf.data(), normal_length_bytes)); + EXPECT_EQ(kStreamData, GetPlatformWString(buf.data())); +} + +TEST_F(FPDFAnnotEmbedderTest, SetAPWithOpacity) { + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ASSERT_TRUE(doc); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); + ASSERT_TRUE(page); + ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData); + ASSERT_TRUE(ap_stream); + + ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); + ASSERT_TRUE(annot); + + ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, + /*R=*/255, /*G=*/0, /*B=*/0, /*A=*/102)); + + const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f}; + EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect)); + + EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, + ap_stream.get())); + + CPDF_AnnotContext* context = CPDFAnnotContextFromFPDFAnnotation(annot.get()); + ASSERT_TRUE(context); + CPDF_Dictionary* annot_dict = context->GetAnnotDict(); + ASSERT_TRUE(annot_dict); + CPDF_Dictionary* ap_dict = annot_dict->GetDictFor(pdfium::annotation::kAP); + ASSERT_TRUE(ap_dict); + CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N"); + ASSERT_TRUE(stream_dict); + CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources"); + ASSERT_TRUE(stream_dict); + CPDF_Dictionary* extGState_dict = resources_dict->GetDictFor("ExtGState"); + ASSERT_TRUE(extGState_dict); + CPDF_Dictionary* gs_dict = extGState_dict->GetDictFor("GS"); + ASSERT_TRUE(gs_dict); + ByteString type = gs_dict->GetStringFor(pdfium::annotation::kType); + EXPECT_EQ("ExtGState", type); + float opacity = gs_dict->GetNumberFor("CA"); + // Opacity value of 102 is represented as 0.4f (=104/255) in /CA entry. + EXPECT_FLOAT_EQ(0.4f, opacity); + ByteString blend_mode = gs_dict->GetStringFor("BM"); + EXPECT_EQ("Normal", blend_mode); + bool alpha_source_flag = gs_dict->GetBooleanFor("AIS", true); + EXPECT_FALSE(alpha_source_flag); +} + +TEST_F(FPDFAnnotEmbedderTest, InkListAPIValidations) { + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ASSERT_TRUE(doc); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); + ASSERT_TRUE(page); + + // Create a new ink annotation. + ScopedFPDFAnnotation ink_annot( + FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); + ASSERT_TRUE(ink_annot); + CPDF_AnnotContext* context = + CPDFAnnotContextFromFPDFAnnotation(ink_annot.get()); + ASSERT_TRUE(context); + CPDF_Dictionary* annot_dict = context->GetAnnotDict(); + ASSERT_TRUE(annot_dict); + + static constexpr FS_POINTF kFirstInkStroke[] = { + {80.0f, 90.0f}, {81.0f, 91.0f}, {82.0f, 92.0f}, + {83.0f, 93.0f}, {84.0f, 94.0f}, {85.0f, 95.0f}}; + static constexpr size_t kFirstStrokePointCount = + pdfium::size(kFirstInkStroke); + + static constexpr FS_POINTF kSecondInkStroke[] = { + {70.0f, 90.0f}, {71.0f, 91.0f}, {72.0f, 92.0f}}; + static constexpr size_t kSecondStrokePointCount = + pdfium::size(kSecondInkStroke); + + static constexpr FS_POINTF kThirdInkStroke[] = {{60.0f, 90.0f}, + {61.0f, 91.0f}, + {62.0f, 92.0f}, + {63.0f, 93.0f}, + {64.0f, 94.0f}}; + static constexpr size_t kThirdStrokePointCount = + pdfium::size(kThirdInkStroke); + + // Negative test: |annot| is passed as nullptr. + EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(nullptr, kFirstInkStroke, + kFirstStrokePointCount)); + + // Negative test: |annot| is not ink annotation. + // Create a new highlight annotation. + ScopedFPDFAnnotation highlight_annot( + FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_HIGHLIGHT)); + ASSERT_TRUE(highlight_annot); + EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(highlight_annot.get(), kFirstInkStroke, + kFirstStrokePointCount)); + + // Negative test: passing |point_count| as 0. + EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, 0)); + + // Negative test: passing |points| array as nullptr. + EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), nullptr, + kFirstStrokePointCount)); + + // Negative test: passing |point_count| more than ULONG_MAX/2. + EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke, + ULONG_MAX / 2 + 1)); + + // InkStroke should get added to ink annotation. Also inklist should get + // created. + EXPECT_EQ(0, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, + kFirstStrokePointCount)); + + CPDF_Array* inklist = annot_dict->GetArrayFor("InkList"); + ASSERT_TRUE(inklist); + EXPECT_EQ(1u, inklist->size()); + EXPECT_EQ(kFirstStrokePointCount * 2, inklist->GetArrayAt(0)->size()); + + // Adding another inkStroke to ink annotation with all valid paremeters. + // InkList already exists in ink_annot. + EXPECT_EQ(1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke, + kSecondStrokePointCount)); + EXPECT_EQ(2u, inklist->size()); + EXPECT_EQ(kSecondStrokePointCount * 2, inklist->GetArrayAt(1)->size()); + + // Adding one more InkStroke to the ink annotation. |point_count| passed is + // less than the data available in |buffer|. + EXPECT_EQ(2, FPDFAnnot_AddInkStroke(ink_annot.get(), kThirdInkStroke, + kThirdStrokePointCount - 1)); + EXPECT_EQ(3u, inklist->size()); + EXPECT_EQ((kThirdStrokePointCount - 1) * 2, inklist->GetArrayAt(2)->size()); +} + +TEST_F(FPDFAnnotEmbedderTest, RemoveInkList) { + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ASSERT_TRUE(doc); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); + ASSERT_TRUE(page); + + // Negative test: |annot| is passed as nullptr. + EXPECT_FALSE(FPDFAnnot_RemoveInkList(nullptr)); + + // Negative test: |annot| is not ink annotation. + // Create a new highlight annotation. + ScopedFPDFAnnotation highlight_annot( + FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_HIGHLIGHT)); + ASSERT_TRUE(highlight_annot); + EXPECT_FALSE(FPDFAnnot_RemoveInkList(highlight_annot.get())); + + // Create a new ink annotation. + ScopedFPDFAnnotation ink_annot( + FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); + ASSERT_TRUE(ink_annot); + CPDF_AnnotContext* context = + CPDFAnnotContextFromFPDFAnnotation(ink_annot.get()); + ASSERT_TRUE(context); + CPDF_Dictionary* annot_dict = context->GetAnnotDict(); + ASSERT_TRUE(annot_dict); + + static constexpr FS_POINTF kInkStroke[] = {{80.0f, 90.0f}, {81.0f, 91.0f}, + {82.0f, 92.0f}, {83.0f, 93.0f}, + {84.0f, 94.0f}, {85.0f, 95.0f}}; + static constexpr size_t kPointCount = pdfium::size(kInkStroke); + + // InkStroke should get added to ink annotation. Also inklist should get + // created. + EXPECT_EQ(0, + FPDFAnnot_AddInkStroke(ink_annot.get(), kInkStroke, kPointCount)); + + CPDF_Array* inklist = annot_dict->GetArrayFor("InkList"); + ASSERT_TRUE(inklist); + ASSERT_EQ(1u, inklist->size()); + EXPECT_EQ(kPointCount * 2, inklist->GetArrayAt(0)->size()); + + // Remove inklist. + EXPECT_TRUE(FPDFAnnot_RemoveInkList(ink_annot.get())); + EXPECT_FALSE(annot_dict->KeyExist("InkList")); +} + TEST_F(FPDFAnnotEmbedderTest, BadParams) { ASSERT_TRUE(OpenDocument("hello_world.pdf")); FPDF_PAGE page = LoadPage(0); @@ -994,13 +1237,22 @@ TEST_F(FPDFAnnotEmbedderTest, ModifyAnnotationFlags) { UnloadPage(page); } -// TODO(crbug.com/pdfium/11): Fix this test and enable. -#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) +// TODO(crbug.com/pdfium/1541): Fix this test and enable. +#if defined(_SKIA_SUPPORT_) #define MAYBE_AddAndModifyImage DISABLED_AddAndModifyImage #else #define MAYBE_AddAndModifyImage AddAndModifyImage #endif TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyImage) { +#if defined(_SKIA_SUPPORT_PATHS_) +#if defined(OS_LINUX) + static const char kMd5NewImage[] = "26a8eb30937226a677839379e0d7ae1a"; + static const char kMd5ModifiedImage[] = "2985114b32ba1a96be78ee643fe31aa5"; +#else + static const char kMd5NewImage[] = "14012ab500b4671fa73dd760129a8a93"; + static const char kMd5ModifiedImage[] = "5f97f98f58ed04dc393f31460485f1a2"; +#endif // defined(OS_LINUX) +#else #if defined(OS_MACOSX) static const char kMd5NewImage[] = "dd18709d90c245a12ce0b8c4d092bea9"; static const char kMd5ModifiedImage[] = "8d6f478ff8c7e67d49b253f1af587a99"; @@ -1011,6 +1263,7 @@ TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyImage) { static const char kMd5NewImage[] = "528e6243dc29d54f36b61e0d3287d935"; static const char kMd5ModifiedImage[] = "6d9e59f3e57a1ff82fb258356b7eb731"; #endif +#endif // defined(_SKIA_SUPPORT_PATHS_) // Open a file with two annotations and load its first page. ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); @@ -1082,23 +1335,27 @@ TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyImage) { VerifySavedDocument(595, 842, kMd5ModifiedImage); } -// TODO(crbug.com/pdfium/11): Fix this test and enable. +TEST_F(FPDFAnnotEmbedderTest, AddAndModifyText) { #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) -#define MAYBE_AddAndModifyText DISABLED_AddAndModifyText +#if defined(OS_LINUX) + static const char kMd5NewText[] = "c9d853a5fb6bca31e9696ccc4462c74a"; + static const char kMd5ModifiedText[] = "bc681fa9174223983c5e4357e919d36c"; #else -#define MAYBE_AddAndModifyText AddAndModifyText -#endif -TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyText) { -#if defined(OS_MACOSX) - static const char kMd5NewText[] = "e657266260b88c964938efe6c9b292da"; - static const char kMd5ModifiedText[] = "7accdf2bac64463101783221f53d3188"; -#elif defined(OS_WIN) + static const char kMd5NewText[] = "4aaa34e9df2e41d621dbd81b1d535c48"; + static const char kMd5ModifiedText[] = "d6ea20beb7834ef4b6d370581ce425fc"; +#endif // defined(OS_LINUX) +#else +#if defined(OS_WIN) static const char kMd5NewText[] = "204cc01749a70b8afc246a4ca33c7eb6"; static const char kMd5ModifiedText[] = "641261a45e8dfd68c89b80bfd237660d"; +#elif defined(OS_MACOSX) + static const char kMd5NewText[] = "e657266260b88c964938efe6c9b292da"; + static const char kMd5ModifiedText[] = "7accdf2bac64463101783221f53d3188"; #else static const char kMd5NewText[] = "00197ad6206f763febad5719e5935306"; static const char kMd5ModifiedText[] = "85853bc0aaa5a4e3af04e58b9cbfff23"; #endif +#endif // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) // Open a file with two annotations and load its first page. ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); @@ -2469,7 +2726,7 @@ TEST_F(FPDFAnnotEmbedderTest, GetFormFieldType) { FPDF_FORMFIELD_CHECKBOX, FPDF_FORMFIELD_RADIOBUTTON}; - for (size_t i = 0; i < FX_ArraySize(kExpectedAnnotTypes); ++i) { + for (size_t i = 0; i < pdfium::size(kExpectedAnnotTypes); ++i) { ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i)); ASSERT_TRUE(annot); EXPECT_EQ(kExpectedAnnotTypes[i], @@ -2641,9 +2898,9 @@ TEST_F(FPDFAnnotEmbedderTest, FocusableAnnotSubtypes) { // Test invalid parameters. EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(nullptr, kDefaultSubtypes, - FX_ArraySize(kDefaultSubtypes))); + pdfium::size(kDefaultSubtypes))); EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(form_handle(), nullptr, - FX_ArraySize(kDefaultSubtypes))); + pdfium::size(kDefaultSubtypes))); EXPECT_EQ(-1, FPDFAnnot_GetFocusableSubtypesCount(nullptr)); std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(1); @@ -2684,7 +2941,7 @@ TEST_F(FPDFAnnotEmbedderTest, MAYBE_FocusableAnnotRendering) { // Make links and highlights focusable. static constexpr FPDF_ANNOTATION_SUBTYPE kSubTypes[] = {FPDF_ANNOT_LINK, FPDF_ANNOT_HIGHLIGHT}; - constexpr int kSubTypesCount = FX_ArraySize(kSubTypes); + constexpr int kSubTypesCount = pdfium::size(kSubTypes); ASSERT_TRUE( FPDFAnnot_SetFocusableSubtypes(form_handle(), kSubTypes, kSubTypesCount)); ASSERT_EQ(kSubTypesCount, FPDFAnnot_GetFocusableSubtypesCount(form_handle())); @@ -2750,7 +3007,7 @@ TEST_F(FPDFAnnotEmbedderTest, GetLinkFromAnnotation) { constexpr char kExpectedResult[] = "https://cs.chromium.org/chromium/src/third_party/pdfium/public/" "fpdf_text.h"; - constexpr unsigned long kExpectedLength = FX_ArraySize(kExpectedResult); + constexpr unsigned long kExpectedLength = pdfium::size(kExpectedResult); unsigned long bufsize = FPDFAction_GetURIPath(document(), action, nullptr, 0); ASSERT_EQ(kExpectedLength, bufsize); @@ -2772,3 +3029,184 @@ TEST_F(FPDFAnnotEmbedderTest, GetLinkFromAnnotation) { UnloadPage(page); } + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountRadioButton) { + // Open a file with radio button widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + // Checks for bad annot. + EXPECT_EQ(-1, + FPDFAnnot_GetFormControlCount(form_handle(), /*annot=*/nullptr)); + + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3)); + ASSERT_TRUE(annot); + + // Checks for bad form handle. + EXPECT_EQ(-1, + FPDFAnnot_GetFormControlCount(/*hHandle=*/nullptr, annot.get())); + + EXPECT_EQ(3, FPDFAnnot_GetFormControlCount(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountCheckBox) { + // Open a file with checkbox widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + EXPECT_EQ(1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlCountInvalidAnnotation) { + // Open a file with ink annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + EXPECT_EQ(-1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexRadioButton) { + // Open a file with radio button widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + // Checks for bad annot. + EXPECT_EQ(-1, + FPDFAnnot_GetFormControlIndex(form_handle(), /*annot=*/nullptr)); + + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3)); + ASSERT_TRUE(annot); + + // Checks for bad form handle. + EXPECT_EQ(-1, + FPDFAnnot_GetFormControlIndex(/*hHandle=*/nullptr, annot.get())); + + EXPECT_EQ(1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexCheckBox) { + // Open a file with checkbox widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + EXPECT_EQ(0, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormControlIndexInvalidAnnotation) { + // Open a file with ink annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + EXPECT_EQ(-1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueRadioButton) { + // Open a file with radio button widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + // Checks for bad annot. + EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue( + form_handle(), /*annot=*/nullptr, + /*buffer=*/nullptr, /*buflen=*/0)); + + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 6)); + ASSERT_TRUE(annot); + + // Checks for bad form handle. + EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue( + /*hHandle=*/nullptr, annot.get(), + /*buffer=*/nullptr, /*buflen=*/0)); + + unsigned long length_bytes = + FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(), + /*buffer=*/nullptr, /*buflen=*/0); + ASSERT_EQ(14u, length_bytes); + std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); + EXPECT_EQ(14u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(), + buf.data(), length_bytes)); + EXPECT_EQ(L"value2", GetPlatformWString(buf.data())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueCheckBox) { + // Open a file with checkbox widget annotations and load its first page. + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + + unsigned long length_bytes = + FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(), + /*buffer=*/nullptr, /*buflen=*/0); + ASSERT_EQ(8u, length_bytes); + std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); + EXPECT_EQ(8u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(), + buf.data(), length_bytes)); + EXPECT_EQ(L"Yes", GetPlatformWString(buf.data())); + } + + UnloadPage(page); +} + +TEST_F(FPDFAnnotEmbedderTest, GetFormFieldExportValueInvalidAnnotation) { + // Open a file with ink annotations and load its first page. + ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); + ASSERT_TRUE(annot); + EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(), + /*buffer=*/nullptr, + /*buflen=*/0)); + } + + UnloadPage(page); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_unittest.cpp deleted file mode 100644 index 7ddd57951a8..00000000000 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_annot_unittest.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright 2019 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "public/fpdf_annot.h" - -#include <limits.h> - -#include <vector> - -#include "constants/annotation_common.h" -#include "core/fpdfapi/page/cpdf_annotcontext.h" -#include "core/fpdfapi/page/cpdf_pagemodule.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "fpdfsdk/cpdfsdk_helpers.h" -#include "public/cpp/fpdf_scopers.h" -#include "public/fpdf_edit.h" -#include "testing/fx_string_testhelpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -const wchar_t kStreamData[] = - L"/GS gs 0.0 0.0 0.0 RG 4 w 211.8 747.6 m 211.8 744.8 " - L"212.6 743.0 214.2 740.8 " - L"c 215.4 739.0 216.8 737.1 218.9 736.1 c 220.8 735.1 221.4 733.0 " - L"223.7 732.4 c 232.6 729.9 242.0 730.8 251.2 730.8 c 257.5 730.8 " - L"263.0 732.9 269.0 734.4 c S"; - -} // namespace - -class PDFAnnotTest : public testing::Test { - protected: - PDFAnnotTest() = default; - ~PDFAnnotTest() override = default; - - void SetUp() override { CPDF_PageModule::Create(); } - void TearDown() override { CPDF_PageModule::Destroy(); } -}; - -TEST_F(PDFAnnotTest, SetAP) { - ScopedFPDFDocument doc(FPDF_CreateNewDocument()); - ASSERT_TRUE(doc); - ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); - ASSERT_TRUE(page); - ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData); - ASSERT_TRUE(ap_stream); - - ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); - ASSERT_TRUE(annot); - - // Negative case: FPDFAnnot_SetAP() should fail if bounding rect is not yet - // set on the annotation. - EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, - ap_stream.get())); - - const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f}; - EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect)); - - ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, - /*R=*/255, /*G=*/0, /*B=*/0, /*A=*/255)); - - EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, - ap_stream.get())); - - // Verify that appearance stream is created as form XObject - CPDF_AnnotContext* context = CPDFAnnotContextFromFPDFAnnotation(annot.get()); - ASSERT_TRUE(context); - CPDF_Dictionary* annot_dict = context->GetAnnotDict(); - ASSERT_TRUE(annot_dict); - CPDF_Dictionary* ap_dict = annot_dict->GetDictFor(pdfium::annotation::kAP); - ASSERT_TRUE(ap_dict); - CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N"); - ASSERT_TRUE(stream_dict); - // Check for non-existence of resources dictionary in case of opaque color - CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources"); - ASSERT_FALSE(resources_dict); - ByteString type = stream_dict->GetStringFor(pdfium::annotation::kType); - EXPECT_EQ("XObject", type); - ByteString sub_type = stream_dict->GetStringFor(pdfium::annotation::kSubtype); - EXPECT_EQ("Form", sub_type); - - // Check that the appearance stream is same as we just set. - const uint32_t kStreamDataSize = - FX_ArraySize(kStreamData) * sizeof(FPDF_WCHAR); - unsigned long normal_length_bytes = FPDFAnnot_GetAP( - annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0); - ASSERT_EQ(kStreamDataSize, normal_length_bytes); - std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes); - EXPECT_EQ(kStreamDataSize, - FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, - buf.data(), normal_length_bytes)); - EXPECT_EQ(kStreamData, GetPlatformWString(buf.data())); -} - -TEST_F(PDFAnnotTest, SetAPWithOpacity) { - ScopedFPDFDocument doc(FPDF_CreateNewDocument()); - ASSERT_TRUE(doc); - ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); - ASSERT_TRUE(page); - ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData); - ASSERT_TRUE(ap_stream); - - ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); - ASSERT_TRUE(annot); - - ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, - /*R=*/255, /*G=*/0, /*B=*/0, /*A=*/102)); - - const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f}; - EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect)); - - EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, - ap_stream.get())); - - CPDF_AnnotContext* context = CPDFAnnotContextFromFPDFAnnotation(annot.get()); - ASSERT_TRUE(context); - CPDF_Dictionary* annot_dict = context->GetAnnotDict(); - ASSERT_TRUE(annot_dict); - CPDF_Dictionary* ap_dict = annot_dict->GetDictFor(pdfium::annotation::kAP); - ASSERT_TRUE(ap_dict); - CPDF_Dictionary* stream_dict = ap_dict->GetDictFor("N"); - ASSERT_TRUE(stream_dict); - CPDF_Dictionary* resources_dict = stream_dict->GetDictFor("Resources"); - ASSERT_TRUE(stream_dict); - CPDF_Dictionary* extGState_dict = resources_dict->GetDictFor("ExtGState"); - ASSERT_TRUE(extGState_dict); - CPDF_Dictionary* gs_dict = extGState_dict->GetDictFor("GS"); - ASSERT_TRUE(gs_dict); - ByteString type = gs_dict->GetStringFor(pdfium::annotation::kType); - EXPECT_EQ("ExtGState", type); - float opacity = gs_dict->GetNumberFor("CA"); - // Opacity value of 102 is represented as 0.4f (=104/255) in /CA entry. - EXPECT_FLOAT_EQ(0.4f, opacity); - ByteString blend_mode = gs_dict->GetStringFor("BM"); - EXPECT_EQ("Normal", blend_mode); - bool alpha_source_flag = gs_dict->GetBooleanFor("AIS", true); - EXPECT_FALSE(alpha_source_flag); -} - -TEST_F(PDFAnnotTest, InkListAPIValidations) { - ScopedFPDFDocument doc(FPDF_CreateNewDocument()); - ASSERT_TRUE(doc); - ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); - ASSERT_TRUE(page); - - // Create a new ink annotation. - ScopedFPDFAnnotation ink_annot( - FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); - ASSERT_TRUE(ink_annot); - CPDF_AnnotContext* context = - CPDFAnnotContextFromFPDFAnnotation(ink_annot.get()); - ASSERT_TRUE(context); - CPDF_Dictionary* annot_dict = context->GetAnnotDict(); - ASSERT_TRUE(annot_dict); - - static constexpr FS_POINTF kFirstInkStroke[] = { - {80.0f, 90.0f}, {81.0f, 91.0f}, {82.0f, 92.0f}, - {83.0f, 93.0f}, {84.0f, 94.0f}, {85.0f, 95.0f}}; - static constexpr size_t kFirstStrokePointCount = - FX_ArraySize(kFirstInkStroke); - - static constexpr FS_POINTF kSecondInkStroke[] = { - {70.0f, 90.0f}, {71.0f, 91.0f}, {72.0f, 92.0f}}; - static constexpr size_t kSecondStrokePointCount = - FX_ArraySize(kSecondInkStroke); - - static constexpr FS_POINTF kThirdInkStroke[] = {{60.0f, 90.0f}, - {61.0f, 91.0f}, - {62.0f, 92.0f}, - {63.0f, 93.0f}, - {64.0f, 94.0f}}; - static constexpr size_t kThirdStrokePointCount = - FX_ArraySize(kThirdInkStroke); - - // Negative test: |annot| is passed as nullptr. - EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(nullptr, kFirstInkStroke, - kFirstStrokePointCount)); - - // Negative test: |annot| is not ink annotation. - // Create a new highlight annotation. - ScopedFPDFAnnotation highlight_annot( - FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_HIGHLIGHT)); - ASSERT_TRUE(highlight_annot); - EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(highlight_annot.get(), kFirstInkStroke, - kFirstStrokePointCount)); - - // Negative test: passing |point_count| as 0. - EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, 0)); - - // Negative test: passing |points| array as nullptr. - EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), nullptr, - kFirstStrokePointCount)); - - // Negative test: passing |point_count| more than ULONG_MAX/2. - EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke, - ULONG_MAX / 2 + 1)); - - // InkStroke should get added to ink annotation. Also inklist should get - // created. - EXPECT_EQ(0, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, - kFirstStrokePointCount)); - - CPDF_Array* inklist = annot_dict->GetArrayFor("InkList"); - ASSERT_TRUE(inklist); - EXPECT_EQ(1u, inklist->size()); - EXPECT_EQ(kFirstStrokePointCount * 2, inklist->GetArrayAt(0)->size()); - - // Adding another inkStroke to ink annotation with all valid paremeters. - // InkList already exists in ink_annot. - EXPECT_EQ(1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke, - kSecondStrokePointCount)); - EXPECT_EQ(2u, inklist->size()); - EXPECT_EQ(kSecondStrokePointCount * 2, inklist->GetArrayAt(1)->size()); - - // Adding one more InkStroke to the ink annotation. |point_count| passed is - // less than the data available in |buffer|. - EXPECT_EQ(2, FPDFAnnot_AddInkStroke(ink_annot.get(), kThirdInkStroke, - kThirdStrokePointCount - 1)); - EXPECT_EQ(3u, inklist->size()); - EXPECT_EQ((kThirdStrokePointCount - 1) * 2, inklist->GetArrayAt(2)->size()); -} - -TEST_F(PDFAnnotTest, RemoveInkList) { - ScopedFPDFDocument doc(FPDF_CreateNewDocument()); - ASSERT_TRUE(doc); - ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100)); - ASSERT_TRUE(page); - - // Negative test: |annot| is passed as nullptr. - EXPECT_FALSE(FPDFAnnot_RemoveInkList(nullptr)); - - // Negative test: |annot| is not ink annotation. - // Create a new highlight annotation. - ScopedFPDFAnnotation highlight_annot( - FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_HIGHLIGHT)); - ASSERT_TRUE(highlight_annot); - EXPECT_FALSE(FPDFAnnot_RemoveInkList(highlight_annot.get())); - - // Create a new ink annotation. - ScopedFPDFAnnotation ink_annot( - FPDFPage_CreateAnnot(page.get(), FPDF_ANNOT_INK)); - ASSERT_TRUE(ink_annot); - CPDF_AnnotContext* context = - CPDFAnnotContextFromFPDFAnnotation(ink_annot.get()); - ASSERT_TRUE(context); - CPDF_Dictionary* annot_dict = context->GetAnnotDict(); - ASSERT_TRUE(annot_dict); - - static constexpr FS_POINTF kInkStroke[] = {{80.0f, 90.0f}, {81.0f, 91.0f}, - {82.0f, 92.0f}, {83.0f, 93.0f}, - {84.0f, 94.0f}, {85.0f, 95.0f}}; - static constexpr size_t kPointCount = FX_ArraySize(kInkStroke); - - // InkStroke should get added to ink annotation. Also inklist should get - // created. - EXPECT_EQ(0, - FPDFAnnot_AddInkStroke(ink_annot.get(), kInkStroke, kPointCount)); - - CPDF_Array* inklist = annot_dict->GetArrayFor("InkList"); - ASSERT_TRUE(inklist); - ASSERT_EQ(1u, inklist->size()); - EXPECT_EQ(kPointCount * 2, inklist->GetArrayAt(0)->size()); - - // Remove inklist. - EXPECT_TRUE(FPDFAnnot_RemoveInkList(ink_annot.get())); - EXPECT_FALSE(annot_dict->KeyExist("InkList")); -} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment.cpp index 7c47fb69cc0..f4e296333f5 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment.cpp @@ -26,7 +26,6 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_memory_wrappers.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" namespace { @@ -202,7 +201,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, FPDF_DOCUMENT document, const void* contents, - const unsigned long len) { + unsigned long len) { CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pFile || !pFile->IsDictionary() || !pDoc || len > INT_MAX) @@ -248,17 +247,23 @@ FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, return true; } -FPDF_EXPORT unsigned long FPDF_CALLCONV +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, void* buffer, - unsigned long buflen) { + unsigned long buflen, + unsigned long* out_buflen) { + if (!out_buflen) + return false; + CPDF_Object* pFile = CPDFObjectFromFPDFAttachment(attachment); if (!pFile) - return 0; + return false; CPDF_Stream* pFileStream = CPDF_FileSpec(pFile).GetFileStream(); if (!pFileStream) - return 0; + return false; - return DecodeStreamMaybeCopyAndReturnLength(pFileStream, buffer, buflen); + *out_buflen = + DecodeStreamMaybeCopyAndReturnLength(pFileStream, buffer, buflen); + return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment_embeddertest.cpp index 08f00dc178f..2b6c8b62d9a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_attachment_embeddertest.cpp @@ -37,11 +37,17 @@ TEST_F(FPDFAttachmentEmbedderTest, ExtractAttachments) { EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes)); EXPECT_EQ(L"1.txt", GetPlatformWString(buf.data())); + // Check some unsuccessful cases of FPDFAttachment_GetFile. + EXPECT_FALSE(FPDFAttachment_GetFile(attachment, nullptr, 0, nullptr)); + EXPECT_FALSE(FPDFAttachment_GetFile(nullptr, nullptr, 0, &length_bytes)); + // Check that the content of the first attachment is correct. - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); std::vector<char> content_buf(length_bytes); - ASSERT_EQ( - 4u, FPDFAttachment_GetFile(attachment, content_buf.data(), length_bytes)); + unsigned long actual_length_bytes; + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(4u, actual_length_bytes); EXPECT_EQ(std::string("test"), std::string(content_buf.data(), 4)); // Check that a non-existent key does not exist. @@ -68,11 +74,12 @@ TEST_F(FPDFAttachmentEmbedderTest, ExtractAttachments) { ASSERT_TRUE(attachment); // Retrieve the second attachment file. - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); content_buf.clear(); content_buf.resize(length_bytes); - ASSERT_EQ(5869u, FPDFAttachment_GetFile(attachment, content_buf.data(), - length_bytes)); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(5869u, actual_length_bytes); // Check that the calculated checksum of the file data matches expectation. const char kCheckSum[] = "72afcddedf554dda63c0c88e06f1ce18"; @@ -101,6 +108,30 @@ TEST_F(FPDFAttachmentEmbedderTest, NoAttachmentToExtract) { EXPECT_FALSE(FPDFDoc_GetAttachment(document(), 0)); } +TEST_F(FPDFAttachmentEmbedderTest, InvalidAttachmentData) { + // Open a file with an attachment that is missing the embedded file (/EF). + ASSERT_TRUE(OpenDocument("embedded_attachments_invalid_data.pdf")); + ASSERT_EQ(1, FPDFDoc_GetAttachmentCount(document())); + + // Retrieve the first attachment. + FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0); + ASSERT_TRUE(attachment); + + // Check that the name of the attachment is correct. + unsigned long length_bytes = FPDFAttachment_GetName(attachment, nullptr, 0); + ASSERT_EQ(12u, length_bytes); + std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); + EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes)); + EXPECT_EQ("1.txt", GetPlatformString(buf.data())); + + // Check that is is not possible to retrieve the file data. + EXPECT_FALSE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); + + // Check that the attachment can be deleted. + EXPECT_TRUE(FPDFDoc_DeleteAttachment(document(), 0)); + EXPECT_EQ(0, FPDFDoc_GetAttachmentCount(document())); +} + TEST_F(FPDFAttachmentEmbedderTest, AddAttachments) { // Open a file with two attachments. ASSERT_TRUE(OpenDocument("embedded_attachments.pdf")); @@ -134,10 +165,12 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachments) { EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data())); // Verify the content of the new attachment (i.e. the first attachment). - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); std::vector<char> content_buf(length_bytes); - ASSERT_EQ( - 6u, FPDFAttachment_GetFile(attachment, content_buf.data(), length_bytes)); + unsigned long actual_length_bytes; + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(6u, actual_length_bytes); EXPECT_EQ(std::string(kContents1), std::string(content_buf.data(), 6)); // Add an attachment to the end of the embedded file list and set its file. @@ -159,11 +192,12 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachments) { EXPECT_EQ(L"z.txt", GetPlatformWString(buf.data())); // Verify the content of the new attachment (i.e. the fourth attachment). - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); content_buf.clear(); content_buf.resize(length_bytes); - ASSERT_EQ( - 6u, FPDFAttachment_GetFile(attachment, content_buf.data(), length_bytes)); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(6u, actual_length_bytes); EXPECT_EQ(std::string(kContents2), std::string(content_buf.data(), 6)); } @@ -203,10 +237,12 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachmentsWithParams) { EXPECT_EQ(L"5.txt", GetPlatformWString(buf.data())); // Verify the content of the new attachment. - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); std::vector<char> content_buf(length_bytes); - ASSERT_EQ(12u, FPDFAttachment_GetFile(attachment, content_buf.data(), - length_bytes)); + unsigned long actual_length_bytes; + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(12u, actual_length_bytes); EXPECT_EQ(std::string(kContents), std::string(content_buf.data(), 12)); // Verify the creation date of the new attachment. @@ -230,7 +266,8 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachmentsWithParams) { // Overwrite the existing file with empty content, and check that the checksum // gets updated to the correct value. EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), nullptr, 0)); - EXPECT_EQ(0u, FPDFAttachment_GetFile(attachment, nullptr, 0)); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); + EXPECT_EQ(0u, length_bytes); length_bytes = FPDFAttachment_GetStringValue(attachment, kChecksumKey, nullptr, 0); ASSERT_EQ(70u, length_bytes); @@ -268,10 +305,12 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachmentsToFileWithNoAttachments) { EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data())); // Verify the content of the new attachment (i.e. the first attachment). - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); std::vector<char> content_buf(length_bytes); - ASSERT_EQ( - 6u, FPDFAttachment_GetFile(attachment, content_buf.data(), length_bytes)); + unsigned long actual_length_bytes; + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(6u, actual_length_bytes); EXPECT_EQ(std::string(kContents1), std::string(content_buf.data(), 6)); // Add an attachment to the end of the embedded file list and set its file. @@ -293,11 +332,12 @@ TEST_F(FPDFAttachmentEmbedderTest, AddAttachmentsToFileWithNoAttachments) { EXPECT_EQ(L"z.txt", GetPlatformWString(buf.data())); // Verify the content of the new attachment (i.e. the second attachment). - length_bytes = FPDFAttachment_GetFile(attachment, nullptr, 0); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, nullptr, 0, &length_bytes)); content_buf.clear(); content_buf.resize(length_bytes); - ASSERT_EQ( - 6u, FPDFAttachment_GetFile(attachment, content_buf.data(), length_bytes)); + ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(), + length_bytes, &actual_length_bytes)); + ASSERT_EQ(6u, actual_length_bytes); EXPECT_EQ(std::string(kContents2), std::string(content_buf.data(), 6)); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_catalog_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_catalog_unittest.cpp index 1ae35b21089..2224065cda6 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_catalog_unittest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_catalog_unittest.cpp @@ -17,13 +17,12 @@ #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_scopers.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/base/ptr_util.h" class CPDF_TestDocument final : public CPDF_Document { public: CPDF_TestDocument() - : CPDF_Document(pdfium::MakeUnique<CPDF_DocRenderData>(), - pdfium::MakeUnique<CPDF_DocPageData>()) {} + : CPDF_Document(std::make_unique<CPDF_DocRenderData>(), + std::make_unique<CPDF_DocPageData>()) {} void SetRoot(CPDF_Dictionary* root) { SetRootForTesting(root); } }; @@ -32,7 +31,7 @@ class PDFCatalogTest : public testing::Test { public: void SetUp() override { CPDF_PageModule::Create(); - auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>(); + auto pTestDoc = std::make_unique<CPDF_TestDocument>(); m_pDoc.reset(FPDFDocumentFromCPDFDocument(pTestDoc.release())); m_pRootObj = pdfium::MakeRetain<CPDF_Dictionary>(); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail.cpp index 11abff337a4..05713ff2de4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_dataavail.cpp @@ -18,7 +18,6 @@ #include "core/fxcrt/retain_ptr.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_formfill.h" -#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" @@ -66,8 +65,7 @@ class FPDF_FileAvailContext final : public CPDF_DataAvail::FileAvail { class FPDF_FileAccessContext final : public IFX_SeekableReadStream { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CONSTRUCT_VIA_MAKE_RETAIN; // IFX_SeekableReadStream: FX_FILESIZE GetSize() override { return file_->m_FileLen; } @@ -116,11 +114,11 @@ class FPDF_DownloadHintsContext final : public CPDF_DataAvail::DownloadHints { class FPDF_AvailContext { public: FPDF_AvailContext(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file) - : file_avail_(pdfium::MakeUnique<FPDF_FileAvailContext>(file_avail)), + : file_avail_(std::make_unique<FPDF_FileAvailContext>(file_avail)), file_read_(pdfium::MakeRetain<FPDF_FileAccessContext>(file)), - data_avail_(pdfium::MakeUnique<CPDF_DataAvail>(file_avail_.get(), - file_read_, - true)) {} + data_avail_(std::make_unique<CPDF_DataAvail>(file_avail_.get(), + file_read_, + true)) {} ~FPDF_AvailContext() = default; CPDF_DataAvail* data_avail() { return data_avail_.get(); } @@ -139,7 +137,7 @@ FPDF_AvailContext* FPDFAvailContextFromFPDFAvail(FPDF_AVAIL avail) { FPDF_EXPORT FPDF_AVAIL FPDF_CALLCONV FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file) { - auto pAvail = pdfium::MakeUnique<FPDF_AvailContext>(file_avail, file); + auto pAvail = std::make_unique<FPDF_AvailContext>(file_avail, file); return pAvail.release(); // Caller takes ownership. } @@ -165,15 +163,15 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { CPDF_Parser::Error error; std::unique_ptr<CPDF_Document> document; std::tie(error, document) = avail_context->data_avail()->ParseDocument( - pdfium::MakeUnique<CPDF_DocRenderData>(), - pdfium::MakeUnique<CPDF_DocPageData>(), password); + std::make_unique<CPDF_DocRenderData>(), + std::make_unique<CPDF_DocPageData>(), password); if (error != CPDF_Parser::SUCCESS) { ProcessParseError(error); return nullptr; } #ifdef PDF_ENABLE_XFA - document->SetExtension(pdfium::MakeUnique<CPDFXFA_Context>(document.get())); + document->SetExtension(std::make_unique<CPDFXFA_Context>(document.get())); #endif // PDF_ENABLE_XFA ReportUnsupportedFeatures(document.get()); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc.cpp index 350d1aae678..e85e530be57 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc.cpp @@ -10,6 +10,7 @@ #include <set> #include <utility> +#include "core/fpdfapi/page/cpdf_annotcontext.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -23,7 +24,6 @@ #include "core/fpdfdoc/cpdf_linklist.h" #include "core/fpdfdoc/cpdf_pagelabel.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -33,7 +33,7 @@ CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, const WideString& title, std::set<const CPDF_Dictionary*>* visited) { // Return if already checked to avoid circular calling. - if (pdfium::ContainsKey(*visited, bookmark.GetDict())) + if (pdfium::Contains(*visited, bookmark.GetDict())) return CPDF_Bookmark(); visited->insert(bookmark.GetDict()); @@ -45,7 +45,7 @@ CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, // Go into children items. CPDF_Bookmark child = tree.GetFirstChild(&bookmark); - while (child.GetDict() && !pdfium::ContainsKey(*visited, child.GetDict())) { + while (child.GetDict() && !pdfium::Contains(*visited, child.GetDict())) { // Check this item and its children. CPDF_Bookmark found = FindBookmark(tree, child, title, visited); if (found.GetDict()) @@ -61,7 +61,7 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) { if (pList) return pList; - auto pNewList = pdfium::MakeUnique<CPDF_LinkList>(); + auto pNewList = std::make_unique<CPDF_LinkList>(); pList = pNewList.get(); pDoc->SetLinksContext(std::move(pNewList)); return pList; @@ -258,7 +258,7 @@ FPDFDest_GetLocationInPage(FPDF_DEST dest, if (!dest) return false; - auto destination = pdfium::MakeUnique<CPDF_Dest>(CPDFArrayFromFPDFDest(dest)); + auto destination = std::make_unique<CPDF_Dest>(CPDFArrayFromFPDFDest(dest)); // FPDF_BOOL is an int, GetXYZ expects bools. bool bHasX; @@ -358,6 +358,20 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page, return false; } +FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV +FPDFLink_GetAnnot(FPDF_PAGE page, FPDF_LINK link_annot) { + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); + CPDF_Dictionary* pAnnotDict = CPDFDictionaryFromFPDFLink(link_annot); + if (!pPage || !pAnnotDict) + return nullptr; + + auto pAnnotContext = std::make_unique<CPDF_AnnotContext>( + pAnnotDict, IPDFPageFromFPDFPage(page)); + + // Caller takes the ownership of the object. + return FPDFAnnotationFromCPDFAnnotContext(pAnnotContext.release()); +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK link_annot, FS_RECTF* rect) { if (!link_annot || !rect) diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_embeddertest.cpp index fc543442cf0..6aabe4a367c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -4,7 +4,6 @@ #include <memory> #include <set> -#include <string> #include <vector> #include "core/fpdfapi/parser/cpdf_document.h" @@ -337,6 +336,23 @@ TEST_F(FPDFDocEmbedderTest, ActionURI) { UnloadPage(page); } +TEST_F(FPDFDocEmbedderTest, LinkToAnnotConversion) { + EXPECT_TRUE(OpenDocument("annots.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + { + FPDF_LINK first_link = FPDFLink_GetLinkAtPoint(page, 69.00, 653.00); + ScopedFPDFAnnotation first_annot(FPDFLink_GetAnnot(page, first_link)); + EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, first_annot.get())); + + FPDF_LINK second_link = FPDFLink_GetLinkAtPoint(page, 80.00, 633.00); + ScopedFPDFAnnotation second_annot(FPDFLink_GetAnnot(page, second_link)); + EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, second_annot.get())); + } + + UnloadPage(page); +} + TEST_F(FPDFDocEmbedderTest, ActionGoto) { EXPECT_TRUE(OpenDocument("goto_action.pdf")); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_unittest.cpp index c9110960b1d..6b3d9921a0e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_unittest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_doc_unittest.cpp @@ -24,13 +24,12 @@ #include "public/cpp/fpdf_scopers.h" #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/base/ptr_util.h" class CPDF_TestDocument final : public CPDF_Document { public: CPDF_TestDocument() - : CPDF_Document(pdfium::MakeUnique<CPDF_DocRenderData>(), - pdfium::MakeUnique<CPDF_DocPageData>()) {} + : CPDF_Document(std::make_unique<CPDF_DocRenderData>(), + std::make_unique<CPDF_DocPageData>()) {} void SetRoot(CPDF_Dictionary* root) { SetRootForTesting(root); } CPDF_IndirectObjectHolder* GetHolder() { return this; } @@ -45,7 +44,7 @@ class PDFDocTest : public testing::Test { void SetUp() override { CPDF_PageModule::Create(); - auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>(); + auto pTestDoc = std::make_unique<CPDF_TestDocument>(); m_pIndirectObjs = pTestDoc->GetHolder(); m_pRootObj.Reset(m_pIndirectObjs->NewIndirect<CPDF_Dictionary>()); pTestDoc->SetRoot(m_pRootObj.Get()); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_edit_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_edit_embeddertest.cpp index 3e96b99c4bf..cb7c8fbe5d4 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -35,7 +35,17 @@ using pdfium::kHelloWorldChecksum; namespace { -const char kRedRectangleChecksum[] = "66d02eaa6181e2c069ce2ea99beda497"; +const char kAllRemovedChecksum[] = "eee4600ac08b458ac7ac2320e225674c"; + +const wchar_t kBottomText[] = L"I'm at the bottom of the page"; + +#if defined(OS_WIN) +const char kBottomTextChecksum[] = "08d1ff3e5a42801bee6077fd366bef00"; +#elif defined(OS_MACOSX) +const char kBottomTextChecksum[] = "324e1db8164a040cf6104538baa95ba6"; +#else +const char kBottomTextChecksum[] = "eacaa24573b8ce997b3882595f096f00"; +#endif #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) #if defined(OS_WIN) @@ -53,6 +63,18 @@ const char kFirstRemovedChecksum[] = "b76df015fe88009c3c342395df96abf1"; #endif #endif // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) +const wchar_t kLoadedFontText[] = L"I am testing my loaded font, WEE."; + +#if defined(OS_WIN) +const char kLoadedFontTextChecksum[] = "d60ba39f9698e32360d99e727dd93165"; +#elif defined(OS_MACOSX) +const char kLoadedFontTextChecksum[] = "fc921c0bbdde73986ac13c15a85db4c3"; +#else +const char kLoadedFontTextChecksum[] = "70592859010ffbf532a2237b8118bcc4"; +#endif + +const char kRedRectangleChecksum[] = "66d02eaa6181e2c069ce2ea99beda497"; + } // namespace class FPDFEditEmbedderTest : public EmbedderTest { @@ -70,9 +92,10 @@ class FPDFEditEmbedderTest : public EmbedderTest { pdfium::span<const uint8_t> span) { const CPDF_Dictionary* font_desc = font_dict->GetDictFor("FontDescriptor"); ASSERT_TRUE(font_desc); - EXPECT_EQ("FontDescriptor", font_desc->GetStringFor("Type")); - EXPECT_EQ(font_dict->GetStringFor("BaseFont"), - font_desc->GetStringFor("FontName")); + EXPECT_EQ("FontDescriptor", font_desc->GetNameFor("Type")); + ByteString font_name = font_desc->GetNameFor("FontName"); + EXPECT_FALSE(font_name.IsEmpty()); + EXPECT_EQ(font_dict->GetNameFor("BaseFont"), font_name); // Check that the font descriptor has the required keys according to spec // 1.7 Table 5.19 @@ -576,13 +599,7 @@ TEST_F(FPDFEditEmbedderTest, BUG_1399) { UnloadPage(page); } -// TODO(crbug.com/pdfium/11): Fix this test and enable. -#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) -#define MAYBE_SetText DISABLED_SetText -#else -#define MAYBE_SetText SetText -#endif -TEST_F(FPDFEditEmbedderTest, MAYBE_SetText) { +TEST_F(FPDFEditEmbedderTest, SetText) { // Load document with some text. EXPECT_TRUE(OpenDocument("hello_world.pdf")); FPDF_PAGE page = LoadPage(0); @@ -598,16 +615,25 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_SetText) { // Verify the "Hello, world!" text is gone and "Changed for SetText test" is // now displayed. ASSERT_EQ(2, FPDFPage_CountObjects(page)); -#if defined(OS_MACOSX) - const char kChangedMD5[] = "904132275a1144ea06b0694537c80b4c"; -#elif defined(OS_WIN) - const char kChangedMD5[] = "3137fdb27962671f5c3963a5e965eff5"; + +#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) +#if defined(OS_WIN) + const char kChangedChecksum[] = "119f828345f547c68e9454418fb7d80d"; #else - const char kChangedMD5[] = "a0c4ea6620772991f66bf7130379b08a"; + const char kChangedChecksum[] = "6bc5171f4eb329474989c6ccfa3d6303"; +#endif // defined(OS_WIN) +#else +#if defined(OS_WIN) + const char kChangedChecksum[] = "3137fdb27962671f5c3963a5e965eff5"; +#elif defined(OS_MACOSX) + const char kChangedChecksum[] = "904132275a1144ea06b0694537c80b4c"; +#else + const char kChangedChecksum[] = "a0c4ea6620772991f66bf7130379b08a"; #endif +#endif // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) { ScopedFPDFBitmap page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap.get(), 200, 200, kChangedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kChangedChecksum); } // Now save the result. @@ -622,7 +648,7 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_SetText) { EXPECT_EQ(2, FPDFPage_CountObjects(saved_page)); { ScopedFPDFBitmap page_bitmap = RenderPage(saved_page); - CompareBitmap(page_bitmap.get(), 200, 200, kChangedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kChangedChecksum); } CloseSavedPage(saved_page); @@ -1092,16 +1118,7 @@ TEST_F(FPDFEditEmbedderTest, RemoveExistingPageObject) { CloseSavedDocument(); } -// TODO(crbug.com/pdfium/11): Fix this test and enable. -#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) -#define MAYBE_RemoveExistingPageObjectSplitStreamsNotLonely \ - DISABLED_RemoveExistingPageObjectSplitStreamsNotLonely -#else -#define MAYBE_RemoveExistingPageObjectSplitStreamsNotLonely \ - RemoveExistingPageObjectSplitStreamsNotLonely -#endif -TEST_F(FPDFEditEmbedderTest, - MAYBE_RemoveExistingPageObjectSplitStreamsNotLonely) { +TEST_F(FPDFEditEmbedderTest, RemoveExistingPageObjectSplitStreamsNotLonely) { // Load document with some text. EXPECT_TRUE(OpenDocument("hello_world_split_streams.pdf")); FPDF_PAGE page = LoadPage(0); @@ -1116,16 +1133,24 @@ TEST_F(FPDFEditEmbedderTest, // Verify the "Hello, world!" text is gone. ASSERT_EQ(2, FPDFPage_CountObjects(page)); -#if defined(OS_MACOSX) - const char kHelloRemovedMD5[] = "3b3b27602a86dfe5996a33c42c59885b"; -#elif defined(OS_WIN) - const char kHelloRemovedMD5[] = "a97d4c72c969ba373c2dce675d277e65"; +#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) +#if defined(OS_WIN) + const char kHelloRemovedChecksum[] = "e05c7837a5cad61305d157720637f969"; +#else + const char kHelloRemovedChecksum[] = "deed7dc2754dc80930f3b05e2ac86c94"; +#endif // defined(OS_WIN) #else - const char kHelloRemovedMD5[] = "95b92950647a2190e1230911e7a1a0e9"; +#if defined(OS_WIN) + const char kHelloRemovedChecksum[] = "a97d4c72c969ba373c2dce675d277e65"; +#elif defined(OS_MACOSX) + const char kHelloRemovedChecksum[] = "3b3b27602a86dfe5996a33c42c59885b"; +#else + const char kHelloRemovedChecksum[] = "95b92950647a2190e1230911e7a1a0e9"; #endif +#endif // defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) { ScopedFPDFBitmap page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap.get(), 200, 200, kHelloRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kHelloRemovedChecksum); } // Save the file @@ -1141,7 +1166,7 @@ TEST_F(FPDFEditEmbedderTest, EXPECT_EQ(2, FPDFPage_CountObjects(saved_page)); { ScopedFPDFBitmap page_bitmap = RenderPage(saved_page); - CompareBitmap(page_bitmap.get(), 200, 200, kHelloRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kHelloRemovedChecksum); } CloseSavedPage(saved_page); @@ -1352,10 +1377,9 @@ TEST_F(FPDFEditEmbedderTest, RemoveAllFromSingleStream) { ASSERT_EQ(0, FPDFPage_CountObjects(page)); - const char kAllRemovedMD5[] = "eee4600ac08b458ac7ac2320e225674c"; { ScopedFPDFBitmap page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum); } // Save the file @@ -1369,7 +1393,7 @@ TEST_F(FPDFEditEmbedderTest, RemoveAllFromSingleStream) { EXPECT_EQ(0, FPDFPage_CountObjects(saved_page)); { ScopedFPDFBitmap page_bitmap = RenderPage(saved_page); - CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum); } CloseSavedPage(saved_page); @@ -1527,10 +1551,9 @@ TEST_F(FPDFEditEmbedderTest, RemoveAllFromMultipleStreams) { ASSERT_EQ(0, FPDFPage_CountObjects(page)); - const char kAllRemovedMD5[] = "eee4600ac08b458ac7ac2320e225674c"; { ScopedFPDFBitmap page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum); } // Save the file @@ -1544,7 +1567,7 @@ TEST_F(FPDFEditEmbedderTest, RemoveAllFromMultipleStreams) { EXPECT_EQ(0, FPDFPage_CountObjects(saved_page)); { ScopedFPDFBitmap page_bitmap = RenderPage(saved_page); - CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedMD5); + CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum); } CloseSavedPage(saved_page); @@ -1946,25 +1969,17 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddStandardFontText) { FPDF_PAGEOBJECT text_object1 = FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); EXPECT_TRUE(text_object1); - ScopedFPDFWideString text1 = - GetFPDFWideString(L"I'm at the bottom of the page"); + ScopedFPDFWideString text1 = GetFPDFWideString(kBottomText); EXPECT_TRUE(FPDFText_SetText(text_object1, text1.get())); FPDFPageObj_Transform(text_object1, 1, 0, 0, 1, 20, 20); FPDFPage_InsertObject(page, text_object1); EXPECT_TRUE(FPDFPage_GenerateContent(page)); { ScopedFPDFBitmap page_bitmap = RenderPage(page); -#if defined(OS_MACOSX) - const char md5[] = "324e1db8164a040cf6104538baa95ba6"; -#elif defined(OS_WIN) - const char md5[] = "08d1ff3e5a42801bee6077fd366bef00"; -#else - const char md5[] = "eacaa24573b8ce997b3882595f096f00"; -#endif - CompareBitmap(page_bitmap.get(), 612, 792, md5); + CompareBitmap(page_bitmap.get(), 612, 792, kBottomTextChecksum); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - VerifySavedDocument(612, 792, md5); + VerifySavedDocument(612, 792, kBottomTextChecksum); } // Try another font @@ -2238,20 +2253,12 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddStandardFontText2) { FPDF_PAGEOBJECT text_object = FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f); EXPECT_TRUE(text_object); - ScopedFPDFWideString text = - GetFPDFWideString(L"I'm at the bottom of the page"); + ScopedFPDFWideString text = GetFPDFWideString(kBottomText); EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 20, 20); FPDFPage_InsertObject(page.get(), text_object); ScopedFPDFBitmap page_bitmap = RenderPage(page.get()); -#if defined(OS_MACOSX) - const char md5[] = "324e1db8164a040cf6104538baa95ba6"; -#elif defined(OS_WIN) - const char md5[] = "08d1ff3e5a42801bee6077fd366bef00"; -#else - const char md5[] = "eacaa24573b8ce997b3882595f096f00"; -#endif - CompareBitmap(page_bitmap.get(), 612, 792, md5); + CompareBitmap(page_bitmap.get(), 612, 792, kBottomTextChecksum); } TEST_F(FPDFEditEmbedderTest, LoadStandardFonts) { @@ -2425,9 +2432,9 @@ TEST_F(FPDFEditEmbedderTest, LoadSimpleType1Font) { EXPECT_TRUE(typed_font->IsType1Font()); const CPDF_Dictionary* font_dict = typed_font->GetFontDict(); - EXPECT_EQ("Font", font_dict->GetStringFor("Type")); - EXPECT_EQ("Type1", font_dict->GetStringFor("Subtype")); - EXPECT_EQ("TimesNewRomanPS-BoldMT", font_dict->GetStringFor("BaseFont")); + EXPECT_EQ("Font", font_dict->GetNameFor("Type")); + EXPECT_EQ("Type1", font_dict->GetNameFor("Subtype")); + EXPECT_EQ("TimesNewRomanPS-BoldMT", font_dict->GetNameFor("BaseFont")); ASSERT_TRUE(font_dict->KeyExist("FirstChar")); ASSERT_TRUE(font_dict->KeyExist("LastChar")); EXPECT_EQ(32, font_dict->GetIntegerFor("FirstChar")); @@ -2454,9 +2461,9 @@ TEST_F(FPDFEditEmbedderTest, LoadSimpleTrueTypeFont) { EXPECT_TRUE(typed_font->IsTrueTypeFont()); const CPDF_Dictionary* font_dict = typed_font->GetFontDict(); - EXPECT_EQ("Font", font_dict->GetStringFor("Type")); - EXPECT_EQ("TrueType", font_dict->GetStringFor("Subtype")); - EXPECT_EQ("CourierNewPSMT", font_dict->GetStringFor("BaseFont")); + EXPECT_EQ("Font", font_dict->GetNameFor("Type")); + EXPECT_EQ("TrueType", font_dict->GetNameFor("Subtype")); + EXPECT_EQ("CourierNewPSMT", font_dict->GetNameFor("BaseFont")); ASSERT_TRUE(font_dict->KeyExist("FirstChar")); ASSERT_TRUE(font_dict->KeyExist("LastChar")); EXPECT_EQ(32, font_dict->GetIntegerFor("FirstChar")); @@ -2484,11 +2491,10 @@ TEST_F(FPDFEditEmbedderTest, LoadCIDType0Font) { // Check font dictionary entries const CPDF_Dictionary* font_dict = typed_font->GetFontDict(); - EXPECT_EQ("Font", font_dict->GetStringFor("Type")); - EXPECT_EQ("Type0", font_dict->GetStringFor("Subtype")); - EXPECT_EQ("TimesNewRomanPSMT-Identity-H", - font_dict->GetStringFor("BaseFont")); - EXPECT_EQ("Identity-H", font_dict->GetStringFor("Encoding")); + EXPECT_EQ("Font", font_dict->GetNameFor("Type")); + EXPECT_EQ("Type0", font_dict->GetNameFor("Subtype")); + EXPECT_EQ("TimesNewRomanPSMT-Identity-H", font_dict->GetNameFor("BaseFont")); + EXPECT_EQ("Identity-H", font_dict->GetNameFor("Encoding")); const CPDF_Array* descendant_array = font_dict->GetArrayFor("DescendantFonts"); ASSERT_TRUE(descendant_array); @@ -2496,9 +2502,9 @@ TEST_F(FPDFEditEmbedderTest, LoadCIDType0Font) { // Check the CIDFontDict const CPDF_Dictionary* cidfont_dict = descendant_array->GetDictAt(0); - EXPECT_EQ("Font", cidfont_dict->GetStringFor("Type")); - EXPECT_EQ("CIDFontType0", cidfont_dict->GetStringFor("Subtype")); - EXPECT_EQ("TimesNewRomanPSMT", cidfont_dict->GetStringFor("BaseFont")); + EXPECT_EQ("Font", cidfont_dict->GetNameFor("Type")); + EXPECT_EQ("CIDFontType0", cidfont_dict->GetNameFor("Subtype")); + EXPECT_EQ("TimesNewRomanPSMT", cidfont_dict->GetNameFor("BaseFont")); const CPDF_Dictionary* cidinfo_dict = cidfont_dict->GetDictFor("CIDSystemInfo"); ASSERT_TRUE(cidinfo_dict); @@ -2533,10 +2539,10 @@ TEST_F(FPDFEditEmbedderTest, LoadCIDType2Font) { // Check font dictionary entries const CPDF_Dictionary* font_dict = typed_font->GetFontDict(); - EXPECT_EQ("Font", font_dict->GetStringFor("Type")); - EXPECT_EQ("Type0", font_dict->GetStringFor("Subtype")); - EXPECT_EQ("Arial-ItalicMT", font_dict->GetStringFor("BaseFont")); - EXPECT_EQ("Identity-H", font_dict->GetStringFor("Encoding")); + EXPECT_EQ("Font", font_dict->GetNameFor("Type")); + EXPECT_EQ("Type0", font_dict->GetNameFor("Subtype")); + EXPECT_EQ("Arial-ItalicMT", font_dict->GetNameFor("BaseFont")); + EXPECT_EQ("Identity-H", font_dict->GetNameFor("Encoding")); const CPDF_Array* descendant_array = font_dict->GetArrayFor("DescendantFonts"); ASSERT_TRUE(descendant_array); @@ -2544,9 +2550,9 @@ TEST_F(FPDFEditEmbedderTest, LoadCIDType2Font) { // Check the CIDFontDict const CPDF_Dictionary* cidfont_dict = descendant_array->GetDictAt(0); - EXPECT_EQ("Font", cidfont_dict->GetStringFor("Type")); - EXPECT_EQ("CIDFontType2", cidfont_dict->GetStringFor("Subtype")); - EXPECT_EQ("Arial-ItalicMT", cidfont_dict->GetStringFor("BaseFont")); + EXPECT_EQ("Font", cidfont_dict->GetNameFor("Type")); + EXPECT_EQ("CIDFontType2", cidfont_dict->GetNameFor("Subtype")); + EXPECT_EQ("Arial-ItalicMT", cidfont_dict->GetNameFor("BaseFont")); const CPDF_Dictionary* cidinfo_dict = cidfont_dict->GetDictFor("CIDSystemInfo"); ASSERT_TRUE(cidinfo_dict); @@ -2592,20 +2598,12 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddTrueTypeFontText) { FPDF_PAGEOBJECT text_object = FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f); EXPECT_TRUE(text_object); - ScopedFPDFWideString text = - GetFPDFWideString(L"I am testing my loaded font, WEE."); + ScopedFPDFWideString text = GetFPDFWideString(kLoadedFontText); EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400); FPDFPage_InsertObject(page, text_object); ScopedFPDFBitmap page_bitmap = RenderPage(page); -#if defined(OS_MACOSX) - const char md5[] = "fc921c0bbdde73986ac13c15a85db4c3"; -#elif defined(OS_WIN) - const char md5[] = "d60ba39f9698e32360d99e727dd93165"; -#else - const char md5[] = "70592859010ffbf532a2237b8118bcc4"; -#endif - CompareBitmap(page_bitmap.get(), 612, 792, md5); + CompareBitmap(page_bitmap.get(), 612, 792, kLoadedFontTextChecksum); // Add some more text, same font FPDF_PAGEOBJECT text_object2 = @@ -2616,20 +2614,20 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddTrueTypeFontText) { FPDFPage_InsertObject(page, text_object2); } ScopedFPDFBitmap page_bitmap2 = RenderPage(page); -#if defined(OS_MACOSX) - const char md5_2[] = "9a1a7dfebe659513691aadd0d95b8d50"; -#elif defined(OS_WIN) - const char md5_2[] = "2199b579c49ab5f80c246a586a80ee90"; +#if defined(OS_WIN) + const char kInsertTrueTypeChecksum[] = "2199b579c49ab5f80c246a586a80ee90"; +#elif defined(OS_MACOSX) + const char kInsertTrueTypeChecksum[] = "9a1a7dfebe659513691aadd0d95b8d50"; #else - const char md5_2[] = "c1d10cce1761c4a998a16b2562030568"; + const char kInsertTrueTypeChecksum[] = "c1d10cce1761c4a998a16b2562030568"; #endif - CompareBitmap(page_bitmap2.get(), 612, 792, md5_2); + CompareBitmap(page_bitmap2.get(), 612, 792, kInsertTrueTypeChecksum); EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); FPDF_ClosePage(page); - VerifySavedDocument(612, 792, md5_2); + VerifySavedDocument(612, 792, kInsertTrueTypeChecksum); } TEST_F(FPDFEditEmbedderTest, TransformAnnot) { @@ -2920,8 +2918,7 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddMarkedText) { FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f); EXPECT_TRUE(text_object); - ScopedFPDFWideString text1 = - GetFPDFWideString(L"I am testing my loaded font, WEE."); + ScopedFPDFWideString text1 = GetFPDFWideString(kLoadedFontText); EXPECT_TRUE(FPDFText_SetText(text_object, text1.get())); FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400); FPDFPage_InsertObject(page, text_object); @@ -2981,17 +2978,10 @@ TEST_F(FPDFEditEmbedderTest, MAYBE_AddMarkedText) { EXPECT_EQ(kBlobLen, out_buffer_len); EXPECT_EQ(0, memcmp(block_value, buffer, kBlobLen)); -// Render and check the bitmap is the expected one. -#if defined(OS_MACOSX) - const char md5[] = "fc921c0bbdde73986ac13c15a85db4c3"; -#elif defined(OS_WIN) - const char md5[] = "d60ba39f9698e32360d99e727dd93165"; -#else - const char md5[] = "70592859010ffbf532a2237b8118bcc4"; -#endif + // Render and check the bitmap is the expected one. { ScopedFPDFBitmap page_bitmap = RenderPage(page); - CompareBitmap(page_bitmap.get(), 612, 792, md5); + CompareBitmap(page_bitmap.get(), 612, 792, kLoadedFontTextChecksum); } // Now save the result. @@ -3481,3 +3471,24 @@ TEST_F(FPDFEditEmbedderTest, GetImageMetadata) { UnloadPage(page); } + +TEST_F(FPDFEditEmbedderTest, GetImageMetadataJpxLzw) { + ASSERT_TRUE(OpenDocument("jpx_lzw.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + + FPDF_IMAGEOBJ_METADATA metadata; + ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata)); + EXPECT_EQ(-1, metadata.marked_content_id); + EXPECT_EQ(612u, metadata.width); + EXPECT_EQ(792u, metadata.height); + EXPECT_FLOAT_EQ(72.0f, metadata.horizontal_dpi); + EXPECT_FLOAT_EQ(72.0f, metadata.vertical_dpi); + EXPECT_EQ(24u, metadata.bits_per_pixel); + EXPECT_EQ(FPDF_COLORSPACE_UNKNOWN, metadata.colorspace); + + UnloadPage(page); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg.cpp index 1e0e560cdf1..7637bf9e3c6 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg.cpp @@ -6,6 +6,7 @@ #include "public/fpdf_edit.h" +#include <memory> #include <utility> #include "core/fpdfapi/page/cpdf_dib.h" @@ -19,7 +20,6 @@ #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "fpdfsdk/cpdfsdk_customaccess.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" namespace { @@ -95,7 +95,7 @@ FPDFPageObj_NewImageObj(FPDF_DOCUMENT document) { if (!pDoc) return nullptr; - auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); + auto pImageObj = std::make_unique<CPDF_ImageObject>(); pImageObj->SetImage(pdfium::MakeRetain<CPDF_Image>(pDoc)); // Caller takes ownership. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg_unittest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg_embeddertest.cpp index 09ec71e0d02..60f6ed14b65 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg_unittest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_editimg_embeddertest.cpp @@ -4,15 +4,11 @@ #include "public/fpdf_edit.h" -#include "core/fpdfapi/page/cpdf_pagemodule.h" #include "public/cpp/fpdf_scopers.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "testing/embedder_test.h" #include "testing/utils/file_util.h" -class PDFEditImgTest : public testing::Test { - void SetUp() override { CPDF_PageModule::Create(); } - void TearDown() override { CPDF_PageModule::Destroy(); } -}; +class PDFEditImgTest : public EmbedderTest {}; TEST_F(PDFEditImgTest, InsertObjectWithInvalidPage) { FPDF_DOCUMENT doc = FPDF_CreateNewDocument(); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_editpage.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_editpage.cpp index 159015232f7..9c0a83aea3f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_editpage.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_editpage.cpp @@ -35,7 +35,6 @@ #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_formfill.h" #include "third_party/base/logging.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA @@ -150,9 +149,9 @@ const CPDF_PageObjectHolder* CPDFPageObjHolderFromFPDFFormObject( } // namespace FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { - auto pDoc = pdfium::MakeUnique<CPDF_Document>( - pdfium::MakeUnique<CPDF_DocRenderData>(), - pdfium::MakeUnique<CPDF_DocPageData>()); + auto pDoc = + std::make_unique<CPDF_Document>(std::make_unique<CPDF_DocRenderData>(), + std::make_unique<CPDF_DocPageData>()); pDoc->CreateNewDoc(); time_t currentTime; @@ -176,7 +175,7 @@ FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { } #ifdef PDF_ENABLE_XFA - pDoc->SetExtension(pdfium::MakeUnique<CPDFXFA_Context>(pDoc.get())); + pDoc->SetExtension(std::make_unique<CPDFXFA_Context>(pDoc.get())); #endif // PDF_ENABLE_XFA // Caller takes ownership of pDoc. @@ -225,7 +224,7 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, #endif // PDF_ENABLE_XFA auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pPageDict); - pPage->SetRenderCache(pdfium::MakeUnique<CPDF_PageRenderCache>(pPage.Get())); + pPage->SetRenderCache(std::make_unique<CPDF_PageRenderCache>(pPage.Get())); pPage->ParseContent(); return FPDFPageFromIPDFPage(pPage.Leak()); // Caller takes ownership. @@ -346,11 +345,10 @@ FPDFPageObjMark_GetName(FPDF_PAGEOBJECTMARK mark, void* buffer, unsigned long buflen, unsigned long* out_buflen) { - if (!mark || !out_buflen) - return false; - const CPDF_ContentMarkItem* pMarkItem = CPDFContentMarkItemFromFPDFPageObjectMark(mark); + if (!pMarkItem || !out_buflen) + return false; *out_buflen = Utf16EncodeMaybeCopyAndReturnLength( WideString::FromUTF8(pMarkItem->GetName().AsStringView()), buffer, @@ -360,11 +358,10 @@ FPDFPageObjMark_GetName(FPDF_PAGEOBJECTMARK mark, FPDF_EXPORT int FPDF_CALLCONV FPDFPageObjMark_CountParams(FPDF_PAGEOBJECTMARK mark) { - if (!mark) - return -1; - const CPDF_ContentMarkItem* pMarkItem = CPDFContentMarkItemFromFPDFPageObjectMark(mark); + if (!pMarkItem) + return -1; const CPDF_Dictionary* pParams = pMarkItem->GetParam(); return pParams ? pParams->size() : 0; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_editpath.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_editpath.cpp index 18c3477438d..7e3048be506 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_editpath.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_editpath.cpp @@ -4,14 +4,13 @@ #include "public/fpdf_edit.h" +#include <memory> #include <utility> -#include <vector> #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fxcrt/fx_system.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/span.h" #include "third_party/base/stl_util.h" @@ -49,7 +48,7 @@ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x, float y) { - auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); + auto pPathObj = std::make_unique<CPDF_PathObject>(); pPathObj->path().AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo); pPathObj->DefaultStates(); @@ -61,7 +60,7 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x, float y, float w, float h) { - auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>(); + auto pPathObj = std::make_unique<CPDF_PathObject>(); pPathObj->path().AppendRect(x, y, x + w, y + h); pPathObj->DefaultStates(); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_edittext.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_edittext.cpp index 3dc4334ee13..91833d979fd 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_edittext.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_edittext.cpp @@ -28,7 +28,6 @@ #include "core/fxge/fx_font.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_edit.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" // These checks are here because core/ and public/ cannot depend on each other. @@ -367,7 +366,7 @@ RetainPtr<CPDF_Font> LoadCompositeFont(CPDF_Document* pDoc, if (dwCurrentChar > kMaxUnicode) break; - if (!pdfium::ContainsKey(widths, dwGlyphIndex)) + if (!pdfium::Contains(widths, dwGlyphIndex)) widths[dwGlyphIndex] = pFont->GetGlyphWidth(dwGlyphIndex); to_unicode[dwGlyphIndex] = dwCurrentChar; dwCurrentChar = @@ -456,7 +455,7 @@ FPDFPageObj_NewTextObj(FPDF_DOCUMENT document, if (!pFont) return nullptr; - auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>(); + auto pTextObj = std::make_unique<CPDF_TextObject>(); pTextObj->m_TextState.SetFont(pFont); pTextObj->m_TextState.SetFontSize(font_size); pTextObj->DefaultStates(); @@ -493,7 +492,7 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFText_LoadFont(FPDF_DOCUMENT document, } auto span = pdfium::make_span(data, size); - auto pFont = pdfium::MakeUnique<CFX_Font>(); + auto pFont = std::make_unique<CFX_Font>(); // TODO(npm): Maybe use FT_Get_X11_Font_Format to check format? Otherwise, we // are allowing giving any font that can be loaded on freetype and setting it @@ -585,7 +584,7 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document, if (!pDoc || !pFont) return nullptr; - auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>(); + auto pTextObj = std::make_unique<CPDF_TextObject>(); pTextObj->m_TextState.SetFont( CPDF_DocPageData::FromDocument(pDoc)->GetFont(pFont->GetFontDict())); pTextObj->m_TextState.SetFontSize(font_size); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_ext.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_ext.cpp index dc928f6285b..37e123c8f1f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_ext.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_ext.cpp @@ -12,7 +12,6 @@ #include "core/fpdfdoc/cpdf_metadata.h" #include "core/fxcrt/fx_extension.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" static_assert(static_cast<int>(UnsupportedFeature::kDocumentXFAForm) == FPDF_UNSP_DOC_XFAFORM, diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill.cpp index 65a5d4eb8c4..bbfc64b4bda 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill.cpp @@ -8,7 +8,6 @@ #include <memory> #include <utility> -#include <vector> #include "core/fpdfapi/page/cpdf_annotcontext.h" #include "core/fpdfapi/page/cpdf_occontext.h" @@ -29,7 +28,6 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widgethandler.h" #include "public/fpdfview.h" -#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" @@ -196,7 +194,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y); CFX_Matrix matrix = pPage->GetDisplayMatrix(rect, rotate); - auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); + auto pDevice = std::make_unique<CFX_DefaultRenderDevice>(); #ifdef _SKIA_SUPPORT_ pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder)); #endif @@ -313,7 +311,7 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, CPDFXFA_Context* pContext = nullptr; if (!formInfo->xfa_disabled) { if (!pDocument->GetExtension()) { - pDocument->SetExtension(pdfium::MakeUnique<CPDFXFA_Context>(pDocument)); + pDocument->SetExtension(std::make_unique<CPDFXFA_Context>(pDocument)); } // If the CPDFXFA_Context has a FormFillEnvironment already then we've done @@ -324,15 +322,15 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, return FPDFFormHandleFromCPDFSDKFormFillEnvironment( pContext->GetFormFillEnv()); } - pXFAHandler = pdfium::MakeUnique<CPDFXFA_WidgetHandler>(); + pXFAHandler = std::make_unique<CPDFXFA_WidgetHandler>(); } #endif // PDF_ENABLE_XFA - auto pFormFillEnv = pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>( + auto pFormFillEnv = std::make_unique<CPDFSDK_FormFillEnvironment>( pDocument, formInfo, - pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>( - pdfium::MakeUnique<CPDFSDK_BAAnnotHandler>(), - pdfium::MakeUnique<CPDFSDK_WidgetHandler>(), std::move(pXFAHandler))); + std::make_unique<CPDFSDK_AnnotHandlerMgr>( + std::make_unique<CPDFSDK_BAAnnotHandler>(), + std::make_unique<CPDFSDK_WidgetHandler>(), std::move(pXFAHandler))); #ifdef PDF_ENABLE_XFA if (pContext) @@ -546,6 +544,12 @@ FPDF_EXPORT void FPDF_CALLCONV FORM_ReplaceSelection(FPDF_FORMHANDLE hHandle, pPageView->ReplaceSelection(WideStringFromFPDFWideString(wsText)); } +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_SelectAllText(FPDF_FORMHANDLE hHandle, + FPDF_PAGE page) { + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + return pPageView && pPageView->SelectAllText(); +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_CanUndo(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) { CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); @@ -621,7 +625,7 @@ FORM_GetFocusedAnnot(FPDF_FORMHANDLE handle, return true; CPDF_Dictionary* annot_dict = cpdfsdk_annot->GetPDFAnnot()->GetAnnotDict(); - auto annot_context = pdfium::MakeUnique<CPDF_AnnotContext>(annot_dict, page); + auto annot_context = std::make_unique<CPDF_AnnotContext>(annot_dict, page); *page_index = page_view->GetPageIndex(); // Caller takes ownership. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill_embeddertest.cpp index 174e9c10563..3eaadeef84f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_formfill_embeddertest.cpp @@ -3,12 +3,10 @@ // found in the LICENSE file. #include <memory> -#include <string> #include <vector> #include "build/build_config.h" #include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "public/cpp/fpdf_scopers.h" @@ -21,6 +19,7 @@ #include "testing/embedder_test_timer_handling_delegate.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/base/stl_util.h" using testing::_; using testing::InSequence; @@ -135,6 +134,11 @@ class FPDFFormFillInteractiveEmbedderTest : public FPDFFormFillEmbedderTest { FORM_OnLButtonUp(form_handle(), page_, 0, end.x, end.y); } + void SelectAllTextAtPoint(const CFX_PointF& point) { + FocusOnPoint(point); + EXPECT_TRUE(FORM_SelectAllText(form_handle(), page_)); + } + void CheckSelection(WideStringView expected_string) { unsigned long actual_len = FORM_GetSelectedText(form_handle(), page_, nullptr, 0); @@ -149,6 +153,10 @@ class FPDFFormFillInteractiveEmbedderTest : public FPDFFormFillEmbedderTest { EXPECT_EQ(expected_string, WideString::FromUTF16LE(buf.data(), num_chars)); } + void FocusOnPoint(const CFX_PointF& point) { + EXPECT_TRUE(FORM_OnFocus(form_handle(), page(), 0, point.x, point.y)); + } + void CheckFocusedFieldText(WideStringView expected_string) { unsigned long actual_len = FORM_GetFocusedText(form_handle(), page_, nullptr, 0); @@ -215,11 +223,11 @@ class FPDFFormFillTextFormEmbedderTest } void SelectAllCharLimitFormTextWithMouse() { - SelectTextWithMouse(CharLimitFormEnd(), CharLimitFormBegin()); + SelectAllTextAtPoint(CharLimitFormBegin()); } void SelectAllRegularFormTextWithMouse() { - SelectTextWithMouse(RegularFormEnd(), RegularFormBegin()); + SelectAllTextAtPoint(RegularFormBegin()); } const CFX_PointF& CharLimitFormBegin() const { @@ -299,17 +307,13 @@ class FPDFFormFillComboBoxFormEmbedderTest } void SelectAllEditableFormTextWithMouse() { - SelectTextWithMouse(EditableFormEnd(), EditableFormBegin()); + SelectAllTextAtPoint(EditableFormBegin()); } void FocusOnEditableForm() { FocusOnPoint(EditableFormDropDown()); } void FocusOnNonEditableForm() { FocusOnPoint(NonEditableFormDropDown()); } - void FocusOnPoint(const CFX_PointF& point) { - EXPECT_EQ(true, FORM_OnFocus(form_handle(), page(), 0, point.x, point.y)); - } - const CFX_PointF& EditableFormBegin() const { static const CFX_PointF point = EditableFormAtX(kFormBeginX); return point; @@ -841,7 +845,7 @@ TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousTab) { static constexpr int kExpectedAnnotIndex[] = {1, 2, 3, 0}; // Tabs should iterate focus over annotations. - for (size_t i = 0; i < FX_ArraySize(kExpectedAnnotIndex); ++i) { + for (size_t i = 0; i < pdfium::size(kExpectedAnnotIndex); ++i) { ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0)); int page_index = -2; FPDF_ANNOTATION annot = nullptr; @@ -865,7 +869,7 @@ TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousShiftTab) { static constexpr int kExpectedAnnotIndex[] = {0, 3, 2, 1}; // Shift-tabs should iterate focus over annotations. - for (size_t i = 0; i < FX_ArraySize(kExpectedAnnotIndex); ++i) { + for (size_t i = 0; i < pdfium::size(kExpectedAnnotIndex); ++i) { ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, FWL_EVENTFLAG_ShiftKey)); int page_index = -2; @@ -1021,6 +1025,75 @@ TEST_F(FPDFFormFillEmbedderTest, BUG_851821) { UnloadPage(page); } +TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInCheckbox) { + EmbedderTestTimerHandlingDelegate delegate; + SetDelegate(&delegate); + + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + // Check for read-only checkbox. + ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1)); + ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get())); + + // Shift-tab to the previous control. + ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, + FWL_EVENTFLAG_ShiftKey)); + FPDF_ANNOTATION annot = nullptr; + int page_index = -1; + ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot)); + EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot)); + + // The read-only checkbox is initially in checked state. + EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot)); + + EXPECT_TRUE(FORM_OnChar(form_handle(), page, FWL_VKEY_Return, 0)); + EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot)); + + EXPECT_TRUE(FORM_OnChar(form_handle(), page, FWL_VKEY_Space, 0)); + EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot)); + + FPDFPage_CloseAnnot(annot); + } + UnloadPage(page); +} + +TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInRadiobutton) { + EmbedderTestTimerHandlingDelegate delegate; + SetDelegate(&delegate); + + ASSERT_TRUE(OpenDocument("click_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + { + // Check for read-only radio button. + ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1)); + ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get())); + + // Tab to the next control. + ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0)); + + FPDF_ANNOTATION annot = nullptr; + int page_index = -1; + ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot)); + EXPECT_EQ(2, FPDFPage_GetAnnotIndex(page, annot)); + // The read-only radio button is initially in checked state. + EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot)); + + EXPECT_TRUE(FORM_OnChar(form_handle(), page, FWL_VKEY_Return, 0)); + EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot)); + + EXPECT_TRUE(FORM_OnChar(form_handle(), page, FWL_VKEY_Space, 0)); + EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot)); + + FPDFPage_CloseAnnot(annot); + } + UnloadPage(page); +} + #ifdef PDF_ENABLE_V8 TEST_F(FPDFFormFillEmbedderTest, DisableJavaScript) { // Test that timers and intervals can't fire without JS. @@ -1464,6 +1537,44 @@ TEST_F(FPDFFormFillEmbedderTest, HasFormFieldAtPointForXFADoc) { UnloadPage(page); } +TEST_F(FPDFFormFillEmbedderTest, SelectAllText) { + ASSERT_TRUE(OpenDocument("text_form.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Test bad arguments. + EXPECT_FALSE(FORM_SelectAllText(nullptr, nullptr)); + EXPECT_FALSE(FORM_SelectAllText(form_handle(), nullptr)); + EXPECT_FALSE(FORM_SelectAllText(nullptr, page)); + + // Focus on the text field and add some text. + EXPECT_TRUE(FORM_OnFocus(form_handle(), page, 0, 115, 115)); + ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello"); + FORM_ReplaceSelection(form_handle(), page, text_to_insert.get()); + + // Sanity check text field data. + uint16_t buffer[6]; + ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page, nullptr, 0)); + ASSERT_EQ(12u, + FORM_GetFocusedText(form_handle(), page, buffer, sizeof(buffer))); + EXPECT_EQ("Hello", GetPlatformString(buffer)); + + // Check there is no selection. + ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page, nullptr, 0)); + ASSERT_EQ(2u, + FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer))); + EXPECT_EQ("", GetPlatformString(buffer)); + + // Check FORM_SelectAllText() works. + EXPECT_TRUE(FORM_SelectAllText(form_handle(), page)); + ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page, nullptr, 0)); + ASSERT_EQ(12u, + FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer))); + EXPECT_EQ("Hello", GetPlatformString(buffer)); + + UnloadPage(page); +} + TEST_F(FPDFFormFillTextFormEmbedderTest, GetSelectedTextEmptyAndBasicKeyboard) { // Test empty selection. CheckFocusedFieldText(L""); @@ -2240,6 +2351,81 @@ TEST_F(FPDFFormFillComboBoxFormEmbedderTest, CheckSelection(L"ABCDEHello"); } +TEST_F(FPDFFormFillComboBoxFormEmbedderTest, + CheckIfEnterAndSpaceKeyAreHandled) { + // Non-editable field is set to 'Banana' (index 1) upon opening. + ClickOnFormFieldAtPoint(NonEditableFormBegin()); + CheckIsIndexSelected(0, false); + CheckIsIndexSelected(1, true); + + // Verify that the Enter key is handled. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Return, 0)); + + // Change the selection in the combo-box using the arrow down key. + EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0)); + CheckIsIndexSelected(1, false); + CheckIsIndexSelected(2, true); + + // Tab to the next control. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, 0)); + + // Shift-tab to the previous control. + EXPECT_TRUE( + FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, FWL_EVENTFLAG_ShiftKey)); + + // Verify that the selection is unchanged. + CheckIsIndexSelected(2, true); + + // Verify that the Space key is handled. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Space, 0)); + + // Change the selection in the combo-box using the arrow down key. + EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0)); + CheckIsIndexSelected(3, true); + + // Tab to the next control. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, 0)); + + // Shift-tab to the previous control. + EXPECT_TRUE( + FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, FWL_EVENTFLAG_ShiftKey)); + + // Verify that the selection is unchanged. + CheckIsIndexSelected(3, true); +} + +TEST_F(FPDFFormFillComboBoxFormEmbedderTest, + CheckIfEnterAndSpaceKeyAreHandledOnEditableFormField) { + // Non-editable field is set to 'Banana' (index 1) upon opening. + ClickOnFormFieldAtPoint(EditableFormBegin()); + CheckIsIndexSelected(0, false); + CheckIsIndexSelected(1, false); + + // Verify that the Enter key is handled. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Return, 0)); + + // Change the selection in the combo-box using the arrow down key. + EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0)); + CheckIsIndexSelected(0, true); + CheckIsIndexSelected(1, false); + + // Tab to the next control. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, 0)); + + // Shift-tab to the previous control. + EXPECT_TRUE( + FORM_OnChar(form_handle(), page(), FWL_VKEY_Tab, FWL_EVENTFLAG_ShiftKey)); + + // Verify that the selection is unchanged. + CheckIsIndexSelected(0, true); + + // Verify that the Space key is handled. + EXPECT_TRUE(FORM_OnChar(form_handle(), page(), FWL_VKEY_Space, 0)); + + CheckFocusedFieldText(L" "); + CheckIsIndexSelected(0, false); +} + TEST_F(FPDFFormFillTextFormEmbedderTest, InsertTextInEmptyCharLimitTextFieldOverflow) { // Click on the textfield. @@ -2998,7 +3184,7 @@ class FPDFFormFillActionUriTest : public EmbedderTest { // Set Widget and Link as supported tabbable annots. constexpr FPDF_ANNOTATION_SUBTYPE kFocusableSubtypes[] = {FPDF_ANNOT_WIDGET, FPDF_ANNOT_LINK}; - constexpr size_t kSubtypeCount = FX_ArraySize(kFocusableSubtypes); + constexpr size_t kSubtypeCount = pdfium::size(kFocusableSubtypes); ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes( form_handle(), kFocusableSubtypes, kSubtypeCount)); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript.cpp index ebe80080ae4..0aaae81637e 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript.cpp @@ -11,7 +11,6 @@ #include "core/fpdfdoc/cpdf_action.h" #include "core/fpdfdoc/cpdf_nametree.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" struct CPDF_JavaScript { WideString name; @@ -53,7 +52,7 @@ FPDFDoc_GetJavaScriptAction(FPDF_DOCUMENT document, int index) { if (!script.has_value()) return nullptr; - auto js = pdfium::MakeUnique<CPDF_JavaScript>(); + auto js = std::make_unique<CPDF_JavaScript>(); js->name = name; js->script = script.value(); return FPDFJavaScriptActionFromCPDFJavaScriptAction(js.release()); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript_embeddertest.cpp index 35deb69799b..8ffc2d9ab35 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_javascript_embeddertest.cpp @@ -3,7 +3,6 @@ // found in the LICENSE file. #include <memory> -#include <string> #include <vector> #include "core/fxcrt/fx_memory.h" diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo.cpp index 819ba05c5a8..43a45e2484a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo.cpp @@ -31,7 +31,6 @@ #include "core/fxcrt/unowned_ptr.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_scopers.h" -#include "third_party/base/ptr_util.h" namespace { @@ -623,7 +622,7 @@ bool CPDF_NPageToOneExporter::ExportNPagesToOne( auto pSrcPage = pdfium::MakeRetain<CPDF_Page>(src(), pSrcPageDict); pSrcPage->SetRenderCache( - pdfium::MakeUnique<CPDF_PageRenderCache>(pSrcPage.Get())); + std::make_unique<CPDF_PageRenderCache>(pSrcPage.Get())); NupPageSettings settings = nupState.CalculateNewPagePosition(pSrcPage->GetPageSize()); bsContent += AddSubPage(pSrcPageDict, settings); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo_embeddertest.cpp index 56846801655..9fd2114d9bb 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_ppo_embeddertest.cpp @@ -99,17 +99,16 @@ TEST_F(FPDFPPOEmbedderTest, BadNupParams) { // TODO(Xlou): Add more tests to check output doc content of // FPDF_ImportNPagesToOne() -// TODO(crbug.com/pdfium/11): Fix this test and enable. -#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) -#define MAYBE_NupRenderImage DISABLED_NupRenderImage -#else -#define MAYBE_NupRenderImage NupRenderImage -#endif -TEST_F(FPDFPPOEmbedderTest, MAYBE_NupRenderImage) { +TEST_F(FPDFPPOEmbedderTest, NupRenderImage) { ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf")); const int kPageCount = 2; +#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) + static constexpr const char* kExpectedMD5s[kPageCount] = { + "bf8fa88dc85a9897931273168e8e1a30", "4fa6a7507e9f3ef4f28719a7d656c3a5"}; +#else static constexpr const char* kExpectedMD5s[kPageCount] = { "4d225b961da0f1bced7c83273e64c9b6", "fb18142190d770cfbc329d2b071aee4d"}; +#endif ScopedFPDFDocument output_doc_3up( FPDF_ImportNPagesToOne(document(), 792, 612, 3, 1)); ASSERT_TRUE(output_doc_3up); @@ -220,16 +219,16 @@ TEST_F(FPDFPPOEmbedderTest, BUG_664284) { UnloadPage(page); } -// TODO(crbug.com/pdfium/11): Fix this test and enable. +TEST_F(FPDFPPOEmbedderTest, BUG_750568) { #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) -#define MAYBE_BUG_750568 DISABLED_BUG_750568 + const char* const kHashes[] = { + "eaa139e944eafb43d31e8742a0e158de", "226485e9d4fa6a67dfe0a88723f12060", + "c5601a3492ae5dcc5dd25140fc463bfe", "1f60055b54de4fac8a59c65e90da156e"}; #else -#define MAYBE_BUG_750568 BUG_750568 -#endif -TEST_F(FPDFPPOEmbedderTest, MAYBE_BUG_750568) { const char* const kHashes[] = { "64ad08132a1c5a166768298c8a578f57", "83b83e2f6bc80707d0a917c7634140b9", "913cd3723a451e4e46fbc2c05702d1ee", "81fb7cfd4860f855eb468f73dfeb6d60"}; +#endif ASSERT_TRUE(OpenDocument("bug_750568.pdf")); ASSERT_EQ(4, FPDF_GetPageCount(document())); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp index 7221b27a6d9..4ccc738b64b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_progressive.cpp @@ -6,6 +6,7 @@ #include "public/fpdf_progressive.h" +#include <memory> #include <utility> #include "core/fpdfapi/page/cpdf_page.h" @@ -16,7 +17,6 @@ #include "fpdfsdk/cpdfsdk_pauseadapter.h" #include "fpdfsdk/cpdfsdk_renderpage.h" #include "public/fpdfview.h" -#include "third_party/base/ptr_util.h" #ifdef _SKIA_SUPPORT_PATHS_ #include "core/fxge/cfx_renderdevice.h" @@ -59,12 +59,12 @@ FPDF_RenderPageBitmapWithColorScheme_Start(FPDF_BITMAP bitmap, if (!pPage) return FPDF_RENDER_FAILED; - auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + auto pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* pContext = pOwnedContext.get(); pPage->SetRenderContext(std::move(pOwnedContext)); RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap)); - auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); + auto pOwnedDevice = std::make_unique<CFX_DefaultRenderDevice>(); CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get(); pContext->m_pDevice = std::move(pOwnedDevice); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp index f44fdd1f30d..8a8c65fe0c9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_structtree_embeddertest.cpp @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_string.h" #include "public/fpdf_structtree.h" #include "testing/embedder_test.h" #include "third_party/base/optional.h" +#include "third_party/base/stl_util.h" class FPDFStructTreeEmbedderTest : public EmbedderTest {}; @@ -57,7 +57,7 @@ TEST_F(FPDFStructTreeEmbedderTest, GetAltText) { // Deliberately pass in a small buffer size to make sure |buffer| remains // untouched. ASSERT_EQ(24U, FPDF_StructElement_GetAltText(gchild_element, buffer, 1)); - for (size_t i = 0; i < FX_ArraySize(buffer); ++i) + for (size_t i = 0; i < pdfium::size(buffer); ++i) EXPECT_EQ(0U, buffer[i]); EXPECT_EQ(-1, FPDF_StructElement_GetMarkedContentID(gchild_element)); @@ -118,7 +118,7 @@ TEST_F(FPDFStructTreeEmbedderTest, GetType) { // Deliberately pass in a small buffer size to make sure |buffer| remains // untouched. ASSERT_EQ(18U, FPDF_StructElement_GetType(element, buffer, 1)); - for (size_t i = 0; i < FX_ArraySize(buffer); ++i) + for (size_t i = 0; i < pdfium::size(buffer); ++i) EXPECT_EQ(0U, buffer[i]); ASSERT_EQ(18U, FPDF_StructElement_GetType(element, buffer, sizeof(buffer))); @@ -154,7 +154,7 @@ TEST_F(FPDFStructTreeEmbedderTest, GetTitle) { // Deliberately pass in a small buffer size to make sure |buffer| remains // untouched. ASSERT_EQ(20U, FPDF_StructElement_GetTitle(element, buffer, 1)); - for (size_t i = 0; i < FX_ArraySize(buffer); ++i) + for (size_t i = 0; i < pdfium::size(buffer); ++i) EXPECT_EQ(0U, buffer[i]); ASSERT_EQ(20U, diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp index 96ceef23a20..0b5c8e6716f 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo.cpp @@ -17,7 +17,6 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/fx_font.h" #include "core/fxge/systemfontinfo_iface.h" -#include "third_party/base/ptr_util.h" static_assert(FXFONT_ANSI_CHARSET == FX_CHARSET_ANSI, "Charset must match"); static_assert(FXFONT_DEFAULT_CHARSET == FX_CHARSET_Default, @@ -134,7 +133,7 @@ FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) { return; CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( - pdfium::MakeUnique<CFX_ExternalFontInfo>(pFontInfoExt)); + std::make_unique<CFX_ExternalFontInfo>(pFontInfoExt)); } FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap() { diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp index a1c151089e4..e67ec559902 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp @@ -142,7 +142,7 @@ TEST_F(FPDFSysFontInfoEmbedderTest, DefaultTTFMap) { // Stop at either end mark. while (cfmap->charset != -1 && cfmap->fontname) { // Only returns values described as legitimate in public header. - EXPECT_TRUE(pdfium::ContainsValue(kAllowedCharsets, cfmap->charset)) + EXPECT_TRUE(pdfium::Contains(kAllowedCharsets, cfmap->charset)) << " for " << cfmap->charset; // Duplicates are not allowed. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_text.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_text.cpp index 5edbf27c2a8..5b5ca935cc0 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_text.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_text.cpp @@ -21,7 +21,6 @@ #include "core/fpdftext/cpdf_textpagefind.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/numerics/safe_conversions.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #if defined(OS_WIN) @@ -49,7 +48,7 @@ FPDF_EXPORT FPDF_TEXTPAGE FPDF_CALLCONV FPDFText_LoadPage(FPDF_PAGE page) { CPDF_ViewerPreferences viewRef(pPDFPage->GetDocument()); auto textpage = - pdfium::MakeUnique<CPDF_TextPage>(pPDFPage, viewRef.IsDirectionR2L()); + std::make_unique<CPDF_TextPage>(pPDFPage, viewRef.IsDirectionR2L()); // Caller takes ownership. return FPDFTextPageFromCPDFTextPage(textpage.release()); @@ -490,7 +489,7 @@ FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { return nullptr; CPDF_TextPage* pPage = CPDFTextPageFromFPDFTextPage(text_page); - auto pageLink = pdfium::MakeUnique<CPDF_LinkExtract>(pPage); + auto pageLink = std::make_unique<CPDF_LinkExtract>(pPage); pageLink->ExtractLinks(); // Caller takes ownership. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_text_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_text_embeddertest.cpp index 77f015ab849..ce9c62272b9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_text_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_text_embeddertest.cpp @@ -8,7 +8,6 @@ #include <vector> #include "build/build_config.h" -#include "core/fxcrt/fx_memory.h" #include "core/fxge/fx_font.h" #include "public/cpp/fpdf_scopers.h" #include "public/fpdf_text.h" @@ -17,11 +16,12 @@ #include "testing/embedder_test.h" #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/base/stl_util.h" namespace { constexpr char kHelloGoodbyeText[] = "Hello, world!\r\nGoodbye, world!"; -constexpr int kHelloGoodbyeTextSize = FX_ArraySize(kHelloGoodbyeText); +constexpr int kHelloGoodbyeTextSize = pdfium::size(kHelloGoodbyeText); bool check_unsigned_shorts(const char* expected, const unsigned short* actual, @@ -676,7 +676,7 @@ TEST_F(FPDFTextEmbedderTest, WebLinksAcrossLines) { "http://example.com/", "http://www.abc.com", }; - static const int kNumLinks = static_cast<int>(FX_ArraySize(kExpectedUrls)); + static const int kNumLinks = static_cast<int>(pdfium::size(kExpectedUrls)); EXPECT_EQ(kNumLinks, FPDFLink_CountWebLinks(pagelink)); @@ -687,7 +687,7 @@ TEST_F(FPDFTextEmbedderTest, WebLinksAcrossLines) { EXPECT_EQ(static_cast<int>(expected_len), FPDFLink_GetURL(pagelink, i, nullptr, 0)); EXPECT_EQ(static_cast<int>(expected_len), - FPDFLink_GetURL(pagelink, i, buffer, FX_ArraySize(buffer))); + FPDFLink_GetURL(pagelink, i, buffer, pdfium::size(buffer))); EXPECT_TRUE(check_unsigned_shorts(kExpectedUrls[i], buffer, expected_len)); } @@ -715,7 +715,7 @@ TEST_F(FPDFTextEmbedderTest, WebLinksAcrossLinesBug) { EXPECT_EQ(kUrlSize, FPDFLink_GetURL(pagelink, 1, nullptr, 0)); EXPECT_EQ(kUrlSize, - FPDFLink_GetURL(pagelink, 1, buffer, FX_ArraySize(buffer))); + FPDFLink_GetURL(pagelink, 1, buffer, pdfium::size(buffer))); EXPECT_TRUE(check_unsigned_shorts(kExpectedUrl, buffer, kUrlSize)); FPDFLink_CloseWebLinks(pagelink); @@ -849,7 +849,7 @@ TEST_F(FPDFTextEmbedderTest, GetFontSize) { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; int count = FPDFText_CountChars(textpage); - ASSERT_EQ(FX_ArraySize(kExpectedFontsSizes), static_cast<size_t>(count)); + ASSERT_EQ(pdfium::size(kExpectedFontsSizes), static_cast<size_t>(count)); for (int i = 0; i < count; ++i) EXPECT_EQ(kExpectedFontsSizes[i], FPDFText_GetFontSize(textpage, i)) << i; @@ -968,18 +968,18 @@ TEST_F(FPDFTextEmbedderTest, Bug_921) { static constexpr int kStartIndex = 238; ASSERT_EQ(268, FPDFText_CountChars(textpage)); - for (size_t i = 0; i < FX_ArraySize(kData); ++i) + for (size_t i = 0; i < pdfium::size(kData); ++i) EXPECT_EQ(kData[i], FPDFText_GetUnicode(textpage, kStartIndex + i)); - unsigned short buffer[FX_ArraySize(kData) + 1]; + unsigned short buffer[pdfium::size(kData) + 1]; memset(buffer, 0xbd, sizeof(buffer)); int count = - FPDFText_GetText(textpage, kStartIndex, FX_ArraySize(kData), buffer); + FPDFText_GetText(textpage, kStartIndex, pdfium::size(kData), buffer); ASSERT_GT(count, 0); - ASSERT_EQ(FX_ArraySize(kData) + 1, static_cast<size_t>(count)); - for (size_t i = 0; i < FX_ArraySize(kData); ++i) + ASSERT_EQ(pdfium::size(kData) + 1, static_cast<size_t>(count)); + for (size_t i = 0; i < pdfium::size(kData); ++i) EXPECT_EQ(kData[i], buffer[i]); - EXPECT_EQ(0, buffer[FX_ArraySize(kData)]); + EXPECT_EQ(0, buffer[pdfium::size(kData)]); FPDFText_ClosePage(textpage); UnloadPage(page); @@ -1001,8 +1001,8 @@ TEST_F(FPDFTextEmbedderTest, GetTextWithHyphen) { 0x0056, 0x0065, 0x0072, 0x0069, 0x0074, 0x0061, 0xfffe, 0x0073, 0x0065, 0x0072, 0x0075, 0x006D, 0x0000}; { - constexpr int count = FX_ArraySize(soft_expected) - 1; - unsigned short buffer[FX_ArraySize(soft_expected)]; + constexpr int count = pdfium::size(soft_expected) - 1; + unsigned short buffer[pdfium::size(soft_expected)]; memset(buffer, 0, sizeof(buffer)); EXPECT_EQ(count + 1, FPDFText_GetText(textpage, 0, count, buffer)); @@ -1014,14 +1014,14 @@ TEST_F(FPDFTextEmbedderTest, GetTextWithHyphen) { { // There isn't the \0 in the actual doc, but there is a \r\n, so need to // add 1 to get aligned. - constexpr size_t offset = FX_ArraySize(soft_expected) + 1; + constexpr size_t offset = pdfium::size(soft_expected) + 1; // Expecting 'User-\r\ngenerated', the - is a unicode character, so cannnot // store in a char[]. constexpr unsigned short hard_expected[] = { 0x0055, 0x0073, 0x0065, 0x0072, 0x2010, 0x000d, 0x000a, 0x0067, 0x0065, 0x006e, 0x0065, 0x0072, 0x0061, 0x0074, 0x0065, 0x0064, 0x0000}; - constexpr int count = FX_ArraySize(hard_expected) - 1; - unsigned short buffer[FX_ArraySize(hard_expected)]; + constexpr int count = pdfium::size(hard_expected) - 1; + unsigned short buffer[pdfium::size(hard_expected)]; EXPECT_EQ(count + 1, FPDFText_GetText(textpage, offset, count, buffer)); for (int i = 0; i < count; i++) @@ -1103,7 +1103,7 @@ TEST_F(FPDFTextEmbedderTest, bug_1029) { 0x0061, 0x0073, 0x0020, 0x0063, 0x006f, 0x006d, 0x006d, 0x0069, 0x0074, 0x0074, 0x0065, 0x0064, 0x002c, 0x0020, 0x0069, 0x0074, 0x0020, 0x006e, 0x006f, 0x0074, 0x0069, 0x0002, 0x0066, 0x0069}; - static_assert(page_range_length == FX_ArraySize(expected), + static_assert(page_range_length == pdfium::size(expected), "Expected should be the same size as the range being " "extracted from page."); EXPECT_LT(page_range_offset + page_range_length, @@ -1205,7 +1205,7 @@ TEST_F(FPDFTextEmbedderTest, GetText) { // Positive testing. constexpr char kHelloText[] = "Hello, world!"; // Return value includes the terminating NUL that is provided. - constexpr unsigned long kHelloUTF16Size = FX_ArraySize(kHelloText) * 2; + constexpr unsigned long kHelloUTF16Size = pdfium::size(kHelloText) * 2; constexpr wchar_t kHelloWideText[] = L"Hello, world!"; unsigned long size = FPDFTextObj_GetText(text_object, text_page, nullptr, 0); ASSERT_EQ(kHelloUTF16Size, size); @@ -1323,14 +1323,14 @@ TEST_F(FPDFTextEmbedderTest, Bug_642) { ASSERT_TRUE(text_page); constexpr char kText[] = "ABCD"; - constexpr size_t kTextSize = FX_ArraySize(kText); + constexpr size_t kTextSize = pdfium::size(kText); // -1 for CountChars not including the \0 EXPECT_EQ(static_cast<int>(kTextSize) - 1, FPDFText_CountChars(text_page.get())); unsigned short buffer[kTextSize]; int num_chars = - FPDFText_GetText(text_page.get(), 0, FX_ArraySize(buffer) - 1, buffer); + FPDFText_GetText(text_page.get(), 0, pdfium::size(buffer) - 1, buffer); ASSERT_EQ(static_cast<int>(kTextSize), num_chars); EXPECT_TRUE(check_unsigned_shorts(kText, buffer, kTextSize)); } @@ -1346,9 +1346,9 @@ TEST_F(FPDFTextEmbedderTest, GetCharAngle) { FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); ASSERT_TRUE(text_page); - static constexpr int kSubstringsSize[] = {FX_ArraySize("Hello,"), - FX_ArraySize(" world!\r\n"), - FX_ArraySize("Goodbye,")}; + static constexpr int kSubstringsSize[] = {pdfium::size("Hello,"), + pdfium::size(" world!\r\n"), + pdfium::size("Goodbye,")}; // -1 for CountChars not including the \0, but +1 for the extra control // character. @@ -1498,7 +1498,7 @@ TEST_F(FPDFTextEmbedderTest, GetStrokeColor) { TEST_F(FPDFTextEmbedderTest, GetMatrix) { constexpr char kExpectedText[] = "A1\r\nA2\r\nA3"; - constexpr size_t kExpectedTextSize = FX_ArraySize(kExpectedText); + constexpr size_t kExpectedTextSize = pdfium::size(kExpectedText); constexpr FS_MATRIX kExpectedMatrices[] = { {12.0f, 0.0f, 0.0f, 10.0f, 66.0f, 90.0f}, {12.0f, 0.0f, 0.0f, 10.0f, 66.0f, 90.0f}, @@ -1511,7 +1511,7 @@ TEST_F(FPDFTextEmbedderTest, GetMatrix) { {1.0f, 0.0f, 0.0f, 0.833333, 60.0f, 130.0f}, {1.0f, 0.0f, 0.0f, 0.833333, 60.0f, 130.0f}, }; - constexpr size_t kExpectedCount = FX_ArraySize(kExpectedMatrices); + constexpr size_t kExpectedCount = pdfium::size(kExpectedMatrices); static_assert(kExpectedCount + 1 == kExpectedTextSize, "Bad expected matrix size"); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_thumbnail.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_thumbnail.cpp index 5c22c8c47bd..df56f1f29fa 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_thumbnail.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_thumbnail.cpp @@ -4,8 +4,6 @@ #include "public/fpdf_thumbnail.h" -#include <vector> - #include "core/fpdfapi/page/cpdf_dib.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp index 0afd461f318..8e180862674 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_transformpage.cpp @@ -8,7 +8,6 @@ #include <memory> #include <sstream> -#include <vector> #include "constants/page_object.h" #include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h" @@ -25,7 +24,6 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/render_defines.h" #include "fpdfsdk/cpdfsdk_helpers.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/span.h" #include "third_party/base/stl_util.h" @@ -368,7 +366,7 @@ FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDF_CreateClipPath(float left, CPDF_Path Path; Path.AppendRect(left, bottom, right, top); - auto pNewClipPath = pdfium::MakeUnique<CPDF_ClipPath>(); + auto pNewClipPath = std::make_unique<CPDF_ClipPath>(); pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, false); // Caller takes ownership. diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_view.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_view.cpp index eddd0db3aaa..c1458394d8a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_view.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_view.cpp @@ -47,6 +47,11 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/span.h" +#ifdef PDF_ENABLE_V8 +#include "fxjs/cfx_v8.h" +#include "third_party/base/no_destructor.h" +#endif + #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" @@ -90,9 +95,9 @@ FPDF_DOCUMENT LoadDocumentImpl( return nullptr; } - auto pDocument = pdfium::MakeUnique<CPDF_Document>( - pdfium::MakeUnique<CPDF_DocRenderData>(), - pdfium::MakeUnique<CPDF_DocPageData>()); + auto pDocument = + std::make_unique<CPDF_Document>(std::make_unique<CPDF_DocRenderData>(), + std::make_unique<CPDF_DocPageData>()); CPDF_Parser::Error error = pDocument->LoadDoc(pFileAccess, password); if (error != CPDF_Parser::SUCCESS) { @@ -122,9 +127,11 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config) { #ifdef PDF_ENABLE_XFA BC_Library_Init(); #endif // PDF_ENABLE_XFA - if (config && config->version >= 2) - IJS_Runtime::Initialize(config->m_v8EmbedderSlot, config->m_pIsolate); - + if (config && config->version >= 2) { + void* platform = config->version >= 3 ? config->m_pPlatform : nullptr; + IJS_Runtime::Initialize(config->m_v8EmbedderSlot, config->m_pIsolate, + platform); + } g_bLibraryInitialized = true; } @@ -307,7 +314,7 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, return nullptr; auto pPage = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict); - pPage->SetRenderCache(pdfium::MakeUnique<CPDF_PageRenderCache>(pPage.Get())); + pPage->SetRenderCache(std::make_unique<CPDF_PageRenderCache>(pPage.Get())); pPage->ParseContent(); return FPDFPageFromIPDFPage(pPage.Leak()); } @@ -439,7 +446,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, if (!pPage) return; - auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + auto pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* pContext = pOwnedContext.get(); CPDF_Page::RenderContextClearer clearer(pPage); pPage->SetRenderContext(std::move(pOwnedContext)); @@ -456,7 +463,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, pPage->GetMaskBoundingBoxes().size() > 100; const bool bHasMask = pPage->HasImageMask() && !bNewBitmap; if (!bNewBitmap && !bHasMask) { - pContext->m_pDevice = pdfium::MakeUnique<CPDF_WindowsRenderDevice>(dc); + pContext->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(dc); CPDFSDK_RenderPageWithContext(pContext, pPage, start_x, start_y, size_x, size_y, rotate, flags, /*color_scheme=*/nullptr, @@ -473,7 +480,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, pContext->m_pDevice = pdfium::WrapUnique(pDevice); pDevice->Attach(pBitmap, false, nullptr, false); if (bHasMask) { - pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); + pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>(); pContext->m_pOptions->GetOptions().bBreakForMasks = true; } @@ -513,11 +520,11 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc, // Begin rendering to the printer. Add flag to indicate the renderer should // pause after each image mask. - pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); pContext = pOwnedContext.get(); pPage->SetRenderContext(std::move(pOwnedContext)); - pContext->m_pDevice = pdfium::MakeUnique<CPDF_WindowsRenderDevice>(dc); - pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); + pContext->m_pDevice = std::make_unique<CPDF_WindowsRenderDevice>(dc); + pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>(); pContext->m_pOptions->GetOptions().bBreakForMasks = true; CPDFSDK_RenderPageWithContext(pContext, pPage, start_x, start_y, size_x, @@ -552,12 +559,12 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, if (!pPage) return; - auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + auto pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* pContext = pOwnedContext.get(); CPDF_Page::RenderContextClearer clearer(pPage); pPage->SetRenderContext(std::move(pOwnedContext)); - auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); + auto pOwnedDevice = std::make_unique<CFX_DefaultRenderDevice>(); CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get(); pContext->m_pDevice = std::move(pOwnedDevice); @@ -587,12 +594,12 @@ FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, if (!pPage) return; - auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + auto pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* pContext = pOwnedContext.get(); CPDF_Page::RenderContextClearer clearer(pPage); pPage->SetRenderContext(std::move(pOwnedContext)); - auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); + auto pOwnedDevice = std::make_unique<CFX_DefaultRenderDevice>(); CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get(); pContext->m_pDevice = std::move(pOwnedDevice); @@ -620,12 +627,12 @@ FPDF_EXPORT FPDF_RECORDER FPDF_CALLCONV FPDF_RenderPageSkp(FPDF_PAGE page, if (!pPage) return nullptr; - auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); + auto pOwnedContext = std::make_unique<CPDF_PageRenderContext>(); CPDF_PageRenderContext* pContext = pOwnedContext.get(); CPDF_Page::RenderContextClearer clearer(pPage); pPage->SetRenderContext(std::move(pOwnedContext)); - auto skDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); + auto skDevice = std::make_unique<CFX_DefaultRenderDevice>(); FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); pContext->m_pDevice = std::move(skDevice); @@ -855,7 +862,7 @@ FPDF_GetPageSizeByIndexF(FPDF_DOCUMENT document, return false; auto page = pdfium::MakeRetain<CPDF_Page>(pDoc, pDict); - page->SetRenderCache(pdfium::MakeUnique<CPDF_PageRenderCache>(page.Get())); + page->SetRenderCache(std::make_unique<CPDF_PageRenderCache>(page.Get())); size->width = page->GetPageWidth(); size->height = page->GetPageHeight(); return true; @@ -989,6 +996,11 @@ FPDF_EXPORT const char* FPDF_CALLCONV FPDF_GetRecommendedV8Flags() { // Use interpreted JS only to avoid RWX pages in our address space. return "--no-expose-wasm --jitless"; } + +FPDF_EXPORT void* FPDF_CALLCONV FPDF_GetArrayBufferAllocatorSharedInstance() { + static pdfium::base::NoDestructor<CFX_V8ArrayBufferAllocator> allocator; + return allocator.get(); +} #endif // PDF_ENABLE_V8 #ifdef PDF_ENABLE_XFA diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_view_c_api_test.c b/chromium/third_party/pdfium/fpdfsdk/fpdf_view_c_api_test.c index c2c77d6e393..f76d3d2f0f8 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_view_c_api_test.c +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_view_c_api_test.c @@ -50,7 +50,10 @@ int CheckPDFiumCApi() { CHK(FPDFAnnot_GetFocusableSubtypes); CHK(FPDFAnnot_GetFocusableSubtypesCount); CHK(FPDFAnnot_GetFontSize); + CHK(FPDFAnnot_GetFormControlCount); + CHK(FPDFAnnot_GetFormControlIndex); CHK(FPDFAnnot_GetFormFieldAtPoint); + CHK(FPDFAnnot_GetFormFieldExportValue); CHK(FPDFAnnot_GetFormFieldFlags); CHK(FPDFAnnot_GetFormFieldName); CHK(FPDFAnnot_GetFormFieldType); @@ -132,6 +135,7 @@ int CheckPDFiumCApi() { CHK(FPDFLink_CountQuadPoints); CHK(FPDFLink_Enumerate); CHK(FPDFLink_GetAction); + CHK(FPDFLink_GetAnnot); CHK(FPDFLink_GetAnnotRect); CHK(FPDFLink_GetDest); CHK(FPDFLink_GetLinkAtPoint); @@ -266,6 +270,7 @@ int CheckPDFiumCApi() { CHK(FORM_OnRButtonUp); CHK(FORM_Redo); CHK(FORM_ReplaceSelection); + CHK(FORM_SelectAllText); CHK(FORM_SetFocusedAnnot); CHK(FORM_SetIndexSelected); CHK(FORM_Undo); @@ -410,6 +415,9 @@ int CheckPDFiumCApi() { CHK(FPDF_DestroyLibrary); CHK(FPDF_DeviceToPage); CHK(FPDF_DocumentHasValidCrossReferenceTable); +#ifdef PDF_ENABLE_V8 + CHK(FPDF_GetArrayBufferAllocatorSharedInstance); +#endif CHK(FPDF_GetDocPermissions); CHK(FPDF_GetFileVersion); CHK(FPDF_GetLastError); diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdf_view_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdf_view_embeddertest.cpp index d3b1c10e1c5..ba507e6c407 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdf_view_embeddertest.cpp @@ -1255,6 +1255,11 @@ TEST_F(FPDFViewEmbedderTest, MAYBE_RenderHelloWorldWithFlags) { TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHPATH, kHelloWorldChecksum); + // For text rendering, When anti-aliasing is disabled, LCD Optimization flag + // will be ignored. + TestRenderPageBitmapWithFlags(page, FPDF_LCD_TEXT | FPDF_RENDER_NO_SMOOTHTEXT, + kNoSmoothtextMD5); + UnloadPage(page); } #endif // defined(OS_LINUX) diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/BUILD.gn b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/BUILD.gn index 4e88c4cd234..658f0507b4a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/BUILD.gn +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/BUILD.gn @@ -37,8 +37,15 @@ source_set("fpdfxfa") { } pdfium_embeddertest_source_set("embeddertests") { - sources = [ "cpdfxfa_docenvironment_embeddertest.cpp" ] + sources = [ + "cpdfxfa_context_embeddertest.cpp", + "cpdfxfa_docenvironment_embeddertest.cpp", + ] configs = [ "//v8:external_startup_data" ] - deps = [ "../../fxjs" ] + deps = [ + ":fpdfxfa", + "../:fpdfsdk", + "../../fxjs", + ] pdfium_root_dir = "../../" } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index a5301826ff5..620016e2b6a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -20,7 +20,6 @@ #include "fxjs/cjs_runtime.h" #include "fxjs/ijs_runtime.h" #include "public/fpdf_formfill.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffapp.h" @@ -82,7 +81,8 @@ RetainPtr<CPDF_SeekableMultiStream> CreateXFAMultiStream( CPDFXFA_Context::CPDFXFA_Context(CPDF_Document* pPDFDoc) : m_pPDFDoc(pPDFDoc), - m_pXFAApp(pdfium::MakeUnique<CXFA_FFApp>(this)), + m_pGCHeap(FXGC_CreateHeap()), + m_pXFAApp(std::make_unique<CXFA_FFApp>(this)), m_DocEnv(this) { ASSERT(m_pPDFDoc); } diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.h index 0f6a14bbeb2..017545e330a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.h +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context.h @@ -18,6 +18,7 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" +#include "fxjs/gc/heap.h" #include "xfa/fxfa/cxfa_ffdoc.h" class CJS_Runtime; @@ -42,12 +43,12 @@ class CPDFXFA_Context final : public CPDF_Document::Extension, bool LoadXFADoc(); CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } CXFA_FFDocView* GetXFADocView() const { return m_pXFADocView.Get(); } + cppgc::Heap* GetGCHeap() { return m_pGCHeap.get(); } FormType GetFormType() const { return m_FormType; } CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv.Get(); } void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv); - RetainPtr<CPDFXFA_Page> GetXFAPage(int page_index); RetainPtr<CPDFXFA_Page> GetXFAPage(CXFA_FFPageView* pPage) const; void ClearChangeMark(); @@ -115,6 +116,7 @@ class CPDFXFA_Context final : public CPDF_Document::Extension, FormType m_FormType = FormType::kNone; UnownedPtr<CPDF_Document> const m_pPDFDoc; + FXGCScopedHeap m_pGCHeap; std::unique_ptr<CXFA_FFDoc> m_pXFADoc; ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv; UnownedPtr<CXFA_FFDocView> m_pXFADocView; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context_embeddertest.cpp new file mode 100644 index 00000000000..b7eed28a593 --- /dev/null +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_context_embeddertest.cpp @@ -0,0 +1,20 @@ +// Copyright 2020 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" + +#include "fpdfsdk/cpdfsdk_helpers.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/xfa_js_embedder_test.h" + +class CPDFXFAContextEmbedderTest : public XFAJSEmbedderTest {}; + +// Should not crash. +TEST_F(CPDFXFAContextEmbedderTest, HasHeap) { + ASSERT_TRUE(OpenDocument("simple_xfa.pdf")); + + CPDF_Document* pDocument = CPDFDocumentFromFPDFDocument(document()); + auto* pContext = static_cast<CPDFXFA_Context*>(pDocument->GetExtension()); + EXPECT_TRUE(pContext->GetGCHeap()); +} diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index e6ae514759d..6f26acba550 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -48,7 +48,7 @@ CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Context* pContext) ASSERT(m_pContext); } -CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() {} +CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() = default; void CPDFXFA_DocEnvironment::SetChangeMark(CXFA_FFDoc* hDoc) { if (hDoc == m_pContext->GetXFADoc() && m_pContext->GetFormFillEnv()) diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index fc9cf9d1644..021af5af12a 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -14,7 +14,6 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h" -#include "third_party/base/ptr_util.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -22,6 +21,14 @@ #include "xfa/fxfa/cxfa_rendercontext.h" #include "xfa/fxgraphics/cxfa_graphics.h" +namespace { + +constexpr uint32_t kIteratorFilter = XFA_WidgetStatus_Visible | + XFA_WidgetStatus_Viewable | + XFA_WidgetStatus_Focused; + +} // namespace + CPDFXFA_Page::CPDFXFA_Page(CPDF_Document* pDocument, int page_index) : m_pDocument(pDocument), m_iPageIndex(page_index) { ASSERT(m_pDocument->GetExtension()); @@ -78,7 +85,7 @@ void CPDFXFA_Page::LoadPDFPageFromDict(CPDF_Dictionary* pPageDict) { ASSERT(pPageDict); m_pPDFPage = pdfium::MakeRetain<CPDF_Page>(GetDocument(), pPageDict); m_pPDFPage->SetRenderCache( - pdfium::MakeUnique<CPDF_PageRenderCache>(m_pPDFPage.Get())); + std::make_unique<CPDF_PageRenderCache>(m_pPDFPage.Get())); m_pPDFPage->ParseContent(); } @@ -180,12 +187,14 @@ CPDFSDK_Annot* CPDFXFA_Page::GetNextXFAAnnot(CPDFSDK_Annot* pSDKAnnot, if (!pXFAWidget) return nullptr; + CXFA_FFPageView* xfa_page_view = GetXFAPageView(); + if (!xfa_page_view) + return nullptr; + ObservedPtr<CPDFSDK_Annot> pObservedAnnot(pSDKAnnot); CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator = - GetXFAPageView()->CreateTraverseWidgetIterator(XFA_WidgetStatus_Visible | - XFA_WidgetStatus_Viewable | - XFA_WidgetStatus_Focused); + xfa_page_view->CreateTraverseWidgetIterator(kIteratorFilter); // Check |pSDKAnnot| again because JS may have destroyed it if (!pObservedAnnot) @@ -210,9 +219,7 @@ CPDFSDK_Annot* CPDFXFA_Page::GetFirstOrLastXFAAnnot(CPDFSDK_PageView* page_view, ObservedPtr<CPDFSDK_PageView> watched_page_view(page_view); std::unique_ptr<IXFA_WidgetIterator> it = - xfa_page_view->CreateTraverseWidgetIterator(XFA_WidgetStatus_Visible | - XFA_WidgetStatus_Viewable | - XFA_WidgetStatus_Focused); + xfa_page_view->CreateTraverseWidgetIterator(kIteratorFilter); if (!watched_page_view) return nullptr; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.h index c121babe814..b7655efb3ab 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -24,8 +24,7 @@ class CXFA_FFPageView; class CPDFXFA_Page final : public IPDF_Page { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CONSTRUCT_VIA_MAKE_RETAIN; // IPDF_Page: CPDF_Page* AsPDFPage() override; diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp index 5a49b92daa3..c5e956f47df 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp @@ -13,7 +13,6 @@ #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/fwl_widgetdef.h" #include "xfa/fwl/fwl_widgethit.h" @@ -225,7 +224,7 @@ std::unique_ptr<CPDFSDK_Annot> CPDFXFA_WidgetHandler::NewAnnotForXFA( CXFA_FFWidget* pAnnot, CPDFSDK_PageView* pPageView) { CPDFSDK_InteractiveForm* pForm = m_pFormFillEnv->GetInteractiveForm(); - return pdfium::MakeUnique<CPDFXFA_Widget>(pAnnot, pPageView, pForm); + return std::make_unique<CPDFXFA_Widget>(pAnnot, pPageView, pForm); } void CPDFXFA_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, @@ -297,6 +296,15 @@ void CPDFXFA_WidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, return pWidgetHandler->PasteText(pXFAWidget->GetXFAFFWidget(), text); } +bool CPDFXFA_WidgetHandler::SelectAllText(CPDFSDK_Annot* pAnnot) { + CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot); + if (!pXFAWidget) + return false; + + CXFA_FFWidgetHandler* pWidgetHandler = GetXFAFFWidgetHandler(pXFAWidget); + return pWidgetHandler->SelectAllText(pXFAWidget->GetXFAFFWidget()); +} + bool CPDFXFA_WidgetHandler::CanUndo(CPDFSDK_Annot* pAnnot) { CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot); if (!pXFAWidget) diff --git a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h index abef600bf8f..abad547bcdc 100644 --- a/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.h @@ -39,6 +39,7 @@ class CPDFXFA_WidgetHandler final : public IPDFSDK_AnnotHandler { WideString GetText(CPDFSDK_Annot* pAnnot) override; WideString GetSelectedText(CPDFSDK_Annot* pAnnot) override; void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) override; + bool SelectAllText(CPDFSDK_Annot* pAnnot) override; bool CanUndo(CPDFSDK_Annot* pAnnot) override; bool CanRedo(CPDFSDK_Annot* pAnnot) override; bool Undo(CPDFSDK_Annot* pAnnot) override; diff --git a/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h b/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h index 234d0b5c1ee..6150bdc9742 100644 --- a/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h +++ b/chromium/third_party/pdfium/fpdfsdk/ipdfsdk_annothandler.h @@ -35,6 +35,7 @@ class IPDFSDK_AnnotHandler { virtual WideString GetSelectedText(CPDFSDK_Annot* pAnnot) = 0; virtual void ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) = 0; + virtual bool SelectAllText(CPDFSDK_Annot* pAnnot) = 0; virtual bool CanUndo(CPDFSDK_Annot* pAnnot) = 0; virtual bool CanRedo(CPDFSDK_Annot* pAnnot) = 0; virtual bool Undo(CPDFSDK_Annot* pAnnot) = 0; diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_caret.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_caret.cpp index cc6ae8af77d..87b79eecd82 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_caret.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_caret.cpp @@ -12,7 +12,6 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -#include "third_party/base/ptr_util.h" CPWL_Caret::CPWL_Caret( const CreateParams& cp, @@ -85,8 +84,8 @@ void CPWL_Caret::SetCaret(bool bVisible, m_ptHead = ptHead; m_ptFoot = ptFoot; - m_pTimer = pdfium::MakeUnique<CFX_Timer>(GetTimerHandler(), this, - kCaretFlashIntervalMs); + m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(), this, + kCaretFlashIntervalMs); if (!CPWL_Wnd::SetVisible(true)) return; diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.cpp index 1f9914354a5..7fe25174c6c 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.cpp @@ -18,7 +18,6 @@ #include "fpdfsdk/pwl/cpwl_list_impl.h" #include "fpdfsdk/pwl/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" namespace { @@ -206,6 +205,10 @@ void CPWL_ComboBox::ReplaceSelection(const WideString& text) { m_pEdit->ReplaceSelection(text); } +bool CPWL_ComboBox::SelectAllText() { + return m_pEdit && m_pEdit->SelectAllText(); +} + bool CPWL_ComboBox::CanUndo() { return m_pEdit && m_pEdit->CanUndo(); } @@ -286,9 +289,9 @@ void CPWL_ComboBox::CreateEdit(const CreateParams& cp) { ecp.rcRectWnd = CFX_FloatRect(); ecp.dwBorderWidth = 0; - ecp.nBorderStyle = BorderStyle::SOLID; + ecp.nBorderStyle = BorderStyle::kSolid; - auto pEdit = pdfium::MakeUnique<CPWL_Edit>(ecp, CloneAttachedData()); + auto pEdit = std::make_unique<CPWL_Edit>(ecp, CloneAttachedData()); m_pEdit = pEdit.get(); m_pEdit->AttachFFLData(m_pFormFiller.Get()); AddChild(std::move(pEdit)); @@ -305,10 +308,10 @@ void CPWL_ComboBox::CreateButton(const CreateParams& cp) { 220.0f / 255.0f, 220.0f / 255.0f); bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; bcp.dwBorderWidth = 2; - bcp.nBorderStyle = BorderStyle::BEVELED; + bcp.nBorderStyle = BorderStyle::kBeveled; bcp.eCursorType = FXCT_ARROW; - auto pButton = pdfium::MakeUnique<CPWL_CBButton>(bcp, CloneAttachedData()); + auto pButton = std::make_unique<CPWL_CBButton>(bcp, CloneAttachedData()); m_pButton = pButton.get(); AddChild(std::move(pButton)); m_pButton->Realize(); @@ -321,7 +324,7 @@ void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { CreateParams lcp = cp; lcp.dwFlags = PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; - lcp.nBorderStyle = BorderStyle::SOLID; + lcp.nBorderStyle = BorderStyle::kSolid; lcp.dwBorderWidth = 1; lcp.eCursorType = FXCT_ARROW; lcp.rcRectWnd = CFX_FloatRect(); @@ -335,7 +338,7 @@ void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { if (cp.sBackgroundColor.nColorType == CFX_Color::kTransparent) lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; - auto pList = pdfium::MakeUnique<CPWL_CBListBox>(lcp, CloneAttachedData()); + auto pList = std::make_unique<CPWL_CBListBox>(lcp, CloneAttachedData()); m_pList = pList.get(); m_pList->AttachFFLData(m_pFormFiller.Get()); AddChild(std::move(pList)); @@ -420,7 +423,7 @@ bool CPWL_ComboBox::RePosChildWnd() { void CPWL_ComboBox::SelectAll() { if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) - m_pEdit->SelectAll(); + m_pEdit->SelectAllText(); } CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { @@ -534,6 +537,28 @@ bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { if (!m_pEdit) return false; + // In a combo box if the ENTER/SPACE key is pressed, show the combo box + // options. + switch (nChar) { + case FWL_VKEY_Return: + SetPopup(!IsPopup()); + SetSelectText(); + return true; + case FWL_VKEY_Space: + // Show the combo box options with space only if the combo box is not + // editable + if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) { + if (!IsPopup()) { + SetPopup(/*bPopUp=*/true); + SetSelectText(); + } + return true; + } + break; + default: + break; + } + m_nSelectItem = -1; if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) return m_pEdit->OnChar(nChar, nFlag); @@ -562,7 +587,7 @@ void CPWL_ComboBox::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { return; SetSelectText(); - SelectAll(); + SelectAllText(); m_pEdit->SetFocus(); SetPopup(false); // Note, |this| may no longer be viable at this point. If more work needs to @@ -574,9 +599,9 @@ bool CPWL_ComboBox::IsPopup() const { } void CPWL_ComboBox::SetSelectText() { - m_pEdit->SelectAll(); + m_pEdit->SelectAllText(); m_pEdit->ReplaceSelection(m_pList->GetText()); - m_pEdit->SelectAll(); + m_pEdit->SelectAllText(); m_nSelectItem = m_pList->GetCurSel(); } diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.h b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.h index 6f71c71865f..cf1a8750c18 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.h +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box.h @@ -68,6 +68,7 @@ class CPWL_ComboBox final : public CPWL_Wnd { WideString GetText() override; WideString GetSelectedText() override; void ReplaceSelection(const WideString& text) override; + bool SelectAllText() override; bool CanUndo() override; bool CanRedo() override; bool Undo() override; diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp index ac50f0cbc13..5b5dd1d4a66 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp @@ -105,7 +105,7 @@ TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextEmptyAndBasicNormal) { EXPECT_FALSE(GetCPWLComboBox()->GetText().IsEmpty()); EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetText().c_str()); - // Check that selection is intially empty, then select entire word. + // Check that selection is initially empty, then select entire word. EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); GetCPWLComboBox()->SetSelectText(); EXPECT_STREQ(L"Banana", GetCPWLComboBox()->GetSelectedText().c_str()); @@ -150,7 +150,7 @@ TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextEmptyAndBasicEditable) { FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty()); - // Check selection is intially empty, then select a provided option. + // Check selection is initially empty, then select a provided option. EXPECT_TRUE(GetCPWLComboBox()->GetSelectedText().IsEmpty()); GetCPWLComboBox()->SetSelect(0); GetCPWLComboBox()->SetSelectText(); diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit.cpp index 9c248759846..43bcd532e40 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit.cpp @@ -10,7 +10,6 @@ #include <memory> #include <sstream> #include <utility> -#include <vector> #include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfdoc/cpvt_word.h" @@ -165,8 +164,8 @@ void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, const CFX_FloatRect rcClient = GetClientRect(); const BorderStyle border_style = GetBorderStyle(); const int32_t nCharArray = m_pEdit->GetCharArray(); - bool draw_border = nCharArray > 0 && (border_style == BorderStyle::SOLID || - border_style == BorderStyle::DASH); + bool draw_border = nCharArray > 0 && (border_style == BorderStyle::kSolid || + border_style == BorderStyle::kDash); if (draw_border) { FX_SAFE_INT32 nCharArraySafe = nCharArray; nCharArraySafe -= 1; @@ -177,7 +176,7 @@ void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, if (draw_border) { CFX_GraphStateData gsd; gsd.m_LineWidth = GetBorderWidth(); - if (border_style == BorderStyle::DASH) { + if (border_style == BorderStyle::kDash) { gsd.m_DashArray = {static_cast<float>(GetBorderDash().nDash), static_cast<float>(GetBorderDash().nGap)}; gsd.m_DashPhase = GetBorderDash().nPhase; diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.cpp index d62c7c6a260..3e16b62f6fe 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.cpp @@ -15,13 +15,12 @@ #include "fpdfsdk/pwl/cpwl_scroll_bar.h" #include "fpdfsdk/pwl/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" CPWL_EditCtrl::CPWL_EditCtrl( const CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) : CPWL_Wnd(cp, std::move(pAttachedData)), - m_pEdit(pdfium::MakeUnique<CPWL_EditImpl>()) { + m_pEdit(std::make_unique<CPWL_EditImpl>()) { GetCreationParams()->eCursorType = FXCT_VBEAM; } @@ -52,6 +51,11 @@ void CPWL_EditCtrl::ReplaceSelection(const WideString& text) { m_pEdit->ReplaceSelection(text); } +bool CPWL_EditCtrl::SelectAllText() { + m_pEdit->SelectAll(); + return true; +} + bool CPWL_EditCtrl::RePosChildWnd() { m_pEdit->SetPlateRect(GetClientRect()); return true; @@ -83,10 +87,10 @@ void CPWL_EditCtrl::CreateEditCaret(const CreateParams& cp) { CreateParams ecp = cp; ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; ecp.dwBorderWidth = 0; - ecp.nBorderStyle = BorderStyle::SOLID; + ecp.nBorderStyle = BorderStyle::kSolid; ecp.rcRectWnd = CFX_FloatRect(); - auto pCaret = pdfium::MakeUnique<CPWL_Caret>(ecp, CloneAttachedData()); + auto pCaret = std::make_unique<CPWL_Caret>(ecp, CloneAttachedData()); m_pEditCaret = pCaret.get(); m_pEditCaret->SetInvalidRect(GetClientRect()); AddChild(std::move(pCaret)); @@ -207,7 +211,7 @@ bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { CutText(); return true; case 'A' - 'A' + 1: - SelectAll(); + SelectAllText(); return true; case 'Z' - 'A' + 1: if (bShift) @@ -349,10 +353,6 @@ void CPWL_EditCtrl::ClearSelection() { m_pEdit->ClearSelection(); } -void CPWL_EditCtrl::SelectAll() { - m_pEdit->SelectAll(); -} - void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) { m_pEdit->SetScrollPos(point); } diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.h b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.h index 67bd2470656..f5ccf3c8d42 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.h +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_ctrl.h @@ -32,7 +32,6 @@ class CPWL_EditCtrl : public CPWL_Wnd { void SetSelection(int32_t nStartChar, int32_t nEndChar); std::pair<int32_t, int32_t> GetSelection() const; void ClearSelection(); - void SelectAll(); CFX_PointF GetScrollPos() const; void SetScrollPos(const CFX_PointF& point); @@ -40,11 +39,6 @@ class CPWL_EditCtrl : public CPWL_Wnd { void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; } int32_t GetCharSet() const; - bool CanUndo() override; - bool CanRedo() override; - bool Undo() override; - bool Redo() override; - void SetReadyToInput(); // CPWL_Wnd: @@ -65,6 +59,11 @@ class CPWL_EditCtrl : public CPWL_Wnd { WideString GetText() override; WideString GetSelectedText() override; void ReplaceSelection(const WideString& text) override; + bool SelectAllText() override; + bool CanUndo() override; + bool CanRedo() override; + bool Undo() override; + bool Redo() override; bool SetCaret(bool bVisible, const CFX_PointF& ptHead, diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_impl.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_impl.cpp index 8dbc9f10bbf..6d0ed20af9b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_impl.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_edit_impl.cpp @@ -26,7 +26,6 @@ #include "fpdfsdk/pwl/cpwl_scroll_bar.h" #include "fpdfsdk/pwl/ipwl_systemhandler.h" #include "third_party/base/compiler_specific.h" -#include "third_party/base/ptr_util.h" namespace { @@ -57,7 +56,7 @@ CPWL_EditImpl_Iterator::CPWL_EditImpl_Iterator( CPDF_VariableText::Iterator* pVTIterator) : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} -CPWL_EditImpl_Iterator::~CPWL_EditImpl_Iterator() {} +CPWL_EditImpl_Iterator::~CPWL_EditImpl_Iterator() = default; bool CPWL_EditImpl_Iterator::NextWord() { return m_pVTIterator->NextWord(); @@ -104,7 +103,7 @@ CPWL_EditImpl_Provider::CPWL_EditImpl_Provider(IPVT_FontMap* pFontMap) ASSERT(m_pFontMap); } -CPWL_EditImpl_Provider::~CPWL_EditImpl_Provider() {} +CPWL_EditImpl_Provider::~CPWL_EditImpl_Provider() = default; IPVT_FontMap* CPWL_EditImpl_Provider::GetFontMap() const { return m_pFontMap; @@ -152,7 +151,7 @@ bool CPWL_EditImpl_Provider::IsLatinWord(uint16_t word) { CPWL_EditImpl_Refresh::CPWL_EditImpl_Refresh() {} -CPWL_EditImpl_Refresh::~CPWL_EditImpl_Refresh() {} +CPWL_EditImpl_Refresh::~CPWL_EditImpl_Refresh() = default; void CPWL_EditImpl_Refresh::BeginRefresh() { m_OldLineRects = std::move(m_NewLineRects); @@ -193,7 +192,7 @@ void CPWL_EditImpl_Refresh::Add(const CFX_FloatRect& new_rect) { CPWL_EditImpl_Undo::CPWL_EditImpl_Undo() : m_nCurUndoPos(0), m_bWorking(false) {} -CPWL_EditImpl_Undo::~CPWL_EditImpl_Undo() {} +CPWL_EditImpl_Undo::~CPWL_EditImpl_Undo() = default; bool CPWL_EditImpl_Undo::CanUndo() const { return m_nCurUndoPos > 0; @@ -267,7 +266,7 @@ CFXEU_InsertWord::CFXEU_InsertWord(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_InsertWord::~CFXEU_InsertWord() {} +CFXEU_InsertWord::~CFXEU_InsertWord() = default; int CFXEU_InsertWord::Redo() { m_pEdit->SelectNone(); @@ -290,7 +289,7 @@ CFXEU_InsertReturn::CFXEU_InsertReturn(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_InsertReturn::~CFXEU_InsertReturn() {} +CFXEU_InsertReturn::~CFXEU_InsertReturn() = default; int CFXEU_InsertReturn::Redo() { m_pEdit->SelectNone(); @@ -312,7 +311,7 @@ CFXEU_ReplaceSelection::CFXEU_ReplaceSelection(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_ReplaceSelection::~CFXEU_ReplaceSelection() {} +CFXEU_ReplaceSelection::~CFXEU_ReplaceSelection() = default; int CFXEU_ReplaceSelection::Redo() { m_pEdit->SelectNone(); @@ -344,7 +343,7 @@ CFXEU_Backspace::CFXEU_Backspace(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_Backspace::~CFXEU_Backspace() {} +CFXEU_Backspace::~CFXEU_Backspace() = default; int CFXEU_Backspace::Redo() { m_pEdit->SelectNone(); @@ -378,7 +377,7 @@ CFXEU_Delete::CFXEU_Delete(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_Delete::~CFXEU_Delete() {} +CFXEU_Delete::~CFXEU_Delete() = default; int CFXEU_Delete::Redo() { m_pEdit->SelectNone(); @@ -404,7 +403,7 @@ CFXEU_Clear::CFXEU_Clear(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_Clear::~CFXEU_Clear() {} +CFXEU_Clear::~CFXEU_Clear() = default; int CFXEU_Clear::Redo() { m_pEdit->SelectNone(); @@ -434,7 +433,7 @@ CFXEU_InsertText::CFXEU_InsertText(CPWL_EditImpl* pEdit, ASSERT(m_pEdit); } -CFXEU_InsertText::~CFXEU_InsertText() {} +CFXEU_InsertText::~CFXEU_InsertText() = default; int CFXEU_InsertText::Redo() { m_pEdit->SelectNone(); @@ -565,7 +564,7 @@ void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice, } CPWL_EditImpl::CPWL_EditImpl() - : m_pVT(pdfium::MakeUnique<CPDF_VariableText>()), + : m_pVT(std::make_unique<CPDF_VariableText>()), m_bEnableScroll(false), m_nAlignment(0), m_bNotifyFlag(false), @@ -573,7 +572,7 @@ CPWL_EditImpl::CPWL_EditImpl() m_bEnableRefresh(true), m_bEnableUndo(true) {} -CPWL_EditImpl::~CPWL_EditImpl() {} +CPWL_EditImpl::~CPWL_EditImpl() = default; void CPWL_EditImpl::Initialize() { m_pVT->Initialize(); @@ -582,7 +581,7 @@ void CPWL_EditImpl::Initialize() { } void CPWL_EditImpl::SetFontMap(IPVT_FontMap* pFontMap) { - m_pVTProvider = pdfium::MakeUnique<CPWL_EditImpl_Provider>(pFontMap); + m_pVTProvider = std::make_unique<CPWL_EditImpl_Provider>(pFontMap); m_pVT->SetProvider(m_pVTProvider.get()); } @@ -597,7 +596,7 @@ void CPWL_EditImpl::SetOperationNotify(CPWL_Edit* pOperationNotify) { CPWL_EditImpl_Iterator* CPWL_EditImpl::GetIterator() { if (!m_pIterator) { m_pIterator = - pdfium::MakeUnique<CPWL_EditImpl_Iterator>(this, m_pVT->GetIterator()); + std::make_unique<CPWL_EditImpl_Iterator>(this, m_pVT->GetIterator()); } return m_pIterator.get(); } @@ -1538,7 +1537,7 @@ bool CPWL_EditImpl::InsertWord(uint16_t word, return false; if (bAddUndo && m_bEnableUndo) { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertWord>( + AddEditUndoItem(std::make_unique<CFXEU_InsertWord>( this, m_wpOldCaret, m_wpCaret, word, charset)); } if (bPaint) @@ -1562,7 +1561,7 @@ bool CPWL_EditImpl::InsertReturn(bool bAddUndo, bool bPaint) { if (bAddUndo && m_bEnableUndo) { AddEditUndoItem( - pdfium::MakeUnique<CFXEU_InsertReturn>(this, m_wpOldCaret, m_wpCaret)); + std::make_unique<CFXEU_InsertReturn>(this, m_wpOldCaret, m_wpCaret)); } if (bPaint) { RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); @@ -1594,7 +1593,7 @@ bool CPWL_EditImpl::Backspace(bool bAddUndo, bool bPaint) { return false; if (bAddUndo && m_bEnableUndo) { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>( + AddEditUndoItem(std::make_unique<CFXEU_Backspace>( this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset)); } if (bPaint) { @@ -1626,10 +1625,10 @@ bool CPWL_EditImpl::Delete(bool bAddUndo, bool bPaint) { m_SelState.Set(m_wpCaret, m_wpCaret); if (bAddUndo && m_bEnableUndo) { if (bSecEnd) { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>( + AddEditUndoItem(std::make_unique<CFXEU_Delete>( this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, bSecEnd)); } else { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_Delete>( + AddEditUndoItem(std::make_unique<CFXEU_Delete>( this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, bSecEnd)); } } @@ -1664,7 +1663,7 @@ bool CPWL_EditImpl::Clear(bool bAddUndo, bool bPaint) { CPVT_WordRange range = m_SelState.ConvertToWordRange(); if (bAddUndo && m_bEnableUndo) { AddEditUndoItem( - pdfium::MakeUnique<CFXEU_Clear>(this, range, GetSelectedText())); + std::make_unique<CFXEU_Clear>(this, range, GetSelectedText())); } SelectNone(); @@ -1697,7 +1696,7 @@ bool CPWL_EditImpl::InsertText(const WideString& sText, return false; if (bAddUndo && m_bEnableUndo) { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_InsertText>( + AddEditUndoItem(std::make_unique<CFXEU_InsertText>( this, m_wpOldCaret, m_wpCaret, sText, charset)); } if (bPaint) @@ -1721,10 +1720,10 @@ void CPWL_EditImpl::PaintInsertText(const CPVT_WordPlace& wpOld, } void CPWL_EditImpl::ReplaceSelection(const WideString& text) { - AddEditUndoItem(pdfium::MakeUnique<CFXEU_ReplaceSelection>(this, false)); + AddEditUndoItem(std::make_unique<CFXEU_ReplaceSelection>(this, false)); ClearSelection(); InsertText(text, FX_CHARSET_Default); - AddEditUndoItem(pdfium::MakeUnique<CFXEU_ReplaceSelection>(this, true)); + AddEditUndoItem(std::make_unique<CFXEU_ReplaceSelection>(this, true)); } bool CPWL_EditImpl::Redo() { diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_icon.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_icon.cpp index 67df09e5ad4..bade07282a7 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_icon.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_icon.cpp @@ -53,35 +53,35 @@ std::pair<float, float> CPWL_Icon::GetScale() { CFX_SizeF image_size = GetImageSize(); float fImageWidth = image_size.width; float fImageHeight = image_size.height; - int32_t nScaleMethod = m_pIconFit ? m_pIconFit->GetScaleMethod() : 0; + CPDF_IconFit::ScaleMethod scale_method = + m_pIconFit ? m_pIconFit->GetScaleMethod() + : CPDF_IconFit::ScaleMethod::kAlways; - switch (nScaleMethod) { - default: - case 0: + switch (scale_method) { + case CPDF_IconFit::ScaleMethod::kAlways: fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); break; - case 1: + case CPDF_IconFit::ScaleMethod::kBigger: if (fPlateWidth < fImageWidth) fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); if (fPlateHeight < fImageHeight) fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); break; - case 2: + case CPDF_IconFit::ScaleMethod::kSmaller: if (fPlateWidth > fImageWidth) fHScale = fPlateWidth / std::max(fImageWidth, 1.0f); if (fPlateHeight > fImageHeight) fVScale = fPlateHeight / std::max(fImageHeight, 1.0f); break; - case 3: + case CPDF_IconFit::ScaleMethod::kNever: break; } - float fMinScale; if (m_pIconFit && m_pIconFit->IsProportionalScale()) { - fMinScale = std::min(fHScale, fVScale); - fHScale = fMinScale; - fVScale = fMinScale; + float min_scale = std::min(fHScale, fVScale); + fHScale = min_scale; + fVScale = min_scale; } return {fHScale, fVScale}; } diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_box.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_box.cpp index 4ad9fe9229f..9e3a7934c71 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_box.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_box.cpp @@ -17,13 +17,12 @@ #include "fpdfsdk/pwl/cpwl_scroll_bar.h" #include "fpdfsdk/pwl/cpwl_wnd.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList) { ASSERT(m_pList); } -CPWL_List_Notify::~CPWL_List_Notify() {} +CPWL_List_Notify::~CPWL_List_Notify() = default; void CPWL_List_Notify::IOnSetScrollInfoY(float fPlateMin, float fPlateMax, @@ -69,13 +68,13 @@ CPWL_ListBox::CPWL_ListBox( const CreateParams& cp, std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) : CPWL_Wnd(cp, std::move(pAttachedData)), - m_pList(pdfium::MakeUnique<CPWL_ListCtrl>()) {} + m_pList(std::make_unique<CPWL_ListCtrl>()) {} CPWL_ListBox::~CPWL_ListBox() = default; void CPWL_ListBox::OnCreated() { m_pList->SetFontMap(GetFontMap()); - m_pListNotify = pdfium::MakeUnique<CPWL_List_Notify>(this); + m_pListNotify = std::make_unique<CPWL_List_Notify>(this); m_pList->SetNotify(m_pListNotify.get()); SetHoverSel(HasFlag(PLBS_HOVERSEL)); diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_impl.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_impl.cpp index a7ceeb9d2c4..f8784f4c2c6 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_impl.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_list_impl.cpp @@ -13,10 +13,9 @@ #include "core/fxcrt/fx_extension.h" #include "fpdfsdk/pwl/cpwl_edit_impl.h" #include "fpdfsdk/pwl/cpwl_list_box.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -CPWL_ListCtrl::Item::Item() : m_pEdit(pdfium::MakeUnique<CPWL_EditImpl>()) { +CPWL_ListCtrl::Item::Item() : m_pEdit(std::make_unique<CPWL_EditImpl>()) { m_pEdit->SetAlignmentV(1, true); m_pEdit->Initialize(); } @@ -53,7 +52,7 @@ WideString CPWL_ListCtrl::Item::GetText() const { CPLST_Select::CPLST_Select() {} -CPLST_Select::~CPLST_Select() {} +CPLST_Select::~CPLST_Select() = default; void CPLST_Select::Add(int32_t nItemIndex) { m_Items[nItemIndex] = SELECTING; @@ -561,7 +560,7 @@ WideString CPWL_ListCtrl::GetText() const { } void CPWL_ListCtrl::AddItem(const WideString& str) { - auto pListItem = pdfium::MakeUnique<Item>(); + auto pListItem = std::make_unique<Item>(); pListItem->SetFontMap(m_pFontMap.Get()); pListItem->SetFontSize(m_fFontSize); pListItem->SetText(str); diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_scroll_bar.cpp index 28de6245384..12414451ea9 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_scroll_bar.cpp @@ -11,11 +11,10 @@ #include <utility> #include <vector> -#include "core/fxcrt/fx_memory.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/pwl/cpwl_wnd.h" -#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" namespace { @@ -199,13 +198,13 @@ void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, 5.0f, 3.0f, 5.0f}; static constexpr float kOffsetsMinY[] = {4.0f, 3.0f, 5.0f, 3.0f, 4.0f, 6.0f, 4.0f}; - static_assert(FX_ArraySize(kOffsetsX) == FX_ArraySize(kOffsetsY), + static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsY), "Wrong offset count"); - static_assert(FX_ArraySize(kOffsetsX) == FX_ArraySize(kOffsetsMinY), + static_assert(pdfium::size(kOffsetsX) == pdfium::size(kOffsetsMinY), "Wrong offset count"); const float* pOffsetsY = m_eSBButtonType == PSBT_MIN ? kOffsetsMinY : kOffsetsY; - for (size_t i = 0; i < FX_ArraySize(kOffsetsX); ++i) + for (size_t i = 0; i < pdfium::size(kOffsetsX); ++i) pts.push_back(CFX_PointF(fX + kOffsetsX[i], fY + pOffsetsY[i])); pDevice->DrawFillArea(mtUser2Device, pts, IsEnabled() @@ -534,29 +533,29 @@ void CPWL_ScrollBar::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) { void CPWL_ScrollBar::CreateButtons(const CreateParams& cp) { CreateParams scp = cp; scp.dwBorderWidth = 2; - scp.nBorderStyle = BorderStyle::BEVELED; + scp.nBorderStyle = BorderStyle::kBeveled; scp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PWS_NOREFRESHCLIP; if (!m_pMinButton) { - auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), - m_sbType, PSBT_MIN); + auto pButton = std::make_unique<CPWL_SBButton>(scp, CloneAttachedData(), + m_sbType, PSBT_MIN); m_pMinButton = pButton.get(); AddChild(std::move(pButton)); m_pMinButton->Realize(); } if (!m_pMaxButton) { - auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), - m_sbType, PSBT_MAX); + auto pButton = std::make_unique<CPWL_SBButton>(scp, CloneAttachedData(), + m_sbType, PSBT_MAX); m_pMaxButton = pButton.get(); AddChild(std::move(pButton)); m_pMaxButton->Realize(); } if (!m_pPosButton) { - auto pButton = pdfium::MakeUnique<CPWL_SBButton>(scp, CloneAttachedData(), - m_sbType, PSBT_POS); + auto pButton = std::make_unique<CPWL_SBButton>(scp, CloneAttachedData(), + m_sbType, PSBT_POS); m_pPosButton = pButton.get(); ObservedPtr<CPWL_ScrollBar> thisObserved(this); if (m_pPosButton->SetVisible(false) && thisObserved) { @@ -677,7 +676,7 @@ void CPWL_ScrollBar::OnMinButtonLBDown(const CFX_PointF& point) { NotifyScrollWindow(); m_bMinOrMax = true; - m_pTimer = pdfium::MakeUnique<CFX_Timer>(GetTimerHandler(), this, 100); + m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(), this, 100); } void CPWL_ScrollBar::OnMinButtonLBUp(const CFX_PointF& point) {} @@ -691,7 +690,7 @@ void CPWL_ScrollBar::OnMaxButtonLBDown(const CFX_PointF& point) { NotifyScrollWindow(); m_bMinOrMax = false; - m_pTimer = pdfium::MakeUnique<CFX_Timer>(GetTimerHandler(), this, 100); + m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(), this, 100); } void CPWL_ScrollBar::OnMaxButtonLBUp(const CFX_PointF& point) {} diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button.cpp index e653ae11746..215df40e17b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button.cpp @@ -39,6 +39,9 @@ bool CPWL_CheckBox::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) { } bool CPWL_CheckBox::OnChar(uint16_t nChar, uint32_t nFlag) { + if (IsReadOnly()) + return false; + SetCheck(!IsChecked()); return true; } @@ -59,6 +62,9 @@ bool CPWL_RadioButton::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) { } bool CPWL_RadioButton::OnChar(uint16_t nChar, uint32_t nFlag) { + if (IsReadOnly()) + return false; + SetCheck(true); return true; } diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp index c99e488b183..ef50ef4a738 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp @@ -108,13 +108,10 @@ class CPWLSpecialButtonEmbedderTest : public EmbedderTest { TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnReadOnlyCheckBox) { FormFillerAndWindowSetup(GetCPDFSDKAnnotReadOnlyCheckBox()); CPWL_CheckBox* check_box = static_cast<CPWL_CheckBox*>(GetWindow()); + EXPECT_TRUE(check_box->IsChecked()); EXPECT_TRUE(GetCPDFSDKFormFillEnv()->GetInteractiveFormFiller()->OnChar( GetCPDFSDKAnnotReadOnlyCheckBox(), '\r', 0)); - // The check box is checked by default. Since it is a read only checkbox, - // clicking Enter shouldn't change its state. - // TODO(http://crbug.com/pdfium/1431) : Change this to EXPECT_TRUE - // as part of the fix. - EXPECT_FALSE(check_box->IsChecked()); + EXPECT_TRUE(check_box->IsChecked()); } TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnCheckBox) { @@ -132,11 +129,10 @@ TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnCheckBox) { TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnReadOnlyRadioButton) { FormFillerAndWindowSetup(GetCPDFSDKAnnotReadOnlyRadioButton()); CPWL_RadioButton* radio_button = static_cast<CPWL_RadioButton*>(GetWindow()); + EXPECT_FALSE(radio_button->IsChecked()); EXPECT_TRUE(GetCPDFSDKFormFillEnv()->GetInteractiveFormFiller()->OnChar( GetCPDFSDKAnnotReadOnlyRadioButton(), '\r', 0)); - // TODO(http://crbug.com/pdfium/1431) : Change this to EXPECT_FALSE - // as part of the fix. - EXPECT_TRUE(radio_button->IsChecked()); + EXPECT_FALSE(radio_button->IsChecked()); } TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnRadioButton) { diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.cpp b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.cpp index 7010d13a33c..1d031f06d4d 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.cpp @@ -6,7 +6,6 @@ #include "fpdfsdk/pwl/cpwl_wnd.h" -#include <map> #include <sstream> #include <utility> #include <vector> @@ -14,7 +13,6 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/pwl/cpwl_scroll_bar.h" #include "public/fpdf_fwlevent.h" -#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -40,7 +38,7 @@ class CPWL_MsgControl final : public Observable { } bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { - return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd); + return pWnd && pdfium::Contains(m_aMousePath, pWnd); } bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { @@ -48,7 +46,7 @@ class CPWL_MsgControl final : public Observable { } bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { - return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd); + return pWnd && pdfium::Contains(m_aKeyboardPath, pWnd); } void SetFocus(CPWL_Wnd* pWnd) { @@ -336,6 +334,10 @@ WideString CPWL_Wnd::GetSelectedText() { void CPWL_Wnd::ReplaceSelection(const WideString& text) {} +bool CPWL_Wnd::SelectAllText() { + return false; +} + bool CPWL_Wnd::CanUndo() { return false; } @@ -490,7 +492,7 @@ void CPWL_Wnd::CreateVScrollBar(const CreateParams& cp) { scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; auto pBar = - pdfium::MakeUnique<CPWL_ScrollBar>(scp, CloneAttachedData(), SBT_VSCROLL); + std::make_unique<CPWL_ScrollBar>(scp, CloneAttachedData(), SBT_VSCROLL); m_pVScrollBar = pBar.get(); AddChild(std::move(pBar)); m_pVScrollBar->Realize(); @@ -659,9 +661,9 @@ void CPWL_Wnd::SetFontSize(float fFontSize) { CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { switch (nBorderStyle) { - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: return CFX_Color(CFX_Color::kGray, 1); - case BorderStyle::INSET: + case BorderStyle::kInset: return CFX_Color(CFX_Color::kGray, 0.5f); default: return CFX_Color(); @@ -670,9 +672,9 @@ CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { switch (nBorderStyle) { - case BorderStyle::BEVELED: + case BorderStyle::kBeveled: return GetBackgroundColor() / 2.0f; - case BorderStyle::INSET: + case BorderStyle::kInset: return CFX_Color(CFX_Color::kGray, 0.75f); default: return CFX_Color(); diff --git a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.h b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.h index 3523f87bfb2..b3730a0332b 100644 --- a/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.h +++ b/chromium/third_party/pdfium/fpdfsdk/pwl/cpwl_wnd.h @@ -112,24 +112,27 @@ class CPWL_Wnd : public Observable { CreateParams(const CreateParams& other); ~CreateParams(); - CFX_FloatRect rcRectWnd; // required - UnownedPtr<TimerHandlerIface> pTimerHandler; // required - UnownedPtr<IPWL_SystemHandler> pSystemHandler; // required - UnownedPtr<IPVT_FontMap> pFontMap; // required - ObservedPtr<ProviderIface> pProvider; // required - UnownedPtr<FocusHandlerIface> pFocusHandler; // optional - uint32_t dwFlags = 0; // optional - CFX_Color sBackgroundColor; // optional - BorderStyle nBorderStyle = BorderStyle::SOLID; // optional - int32_t dwBorderWidth = 1; // optional - CFX_Color sBorderColor; // optional - CFX_Color sTextColor; // optional - int32_t nTransparency = 255; // optional - float fFontSize; // optional - CPWL_Dash sDash; // optional - CPWL_MsgControl* pMsgControl = nullptr; // ignore - int32_t eCursorType = FXCT_ARROW; // ignore - CFX_Matrix mtChild; // ignore + // Required: + CFX_FloatRect rcRectWnd; + UnownedPtr<TimerHandlerIface> pTimerHandler; + UnownedPtr<IPWL_SystemHandler> pSystemHandler; + UnownedPtr<IPVT_FontMap> pFontMap; + ObservedPtr<ProviderIface> pProvider; + // Optional: + UnownedPtr<FocusHandlerIface> pFocusHandler; + uint32_t dwFlags = 0; + CFX_Color sBackgroundColor; + BorderStyle nBorderStyle = BorderStyle::kSolid; + int32_t dwBorderWidth = 1; + CFX_Color sBorderColor; + CFX_Color sTextColor; + int32_t nTransparency = 255; + float fFontSize; + CPWL_Dash sDash; + // Ignore: + CPWL_MsgControl* pMsgControl = nullptr; + int32_t eCursorType = FXCT_ARROW; + CFX_Matrix mtChild; }; static bool IsSHIFTKeyDown(uint32_t nFlag); @@ -172,6 +175,7 @@ class CPWL_Wnd : public Observable { virtual WideString GetText(); virtual WideString GetSelectedText(); virtual void ReplaceSelection(const WideString& text); + virtual bool SelectAllText(); virtual bool CanUndo(); virtual bool CanRedo(); |