summaryrefslogtreecommitdiff
path: root/chromium/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/pdf')
-rw-r--r--chromium/pdf/BUILD.gn67
-rw-r--r--chromium/pdf/DEPS4
-rw-r--r--chromium/pdf/DIR_METADATA4
-rw-r--r--chromium/pdf/accessibility.cc2
-rw-r--r--chromium/pdf/accessibility.h4
-rw-r--r--chromium/pdf/accessibility_helper.cc4
-rw-r--r--chromium/pdf/accessibility_structs.h6
-rw-r--r--chromium/pdf/document_layout.cc22
-rw-r--r--chromium/pdf/document_layout.h37
-rw-r--r--chromium/pdf/document_layout_unittest.cc128
-rw-r--r--chromium/pdf/document_loader_impl.cc4
-rw-r--r--chromium/pdf/draw_utils/coordinates.cc2
-rw-r--r--chromium/pdf/draw_utils/coordinates.h84
-rw-r--r--chromium/pdf/draw_utils/coordinates_unittest.cc2
-rw-r--r--chromium/pdf/features.gni6
-rw-r--r--chromium/pdf/out_of_process_instance.cc157
-rw-r--r--chromium/pdf/out_of_process_instance.h32
-rw-r--r--chromium/pdf/page_orientation.cc2
-rw-r--r--chromium/pdf/paint_aggregator.h8
-rw-r--r--chromium/pdf/paint_manager.cc2
-rw-r--r--chromium/pdf/paint_manager.h6
-rw-r--r--chromium/pdf/pdf.cc4
-rw-r--r--chromium/pdf/pdf.h86
-rw-r--r--chromium/pdf/pdf_engine.h72
-rw-r--r--chromium/pdf/pdf_features.cc2
-rw-r--r--chromium/pdf/pdf_transform.cc4
-rw-r--r--chromium/pdf/pdf_transform.h28
-rw-r--r--chromium/pdf/pdf_transform_unittest.cc8
-rw-r--r--chromium/pdf/pdf_utils/dates.cc22
-rw-r--r--chromium/pdf/pdf_view_plugin_base.cc39
-rw-r--r--chromium/pdf/pdf_view_plugin_base.h18
-rw-r--r--chromium/pdf/pdf_view_web_plugin.cc226
-rw-r--r--chromium/pdf/pdf_view_web_plugin.h86
-rw-r--r--chromium/pdf/pdf_view_web_plugin_unittest.cc324
-rw-r--r--chromium/pdf/pdfium/findtext_unittest.cc2
-rw-r--r--chromium/pdf/pdfium/pdfium_api_string_buffer_adapter.h38
-rw-r--r--chromium/pdf/pdfium/pdfium_assert_matching_enums.cc187
-rw-r--r--chromium/pdf/pdfium/pdfium_document.h4
-rw-r--r--chromium/pdf/pdfium/pdfium_engine.cc421
-rw-r--r--chromium/pdf/pdfium/pdfium_engine.h136
-rw-r--r--chromium/pdf/pdfium/pdfium_engine_exports.cc18
-rw-r--r--chromium/pdf/pdfium/pdfium_engine_exports.h4
-rw-r--r--chromium/pdf/pdfium/pdfium_engine_exports_unittest.cc27
-rw-r--r--chromium/pdf/pdfium/pdfium_engine_unittest.cc56
-rw-r--r--chromium/pdf/pdfium/pdfium_font_linux.cc2
-rw-r--r--chromium/pdf/pdfium/pdfium_font_linux.h2
-rw-r--r--chromium/pdf/pdfium/pdfium_form_filler.cc16
-rw-r--r--chromium/pdf/pdfium/pdfium_form_filler.h2
-rw-r--r--chromium/pdf/pdfium/pdfium_form_filler_unittest.cc19
-rw-r--r--chromium/pdf/pdfium/pdfium_page.cc58
-rw-r--r--chromium/pdf/pdfium/pdfium_page.h46
-rw-r--r--chromium/pdf/pdfium/pdfium_page_unittest.cc10
-rw-r--r--chromium/pdf/pdfium/pdfium_permissions.cc2
-rw-r--r--chromium/pdf/pdfium/pdfium_print.cc14
-rw-r--r--chromium/pdf/pdfium/pdfium_print.h10
-rw-r--r--chromium/pdf/pdfium/pdfium_print_unittest.cc4
-rw-r--r--chromium/pdf/pdfium/pdfium_test_base.h4
-rw-r--r--chromium/pdf/post_message_receiver.cc69
-rw-r--r--chromium/pdf/post_message_receiver.h17
-rw-r--r--chromium/pdf/ppapi_migration/graphics.cc3
-rw-r--r--chromium/pdf/ppapi_migration/graphics.h4
-rw-r--r--chromium/pdf/ppapi_migration/graphics_unittest.cc18
-rw-r--r--chromium/pdf/ppapi_migration/input_event_conversions.cc279
-rw-r--r--chromium/pdf/ppapi_migration/input_event_conversions.h218
-rw-r--r--chromium/pdf/ppapi_migration/ppapi_assert_matching_enums.cc106
-rw-r--r--chromium/pdf/ppapi_migration/value_conversions.cc4
-rw-r--r--chromium/pdf/ui/document_properties.cc4
-rw-r--r--chromium/pdf/ui/document_properties.h6
-rw-r--r--chromium/pdf/ui/document_properties_unittest.cc4
-rw-r--r--chromium/pdf/ui/thumbnail.cc4
-rw-r--r--chromium/pdf/url_loader_wrapper.h4
71 files changed, 1856 insertions, 1468 deletions
diff --git a/chromium/pdf/BUILD.gn b/chromium/pdf/BUILD.gn
index aa5cb6e45a4..16b69868340 100644
--- a/chromium/pdf/BUILD.gn
+++ b/chromium/pdf/BUILD.gn
@@ -20,16 +20,25 @@ buildflag_header("buildflags") {
}
if (enable_pdf) {
- config("pdf_common_config") {
+ config("common") {
configs = [ "//build/config/compiler:noshadowing" ]
+ }
+
+ config("strict") {
+ configs = [
+ ":common",
+ "//build/config/compiler:wexit_time_destructors",
+ ]
+ }
+ config("pdfium_includes") {
include_dirs = [ "//third_party/pdfium" ]
}
static_library("pdf") {
sources = [ "pdf.cc" ]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public = [ "pdf.h" ]
@@ -44,7 +53,7 @@ if (enable_pdf) {
static_library("pdf_ppapi") {
sources = [ "pdf_ppapi.cc" ]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public = [ "pdf_ppapi.h" ]
@@ -63,7 +72,7 @@ if (enable_pdf) {
source_set("features") {
sources = [ "pdf_features.cc" ]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public = [ "pdf_features.h" ]
@@ -150,7 +159,9 @@ if (enable_pdf) {
"url_loader_wrapper_impl.h",
]
- configs += [ ":pdf_common_config" ]
+ public_configs = [ ":pdfium_includes" ]
+
+ configs += [ ":strict" ]
public_deps = [ "//skia" ]
@@ -168,10 +179,13 @@ if (enable_pdf) {
"//ppapi/cpp:objects",
"//ppapi/cpp/private:internal_module",
"//printing",
+ "//third_party/blink/public/common:headers",
"//third_party/icu",
"//third_party/pdfium",
"//ui/base",
"//ui/base/cursor/mojom:cursor_type",
+ "//ui/events:events_base",
+ "//ui/events/blink",
"//ui/gfx/codec",
"//ui/gfx/range",
]
@@ -187,9 +201,14 @@ if (enable_pdf) {
source_set("assert_enums") {
visibility = [ ":*" ]
- sources = [ "pdfium/pdfium_assert_matching_enums.cc" ]
+ testonly = true
- configs += [ ":pdf_common_config" ]
+ sources = [
+ "pdfium/pdfium_assert_matching_enums.cc",
+ "ppapi_migration/ppapi_assert_matching_enums.cc",
+ ]
+
+ configs += [ ":common" ]
deps = [
":accessibility_structs",
@@ -197,6 +216,7 @@ if (enable_pdf) {
":pdf",
":ppapi_migration",
"//ppapi/c",
+ "//third_party/blink/public/common:headers",
"//third_party/pdfium",
"//ui/base",
]
@@ -212,7 +232,7 @@ if (enable_pdf) {
"accessibility_structs.h",
]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
deps = [
"//base",
@@ -242,7 +262,7 @@ if (enable_pdf) {
"ppapi_migration/value_conversions.h",
]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public_deps = [ "//third_party/abseil-cpp:absl" ]
@@ -251,6 +271,7 @@ if (enable_pdf) {
"//ppapi/cpp:objects",
"//skia",
"//third_party/blink/public:blink",
+ "//third_party/blink/public/common:headers",
"//ui/base",
"//ui/base/cursor/mojom:cursor_type",
"//ui/gfx",
@@ -265,7 +286,7 @@ if (enable_pdf) {
"out_of_process_instance.h",
]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public_deps = [ "//third_party/abseil-cpp:absl" ]
@@ -280,6 +301,7 @@ if (enable_pdf) {
"//ppapi/cpp:objects",
"//ppapi/cpp/private:internal_module",
"//skia",
+ "//third_party/blink/public/common:headers",
"//ui/base",
"//ui/base/cursor/mojom:cursor_type",
]
@@ -300,7 +322,7 @@ if (enable_pdf) {
"post_message_sender.h",
]
- configs += [ ":pdf_common_config" ]
+ configs += [ ":strict" ]
public = [ "pdf_view_web_plugin.h" ]
@@ -315,8 +337,10 @@ if (enable_pdf) {
"//ppapi/cpp:objects", # TODO(crbug.com/1114263): PDFEngine::Client only.
"//skia",
"//third_party/blink/public:blink_headers",
+ "//third_party/blink/public/common:headers",
"//ui/base/cursor:cursor_base",
"//ui/base/cursor/mojom:cursor_type",
+ "//ui/events/blink",
"//v8",
]
}
@@ -331,9 +355,11 @@ if (enable_pdf) {
"test/test_client.h",
"test/test_document_loader.cc",
"test/test_document_loader.h",
+ "test/test_helpers.cc",
+ "test/test_helpers.h",
]
- configs += [ "//build/config/compiler:noshadowing" ]
+ configs += [ ":common" ]
deps = [
":internal",
@@ -341,6 +367,7 @@ if (enable_pdf) {
"//base",
"//ppapi/cpp:objects",
"//testing/gtest",
+ "//ui/gfx:geometry_skia",
"//ui/gfx/range",
]
}
@@ -357,6 +384,7 @@ if (enable_pdf) {
"pdf_transform_unittest.cc",
"pdf_utils/dates_unittest.cc",
"pdf_view_plugin_base_unittest.cc",
+ "pdf_view_web_plugin_unittest.cc",
"pdfium/accessibility_unittest.cc",
"pdfium/findtext_unittest.cc",
"pdfium/pdfium_engine_exports_unittest.cc",
@@ -377,10 +405,7 @@ if (enable_pdf) {
"ui/thumbnail_unittest.cc",
]
- configs += [
- ":pdf_common_config",
- "//v8:external_startup_data",
- ]
+ configs += [ ":common" ]
data = [ "test/data/" ]
@@ -400,6 +425,8 @@ if (enable_pdf) {
"//cc:test_support",
"//components/strings",
"//gin",
+ "//mojo/core/embedder",
+ "//mojo/public/cpp/bindings",
"//ppapi/c",
"//ppapi/cpp:objects",
"//printing",
@@ -407,6 +434,8 @@ if (enable_pdf) {
"//testing/gmock",
"//testing/gtest",
"//third_party/blink/public:blink",
+ "//third_party/blink/public:test_support",
+ "//third_party/blink/public/common:headers",
"//third_party/pdfium",
"//ui/base:test_support",
"//ui/gfx:test_support",
@@ -415,7 +444,11 @@ if (enable_pdf) {
]
if (v8_use_external_startup_data) {
- data += [ "$root_out_dir/snapshot_blob.bin" ]
+ deps += [ "//tools/v8_context_snapshot" ]
+ configs += [
+ "//tools/v8_context_snapshot:use_v8_context_snapshot",
+ "//v8:external_startup_data",
+ ]
}
}
diff --git a/chromium/pdf/DEPS b/chromium/pdf/DEPS
index 184bbb1bb23..03c93c39482 100644
--- a/chromium/pdf/DEPS
+++ b/chromium/pdf/DEPS
@@ -2,13 +2,15 @@ include_rules = [
"+cc/paint",
"+content/public/renderer/v8_value_converter.h",
"+gin",
+ "+mojo/core/embedder",
+ "+mojo/public/cpp/bindings",
"+net",
"+ppapi",
"+printing",
"+third_party/blink/public",
"+third_party/skia/include/core",
"+ui/base",
- "+ui/events/keycodes/keyboard_codes.h",
+ "+ui/events",
"+ui/gfx",
"+v8/include/v8.h"
]
diff --git a/chromium/pdf/DIR_METADATA b/chromium/pdf/DIR_METADATA
index 22fab08d651..8734c2bd51c 100644
--- a/chromium/pdf/DIR_METADATA
+++ b/chromium/pdf/DIR_METADATA
@@ -1,10 +1,10 @@
# Metadata information for this directory.
#
# For more information on DIR_METADATA files, see:
-# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+# https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/tools/dirmd/README.md
#
# For the schema of this file, see Metadata message:
-# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+# https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/tools/dirmd/proto/dir_metadata.proto
monorail {
component: "Internals>Plugins>PDF"
diff --git a/chromium/pdf/accessibility.cc b/chromium/pdf/accessibility.cc
index fa07862a295..65e663ede8f 100644
--- a/chromium/pdf/accessibility.cc
+++ b/chromium/pdf/accessibility.cc
@@ -58,7 +58,7 @@ bool GetAccessibilityInfo(PDFEngine* engine,
int char_index = 0;
while (char_index < char_count) {
- base::Optional<AccessibilityTextRunInfo> text_run_info_result =
+ absl::optional<AccessibilityTextRunInfo> text_run_info_result =
engine->GetTextRunInfo(page_index, char_index);
DCHECK(text_run_info_result.has_value());
const auto& text_run_info = text_run_info_result.value();
diff --git a/chromium/pdf/accessibility.h b/chromium/pdf/accessibility.h
index 52c6ffcf006..a06d42a6956 100644
--- a/chromium/pdf/accessibility.h
+++ b/chromium/pdf/accessibility.h
@@ -17,8 +17,8 @@ struct AccessibilityPageInfo;
struct AccessibilityPageObjects;
struct AccessibilityTextRunInfo;
-// Retrieve |page_info|, |text_runs|, |chars|, and |page_objects| from
-// |engine| for the page at 0-indexed |page_index|. Returns true on success with
+// Retrieve `page_info`, `text_runs`, `chars`, and `page_objects` from
+// `engine` for the page at 0-indexed `page_index`. Returns true on success with
// all out parameters filled, or false on failure with all out parameters
// untouched.
bool GetAccessibilityInfo(PDFEngine* engine,
diff --git a/chromium/pdf/accessibility_helper.cc b/chromium/pdf/accessibility_helper.cc
index 3217cbe4f2f..1822badd389 100644
--- a/chromium/pdf/accessibility_helper.cc
+++ b/chromium/pdf/accessibility_helper.cc
@@ -9,8 +9,8 @@
#include <vector>
#include "base/numerics/safe_math.h"
-#include "base/optional.h"
#include "pdf/accessibility_structs.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace chrome_pdf {
@@ -38,7 +38,7 @@ AccessibilityTextRunRangeInfo GetEnclosingTextRunRangeForCharRange(
return text_range;
uint32_t end_char_index = checked_end_char_index.ValueOrDie();
uint32_t current_char_index = 0;
- base::Optional<uint32_t> start_text_run;
+ absl::optional<uint32_t> start_text_run;
for (size_t i = 0; i < text_runs.size(); ++i) {
if (!start_text_run.has_value() &&
IsCharWithinTextRun(text_runs[i], current_char_index,
diff --git a/chromium/pdf/accessibility_structs.h b/chromium/pdf/accessibility_structs.h
index cfce34ac515..7bdb1b7a7c8 100644
--- a/chromium/pdf/accessibility_structs.h
+++ b/chromium/pdf/accessibility_structs.h
@@ -297,13 +297,13 @@ struct AccessibilityButtonInfo {
// Represents count of controls in the control group. A group of interactive
// form annotations is collectively called a form control group. Here, an
// interactive form annotation, should be either a radio button or a
- // checkbox. Value of |control_count| is >= 1.
+ // checkbox. Value of `control_count` is >= 1.
uint32_t control_count = 0;
// Represents index of the control in the control group. A group of
// interactive form annotations is collectively called a form control group.
// Here, an interactive form annotation, should be either a radio button or
- // a checkbox. Value of |control_index| should always be less than
- // |control_count|.
+ // a checkbox. Value of `control_index` should always be less than
+ // `control_count`.
uint32_t control_index = 0;
// Index of this button in the collection of buttons in the page.
uint32_t index_in_page = 0;
diff --git a/chromium/pdf/document_layout.cc b/chromium/pdf/document_layout.cc
index 9f5b12c460c..f13d7d066e9 100644
--- a/chromium/pdf/document_layout.cc
+++ b/chromium/pdf/document_layout.cc
@@ -53,7 +53,8 @@ base::Value DocumentLayout::Options::ToValue() const {
base::Value dictionary(base::Value::Type::DICTIONARY);
dictionary.SetIntKey(kDefaultPageOrientation,
static_cast<int32_t>(default_page_orientation_));
- dictionary.SetBoolKey(kTwoUpViewEnabled, two_up_view_enabled_);
+ dictionary.SetBoolKey(kTwoUpViewEnabled,
+ page_spread_ == PageSpread::kTwoUpOdd);
return dictionary;
}
@@ -61,7 +62,7 @@ void DocumentLayout::Options::FromValue(const base::Value& value) {
DCHECK(value.is_dict());
int32_t default_page_orientation =
- value.FindKey(kDefaultPageOrientation)->GetInt();
+ value.FindIntKey(kDefaultPageOrientation).value();
DCHECK_GE(default_page_orientation,
static_cast<int32_t>(PageOrientation::kOriginal));
DCHECK_LE(default_page_orientation,
@@ -69,7 +70,9 @@ void DocumentLayout::Options::FromValue(const base::Value& value) {
default_page_orientation_ =
static_cast<PageOrientation>(default_page_orientation);
- two_up_view_enabled_ = value.FindKey(kTwoUpViewEnabled)->GetBool();
+ page_spread_ = value.FindBoolKey(kTwoUpViewEnabled).value()
+ ? PageSpread::kTwoUpOdd
+ : PageSpread::kOneUp;
}
void DocumentLayout::Options::RotatePagesClockwise() {
@@ -98,7 +101,16 @@ void DocumentLayout::SetOptions(const Options& options) {
options_ = options;
}
-void DocumentLayout::ComputeSingleViewLayout(
+void DocumentLayout::ComputeLayout(const std::vector<gfx::Size>& page_sizes) {
+ switch (options_.page_spread()) {
+ case PageSpread::kOneUp:
+ return ComputeOneUpLayout(page_sizes);
+ case PageSpread::kTwoUpOdd:
+ return ComputeTwoUpOddLayout(page_sizes);
+ }
+}
+
+void DocumentLayout::ComputeOneUpLayout(
const std::vector<gfx::Size>& page_sizes) {
gfx::Size document_size(GetWidestPageWidth(page_sizes), 0);
@@ -130,7 +142,7 @@ void DocumentLayout::ComputeSingleViewLayout(
}
}
-void DocumentLayout::ComputeTwoUpViewLayout(
+void DocumentLayout::ComputeTwoUpOddLayout(
const std::vector<gfx::Size>& page_sizes) {
gfx::Size document_size(GetWidestPageWidth(page_sizes), 0);
diff --git a/chromium/pdf/document_layout.h b/chromium/pdf/document_layout.h
index fb028424e55..4bd6cadf658 100644
--- a/chromium/pdf/document_layout.h
+++ b/chromium/pdf/document_layout.h
@@ -25,10 +25,16 @@ namespace chrome_pdf {
//
// All layout units are pixels.
//
-// The |Options| class controls the behavior of the layout, such as the default
+// The `Options` class controls the behavior of the layout, such as the default
// orientation of pages.
class DocumentLayout final {
public:
+ // TODO(crbug.com/1144505): Add `kTwoUpEven` page spread support.
+ enum class PageSpread {
+ kOneUp = 0, // One page per spread.
+ kTwoUpOdd = 1, // Two pages per spread, with odd pages first.
+ };
+
// Options controlling layout behavior.
class Options final {
public:
@@ -40,7 +46,7 @@ class DocumentLayout final {
~Options();
friend bool operator==(const Options& lhs, const Options& rhs) {
- return lhs.two_up_view_enabled() == rhs.two_up_view_enabled() &&
+ return lhs.page_spread() == rhs.page_spread() &&
lhs.default_page_orientation() == rhs.default_page_orientation();
}
@@ -64,14 +70,14 @@ class DocumentLayout final {
// Rotates default page orientation 90 degrees counterclockwise.
void RotatePagesCounterclockwise();
- bool two_up_view_enabled() const { return two_up_view_enabled_; }
+ PageSpread page_spread() const { return page_spread_; }
// Changes two-up view status.
- void set_two_up_view_enabled(bool enable) { two_up_view_enabled_ = enable; }
+ void set_page_spread(PageSpread spread) { page_spread_ = spread; }
private:
PageOrientation default_page_orientation_ = PageOrientation::kOriginal;
- bool two_up_view_enabled_ = false;
+ PageSpread page_spread_ = PageSpread::kOneUp;
};
static const draw_utils::PageInsetSizes kSingleViewInsets;
@@ -121,15 +127,8 @@ class DocumentLayout final {
return page_layouts_[page_index].inner_rect;
}
- // Computes layout that represent |page_sizes| formatted for single view.
- //
- // TODO(kmoon): Control layout type using an option.
- void ComputeSingleViewLayout(const std::vector<gfx::Size>& page_sizes);
-
- // Computes layout that represent |page_sizes| formatted for two-up view.
- //
- // TODO(kmoon): Control layout type using an option.
- void ComputeTwoUpViewLayout(const std::vector<gfx::Size>& page_sizes);
+ // Computes the layout for a given list of `page_sizes` based on `options_`.
+ void ComputeLayout(const std::vector<gfx::Size>& page_sizes);
private:
// Layout of a single page.
@@ -141,15 +140,19 @@ class DocumentLayout final {
gfx::Rect inner_rect;
};
- // Copies |source_rect| to |destination_rect|, setting |dirty_| to true if
- // |destination_rect| is modified as a result.
+ // Helpers for ComputeLayout() handling different page spreads.
+ void ComputeOneUpLayout(const std::vector<gfx::Size>& page_sizes);
+ void ComputeTwoUpOddLayout(const std::vector<gfx::Size>& page_sizes);
+
+ // Copies `source_rect` to `destination_rect`, setting `dirty_` to true if
+ // `destination_rect` is modified as a result.
void CopyRectIfModified(const gfx::Rect& source_rect,
gfx::Rect& destination_rect);
Options options_;
// Indicates if the layout has changed in an externally-observable way,
- // usually as a result of calling |ComputeLayout()| with different inputs.
+ // usually as a result of calling `ComputeLayout()` with different inputs.
//
// Some operations that may trigger layout changes:
// * Changing page sizes
diff --git a/chromium/pdf/document_layout_unittest.cc b/chromium/pdf/document_layout_unittest.cc
index b65c1941ba6..b10e6e353ef 100644
--- a/chromium/pdf/document_layout_unittest.cc
+++ b/chromium/pdf/document_layout_unittest.cc
@@ -17,42 +17,37 @@ class DocumentLayoutOptionsTest : public testing::Test {
DocumentLayout::Options options_;
};
-class DocumentLayoutTest : public testing::Test {
- protected:
- DocumentLayout layout_;
-};
-
TEST_F(DocumentLayoutOptionsTest, DefaultConstructor) {
EXPECT_EQ(options_.default_page_orientation(), PageOrientation::kOriginal);
- EXPECT_FALSE(options_.two_up_view_enabled());
+ EXPECT_EQ(options_.page_spread(), DocumentLayout::PageSpread::kOneUp);
}
TEST_F(DocumentLayoutOptionsTest, CopyConstructor) {
options_.RotatePagesClockwise();
- options_.set_two_up_view_enabled(true);
+ options_.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
DocumentLayout::Options copy(options_);
EXPECT_EQ(copy.default_page_orientation(), PageOrientation::kClockwise90);
- EXPECT_TRUE(copy.two_up_view_enabled());
+ EXPECT_EQ(copy.page_spread(), DocumentLayout::PageSpread::kTwoUpOdd);
options_.RotatePagesClockwise();
- options_.set_two_up_view_enabled(false);
+ options_.set_page_spread(DocumentLayout::PageSpread::kOneUp);
EXPECT_EQ(copy.default_page_orientation(), PageOrientation::kClockwise90);
- EXPECT_TRUE(copy.two_up_view_enabled());
+ EXPECT_EQ(copy.page_spread(), DocumentLayout::PageSpread::kTwoUpOdd);
}
TEST_F(DocumentLayoutOptionsTest, CopyAssignment) {
options_.RotatePagesClockwise();
- options_.set_two_up_view_enabled(true);
+ options_.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
DocumentLayout::Options copy = options_;
EXPECT_EQ(copy.default_page_orientation(), PageOrientation::kClockwise90);
- EXPECT_TRUE(copy.two_up_view_enabled());
+ EXPECT_EQ(copy.page_spread(), DocumentLayout::PageSpread::kTwoUpOdd);
options_.RotatePagesClockwise();
- options_.set_two_up_view_enabled(false);
+ options_.set_page_spread(DocumentLayout::PageSpread::kOneUp);
EXPECT_EQ(copy.default_page_orientation(), PageOrientation::kClockwise90);
- EXPECT_TRUE(copy.two_up_view_enabled());
+ EXPECT_EQ(copy.page_spread(), DocumentLayout::PageSpread::kTwoUpOdd);
}
TEST_F(DocumentLayoutOptionsTest, Equals) {
@@ -73,16 +68,16 @@ TEST_F(DocumentLayoutOptionsTest, Equals) {
copy.RotatePagesCounterclockwise();
EXPECT_TRUE(copy == options_);
- options_.set_two_up_view_enabled(true);
+ options_.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
EXPECT_FALSE(copy == options_);
- copy.set_two_up_view_enabled(true);
+ copy.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
EXPECT_TRUE(copy == options_);
- options_.set_two_up_view_enabled(false);
+ options_.set_page_spread(DocumentLayout::PageSpread::kOneUp);
EXPECT_FALSE(copy == options_);
- copy.set_two_up_view_enabled(false);
+ copy.set_page_spread(DocumentLayout::PageSpread::kOneUp);
EXPECT_TRUE(copy == options_);
}
@@ -133,17 +128,29 @@ TEST_F(DocumentLayoutOptionsTest, RotatePagesCounterclockwise) {
EXPECT_EQ(options_.default_page_orientation(), PageOrientation::kOriginal);
}
+class DocumentLayoutTest : public testing::Test {
+ protected:
+ void SetPageSpread(DocumentLayout::PageSpread page_spread) {
+ DocumentLayout::Options options;
+ options.set_page_spread(page_spread);
+ layout_.SetOptions(options);
+ }
+
+ DocumentLayout layout_;
+};
+
TEST_F(DocumentLayoutTest, DefaultConstructor) {
EXPECT_EQ(layout_.options().default_page_orientation(),
PageOrientation::kOriginal);
- EXPECT_FALSE(layout_.options().two_up_view_enabled());
+ EXPECT_EQ(layout_.options().page_spread(),
+ DocumentLayout::PageSpread::kOneUp);
EXPECT_FALSE(layout_.dirty());
EXPECT_EQ(layout_.size(), gfx::Size(0, 0));
EXPECT_EQ(layout_.page_count(), 0u);
}
TEST_F(DocumentLayoutTest, SetOptionsDoesNotRecomputeLayout) {
- layout_.ComputeSingleViewLayout({gfx::Size(100, 200)});
+ layout_.ComputeLayout({{100, 200}});
EXPECT_EQ(layout_.size(), gfx::Size(100, 200));
DocumentLayout::Options options;
@@ -165,28 +172,30 @@ TEST_F(DocumentLayoutTest, DirtySetOnOptionsChange) {
layout_.clear_dirty();
- options.set_two_up_view_enabled(true);
+ options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
layout_.SetOptions(options);
EXPECT_TRUE(layout_.dirty());
}
TEST_F(DocumentLayoutTest, DirtyNotSetOnSameOptions) {
DocumentLayout::Options options;
- options.set_two_up_view_enabled(true);
+ options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
layout_.SetOptions(options);
EXPECT_TRUE(layout_.dirty());
layout_.clear_dirty();
- options.set_two_up_view_enabled(true);
+ options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
layout_.SetOptions(options);
EXPECT_FALSE(layout_.dirty());
}
-TEST_F(DocumentLayoutTest, ComputeSingleViewLayout) {
+TEST_F(DocumentLayoutTest, ComputeLayoutOneUp) {
+ SetPageSpread(DocumentLayout::PageSpread::kOneUp);
+
std::vector<gfx::Size> page_sizes{
{300, 400}, {400, 500}, {300, 400}, {200, 300}};
- layout_.ComputeSingleViewLayout(page_sizes);
+ layout_.ComputeLayout(page_sizes);
ASSERT_EQ(4u, layout_.page_count());
EXPECT_EQ(gfx::Rect(50, 0, 300, 400), layout_.page_rect(0));
EXPECT_EQ(gfx::Rect(0, 404, 400, 500), layout_.page_rect(1));
@@ -199,7 +208,7 @@ TEST_F(DocumentLayoutTest, ComputeSingleViewLayout) {
EXPECT_EQ(gfx::Size(400, 1612), layout_.size());
page_sizes = {{240, 300}, {320, 400}, {250, 360}, {300, 600}, {270, 555}};
- layout_.ComputeSingleViewLayout(page_sizes);
+ layout_.ComputeLayout(page_sizes);
ASSERT_EQ(5u, layout_.page_count());
EXPECT_EQ(gfx::Rect(40, 0, 240, 300), layout_.page_rect(0));
EXPECT_EQ(gfx::Rect(0, 304, 320, 400), layout_.page_rect(1));
@@ -214,11 +223,36 @@ TEST_F(DocumentLayoutTest, ComputeSingleViewLayout) {
EXPECT_EQ(gfx::Size(320, 2231), layout_.size());
}
-TEST_F(DocumentLayoutTest, ComputeTwoUpViewLayout) {
+TEST_F(DocumentLayoutTest, DirtySetOnLayoutInputChangeOneUp) {
+ SetPageSpread(DocumentLayout::PageSpread::kOneUp);
+
+ layout_.ComputeLayout({{100, 200}});
+ EXPECT_TRUE(layout_.dirty());
+ layout_.clear_dirty();
+ EXPECT_FALSE(layout_.dirty());
+
+ layout_.ComputeLayout({{100, 200}});
+ EXPECT_FALSE(layout_.dirty());
+
+ layout_.ComputeLayout({{200, 100}});
+ EXPECT_TRUE(layout_.dirty());
+ layout_.clear_dirty();
+
+ layout_.ComputeLayout({{200, 100}, {300, 300}});
+ EXPECT_TRUE(layout_.dirty());
+ layout_.clear_dirty();
+
+ layout_.ComputeLayout({{200, 100}});
+ EXPECT_TRUE(layout_.dirty());
+}
+
+TEST_F(DocumentLayoutTest, ComputeLayoutTwoUpOdd) {
+ SetPageSpread(DocumentLayout::PageSpread::kTwoUpOdd);
+
// Test case where the widest page is on the right.
std::vector<gfx::Size> page_sizes{
{826, 1066}, {1066, 826}, {826, 1066}, {826, 900}};
- layout_.ComputeTwoUpViewLayout(page_sizes);
+ layout_.ComputeLayout(page_sizes);
ASSERT_EQ(4u, layout_.page_count());
EXPECT_EQ(gfx::Rect(240, 0, 826, 1066), layout_.page_rect(0));
EXPECT_EQ(gfx::Rect(1066, 0, 1066, 826), layout_.page_rect(1));
@@ -232,7 +266,7 @@ TEST_F(DocumentLayoutTest, ComputeTwoUpViewLayout) {
// Test case where the widest page is on the left.
page_sizes = {{1066, 826}, {820, 1056}, {820, 890}, {826, 1066}};
- layout_.ComputeTwoUpViewLayout(page_sizes);
+ layout_.ComputeLayout(page_sizes);
ASSERT_EQ(4u, layout_.page_count());
EXPECT_EQ(gfx::Rect(0, 0, 1066, 826), layout_.page_rect(0));
EXPECT_EQ(gfx::Rect(1066, 0, 820, 1056), layout_.page_rect(1));
@@ -246,7 +280,7 @@ TEST_F(DocumentLayoutTest, ComputeTwoUpViewLayout) {
// Test case where there's an odd # of pages.
page_sizes = {{200, 300}, {400, 200}, {300, 600}, {250, 500}, {300, 400}};
- layout_.ComputeTwoUpViewLayout(page_sizes);
+ layout_.ComputeLayout(page_sizes);
ASSERT_EQ(5u, layout_.page_count());
EXPECT_EQ(gfx::Rect(200, 0, 200, 300), layout_.page_rect(0));
EXPECT_EQ(gfx::Rect(400, 0, 400, 200), layout_.page_rect(1));
@@ -261,46 +295,26 @@ TEST_F(DocumentLayoutTest, ComputeTwoUpViewLayout) {
EXPECT_EQ(gfx::Size(800, 1300), layout_.size());
}
-TEST_F(DocumentLayoutTest, DirtySetOnSingleViewLayoutInputChange) {
- layout_.ComputeSingleViewLayout({gfx::Size(100, 200)});
- EXPECT_TRUE(layout_.dirty());
- layout_.clear_dirty();
- EXPECT_FALSE(layout_.dirty());
-
- layout_.ComputeSingleViewLayout({gfx::Size(100, 200)});
- EXPECT_FALSE(layout_.dirty());
-
- layout_.ComputeSingleViewLayout({gfx::Size(200, 100)});
- EXPECT_TRUE(layout_.dirty());
- layout_.clear_dirty();
-
- layout_.ComputeSingleViewLayout({gfx::Size(200, 100), gfx::Size(300, 300)});
- EXPECT_TRUE(layout_.dirty());
- layout_.clear_dirty();
-
- layout_.ComputeSingleViewLayout({gfx::Size(200, 100)});
- EXPECT_TRUE(layout_.dirty());
-}
+TEST_F(DocumentLayoutTest, DirtySetOnLayoutInputChangeTwoUpOdd) {
+ SetPageSpread(DocumentLayout::PageSpread::kTwoUpOdd);
-TEST_F(DocumentLayoutTest, DirtySetOnTwoUpViewLayoutInputChange) {
- layout_.ComputeTwoUpViewLayout({gfx::Size(100, 200), gfx::Size(200, 100)});
+ layout_.ComputeLayout({{100, 200}, {200, 100}});
EXPECT_TRUE(layout_.dirty());
layout_.clear_dirty();
EXPECT_FALSE(layout_.dirty());
- layout_.ComputeTwoUpViewLayout({gfx::Size(100, 200), gfx::Size(200, 100)});
+ layout_.ComputeLayout({{100, 200}, {200, 100}});
EXPECT_FALSE(layout_.dirty());
- layout_.ComputeTwoUpViewLayout({gfx::Size(200, 100), gfx::Size(100, 200)});
+ layout_.ComputeLayout({{200, 100}, {100, 200}});
EXPECT_TRUE(layout_.dirty());
layout_.clear_dirty();
- layout_.ComputeTwoUpViewLayout(
- {gfx::Size(200, 100), gfx::Size(100, 200), gfx::Size(300, 300)});
+ layout_.ComputeLayout({{200, 100}, {100, 200}, {300, 300}});
EXPECT_TRUE(layout_.dirty());
layout_.clear_dirty();
- layout_.ComputeTwoUpViewLayout({gfx::Size(200, 100), gfx::Size(100, 200)});
+ layout_.ComputeLayout({{200, 100}, {100, 200}});
EXPECT_TRUE(layout_.dirty());
}
diff --git a/chromium/pdf/document_loader_impl.cc b/chromium/pdf/document_loader_impl.cc
index 3f403d08012..3fb1393db54 100644
--- a/chromium/pdf/document_loader_impl.cc
+++ b/chromium/pdf/document_loader_impl.cc
@@ -32,7 +32,7 @@ namespace {
// Experimentally chosen value.
constexpr int kChunkCloseDistance = 10;
-// Return true if the HTTP response of |loader| is a successful one and loading
+// Return true if the HTTP response of `loader` is a successful one and loading
// should continue. 4xx error indicate subsequent requests will fail too.
// e.g. resource has been removed from the server while loading it. 301
// indicates a redirect was returned which won't be successful because we
@@ -379,7 +379,7 @@ uint32_t DocumentLoaderImpl::EndOfCurrentChunk() const {
void DocumentLoaderImpl::ReadComplete() {
if (GetDocumentSize() != 0) {
- // If there is remaining data in |chunk_|, then save whatever can be saved.
+ // If there is remaining data in `chunk_`, then save whatever can be saved.
// e.g. In the underrun case.
if (chunk_.data_size != 0)
SaveChunkData();
diff --git a/chromium/pdf/draw_utils/coordinates.cc b/chromium/pdf/draw_utils/coordinates.cc
index 91f6a78a63b..3161cee1c28 100644
--- a/chromium/pdf/draw_utils/coordinates.cc
+++ b/chromium/pdf/draw_utils/coordinates.cc
@@ -83,7 +83,7 @@ PageInsetSizes GetPageInsetsForTwoUpView(
int horizontal_separator) {
DCHECK_LT(page_index, num_of_pages);
- // Don't change |two_up_insets| if the page is on the left side and is the
+ // Don't change `two_up_insets` if the page is on the left side and is the
// last page. In this case, the shadows on both sides should be the same size.
PageInsetSizes two_up_insets = single_view_insets;
if (page_index % 2 == 1)
diff --git a/chromium/pdf/draw_utils/coordinates.h b/chromium/pdf/draw_utils/coordinates.h
index 3805c21036d..7fd72d64888 100644
--- a/chromium/pdf/draw_utils/coordinates.h
+++ b/chromium/pdf/draw_utils/coordinates.h
@@ -41,38 +41,38 @@ struct IndexedPage {
gfx::Rect rect;
};
-// Given a right page's |bottom_gap|, reduce it to only the part of |bottom_gap|
-// that is directly below the right page by translating |bottom_gap| to |page_x|
+// Given a right page's `bottom_gap`, reduce it to only the part of `bottom_gap`
+// that is directly below the right page by translating `bottom_gap` to `page_x`
// and halving its width. This avoids over-drawing empty space on the already
// drawn left page and the empty space to the right of the page.
void AdjustBottomGapForRightSidePage(int page_x, gfx::Rect* bottom_gap);
-// Given |doc_width|, horizontally center |rect| within the document.
-// |doc_width| must be greater than or equal to |rect|.
+// Given `doc_width`, horizontally center `rect` within the document.
+// `doc_width` must be greater than or equal to `rect`.
void CenterRectHorizontally(int doc_width, gfx::Rect* rect);
-// Given |rect_size|, sets the width of |doc_size| to the max of |rect_size|'s
-// width and |doc_size|'s width. Also adds the height of |rect_size| to
-// |doc_size|'s height.
+// Given `rect_size`, sets the width of `doc_size` to the max of `rect_size`'s
+// width and `doc_size`'s width. Also adds the height of `rect_size` to
+// `doc_size`'s height.
void ExpandDocumentSize(const gfx::Size& rect_size, gfx::Size* doc_size);
-// Given |page_rect_bottom| and |bottom_rect| in the same coordinate space,
-// return a gfx::Rect object representing the portion of |bottom_rect| that is
-// below |page_rect_bottom|. Returns an empty rectangle if |page_rect_bottom|
-// is greater than or equal to |bottom_rect.bottom()|.
+// Given `page_rect_bottom` and `bottom_rect` in the same coordinate space,
+// return a gfx::Rect object representing the portion of `bottom_rect` that is
+// below `page_rect_bottom`. Returns an empty rectangle if `page_rect_bottom`
+// is greater than or equal to `bottom_rect.bottom()`.
gfx::Rect GetBottomGapBetweenRects(int page_rect_bottom,
const gfx::Rect& bottom_rect);
-// Given |visible_pages| and |visible_screen| in the same coordinates, return
-// the index of the page in |visible_pages| which has the largest proportion of
-// its area intersecting with |visible_screen|. If there is a tie, return the
-// page with the lower index. Returns -1 if |visible_pages| is empty. Returns
-// first page in |visible_pages| if no page intersects with |visible_screen|.
+// Given `visible_pages` and `visible_screen` in the same coordinates, return
+// the index of the page in `visible_pages` which has the largest proportion of
+// its area intersecting with `visible_screen`. If there is a tie, return the
+// page with the lower index. Returns -1 if `visible_pages` is empty. Returns
+// first page in `visible_pages` if no page intersects with `visible_screen`.
int GetMostVisiblePage(const std::vector<IndexedPage>& visible_pages,
const gfx::Rect& visible_screen);
-// Given |page_index|, and |num_of_pages|, return the configuration of
-// |single_view_insets| and |horizontal_separator| for the current page in
+// Given `page_index`, and `num_of_pages`, return the configuration of
+// `single_view_insets` and `horizontal_separator` for the current page in
// two-up view.
PageInsetSizes GetPageInsetsForTwoUpView(
size_t page_index,
@@ -80,23 +80,23 @@ PageInsetSizes GetPageInsetsForTwoUpView(
const PageInsetSizes& single_view_insets,
int horizontal_separator);
-// Given |rect_size| and |document_size| create a horizontally centered
+// Given `rect_size` and `document_size` create a horizontally centered
// gfx::Rect placed at the bottom of the current document.
gfx::Rect GetRectForSingleView(const gfx::Size& rect_size,
const gfx::Size& document_size);
-// Given |rect| in document coordinates, a |position| in screen coordinates,
-// and a |zoom| factor, returns the rectangle in screen coordinates (i.e.
-// 0,0 is top left corner of plugin area). An empty |rect| will always
-// result in an empty output rect. For |zoom|, a value of 1 means 100%.
-// |zoom| is never less than or equal to 0.
+// Given `rect` in document coordinates, a `position` in screen coordinates,
+// and a `zoom` factor, returns the rectangle in screen coordinates (i.e.
+// 0,0 is top left corner of plugin area). An empty `rect` will always
+// result in an empty output rect. For `zoom`, a value of 1 means 100%.
+// `zoom` is never less than or equal to 0.
gfx::Rect GetScreenRect(const gfx::Rect& rect,
const gfx::Point& position,
double zoom);
-// Given |page_y|, |page_height|, |inset_sizes|, |doc_width|, and
-// |bottom_separator| all in the same coordinate space, return the page and its
-// surrounding border areas and |bottom_separator|. This includes the sides if
+// Given `page_y`, `page_height`, `inset_sizes`, `doc_width`, and
+// `bottom_separator` all in the same coordinate space, return the page and its
+// surrounding border areas and `bottom_separator`. This includes the sides if
// the page is narrower than the document.
gfx::Rect GetSurroundingRect(int page_y,
int page_height,
@@ -104,38 +104,38 @@ gfx::Rect GetSurroundingRect(int page_y,
int doc_width,
int bottom_separator);
-// Given |page_rect| in document coordinates, |inset_sizes|, and
-// |bottom_separator|, return a gfx::Rect object representing the gap on the
+// Given `page_rect` in document coordinates, `inset_sizes`, and
+// `bottom_separator`, return a gfx::Rect object representing the gap on the
// left side of the page created by insetting the page. I.e. the difference,
-// on the left side, between the initial |page_rect| and the |page_rect| inset
-// with |inset_sizes| (current value of |page_rect|).
-// The x coordinate of |page_rect| must be greater than or equal to
-// |inset_sizes.left|.
+// on the left side, between the initial `page_rect` and the `page_rect` inset
+// with `inset_sizes` (current value of `page_rect`).
+// The x coordinate of `page_rect` must be greater than or equal to
+// `inset_sizes.left`.
gfx::Rect GetLeftFillRect(const gfx::Rect& page_rect,
const PageInsetSizes& inset_sizes,
int bottom_separator);
-// Same as GetLeftFillRect(), but for the right side of |page_rect| and also
-// depends on the |doc_width|. Additionally, |doc_width| must be greater than or
-// equal to the sum of |page_rect.right| and |inset_sizes.right|.
+// Same as GetLeftFillRect(), but for the right side of `page_rect` and also
+// depends on the `doc_width`. Additionally, `doc_width` must be greater than or
+// equal to the sum of `page_rect.right` and `inset_sizes.right`.
gfx::Rect GetRightFillRect(const gfx::Rect& page_rect,
const PageInsetSizes& inset_sizes,
int doc_width,
int bottom_separator);
-// Same as GetLeftFillRect(), but for the bottom side of |page_rect|.
+// Same as GetLeftFillRect(), but for the bottom side of `page_rect`.
gfx::Rect GetBottomFillRect(const gfx::Rect& page_rect,
const PageInsetSizes& inset_sizes,
int bottom_separator);
-// Given |rect_size|, create a gfx::Rect where the top-right corner lies at
-// |position|. The width of |rect_size| must be less than or equal to the x
-// value for |position|.
+// Given `rect_size`, create a gfx::Rect where the top-right corner lies at
+// `position`. The width of `rect_size` must be less than or equal to the x
+// value for `position`.
gfx::Rect GetLeftRectForTwoUpView(const gfx::Size& rect_size,
const gfx::Point& position);
-// Given |rect_size|, create a gfx::Rect where the top-left corner lies at
-// |position|.
+// Given `rect_size`, create a gfx::Rect where the top-left corner lies at
+// `position`.
gfx::Rect GetRightRectForTwoUpView(const gfx::Size& rect_size,
const gfx::Point& position);
diff --git a/chromium/pdf/draw_utils/coordinates_unittest.cc b/chromium/pdf/draw_utils/coordinates_unittest.cc
index 0628a2b4774..ff19aac172d 100644
--- a/chromium/pdf/draw_utils/coordinates_unittest.cc
+++ b/chromium/pdf/draw_utils/coordinates_unittest.cc
@@ -90,7 +90,7 @@ TEST(CoordinateTest, GetBottomGapBetweenRects) {
EXPECT_EQ(gfx::Rect(150, -100, 400, 150),
GetBottomGapBetweenRects(-100, {150, 0, 400, 50}));
- // Test case where |page_rect_bottom| >= |dirty_rect.bottom()|.
+ // Test case where `page_rect_bottom` >= `dirty_rect.bottom()`.
EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
GetBottomGapBetweenRects(1400, {0, 10, 300, 500}));
}
diff --git a/chromium/pdf/features.gni b/chromium/pdf/features.gni
index 8b7c8138465..4fe9c63061f 100644
--- a/chromium/pdf/features.gni
+++ b/chromium/pdf/features.gni
@@ -9,7 +9,11 @@ import("//build/config/chromecast_build.gni")
# disabled.
declare_args() {
- enable_pdf = !is_android && !is_ios && !is_chromecast
+ # TODO(crbug.com/702993): Currently disabled on Fuchsia because the PDF Viewer
+ # currently depends on PPAPI. It does not make sense to port PPAPI, which is
+ # being deprecated, to Fuchsia. Once the PDF Viewer no longer uses PPAPI, the
+ # PDF Viewer should be enabled on Fuchsia, like on other desktop platforms.
+ enable_pdf = !is_android && !is_ios && !is_chromecast && !is_fuchsia
# Enable additional code for the Pepper-free PDF viewer.
#
diff --git a/chromium/pdf/out_of_process_instance.cc b/chromium/pdf/out_of_process_instance.cc
index 4153bd63bc9..e41a167b09a 100644
--- a/chromium/pdf/out_of_process_instance.cc
+++ b/chromium/pdf/out_of_process_instance.cc
@@ -19,7 +19,6 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
-#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
@@ -57,6 +56,8 @@
#include "ppapi/cpp/size.h"
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/var_dictionary.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
@@ -109,7 +110,7 @@ constexpr base::TimeDelta kFindResultCooldown =
// Same value as printing::COMPLETE_PREVIEW_DOCUMENT_INDEX.
constexpr int kCompletePDFIndex = -1;
-// A different negative value to differentiate itself from |kCompletePDFIndex|.
+// A different negative value to differentiate itself from `kCompletePDFIndex`.
constexpr int kInvalidPDFIndex = -2;
constexpr char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
@@ -211,6 +212,14 @@ void ReplaceSelection(PP_Instance instance, const char* text) {
}
}
+void SelectAll(PP_Instance instance) {
+ void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
+ if (object) {
+ auto* obj_instance = static_cast<OutOfProcessInstance*>(object);
+ obj_instance->SelectAll();
+ }
+}
+
PP_Bool CanUndo(PP_Instance instance) {
void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
if (!object)
@@ -300,6 +309,7 @@ const PPP_Pdf ppp_private = {
&CanEditText,
&HasEditableText,
&ReplaceSelection,
+ &SelectAll,
&CanUndo,
&CanRedo,
&Undo,
@@ -309,7 +319,7 @@ const PPP_Pdf ppp_private = {
};
int ExtractPrintPreviewPageIndex(base::StringPiece src_url) {
- // Sample |src_url| format: chrome://print/id/page_index/print.pdf
+ // Sample `src_url` format: chrome://print/id/page_index/print.pdf
// The page_index is zero-based, but can be negative with special meanings.
std::vector<base::StringPiece> url_substr =
base::SplitStringPiece(src_url.substr(strlen(kChromePrint)), "/",
@@ -334,11 +344,6 @@ bool IsPreviewingPDF(int print_preview_page_count) {
return print_preview_page_count == 0;
}
-void ScaleFloatPoint(float scale, pp::FloatPoint* point) {
- point->set_x(point->x() * scale);
- point->set_y(point->y() * scale);
-}
-
void ScalePoint(float scale, pp::Point* point) {
point->set_x(static_cast<int>(point->x() * scale));
point->set_y(static_cast<int>(point->y() * scale));
@@ -550,7 +555,7 @@ bool OutOfProcessInstance::Init(uint32_t argc,
InitializeEngine(script_option);
// If we're in print preview mode we don't need to load the document yet.
- // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting
+ // A `kJSResetPrintPreviewModeType` message will be sent to the plugin letting
// it know the url to load. By not loading here we avoid loading the same
// document twice.
if (IsPrintPreview())
@@ -596,68 +601,11 @@ void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
}
bool OutOfProcessInstance::HandleInputEvent(const pp::InputEvent& event) {
- // Ignore user input in read-only mode.
- // TODO(dhoss): Add a test for ignored input events. It is currently difficult
- // to unit test certain `OutOfProcessInstance` methods.
- if (engine()->IsReadOnly())
- return false;
-
- // To simplify things, convert the event into device coordinates.
- pp::InputEvent event_device_res(event);
- {
- pp::MouseInputEvent mouse_event(event);
- if (!mouse_event.is_null()) {
- pp::Point point = mouse_event.GetPosition();
- pp::Point movement = mouse_event.GetMovement();
- ScalePoint(device_scale(), &point);
- point.set_x(point.x() - available_area().x());
-
- ScalePoint(device_scale(), &movement);
- mouse_event =
- pp::MouseInputEvent(this, event.GetType(), event.GetTimeStamp(),
- event.GetModifiers(), mouse_event.GetButton(),
- point, mouse_event.GetClickCount(), movement);
- event_device_res = mouse_event;
- }
- }
- {
- pp::TouchInputEvent touch_event(event);
- if (!touch_event.is_null()) {
- pp::TouchInputEvent new_touch_event = pp::TouchInputEvent(
- this, touch_event.GetType(), touch_event.GetTimeStamp(),
- touch_event.GetModifiers());
-
- for (uint32_t i = 0;
- i < touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES);
- i++) {
- pp::TouchPoint touch_point =
- touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, i);
-
- pp::FloatPoint point = touch_point.position();
- ScaleFloatPoint(device_scale(), &point);
- point.set_x(point.x() - available_area().x());
-
- new_touch_event.AddTouchPoint(
- PP_TOUCHLIST_TYPE_TARGETTOUCHES,
- {touch_point.id(), point, touch_point.radii(),
- touch_point.rotation_angle(), touch_point.pressure()});
- }
- event_device_res = new_touch_event;
- }
- }
-
- if (SendInputEventToEngine(event_device_res))
- return true;
-
- // Middle click is used for scrolling and is handled by the container page.
- pp::MouseInputEvent mouse_event(event_device_res);
- if (!mouse_event.is_null() &&
- mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
+ std::unique_ptr<blink::WebInputEvent> web_event = GetWebInputEvent(event);
+ if (!web_event)
return false;
- }
- // Return true for unhandled clicks so the plugin takes focus.
- return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
+ return PdfViewPluginBase::HandleInputEvent(*web_event);
}
void OutOfProcessInstance::DidChangeView(const pp::View& view) {
@@ -684,7 +632,7 @@ void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
static_cast<PP_PrivateDuplexMode_Dev>(engine()->GetDuplexType());
options->copies = engine()->GetCopiesToPrint();
- base::Optional<gfx::Size> uniform_page_size =
+ absl::optional<gfx::Size> uniform_page_size =
engine()->GetUniformPageSizePoints();
options->is_page_size_uniform = PP_FromBool(uniform_page_size.has_value());
options->uniform_page_size = PPSizeFromSize(
@@ -693,16 +641,22 @@ void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
void OutOfProcessInstance::SelectionChanged(const gfx::Rect& left,
const gfx::Rect& right) {
- pp::Point l(left.x() + available_area().x(), left.y());
- pp::Point r(right.x() + available_area().x(), right.y());
+ const gfx::Rect left_with_offset = left + plugin_rect().OffsetFromOrigin();
+ const gfx::Rect right_with_offset = right + plugin_rect().OffsetFromOrigin();
+
+ pp::Point l(left_with_offset.x() + available_area().x(),
+ left_with_offset.y());
+ pp::Point r(right_with_offset.x() + available_area().x(),
+ right_with_offset.y());
float inverse_scale = 1.0f / device_scale();
ScalePoint(inverse_scale, &l);
ScalePoint(inverse_scale, &r);
- pp::PDF::SelectionChanged(GetPluginInstance(),
- PP_MakeFloatPoint(l.x(), l.y()), left.height(),
- PP_MakeFloatPoint(r.x(), r.y()), right.height());
+ pp::PDF::SelectionChanged(
+ GetPluginInstance(), PP_MakeFloatPoint(l.x(), l.y()),
+ left_with_offset.height(), PP_MakeFloatPoint(r.x(), r.y()),
+ right_with_offset.height());
if (accessibility_state() == AccessibilityState::kLoaded)
PrepareAndSetAccessibilityViewportInfo();
}
@@ -755,6 +709,10 @@ void OutOfProcessInstance::ReplaceSelection(const std::string& text) {
engine()->ReplaceSelection(text);
}
+void OutOfProcessInstance::SelectAll() {
+ engine()->SelectAll();
+}
+
bool OutOfProcessInstance::CanUndo() {
return engine()->CanUndo();
}
@@ -885,10 +843,10 @@ void OutOfProcessInstance::SetFormFieldInFocus(bool in_focus) {
: PP_TEXTINPUT_TYPE_DEV_NONE);
}
-void OutOfProcessInstance::UpdateCursor(ui::mojom::CursorType cursor_type) {
- if (cursor_type == cursor_type_)
+void OutOfProcessInstance::UpdateCursor(ui::mojom::CursorType new_cursor_type) {
+ if (cursor_type() == new_cursor_type)
return;
- cursor_type_ = cursor_type;
+ set_cursor_type(new_cursor_type);
const PPB_CursorControl_Dev* cursor_interface =
reinterpret_cast<const PPB_CursorControl_Dev*>(
@@ -900,7 +858,7 @@ void OutOfProcessInstance::UpdateCursor(ui::mojom::CursorType cursor_type) {
}
cursor_interface->SetCursor(pp_instance(),
- PPCursorTypeFromCursorType(cursor_type_),
+ PPCursorTypeFromCursorType(cursor_type()),
pp::ImageData().pp_resource(), nullptr);
}
@@ -1066,9 +1024,9 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
}
// The page count is zero if the print preview source is a PDF. In which
- // case, the page index for |url| should be at |kCompletePDFIndex|.
+ // case, the page index for `url` should be at `kCompletePDFIndex`.
// When the page count is not zero, then the source is not PDF. In which
- // case, the page index for |url| should be non-negative.
+ // case, the page index for `url` should be non-negative.
bool is_previewing_pdf = IsPreviewingPDF(print_preview_page_count);
int page_index = ExtractPrintPreviewPageIndex(url);
if ((is_previewing_pdf && page_index != kCompletePDFIndex) ||
@@ -1415,43 +1373,6 @@ void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
}
-bool OutOfProcessInstance::SendInputEventToEngine(const pp::InputEvent& event) {
- switch (event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- case PP_INPUTEVENT_TYPE_MOUSEUP:
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- case PP_INPUTEVENT_TYPE_MOUSEENTER:
- case PP_INPUTEVENT_TYPE_MOUSELEAVE:
- return engine()->HandleEvent(
- GetMouseInputEvent(pp::MouseInputEvent(event)));
- case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
- case PP_INPUTEVENT_TYPE_KEYDOWN:
- case PP_INPUTEVENT_TYPE_KEYUP:
- case PP_INPUTEVENT_TYPE_CHAR:
- return engine()->HandleEvent(
- GetKeyboardInputEvent(pp::KeyboardInputEvent(event)));
- case PP_INPUTEVENT_TYPE_TOUCHSTART:
- case PP_INPUTEVENT_TYPE_TOUCHEND:
- case PP_INPUTEVENT_TYPE_TOUCHMOVE:
- case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
- return engine()->HandleEvent(
- GetTouchInputEvent(pp::TouchInputEvent(event)));
- case PP_INPUTEVENT_TYPE_WHEEL:
- case PP_INPUTEVENT_TYPE_CONTEXTMENU:
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
- case PP_INPUTEVENT_TYPE_IME_TEXT:
- // These event types are not used in PDFiumEngine, so there are no
- // functions to convert them from pp::InputEvent to
- // chrome_pdf::InputEvent. As such just send a dummy NoneInputEvent
- // instead.
- return engine()->HandleEvent(NoneInputEvent());
- case PP_INPUTEVENT_TYPE_UNDEFINED:
- return false;
- }
-}
-
void OutOfProcessInstance::OnPrint(int32_t /*unused_but_required*/) {
pp::PDF::Print(this);
}
diff --git a/chromium/pdf/out_of_process_instance.h b/chromium/pdf/out_of_process_instance.h
index e281335bdba..6de811b7647 100644
--- a/chromium/pdf/out_of_process_instance.h
+++ b/chromium/pdf/out_of_process_instance.h
@@ -25,7 +25,6 @@
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/find_private.h"
#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/gfx/geometry/rect.h"
namespace gfx {
@@ -85,6 +84,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
bool CanEditText();
bool HasEditableText();
void ReplaceSelection(const std::string& text);
+ void SelectAll();
bool CanUndo();
bool CanRedo();
void Undo();
@@ -95,7 +95,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
void FlushCallback(int32_t result);
// PdfViewPluginBase:
- void UpdateCursor(ui::mojom::CursorType cursor_type) override;
+ void UpdateCursor(ui::mojom::CursorType new_cursor_type) override;
void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override;
@@ -178,14 +178,14 @@ class OutOfProcessInstance : public PdfViewPluginBase,
kEdited = 2,
};
- // Reduces the document to 1 page and appends |print_preview_page_count_| - 1
+ // Reduces the document to 1 page and appends `print_preview_page_count_` - 1
// blank pages to the document for print preview.
void AppendBlankPrintPreviewPages();
- // Process the preview page data information. |src_url| specifies the preview
- // page data location. The |src_url| is in the format:
+ // Process the preview page data information. `src_url` specifies the preview
+ // page data location. The `src_url` is in the format:
// chrome://print/id/page_number/print.pdf
- // |dest_page_index| specifies the blank page index that needs to be replaced
+ // `dest_page_index` specifies the blank page index that needs to be replaced
// with the new page data.
void ProcessPreviewPageInfo(const std::string& src_url, int dest_page_index);
// Load the next available preview page into the blank page.
@@ -197,19 +197,9 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// Callback to print without re-entrancy issues.
void OnPrint(int32_t /*unused_but_required*/);
- // Helper for HandleInputEvent(). Returns whether engine() handled the event
- // or not.
- bool SendInputEventToEngine(const pp::InputEvent& event);
-
// The Pepper image data that is in sync with mutable_image_data().
pp::ImageData pepper_image_data_;
- // The current cursor type.
- ui::mojom::CursorType cursor_type_ = ui::mojom::CursorType::kPointer;
-
- // True if the plugin is full-page.
- bool full_ = false;
-
struct PrintSettings {
PrintSettings() { Clear(); }
@@ -233,11 +223,11 @@ class OutOfProcessInstance : public PdfViewPluginBase,
PrintSettings print_settings_;
// The PreviewModeClient used for print preview. Will be passed to
- // |preview_engine_|.
+ // `preview_engine_`.
std::unique_ptr<PreviewModeClient> preview_client_;
// This engine is used to render the individual preview page data. This is
- // used only in print preview mode. This will use |PreviewModeClient|
+ // used only in print preview mode. This will use `PreviewModeClient`
// interface which has very limited access to the pp::Instance.
std::unique_ptr<PDFiumEngine> preview_engine_;
@@ -262,10 +252,10 @@ class OutOfProcessInstance : public PdfViewPluginBase,
int print_preview_page_count_ = -1;
// Number of pages loaded in print preview mode for non-PDF source. Always
- // less than or equal to |print_preview_page_count_|.
+ // less than or equal to `print_preview_page_count_`.
int print_preview_loaded_page_count_ = -1;
- // Used to manage loaded print preview page information. A |PreviewPageInfo|
+ // Used to manage loaded print preview page information. A `PreviewPageInfo`
// consists of data source URL string and the page index in the destination
// document.
// The URL string embeds a page number that can be found with
@@ -280,7 +270,7 @@ class OutOfProcessInstance : public PdfViewPluginBase,
std::unique_ptr<pp::TextInput_Dev> text_input_;
// Whether an update to the number of find results found was sent less than
- // |kFindResultCooldownMs| milliseconds ago.
+ // `kFindResultCooldownMs` milliseconds ago.
bool recently_sent_find_update_ = false;
// The tickmarks.
diff --git a/chromium/pdf/page_orientation.cc b/chromium/pdf/page_orientation.cc
index 6ce84799b5f..a652958e02c 100644
--- a/chromium/pdf/page_orientation.cc
+++ b/chromium/pdf/page_orientation.cc
@@ -31,7 +31,7 @@ PageOrientation RotateClockwise(PageOrientation orientation) {
}
PageOrientation RotateCounterclockwise(PageOrientation orientation) {
- // Adding |kLast| is equivalent to rotating one step counterclockwise.
+ // Adding `kLast` is equivalent to rotating one step counterclockwise.
return AddOrientations(orientation, PageOrientation::kLast);
}
diff --git a/chromium/pdf/paint_aggregator.h b/chromium/pdf/paint_aggregator.h
index 91bf03fbaa1..ba6941ce725 100644
--- a/chromium/pdf/paint_aggregator.h
+++ b/chromium/pdf/paint_aggregator.h
@@ -90,8 +90,8 @@ class PaintAggregator {
InternalPaintUpdate();
~InternalPaintUpdate();
- // Computes the rect damaged by scrolling within |scroll_rect| by
- // |scroll_delta|. This rect must be repainted. It is not included in
+ // Computes the rect damaged by scrolling within `scroll_rect` by
+ // `scroll_delta`. This rect must be repainted. It is not included in
// paint_rects.
gfx::Rect GetScrollDamage() const;
@@ -113,8 +113,8 @@ class PaintAggregator {
const gfx::Vector2d& amount) const;
void InvalidateScrollRect();
- // Internal method used by InvalidateRect. If |check_scroll| is true, then the
- // method checks if there's a pending scroll and if so also invalidates |rect|
+ // Internal method used by InvalidateRect. If `check_scroll` is true, then the
+ // method checks if there's a pending scroll and if so also invalidates `rect`
// in the new scroll position.
void InvalidateRectInternal(const gfx::Rect& rect, bool check_scroll);
diff --git a/chromium/pdf/paint_manager.cc b/chromium/pdf/paint_manager.cc
index ef492c140da..6b43c5057b9 100644
--- a/chromium/pdf/paint_manager.cc
+++ b/chromium/pdf/paint_manager.cc
@@ -185,7 +185,7 @@ void PaintManager::DoPaint() {
// have an unpainted device bound. The needs_binding flag tells us whether to
// do this later.
//
- // Note that |has_pending_resize_| will always be set on the first DoPaint().
+ // Note that `has_pending_resize_` will always be set on the first DoPaint().
DCHECK(graphics_ || has_pending_resize_);
if (has_pending_resize_) {
plugin_size_ = pending_size_;
diff --git a/chromium/pdf/paint_manager.h b/chromium/pdf/paint_manager.h
index 100d27f897e..43c1c9905fc 100644
--- a/chromium/pdf/paint_manager.h
+++ b/chromium/pdf/paint_manager.h
@@ -42,7 +42,7 @@ class PaintManager {
class Client {
public:
// Creates a new, unbound `Graphics` for the paint manager, with the given
- // |size| and always-opaque rendering.
+ // `size` and always-opaque rendering.
virtual std::unique_ptr<Graphics> CreatePaintGraphics(
const gfx::Size& size) = 0;
@@ -134,8 +134,8 @@ class PaintManager {
float GetEffectiveDeviceScale() const;
// Set the transform for the graphics layer.
- // If |schedule_flush| is true, it ensures a flush will be scheduled for
- // this change. If |schedule_flush| is false, then the change will not take
+ // If `schedule_flush` is true, it ensures a flush will be scheduled for
+ // this change. If `schedule_flush` is false, then the change will not take
// effect until another change causes a flush.
void SetTransform(float scale,
const gfx::Point& origin,
diff --git a/chromium/pdf/pdf.cc b/chromium/pdf/pdf.cc
index 8b44c72651e..afc4b58c864 100644
--- a/chromium/pdf/pdf.cc
+++ b/chromium/pdf/pdf.cc
@@ -93,7 +93,7 @@ bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
return engine_exports->GetPDFDocInfo(pdf_buffer, page_count, max_page_width);
}
-base::Optional<bool> IsPDFDocTagged(base::span<const uint8_t> pdf_buffer) {
+absl::optional<bool> IsPDFDocTagged(base::span<const uint8_t> pdf_buffer) {
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
PDFEngineExports* engine_exports = PDFEngineExports::Get();
return engine_exports->IsPDFDocTagged(pdf_buffer);
@@ -106,7 +106,7 @@ base::Value GetPDFStructTreeForPage(base::span<const uint8_t> pdf_buffer,
return engine_exports->GetPDFStructTreeForPage(pdf_buffer, page_index);
}
-base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
+absl::optional<gfx::SizeF> GetPDFPageSizeByIndex(
base::span<const uint8_t> pdf_buffer,
int page_number) {
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
diff --git a/chromium/pdf/pdf.h b/chromium/pdf/pdf.h
index 155392aac14..07f1c38fc90 100644
--- a/chromium/pdf/pdf.h
+++ b/chromium/pdf/pdf.h
@@ -8,10 +8,10 @@
#include <vector>
#include "base/containers/span.h"
-#include "base/optional.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#if defined(OS_WIN)
#include <windows.h>
@@ -33,7 +33,7 @@ namespace chrome_pdf {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Create a flattened PDF document from an existing PDF document.
-// |input_buffer| is the buffer that contains the entire PDF document to be
+// `input_buffer` is the buffer that contains the entire PDF document to be
// flattened.
std::vector<uint8_t> CreateFlattenedPdf(base::span<const uint8_t> input_buffer);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
@@ -46,36 +46,36 @@ enum PrintingMode {
kTextOnly = 1,
kPostScript2 = 2,
kPostScript3 = 3,
- // Values 4 and 5 are similar to |kPostScript2| and |kPostScript3|, but are
+ // Values 4 and 5 are similar to `kPostScript2` and `kPostScript3`, but are
// not intended for use in sandboxed environments like Chromium's.
kEmfWithReducedRasterization = 6,
};
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
+// `pdf_buffer` is the buffer that contains the entire PDF document to be
// rendered.
-// |page_number| is the 0-based index of the page to be rendered.
-// |dc| is the device context to render into.
-// |dpi_x| and |dpi_y| is the resolution.
-// |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height|
+// `page_number` is the 0-based index of the page to be rendered.
+// `dc` is the device context to render into.
+// `dpi_x` and `dpi_y` is the resolution.
+// `bounds_origin_x`, `bounds_origin_y`, `bounds_width` and `bounds_height`
// specify a bounds rectangle within the DC in which to render the PDF
// page.
-// |fit_to_bounds| specifies whether the output should be shrunk to fit the
+// `fit_to_bounds` specifies whether the output should be shrunk to fit the
// supplied bounds if the page size is larger than the bounds in any
// dimension. If this is false, parts of the PDF page that lie outside
// the bounds will be clipped.
-// |stretch_to_bounds| specifies whether the output should be stretched to fit
+// `stretch_to_bounds` specifies whether the output should be stretched to fit
// the supplied bounds if the page size is smaller than the bounds in any
// dimension.
-// If both |fit_to_bounds| and |stretch_to_bounds| are true, then
-// |fit_to_bounds| is honored first.
-// |keep_aspect_ratio| If any scaling is to be done is true, this flag
+// If both `fit_to_bounds` and `stretch_to_bounds` are true, then
+// `fit_to_bounds` is honored first.
+// `keep_aspect_ratio` If any scaling is to be done is true, this flag
// specifies whether the original aspect ratio of the page should be
// preserved while scaling.
-// |center_in_bounds| specifies whether the final image (after any scaling is
+// `center_in_bounds` specifies whether the final image (after any scaling is
// done) should be centered within the given bounds.
-// |autorotate| specifies whether the final image should be rotated to match
+// `autorotate` specifies whether the final image should be rotated to match
// the output bound.
-// |use_color| specifies color or grayscale.
+// `use_color` specifies color or grayscale.
// Returns false if the document or the page number are not valid.
bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
int page_number,
@@ -101,7 +101,7 @@ void SetPDFUseGDIPrinting(bool enable);
void SetPDFUsePrintMode(int mode);
#endif // defined(OS_WIN)
-// |page_count| and |max_page_width| are optional and can be NULL.
+// `page_count` and `max_page_width` are optional and can be NULL.
// Returns false if the document is not valid.
bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
int* page_count,
@@ -110,7 +110,7 @@ bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
// Whether the PDF is Tagged (see 10.7 "Tagged PDF" in PDF Reference 1.7).
// Returns true if it's a tagged (accessible) PDF, false if it's a valid
// PDF but untagged, and nullopt if the PDF can't be parsed.
-base::Optional<bool> IsPDFDocTagged(base::span<const uint8_t> pdf_buffer);
+absl::optional<bool> IsPDFDocTagged(base::span<const uint8_t> pdf_buffer);
// Given a tagged PDF (see IsPDFDocTagged, above), return the portion of
// the structure tree for a given page as a hierarchical tree of base::Values.
@@ -118,13 +118,13 @@ base::Value GetPDFStructTreeForPage(base::span<const uint8_t> pdf_buffer,
int page_index);
// Gets the dimensions of a specific page in a document.
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
+// `pdf_buffer` is the buffer that contains the entire PDF document to be
// rendered.
-// |page_number| is the page number that the function will get the dimensions
+// `page_number` is the page number that the function will get the dimensions
// of.
// Returns the size of the page in points, or nullopt if the document or the
// page number are not valid.
-base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
+absl::optional<gfx::SizeF> GetPDFPageSizeByIndex(
base::span<const uint8_t> pdf_buffer,
int page_number);
@@ -148,13 +148,13 @@ struct RenderOptions {
};
// Renders PDF page into 4-byte per pixel BGRA color bitmap.
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
+// `pdf_buffer` is the buffer that contains the entire PDF document to be
// rendered.
-// |page_number| is the 0-based index of the page to be rendered.
-// |bitmap_buffer| is the output buffer for bitmap.
-// |bitmap_size| is the size of the output bitmap.
-// |dpi| is the 2D resolution.
-// |options| is the options to render with.
+// `page_number` is the 0-based index of the page to be rendered.
+// `bitmap_buffer` is the output buffer for bitmap.
+// `bitmap_size` is the size of the output bitmap.
+// `dpi` is the 2D resolution.
+// `options` is the options to render with.
// Returns false if the document or the page number are not valid.
bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
int page_number,
@@ -164,22 +164,22 @@ bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
const RenderOptions& options);
// Convert multiple PDF pages into a N-up PDF.
-// |input_buffers| is the vector of buffers with each buffer contains a PDF.
+// `input_buffers` is the vector of buffers with each buffer contains a PDF.
// If any of the PDFs contains multiple pages, only the first page of the
// document is used.
-// |pages_per_sheet| is the number of pages to put on one sheet.
-// |page_size| is the output page size, measured in PDF "user space" units.
-// |printable_area| is the output page printable area, measured in PDF
-// "user space" units. Should be smaller than |page_size|.
+// `pages_per_sheet` is the number of pages to put on one sheet.
+// `page_size` is the output page size, measured in PDF "user space" units.
+// `printable_area` is the output page printable area, measured in PDF
+// "user space" units. Should be smaller than `page_size`.
//
-// |page_size| is the print media size. The page size of the output N-up PDF is
-// determined by the |pages_per_sheet|, the orientation of the PDF pages
-// contained in the |input_buffers|, and the media page size |page_size|. For
-// example, when |page_size| = 512x792, |pages_per_sheet| = 2, and the
-// orientation of |input_buffers| = portrait, the output N-up PDF will be
+// `page_size` is the print media size. The page size of the output N-up PDF is
+// determined by the `pages_per_sheet`, the orientation of the PDF pages
+// contained in the `input_buffers`, and the media page size `page_size`. For
+// example, when `page_size` = 512x792, `pages_per_sheet` = 2, and the
+// orientation of `input_buffers` = portrait, the output N-up PDF will be
// 792x512.
// See printing::NupParameters for more details on how the output page
-// orientation is determined, to understand why |page_size| may be swapped in
+// orientation is determined, to understand why `page_size` may be swapped in
// some cases.
std::vector<uint8_t> ConvertPdfPagesToNupPdf(
std::vector<base::span<const uint8_t>> input_buffers,
@@ -188,12 +188,12 @@ std::vector<uint8_t> ConvertPdfPagesToNupPdf(
const gfx::Rect& printable_area);
// Convert a PDF document to a N-up PDF document.
-// |input_buffer| is the buffer that contains the entire PDF document to be
+// `input_buffer` is the buffer that contains the entire PDF document to be
// converted to a N-up PDF document.
-// |pages_per_sheet| is the number of pages to put on one sheet.
-// |page_size| is the output page size, measured in PDF "user space" units.
-// |printable_area| is the output page printable area, measured in PDF
-// "user space" units. Should be smaller than |page_size|.
+// `pages_per_sheet` is the number of pages to put on one sheet.
+// `page_size` is the output page size, measured in PDF "user space" units.
+// `printable_area` is the output page printable area, measured in PDF
+// "user space" units. Should be smaller than `page_size`.
//
// Refer to the description of ConvertPdfPagesToNupPdf to understand how the
// output page size will be calculated.
diff --git a/chromium/pdf/pdf_engine.h b/chromium/pdf/pdf_engine.h
index 9ecba9d5f25..261bef721f1 100644
--- a/chromium/pdf/pdf_engine.h
+++ b/chromium/pdf/pdf_engine.h
@@ -13,7 +13,6 @@
#include "base/callback.h"
#include "base/containers/span.h"
-#include "base/optional.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
@@ -24,6 +23,7 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/url_loader.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
#include "ui/base/window_open_disposition.h"
@@ -48,6 +48,10 @@ namespace base {
class Location;
} // namespace base
+namespace blink {
+class WebInputEvent;
+} // namespace blink
+
namespace gfx {
class Point;
class Rect;
@@ -58,7 +62,6 @@ class Vector2d;
namespace chrome_pdf {
-class InputEvent;
class Thumbnail;
class UrlLoader;
struct AccessibilityActionData;
@@ -73,7 +76,7 @@ struct DocumentMetadata;
using SendThumbnailCallback = base::OnceCallback<void(Thumbnail)>;
// Do one time initialization of the SDK.
-// If |enable_v8| is false, then the PDFEngine will not be able to run
+// If `enable_v8` is false, then the PDFEngine will not be able to run
// JavaScript.
void InitializeSDK(bool enable_v8);
// Tells the SDK that we're shutting down.
@@ -104,8 +107,8 @@ class PDFEngine {
// Number of parameters for the view.
unsigned long num_params;
- // Parameters for the view. Their meaning depends on the |view| and their
- // number is defined by |num_params| but is at most |kMaxViewParams|. Note:
+ // Parameters for the view. Their meaning depends on the `view` and their
+ // number is defined by `num_params` but is at most `kMaxViewParams`. Note:
// If a parameter stands for the x/y coordinates, it should be transformed
// into the corresponding in-screen coordinates before it's sent to the
// viewport.
@@ -144,22 +147,22 @@ class PDFEngine {
// Scroll by a given delta relative to the current position.
virtual void ScrollBy(const gfx::Vector2d& delta) {}
- // Scroll to zero-based |page|.
+ // Scroll to zero-based `page`.
virtual void ScrollToPage(int page) {}
// Navigate to the given url.
virtual void NavigateTo(const std::string& url,
WindowOpenDisposition disposition) {}
- // Navigate to the given destination. Zero-based |page| index. |x|, |y| and
- // |zoom| are optional and can be nullptr.
+ // Navigate to the given destination. Zero-based `page` index. `x`, `y` and
+ // `zoom` are optional and can be nullptr.
virtual void NavigateToDestination(int page,
const float* x,
const float* y,
const float* zoom) {}
// Updates the cursor.
- virtual void UpdateCursor(ui::mojom::CursorType cursor_type) {}
+ virtual void UpdateCursor(ui::mojom::CursorType new_cursor_type) {}
// Updates the tick marks in the vertical scrollbar.
virtual void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) {}
@@ -305,7 +308,7 @@ class PDFEngine {
std::vector<gfx::Rect>& pending) = 0;
virtual void PostPaint() = 0;
virtual bool HandleDocumentLoad(std::unique_ptr<UrlLoader> loader) = 0;
- virtual bool HandleEvent(const InputEvent& event) = 0;
+ virtual bool HandleInputEvent(const blink::WebInputEvent& event) = 0;
virtual uint32_t QuerySupportedPrintOutputFormats() = 0;
virtual void PrintBegin() = 0;
virtual pp::Resource PrintPages(
@@ -333,17 +336,17 @@ class PDFEngine {
virtual std::string GetSelectedText() = 0;
// Returns true if focus is within an editable form text area.
- virtual bool CanEditText() = 0;
+ virtual bool CanEditText() const = 0;
// Returns true if focus is within an editable form text area and the text
// area has text.
- virtual bool HasEditableText() = 0;
+ virtual bool HasEditableText() const = 0;
// Replace selected text within an editable form text area with another
// string. If there is no selected text, append the replacement text after the
// current caret position.
virtual void ReplaceSelection(const std::string& text) = 0;
// Methods to check if undo/redo is possible, and to perform them.
- virtual bool CanUndo() = 0;
- virtual bool CanRedo() = 0;
+ virtual bool CanUndo() const = 0;
+ virtual bool CanRedo() const = 0;
virtual void Undo() = 0;
virtual void Redo() = 0;
// Handles actions invoked by Accessibility clients.
@@ -356,20 +359,20 @@ class PDFEngine {
// Gets the list of DocumentAttachmentInfo from the document.
virtual const std::vector<DocumentAttachmentInfo>&
GetDocumentAttachmentInfoList() const = 0;
- // Gets the content of an attachment by the attachment's |index|. |index|
- // must be in the range of [0, attachment_count-1), where |attachment_count|
+ // Gets the content of an attachment by the attachment's `index`. `index`
+ // must be in the range of [0, attachment_count-1), where `attachment_count`
// is the number of attachments embedded in the document.
// The caller of this method is responsible for checking whether the
// attachment is readable, attachment size is not 0 byte, and the return
// value's size matches the corresponding DocumentAttachmentInfo's
- // |size_bytes|.
+ // `size_bytes`.
virtual std::vector<uint8_t> GetAttachmentData(size_t index) = 0;
// Gets metadata about the document.
virtual const DocumentMetadata& GetDocumentMetadata() const = 0;
// Gets the number of pages in the document.
virtual int GetNumberOfPages() const = 0;
// Gets the named destination by name.
- virtual base::Optional<PDFEngine::NamedDestination> GetNamedDestination(
+ virtual absl::optional<PDFEngine::NamedDestination> GetNamedDestination(
const std::string& destination) = 0;
// Gets the index of the most visible page, or -1 if none are visible.
virtual int GetMostVisiblePage() = 0;
@@ -380,9 +383,6 @@ class PDFEngine {
// Returns a page's rect in screen coordinates, as well as its surrounding
// border areas and bottom separator.
virtual gfx::Rect GetPageScreenRect(int page_index) const = 0;
- // Gets the offset of the vertical scrollbar from the top in document
- // coordinates.
- virtual int GetVerticalScrollbarYPosition() = 0;
// Set color / grayscale rendering modes.
virtual void SetGrayscale(bool grayscale) = 0;
// Get the number of characters on a given page.
@@ -393,27 +393,27 @@ class PDFEngine {
virtual uint32_t GetCharUnicode(int page_index, int char_index) = 0;
// Given a start char index, find the longest continuous run of text that's
// in a single direction and with the same text style. Return a filled out
- // AccessibilityTextRunInfo on success or base::nullopt on failure. e.g. When
- // |start_char_index| is out of bounds.
- virtual base::Optional<AccessibilityTextRunInfo> GetTextRunInfo(
+ // AccessibilityTextRunInfo on success or absl::nullopt on failure. e.g. When
+ // `start_char_index` is out of bounds.
+ virtual absl::optional<AccessibilityTextRunInfo> GetTextRunInfo(
int page_index,
int start_char_index) = 0;
- // For all the links on page |page_index|, get their urls, underlying text
+ // For all the links on page `page_index`, get their urls, underlying text
// ranges and bounding boxes.
virtual std::vector<AccessibilityLinkInfo> GetLinkInfo(
int page_index,
const std::vector<AccessibilityTextRunInfo>& text_runs) = 0;
- // For all the images in page |page_index|, get their alt texts and bounding
+ // For all the images in page `page_index`, get their alt texts and bounding
// boxes.
virtual std::vector<AccessibilityImageInfo> GetImageInfo(
int page_index,
uint32_t text_run_count) = 0;
- // For all the highlights in page |page_index|, get their underlying text
+ // For all the highlights in page `page_index`, get their underlying text
// ranges and bounding boxes.
virtual std::vector<AccessibilityHighlightInfo> GetHighlightInfo(
int page_index,
const std::vector<AccessibilityTextRunInfo>& text_runs) = 0;
- // For all the text fields in page |page_index|, get their properties like
+ // For all the text fields in page `page_index`, get their properties like
// name, value, bounding boxes etc.
virtual std::vector<AccessibilityTextFieldInfo> GetTextFieldInfo(
int page_index,
@@ -427,8 +427,8 @@ class PDFEngine {
// Returns the duplex setting.
virtual int GetDuplexType() = 0;
// Returns the uniform page size of the document in points. Returns
- // `base::nullopt` if the document has more than one page size.
- virtual base::Optional<gfx::Size> GetUniformPageSizePoints() = 0;
+ // `absl::nullopt` if the document has more than one page size.
+ virtual absl::optional<gfx::Size> GetUniformPageSizePoints() = 0;
// Returns a list of Values of Bookmarks. Each Bookmark is a dictionary Value
// which contains the following key/values:
@@ -438,11 +438,11 @@ class PDFEngine {
// a dictionary Value of the same structure.
virtual base::Value GetBookmarks() = 0;
- // Append blank pages to make a 1-page document to a |num_pages| document.
+ // Append blank pages to make a 1-page document to a `num_pages` document.
// Always retain the first page data.
virtual void AppendBlankPages(size_t num_pages) = 0;
- // Append the first page of the document loaded with the |engine| to this
- // document at page |index|.
+ // Append the first page of the document loaded with the `engine` to this
+ // document at page `index`.
virtual void AppendPage(PDFEngine* engine, int index) = 0;
virtual std::vector<uint8_t> GetSaveData() = 0;
@@ -469,7 +469,7 @@ class PDFEngine {
virtual bool ReadLoadedBytes(uint32_t length, void* buffer) = 0;
// Requests for a thumbnail to be sent using a callback when the page is ready
- // to be rendered. |send_callback| is run with the thumbnail data when ready.
+ // to be rendered. `send_callback` is run with the thumbnail data when ready.
virtual void RequestThumbnail(int page_index,
float device_pixel_ratio,
SendThumbnailCallback send_callback) = 0;
@@ -553,7 +553,7 @@ class PDFEngineExports {
// Whether the PDF is Tagged (see 10.7 "Tagged PDF" in PDF Reference 1.7).
// Returns true if it's a tagged (accessible) PDF, false if it's a valid
// PDF but untagged, and nullopt if the PDF can't be parsed.
- virtual base::Optional<bool> IsPDFDocTagged(
+ virtual absl::optional<bool> IsPDFDocTagged(
base::span<const uint8_t> pdf_buffer) = 0;
// Given a tagged PDF (see IsPDFDocTagged, above), return the portion of
@@ -563,7 +563,7 @@ class PDFEngineExports {
int page_index) = 0;
// See the definition of GetPDFPageSizeByIndex in pdf.cc for details.
- virtual base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
+ virtual absl::optional<gfx::SizeF> GetPDFPageSizeByIndex(
base::span<const uint8_t> pdf_buffer,
int page_number) = 0;
};
diff --git a/chromium/pdf/pdf_features.cc b/chromium/pdf/pdf_features.cc
index 752588ce7de..470beae679d 100644
--- a/chromium/pdf/pdf_features.cc
+++ b/chromium/pdf/pdf_features.cc
@@ -26,7 +26,7 @@ const base::Feature kPdfViewerDocumentProperties = {
"PdfViewerDocumentProperties", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kPdfViewerPresentationMode = {
- "PdfViewerPresentationMode", base::FEATURE_DISABLED_BY_DEFAULT};
+ "PdfViewerPresentationMode", base::FEATURE_ENABLED_BY_DEFAULT};
// Feature has no effect if Chrome is built with no XFA support.
const base::Feature kPdfXfaSupport = {"PdfXfaSupport",
diff --git a/chromium/pdf/pdf_transform.cc b/chromium/pdf/pdf_transform.cc
index 1c075b190f3..f0097f73423 100644
--- a/chromium/pdf/pdf_transform.cc
+++ b/chromium/pdf/pdf_transform.cc
@@ -76,8 +76,8 @@ PdfRectangle CalculateClipBoxBoundary(const PdfRectangle& media_box,
const PdfRectangle& crop_box) {
PdfRectangle clip_box;
- // Clip |media_box| to the size of |crop_box|, but ignore |crop_box| if it is
- // bigger than |media_box|.
+ // Clip `media_box` to the size of `crop_box`, but ignore `crop_box` if it is
+ // bigger than `media_box`.
clip_box.left = std::max(crop_box.left, media_box.left);
clip_box.bottom = std::max(crop_box.bottom, media_box.bottom);
clip_box.right = std::min(crop_box.right, media_box.right);
diff --git a/chromium/pdf/pdf_transform.h b/chromium/pdf/pdf_transform.h
index 91a27b5bf64..31cd2074626 100644
--- a/chromium/pdf/pdf_transform.h
+++ b/chromium/pdf/pdf_transform.h
@@ -22,12 +22,12 @@ struct PdfRectangle {
float top;
};
-// Calculate the scale factor between |content_rect| and a page of |src_size|.
+// Calculate the scale factor between `content_rect` and a page of `src_size`.
//
-// |content_rect| specifies the printable area of the destination page, with
+// `content_rect` specifies the printable area of the destination page, with
// origin at left-bottom. Values are in points.
-// |src_size| specifies the source page size in points.
-// |rotated| True if source page is rotated 90 degree or 270 degree.
+// `src_size` specifies the source page size in points.
+// `rotated` True if source page is rotated 90 degree or 270 degree.
float CalculateScaleFactor(const gfx::Rect& content_rect,
const gfx::SizeF& src_size,
bool rotated);
@@ -40,7 +40,7 @@ void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box);
// Set the media box and/or crop box as needed. If both boxes are there, then
// nothing needs to be done. If one box is missing, then fill it with the value
// from the other box. If both boxes are missing, then they both get the default
-// value from SetDefaultClipBox(), based on |rotated|.
+// value from SetDefaultClipBox(), based on `rotated`.
void CalculateMediaBoxAndCropBox(bool rotated,
bool has_media_box,
bool has_crop_box,
@@ -51,20 +51,20 @@ void CalculateMediaBoxAndCropBox(bool rotated,
// source page and scale factor.
// Returns the computed source clip box values.
//
-// |media_box| The PDF's media box.
-// |crop_box| The PDF's crop box.
+// `media_box` The PDF's media box.
+// `crop_box` The PDF's crop box.
PdfRectangle CalculateClipBoxBoundary(const PdfRectangle& media_box,
const PdfRectangle& crop_box);
-// Scale |rect| by |scale_factor|.
+// Scale `rect` by `scale_factor`.
void ScalePdfRectangle(float scale_factor, PdfRectangle* rect);
// Calculate the clip box translation offset for a page that does need to be
// scaled. All parameters are in points.
//
-// |content_rect| specifies the printable area of the destination page, with
+// `content_rect` specifies the printable area of the destination page, with
// origin at left-bottom.
-// |source_clip_box| specifies the source clip box positions, relative to
+// `source_clip_box` specifies the source clip box positions, relative to
// origin at left-bottom.
// Returns the final translation offsets for the source clip box, relative to
// origin at left-bottom.
@@ -74,11 +74,11 @@ gfx::PointF CalculateScaledClipBoxOffset(const gfx::Rect& content_rect,
// Calculate the clip box offset for a page that does not need to be scaled.
// All parameters are in points.
//
-// |rotation| specifies the source page rotation values which are N / 90
+// `rotation` specifies the source page rotation values which are N / 90
// degrees.
-// |page_width| specifies the screen destination page width.
-// |page_height| specifies the screen destination page height.
-// |source_clip_box| specifies the source clip box positions, relative to origin
+// `page_width` specifies the screen destination page width.
+// `page_height` specifies the screen destination page height.
+// `source_clip_box` specifies the source clip box positions, relative to origin
// at left-bottom.
// Returns the final translation offsets for the source clip box, relative to
// origin at left-bottom.
diff --git a/chromium/pdf/pdf_transform_unittest.cc b/chromium/pdf/pdf_transform_unittest.cc
index dd4664d1ac5..cbc65754a99 100644
--- a/chromium/pdf/pdf_transform_unittest.cc
+++ b/chromium/pdf/pdf_transform_unittest.cc
@@ -195,13 +195,13 @@ TEST(PdfTransformTest, CalculateScaledClipBoxOffset) {
PdfRectangle clip_box;
gfx::PointF offset;
- // |rect| and |clip_box| are the same size.
+ // `rect` and `clip_box` are the same size.
InitializeBoxToDefaultPortraitValues(&clip_box);
offset = CalculateScaledClipBoxOffset(rect, clip_box);
EXPECT_FLOAT_EQ(0, offset.x());
EXPECT_FLOAT_EQ(0, offset.y());
- // |rect| is larger than |clip_box|.
+ // `rect` is larger than `clip_box`.
clip_box.top /= 2;
clip_box.right /= 4;
offset = CalculateScaledClipBoxOffset(rect, clip_box);
@@ -215,7 +215,7 @@ TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
PdfRectangle clip_box;
gfx::PointF offset;
- // |rect|, page size and |clip_box| are the same.
+ // `rect`, page size and `clip_box` are the same.
InitializeBoxToDefaultPortraitValues(&clip_box);
offset =
CalculateNonScaledClipBoxOffset(0, page_width, page_height, clip_box);
@@ -234,7 +234,7 @@ TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
EXPECT_FLOAT_EQ(180, offset.x());
EXPECT_FLOAT_EQ(-180, offset.y());
- // Smaller |clip_box|.
+ // Smaller `clip_box`.
clip_box.top /= 4;
clip_box.right /= 2;
offset =
diff --git a/chromium/pdf/pdf_utils/dates.cc b/chromium/pdf/pdf_utils/dates.cc
index 091fc2beb04..6d2f9ba3343 100644
--- a/chromium/pdf/pdf_utils/dates.cc
+++ b/chromium/pdf/pdf_utils/dates.cc
@@ -6,11 +6,11 @@
#include <stdint.h>
-#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace chrome_pdf {
@@ -27,9 +27,9 @@ class DateDeserializer final {
// Pops the first `num_digits` characters from the string and converts them to
// an int if possible. Popping too many characters or characters that cannot
// be converted puts the deserializer in a stopped state.
- base::Optional<int> PopDigits(size_t num_digits) {
+ absl::optional<int> PopDigits(size_t num_digits) {
if (stopped_)
- return base::nullopt;
+ return absl::nullopt;
// `base::StringToUint()` allows leading sign characters, so also verify
// that the front character is a digit.
@@ -38,7 +38,7 @@ class DateDeserializer final {
!base::IsAsciiDigit(deserializing_.front()) ||
!base::StringToUint(deserializing_.substr(0, num_digits), &value)) {
stopped_ = true;
- return base::nullopt;
+ return absl::nullopt;
}
// Pop front characters.
@@ -47,14 +47,14 @@ class DateDeserializer final {
}
// Pops the front character if it is not a digit. Otherwise, does not change
- // the state of the deserializer and returns `base::nullopt`.
- base::Optional<char> TryPopNonDigit() {
+ // the state of the deserializer and returns `absl::nullopt`.
+ absl::optional<char> TryPopNonDigit() {
if (stopped_ || deserializing_.empty())
- return base::nullopt;
+ return absl::nullopt;
const char front = deserializing_.front();
if (base::IsAsciiDigit(front))
- return base::nullopt;
+ return absl::nullopt;
deserializing_ = deserializing_.substr(1);
return front;
@@ -76,7 +76,7 @@ base::TimeDelta ParseOffset(DateDeserializer& deserializer) {
base::TimeDelta offset;
// UTC is assumed if no time zone information is provided.
- const base::Optional<char> sign = deserializer.TryPopNonDigit();
+ const absl::optional<char> sign = deserializer.TryPopNonDigit();
if (!sign.has_value() || (sign.value() != '+' && sign.value() != '-'))
return offset;
@@ -84,7 +84,7 @@ base::TimeDelta ParseOffset(DateDeserializer& deserializer) {
// The spec requires that the hours offset be followed by an apostrophe, but
// don't be strict about its presence.
- const base::Optional<char> apostrophe = deserializer.TryPopNonDigit();
+ const absl::optional<char> apostrophe = deserializer.TryPopNonDigit();
if (apostrophe.has_value() && apostrophe.value() != '\'')
return sign.value() == '+' ? offset : -offset;
@@ -108,7 +108,7 @@ base::Time ParsePdfDate(base::StringPiece date) {
DateDeserializer deserializer(date);
// Year is the only required part of a valid date.
- const base::Optional<int> deserialized_year = deserializer.PopDigits(4);
+ const absl::optional<int> deserialized_year = deserializer.PopDigits(4);
if (!deserialized_year.has_value())
return base::Time();
diff --git a/chromium/pdf/pdf_view_plugin_base.cc b/chromium/pdf/pdf_view_plugin_base.cc
index b77e53a2619..6b19a79eec9 100644
--- a/chromium/pdf/pdf_view_plugin_base.cc
+++ b/chromium/pdf/pdf_view_plugin_base.cc
@@ -26,7 +26,6 @@
#include "base/notreached.h"
#include "base/numerics/ranges.h"
#include "base/numerics/safe_conversions.h"
-#include "base/optional.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
@@ -46,13 +45,19 @@
#include "pdf/ui/document_properties.h"
#include "pdf/ui/file_name.h"
#include "pdf/ui/thumbnail.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
+#include "third_party/blink/public/common/input/web_mouse_event.h"
+#include "third_party/blink/public/common/input/web_touch_event.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/text/bytes_formatting.h"
+#include "ui/events/blink/blink_event_util.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
+#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/skia_util.h"
namespace chrome_pdf {
@@ -363,6 +368,36 @@ void PdfViewPluginBase::DocumentFocusChanged(bool document_has_focus) {
SendMessage(std::move(message));
}
+// TODO(crbug.com/1191817): Add tests for input events. Unit testing should be
+// feasible now that the Pepper dependency is removed for input events.
+bool PdfViewPluginBase::HandleInputEvent(const blink::WebInputEvent& event) {
+ // Ignore user input in read-only mode.
+ if (engine()->IsReadOnly())
+ return false;
+
+ // `engine()` expects input events in device coordinates.
+ std::unique_ptr<blink::WebInputEvent> transformed_event =
+ ui::TranslateAndScaleWebInputEvent(
+ event, gfx::Vector2dF(-available_area_.x() / device_scale_, 0),
+ device_scale_);
+
+ const blink::WebInputEvent& event_to_handle =
+ transformed_event ? *transformed_event : event;
+
+ if (engine()->HandleInputEvent(event_to_handle))
+ return true;
+
+ // Middle click is used for scrolling and is handled by the container page.
+ if (blink::WebInputEvent::IsMouseEventType(event_to_handle.GetType()) &&
+ static_cast<const blink::WebMouseEvent&>(event_to_handle).button ==
+ blink::WebPointerProperties::Button::kMiddle) {
+ return false;
+ }
+
+ // Return true for unhandled clicks so the plugin takes focus.
+ return event_to_handle.GetType() == blink::WebInputEvent::Type::kMouseDown;
+}
+
void PdfViewPluginBase::HandleMessage(const base::Value& message) {
using MessageHandler = void (PdfViewPluginBase::*)(const base::Value&);
static constexpr auto kMessageHandlers =
@@ -707,7 +742,7 @@ void PdfViewPluginBase::HandleGetNamedDestinationMessage(
message.FindStringKey("namedDestination");
CHECK(destination_name);
- base::Optional<PDFEngine::NamedDestination> named_destination =
+ absl::optional<PDFEngine::NamedDestination> named_destination =
engine()->GetNamedDestination(*destination_name);
const int page_number = named_destination.has_value()
diff --git a/chromium/pdf/pdf_view_plugin_base.h b/chromium/pdf/pdf_view_plugin_base.h
index 54d3b6bed1a..e6e02c4c5fa 100644
--- a/chromium/pdf/pdf_view_plugin_base.h
+++ b/chromium/pdf/pdf_view_plugin_base.h
@@ -18,6 +18,7 @@
#include "pdf/pdfium/pdfium_form_filler.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
@@ -26,6 +27,10 @@ namespace base {
class Value;
} // namespace base
+namespace blink {
+class WebInputEvent;
+} // namespace blink
+
namespace chrome_pdf {
class Image;
@@ -126,6 +131,7 @@ class PdfViewPluginBase : public PDFEngine::Client,
// their destructor to ensure the engine is destroyed first.
void DestroyEngine();
+ const PDFiumEngine* engine() const { return engine_.get(); }
PDFiumEngine* engine() { return engine_.get(); }
PaintManager& paint_manager() { return paint_manager_; }
@@ -148,6 +154,8 @@ class PdfViewPluginBase : public PDFEngine::Client,
virtual void DidOpenPreview(std::unique_ptr<UrlLoader> loader,
int32_t result) = 0;
+ bool HandleInputEvent(const blink::WebInputEvent& event);
+
// Handles `postMessage()` calls from the embedder.
void HandleMessage(const base::Value& message);
@@ -257,6 +265,11 @@ class PdfViewPluginBase : public PDFEngine::Client,
void set_url(const std::string& url) { url_ = url; }
+ ui::mojom::CursorType cursor_type() const { return cursor_type_; }
+ void set_cursor_type(ui::mojom::CursorType cursor_type) {
+ cursor_type_ = cursor_type;
+ }
+
bool full_frame() const { return full_frame_; }
void set_full_frame(bool full_frame) { full_frame_ = full_frame; }
@@ -364,6 +377,9 @@ class PdfViewPluginBase : public PDFEngine::Client,
// The URL of the PDF document.
std::string url_;
+ // The current cursor type.
+ ui::mojom::CursorType cursor_type_ = ui::mojom::CursorType::kPointer;
+
// True if the plugin occupies the entire frame (not embedded).
bool full_frame_ = false;
@@ -372,7 +388,7 @@ class PdfViewPluginBase : public PDFEngine::Client,
std::vector<BackgroundPart> background_parts_;
- // Deferred invalidates while |in_paint_| is true.
+ // Deferred invalidates while `in_paint_` is true.
std::vector<gfx::Rect> deferred_invalidates_;
// Remaining area, in pixels, to render the pdf in after accounting for
diff --git a/chromium/pdf/pdf_view_web_plugin.cc b/chromium/pdf/pdf_view_web_plugin.cc
index c8bc44f814e..ee5716bc2a0 100644
--- a/chromium/pdf/pdf_view_web_plugin.cc
+++ b/chromium/pdf/pdf_view_web_plugin.cc
@@ -14,6 +14,7 @@
#include "base/check_op.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
+#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/thread_annotations.h"
#include "base/threading/sequenced_task_runner_handle.h"
@@ -35,10 +36,12 @@
#include "pdf/ppapi_migration/url_loader.h"
#include "ppapi/c/pp_errors.h"
#include "third_party/blink/public/common/input/web_coalesced_input_event.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/common/metrics/document_update_reason.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-shared.h"
#include "third_party/blink/public/platform/web_input_event_result.h"
#include "third_party/blink/public/platform/web_string.h"
+#include "third_party/blink/public/platform/web_text_input_type.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_request.h"
@@ -46,6 +49,7 @@
#include "third_party/blink/public/web/web_associated_url_loader.h"
#include "third_party/blink/public/web/web_associated_url_loader_options.h"
#include "third_party/blink/public/web/web_document.h"
+#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_plugin_container.h"
#include "third_party/blink/public/web/web_plugin_params.h"
@@ -54,8 +58,10 @@
#include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
+#include "ui/events/blink/blink_event_util.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/range/range.h"
#include "ui/gfx/skia_util.h"
#include "v8/include/v8.h"
@@ -71,8 +77,8 @@ namespace {
class PerProcessInitializer final {
public:
static PerProcessInitializer& GetInstance() {
- static PerProcessInitializer instance;
- return instance;
+ static base::NoDestructor<PerProcessInitializer> instance;
+ return *instance;
}
void Acquire() {
@@ -108,6 +114,52 @@ class PerProcessInitializer final {
THREAD_CHECKER(thread_checker_);
};
+class BlinkContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
+ public:
+ explicit BlinkContainerWrapper(blink::WebPluginContainer* container)
+ : container_(container) {
+ DCHECK(container_);
+ }
+ BlinkContainerWrapper(const BlinkContainerWrapper&) = delete;
+ BlinkContainerWrapper& operator=(const BlinkContainerWrapper&) = delete;
+ ~BlinkContainerWrapper() override = default;
+
+ void Invalidate() override { container_->Invalidate(); }
+
+ float DeviceScaleFactor() const override {
+ return container_->DeviceScaleFactor();
+ }
+
+ void SetReferrerForRequest(blink::WebURLRequest& request,
+ const blink::WebURL& referrer_url) override {
+ GetFrame()->SetReferrerForRequest(request, referrer_url);
+ }
+
+ void TextSelectionChanged(const blink::WebString& selection_text,
+ uint32_t offset,
+ const gfx::Range& range) override {
+ GetFrame()->TextSelectionChanged(selection_text, offset, range);
+ }
+
+ std::unique_ptr<blink::WebAssociatedURLLoader> CreateAssociatedURLLoader(
+ const blink::WebAssociatedURLLoaderOptions& options) override {
+ return GetFrame()->CreateAssociatedURLLoader(options);
+ }
+
+ void UpdateTextInputState() override {
+ return GetFrame()->FrameWidget()->UpdateTextInputState();
+ }
+
+ blink::WebLocalFrame* GetFrame() override {
+ return container_->GetDocument().GetFrame();
+ }
+
+ blink::WebPluginContainer* Container() override { return container_; }
+
+ private:
+ blink::WebPluginContainer* const container_;
+};
+
} // namespace
PdfViewWebPlugin::PdfViewWebPlugin(const blink::WebPluginParams& params)
@@ -115,10 +167,20 @@ PdfViewWebPlugin::PdfViewWebPlugin(const blink::WebPluginParams& params)
PdfViewWebPlugin::~PdfViewWebPlugin() = default;
-// Modeled on `OutOfProcessInstance::Init()`.
bool PdfViewWebPlugin::Initialize(blink::WebPluginContainer* container) {
DCHECK_EQ(container->Plugin(), this);
- container_ = container;
+ return InitializeCommon(std::make_unique<BlinkContainerWrapper>(container));
+}
+
+bool PdfViewWebPlugin::InitializeForTesting(
+ std::unique_ptr<ContainerWrapper> container_wrapper) {
+ return InitializeCommon(std::move(container_wrapper));
+}
+
+// Modeled on `OutOfProcessInstance::Init()`.
+bool PdfViewWebPlugin::InitializeCommon(
+ std::unique_ptr<ContainerWrapper> container_wrapper) {
+ container_wrapper_ = std::move(container_wrapper);
std::string stream_url;
for (size_t i = 0; i < initial_params_.attribute_names.size(); ++i) {
@@ -142,26 +204,25 @@ bool PdfViewWebPlugin::Initialize(blink::WebPluginContainer* container) {
PerProcessInitializer::GetInstance().Acquire();
InitializeEngine(PDFiumFormFiller::ScriptOption::kNoJavaScript);
LoadUrl(stream_url, /*is_print_preview=*/false);
- post_message_sender_.set_container(container_);
+ post_message_sender_.set_container(Container());
return true;
}
void PdfViewWebPlugin::Destroy() {
- if (container_) {
+ if (container_wrapper_) {
// Explicitly destroy the PDFEngine during destruction as it may call back
// into this object.
DestroyEngine();
PerProcessInitializer::GetInstance().Release();
+ container_wrapper_.reset();
+ post_message_sender_.set_container(nullptr);
}
- container_ = nullptr;
- post_message_sender_.set_container(nullptr);
-
delete this;
}
blink::WebPluginContainer* PdfViewWebPlugin::Container() const {
- return container_;
+ return container_wrapper_ ? container_wrapper_->Container() : nullptr;
}
v8::Local<v8::Object> PdfViewWebPlugin::V8ScriptableObject(
@@ -213,7 +274,7 @@ void PdfViewWebPlugin::UpdateGeometry(const gfx::Rect& window_rect,
const gfx::Rect& clip_rect,
const gfx::Rect& unobscured_rect,
bool is_visible) {
- OnViewportChanged(window_rect, container_->DeviceScaleFactor());
+ OnViewportChanged(window_rect, container_wrapper_->DeviceScaleFactor());
}
void PdfViewWebPlugin::UpdateFocus(bool focused,
@@ -224,7 +285,24 @@ void PdfViewWebPlugin::UpdateVisibility(bool visibility) {}
blink::WebInputEventResult PdfViewWebPlugin::HandleInputEvent(
const blink::WebCoalescedInputEvent& event,
ui::Cursor* cursor) {
- return blink::WebInputEventResult::kNotHandled;
+ // TODO(crbug.com/702993): The input events received by the Pepper plugin
+ // already have the device scale applied. The scaling done here should be
+ // moved into `PdfViewPluginBase::HandleInputEvent()` once the Pepper plugin
+ // is removed.
+ std::unique_ptr<blink::WebInputEvent> scaled_event =
+ ui::ScaleWebInputEvent(event.Event(), device_scale());
+
+ const blink::WebInputEvent& event_to_handle =
+ scaled_event ? *scaled_event : event.Event();
+
+ const blink::WebInputEventResult result =
+ PdfViewPluginBase::HandleInputEvent(event_to_handle)
+ ? blink::WebInputEventResult::kHandledApplication
+ : blink::WebInputEventResult::kNotHandled;
+
+ *cursor = cursor_type();
+
+ return result;
}
void PdfViewWebPlugin::DidReceiveResponse(
@@ -236,7 +314,61 @@ void PdfViewWebPlugin::DidFinishLoading() {}
void PdfViewWebPlugin::DidFailLoading(const blink::WebURLError& error) {}
-void PdfViewWebPlugin::UpdateCursor(ui::mojom::CursorType cursor_type) {}
+bool PdfViewWebPlugin::HasSelection() const {
+ return !selected_text_.IsEmpty();
+}
+
+blink::WebString PdfViewWebPlugin::SelectionAsText() const {
+ return selected_text_;
+}
+
+blink::WebString PdfViewWebPlugin::SelectionAsMarkup() const {
+ return selected_text_;
+}
+
+bool PdfViewWebPlugin::CanEditText() const {
+ return engine()->CanEditText();
+}
+
+bool PdfViewWebPlugin::HasEditableText() const {
+ return engine()->HasEditableText();
+}
+
+bool PdfViewWebPlugin::CanUndo() const {
+ return engine()->CanUndo();
+}
+
+bool PdfViewWebPlugin::CanRedo() const {
+ return engine()->CanRedo();
+}
+
+bool PdfViewWebPlugin::ExecuteEditCommand(const blink::WebString& name,
+ const blink::WebString& value) {
+ if (name == "SelectAll")
+ return SelectAll();
+
+ if (name == "Cut")
+ return Cut();
+
+ if (name == "Paste" || name == "PasteAndMatchStyle")
+ return Paste(value);
+
+ if (name == "Undo")
+ return Undo();
+
+ if (name == "Redo")
+ return Redo();
+
+ return false;
+}
+
+blink::WebTextInputType PdfViewWebPlugin::GetPluginTextInputType() {
+ return text_input_type_;
+}
+
+void PdfViewWebPlugin::UpdateCursor(ui::mojom::CursorType new_cursor_type) {
+ set_cursor_type(new_cursor_type);
+}
void PdfViewWebPlugin::UpdateTickMarks(
const std::vector<gfx::Rect>& tickmarks) {}
@@ -288,7 +420,9 @@ void PdfViewWebPlugin::SelectionChanged(const gfx::Rect& left,
void PdfViewWebPlugin::EnteredEditMode() {}
void PdfViewWebPlugin::SetSelectedText(const std::string& selected_text) {
- NOTIMPLEMENTED();
+ selected_text_ = blink::WebString::FromUTF8(selected_text);
+ container_wrapper_->TextSelectionChanged(
+ selected_text_, /*offset=*/0, gfx::Range(0, selected_text_.length()));
}
void PdfViewWebPlugin::SetLinkUnderCursor(
@@ -324,34 +458,30 @@ void PdfViewWebPlugin::ScheduleTaskOnMainThread(const base::Location& from_here,
}
bool PdfViewWebPlugin::IsValid() const {
- return container_ && container_->GetDocument().GetFrame();
+ return container_wrapper_ && container_wrapper_->GetFrame();
}
blink::WebURL PdfViewWebPlugin::CompleteURL(
const blink::WebString& partial_url) const {
DCHECK(IsValid());
- return container_->GetDocument().CompleteURL(partial_url);
+ return Container()->GetDocument().CompleteURL(partial_url);
}
net::SiteForCookies PdfViewWebPlugin::SiteForCookies() const {
DCHECK(IsValid());
- return container_->GetDocument().SiteForCookies();
+ return Container()->GetDocument().SiteForCookies();
}
void PdfViewWebPlugin::SetReferrerForRequest(
blink::WebURLRequest& request,
const blink::WebURL& referrer_url) {
- DCHECK(IsValid());
- container_->GetDocument().GetFrame()->SetReferrerForRequest(request,
- referrer_url);
+ container_wrapper_->SetReferrerForRequest(request, referrer_url);
}
std::unique_ptr<blink::WebAssociatedURLLoader>
PdfViewWebPlugin::CreateAssociatedURLLoader(
const blink::WebAssociatedURLLoaderOptions& options) {
- DCHECK(IsValid());
- return container_->GetDocument().GetFrame()->CreateAssociatedURLLoader(
- options);
+ return container_wrapper_->CreateAssociatedURLLoader(options);
}
void PdfViewWebPlugin::OnMessage(const base::Value& message) {
@@ -364,7 +494,8 @@ void PdfViewWebPlugin::UpdateSnapshot(sk_sp<SkImage> snapshot) {
.set_image(std::move(snapshot), cc::PaintImage::GetNextContentId())
.set_id(cc::PaintImage::GetNextId())
.TakePaintImage();
- InvalidateRectInPluginContainer(gfx::Rect(plugin_rect().size()));
+ if (!plugin_rect().IsEmpty())
+ InvalidatePluginContainer();
}
base::WeakPtr<PdfViewPluginBase> PdfViewWebPlugin::GetWeakPtr() {
@@ -402,7 +533,9 @@ void PdfViewWebPlugin::InitImageData(const gfx::Size& size) {
}
void PdfViewWebPlugin::SetFormFieldInFocus(bool in_focus) {
- NOTIMPLEMENTED();
+ text_input_type_ = in_focus ? blink::WebTextInputType::kWebTextInputTypeText
+ : blink::WebTextInputType::kWebTextInputTypeNone;
+ container_wrapper_->UpdateTextInputState();
}
// TODO(https://crbug.com/1144444): Add a Pepper-free implementation to set
@@ -458,18 +591,47 @@ void PdfViewWebPlugin::OnViewportChanged(const gfx::Rect& view_rect,
}
void PdfViewWebPlugin::InvalidatePluginContainer() {
- DCHECK(container_);
+ container_wrapper_->Invalidate();
+}
+
+bool PdfViewWebPlugin::SelectAll() {
+ if (!CanEditText())
+ return false;
- container_->Invalidate();
+ engine()->SelectAll();
+ return true;
}
-void PdfViewWebPlugin::InvalidateRectInPluginContainer(const gfx::Rect& rect) {
- DCHECK(container_);
+bool PdfViewWebPlugin::Cut() {
+ if (!HasSelection() || !CanEditText())
+ return false;
- if (plugin_rect().IsEmpty())
- return;
+ engine()->ReplaceSelection("");
+ return true;
+}
+
+bool PdfViewWebPlugin::Paste(const blink::WebString& value) {
+ if (!CanEditText())
+ return false;
- container_->InvalidateRect(rect);
+ engine()->ReplaceSelection(value.Utf8());
+ return true;
+}
+
+bool PdfViewWebPlugin::Undo() {
+ if (!CanUndo())
+ return false;
+
+ engine()->Undo();
+ return true;
+}
+
+bool PdfViewWebPlugin::Redo() {
+ if (!CanRedo())
+ return false;
+
+ engine()->Redo();
+ return true;
}
} // namespace chrome_pdf
diff --git a/chromium/pdf/pdf_view_web_plugin.h b/chromium/pdf/pdf_view_web_plugin.h
index 72a94d14098..f594e5ffe53 100644
--- a/chromium/pdf/pdf_view_web_plugin.h
+++ b/chromium/pdf/pdf_view_web_plugin.h
@@ -5,6 +5,8 @@
#ifndef PDF_PDF_VIEW_WEB_PLUGIN_H_
#define PDF_PDF_VIEW_WEB_PLUGIN_H_
+#include <memory>
+
#include "base/memory/weak_ptr.h"
#include "cc/paint/paint_image.h"
#include "pdf/pdf_view_plugin_base.h"
@@ -12,14 +14,25 @@
#include "pdf/post_message_sender.h"
#include "pdf/ppapi_migration/graphics.h"
#include "pdf/ppapi_migration/url_loader.h"
+#include "third_party/blink/public/platform/web_string.h"
+#include "third_party/blink/public/platform/web_text_input_type.h"
#include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/public/web/web_plugin_params.h"
#include "v8/include/v8.h"
namespace blink {
+class WebAssociatedURLLoader;
+class WebLocalFrame;
class WebPluginContainer;
+class WebURL;
+class WebURLRequest;
+struct WebAssociatedURLLoaderOptions;
} // namespace blink
+namespace gfx {
+class Range;
+} // namespace gfx
+
namespace chrome_pdf {
// Skeleton for a `blink::WebPlugin` to replace `OutOfProcessInstance`.
@@ -29,6 +42,42 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
public PostMessageReceiver::Client,
public SkiaGraphics::Client {
public:
+ class ContainerWrapper {
+ public:
+ virtual ~ContainerWrapper() = default;
+
+ // Invalidates the entire web plugin container and schedules a paint of the
+ // page in it.
+ virtual void Invalidate() = 0;
+
+ // Returns the device scale factor.
+ virtual float DeviceScaleFactor() const = 0;
+
+ // Calls underlying WebLocalFrame::SetReferrerForRequest().
+ virtual void SetReferrerForRequest(blink::WebURLRequest& request,
+ const blink::WebURL& referrer_url) = 0;
+
+ // Calls underlying WebLocalFrame::TextSelectionChanged().
+ virtual void TextSelectionChanged(const blink::WebString& selection_text,
+ uint32_t offset,
+ const gfx::Range& range) = 0;
+
+ // Calls underlying WebLocalFrame::CreateAssociatedURLLoader().
+ virtual std::unique_ptr<blink::WebAssociatedURLLoader>
+ CreateAssociatedURLLoader(
+ const blink::WebAssociatedURLLoaderOptions& options) = 0;
+
+ // Notifies the frame widget about the text input type change.
+ virtual void UpdateTextInputState() = 0;
+
+ // Returns the local frame to which the web plugin container belongs.
+ virtual blink::WebLocalFrame* GetFrame() = 0;
+
+ // Returns the blink web plugin container pointer that's wrapped inside this
+ // object. Returns nullptr if this object is for test only.
+ virtual blink::WebPluginContainer* Container() = 0;
+ };
+
explicit PdfViewWebPlugin(const blink::WebPluginParams& params);
PdfViewWebPlugin(const PdfViewWebPlugin& other) = delete;
PdfViewWebPlugin& operator=(const PdfViewWebPlugin& other) = delete;
@@ -53,9 +102,19 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
void DidReceiveData(const char* data, size_t data_length) override;
void DidFinishLoading() override;
void DidFailLoading(const blink::WebURLError& error) override;
+ bool HasSelection() const override;
+ blink::WebString SelectionAsText() const override;
+ blink::WebString SelectionAsMarkup() const override;
+ bool CanEditText() const override;
+ bool HasEditableText() const override;
+ bool CanUndo() const override;
+ bool CanRedo() const override;
+ bool ExecuteEditCommand(const blink::WebString& name,
+ const blink::WebString& value) override;
+ blink::WebTextInputType GetPluginTextInputType() override;
// PdfViewPluginBase:
- void UpdateCursor(ui::mojom::CursorType cursor_type) override;
+ void UpdateCursor(ui::mojom::CursorType new_cursor_type) override;
void UpdateTickMarks(const std::vector<gfx::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override;
@@ -100,6 +159,12 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// SkiaGraphics::Client:
void UpdateSnapshot(sk_sp<SkImage> snapshot) override;
+ // Initializes the plugin using the `container_wrapper` provided by tests.
+ bool InitializeForTesting(
+ std::unique_ptr<ContainerWrapper> container_wrapper);
+
+ const gfx::Rect& GetPluginRectForTesting() const { return plugin_rect(); }
+
protected:
// PdfViewPluginBase:
base::WeakPtr<PdfViewPluginBase> GetWeakPtr() override;
@@ -127,18 +192,29 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
// Call `Destroy()` instead.
~PdfViewWebPlugin() override;
+ bool InitializeCommon(std::unique_ptr<ContainerWrapper> container_wrapper);
+
void OnViewportChanged(const gfx::Rect& view_rect, float new_device_scale);
// Invalidates the entire web plugin container and schedules a paint of the
// page in it.
void InvalidatePluginContainer();
- // Schedules a paint of the page of a given region in the web plugin
- // container. The coordinates are relative to the top-left of the container.
- void InvalidateRectInPluginContainer(const gfx::Rect& rect);
+ // Text editing methods.
+ bool SelectAll();
+ bool Cut();
+ bool Paste(const blink::WebString& value);
+ bool Undo();
+ bool Redo();
+
+ blink::WebString selected_text_;
+
+ blink::WebTextInputType text_input_type_ =
+ blink::WebTextInputType::kWebTextInputTypeNone;
blink::WebPluginParams initial_params_;
- blink::WebPluginContainer* container_ = nullptr;
+
+ std::unique_ptr<ContainerWrapper> container_wrapper_;
v8::Persistent<v8::Object> scriptable_receiver_;
PostMessageSender post_message_sender_;
diff --git a/chromium/pdf/pdf_view_web_plugin_unittest.cc b/chromium/pdf/pdf_view_web_plugin_unittest.cc
new file mode 100644
index 00000000000..7606edbfd74
--- /dev/null
+++ b/chromium/pdf/pdf_view_web_plugin_unittest.cc
@@ -0,0 +1,324 @@
+// Copyright 2021 The Chromium 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 "pdf/pdf_view_web_plugin.h"
+
+#include <memory>
+#include <utility>
+
+#include "cc/paint/paint_canvas.h"
+#include "cc/test/pixel_comparator.h"
+#include "cc/test/pixel_test_utils.h"
+#include "pdf/ppapi_migration/bitmap.h"
+#include "pdf/test/test_helpers.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/platform/web_string.h"
+#include "third_party/blink/public/platform/web_text_input_type.h"
+#include "third_party/blink/public/web/web_associated_url_loader.h"
+#include "third_party/blink/public/web/web_plugin_params.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/skia_util.h"
+
+namespace chrome_pdf {
+
+namespace {
+
+// `kCanvasSize` needs to be big enough to hold plugin's snapshots during
+// testing.
+constexpr gfx::Size kCanvasSize(100, 100);
+
+// Note: Make sure `kDefaultColor` is different from `kPaintColor` and the
+// plugin's background color. This will help identify bitmap changes after
+// painting.
+constexpr SkColor kDefaultColor = SK_ColorGREEN;
+
+constexpr SkColor kPaintColor = SK_ColorRED;
+
+struct PaintParams {
+ // The plugin container's device scale.
+ float device_scale;
+
+ // The window area.
+ gfx::Rect window_rect;
+
+ // The target painting area on the canvas.
+ gfx::Rect paint_rect;
+};
+
+// Generates the expected `SkBitmap` with `paint_color` filled in the expected
+// clipped area and `kDefaultColor` as the background color.
+SkBitmap GenerateExpectedBitmapForPaint(float device_scale,
+ const gfx::Rect& plugin_rect,
+ const gfx::Rect& paint_rect,
+ SkColor paint_color) {
+ gfx::Rect expected_clipped_area = gfx::IntersectRects(
+ gfx::ScaleToEnclosingRectSafe(plugin_rect, 1.0f / device_scale),
+ paint_rect);
+
+ SkBitmap expected_bitmap =
+ CreateN32PremulSkBitmap(gfx::SizeToSkISize(kCanvasSize));
+ expected_bitmap.eraseColor(kDefaultColor);
+ expected_bitmap.erase(paint_color, gfx::RectToSkIRect(expected_clipped_area));
+ return expected_bitmap;
+}
+
+class FakeContainerWrapper final : public PdfViewWebPlugin::ContainerWrapper {
+ public:
+ explicit FakeContainerWrapper(PdfViewWebPlugin* web_plugin)
+ : web_plugin_(web_plugin) {
+ UpdateTextInputState();
+ }
+
+ FakeContainerWrapper(const FakeContainerWrapper&) = delete;
+ FakeContainerWrapper& operator=(const FakeContainerWrapper&) = delete;
+ ~FakeContainerWrapper() override = default;
+
+ // PdfViewWebPlugin::ContainerWrapper:
+ void Invalidate() override {}
+
+ float DeviceScaleFactor() const override { return device_scale_; }
+
+ MOCK_METHOD(void,
+ SetReferrerForRequest,
+ (blink::WebURLRequest&, const blink::WebURL&),
+ (override));
+
+ MOCK_METHOD(void,
+ TextSelectionChanged,
+ (const blink::WebString&, uint32_t, const gfx::Range&),
+ (override));
+
+ MOCK_METHOD(std::unique_ptr<blink::WebAssociatedURLLoader>,
+ CreateAssociatedURLLoader,
+ (const blink::WebAssociatedURLLoaderOptions&),
+ (override));
+
+ void UpdateTextInputState() override {
+ widget_text_input_type_ = web_plugin_->GetPluginTextInputType();
+ }
+
+ blink::WebLocalFrame* GetFrame() override { return nullptr; }
+
+ // TODO(https://crbug.com/1207575): Container() should not be used for testing
+ // since it doesn't have a valid blink::WebPluginContainer. Make this method
+ // fail once ContainerWrapper instead of blink::WebPluginContainer is used for
+ // initializing `PostMessageSender`.
+ blink::WebPluginContainer* Container() override { return nullptr; }
+
+ blink::WebTextInputType widget_text_input_type() const {
+ return widget_text_input_type_;
+ }
+
+ void set_device_scale(float device_scale) { device_scale_ = device_scale; }
+
+ private:
+ float device_scale_ = 1.0f;
+
+ // Represents the frame widget's text input type.
+ blink::WebTextInputType widget_text_input_type_;
+
+ PdfViewWebPlugin* web_plugin_;
+};
+
+} // namespace
+
+class PdfViewWebPluginTest : public testing::Test {
+ public:
+ // Custom deleter for `plugin_`. PdfViewWebPlugin must be destroyed by
+ // PdfViewWebPlugin::Destroy() instead of its destructor.
+ struct PluginDeleter {
+ void operator()(PdfViewWebPlugin* ptr) { ptr->Destroy(); }
+ };
+
+ PdfViewWebPluginTest() = default;
+ PdfViewWebPluginTest(const PdfViewWebPluginTest&) = delete;
+ PdfViewWebPluginTest& operator=(const PdfViewWebPluginTest&) = delete;
+ ~PdfViewWebPluginTest() override = default;
+
+ void SetUp() override {
+ plugin_ = std::unique_ptr<PdfViewWebPlugin, PluginDeleter>(
+ new PdfViewWebPlugin(blink::WebPluginParams()));
+
+ auto wrapper = std::make_unique<FakeContainerWrapper>(plugin_.get());
+ wrapper_ptr_ = wrapper.get();
+ plugin_->InitializeForTesting(std::move(wrapper));
+ }
+
+ void TearDown() override {
+ plugin_.reset();
+ wrapper_ptr_ = nullptr;
+ }
+
+ void UpdatePluginGeometry(float device_scale, const gfx::Rect& window_rect) {
+ // The plugin container's device scale must be set before calling
+ // UpdateGeometry().
+ ASSERT_TRUE(wrapper_ptr_);
+ wrapper_ptr_->set_device_scale(device_scale);
+ plugin_->UpdateGeometry(window_rect, window_rect, window_rect,
+ /*is_visible=*/true);
+ }
+
+ void TestUpdateGeometrySetsPluginRect(float device_scale,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& expected_plugin_rect) {
+ UpdatePluginGeometry(device_scale, window_rect);
+ EXPECT_EQ(expected_plugin_rect, plugin_->GetPluginRectForTesting())
+ << "Failure at device scale of " << device_scale << ", window rect of "
+ << window_rect.ToString();
+ }
+
+ void TestPaintEmptySnapshots(float device_scale,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& paint_rect) {
+ UpdatePluginGeometry(device_scale, window_rect);
+ canvas_.DrawColor(kDefaultColor);
+
+ plugin_->Paint(canvas_.sk_canvas(), paint_rect);
+
+ // Expect the clipped area on canvas to be filled with plugin's background
+ // color.
+ SkBitmap expected_bitmap = GenerateExpectedBitmapForPaint(
+ device_scale, plugin_->GetPluginRectForTesting(), paint_rect,
+ plugin_->GetBackgroundColor());
+ EXPECT_TRUE(
+ cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap,
+ cc::ExactPixelComparator(/*discard_alpha=*/false)))
+ << "Failure at device scale of " << device_scale << ", window rect of "
+ << window_rect.ToString();
+ }
+
+ void TestPaintSnapshots(float device_scale,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& paint_rect) {
+ UpdatePluginGeometry(device_scale, window_rect);
+ canvas_.DrawColor(kDefaultColor);
+
+ // Fill the graphics device with `kPaintColor` and update the plugin's
+ // snapshot.
+ const gfx::Rect& plugin_rect = plugin_->GetPluginRectForTesting();
+ std::unique_ptr<Graphics> graphics =
+ plugin_->CreatePaintGraphics(plugin_rect.size());
+ graphics->PaintImage(
+ CreateSkiaImageForTesting(plugin_rect.size(), kPaintColor),
+ gfx::Rect(plugin_rect.width(), plugin_rect.height()));
+ graphics->Flush(base::DoNothing());
+
+ plugin_->Paint(canvas_.sk_canvas(), paint_rect);
+
+ // Expect the clipped area on canvas to be filled with `kPaintColor`.
+ SkBitmap expected_bitmap = GenerateExpectedBitmapForPaint(
+ device_scale, plugin_rect, paint_rect, kPaintColor);
+ EXPECT_TRUE(
+ cc::MatchesBitmap(canvas_.GetBitmap(), expected_bitmap,
+ cc::ExactPixelComparator(/*discard_alpha=*/false)))
+ << "Failure at device scale of " << device_scale << ", window rect of "
+ << window_rect.ToString();
+ }
+
+ FakeContainerWrapper* wrapper_ptr_;
+ std::unique_ptr<PdfViewWebPlugin, PluginDeleter> plugin_;
+
+ // Provides the cc::PaintCanvas for painting.
+ gfx::Canvas canvas_{kCanvasSize, /*image_scale=*/1.0f, /*is_opaque=*/true};
+};
+
+TEST_F(PdfViewWebPluginTest, UpdateGeometrySetsPluginRect) {
+ struct UpdateGeometryParams {
+ // The plugin container's device scale.
+ float device_scale;
+
+ // The window area.
+ gfx::Rect window_rect;
+
+ // The expected plugin rect.
+ gfx::Rect expected_plugin_rect;
+ };
+
+ static constexpr UpdateGeometryParams kUpdateGeometryParams[] = {
+ {1.0f, gfx::Rect(3, 4, 5, 6), gfx::Rect(3, 4, 5, 6)},
+ {2.0f, gfx::Rect(5, 6, 7, 8), gfx::Rect(10, 12, 14, 16)},
+ };
+
+ for (const auto& params : kUpdateGeometryParams) {
+ TestUpdateGeometrySetsPluginRect(params.device_scale, params.window_rect,
+ params.expected_plugin_rect);
+ }
+}
+
+TEST_F(PdfViewWebPluginTest, PaintEmptySnapshots) {
+ static constexpr PaintParams kPaintEmptySnapshotsParams[]{
+ // The window origin falls outside the `paint_rect` area.
+ {1.0f, gfx::Rect(10, 10, 20, 20), gfx::Rect(5, 5, 15, 15)},
+ {4.0f, gfx::Rect(10, 10, 20, 20), gfx::Rect(5, 5, 15, 15)},
+ // The window origin falls within the `paint_rect` area.
+ {1.0f, gfx::Rect(4, 4, 20, 20), gfx::Rect(8, 8, 15, 15)},
+ {4.0f, gfx::Rect(4, 4, 20, 20), gfx::Rect(8, 8, 15, 15)},
+ };
+
+ for (const auto& params : kPaintEmptySnapshotsParams) {
+ TestPaintEmptySnapshots(params.device_scale, params.window_rect,
+ params.paint_rect);
+ }
+}
+
+TEST_F(PdfViewWebPluginTest, PaintSnapshots) {
+ static constexpr PaintParams kPaintWithScalesTestParams[] = {
+ // The window origin falls outside the `paint_rect` area.
+ {1.0f, gfx::Rect(8, 8, 30, 30), gfx::Rect(10, 10, 30, 30)},
+ {2.0f, gfx::Rect(8, 8, 30, 30), gfx::Rect(10, 10, 30, 30)},
+ // The window origin falls within the `paint_rect` area.
+ {1.0f, gfx::Rect(10, 10, 30, 30), gfx::Rect(4, 4, 30, 30)},
+ {2.0f, gfx::Rect(10, 10, 30, 30), gfx::Rect(4, 4, 30, 30)},
+ };
+
+ for (const auto& params : kPaintWithScalesTestParams) {
+ TestPaintSnapshots(params.device_scale, params.window_rect,
+ params.paint_rect);
+ }
+}
+
+TEST_F(PdfViewWebPluginTest, ChangeTextSelection) {
+ ASSERT_FALSE(plugin_->HasSelection());
+ ASSERT_TRUE(plugin_->SelectionAsText().IsEmpty());
+ ASSERT_TRUE(plugin_->SelectionAsMarkup().IsEmpty());
+
+ static constexpr char kSelectedText[] = "1234";
+ EXPECT_CALL(*wrapper_ptr_,
+ TextSelectionChanged(blink::WebString::FromUTF8(kSelectedText), 0,
+ gfx::Range(0, 4)));
+
+ plugin_->SetSelectedText(kSelectedText);
+ EXPECT_TRUE(plugin_->HasSelection());
+ EXPECT_EQ(kSelectedText, plugin_->SelectionAsText().Utf8());
+ EXPECT_EQ(kSelectedText, plugin_->SelectionAsMarkup().Utf8());
+
+ static constexpr char kEmptyText[] = "";
+ EXPECT_CALL(*wrapper_ptr_,
+ TextSelectionChanged(blink::WebString::FromUTF8(kEmptyText), 0,
+ gfx::Range(0, 0)));
+ plugin_->SetSelectedText(kEmptyText);
+ EXPECT_FALSE(plugin_->HasSelection());
+ EXPECT_TRUE(plugin_->SelectionAsText().IsEmpty());
+ EXPECT_TRUE(plugin_->SelectionAsMarkup().IsEmpty());
+}
+
+TEST_F(PdfViewWebPluginTest, FormTextFieldFocusChangeUpdatesTextInputType) {
+ ASSERT_EQ(blink::WebTextInputType::kWebTextInputTypeNone,
+ wrapper_ptr_->widget_text_input_type());
+
+ plugin_->FormTextFieldFocusChange(true);
+ EXPECT_EQ(blink::WebTextInputType::kWebTextInputTypeText,
+ wrapper_ptr_->widget_text_input_type());
+
+ plugin_->FormTextFieldFocusChange(false);
+ EXPECT_EQ(blink::WebTextInputType::kWebTextInputTypeNone,
+ wrapper_ptr_->widget_text_input_type());
+}
+
+} // namespace chrome_pdf
diff --git a/chromium/pdf/pdfium/findtext_unittest.cc b/chromium/pdf/pdfium/findtext_unittest.cc
index acca90d79c8..740e449eba3 100644
--- a/chromium/pdf/pdfium/findtext_unittest.cc
+++ b/chromium/pdf/pdfium/findtext_unittest.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/optional.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_test_base.h"
#include "pdf/test/test_client.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
using testing::_;
using testing::InSequence;
diff --git a/chromium/pdf/pdfium/pdfium_api_string_buffer_adapter.h b/chromium/pdf/pdfium/pdfium_api_string_buffer_adapter.h
index 4eaaf3c7663..32a95230b5f 100644
--- a/chromium/pdf/pdfium/pdfium_api_string_buffer_adapter.h
+++ b/chromium/pdf/pdfium/pdfium_api_string_buffer_adapter.h
@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/numerics/safe_math.h"
-#include "base/optional.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace chrome_pdf {
@@ -24,11 +24,11 @@ namespace internal {
template <class StringType>
class PDFiumAPIStringBufferAdapter {
public:
- // |str| is the string to write into.
- // |expected_size| is the number of characters the PDFium API will write,
+ // `str` is the string to write into.
+ // `expected_size` is the number of characters the PDFium API will write,
// including the null-terminator. It should be at least 1.
- // |check_expected_size| whether to check the actual number of characters
- // written into |str| against |expected_size| when calling Close().
+ // `check_expected_size` whether to check the actual number of characters
+ // written into `str` against `expected_size` when calling Close().
PDFiumAPIStringBufferAdapter(StringType* str,
size_t expected_size,
bool check_expected_size);
@@ -37,12 +37,12 @@ class PDFiumAPIStringBufferAdapter {
delete;
~PDFiumAPIStringBufferAdapter();
- // Returns a pointer to |str_|'s buffer. The buffer's size is large enough to
- // hold |expected_size_| + 1 characters, so the PDFium API that uses the
+ // Returns a pointer to `str_`'s buffer. The buffer's size is large enough to
+ // hold `expected_size_` + 1 characters, so the PDFium API that uses the
// pointer has space to write a null-terminator.
void* GetData();
- // Resizes |str_| to |actual_size| - 1 characters, thereby removing the extra
+ // Resizes `str_` to `actual_size` - 1 characters, thereby removing the extra
// null-terminator. This must be called prior to the adapter's destruction.
// The pointer returned by GetData() should be considered invalid.
void Close(size_t actual_size);
@@ -68,23 +68,23 @@ class PDFiumAPIStringBufferAdapter {
// for std::strings, PDFiumAPIStringBufferAdapter is equivalent.
class PDFiumAPIStringBufferSizeInBytesAdapter {
public:
- // |str| is the string to write into.
- // |expected_size| is the number of bytes the PDFium API will write,
+ // `str` is the string to write into.
+ // `expected_size` is the number of bytes the PDFium API will write,
// including the null-terminator. It should be at least the size of a
// character in bytes.
- // |check_expected_size| whether to check the actual number of bytes
- // written into |str| against |expected_size| when calling Close().
+ // `check_expected_size` whether to check the actual number of bytes
+ // written into `str` against `expected_size` when calling Close().
PDFiumAPIStringBufferSizeInBytesAdapter(std::u16string* str,
size_t expected_size,
bool check_expected_size);
~PDFiumAPIStringBufferSizeInBytesAdapter();
- // Returns a pointer to |str_|'s buffer. The buffer's size is large enough to
- // hold |expected_size_| + sizeof(char16_t) bytes, so the PDFium API that
+ // Returns a pointer to `str_`'s buffer. The buffer's size is large enough to
+ // hold `expected_size_` + sizeof(char16_t) bytes, so the PDFium API that
// uses the pointer has space to write a null-terminator.
void* GetData();
- // Resizes |str_| to |actual_size| - sizeof(char16_t) bytes, thereby
+ // Resizes `str_` to `actual_size` - sizeof(char16_t) bytes, thereby
// removing the extra null-terminator. This must be called prior to the
// adapter's destruction. The pointer returned by GetData() should be
// considered invalid.
@@ -103,12 +103,12 @@ template <class AdapterType,
class StringType,
typename BufferType,
typename ReturnType>
-base::Optional<StringType> CallPDFiumStringBufferApiAndReturnOptional(
+absl::optional<StringType> CallPDFiumStringBufferApiAndReturnOptional(
base::RepeatingCallback<ReturnType(BufferType*, ReturnType)> api,
bool check_expected_size) {
ReturnType expected_size = api.Run(nullptr, 0);
if (expected_size == 0)
- return base::nullopt;
+ return absl::nullopt;
StringType str;
AdapterType api_string_adapter(&str, expected_size, check_expected_size);
@@ -124,7 +124,7 @@ template <class AdapterType,
StringType CallPDFiumStringBufferApi(
base::RepeatingCallback<ReturnType(BufferType*, ReturnType)> api,
bool check_expected_size) {
- base::Optional<StringType> result =
+ absl::optional<StringType> result =
CallPDFiumStringBufferApiAndReturnOptional<AdapterType, StringType>(
api, check_expected_size);
return result.value_or(StringType());
@@ -146,7 +146,7 @@ std::u16string CallPDFiumWideStringBufferApi(
// Variant of CallPDFiumWideStringBufferApi() that distinguishes between API
// call failures and empty string return values.
template <typename BufferType>
-base::Optional<std::u16string> CallPDFiumWideStringBufferApiAndReturnOptional(
+absl::optional<std::u16string> CallPDFiumWideStringBufferApiAndReturnOptional(
base::RepeatingCallback<unsigned long(BufferType*, unsigned long)> api,
bool check_expected_size) {
using adapter_type = internal::PDFiumAPIStringBufferSizeInBytesAdapter;
diff --git a/chromium/pdf/pdfium/pdfium_assert_matching_enums.cc b/chromium/pdf/pdfium/pdfium_assert_matching_enums.cc
index 49faf44e9cb..fc24ccd4ff5 100644
--- a/chromium/pdf/pdfium/pdfium_assert_matching_enums.cc
+++ b/chromium/pdf/pdfium/pdfium_assert_matching_enums.cc
@@ -6,10 +6,10 @@
#include "pdf/accessibility_structs.h"
#include "pdf/content_restriction.h"
#include "pdf/document_metadata.h"
-#include "pdf/ppapi_migration/input_event_conversions.h"
#include "ppapi/c/pp_input_event.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/private/ppp_pdf.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/pdfium/public/fpdf_edit.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
#include "third_party/pdfium/public/fpdf_fwlevent.h"
@@ -21,60 +21,29 @@
#include "pdf/pdf.h"
#endif
+namespace chrome_pdf {
+
#define STATIC_ASSERT_ENUM(a, b) \
static_assert(static_cast<int>(a) == static_cast<int>(b), \
"mismatching enums: " #a)
-// Enum asserts between PP_INPUTEVENT_MODIFIER* and InputEventModifier
-// modifiers.
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_SHIFTKEY,
- chrome_pdf::kInputEventModifierShiftKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_CONTROLKEY,
- chrome_pdf::kInputEventModifierControlKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ALTKEY,
- chrome_pdf::kInputEventModifierAltKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_METAKEY,
- chrome_pdf::kInputEventModifierMetaKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISKEYPAD,
- chrome_pdf::kInputEventModifierIsKeyPad);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT,
- chrome_pdf::kInputEventModifierIsAutoRepeat);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN,
- chrome_pdf::kInputEventModifierLeftButtonDown);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN,
- chrome_pdf::kInputEventModifierMiddleButtonDown);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN,
- chrome_pdf::kInputEventModifierRightButtonDown);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY,
- chrome_pdf::kInputEventModifierCapsLockKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY,
- chrome_pdf::kInputEventModifierNumLockKey);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISLEFT,
- chrome_pdf::kInputEventModifierIsLeft);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISRIGHT,
- chrome_pdf::kInputEventModifierIsRight);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISPEN,
- chrome_pdf::kInputEventModifierIsPen);
-STATIC_ASSERT_ENUM(PP_INPUTEVENT_MODIFIER_ISERASER,
- chrome_pdf::kInputEventModifierIsEraser);
-
-// Enum asserts between InputEventModifier and FWL_* modifiers.
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierShiftKey,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kShiftKey,
FWL_EVENTFLAG_ShiftKey);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierControlKey,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kControlKey,
FWL_EVENTFLAG_ControlKey);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierAltKey, FWL_EVENTFLAG_AltKey);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierMetaKey,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kAltKey,
+ FWL_EVENTFLAG_AltKey);
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kMetaKey,
FWL_EVENTFLAG_MetaKey);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierIsKeyPad,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kIsKeyPad,
FWL_EVENTFLAG_KeyPad);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierIsAutoRepeat,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kIsAutoRepeat,
FWL_EVENTFLAG_AutoRepeat);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierLeftButtonDown,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kLeftButtonDown,
FWL_EVENTFLAG_LeftButtonDown);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierMiddleButtonDown,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kMiddleButtonDown,
FWL_EVENTFLAG_MiddleButtonDown);
-STATIC_ASSERT_ENUM(chrome_pdf::kInputEventModifierRightButtonDown,
+STATIC_ASSERT_ENUM(blink::WebInputEvent::Modifiers::kRightButtonDown,
FWL_EVENTFLAG_RightButtonDown);
STATIC_ASSERT_ENUM(ui::VKEY_BACK, FWL_VKEY_Back);
@@ -278,131 +247,23 @@ STATIC_ASSERT_ENUM(PP_TEXTRENDERINGMODE_FILLSTROKECLIP,
STATIC_ASSERT_ENUM(PP_TEXTRENDERINGMODE_CLIP, FPDF_TEXTRENDERMODE_CLIP);
STATIC_ASSERT_ENUM(PP_TEXTRENDERINGMODE_LAST, FPDF_TEXTRENDERMODE_LAST);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kUnknown,
- PP_TEXTRENDERINGMODE_UNKNOWN);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kFill,
- PP_TEXTRENDERINGMODE_FILL);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kStroke,
- PP_TEXTRENDERINGMODE_STROKE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kFillStroke,
- PP_TEXTRENDERINGMODE_FILLSTROKE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kInvisible,
- PP_TEXTRENDERINGMODE_INVISIBLE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kFillClip,
- PP_TEXTRENDERINGMODE_FILLCLIP);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kStrokeClip,
- PP_TEXTRENDERINGMODE_STROKECLIP);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kFillStrokeClip,
- PP_TEXTRENDERINGMODE_FILLSTROKECLIP);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kClip,
- PP_TEXTRENDERINGMODE_CLIP);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextRenderMode::kMaxValue,
- PP_TEXTRENDERINGMODE_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::FormType::kNone, FORMTYPE_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::FormType::kAcroForm, FORMTYPE_ACRO_FORM);
-STATIC_ASSERT_ENUM(chrome_pdf::FormType::kXFAFull, FORMTYPE_XFA_FULL);
-STATIC_ASSERT_ENUM(chrome_pdf::FormType::kXFAForeground,
- FORMTYPE_XFA_FOREGROUND);
-STATIC_ASSERT_ENUM(chrome_pdf::FormType::kMaxValue, FORMTYPE_COUNT - 1);
+STATIC_ASSERT_ENUM(FormType::kNone, FORMTYPE_NONE);
+STATIC_ASSERT_ENUM(FormType::kAcroForm, FORMTYPE_ACRO_FORM);
+STATIC_ASSERT_ENUM(FormType::kXFAFull, FORMTYPE_XFA_FULL);
+STATIC_ASSERT_ENUM(FormType::kXFAForeground, FORMTYPE_XFA_FOREGROUND);
+STATIC_ASSERT_ENUM(FormType::kMaxValue, FORMTYPE_COUNT - 1);
STATIC_ASSERT_ENUM(PP_PRIVATEBUTTON_PUSHBUTTON, FPDF_FORMFIELD_PUSHBUTTON);
STATIC_ASSERT_ENUM(PP_PRIVATEBUTTON_CHECKBOX, FPDF_FORMFIELD_CHECKBOX);
STATIC_ASSERT_ENUM(PP_PRIVATEBUTTON_RADIOBUTTON, FPDF_FORMFIELD_RADIOBUTTON);
#if defined(OS_WIN)
-STATIC_ASSERT_ENUM(chrome_pdf::kEmf, FPDF_PRINTMODE_EMF);
-STATIC_ASSERT_ENUM(chrome_pdf::kTextOnly, FPDF_PRINTMODE_TEXTONLY);
-STATIC_ASSERT_ENUM(chrome_pdf::kPostScript2, FPDF_PRINTMODE_POSTSCRIPT2);
-STATIC_ASSERT_ENUM(chrome_pdf::kPostScript3, FPDF_PRINTMODE_POSTSCRIPT3);
-STATIC_ASSERT_ENUM(chrome_pdf::kEmfWithReducedRasterization,
+STATIC_ASSERT_ENUM(kEmf, FPDF_PRINTMODE_EMF);
+STATIC_ASSERT_ENUM(kTextOnly, FPDF_PRINTMODE_TEXTONLY);
+STATIC_ASSERT_ENUM(kPostScript2, FPDF_PRINTMODE_POSTSCRIPT2);
+STATIC_ASSERT_ENUM(kPostScript3, FPDF_PRINTMODE_POSTSCRIPT3);
+STATIC_ASSERT_ENUM(kEmfWithReducedRasterization,
FPDF_PRINTMODE_EMF_IMAGE_MASKS);
#endif
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kNone,
- PP_PRIVATEDIRECTION_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kLeftToRight,
- PP_PRIVATEDIRECTION_LTR);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kRightToLeft,
- PP_PRIVATEDIRECTION_RTL);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kTopToBottom,
- PP_PRIVATEDIRECTION_TTB);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kBottomToTop,
- PP_PRIVATEDIRECTION_BTT);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityTextDirection::kMaxValue,
- PP_PRIVATEDIRECTION_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::ChoiceFieldType::kListBox,
- PP_PRIVATECHOICEFIELD_LISTBOX);
-STATIC_ASSERT_ENUM(chrome_pdf::ChoiceFieldType::kComboBox,
- PP_PRIVATECHOICEFIELD_COMBOBOX);
-STATIC_ASSERT_ENUM(chrome_pdf::ChoiceFieldType::kMaxValue,
- PP_PRIVATECHOICEFIELD_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::ButtonType::kPushButton,
- PP_PRIVATEBUTTON_PUSHBUTTON);
-STATIC_ASSERT_ENUM(chrome_pdf::ButtonType::kPushButton, PP_PRIVATEBUTTON_FIRST);
-STATIC_ASSERT_ENUM(chrome_pdf::ButtonType::kCheckBox,
- PP_PRIVATEBUTTON_CHECKBOX);
-STATIC_ASSERT_ENUM(chrome_pdf::ButtonType::kRadioButton,
- PP_PRIVATEBUTTON_RADIOBUTTON);
-STATIC_ASSERT_ENUM(chrome_pdf::ButtonType::kMaxValue, PP_PRIVATEBUTTON_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kNone,
- PP_PRIVATEFOCUSOBJECT_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kDocument,
- PP_PRIVATEFOCUSOBJECT_DOCUMENT);
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kLink,
- PP_PRIVATEFOCUSOBJECT_LINK);
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kHighlight,
- PP_PRIVATEFOCUSOBJECT_HIGHLIGHT);
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kTextField,
- PP_PRIVATEFOCUSOBJECT_TEXT_FIELD);
-STATIC_ASSERT_ENUM(chrome_pdf::FocusObjectType::kMaxValue,
- PP_PRIVATEFOCUSOBJECT_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kNone, PP_PDF_ACTION_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kScrollToMakeVisible,
- PP_PDF_SCROLL_TO_MAKE_VISIBLE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kDoDefaultAction,
- PP_PDF_DO_DEFAULT_ACTION);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kScrollToGlobalPoint,
- PP_PDF_SCROLL_TO_GLOBAL_POINT);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kSetSelection,
- PP_PDF_SET_SELECTION);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAction::kMaxValue,
- PP_PDF_ACCESSIBILITYACTION_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kNone,
- PP_PDF_TYPE_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kLink, PP_PDF_LINK);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityAnnotationType::kMaxValue,
- PP_PDF_ACCESSIBILITY_ANNOTATIONTYPE_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kNone,
- PP_PDF_SCROLL_NONE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kCenter,
- PP_PDF_SCROLL_ALIGNMENT_CENTER);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kTop,
- PP_PDF_SCROLL_ALIGNMENT_TOP);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kBottom,
- PP_PDF_SCROLL_ALIGNMENT_BOTTOM);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kLeft,
- PP_PDF_SCROLL_ALIGNMENT_LEFT);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kRight,
- PP_PDF_SCROLL_ALIGNMENT_RIGHT);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kClosestToEdge,
- PP_PDF_SCROLL_ALIGNMENT_CLOSEST_EDGE);
-STATIC_ASSERT_ENUM(chrome_pdf::AccessibilityScrollAlignment::kMaxValue,
- PP_PDF_ACCESSIBILITYSCROLLALIGNMENT_LAST);
-
-STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionCopy,
- PP_CONTENT_RESTRICTION_COPY);
-STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionCut,
- PP_CONTENT_RESTRICTION_CUT);
-STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionPaste,
- PP_CONTENT_RESTRICTION_PASTE);
-STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionPrint,
- PP_CONTENT_RESTRICTION_PRINT);
-STATIC_ASSERT_ENUM(chrome_pdf::kContentRestrictionSave,
- PP_CONTENT_RESTRICTION_SAVE);
+} // namespace chrome_pdf
diff --git a/chromium/pdf/pdfium/pdfium_document.h b/chromium/pdf/pdfium/pdfium_document.h
index 0df76d8bdc1..5c7db4f0974 100644
--- a/chromium/pdf/pdfium/pdfium_document.h
+++ b/chromium/pdf/pdfium/pdfium_document.h
@@ -57,11 +57,11 @@ class PDFiumDocument {
ScopedFPDFAvail fpdf_availability_;
// The PDFium wrapper object for the document. Must come after
- // |fpdf_availability_| to prevent outliving it.
+ // `fpdf_availability_` to prevent outliving it.
ScopedFPDFDocument doc_handle_;
// The PDFium wrapper for form data. Used even if there are no form controls
- // on the page. Must come after |doc_handle_| to prevent outliving it.
+ // on the page. Must come after `doc_handle_` to prevent outliving it.
ScopedFPDFFormHandle form_handle_;
// Current form availability status.
diff --git a/chromium/pdf/pdfium/pdfium_engine.cc b/chromium/pdf/pdfium/pdfium_engine.cc
index 64b4133ff95..333ce72fbe3 100644
--- a/chromium/pdf/pdfium/pdfium_engine.cc
+++ b/chromium/pdf/pdfium/pdfium_engine.cc
@@ -18,6 +18,7 @@
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/check_op.h"
+#include "base/containers/contains.h"
#include "base/debug/alias.h"
#include "base/feature_list.h"
#include "base/location.h"
@@ -30,6 +31,7 @@
#include "base/time/time.h"
#include "build/build_config.h"
#include "gin/array_buffer.h"
+#include "gin/public/cppgc.h"
#include "gin/public/gin_embedders.h"
#include "gin/public/isolate_holder.h"
#include "gin/public/v8_platform.h"
@@ -48,12 +50,17 @@
#include "pdf/pdfium/pdfium_unsupported_features.h"
#include "pdf/ppapi_migration/bitmap.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
-#include "pdf/ppapi_migration/input_event_conversions.h"
#include "pdf/ppapi_migration/url_loader.h"
#include "pdf/url_loader_wrapper_impl.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/pdf.h"
#include "printing/units.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
+#include "third_party/blink/public/common/input/web_keyboard_event.h"
+#include "third_party/blink/public/common/input/web_mouse_event.h"
+#include "third_party/blink/public/common/input/web_pointer_properties.h"
+#include "third_party/blink/public/common/input/web_touch_event.h"
+#include "third_party/blink/public/common/input/web_touch_point.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_annot.h"
#include "third_party/pdfium/public/fpdf_attachment.h"
@@ -210,7 +217,7 @@ void FormatStringForOS(std::u16string* text) {
#endif
}
-// Returns true if |cur| is a character to break on.
+// Returns true if `cur` is a character to break on.
// For double clicks, look for work breaks.
// For triple clicks, look for line breaks.
// The actual algorithm used in Blink is much more complicated, so do a simple
@@ -251,7 +258,7 @@ void SetUpV8() {
gin::IsolateHolder::IsolateType::kUtility);
g_isolate_holder->isolate()->Enter();
#if defined(PDF_ENABLE_XFA)
- cppgc::InitializeProcess(gin::V8Platform::Get()->GetPageAllocator());
+ gin::InitializeCppgcFromV8Platform();
#endif
}
@@ -265,7 +272,7 @@ void TearDownV8() {
}
#endif // defined(PDF_ENABLE_V8)
-// Returns true if the given |area| and |form_type| combination from
+// Returns true if the given `area` and `form_type` combination from
// PDFiumEngine::GetCharIndex() indicates it is a form text area.
bool IsFormTextArea(PDFiumPage::Area area, int form_type) {
if (form_type == FPDF_FORMFIELD_UNKNOWN)
@@ -293,20 +300,16 @@ bool IsLinkArea(PDFiumPage::Area area) {
return area == PDFiumPage::WEBLINK_AREA || area == PDFiumPage::DOCLINK_AREA;
}
-// Normalize a MouseInputEvent. For Mac, this means transforming ctrl + left
-// button down events into a right button down events.
-MouseInputEvent NormalizeMouseEvent(const MouseInputEvent& event) {
- MouseInputEvent normalized_event = event;
+// Normalize a blink::WebMouseEvent. For macOS, normalization means transforming
+// the ctrl + left button down events into a right button down event.
+blink::WebMouseEvent NormalizeMouseEvent(const blink::WebMouseEvent& event) {
+ blink::WebMouseEvent normalized_event = event;
#if defined(OS_MAC)
- uint32_t modifiers = event.GetModifiers();
- if ((event.GetModifiers() & kInputEventModifierControlKey) &&
- event.GetButton() == InputEventMouseButtonType::kLeft &&
- event.GetEventType() == InputEventType::kMouseDown) {
- uint32_t new_modifiers = modifiers & ~kInputEventModifierControlKey;
- normalized_event =
- MouseInputEvent(InputEventType::kMouseDown, event.GetTimeStamp(),
- new_modifiers, InputEventMouseButtonType::kRight,
- event.GetPosition(), 1, event.GetMovement());
+ if ((event.GetModifiers() & blink::WebInputEvent::Modifiers::kControlKey) &&
+ event.button == blink::WebPointerProperties::Button::kLeft &&
+ event.GetType() == blink::WebInputEvent::Type::kMouseDown) {
+ normalized_event.SetModifiers(
+ event.GetModifiers() & ~blink::WebInputEvent::Modifiers::kControlKey);
}
#endif
return normalized_event;
@@ -582,6 +585,7 @@ void PDFiumEngine::PluginSizeUpdated(const gfx::Size& size) {
plugin_size_ = size;
CalculateVisiblePages();
+ OnSelectionPositionChanged();
}
void PDFiumEngine::ScrolledToXPosition(int position) {
@@ -630,10 +634,10 @@ void PDFiumEngine::Paint(const gfx::Rect& rect,
// Compute the leftover dirty region. The first page may have blank space
// above it, in which case we also need to subtract that space from the
// dirty region.
- // If two-up view is enabled, we don't need to recompute |leftover| since
- // subtracting |leftover| with a two-up view page won't result in a
+ // If two-up view is enabled, we don't need to recompute `leftover` since
+ // subtracting `leftover` with a two-up view page won't result in a
// rectangle.
- if (!layout_.options().two_up_view_enabled()) {
+ if (layout_.options().page_spread() == DocumentLayout::PageSpread::kOneUp) {
if (i == 0) {
gfx::Rect blank_space_in_screen = dirty_in_screen;
blank_space_in_screen.set_y(0);
@@ -779,7 +783,7 @@ void PDFiumEngine::OnPendingRequestComplete() {
return;
}
- // LoadDocument() will result in |pending_pages_| being reset so there's no
+ // LoadDocument() will result in `pending_pages_` being reset so there's no
// need to run the code below in that case.
bool update_pages = false;
std::vector<int> still_pending;
@@ -842,7 +846,7 @@ void PDFiumEngine::FinishLoadingDocument() {
client_->Invalidate(GetPageScreenRect(i));
}
- // Transition |document_loaded_| to true after finishing any calls to
+ // Transition `document_loaded_` to true after finishing any calls to
// FPDFAvail_IsPageAvail(), since we no longer need to defer calls to this
// function from LoadPageInfo(). Note that LoadBody() calls LoadPageInfo()
// indirectly, so we cannot make this transition earlier.
@@ -894,44 +898,44 @@ void PDFiumEngine::ContinueFind(int32_t result) {
StartFind(current_find_text_, result != 0);
}
-bool PDFiumEngine::HandleEvent(const InputEvent& event) {
+bool PDFiumEngine::HandleInputEvent(const blink::WebInputEvent& event) {
DCHECK(!defer_page_unload_);
defer_page_unload_ = true;
bool rv = false;
- switch (event.GetEventType()) {
- case InputEventType::kMouseDown:
- rv = OnMouseDown(static_cast<const MouseInputEvent&>(event));
+ switch (event.GetType()) {
+ case blink::WebInputEvent::Type::kMouseDown:
+ rv = OnMouseDown(static_cast<const blink::WebMouseEvent&>(event));
break;
- case InputEventType::kMouseUp:
- rv = OnMouseUp(static_cast<const MouseInputEvent&>(event));
+ case blink::WebInputEvent::Type::kMouseUp:
+ rv = OnMouseUp(static_cast<const blink::WebMouseEvent&>(event));
break;
- case InputEventType::kMouseMove:
- rv = OnMouseMove(static_cast<const MouseInputEvent&>(event));
+ case blink::WebInputEvent::Type::kMouseMove:
+ rv = OnMouseMove(static_cast<const blink::WebMouseEvent&>(event));
break;
- case InputEventType::kMouseEnter:
- OnMouseEnter(static_cast<const MouseInputEvent&>(event));
+ case blink::WebInputEvent::Type::kMouseEnter:
+ OnMouseEnter(static_cast<const blink::WebMouseEvent&>(event));
break;
- case InputEventType::kKeyDown:
- rv = OnKeyDown(static_cast<const KeyboardInputEvent&>(event));
+ case blink::WebInputEvent::Type::kRawKeyDown:
+ rv = OnKeyDown(static_cast<const blink::WebKeyboardEvent&>(event));
break;
- case InputEventType::kKeyUp:
- rv = OnKeyUp(static_cast<const KeyboardInputEvent&>(event));
+ case blink::WebInputEvent::Type::kKeyUp:
+ rv = OnKeyUp(static_cast<const blink::WebKeyboardEvent&>(event));
break;
- case InputEventType::kChar:
- rv = OnChar(static_cast<const KeyboardInputEvent&>(event));
+ case blink::WebInputEvent::Type::kChar:
+ rv = OnChar(static_cast<const blink::WebKeyboardEvent&>(event));
break;
- case InputEventType::kTouchStart: {
+ case blink::WebInputEvent::Type::kTouchStart: {
KillTouchTimer();
- const auto& touch_event = static_cast<const TouchInputEvent&>(event);
- if (touch_event.GetTouchCount() == 1)
+ const auto& touch_event = static_cast<const blink::WebTouchEvent&>(event);
+ if (touch_event.touches_length == 1)
ScheduleTouchTimer(touch_event);
break;
}
- case InputEventType::kTouchEnd:
+ case blink::WebInputEvent::Type::kTouchEnd:
KillTouchTimer();
break;
- case InputEventType::kTouchMove:
+ case blink::WebInputEvent::Type::kTouchMove:
// TODO(dsinclair): This should allow a little bit of movement (up to the
// touch radii) to account for finger jiggle.
KillTouchTimer();
@@ -1188,15 +1192,17 @@ PDFiumPage::Area PDFiumEngine::GetCharIndex(const gfx::Point& point,
: result;
}
-bool PDFiumEngine::OnMouseDown(const MouseInputEvent& event) {
- MouseInputEvent normalized_event = NormalizeMouseEvent(event);
- if (normalized_event.GetButton() == InputEventMouseButtonType::kLeft)
- return OnLeftMouseDown(normalized_event);
- if (normalized_event.GetButton() == InputEventMouseButtonType::kMiddle)
- return OnMiddleMouseDown(normalized_event);
- if (normalized_event.GetButton() == InputEventMouseButtonType::kRight)
- return OnRightMouseDown(normalized_event);
- return false;
+bool PDFiumEngine::OnMouseDown(const blink::WebMouseEvent& event) {
+ switch (event.button) {
+ case blink::WebPointerProperties::Button::kLeft:
+ return OnLeftMouseDown(NormalizeMouseEvent(event));
+ case blink::WebPointerProperties::Button::kMiddle:
+ return OnMiddleMouseDown(NormalizeMouseEvent(event));
+ case blink::WebPointerProperties::Button::kRight:
+ return OnRightMouseDown(NormalizeMouseEvent(event));
+ default:
+ return false;
+ }
}
void PDFiumEngine::OnSingleClick(int page_index, int char_index) {
@@ -1236,7 +1242,9 @@ void PDFiumEngine::OnMultipleClick(int click_count,
client_->NotifyTouchSelectionOccurred();
}
-bool PDFiumEngine::OnLeftMouseDown(const MouseInputEvent& event) {
+bool PDFiumEngine::OnLeftMouseDown(const blink::WebMouseEvent& event) {
+ DCHECK_EQ(blink::WebPointerProperties::Button::kLeft, event.button);
+
SetMouseLeftButtonDown(true);
auto selection_invalidator =
@@ -1247,7 +1255,7 @@ bool PDFiumEngine::OnLeftMouseDown(const MouseInputEvent& event) {
int char_index = -1;
int form_type = FPDF_FORMFIELD_UNKNOWN;
PDFiumPage::LinkTarget target;
- gfx::Point point = event.GetPosition();
+ const gfx::Point point = gfx::ToRoundedPoint(event.PositionInWidget());
PDFiumPage::Area area =
GetCharIndex(point, &page_index, &char_index, &form_type, &target);
DCHECK_GE(form_type, FPDF_FORMFIELD_UNKNOWN);
@@ -1279,9 +1287,9 @@ bool PDFiumEngine::OnLeftMouseDown(const MouseInputEvent& event) {
FPDF_PAGE page = pages_[page_index]->GetPage();
- if (event.GetClickCount() == 1) {
+ if (event.ClickCount() == 1) {
FORM_OnLButtonDown(form(), page, event.GetModifiers(), page_x, page_y);
- } else if (event.GetClickCount() == 2) {
+ } else if (event.ClickCount() == 2) {
FORM_OnLButtonDoubleClick(form(), page, event.GetModifiers(), page_x,
page_y);
}
@@ -1293,18 +1301,21 @@ bool PDFiumEngine::OnLeftMouseDown(const MouseInputEvent& event) {
if (area != PDFiumPage::TEXT_AREA)
return true; // Return true so WebKit doesn't do its own highlighting.
- if (event.GetClickCount() == 1)
+ if (event.ClickCount() == 1)
OnSingleClick(page_index, char_index);
- else if (event.GetClickCount() == 2 || event.GetClickCount() == 3)
- OnMultipleClick(event.GetClickCount(), page_index, char_index);
+ else if (event.ClickCount() == 2 || event.ClickCount() == 3)
+ OnMultipleClick(event.ClickCount(), page_index, char_index);
return true;
}
-bool PDFiumEngine::OnMiddleMouseDown(const MouseInputEvent& event) {
+bool PDFiumEngine::OnMiddleMouseDown(const blink::WebMouseEvent& event) {
+ DCHECK_EQ(blink::WebPointerProperties::Button::kMiddle, event.button);
+
SetMouseLeftButtonDown(false);
mouse_middle_button_down_ = true;
- mouse_middle_button_last_position_ = event.GetPosition();
+ mouse_middle_button_last_position_ =
+ gfx::ToRoundedPoint(event.PositionInWidget());
SelectionChangeInvalidator selection_invalidator(this);
selection_.clear();
@@ -1314,8 +1325,8 @@ bool PDFiumEngine::OnMiddleMouseDown(const MouseInputEvent& event) {
int unused_form_type = FPDF_FORMFIELD_UNKNOWN;
PDFiumPage::LinkTarget target;
PDFiumPage::Area area =
- GetCharIndex(event.GetPosition(), &unused_page_index, &unused_char_index,
- &unused_form_type, &target);
+ GetCharIndex(mouse_middle_button_last_position_, &unused_page_index,
+ &unused_char_index, &unused_form_type, &target);
mouse_down_state_.Set(area, target);
// Decide whether to open link or not based on user action in mouse up and
@@ -1332,10 +1343,10 @@ bool PDFiumEngine::OnMiddleMouseDown(const MouseInputEvent& event) {
return false;
}
-bool PDFiumEngine::OnRightMouseDown(const MouseInputEvent& event) {
- DCHECK_EQ(InputEventMouseButtonType::kRight, event.GetButton());
+bool PDFiumEngine::OnRightMouseDown(const blink::WebMouseEvent& event) {
+ DCHECK_EQ(blink::WebPointerProperties::Button::kRight, event.button);
- gfx::Point point = event.GetPosition();
+ const gfx::Point point = gfx::ToRoundedPoint(event.PositionInWidget());
int page_index = -1;
int char_index = -1;
int form_type = FPDF_FORMFIELD_UNKNOWN;
@@ -1424,33 +1435,35 @@ bool PDFiumEngine::NavigateToLinkDestination(
return false;
}
-bool PDFiumEngine::OnMouseUp(const MouseInputEvent& event) {
- if (event.GetButton() != InputEventMouseButtonType::kLeft &&
- event.GetButton() != InputEventMouseButtonType::kMiddle) {
+bool PDFiumEngine::OnMouseUp(const blink::WebMouseEvent& event) {
+ if (event.button != blink::WebPointerProperties::Button::kLeft &&
+ event.button != blink::WebPointerProperties::Button::kMiddle) {
return false;
}
- if (event.GetButton() == InputEventMouseButtonType::kLeft)
+ if (event.button == blink::WebPointerProperties::Button::kLeft)
SetMouseLeftButtonDown(false);
- else if (event.GetButton() == InputEventMouseButtonType::kMiddle)
+ else if (event.button == blink::WebPointerProperties::Button::kMiddle)
mouse_middle_button_down_ = false;
int page_index = -1;
int char_index = -1;
int form_type = FPDF_FORMFIELD_UNKNOWN;
PDFiumPage::LinkTarget target;
- gfx::Point point = event.GetPosition();
+ gfx::Point point = gfx::ToRoundedPoint(event.PositionInWidget());
PDFiumPage::Area area =
GetCharIndex(point, &page_index, &char_index, &form_type, &target);
// Open link on mouse up for same link for which mouse down happened earlier.
if (mouse_down_state_.Matches(area, target)) {
- uint32_t modifiers = event.GetModifiers();
- bool middle_button = !!(modifiers & kInputEventModifierMiddleButtonDown);
- bool alt_key = !!(modifiers & kInputEventModifierAltKey);
- bool ctrl_key = !!(modifiers & kInputEventModifierControlKey);
- bool meta_key = !!(modifiers & kInputEventModifierMetaKey);
- bool shift_key = !!(modifiers & kInputEventModifierShiftKey);
+ int modifiers = event.GetModifiers();
+ bool middle_button =
+ !!(modifiers & blink::WebInputEvent::Modifiers::kMiddleButtonDown);
+ bool alt_key = !!(modifiers & blink::WebInputEvent::Modifiers::kAltKey);
+ bool ctrl_key =
+ !!(modifiers & blink::WebInputEvent::Modifiers::kControlKey);
+ bool meta_key = !!(modifiers & blink::WebInputEvent::Modifiers::kMetaKey);
+ bool shift_key = !!(modifiers & blink::WebInputEvent::Modifiers::kShiftKey);
WindowOpenDisposition disposition = ui::DispositionFromClick(
middle_button, alt_key, ctrl_key, meta_key, shift_key);
@@ -1459,7 +1472,7 @@ bool PDFiumEngine::OnMouseUp(const MouseInputEvent& event) {
return true;
}
- if (event.GetButton() == InputEventMouseButtonType::kMiddle) {
+ if (event.button == blink::WebPointerProperties::Button::kMiddle) {
if (kViewerImplementedPanning) {
// Update the cursor when panning stops.
client_->UpdateCursor(DetermineCursorType(area, form_type));
@@ -1484,16 +1497,16 @@ bool PDFiumEngine::OnMouseUp(const MouseInputEvent& event) {
return true;
}
-bool PDFiumEngine::OnMouseMove(const MouseInputEvent& event) {
+bool PDFiumEngine::OnMouseMove(const blink::WebMouseEvent& event) {
int page_index = -1;
int char_index = -1;
int form_type = FPDF_FORMFIELD_UNKNOWN;
PDFiumPage::LinkTarget target;
- gfx::Point point = event.GetPosition();
+ const gfx::Point point = gfx::ToRoundedPoint(event.PositionInWidget());
PDFiumPage::Area area =
GetCharIndex(point, &page_index, &char_index, &form_type, &target);
- // Clear |mouse_down_state_| if mouse moves away from where the mouse down
+ // Clear `mouse_down_state_` if mouse moves away from where the mouse down
// happened.
if (!mouse_down_state_.Matches(area, target))
mouse_down_state_.Reset();
@@ -1514,20 +1527,20 @@ bool PDFiumEngine::OnMouseMove(const MouseInputEvent& event) {
// If in form text area while left mouse button is held down, check if form
// text selection needs to be updated.
if (mouse_left_button_down_ && area == PDFiumPage::FORM_TEXT_AREA &&
- last_focused_page_ != -1) {
+ PageIndexInBounds(last_focused_page_)) {
SetFormSelectedText(form(), pages_[last_focused_page_]->GetPage());
}
if (kViewerImplementedPanning && mouse_middle_button_down_) {
// Subtract (origin - destination) so delta is already the delta for
// moving the page, rather than the delta the mouse moved.
- // GetMovement() does not work here, as small mouse movements are
- // considered zero.
+ // `event.movement_x` and `event.movement_y` do not work here, as small
+ // mouse movements are considered zero.
gfx::Vector2d page_position_delta =
- mouse_middle_button_last_position_ - event.GetPosition();
+ mouse_middle_button_last_position_ - point;
if (page_position_delta.x() != 0 || page_position_delta.y() != 0) {
client_->ScrollBy(page_position_delta);
- mouse_middle_button_last_position_ = event.GetPosition();
+ mouse_middle_button_last_position_ = point;
}
}
@@ -1585,11 +1598,13 @@ ui::mojom::CursorType PDFiumEngine::DetermineCursorType(PDFiumPage::Area area,
}
}
-void PDFiumEngine::OnMouseEnter(const MouseInputEvent& event) {
- if (event.GetModifiers() & kInputEventModifierMiddleButtonDown) {
+void PDFiumEngine::OnMouseEnter(const blink::WebMouseEvent& event) {
+ if (event.GetModifiers() &
+ blink::WebInputEvent::Modifiers::kMiddleButtonDown) {
if (!mouse_middle_button_down_) {
mouse_middle_button_down_ = true;
- mouse_middle_button_last_position_ = event.GetPosition();
+ mouse_middle_button_last_position_ =
+ gfx::ToRoundedPoint(event.PositionInWidget());
}
} else {
if (mouse_middle_button_down_) {
@@ -1600,7 +1615,7 @@ void PDFiumEngine::OnMouseEnter(const MouseInputEvent& event) {
bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
// Check if the user has decreased their selection area and we need to remove
- // pages from |selection_|.
+ // pages from `selection_`.
for (size_t i = 0; i < selection_.size(); ++i) {
if (selection_[i].page_index() == page_index) {
// There should be no other pages after this.
@@ -1627,8 +1642,8 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
// Selecting into the next page.
// Save the current last selection for use below.
- // Warning: Do not use references / pointers into |selection_|, as the code
- // below can modify |selection_| and invalidate those references / pointers.
+ // Warning: Do not use references / pointers into `selection_`, as the code
+ // below can modify `selection_` and invalidate those references / pointers.
const size_t last_selection_index = selection_.size() - 1;
// First make sure that there are no gaps in selection, i.e. if mousedown on
@@ -1663,28 +1678,28 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
return true;
}
-bool PDFiumEngine::OnKeyDown(const KeyboardInputEvent& event) {
+bool PDFiumEngine::OnKeyDown(const blink::WebKeyboardEvent& event) {
// Handle tab events first as we might need to transition focus to an
// annotation in PDF.
- if (event.GetKeyCode() == FWL_VKEY_Tab)
+ if (event.windows_key_code == FWL_VKEY_Tab)
return HandleTabEvent(event.GetModifiers());
- if (last_focused_page_ == -1)
+ if (!PageIndexInBounds(last_focused_page_))
return false;
bool rv = !!FORM_OnKeyDown(form(), pages_[last_focused_page_]->GetPage(),
- event.GetKeyCode(), event.GetModifiers());
+ event.windows_key_code, event.GetModifiers());
- if (event.GetKeyCode() == ui::VKEY_BACK ||
- event.GetKeyCode() == ui::VKEY_ESCAPE) {
+ if (!event.IsCharacterKey()) {
// Blink does not send char events for backspace or escape keys, see
- // WebKeyboardEvent::IsCharacterKey() and b/961192 for more information.
- // So just fake one since PDFium uses it.
- std::string str;
- str.push_back(event.GetKeyCode());
- KeyboardInputEvent synthesized(InputEventType::kChar, event.GetTimeStamp(),
- event.GetModifiers(), event.GetKeyCode(),
- str);
+ // `blink::WebKeyboardEvent::IsCharacterKey()` and b/961192 for more
+ // information. So just fake one since PDFium uses it.
+ blink::WebKeyboardEvent synthesized(blink::WebInputEvent::Type::kChar,
+ event.GetModifiers(),
+ event.TimeStamp());
+ synthesized.windows_key_code = event.windows_key_code;
+ synthesized.text[0] = synthesized.windows_key_code;
+ synthesized.text[1] = L'\0';
OnChar(synthesized);
}
@@ -1692,8 +1707,8 @@ bool PDFiumEngine::OnKeyDown(const KeyboardInputEvent& event) {
// macOS doesn't have keyboard-triggered context menus.
// Scroll focused annotation into view when context menu is invoked through
// keyboard <Shift-F10>.
- if (event.GetKeyCode() == FWL_VKEY_F10 &&
- (event.GetModifiers() & kInputEventModifierShiftKey)) {
+ if (event.windows_key_code == FWL_VKEY_F10 &&
+ (event.GetModifiers() & blink::WebInputEvent::Modifiers::kShiftKey)) {
DCHECK(!rv);
ScrollFocusedAnnotationIntoView();
}
@@ -1702,8 +1717,8 @@ bool PDFiumEngine::OnKeyDown(const KeyboardInputEvent& event) {
return rv;
}
-bool PDFiumEngine::OnKeyUp(const KeyboardInputEvent& event) {
- if (last_focused_page_ == -1)
+bool PDFiumEngine::OnKeyUp(const blink::WebKeyboardEvent& event) {
+ if (!PageIndexInBounds(last_focused_page_))
return false;
// Check if form text selection needs to be updated.
@@ -1711,21 +1726,22 @@ bool PDFiumEngine::OnKeyUp(const KeyboardInputEvent& event) {
if (in_form_text_area_)
SetFormSelectedText(form(), page);
- return !!FORM_OnKeyUp(form(), page, event.GetKeyCode(), event.GetModifiers());
+ return !!FORM_OnKeyUp(form(), page, event.windows_key_code,
+ event.GetModifiers());
}
-bool PDFiumEngine::OnChar(const KeyboardInputEvent& event) {
- if (last_focused_page_ == -1)
+bool PDFiumEngine::OnChar(const blink::WebKeyboardEvent& event) {
+ if (!PageIndexInBounds(last_focused_page_))
return false;
- std::u16string str = base::UTF8ToUTF16(event.GetKeyChar());
- bool rv = !!FORM_OnChar(form(), pages_[last_focused_page_]->GetPage(), str[0],
- event.GetModifiers());
+ bool rv = !!FORM_OnChar(form(), pages_[last_focused_page_]->GetPage(),
+ event.text[0], event.GetModifiers());
// Scroll editable form text into view on char events. We should not scroll
// focused annotation on escape char event since escape char is used to
// dismiss focus from form controls.
- if (rv && editable_form_text_area_ && event.GetKeyCode() != ui::VKEY_ESCAPE) {
+ if (rv && editable_form_text_area_ &&
+ event.windows_key_code != ui::VKEY_ESCAPE) {
ScrollFocusedAnnotationIntoView();
}
@@ -1893,7 +1909,7 @@ void PDFiumEngine::SearchUsingICU(const std::u16string& term,
std::u16string adjusted_page_text;
adjusted_page_text.reserve(page_text.size());
- // Values in |removed_indices| are in the adjusted text index space and
+ // Values in `removed_indices` are in the adjusted text index space and
// indicate a character was removed from the page text before the given
// index. If multiple characters are removed in a row then there will be
// multiple entries with the same value.
@@ -1963,7 +1979,7 @@ void PDFiumEngine::SearchUsingICU(const std::u16string& term,
pages_[current_page]->GetTextPage(),
temp_start + page_text_result_length);
- // If |term| occurs at the end of a page, then |end| will be -1 due to the
+ // If `term` occurs at the end of a page, then `end` will be -1 due to the
// index being out of bounds. Compensate for this case so the range
// character count calculation below works out.
if (temp_start + page_text_result_length == original_text_length) {
@@ -2045,7 +2061,7 @@ bool PDFiumEngine::SelectFindResult(bool forward) {
size_t current_find_index_value = current_find_index_.value();
base::debug::Alias(&current_find_index_value);
- // Use zoom of 1.0 since |visible_rect| is without zoom.
+ // Use zoom of 1.0 since `visible_rect` is without zoom.
const std::vector<gfx::Rect>& rects =
find_results_[current_find_index_.value()].GetScreenRects(
gfx::Point(), 1.0, layout_.options().default_page_orientation());
@@ -2153,7 +2169,9 @@ void PDFiumEngine::SetReadOnly(bool enable) {
}
void PDFiumEngine::SetTwoUpView(bool enable) {
- desired_layout_options_.set_two_up_view_enabled(enable);
+ desired_layout_options_.set_page_spread(
+ enable ? DocumentLayout::PageSpread::kTwoUpOdd
+ : DocumentLayout::PageSpread::kOneUp);
ProposeNextDocumentLayout();
}
@@ -2194,14 +2212,15 @@ std::string PDFiumEngine::GetSelectedText() {
return base::UTF16ToUTF8(result);
}
-bool PDFiumEngine::CanEditText() {
+bool PDFiumEngine::CanEditText() const {
return editable_form_text_area_;
}
-bool PDFiumEngine::HasEditableText() {
+bool PDFiumEngine::HasEditableText() const {
DCHECK(CanEditText());
- if (last_focused_page_ == -1)
+ if (!PageIndexInBounds(last_focused_page_))
return false;
+
FPDF_PAGE page = pages_[last_focused_page_]->GetPage();
// If the return value is 2, that corresponds to "\0\0".
return FORM_GetFocusedText(form(), page, nullptr, 0) > 2;
@@ -2209,36 +2228,36 @@ bool PDFiumEngine::HasEditableText() {
void PDFiumEngine::ReplaceSelection(const std::string& text) {
DCHECK(CanEditText());
- if (last_focused_page_ != -1) {
- std::u16string text_wide = base::UTF8ToUTF16(text);
- FPDF_WIDESTRING text_pdf_wide =
- reinterpret_cast<FPDF_WIDESTRING>(text_wide.c_str());
+ if (!PageIndexInBounds(last_focused_page_))
+ return;
- FORM_ReplaceSelection(form(), pages_[last_focused_page_]->GetPage(),
- text_pdf_wide);
- }
+ std::u16string text_wide = base::UTF8ToUTF16(text);
+ FORM_ReplaceSelection(form(), pages_[last_focused_page_]->GetPage(),
+ reinterpret_cast<FPDF_WIDESTRING>(text_wide.c_str()));
}
-bool PDFiumEngine::CanUndo() {
- if (last_focused_page_ == -1)
- return false;
- return !!FORM_CanUndo(form(), pages_[last_focused_page_]->GetPage());
+bool PDFiumEngine::CanUndo() const {
+ return PageIndexInBounds(last_focused_page_) &&
+ FORM_CanUndo(form(), pages_[last_focused_page_]->GetPage());
}
-bool PDFiumEngine::CanRedo() {
- if (last_focused_page_ == -1)
- return false;
- return !!FORM_CanRedo(form(), pages_[last_focused_page_]->GetPage());
+bool PDFiumEngine::CanRedo() const {
+ return PageIndexInBounds(last_focused_page_) &&
+ FORM_CanRedo(form(), pages_[last_focused_page_]->GetPage());
}
void PDFiumEngine::Undo() {
- if (last_focused_page_ != -1)
- FORM_Undo(form(), pages_[last_focused_page_]->GetPage());
+ if (!PageIndexInBounds(last_focused_page_))
+ return;
+
+ FORM_Undo(form(), pages_[last_focused_page_]->GetPage());
}
void PDFiumEngine::Redo() {
- if (last_focused_page_ != -1)
- FORM_Redo(form(), pages_[last_focused_page_]->GetPage());
+ if (!PageIndexInBounds(last_focused_page_))
+ return;
+
+ FORM_Redo(form(), pages_[last_focused_page_]->GetPage());
}
void PDFiumEngine::HandleAccessibilityAction(
@@ -2299,16 +2318,22 @@ std::string PDFiumEngine::GetLinkAtPosition(const gfx::Point& point) {
}
bool PDFiumEngine::HasPermission(DocumentPermission permission) const {
- // No |permissions_| means no restrictions.
+ // No `permissions_` means no restrictions.
if (!permissions_)
return true;
return permissions_->HasPermission(permission);
}
void PDFiumEngine::SelectAll() {
- if (in_form_text_area_ || IsReadOnly())
+ if (IsReadOnly())
return;
+ if (in_form_text_area_) {
+ if (PageIndexInBounds(last_focused_page_))
+ FORM_SelectAllText(form(), pages_[last_focused_page_]->GetPage());
+ return;
+ }
+
SelectionChangeInvalidator selection_invalidator(this);
selection_.clear();
@@ -2376,9 +2401,9 @@ base::Value PDFiumEngine::TraverseBookmarks(FPDF_BOOKMARK bookmark,
if (PageIndexInBounds(page_index)) {
dict.SetIntKey("page", page_index);
- base::Optional<float> x;
- base::Optional<float> y;
- base::Optional<float> zoom;
+ absl::optional<float> x;
+ absl::optional<float> y;
+ absl::optional<float> zoom;
pages_[page_index]->GetPageDestinationTarget(dest, &x, &y, &zoom);
if (x)
@@ -2481,7 +2506,7 @@ void PDFiumEngine::ScrollToGlobalPoint(const gfx::Rect& target_rect,
client_->ScrollBy(scroll_offset - global_point);
}
-base::Optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
+absl::optional<PDFEngine::NamedDestination> PDFiumEngine::GetNamedDestination(
const std::string& destination) {
// Look for the destination.
FPDF_DEST dest = FPDF_GetNamedDestByName(doc(), destination.c_str());
@@ -2541,22 +2566,22 @@ gfx::Rect PDFiumEngine::GetPageContentsRect(int index) {
return GetScreenRect(pages_[index]->rect());
}
-int PDFiumEngine::GetVerticalScrollbarYPosition() {
- return position_.y();
-}
-
void PDFiumEngine::SetGrayscale(bool grayscale) {
render_grayscale_ = grayscale;
}
-void PDFiumEngine::HandleLongPress(const TouchInputEvent& event) {
+void PDFiumEngine::HandleLongPress(const blink::WebTouchEvent& event) {
base::AutoReset<bool> handling_long_press_guard(&handling_long_press_, true);
- gfx::Point point = gfx::ToRoundedPoint(event.GetTargetTouchPoint());
+
+ // Only consider the first touch point.
+ DCHECK_GT(event.touches_length, 0u);
// Send a fake mouse down to trigger the multi-click selection code.
- MouseInputEvent mouse_event(
- InputEventType::kMouseDown, event.GetTimeStamp(), event.GetModifiers(),
- InputEventMouseButtonType::kLeft, point, 2, point);
+ blink::WebMouseEvent mouse_event(blink::WebInputEvent::Type::kMouseDown,
+ event.GetModifiers(), event.TimeStamp());
+ mouse_event.button = blink::WebPointerProperties::Button::kLeft;
+ mouse_event.click_count = 2;
+ mouse_event.SetPositionInWidget(event.touches[0].PositionInWidget());
OnMouseDown(mouse_event);
}
@@ -2576,7 +2601,7 @@ uint32_t PDFiumEngine::GetCharUnicode(int page_index, int char_index) {
return pages_[page_index]->GetCharUnicode(char_index);
}
-base::Optional<AccessibilityTextRunInfo> PDFiumEngine::GetTextRunInfo(
+absl::optional<AccessibilityTextRunInfo> PDFiumEngine::GetTextRunInfo(
int page_index,
int start_char_index) {
DCHECK(PageIndexInBounds(page_index));
@@ -2626,17 +2651,17 @@ int PDFiumEngine::GetDuplexType() {
return static_cast<int>(FPDF_VIEWERREF_GetDuplex(doc()));
}
-base::Optional<gfx::Size> PDFiumEngine::GetUniformPageSizePoints() {
+absl::optional<gfx::Size> PDFiumEngine::GetUniformPageSizePoints() {
if (pages_.empty())
- return base::nullopt;
+ return absl::nullopt;
gfx::Size page_size = GetPageSize(0);
for (size_t i = 1; i < pages_.size(); ++i) {
if (page_size != GetPageSize(i))
- return base::nullopt;
+ return absl::nullopt;
}
- // Convert |page_size| back to points.
+ // Convert `page_size` back to points.
return gfx::Size(
ConvertUnit(page_size.width(), kPixelsPerInch, kPointsPerInch),
ConvertUnit(page_size.height(), kPixelsPerInch, kPointsPerInch));
@@ -2710,7 +2735,7 @@ bool PDFiumEngine::TryLoadingDoc(const std::string& password,
*needs_password = false;
if (doc()) {
// This is probably not necessary, because it should have already been
- // called below in the |doc_| initialization path. However, the previous
+ // called below in the `doc_` initialization path. However, the previous
// call may have failed, so call it again for good measure.
FX_DOWNLOADHINTS& download_hints = document_->download_hints();
FPDFAvail_IsDocAvail(fpdf_availability(), &download_hints);
@@ -2792,7 +2817,7 @@ void PDFiumEngine::RefreshCurrentDocumentLayout() {
DCHECK_EQ(pages_.size(), layout_.page_count());
for (size_t i = 0; i < layout_.page_count(); ++i) {
- // TODO(kmoon): This should be the only place that sets |PDFiumPage::rect_|.
+ // TODO(kmoon): This should be the only place that sets `PDFiumPage::rect_`.
pages_[i]->set_rect(layout_.page_bounds_rect(i));
}
@@ -2816,11 +2841,7 @@ void PDFiumEngine::UpdateDocumentLayout(DocumentLayout* layout) {
if (page_sizes.empty())
return;
- if (layout->options().two_up_view_enabled()) {
- layout->ComputeTwoUpViewLayout(page_sizes);
- } else {
- layout->ComputeSingleViewLayout(page_sizes);
- }
+ layout->ComputeLayout(page_sizes);
}
std::vector<gfx::Size> PDFiumEngine::LoadPageSizes(
@@ -2837,9 +2858,9 @@ std::vector<gfx::Size> PDFiumEngine::LoadPageSizes(
const bool doc_complete = doc_loader_->IsDocumentComplete();
const bool is_linear = IsLinearized();
for (size_t i = 0; i < new_page_count; ++i) {
- // Get page availability. If |document_loaded_| == true and the page is not
+ // Get page availability. If `document_loaded_` == true and the page is not
// new, then the page has been constructed already. Get page availability
- // flag from already existing PDFiumPage object. If |document_loaded_| ==
+ // flag from already existing PDFiumPage object. If `document_loaded_` ==
// false or the page is new, then the page may not be fully loaded yet.
bool page_available;
if (document_loaded_ && i < pages_.size()) {
@@ -2861,8 +2882,8 @@ std::vector<gfx::Size> PDFiumEngine::LoadPageSizes(
page_sizes.push_back(size);
}
- // Add new pages. If |document_loaded_| == false, do not mark page as
- // available even if |doc_complete| is true because FPDFAvail_IsPageAvail()
+ // Add new pages. If `document_loaded_` == false, do not mark page as
+ // available even if `doc_complete` is true because FPDFAvail_IsPageAvail()
// still has to be called for this page, which will be done in
// FinishLoadingDocument().
for (size_t i = pages_.size(); i < new_page_count; ++i) {
@@ -3071,7 +3092,7 @@ draw_utils::PageInsetSizes PDFiumEngine::GetInsetSizes(
size_t num_of_pages) const {
DCHECK_LT(page_index, num_of_pages);
- if (layout_options.two_up_view_enabled()) {
+ if (layout_options.page_spread() == DocumentLayout::PageSpread::kTwoUpOdd) {
return draw_utils::GetPageInsetsForTwoUpView(
page_index, num_of_pages, DocumentLayout::kSingleViewInsets,
DocumentLayout::kHorizontalSeparator);
@@ -3103,18 +3124,19 @@ void PDFiumEngine::InsetPage(const DocumentLayout::Options& layout_options,
static_cast<int>(ceil(inset_sizes.bottom * multiplier)));
}
-base::Optional<size_t> PDFiumEngine::GetAdjacentPageIndexForTwoUpView(
+absl::optional<size_t> PDFiumEngine::GetAdjacentPageIndexForTwoUpView(
size_t page_index,
size_t num_of_pages) const {
DCHECK_LT(page_index, num_of_pages);
- if (!layout_.options().two_up_view_enabled())
- return base::nullopt;
+ if (layout_.options().page_spread() == DocumentLayout::PageSpread::kOneUp) {
+ return absl::nullopt;
+ }
int adjacent_page_offset = page_index % 2 ? -1 : 1;
size_t adjacent_page_index = page_index + adjacent_page_offset;
if (adjacent_page_index >= num_of_pages)
- return base::nullopt;
+ return absl::nullopt;
return adjacent_page_index;
}
@@ -3215,7 +3237,8 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
GetInsetSizes(layout_.options(), page_index, pages_.size());
gfx::Rect page_rect = pages_[page_index]->rect();
- const bool is_two_up_view = layout_.options().two_up_view_enabled();
+ const bool is_two_up_view =
+ layout_.options().page_spread() == DocumentLayout::PageSpread::kTwoUpOdd;
if (page_rect.x() > 0 && (!is_two_up_view || page_index % 2 == 0)) {
// If in two-up view, only need to draw the left empty space for left pages
// since the gap between the left and right page will be drawn by the left
@@ -3412,7 +3435,7 @@ gfx::Rect PDFiumEngine::GetPageScreenRect(int page_index) const {
GetInsetSizes(layout_.options(), page_index, pages_.size());
int max_page_height = page_rect.height();
- base::Optional<size_t> adjacent_page_index =
+ absl::optional<size_t> adjacent_page_index =
GetAdjacentPageIndexForTwoUpView(page_index, pages_.size());
if (adjacent_page_index.has_value()) {
max_page_height = std::max(
@@ -3599,7 +3622,7 @@ void PDFiumEngine::DeviceToPage(int page_index,
}
int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
- // Copy |visible_pages_| since it can change as a result of loading the page
+ // Copy `visible_pages_` since it can change as a result of loading the page
// in GetPage(). See https://crbug.com/822091.
std::vector<int> visible_pages_copy(visible_pages_);
for (int page_index : visible_pages_copy) {
@@ -3775,7 +3798,7 @@ void PDFiumEngine::EnteredEditMode() {
void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
// If focus was previously in form text area, clear form text selection.
// Clearing needs to be done before changing focus to ensure the correct
- // observer is notified of the change in selection. When |in_form_text_area_|
+ // observer is notified of the change in selection. When `in_form_text_area_`
// is true, this is the Renderer. After it flips, the MimeHandler is notified.
if (in_form_text_area_) {
client_->SetSelectedText("");
@@ -3784,7 +3807,7 @@ void PDFiumEngine::SetInFormTextArea(bool in_form_text_area) {
client_->FormTextFieldFocusChange(in_form_text_area);
in_form_text_area_ = in_form_text_area;
- // Clear |editable_form_text_area_| when focus no longer in form text area.
+ // Clear `editable_form_text_area_` when focus no longer in form text area.
if (!in_form_text_area_)
editable_form_text_area_ = false;
}
@@ -3809,10 +3832,10 @@ bool PDFiumEngine::IsAnnotationAnEditableFormTextArea(FPDF_ANNOTATION annot,
return CheckIfEditableFormTextArea(flags, form_type);
}
-void PDFiumEngine::ScheduleTouchTimer(const TouchInputEvent& evt) {
+void PDFiumEngine::ScheduleTouchTimer(const blink::WebTouchEvent& event) {
touch_timer_.Start(FROM_HERE, kTouchLongPressTimeout,
base::BindOnce(&PDFiumEngine::HandleLongPress,
- base::Unretained(this), evt));
+ base::Unretained(this), event));
}
void PDFiumEngine::KillTouchTimer() {
@@ -3988,7 +4011,7 @@ void PDFiumEngine::GetSelection(uint32_t* selection_start_page_index,
// If the selection is all within one page, the end index is the
// start index plus the char count. But if the selection spans
// multiple pages, the selection starts at the beginning of the
- // last page in |selection_| and goes to the char count.
+ // last page in `selection_` and goes to the char count.
if (len == 1) {
*selection_end_char_index =
selection_[0].char_index() + selection_[0].char_count();
@@ -4095,24 +4118,24 @@ PdfVersion PDFiumEngine::GetDocumentVersion() const {
}
}
-bool PDFiumEngine::HandleTabEvent(uint32_t modifiers) {
- bool alt_key = !!(modifiers & kInputEventModifierAltKey);
- bool ctrl_key = !!(modifiers & kInputEventModifierControlKey);
+bool PDFiumEngine::HandleTabEvent(int modifiers) {
+ bool alt_key = !!(modifiers & blink::WebInputEvent::Modifiers::kAltKey);
+ bool ctrl_key = !!(modifiers & blink::WebInputEvent::Modifiers::kControlKey);
if (alt_key || ctrl_key)
return HandleTabEventWithModifiers(modifiers);
- return modifiers & kInputEventModifierShiftKey ? HandleTabBackward(modifiers)
- : HandleTabForward(modifiers);
+ bool shift_key = !!(modifiers & blink::WebInputEvent::Modifiers::kShiftKey);
+ return shift_key ? HandleTabBackward(modifiers) : HandleTabForward(modifiers);
}
-bool PDFiumEngine::HandleTabEventWithModifiers(uint32_t modifiers) {
+bool PDFiumEngine::HandleTabEventWithModifiers(int modifiers) {
// Only handle cases when a page is focused, else return false.
switch (focus_item_type_) {
case FocusElementType::kNone:
case FocusElementType::kDocument:
return false;
case FocusElementType::kPage:
- if (last_focused_page_ == -1)
+ if (!PageIndexInBounds(last_focused_page_))
return false;
return !!FORM_OnKeyDown(form(), pages_[last_focused_page_]->GetPage(),
FWL_VKEY_Tab, modifiers);
@@ -4122,7 +4145,7 @@ bool PDFiumEngine::HandleTabEventWithModifiers(uint32_t modifiers) {
}
}
-bool PDFiumEngine::HandleTabForward(uint32_t modifiers) {
+bool PDFiumEngine::HandleTabForward(int modifiers) {
if (focus_item_type_ == FocusElementType::kNone) {
UpdateFocusItemType(FocusElementType::kDocument);
return true;
@@ -4150,7 +4173,7 @@ bool PDFiumEngine::HandleTabForward(uint32_t modifiers) {
return did_tab_forward;
}
-bool PDFiumEngine::HandleTabBackward(uint32_t modifiers) {
+bool PDFiumEngine::HandleTabBackward(int modifiers) {
if (focus_item_type_ == FocusElementType::kDocument) {
UpdateFocusItemType(FocusElementType::kNone);
return false;
@@ -4173,11 +4196,11 @@ bool PDFiumEngine::HandleTabBackward(uint32_t modifiers) {
UpdateFocusItemType(FocusElementType::kPage);
} else {
// No focusable annotation found in pages. Possible scenarios:
- // Case 1: |focus_item_type_| is None. Since no object in any page can take
+ // Case 1: `focus_item_type_` is None. Since no object in any page can take
// the focus, the document should take focus.
- // Case 2: |focus_item_type_| is Page. Since there aren't any objects that
+ // Case 2: `focus_item_type_` is Page. Since there aren't any objects that
// could take focus, the document should take focus.
- // Case 3: |focus_item_type_| is Document. Move focus_item_type_ to None.
+ // Case 3: `focus_item_type_` is Document. Move focus_item_type_ to None.
switch (focus_item_type_) {
case FocusElementType::kPage:
case FocusElementType::kNone:
diff --git a/chromium/pdf/pdfium/pdfium_engine.h b/chromium/pdf/pdfium/pdfium_engine.h
index b9996a3b4d3..e9207174c40 100644
--- a/chromium/pdf/pdfium/pdfium_engine.h
+++ b/chromium/pdf/pdfium/pdfium_engine.h
@@ -14,7 +14,6 @@
#include <vector>
#include "base/memory/weak_ptr.h"
-#include "base/optional.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/values.h"
@@ -29,6 +28,7 @@
#include "pdf/pdfium/pdfium_range.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/cpp/dev/buffer_dev.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
#include "third_party/pdfium/public/fpdf_progressive.h"
@@ -39,14 +39,17 @@
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
+namespace blink {
+class WebKeyboardEvent;
+class WebMouseEvent;
+class WebTouchEvent;
+} // namespace blink
+
namespace chrome_pdf {
enum class AccessibilityScrollAlignment;
-class KeyboardInputEvent;
-class MouseInputEvent;
class PDFiumDocument;
class PDFiumPermissions;
-class TouchInputEvent;
struct AccessibilityActionData;
struct AccessibilityTextRunInfo;
struct PageCharacterIndex;
@@ -66,7 +69,7 @@ class PDFiumEngine : public PDFEngine,
// Exposed for testing.
enum class FocusElementType { kNone, kDocument, kPage };
- // NOTE: |script_option| is ignored when PDF_ENABLE_V8 is not defined.
+ // NOTE: `script_option` is ignored when PDF_ENABLE_V8 is not defined.
PDFiumEngine(PDFEngine::Client* client,
PDFiumFormFiller::ScriptOption script_option);
PDFiumEngine(const PDFiumEngine&) = delete;
@@ -90,7 +93,7 @@ class PDFiumEngine : public PDFEngine,
std::vector<gfx::Rect>& pending) override;
void PostPaint() override;
bool HandleDocumentLoad(std::unique_ptr<UrlLoader> loader) override;
- bool HandleEvent(const InputEvent& event) override;
+ bool HandleInputEvent(const blink::WebInputEvent& event) override;
uint32_t QuerySupportedPrintOutputFormats() override;
void PrintBegin() override;
pp::Resource PrintPages(
@@ -112,11 +115,11 @@ class PDFiumEngine : public PDFEngine,
gfx::Size ApplyDocumentLayout(
const DocumentLayout::Options& options) override;
std::string GetSelectedText() override;
- bool CanEditText() override;
- bool HasEditableText() override;
+ bool CanEditText() const override;
+ bool HasEditableText() const override;
void ReplaceSelection(const std::string& text) override;
- bool CanUndo() override;
- bool CanRedo() override;
+ bool CanUndo() const override;
+ bool CanRedo() const override;
void Undo() override;
void Redo() override;
void HandleAccessibilityAction(
@@ -130,18 +133,17 @@ class PDFiumEngine : public PDFEngine,
const DocumentMetadata& GetDocumentMetadata() const override;
int GetNumberOfPages() const override;
base::Value GetBookmarks() override;
- base::Optional<PDFEngine::NamedDestination> GetNamedDestination(
+ absl::optional<PDFEngine::NamedDestination> GetNamedDestination(
const std::string& destination) override;
int GetMostVisiblePage() override;
gfx::Rect GetPageBoundsRect(int index) override;
gfx::Rect GetPageContentsRect(int index) override;
gfx::Rect GetPageScreenRect(int page_index) const override;
- int GetVerticalScrollbarYPosition() override;
void SetGrayscale(bool grayscale) override;
int GetCharCount(int page_index) override;
gfx::RectF GetCharBounds(int page_index, int char_index) override;
uint32_t GetCharUnicode(int page_index, int char_index) override;
- base::Optional<AccessibilityTextRunInfo> GetTextRunInfo(
+ absl::optional<AccessibilityTextRunInfo> GetTextRunInfo(
int page_index,
int start_char_index) override;
std::vector<AccessibilityLinkInfo> GetLinkInfo(
@@ -159,7 +161,7 @@ class PDFiumEngine : public PDFEngine,
bool GetPrintScaling() override;
int GetCopiesToPrint() override;
int GetDuplexType() override;
- base::Optional<gfx::Size> GetUniformPageSizePoints() override;
+ absl::optional<gfx::Size> GetUniformPageSizePoints() override;
void AppendBlankPages(size_t num_pages) override;
void AppendPage(PDFEngine* engine, int index) override;
std::vector<uint8_t> GetSaveData() override;
@@ -215,7 +217,7 @@ class PDFiumEngine : public PDFEngine,
// coordinates.
std::vector<gfx::Rect> GetVisibleSelections() const;
- // Invalidates |selection|, but with |selection| slightly expanded to
+ // Invalidates `selection`, but with `selection` slightly expanded to
// compensate for any rounding errors.
void Invalidate(const gfx::Rect& selection);
@@ -258,8 +260,8 @@ class PDFiumEngine : public PDFEngine,
// Try loading the document. Returns true if the document is successfully
// loaded or is already loaded otherwise it will return false. If there is a
- // password, then |password| is non-empty. If the document could not be loaded
- // and needs a password, |needs_password| will be set to true.
+ // password, then `password` is non-empty. If the document could not be loaded
+ // and needs a password, `needs_password` will be set to true.
bool TryLoadingDoc(const std::string& password, bool* needs_password);
// Asks the user for the document password and then continue loading the
@@ -270,13 +272,13 @@ class PDFiumEngine : public PDFEngine,
void OnGetPasswordComplete(const std::string& password);
// Continues loading the document when the password has been retrieved, or if
- // there is no password. If there is no password, then |password| is empty.
+ // there is no password. If there is no password, then `password` is empty.
void ContinueLoadingDocument(const std::string& password);
// Finishes loading the document. Recalculate the document size if there were
// pages that were not previously available.
// Also notifies the client that the document has been loaded.
- // This should only be called after |doc_| has been loaded and the document is
+ // This should only be called after `doc_` has been loaded and the document is
// fully downloaded.
// If this has been run once, it will not notify the client again.
void FinishLoadingDocument();
@@ -288,10 +290,10 @@ class PDFiumEngine : public PDFEngine,
void RefreshCurrentDocumentLayout();
// Proposes the next document layout using the current pages and
- // |desired_layout_options_|.
+ // `desired_layout_options_`.
void ProposeNextDocumentLayout();
- // Updates |layout| using the current page sizes.
+ // Updates `layout` using the current page sizes.
void UpdateDocumentLayout(DocumentLayout* layout);
// Loads information about the pages in the document, calculating and
@@ -339,23 +341,23 @@ class PDFiumEngine : public PDFEngine,
// Helper function for getting the inset sizes for the current layout. If
// two-up view is enabled, the configuration of inset sizes depends on
- // the position of the page, specified by |page_index| and |num_of_pages|.
+ // the position of the page, specified by `page_index` and `num_of_pages`.
draw_utils::PageInsetSizes GetInsetSizes(
const DocumentLayout::Options& layout_options,
size_t page_index,
size_t num_of_pages) const;
- // If two-up view is disabled, enlarges |page_size| with inset sizes for
+ // If two-up view is disabled, enlarges `page_size` with inset sizes for
// single-view. If two-up view is enabled, calls GetInsetSizes() with
- // |page_index| and |num_of_pages|, and uses the returned inset sizes to
- // enlarge |page_size|.
+ // `page_index` and `num_of_pages`, and uses the returned inset sizes to
+ // enlarge `page_size`.
void EnlargePage(const DocumentLayout::Options& layout_options,
size_t page_index,
size_t num_of_pages,
gfx::Size* page_size) const;
- // Similar to EnlargePage(), but insets a |rect|. Also multiplies the inset
- // sizes by |multiplier|, using the ceiling of the result.
+ // Similar to EnlargePage(), but insets a `rect`. Also multiplies the inset
+ // sizes by `multiplier`, using the ceiling of the result.
void InsetPage(const DocumentLayout::Options& layout_options,
size_t page_index,
size_t num_of_pages,
@@ -363,9 +365,9 @@ class PDFiumEngine : public PDFEngine,
gfx::Rect& rect) const;
// If two-up view is enabled, returns the index of the page beside
- // |page_index| page. Returns base::nullopt if there is no adjacent page or
+ // `page_index` page. Returns absl::nullopt if there is no adjacent page or
// if two-up view is disabled.
- base::Optional<size_t> GetAdjacentPageIndexForTwoUpView(
+ absl::optional<size_t> GetAdjacentPageIndexForTwoUpView(
size_t page_index,
size_t num_of_pages) const;
@@ -378,7 +380,7 @@ class PDFiumEngine : public PDFEngine,
// Called to continue searching so we don't block the main thread.
void ContinueFind(int32_t result);
- // Inserts a find result into |find_results_|, which is sorted.
+ // Inserts a find result into `find_results_`, which is sorted.
void AddFindResult(const PDFiumRange& result);
// Search a page using PDFium's methods. Doesn't work with unicode. This
@@ -397,13 +399,13 @@ class PDFiumEngine : public PDFEngine,
int current_page);
// Input event handlers.
- bool OnMouseDown(const MouseInputEvent& event);
- bool OnMouseUp(const MouseInputEvent& event);
- bool OnMouseMove(const MouseInputEvent& event);
- void OnMouseEnter(const MouseInputEvent& event);
- bool OnKeyDown(const KeyboardInputEvent& event);
- bool OnKeyUp(const KeyboardInputEvent& event);
- bool OnChar(const KeyboardInputEvent& event);
+ bool OnMouseDown(const blink::WebMouseEvent& event);
+ bool OnMouseUp(const blink::WebMouseEvent& event);
+ bool OnMouseMove(const blink::WebMouseEvent& event);
+ void OnMouseEnter(const blink::WebMouseEvent& event);
+ bool OnKeyDown(const blink::WebKeyboardEvent& event);
+ bool OnKeyUp(const blink::WebKeyboardEvent& event);
+ bool OnChar(const blink::WebKeyboardEvent& event);
// Decide what cursor should be displayed.
ui::mojom::CursorType DetermineCursorType(PDFiumPage::Area area,
@@ -425,11 +427,11 @@ class PDFiumEngine : public PDFEngine,
pp::Buffer_Dev ConvertPdfToBufferDev(const std::vector<uint8_t>& pdf_data);
- // Checks if |page| has selected text in a form element. If so, sets that as
+ // Checks if `page` has selected text in a form element. If so, sets that as
// the plugin's text selection.
void SetFormSelectedText(FPDF_FORMHANDLE form_handle, FPDF_PAGE page);
- // Given |point|, returns which page and character location it's closest to,
+ // Given `point`, returns which page and character location it's closest to,
// as well as extra information about objects at that point.
PDFiumPage::Area GetCharIndex(const gfx::Point& point,
int* page_index,
@@ -439,9 +441,9 @@ class PDFiumEngine : public PDFEngine,
void OnSingleClick(int page_index, int char_index);
void OnMultipleClick(int click_count, int page_index, int char_index);
- bool OnLeftMouseDown(const MouseInputEvent& event);
- bool OnMiddleMouseDown(const MouseInputEvent& event);
- bool OnRightMouseDown(const MouseInputEvent& event);
+ bool OnLeftMouseDown(const blink::WebMouseEvent& event);
+ bool OnMiddleMouseDown(const blink::WebMouseEvent& event);
+ bool OnRightMouseDown(const blink::WebMouseEvent& event);
// Starts a progressive paint operation given a rectangle in screen
// coordinates. Returns the index in progressive_rects_.
@@ -499,13 +501,13 @@ class PDFiumEngine : public PDFEngine,
// Returns the currently visible rectangle in document coordinates.
gfx::Rect GetVisibleRect() const;
- // Given |rect| in document coordinates, returns the rectangle in screen
+ // Given `rect` in document coordinates, returns the rectangle in screen
// coordinates. (i.e. 0,0 is top left corner of plugin area)
gfx::Rect GetScreenRect(const gfx::Rect& rect) const;
- // Given an image |buffer| with |stride|, highlights |rect|.
- // |highlighted_rects| contains the already highlighted rectangles and will be
- // updated to include |rect| if |rect| has not already been highlighted.
+ // Given an image `buffer` with `stride`, highlights `rect`.
+ // `highlighted_rects` contains the already highlighted rectangles and will be
+ // updated to include `rect` if `rect` has not already been highlighted.
void Highlight(void* buffer,
int stride,
const gfx::Rect& rect,
@@ -515,7 +517,7 @@ class PDFiumEngine : public PDFEngine,
std::vector<gfx::Rect>& highlighted_rects) const;
// Helper function to convert a device to page coordinates. If the page is
- // not yet loaded, |page_x| and |page_y| will be set to 0.
+ // not yet loaded, `page_x` and `page_y` will be set to 0.
void DeviceToPage(int page_index,
const gfx::Point& device_point,
double* page_x,
@@ -554,7 +556,7 @@ class PDFiumEngine : public PDFEngine,
// Sets whether or not left mouse button is currently being held down.
void SetMouseLeftButtonDown(bool is_mouse_left_button_down);
- // Given an annotation which is a form of |form_type| which is known to be a
+ // Given an annotation which is a form of `form_type` which is known to be a
// form text area, check if it is an editable form text area.
bool IsAnnotationAnEditableFormTextArea(FPDF_ANNOTATION annot,
int form_type) const;
@@ -562,9 +564,9 @@ class PDFiumEngine : public PDFEngine,
bool PageIndexInBounds(int index) const;
bool IsPageCharacterIndexInBounds(const PageCharacterIndex& index) const;
- void ScheduleTouchTimer(const TouchInputEvent& event);
+ void ScheduleTouchTimer(const blink::WebTouchEvent& event);
void KillTouchTimer();
- void HandleLongPress(const TouchInputEvent& event);
+ void HandleLongPress(const blink::WebTouchEvent& event);
// Returns a base::Value (representing a bookmark), which in turn contains
// child base::Value dictionaries (representing the child bookmarks).
@@ -577,7 +579,7 @@ class PDFiumEngine : public PDFEngine,
const AccessibilityScrollAlignment& horizontal_scroll_alignment,
const AccessibilityScrollAlignment& vertical_scroll_alignment);
- // Scrolls top left of a rect in page |target_rect| to |global_point|.
+ // Scrolls top left of a rect in page `target_rect` to `global_point`.
// Global point is point relative to viewport in screen.
void ScrollToGlobalPoint(const gfx::Rect& target_rect,
const gfx::Point& global_point);
@@ -586,7 +588,7 @@ class PDFiumEngine : public PDFEngine,
void EnteredEditMode();
// Navigates to a link destination depending on the type of destination.
- // Returns false if |area| is not a link.
+ // Returns false if `area` is not a link.
bool NavigateToLinkDestination(PDFiumPage::Area area,
const PDFiumPage::LinkTarget& target,
WindowOpenDisposition disposition);
@@ -595,27 +597,27 @@ class PDFiumEngine : public PDFEngine,
static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE* param);
// Used for text selection. Given the start and end of selection, sets the
- // text range in |selection_|.
+ // text range in `selection_`.
void SetSelection(const PageCharacterIndex& selection_start_index,
const PageCharacterIndex& selection_end_index);
// Scroll the current focused annotation into view if not already in view.
void ScrollFocusedAnnotationIntoView();
- // Given |annot|, scroll the |annot| into view if not already in view.
+ // Given `annot`, scroll the `annot` into view if not already in view.
void ScrollAnnotationIntoView(FPDF_ANNOTATION annot, int page_index);
void OnFocusedAnnotationUpdated(FPDF_ANNOTATION annot, int page_index);
// Read the attachments' information inside the PDF document, and set
- // |doc_attachment_info_list_|. To be called after the document is loaded.
+ // `doc_attachment_info_list_`. To be called after the document is loaded.
void LoadDocumentAttachmentInfoList();
- // Fetches and populates the fields of |doc_metadata_|. To be called after the
+ // Fetches and populates the fields of `doc_metadata_`. To be called after the
// document is loaded.
void LoadDocumentMetadata();
- // Retrieves the value of |field| in the document information dictionary.
+ // Retrieves the value of `field` in the document information dictionary.
// Trims whitespace characters from the retrieved value.
std::string GetTrimmedMetadataByField(FPDF_BYTESTRING field) const;
@@ -624,15 +626,15 @@ class PDFiumEngine : public PDFEngine,
// This is a layer between OnKeyDown() and actual tab handling to facilitate
// testing.
- bool HandleTabEvent(uint32_t modifiers);
+ bool HandleTabEvent(int modifiers);
// Helper functions to handle tab events.
- bool HandleTabEventWithModifiers(uint32_t modifiers);
- bool HandleTabForward(uint32_t modifiers);
- bool HandleTabBackward(uint32_t modifiers);
+ bool HandleTabEventWithModifiers(int modifiers);
+ bool HandleTabForward(int modifiers);
+ bool HandleTabBackward(int modifiers);
- // Updates the currently focused object stored in |focus_item_type_|. Notifies
- // |client_| about document focus change, if any.
+ // Updates the currently focused object stored in `focus_item_type_`. Notifies
+ // `client_` about document focus change, if any.
void UpdateFocusItemType(FocusElementType focus_item_type);
void UpdateLinkUnderCursor(const std::string& target_url);
@@ -726,9 +728,9 @@ class PDFiumEngine : public PDFEngine,
int last_page_to_search_ = -1;
int last_character_index_to_search_ = -1; // -1 if search until end of page.
// Which result the user has currently selected. (0-based)
- base::Optional<size_t> current_find_index_;
+ absl::optional<size_t> current_find_index_;
// Where to resume searching. (0-based)
- base::Optional<size_t> resume_find_index_;
+ absl::optional<size_t> resume_find_index_;
std::unique_ptr<PDFiumPermissions> permissions_;
@@ -762,7 +764,7 @@ class PDFiumEngine : public PDFEngine,
// Holds the page index requested by PDFium while the scroll operation
// is being handled (asynchronously).
- base::Optional<int> in_flight_visible_page_;
+ absl::optional<int> in_flight_visible_page_;
// Set to true after FORM_DoDocumentJSAction/FORM_DoDocumentOpenAction have
// been called. Only after that can we call FORM_DoPageAAction.
@@ -847,7 +849,7 @@ class PDFiumEngine : public PDFEngine,
// Weak pointers from this factory are used to bind the ContinueFind()
// function. This allows those weak pointers to be invalidated during
- // StopFind(), and keeps the invalidation separated from |weak_factory_|.
+ // StopFind(), and keeps the invalidation separated from `weak_factory_`.
base::WeakPtrFactory<PDFiumEngine> find_weak_factory_{this};
};
diff --git a/chromium/pdf/pdfium/pdfium_engine_exports.cc b/chromium/pdf/pdfium/pdfium_engine_exports.cc
index 780361bab26..1b695652d35 100644
--- a/chromium/pdf/pdfium/pdfium_engine_exports.cc
+++ b/chromium/pdf/pdfium/pdfium_engine_exports.cc
@@ -10,13 +10,13 @@
#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
-#include "base/optional.h"
#include "build/chromeos_buildflags.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
#include "pdf/pdfium/pdfium_print.h"
#include "printing/nup_parameters.h"
#include "printing/units.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_catalog.h"
#include "third_party/pdfium/public/fpdf_ppo.h"
@@ -153,7 +153,7 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
if (children_count <= 0)
return base::Value(base::Value::Type::NONE);
- base::Optional<std::u16string> opt_type =
+ absl::optional<std::u16string> opt_type =
CallPDFiumWideStringBufferApiAndReturnOptional(
base::BindRepeating(FPDF_StructElement_GetType, struct_elem), true);
if (!opt_type)
@@ -162,14 +162,14 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
base::Value result(base::Value::Type::DICTIONARY);
result.SetStringKey("type", *opt_type);
- base::Optional<std::u16string> opt_alt =
+ absl::optional<std::u16string> opt_alt =
CallPDFiumWideStringBufferApiAndReturnOptional(
base::BindRepeating(FPDF_StructElement_GetAltText, struct_elem),
true);
if (opt_alt)
result.SetStringKey("alt", *opt_alt);
- base::Optional<std::u16string> opt_lang =
+ absl::optional<std::u16string> opt_lang =
CallPDFiumWideStringBufferApiAndReturnOptional(
base::BindRepeating(FPDF_StructElement_GetLang, struct_elem), true);
if (opt_lang)
@@ -411,11 +411,11 @@ bool PDFiumEngineExports::GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
return true;
}
-base::Optional<bool> PDFiumEngineExports::IsPDFDocTagged(
+absl::optional<bool> PDFiumEngineExports::IsPDFDocTagged(
base::span<const uint8_t> pdf_buffer) {
ScopedFPDFDocument doc = LoadPdfData(pdf_buffer);
if (!doc)
- return base::nullopt;
+ return absl::nullopt;
return FPDFCatalog_IsTagged(doc.get());
}
@@ -448,16 +448,16 @@ base::Value PDFiumEngineExports::GetPDFStructTreeForPage(
return RecursiveGetStructTree(struct_root_elem);
}
-base::Optional<gfx::SizeF> PDFiumEngineExports::GetPDFPageSizeByIndex(
+absl::optional<gfx::SizeF> PDFiumEngineExports::GetPDFPageSizeByIndex(
base::span<const uint8_t> pdf_buffer,
int page_number) {
ScopedFPDFDocument doc = LoadPdfData(pdf_buffer);
if (!doc)
- return base::nullopt;
+ return absl::nullopt;
FS_SIZEF size;
if (!FPDF_GetPageSizeByIndexF(doc.get(), page_number, &size))
- return base::nullopt;
+ return absl::nullopt;
return gfx::SizeF(size.width, size.height);
}
diff --git a/chromium/pdf/pdfium/pdfium_engine_exports.h b/chromium/pdf/pdfium/pdfium_engine_exports.h
index 39d11fb6aa0..66215e0fc8d 100644
--- a/chromium/pdf/pdfium/pdfium_engine_exports.h
+++ b/chromium/pdf/pdfium/pdfium_engine_exports.h
@@ -54,11 +54,11 @@ class PDFiumEngineExports : public PDFEngineExports {
bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
int* page_count,
float* max_page_width) override;
- base::Optional<bool> IsPDFDocTagged(
+ absl::optional<bool> IsPDFDocTagged(
base::span<const uint8_t> pdf_buffer) override;
base::Value GetPDFStructTreeForPage(base::span<const uint8_t> pdf_buffer,
int page_index) override;
- base::Optional<gfx::SizeF> GetPDFPageSizeByIndex(
+ absl::optional<gfx::SizeF> GetPDFPageSizeByIndex(
base::span<const uint8_t> pdf_buffer,
int page_number) override;
};
diff --git a/chromium/pdf/pdfium/pdfium_engine_exports_unittest.cc b/chromium/pdf/pdfium/pdfium_engine_exports_unittest.cc
index 189504a58b4..0c949105ec9 100644
--- a/chromium/pdf/pdfium/pdfium_engine_exports_unittest.cc
+++ b/chromium/pdf/pdfium/pdfium_engine_exports_unittest.cc
@@ -3,13 +3,10 @@
// found in the LICENSE file.
#include "base/files/file_util.h"
-#include "base/optional.h"
#include "base/path_service.h"
-#include "base/test/test_simple_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "gin/v8_initializer.h"
#include "pdf/pdf.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
@@ -18,16 +15,6 @@ namespace chrome_pdf {
namespace {
-void LoadV8SnapshotData() {
-#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
- static bool loaded = false;
- if (!loaded) {
- loaded = true;
- gin::V8Initializer::LoadV8Snapshot();
- }
-#endif
-}
-
class PDFiumEngineExportsTest : public testing::Test {
public:
PDFiumEngineExportsTest() = default;
@@ -37,11 +24,6 @@ class PDFiumEngineExportsTest : public testing::Test {
protected:
void SetUp() override {
- LoadV8SnapshotData();
-
- handle_ = std::make_unique<base::ThreadTaskRunnerHandle>(
- base::MakeRefCounted<base::TestSimpleTaskRunner>());
-
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &pdf_data_dir_));
pdf_data_dir_ = pdf_data_dir_.Append(FILE_PATH_LITERAL("pdf"))
.Append(FILE_PATH_LITERAL("test"))
@@ -51,7 +33,6 @@ class PDFiumEngineExportsTest : public testing::Test {
const base::FilePath& pdf_data_dir() const { return pdf_data_dir_; }
private:
- std::unique_ptr<base::ThreadTaskRunnerHandle> handle_;
base::FilePath pdf_data_dir_;
};
@@ -86,7 +67,7 @@ TEST_F(PDFiumEngineExportsTest, GetPDFPageSizeByIndex) {
ASSERT_TRUE(GetPDFDocInfo(pdf_span, &page_count, nullptr));
ASSERT_EQ(2, page_count);
for (int page_number = 0; page_number < page_count; ++page_number) {
- base::Optional<gfx::SizeF> page_size =
+ absl::optional<gfx::SizeF> page_size =
GetPDFPageSizeByIndex(pdf_span, page_number);
ASSERT_TRUE(page_size.has_value());
EXPECT_EQ(gfx::SizeF(200, 200), page_size.value());
@@ -128,7 +109,7 @@ TEST_F(PDFiumEngineExportsTest, ConvertPdfPagesToNupPdf) {
ASSERT_TRUE(GetPDFDocInfo(output_pdf_span, &page_count, nullptr));
ASSERT_EQ(1, page_count);
- base::Optional<gfx::SizeF> page_size =
+ absl::optional<gfx::SizeF> page_size =
GetPDFPageSizeByIndex(output_pdf_span, 0);
ASSERT_TRUE(page_size.has_value());
EXPECT_EQ(gfx::SizeF(792, 612), page_size.value());
@@ -156,7 +137,7 @@ TEST_F(PDFiumEngineExportsTest, ConvertPdfDocumentToNupPdf) {
ASSERT_TRUE(GetPDFDocInfo(output_pdf_span, &page_count, nullptr));
ASSERT_EQ(2, page_count);
for (int page_number = 0; page_number < page_count; ++page_number) {
- base::Optional<gfx::SizeF> page_size =
+ absl::optional<gfx::SizeF> page_size =
GetPDFPageSizeByIndex(output_pdf_span, page_number);
ASSERT_TRUE(page_size.has_value());
EXPECT_EQ(gfx::SizeF(612, 792), page_size.value());
diff --git a/chromium/pdf/pdfium/pdfium_engine_unittest.cc b/chromium/pdf/pdfium/pdfium_engine_unittest.cc
index cf976dc1374..6089a0d8375 100644
--- a/chromium/pdf/pdfium/pdfium_engine_unittest.cc
+++ b/chromium/pdf/pdfium/pdfium_engine_unittest.cc
@@ -11,7 +11,6 @@
#include "base/test/gtest_util.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
-#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "pdf/document_attachment_info.h"
#include "pdf/document_layout.h"
@@ -19,12 +18,12 @@
#include "pdf/pdf_features.h"
#include "pdf/pdfium/pdfium_page.h"
#include "pdf/pdfium/pdfium_test_base.h"
-#include "pdf/ppapi_migration/input_event_conversions.h"
#include "pdf/test/test_client.h"
#include "pdf/test/test_document_loader.h"
#include "pdf/ui/thumbnail.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
@@ -159,7 +158,7 @@ TEST_F(PDFiumEngineTest, InitializeWithRectanglesMultiPagesPdfInTwoUpView) {
ASSERT_TRUE(engine);
DocumentLayout::Options options;
- options.set_two_up_view_enabled(true);
+ options.set_page_spread(DocumentLayout::PageSpread::kTwoUpOdd);
EXPECT_CALL(client, ProposeDocumentLayout(LayoutWithOptions(options)))
.WillOnce(Return());
engine->SetTwoUpView(true);
@@ -551,7 +550,7 @@ class PDFiumEngineTabbingTest : public PDFiumTestBase {
PDFiumEngineTabbingTest(const PDFiumEngineTabbingTest&) = delete;
PDFiumEngineTabbingTest& operator=(const PDFiumEngineTabbingTest&) = delete;
- bool HandleTabEvent(PDFiumEngine* engine, uint32_t modifiers) {
+ bool HandleTabEvent(PDFiumEngine* engine, int modifiers) {
return engine->HandleTabEvent(modifiers);
}
@@ -587,10 +586,6 @@ class PDFiumEngineTabbingTest : public PDFiumTestBase {
void ScrollFocusedAnnotationIntoView(PDFiumEngine* engine) {
engine->ScrollFocusedAnnotationIntoView();
}
-
- protected:
- base::test::TaskEnvironment task_environment_{
- base::test::TaskEnvironment::TimeSource::MOCK_TIME};
};
TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorTest) {
@@ -627,7 +622,8 @@ TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorTest) {
EXPECT_EQ("https://www.google.com/", GetLinkUnderCursor(engine.get()));
// Tab to previous annotation.
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ("", GetLinkUnderCursor(engine.get()));
}
@@ -767,26 +763,31 @@ TEST_F(PDFiumEngineTabbingTest, TabbingBackwardTest) {
GetFocusedElementType(engine.get()));
EXPECT_EQ(-1, GetLastFocusedPage(engine.get()));
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(1, GetLastFocusedPage(engine.get()));
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kDocument,
GetFocusedElementType(engine.get()));
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_FALSE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kNone,
GetFocusedElementType(engine.get()));
}
@@ -813,9 +814,11 @@ TEST_F(PDFiumEngineTabbingTest, TabbingWithModifiers) {
EXPECT_EQ(-1, GetLastFocusedPage(engine.get()));
// Tabbing with ctrl modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierControlKey));
+ ASSERT_FALSE(HandleTabEvent(engine.get(),
+ blink::WebInputEvent::Modifiers::kControlKey));
// Tabbing with alt modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierAltKey));
+ ASSERT_FALSE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kAltKey));
// Tab to bring document into focus.
ASSERT_TRUE(HandleTabEvent(engine.get(), 0));
@@ -823,9 +826,11 @@ TEST_F(PDFiumEngineTabbingTest, TabbingWithModifiers) {
GetFocusedElementType(engine.get()));
// Tabbing with ctrl modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierControlKey));
+ ASSERT_FALSE(HandleTabEvent(engine.get(),
+ blink::WebInputEvent::Modifiers::kControlKey));
// Tabbing with alt modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierAltKey));
+ ASSERT_FALSE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kAltKey));
// Tab to bring first page into focus.
ASSERT_TRUE(HandleTabEvent(engine.get(), 0));
@@ -833,9 +838,11 @@ TEST_F(PDFiumEngineTabbingTest, TabbingWithModifiers) {
GetFocusedElementType(engine.get()));
// Tabbing with ctrl modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierControlKey));
+ ASSERT_FALSE(HandleTabEvent(engine.get(),
+ blink::WebInputEvent::Modifiers::kControlKey));
// Tabbing with alt modifier.
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierAltKey));
+ ASSERT_FALSE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kAltKey));
}
TEST_F(PDFiumEngineTabbingTest, NoFocusableItemTabbingTest) {
@@ -873,11 +880,13 @@ TEST_F(PDFiumEngineTabbingTest, NoFocusableItemTabbingTest) {
GetFocusedElementType(engine.get()));
// Tabbing backward.
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kDocument,
GetFocusedElementType(engine.get()));
- ASSERT_FALSE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_FALSE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kNone,
GetFocusedElementType(engine.get()));
}
@@ -1055,7 +1064,8 @@ TEST_F(PDFiumEngineTabbingTest, RetainSelectionOnFocusNotInFormTextArea) {
EXPECT_EQ(1u, GetSelectionSize(engine.get()));
// Tab to bring focus to a non form text area annotation (Button).
- ASSERT_TRUE(HandleTabEvent(engine.get(), kInputEventModifierShiftKey));
+ ASSERT_TRUE(
+ HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
diff --git a/chromium/pdf/pdfium/pdfium_font_linux.cc b/chromium/pdf/pdfium/pdfium_font_linux.cc
index dd7f4f48c64..2f31779fde6 100644
--- a/chromium/pdf/pdfium/pdfium_font_linux.cc
+++ b/chromium/pdf/pdfium/pdfium_font_linux.cc
@@ -142,7 +142,7 @@ void* MapFont(FPDF_SYSFONTINFO*,
} else {
std::string encoding;
if (base::DetectEncoding(face, &encoding)) {
- // ConvertToUtf8AndNormalize() clears |face_utf8| on failure.
+ // ConvertToUtf8AndNormalize() clears `face_utf8` on failure.
base::ConvertToUtf8AndNormalize(face, encoding, &face_utf8);
}
}
diff --git a/chromium/pdf/pdfium/pdfium_font_linux.h b/chromium/pdf/pdfium/pdfium_font_linux.h
index 4caa7913550..3e5decd6b19 100644
--- a/chromium/pdf/pdfium/pdfium_font_linux.h
+++ b/chromium/pdf/pdfium/pdfium_font_linux.h
@@ -17,7 +17,7 @@ namespace chrome_pdf {
void InitializeLinuxFontMapper();
// Keeps track of the most recently used plugin instance. This is a no-op of
-// |last_instance| is null.
+// `last_instance` is null.
void SetLastInstance(pp::Instance* last_instance);
} // namespace chrome_pdf
diff --git a/chromium/pdf/pdfium/pdfium_form_filler.cc b/chromium/pdf/pdfium/pdfium_form_filler.cc
index b2ac56ae874..b4d57a6127b 100644
--- a/chromium/pdf/pdfium/pdfium_form_filler.cc
+++ b/chromium/pdf/pdfium/pdfium_form_filler.cc
@@ -9,13 +9,14 @@
#include <utility>
#include "base/bind.h"
+#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "pdf/pdf_features.h"
#include "pdf/pdfium/pdfium_engine.h"
-#include "pdf/ppapi_migration/input_event_conversions.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/pdfium/public/fpdf_annot.h"
#include "ui/gfx/geometry/rect.h"
@@ -330,11 +331,12 @@ void PDFiumFormFiller::Form_DoURIActionWithKeyboardModifier(
FPDF_BYTESTRING uri,
int modifiers) {
PDFiumEngine* engine = GetEngine(param);
- bool middle_button = !!(modifiers & kInputEventModifierMiddleButtonDown);
- bool alt_key = !!(modifiers & kInputEventModifierAltKey);
- bool ctrl_key = !!(modifiers & kInputEventModifierControlKey);
- bool meta_key = !!(modifiers & kInputEventModifierMetaKey);
- bool shift_key = !!(modifiers & kInputEventModifierShiftKey);
+ bool middle_button =
+ !!(modifiers & blink::WebInputEvent::Modifiers::kMiddleButtonDown);
+ bool alt_key = !!(modifiers & blink::WebInputEvent::Modifiers::kAltKey);
+ bool ctrl_key = !!(modifiers & blink::WebInputEvent::Modifiers::kControlKey);
+ bool meta_key = !!(modifiers & blink::WebInputEvent::Modifiers::kMetaKey);
+ bool shift_key = !!(modifiers & blink::WebInputEvent::Modifiers::kShiftKey);
WindowOpenDisposition disposition = ui::DispositionFromClick(
middle_button, alt_key, ctrl_key, meta_key, shift_key);
@@ -641,7 +643,7 @@ void PDFiumFormFiller::Form_Mail(IPDF_JSPLATFORM* param,
FPDF_WIDESTRING cc,
FPDF_WIDESTRING bcc,
FPDF_WIDESTRING message) {
- // Note: |mail_data| and |length| are ignored. We don't handle attachments;
+ // Note: `mail_data` and `length` are ignored. We don't handle attachments;
// there is no way with mailto.
std::string to_str = WideStringToString(to);
std::string cc_str = WideStringToString(cc);
diff --git a/chromium/pdf/pdfium/pdfium_form_filler.h b/chromium/pdf/pdfium/pdfium_form_filler.h
index 3408a8114ff..53b206e7d66 100644
--- a/chromium/pdf/pdfium/pdfium_form_filler.h
+++ b/chromium/pdf/pdfium/pdfium_form_filler.h
@@ -22,7 +22,7 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
enum class ScriptOption { kNoJavaScript, kJavaScript, kJavaScriptAndXFA };
static PDFiumFormFiller::ScriptOption DefaultScriptOption();
- // NOTE: |script_option| is ignored when PDF_ENABLE_V8 is not defined.
+ // NOTE: `script_option` is ignored when PDF_ENABLE_V8 is not defined.
PDFiumFormFiller(PDFiumEngine* engine, ScriptOption script_option);
PDFiumFormFiller(const PDFiumFormFiller&) = delete;
PDFiumFormFiller& operator=(const PDFiumFormFiller&) = delete;
diff --git a/chromium/pdf/pdfium/pdfium_form_filler_unittest.cc b/chromium/pdf/pdfium/pdfium_form_filler_unittest.cc
index 031bff08a33..c86242b57b9 100644
--- a/chromium/pdf/pdfium/pdfium_form_filler_unittest.cc
+++ b/chromium/pdf/pdfium/pdfium_form_filler_unittest.cc
@@ -5,9 +5,9 @@
#include "build/build_config.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_test_base.h"
-#include "pdf/ppapi_migration/input_event_conversions.h"
#include "pdf/test/test_client.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/pdfium/public/fpdf_annot.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
@@ -89,25 +89,26 @@ TEST_F(FormFillerTest, DoURIActionWithKeyboardModifier) {
.Times(1);
}
+ constexpr blink::WebInputEvent::Modifiers kModifierKey =
#if defined(OS_MAC)
-#define modifier_key kInputEventModifierMetaKey;
+ blink::WebInputEvent::Modifiers::kMetaKey;
#else
-#define modifier_key kInputEventModifierControlKey
+ blink::WebInputEvent::Modifiers::kControlKey;
#endif
int modifiers = 0;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers = kInputEventModifierAltKey;
+ modifiers = blink::WebInputEvent::Modifiers::kAltKey;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers = modifier_key;
+ modifiers = kModifierKey;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers = kInputEventModifierShiftKey;
+ modifiers = blink::WebInputEvent::Modifiers::kShiftKey;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers |= modifier_key;
+ modifiers |= kModifierKey;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers = kInputEventModifierMiddleButtonDown;
+ modifiers = blink::WebInputEvent::Modifiers::kMiddleButtonDown;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
- modifiers |= kInputEventModifierShiftKey;
+ modifiers |= blink::WebInputEvent::Modifiers::kShiftKey;
TriggerDoURIActionWithKeyboardModifier(engine.get(), kUri, modifiers);
}
diff --git a/chromium/pdf/pdfium/pdfium_page.cc b/chromium/pdf/pdfium/pdfium_page.cc
index cfbaa0a5767..c8af6ea5e58 100644
--- a/chromium/pdf/pdfium/pdfium_page.cc
+++ b/chromium/pdf/pdfium/pdfium_page.cc
@@ -78,7 +78,7 @@ gfx::RectF FloatPageRectToPixelRect(FPDF_PAGE page, const gfx::RectF& input) {
if (max_y < min_y)
std::swap(min_y, max_y);
- // Make sure small but non-zero dimensions for |input| does not get rounded
+ // Make sure small but non-zero dimensions for `input` does not get rounded
// down to 0.
int width = max_x - min_x;
int height = max_y - min_y;
@@ -198,9 +198,9 @@ bool FloatEquals(float f1, float f2) {
template <typename T, typename U>
uint32_t CountOverlaps(const std::vector<T>& first_set,
const std::vector<U>& second_set) {
- // This method assumes vectors passed are sorted by |start_char_index|.
+ // This method assumes vectors passed are sorted by `start_char_index`.
uint32_t overlaps = 0;
- // Count overlaps between |first_set| and |second_set|.
+ // Count overlaps between `first_set` and `second_set`.
for (const auto& first_set_object : first_set) {
gfx::Range first_range(
first_set_object.start_char_index,
@@ -212,10 +212,10 @@ uint32_t CountOverlaps(const std::vector<T>& first_set,
if (first_range.Intersects(second_range)) {
overlaps++;
} else if (first_range.start() < second_range.start()) {
- // Both range vectors are sorted by |start_char_index|. In case they
- // don't overlap, and the |second_range| starts after the |first_range|,
- // then all successive |second_set_object| will not overlap with
- // |first_range|.
+ // Both range vectors are sorted by `start_char_index`. In case they
+ // don't overlap, and the `second_range` starts after the `first_range`,
+ // then all successive `second_set_object` will not overlap with
+ // `first_range`.
break;
}
}
@@ -226,7 +226,7 @@ uint32_t CountOverlaps(const std::vector<T>& first_set,
// Count overlaps within text annotations.
template <typename T>
uint32_t CountInternalTextOverlaps(const std::vector<T>& text_objects) {
- // This method assumes text_objects is sorted by |start_char_index|.
+ // This method assumes text_objects is sorted by `start_char_index`.
uint32_t overlaps = 0;
for (size_t i = 0; i < text_objects.size(); ++i) {
gfx::Range range1(
@@ -241,10 +241,10 @@ uint32_t CountInternalTextOverlaps(const std::vector<T>& text_objects) {
if (range1.Intersects(range2)) {
overlaps++;
} else {
- // The input is sorted by |start_char_index|. In case |range1| and
- // |range2| do not overlap, and |range2| starts after |range1|, then
+ // The input is sorted by `start_char_index`. In case `range1` and
+ // `range2` do not overlap, and `range2` starts after `range1`, then
// successive ranges in the inner loop will also not overlap with
- // |range1|.
+ // `range1`.
break;
}
}
@@ -443,21 +443,21 @@ void PDFiumPage::LogOverlappingAnnotations() {
overlap_count, 1, 100, 50);
}
-base::Optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
+absl::optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
int start_char_index) {
FPDF_PAGE page = GetPage();
FPDF_TEXTPAGE text_page = GetTextPage();
int chars_count = FPDFText_CountChars(text_page);
- // Check to make sure |start_char_index| is within bounds.
+ // Check to make sure `start_char_index` is within bounds.
if (start_char_index < 0 || start_char_index >= chars_count)
- return base::nullopt;
+ return absl::nullopt;
int actual_start_char_index = GetFirstNonUnicodeWhiteSpaceCharIndex(
text_page, start_char_index, chars_count);
// Check to see if GetFirstNonUnicodeWhiteSpaceCharIndex() iterated through
// all the characters.
if (actual_start_char_index >= chars_count) {
- // If so, |info.len| needs to take the number of characters
+ // If so, `info.len` needs to take the number of characters
// iterated into account.
DCHECK_GT(actual_start_char_index, start_char_index);
AccessibilityTextRunInfo info;
@@ -466,7 +466,7 @@ base::Optional<AccessibilityTextRunInfo> PDFiumPage::GetTextRunInfo(
}
// If the first character in a text run is a space, we need to start
- // |text_run_bounds| from the space character instead of the first
+ // `text_run_bounds` from the space character instead of the first
// non-space unicode character.
gfx::RectF text_run_bounds =
actual_start_char_index > start_char_index
@@ -874,8 +874,8 @@ PDFiumPage::Area PDFiumPage::GetDestinationTarget(FPDF_DEST destination,
target->page = page_index;
- base::Optional<float> x;
- base::Optional<float> y;
+ absl::optional<float> x;
+ absl::optional<float> y;
GetPageDestinationTarget(destination, &x, &y, &target->zoom);
if (x) {
@@ -889,12 +889,12 @@ PDFiumPage::Area PDFiumPage::GetDestinationTarget(FPDF_DEST destination,
}
void PDFiumPage::GetPageDestinationTarget(FPDF_DEST destination,
- base::Optional<float>* dest_x,
- base::Optional<float>* dest_y,
- base::Optional<float>* zoom_value) {
- *dest_x = base::nullopt;
- *dest_y = base::nullopt;
- *zoom_value = base::nullopt;
+ absl::optional<float>* dest_x,
+ absl::optional<float>* dest_y,
+ absl::optional<float>* zoom_value) {
+ *dest_x = absl::nullopt;
+ *dest_y = absl::nullopt;
+ *zoom_value = absl::nullopt;
if (!available_)
return;
@@ -1084,7 +1084,7 @@ void PDFiumPage::PopulateAnnotationLinks() {
int quad_point_count = FPDFLink_CountQuadPoints(link_annot);
// Calculate the bounds of link using the quad points data.
// If quad points for link is not present then use
- // |link_rect| to calculate the bounds instead.
+ // `link_rect` to calculate the bounds instead.
if (quad_point_count > 0) {
for (int i = 0; i < quad_point_count; ++i) {
FS_QUADPOINTSF point;
@@ -1143,7 +1143,7 @@ void PDFiumPage::CalculateImages() {
if (FPDFImageObj_GetImageMetadata(page_object, page, &image_metadata)) {
int marked_content_id = image_metadata.marked_content_id;
if (marked_content_id >= 0) {
- // If |marked_content_id| is already present, ignore the one being
+ // If `marked_content_id` is already present, ignore the one being
// inserted.
marked_content_id_image_map.insert(
{marked_content_id, images_.size()});
@@ -1513,7 +1513,7 @@ void PDFiumPage::RequestThumbnail(float device_pixel_ratio,
}
// It is safe to use base::Unretained(this) because the callback is only used
- // by |this|.
+ // by `this`.
thumbnail_callback_ = base::BindOnce(
&PDFiumPage::GenerateAndSendThumbnail, base::Unretained(this),
device_pixel_ratio, std::move(send_callback));
@@ -1537,8 +1537,8 @@ Thumbnail PDFiumPage::GenerateThumbnail(float device_pixel_ratio) {
sk_bitmap.width(), sk_bitmap.height(),
/*color=*/0xFFFFFFFF);
- // The combination of the |FPDF_REVERSE_BYTE_ORDER| rendering flag and the
- // |FPDFBitmap_BGRA| format when initializing |fpdf_bitmap| results in an RGBA
+ // The combination of the `FPDF_REVERSE_BYTE_ORDER` rendering flag and the
+ // `FPDFBitmap_BGRA` format when initializing `fpdf_bitmap` results in an RGBA
// rendering, which is the format required by HTML <canvas>.
FPDF_RenderPageBitmap(fpdf_bitmap.get(), GetPage(), /*start_x=*/0,
/*start_y=*/0, sk_bitmap.width(), sk_bitmap.height(),
diff --git a/chromium/pdf/pdfium/pdfium_page.h b/chromium/pdf/pdfium/pdfium_page.h
index 7be403a785c..c09b0c9a384 100644
--- a/chromium/pdf/pdfium/pdfium_page.h
+++ b/chromium/pdf/pdfium/pdfium_page.h
@@ -13,10 +13,10 @@
#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
-#include "base/optional.h"
#include "pdf/page_orientation.h"
#include "pdf/pdf_engine.h"
#include "ppapi/cpp/private/pdf.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/pdfium/public/cpp/fpdf_scopers.h"
#include "third_party/pdfium/public/fpdf_doc.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
@@ -60,7 +60,7 @@ class PDFiumPage {
// Log overlaps between annotations in the page.
void LogOverlappingAnnotations();
// See definition of PDFEngine::GetTextRunInfo().
- base::Optional<AccessibilityTextRunInfo> GetTextRunInfo(int start_char_index);
+ absl::optional<AccessibilityTextRunInfo> GetTextRunInfo(int start_char_index);
// Get a unicode character from the page.
uint32_t GetCharUnicode(int char_index);
// Get the bounds of a character in page pixels.
@@ -102,15 +102,15 @@ class PDFiumPage {
// Valid for DOCLINK_AREA only.
int page;
// Valid for DOCLINK_AREA only. From the top-left of the page.
- base::Optional<float> x_in_pixels;
- base::Optional<float> y_in_pixels;
+ absl::optional<float> x_in_pixels;
+ absl::optional<float> y_in_pixels;
// Valid for DOCLINK_AREA only.
- base::Optional<float> zoom;
+ absl::optional<float> zoom;
};
- // Given a |link_index|, returns the type of underlying area and the link
- // target. |target| must be valid. Returns NONSELECTABLE_AREA if
- // |link_index| is invalid.
+ // Given a `link_index`, returns the type of underlying area and the link
+ // target. `target` must be valid. Returns NONSELECTABLE_AREA if
+ // `link_index` is invalid.
Area GetLinkTargetAtIndex(int link_index, LinkTarget* target);
// Returns link type and fills target associated with a link. Returns
@@ -120,9 +120,9 @@ class PDFiumPage {
// Fills the output params with the in-page coordinates and the zoom value of
// the destination.
void GetPageDestinationTarget(FPDF_DEST destination,
- base::Optional<float>* dest_x,
- base::Optional<float>* dest_y,
- base::Optional<float>* zoom_value);
+ absl::optional<float>* dest_x,
+ absl::optional<float>* dest_y,
+ absl::optional<float>* zoom_value);
// For a named destination with "XYZ" view fit type, pre-processes the in-page
// x/y coordinate in case it's out of the range of the page dimension. Then
@@ -158,7 +158,7 @@ class PDFiumPage {
// Gets the number of characters in the page.
int GetCharCount();
- // Returns true if the given |char_index| lies within the character range
+ // Returns true if the given `char_index` lies within the character range
// of the page.
bool IsCharIndexInBounds(int char_index);
@@ -182,7 +182,7 @@ class PDFiumPage {
void RequestThumbnail(float device_pixel_ratio,
SendThumbnailCallback send_callback);
- // Generates a page thumbnail accommodating a specific |device_pixel_ratio|.
+ // Generates a page thumbnail accommodating a specific `device_pixel_ratio`.
Thumbnail GenerateThumbnail(float device_pixel_ratio);
int index() const { return index_; }
@@ -331,7 +331,7 @@ class PDFiumPage {
// Represents index of the control in the control group. A group of
// interactive form annotations is collectively called a form control
// group. Here an interactive form annotation should be either a radio
- // button or a checkbox. Value of |control_index| is -1 for push button.
+ // button or a checkbox. Value of `control_index` is -1 for push button.
int control_index = -1;
};
@@ -348,13 +348,13 @@ class PDFiumPage {
void CalculateImages();
// Populate annotations like highlight and text field on the page.
void PopulateAnnotations();
- // Populate |highlights_| with |annot|.
+ // Populate `highlights_` with `annot`.
void PopulateHighlight(FPDF_ANNOTATION annot);
- // Populate |text_fields_| with |annot|.
+ // Populate `text_fields_` with `annot`.
void PopulateTextField(FPDF_ANNOTATION annot);
- // Populate |choice_fields_| with |annot|.
+ // Populate `choice_fields_` with `annot`.
void PopulateChoiceField(FPDF_ANNOTATION annot);
- // Populate |buttons_| with |annot|.
+ // Populate `buttons_` with `annot`.
void PopulateButton(FPDF_ANNOTATION annot);
// Populate form fields like text field, choice field and button on the page.
void PopulateFormField(FPDF_ANNOTATION annot);
@@ -370,23 +370,23 @@ class PDFiumPage {
// Set text run style information based on a character of the text run.
void CalculateTextRunStyleInfo(int char_index,
AccessibilityTextStyleInfo& style_info);
- // Returns a boolean indicating if the character at index |char_index| has the
+ // Returns a boolean indicating if the character at index `char_index` has the
// same text style as the text run.
bool AreTextStyleEqual(int char_index,
const AccessibilityTextStyleInfo& style);
// Key : Marked content id for the image element as specified in the
// struct tree.
- // Value : Index of image in the |images_| vector.
+ // Value : Index of image in the `images_` vector.
using MarkedContentIdToImageMap = std::map<int, size_t>;
// Traverses the entire struct tree of the page recursively and extracts the
// alt text from struct tree elements corresponding to the marked content IDs
- // present in |marked_content_id_image_map|.
+ // present in `marked_content_id_image_map`.
void PopulateImageAltText(
const MarkedContentIdToImageMap& marked_content_id_image_map);
// Traverses a struct element and its sub-tree recursively and extracts the
// alt text from struct elements corresponding to the marked content IDs
- // present in |marked_content_id_image_map|. Uses |visited_elements| to guard
+ // present in `marked_content_id_image_map`. Uses `visited_elements` to guard
// against malformed struct trees.
void PopulateImageAltTextForStructElement(
const MarkedContentIdToImageMap& marked_content_id_image_map,
@@ -397,7 +397,7 @@ class PDFiumPage {
const std::vector<Highlight>& highlights);
bool PopulateFormFieldProperties(FPDF_ANNOTATION annot,
FormField* form_field);
- // Generates and sends the thumbnail using |send_callback|.
+ // Generates and sends the thumbnail using `send_callback`.
void GenerateAndSendThumbnail(float device_pixel_ratio,
SendThumbnailCallback send_callback);
diff --git a/chromium/pdf/pdfium/pdfium_page_unittest.cc b/chromium/pdf/pdfium/pdfium_page_unittest.cc
index 98a329d71e5..002c57a25c9 100644
--- a/chromium/pdf/pdfium/pdfium_page_unittest.cc
+++ b/chromium/pdf/pdfium/pdfium_page_unittest.cc
@@ -9,7 +9,6 @@
#include "base/check.h"
#include "base/files/file_path.h"
-#include "base/optional.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -24,6 +23,7 @@
#include "pdf/ui/thumbnail.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/pdfium/public/fpdf_formfill.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/rect.h"
@@ -268,7 +268,7 @@ TEST_F(PDFiumPageTextTest, TestTextRunBounds) {
constexpr int kFirstRunStartIndex = 0;
constexpr int kFirstRunEndIndex = 20;
constexpr int kPageIndex = 0;
- base::Optional<AccessibilityTextRunInfo> text_run_info_1 =
+ absl::optional<AccessibilityTextRunInfo> text_run_info_1 =
engine->GetTextRunInfo(kPageIndex, kFirstRunStartIndex);
ASSERT_TRUE(text_run_info_1.has_value());
@@ -304,7 +304,7 @@ TEST_F(PDFiumPageTextTest, TestTextRunBounds) {
// Test the properties of second text run.
// Note: The leading spaces in second text run are accounted for in the end
// of first text run. Hence we won't see a space leading the second text run.
- base::Optional<AccessibilityTextRunInfo> text_run_info_2 =
+ absl::optional<AccessibilityTextRunInfo> text_run_info_2 =
engine->GetTextRunInfo(kPageIndex, kSecondRunStartIndex);
ASSERT_TRUE(text_run_info_2.has_value());
@@ -385,7 +385,7 @@ TEST_F(PDFiumPageTextTest, GetTextRunInfo) {
}
// Test negative char index returns nullopt
- base::Optional<AccessibilityTextRunInfo> text_run_info_result =
+ absl::optional<AccessibilityTextRunInfo> text_run_info_result =
engine->GetTextRunInfo(0, -1);
ASSERT_FALSE(text_run_info_result.has_value());
@@ -439,7 +439,7 @@ TEST_F(PDFiumPageTextTest, TestHighlightTextRunInfo) {
int current_char_index = 0;
for (const auto& expected_text_run : expected_text_runs) {
- base::Optional<AccessibilityTextRunInfo> text_run_info_result =
+ absl::optional<AccessibilityTextRunInfo> text_run_info_result =
engine->GetTextRunInfo(0, current_char_index);
ASSERT_TRUE(text_run_info_result.has_value());
const auto& actual_text_run = text_run_info_result.value();
diff --git a/chromium/pdf/pdfium/pdfium_permissions.cc b/chromium/pdf/pdfium/pdfium_permissions.cc
index b24c6f42a58..b891553ee68 100644
--- a/chromium/pdf/pdfium/pdfium_permissions.cc
+++ b/chromium/pdf/pdfium/pdfium_permissions.cc
@@ -48,7 +48,7 @@ bool PDFiumPermissions::HasPermission(
}
} else {
// Security handler revision 3+ have different rules for interpreting the
- // bits in |permission_bits_|.
+ // bits in `permission_bits_`.
switch (permission) {
case PDFEngine::PERMISSION_COPY:
return (permission_bits_ & kPDFPermissionCopyMask) != 0;
diff --git a/chromium/pdf/pdfium/pdfium_print.cc b/chromium/pdf/pdfium/pdfium_print.cc
index f6df2b1c515..c0b3aefbc8c 100644
--- a/chromium/pdf/pdfium/pdfium_print.cc
+++ b/chromium/pdf/pdfium/pdfium_print.cc
@@ -39,7 +39,7 @@ namespace chrome_pdf {
namespace {
// UI should have done parameter sanity check, when execution
-// reaches here, |pages_per_sheet| should be a positive integer.
+// reaches here, `pages_per_sheet` should be a positive integer.
bool ShouldDoNup(int pages_per_sheet) {
return pages_per_sheet > 1;
}
@@ -52,10 +52,10 @@ int GetDocumentPageCount(FPDF_DOCUMENT doc) {
// Set the destination page size and content area in points based on source
// page rotation and orientation.
//
-// |rotated| True if source page is rotated 90 degree or 270 degree.
-// |is_src_page_landscape| is true if the source page orientation is landscape.
-// |page_size| has the actual destination page size in points.
-// |content_rect| has the actual destination page printable area values in
+// `rotated` True if source page is rotated 90 degree or 270 degree.
+// `is_src_page_landscape` is true if the source page orientation is landscape.
+// `page_size` has the actual destination page size in points.
+// `content_rect` has the actual destination page printable area values in
// points.
void SetPageSizeAndContentRect(bool rotated,
bool is_src_page_landscape,
@@ -72,7 +72,7 @@ void SetPageSizeAndContentRect(bool rotated,
}
}
-// Transform |page| contents to fit in the selected printer paper size.
+// Transform `page` contents to fit in the selected printer paper size.
void TransformPDFPageForPrinting(FPDF_PAGE page,
float scale_factor,
PP_PrintScalingOption_Dev scaling_option,
@@ -186,7 +186,7 @@ void FitContentsToPrintableAreaIfRequired(
}
// Takes the same parameters as PDFiumPrint::CreateNupPdf().
-// On success, returns the N-up version of |doc|. On failure, returns nullptr.
+// On success, returns the N-up version of `doc`. On failure, returns nullptr.
ScopedFPDFDocument CreateNupPdfDocument(ScopedFPDFDocument doc,
size_t pages_per_sheet,
const gfx::Size& page_size,
diff --git a/chromium/pdf/pdfium/pdfium_print.h b/chromium/pdf/pdfium/pdfium_print.h
index ab9f14454cd..990b12cabee 100644
--- a/chromium/pdf/pdfium/pdfium_print.h
+++ b/chromium/pdf/pdfium/pdfium_print.h
@@ -33,8 +33,8 @@ class PDFiumPrint {
~PDFiumPrint();
#if BUILDFLAG(IS_CHROMEOS_ASH)
- // Flattens the |doc|.
- // On success, returns the flattened version of |doc| as a vector.
+ // Flattens the `doc`.
+ // On success, returns the flattened version of `doc` as a vector.
// On failure, returns an empty vector.
static std::vector<uint8_t> CreateFlattenedPdf(ScopedFPDFDocument doc);
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
@@ -43,9 +43,9 @@ class PDFiumPrint {
const PP_PrintPageNumberRange_Dev* page_ranges,
uint32_t page_range_count);
- // Performs N-up PDF generation for |doc| based on |pages_per_sheet|,
- // |page_size|, and |printable_area|.
- // On success, returns the N-up version of |doc| as a vector.
+ // Performs N-up PDF generation for `doc` based on `pages_per_sheet`,
+ // `page_size`, and `printable_area`.
+ // On success, returns the N-up version of `doc` as a vector.
// On failure, returns an empty vector.
static std::vector<uint8_t> CreateNupPdf(ScopedFPDFDocument doc,
size_t pages_per_sheet,
diff --git a/chromium/pdf/pdfium/pdfium_print_unittest.cc b/chromium/pdf/pdfium/pdfium_print_unittest.cc
index 28f472f0fe6..9949bd9eae4 100644
--- a/chromium/pdf/pdfium/pdfium_print_unittest.cc
+++ b/chromium/pdf/pdfium/pdfium_print_unittest.cc
@@ -7,7 +7,6 @@
#include <memory>
#include "base/hash/md5.h"
-#include "base/optional.h"
#include "base/stl_util.h"
#include "pdf/pdfium/pdfium_engine.h"
#include "pdf/pdfium/pdfium_engine_exports.h"
@@ -18,6 +17,7 @@
#include "printing/pdf_render_settings.h"
#include "printing/units.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_f.h"
@@ -46,7 +46,7 @@ void CheckPdfDimensions(const std::vector<uint8_t>& pdf_data,
ASSERT_EQ(expected_dimensions.size(), static_cast<size_t>(page_count));
for (int i = 0; i < page_count; ++i) {
- base::Optional<gfx::SizeF> page_size =
+ absl::optional<gfx::SizeF> page_size =
exports.GetPDFPageSizeByIndex(pdf_data, i);
ASSERT_TRUE(page_size.has_value());
EXPECT_EQ(expected_dimensions[i], page_size.value());
diff --git a/chromium/pdf/pdfium/pdfium_test_base.h b/chromium/pdf/pdfium/pdfium_test_base.h
index 1a16e812233..fe46e0ddad3 100644
--- a/chromium/pdf/pdfium/pdfium_test_base.h
+++ b/chromium/pdf/pdfium/pdfium_test_base.h
@@ -50,8 +50,8 @@ class PDFiumTestBase : public testing::Test {
void SetUp() override;
void TearDown() override;
- // Initializes a PDFiumEngine for use in testing with |client|. Loads a PDF
- // named |pdf_name|. See TestDocumentLoader for more info about |pdf_name|.
+ // Initializes a PDFiumEngine for use in testing with `client`. Loads a PDF
+ // named `pdf_name`. See TestDocumentLoader for more info about `pdf_name`.
std::unique_ptr<PDFiumEngine> InitializeEngine(
TestClient* client,
const base::FilePath::CharType* pdf_name);
diff --git a/chromium/pdf/post_message_receiver.cc b/chromium/pdf/post_message_receiver.cc
index 6ea632030f3..1d78b7efb0b 100644
--- a/chromium/pdf/post_message_receiver.cc
+++ b/chromium/pdf/post_message_receiver.cc
@@ -5,9 +5,12 @@
#include "pdf/post_message_receiver.h"
#include <memory>
+#include <string>
#include <utility>
+#include <vector>
#include "base/bind.h"
+#include "base/check_op.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
@@ -15,7 +18,9 @@
#include "base/sequenced_task_runner.h"
#include "base/values.h"
#include "content/public/renderer/v8_value_converter.h"
+#include "gin/function_template.h"
#include "gin/handle.h"
+#include "gin/interceptor.h"
#include "gin/object_template_builder.h"
#include "gin/public/wrapper_info.h"
#include "gin/wrappable.h"
@@ -23,6 +28,12 @@
namespace chrome_pdf {
+namespace {
+
+constexpr char kPropertyName[] = "postMessage";
+
+} // namespace
+
// static
gin::WrapperInfo PostMessageReceiver::kWrapperInfo = {gin::kEmbedderNativeGin};
@@ -44,31 +55,65 @@ PostMessageReceiver::PostMessageReceiver(
v8::Isolate* isolate,
base::WeakPtr<Client> client,
scoped_refptr<base::SequencedTaskRunner> client_task_runner)
- : isolate_(isolate),
+ : gin::NamedPropertyInterceptor(isolate, this),
+ isolate_(isolate),
client_(std::move(client)),
client_task_runner_(std::move(client_task_runner)) {}
gin::ObjectTemplateBuilder PostMessageReceiver::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
- // The function template needs to be created with a repeating callback instead
- // of a member function pointer (MFP). Gin expects the first parameter for a
- // callback to a MFP to be the JavaScript `this` object corresponding to this
- // scriptable object exposed through Blink. However, the actual receiving
- // object for a plugins is a HTMLEmbedElement and Blink internally forwards
- // the parameters to this scriptable object.
+ // `gin::ObjectTemplateBuilder::SetMethod()` can't be used here because it
+ // would create a function template which expects the first parameter to a
+ // member function pointer to be the JavaScript `this` object corresponding
+ // to this scriptable object exposed through Blink. However, the actual
+ // receiving object for a plugin is an HTMLEmbedElement and Blink internally
+ // forwards the parameters to this scriptable object.
+ //
+ // Also, passing a callback would cause Gin to ignore the target. Because Gin
+ // creates the object template of a type only once per isolate, the member
+ // method of the first `PostMessageReceiver` instance would get effectively
+ // treated like a static method for all other instances.
//
- // `base::Unretained(this)` is safe to use because the callback will only be
- // called within the lifetime of the wrapped PostMessageReceiver object.
+ // An interceptor allows for the creation of a function template per instance.
return gin::Wrappable<PostMessageReceiver>::GetObjectTemplateBuilder(isolate)
- .SetMethod("postMessage",
- base::BindRepeating(&PostMessageReceiver::PostMessage,
- base::Unretained(this)));
+ .AddNamedPropertyInterceptor();
}
const char* PostMessageReceiver::GetTypeName() {
return "ChromePdfPostMessageReceiver";
}
+v8::Local<v8::Value> PostMessageReceiver::GetNamedProperty(
+ v8::Isolate* isolate,
+ const std::string& property) {
+ DCHECK_EQ(isolate_, isolate);
+
+ if (property != kPropertyName)
+ return v8::Local<v8::Value>();
+
+ return GetFunctionTemplate()
+ ->GetFunction(isolate->GetCurrentContext())
+ .ToLocalChecked();
+}
+
+std::vector<std::string> PostMessageReceiver::EnumerateNamedProperties(
+ v8::Isolate* isolate) {
+ DCHECK_EQ(isolate_, isolate);
+ return {kPropertyName};
+}
+
+v8::Local<v8::FunctionTemplate> PostMessageReceiver::GetFunctionTemplate() {
+ if (function_template_.IsEmpty()) {
+ function_template_.Reset(
+ isolate_,
+ gin::CreateFunctionTemplate(
+ isolate_, base::BindRepeating(&PostMessageReceiver::PostMessage,
+ weak_factory_.GetWeakPtr())));
+ }
+
+ return function_template_.Get(isolate_);
+}
+
std::unique_ptr<base::Value> PostMessageReceiver::ConvertMessage(
v8::Local<v8::Value> message) {
if (!v8_value_converter_)
diff --git a/chromium/pdf/post_message_receiver.h b/chromium/pdf/post_message_receiver.h
index ca4daebda6c..31b0407bf5c 100644
--- a/chromium/pdf/post_message_receiver.h
+++ b/chromium/pdf/post_message_receiver.h
@@ -9,6 +9,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
+#include "gin/interceptor.h"
#include "gin/public/wrapper_info.h"
#include "gin/wrappable.h"
#include "v8/include/v8.h"
@@ -33,7 +34,8 @@ namespace chrome_pdf {
// `PostMessageReceiver`'s lifetime is managed by the V8 garbage collector,
// meaning it can outlive the `Client`. Messages are dropped if the `Client` is
// destroyed.
-class PostMessageReceiver final : public gin::Wrappable<PostMessageReceiver> {
+class PostMessageReceiver final : public gin::Wrappable<PostMessageReceiver>,
+ public gin::NamedPropertyInterceptor {
public:
// The interface for a plugin client that handles messages from its embedder.
class Client {
@@ -72,6 +74,15 @@ class PostMessageReceiver final : public gin::Wrappable<PostMessageReceiver> {
v8::Isolate* isolate) override;
const char* GetTypeName() override;
+ // gin::NamedPropertyInterceptor:
+ v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate,
+ const std::string& property) override;
+ std::vector<std::string> EnumerateNamedProperties(
+ v8::Isolate* isolate) override;
+
+ // Lazily creates and retrieves `function_template_`.
+ v8::Local<v8::FunctionTemplate> GetFunctionTemplate();
+
// Converts `message` so it can be consumed by `client_`.
std::unique_ptr<base::Value> ConvertMessage(v8::Local<v8::Value> message);
@@ -80,11 +91,15 @@ class PostMessageReceiver final : public gin::Wrappable<PostMessageReceiver> {
std::unique_ptr<content::V8ValueConverter> v8_value_converter_;
+ v8::Persistent<v8::FunctionTemplate> function_template_;
+
v8::Isolate* isolate_;
base::WeakPtr<Client> client_;
scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
+
+ base::WeakPtrFactory<PostMessageReceiver> weak_factory_{this};
};
} // namespace chrome_pdf
diff --git a/chromium/pdf/ppapi_migration/graphics.cc b/chromium/pdf/ppapi_migration/graphics.cc
index 2be1b66531d..b641e055ed7 100644
--- a/chromium/pdf/ppapi_migration/graphics.cc
+++ b/chromium/pdf/ppapi_migration/graphics.cc
@@ -101,6 +101,9 @@ SkiaGraphics::SkiaGraphics(Client* client, const gfx::Size& size)
SkiaGraphics::~SkiaGraphics() = default;
+// TODO(https://crbug.com/1099020): After completely switching to non-Pepper
+// plugin, make Flush() return false since there is no pending action for
+// syncing the client's snapshot.
bool SkiaGraphics::Flush(ResultCallback callback) {
sk_sp<SkImage> snapshot = skia_graphics_->makeImageSnapshot();
skia_graphics_->getCanvas()->drawImage(
diff --git a/chromium/pdf/ppapi_migration/graphics.h b/chromium/pdf/ppapi_migration/graphics.h
index 6b1f95cf2e3..eafd1d2760b 100644
--- a/chromium/pdf/ppapi_migration/graphics.h
+++ b/chromium/pdf/ppapi_migration/graphics.h
@@ -41,11 +41,11 @@ class Graphics {
// `true` if the callback is still pending.
virtual bool Flush(ResultCallback callback) = 0;
- // Paints the |src_rect| region of |image| to the graphics device. The image
+ // Paints the `src_rect` region of `image` to the graphics device. The image
// must be compatible with the concrete `Graphics` implementation.
virtual void PaintImage(const Image& image, const gfx::Rect& src_rect) = 0;
- // Shifts the |clip| region of the graphics device by |amount|.
+ // Shifts the `clip` region of the graphics device by `amount`.
virtual void Scroll(const gfx::Rect& clip, const gfx::Vector2d& amount) = 0;
// Sets the output scale factor. Must be greater than 0.
diff --git a/chromium/pdf/ppapi_migration/graphics_unittest.cc b/chromium/pdf/ppapi_migration/graphics_unittest.cc
index 11029f85f79..2269534504b 100644
--- a/chromium/pdf/ppapi_migration/graphics_unittest.cc
+++ b/chromium/pdf/ppapi_migration/graphics_unittest.cc
@@ -7,12 +7,12 @@
#include <utility>
#include "base/callback_helpers.h"
-#include "base/test/task_environment.h"
#include "cc/test/pixel_comparator.h"
#include "cc/test/pixel_test_utils.h"
#include "pdf/ppapi_migration/bitmap.h"
#include "pdf/ppapi_migration/callback.h"
#include "pdf/ppapi_migration/image.h"
+#include "pdf/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
@@ -39,12 +39,6 @@ struct FakeSkiaGraphicsClient : public SkiaGraphics::Client {
sk_sp<SkImage> snapshot;
};
-Image CreateSourceImage(const SkISize& src_size) {
- SkBitmap bitmap = CreateN32PremulSkBitmap(src_size);
- bitmap.eraseColor(SK_ColorRED);
- return Image(bitmap);
-}
-
SkBitmap GenerateExpectedBitmap(const SkISize& graphics_size,
const SkIRect& rect) {
SkBitmap bitmap = CreateN32PremulSkBitmap(graphics_size);
@@ -71,7 +65,7 @@ SkBitmap CreateNonuniformBitmap(int width, int height) {
class SkiaGraphicsTest : public testing::Test {
protected:
void TestPaintImageResult(const SkISize& graphics_size,
- const SkISize& src_size,
+ const gfx::Size& src_size,
const gfx::Rect& paint_rect,
const SkIRect& overlapped_rect) {
graphics_ =
@@ -79,7 +73,8 @@ class SkiaGraphicsTest : public testing::Test {
ASSERT_TRUE(graphics_);
// Create snapshots as SkImage and SkBitmap after painting.
- graphics_->PaintImage(CreateSourceImage(src_size), paint_rect);
+ graphics_->PaintImage(CreateSkiaImageForTesting(src_size, SK_ColorRED),
+ paint_rect);
graphics_->Flush(base::DoNothing());
SkBitmap snapshot_bitmap;
ASSERT_TRUE(client_.snapshot->asLegacyBitmap(&snapshot_bitmap));
@@ -102,9 +97,6 @@ class SkiaGraphicsTest : public testing::Test {
FakeSkiaGraphicsClient client_;
std::unique_ptr<Graphics> graphics_;
-
- private:
- base::test::TaskEnvironment task_environment_;
};
class SkiaGraphicsScrollTest : public SkiaGraphicsTest {
@@ -163,7 +155,7 @@ TEST_F(SkiaGraphicsTest, PaintImage) {
SkISize graphics_size;
// Size of the source image.
- SkISize src_size;
+ gfx::Size src_size;
// Painting area.
gfx::Rect paint_rect;
diff --git a/chromium/pdf/ppapi_migration/input_event_conversions.cc b/chromium/pdf/ppapi_migration/input_event_conversions.cc
index 0a84ca07300..8ff8228c27e 100644
--- a/chromium/pdf/ppapi_migration/input_event_conversions.cc
+++ b/chromium/pdf/ppapi_migration/input_event_conversions.cc
@@ -2,221 +2,180 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "pdf/ppapi_migration/input_event_conversions.h"
+
#include <stdint.h>
-#include "pdf/ppapi_migration/input_event_conversions.h"
+#include <algorithm>
+#include <memory>
+#include "base/check_op.h"
#include "base/notreached.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/var.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
+#include "third_party/blink/public/common/input/web_keyboard_event.h"
+#include "third_party/blink/public/common/input/web_mouse_event.h"
+#include "third_party/blink/public/common/input/web_pointer_properties.h"
+#include "third_party/blink/public/common/input/web_touch_event.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
-#include "ui/gfx/geometry/point_conversions.h"
+
+namespace chrome_pdf {
namespace {
-chrome_pdf::InputEventType GetEventType(const PP_InputEvent_Type& input_type) {
- switch (input_type) {
+blink::WebInputEvent::Type GetWebInputEventType(PP_InputEvent_Type event_type) {
+ switch (event_type) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- return chrome_pdf::InputEventType::kMouseDown;
+ return blink::WebInputEvent::Type::kMouseDown;
case PP_INPUTEVENT_TYPE_MOUSEUP:
- return chrome_pdf::InputEventType::kMouseUp;
+ return blink::WebInputEvent::Type::kMouseUp;
case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- return chrome_pdf::InputEventType::kMouseMove;
+ return blink::WebInputEvent::Type::kMouseMove;
case PP_INPUTEVENT_TYPE_MOUSEENTER:
- return chrome_pdf::InputEventType::kMouseEnter;
+ return blink::WebInputEvent::Type::kMouseEnter;
case PP_INPUTEVENT_TYPE_MOUSELEAVE:
- return chrome_pdf::InputEventType::kMouseLeave;
+ return blink::WebInputEvent::Type::kMouseLeave;
case PP_INPUTEVENT_TYPE_WHEEL:
- return chrome_pdf::InputEventType::kWheel;
+ return blink::WebInputEvent::Type::kMouseWheel;
case PP_INPUTEVENT_TYPE_RAWKEYDOWN:
- return chrome_pdf::InputEventType::kRawKeyDown;
case PP_INPUTEVENT_TYPE_KEYDOWN:
- return chrome_pdf::InputEventType::kKeyDown;
+ // Blink no longer passes `kKeyDown` events into plugins, and instead
+ // passes `kRawKeyDown` events. However, `kRawKeyDown` gets mapped to
+ // `PP_INPUTEVENT_TYPE_KEYDOWN` for backwards compatibility. Map both
+ // Pepper enums to `kRawKeyDown` to allow for a common implementation
+ // between the Pepper and Pepper-free plugins.
+ // See the comments inside the definition of `ConvertEventTypes()` in
+ // content/renderer/pepper/event_conversion.cc.
+ return blink::WebInputEvent::Type::kRawKeyDown;
case PP_INPUTEVENT_TYPE_KEYUP:
- return chrome_pdf::InputEventType::kKeyUp;
+ return blink::WebInputEvent::Type::kKeyUp;
case PP_INPUTEVENT_TYPE_CHAR:
- return chrome_pdf::InputEventType::kChar;
+ return blink::WebInputEvent::Type::kChar;
case PP_INPUTEVENT_TYPE_CONTEXTMENU:
- return chrome_pdf::InputEventType::kContextMenu;
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START:
- return chrome_pdf::InputEventType::kImeCompositionStart;
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE:
- return chrome_pdf::InputEventType::kImeCompositionUpdate;
- case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END:
- return chrome_pdf::InputEventType::kImeCompositionEnd;
- case PP_INPUTEVENT_TYPE_IME_TEXT:
- return chrome_pdf::InputEventType::kImeText;
+ return blink::WebInputEvent::Type::kContextMenu;
case PP_INPUTEVENT_TYPE_TOUCHSTART:
- return chrome_pdf::InputEventType::kTouchStart;
+ return blink::WebInputEvent::Type::kTouchStart;
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
- return chrome_pdf::InputEventType::kTouchMove;
+ return blink::WebInputEvent::Type::kTouchMove;
case PP_INPUTEVENT_TYPE_TOUCHEND:
- return chrome_pdf::InputEventType::kTouchEnd;
+ return blink::WebInputEvent::Type::kTouchEnd;
case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
- return chrome_pdf::InputEventType::kTouchCancel;
+ return blink::WebInputEvent::Type::kTouchCancel;
default:
NOTREACHED();
- return chrome_pdf::InputEventType::kNone;
+ return blink::WebInputEvent::Type::kUndefined;
}
}
-chrome_pdf::InputEventMouseButtonType GetInputEventMouseButtonType(
- const PP_InputEvent_MouseButton& mouse_button_type) {
- switch (mouse_button_type) {
+blink::WebPointerProperties::Button GetWebPointerPropertiesButton(
+ const PP_InputEvent_MouseButton& button_type) {
+ switch (button_type) {
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
- return chrome_pdf::InputEventMouseButtonType::kLeft;
+ return blink::WebPointerProperties::Button::kLeft;
case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
- return chrome_pdf::InputEventMouseButtonType::kMiddle;
+ return blink::WebPointerProperties::Button::kMiddle;
case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
- return chrome_pdf::InputEventMouseButtonType::kRight;
+ return blink::WebPointerProperties::Button::kRight;
default:
- return chrome_pdf::InputEventMouseButtonType::kNone;
+ // No other mouse button type is handled by the PDF plugin.
+ return blink::WebPointerProperties::Button::kNoButton;
}
}
-bool IsKeyboardEventType(chrome_pdf::InputEventType event_type) {
- switch (event_type) {
- case chrome_pdf::InputEventType::kRawKeyDown:
- case chrome_pdf::InputEventType::kKeyDown:
- case chrome_pdf::InputEventType::kKeyUp:
- case chrome_pdf::InputEventType::kChar:
- return true;
- default:
- return false;
- }
-}
+std::unique_ptr<blink::WebMouseEvent> GetWebMouseEvent(
+ const pp::MouseInputEvent& event) {
+ const blink::WebInputEvent::Type type = GetWebInputEventType(event.GetType());
+ DCHECK(blink::WebInputEvent::IsMouseEventType(type));
+ DCHECK_NE(type, blink::WebInputEvent::Type::kContextMenu);
-bool IsMouseEventType(chrome_pdf::InputEventType event_type) {
- switch (event_type) {
- case chrome_pdf::InputEventType::kMouseDown:
- case chrome_pdf::InputEventType::kMouseUp:
- case chrome_pdf::InputEventType::kMouseMove:
- case chrome_pdf::InputEventType::kMouseEnter:
- case chrome_pdf::InputEventType::kMouseLeave:
- return true;
- default:
- return false;
- }
-}
+ auto mouse_event = std::make_unique<blink::WebMouseEvent>(
+ type, event.GetModifiers(),
+ base::TimeTicks() + base::TimeDelta::FromSecondsD(event.GetTimeStamp()));
-bool IsTouchEventType(chrome_pdf::InputEventType event_type) {
- switch (event_type) {
- case chrome_pdf::InputEventType::kTouchStart:
- case chrome_pdf::InputEventType::kTouchMove:
- case chrome_pdf::InputEventType::kTouchEnd:
- case chrome_pdf::InputEventType::kTouchCancel:
- return true;
- default:
- return false;
- }
-}
+ mouse_event->button = GetWebPointerPropertiesButton(event.GetButton());
+ mouse_event->click_count = event.GetClickCount();
-} // namespace
+ const pp::Point& position = event.GetPosition();
+ mouse_event->SetPositionInWidget(position.x(), position.y());
-namespace chrome_pdf {
-
-InputEvent::InputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers)
- : event_type_(event_type), time_stamp_(time_stamp), modifiers_(modifiers) {}
-
-InputEvent::InputEvent(const InputEvent& other) = default;
-
-InputEvent& InputEvent::operator=(const InputEvent& other) = default;
-
-InputEvent::~InputEvent() = default;
-
-KeyboardInputEvent::KeyboardInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers,
- uint32_t keyboard_code,
- const std::string& key_char)
- : InputEvent(event_type, time_stamp, modifiers),
- keyboard_code_(keyboard_code),
- key_char_(key_char) {
- DCHECK(IsKeyboardEventType(GetEventType()));
+ return mouse_event;
}
-KeyboardInputEvent::KeyboardInputEvent(const KeyboardInputEvent& other) =
- default;
-
-KeyboardInputEvent& KeyboardInputEvent::operator=(
- const KeyboardInputEvent& other) = default;
-
-KeyboardInputEvent::~KeyboardInputEvent() = default;
-
-MouseInputEvent::MouseInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers,
- InputEventMouseButtonType mouse_button_type,
- const gfx::Point& point,
- int32_t click_count,
- const gfx::Point& movement)
- : InputEvent(event_type, time_stamp, modifiers),
- mouse_button_type_(mouse_button_type),
- point_(point),
- click_count_(click_count),
- movement_(movement) {
- DCHECK(IsMouseEventType(GetEventType()));
-}
+std::unique_ptr<blink::WebKeyboardEvent> GetWebKeyboardEvent(
+ const pp::KeyboardInputEvent& event) {
+ const blink::WebInputEvent::Type type = GetWebInputEventType(event.GetType());
+ DCHECK(blink::WebInputEvent::IsKeyboardEventType(type));
-MouseInputEvent::MouseInputEvent(const MouseInputEvent& other) = default;
+ auto keyboard_event = std::make_unique<blink::WebKeyboardEvent>(
+ type, event.GetModifiers(),
+ base::TimeTicks() + base::TimeDelta::FromSecondsD(event.GetTimeStamp()));
-MouseInputEvent& MouseInputEvent::operator=(const MouseInputEvent& other) =
- default;
+ keyboard_event->windows_key_code = event.GetKeyCode();
-MouseInputEvent::~MouseInputEvent() = default;
+ const std::u16string text16 =
+ base::UTF8ToUTF16(event.GetCharacterText().AsString());
+ const size_t text_len =
+ std::min(blink::WebKeyboardEvent::kTextLengthCap, text16.size());
+ std::copy_n(text16.begin(), text_len, keyboard_event->text);
+ std::fill_n(keyboard_event->text + text_len,
+ blink::WebKeyboardEvent::kTextLengthCap - text_len, L'\0');
-TouchInputEvent::TouchInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers,
- const gfx::PointF& target_touch_point,
- int32_t touch_count)
- : InputEvent(event_type, time_stamp, modifiers),
- target_touch_point_(target_touch_point),
- touch_count_(touch_count) {
- DCHECK(IsTouchEventType(GetEventType()));
+ return keyboard_event;
}
-TouchInputEvent::TouchInputEvent(const TouchInputEvent& other) = default;
-
-TouchInputEvent& TouchInputEvent::operator=(const TouchInputEvent& other) =
- default;
-
-TouchInputEvent::~TouchInputEvent() = default;
-
-NoneInputEvent::NoneInputEvent()
- : InputEvent(InputEventType::kNone, 0, kInputEventModifierNone) {}
-
-NoneInputEvent::NoneInputEvent(const NoneInputEvent& other) = default;
-
-NoneInputEvent& NoneInputEvent::operator=(const NoneInputEvent& other) =
- default;
-
-NoneInputEvent::~NoneInputEvent() = default;
+std::unique_ptr<blink::WebTouchEvent> GetWebTouchEvent(
+ const pp::TouchInputEvent& event) {
+ const blink::WebInputEvent::Type type = GetWebInputEventType(event.GetType());
+ DCHECK(blink::WebInputEvent::IsTouchEventType(type));
+ DCHECK_NE(type, blink::WebInputEvent::Type::kTouchScrollStarted);
+
+ auto touch_event = std::make_unique<blink::WebTouchEvent>(
+ type, event.GetModifiers(),
+ base::TimeTicks() + base::TimeDelta::FromSecondsD(event.GetTimeStamp()));
+
+ // The PDF plugin only cares about the first touch and the number of touches,
+ // but copy over all the touches so that `touch_event->touches_length`
+ // accurately stores the length of `touches`.
+ touch_event->touches_length =
+ std::min<uint32_t>(blink::WebTouchEvent::kTouchesLengthCap,
+ event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES));
+ for (size_t i = 0; i < touch_event->touches_length; ++i) {
+ touch_event->touches[i].SetPositionInWidget(PointFFromPPFloatPoint(
+ event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, i).position()));
+ }
-KeyboardInputEvent GetKeyboardInputEvent(const pp::KeyboardInputEvent& event) {
- return KeyboardInputEvent(GetEventType(event.GetType()), event.GetTimeStamp(),
- event.GetModifiers(), event.GetKeyCode(),
- event.GetCharacterText().AsString());
+ return touch_event;
}
-MouseInputEvent GetMouseInputEvent(const pp::MouseInputEvent& event) {
- return MouseInputEvent(
- GetEventType(event.GetType()), event.GetTimeStamp(), event.GetModifiers(),
- GetInputEventMouseButtonType(event.GetButton()),
- PointFromPPPoint(event.GetPosition()), event.GetClickCount(),
- PointFromPPPoint(event.GetMovement()));
-}
+} // namespace
-TouchInputEvent GetTouchInputEvent(const pp::TouchInputEvent& event) {
- pp::FloatPoint point =
- event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
- return TouchInputEvent(GetEventType(event.GetType()), event.GetTimeStamp(),
- event.GetModifiers(), PointFFromPPFloatPoint(point),
- event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES));
+std::unique_ptr<blink::WebInputEvent> GetWebInputEvent(
+ const pp::InputEvent& event) {
+ switch (GetWebInputEventType(event.GetType())) {
+ case blink::WebInputEvent::Type::kMouseDown:
+ case blink::WebInputEvent::Type::kMouseUp:
+ case blink::WebInputEvent::Type::kMouseMove:
+ case blink::WebInputEvent::Type::kMouseEnter:
+ case blink::WebInputEvent::Type::kMouseLeave:
+ return GetWebMouseEvent(pp::MouseInputEvent(event));
+ case blink::WebInputEvent::Type::kRawKeyDown:
+ case blink::WebInputEvent::Type::kKeyUp:
+ case blink::WebInputEvent::Type::kChar:
+ return GetWebKeyboardEvent(pp::KeyboardInputEvent(event));
+ case blink::WebInputEvent::Type::kTouchStart:
+ case blink::WebInputEvent::Type::kTouchMove:
+ case blink::WebInputEvent::Type::kTouchEnd:
+ case blink::WebInputEvent::Type::kTouchCancel:
+ return GetWebTouchEvent(pp::TouchInputEvent(event));
+ default:
+ // Don't bother converting event types not handled by the PDF plugin.
+ return nullptr;
+ }
}
PP_CursorType_Dev PPCursorTypeFromCursorType(
diff --git a/chromium/pdf/ppapi_migration/input_event_conversions.h b/chromium/pdf/ppapi_migration/input_event_conversions.h
index a8b9065fe32..e5fcafdb146 100644
--- a/chromium/pdf/ppapi_migration/input_event_conversions.h
+++ b/chromium/pdf/ppapi_migration/input_event_conversions.h
@@ -6,225 +6,25 @@
#define PDF_PPAPI_MIGRATION_INPUT_EVENT_CONVERSIONS_H_
#include <stdint.h>
+
+#include <memory>
#include <string>
#include "ppapi/c/dev/pp_cursor_type_dev.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/point_f.h"
+
+namespace blink {
+class WebInputEvent;
+} // namespace blink
namespace pp {
-class KeyboardInputEvent;
-class MouseInputEvent;
-class TouchInputEvent;
+class InputEvent;
} // namespace pp
namespace chrome_pdf {
-enum InputEventModifier : uint32_t {
- // None represents no modifier key specified.
- kInputEventModifierNone = 0,
- kInputEventModifierShiftKey = 1 << 0,
- kInputEventModifierControlKey = 1 << 1,
- kInputEventModifierAltKey = 1 << 2,
- kInputEventModifierMetaKey = 1 << 3,
- kInputEventModifierIsKeyPad = 1 << 4,
- kInputEventModifierIsAutoRepeat = 1 << 5,
- kInputEventModifierLeftButtonDown = 1 << 6,
- kInputEventModifierMiddleButtonDown = 1 << 7,
- kInputEventModifierRightButtonDown = 1 << 8,
- kInputEventModifierCapsLockKey = 1 << 9,
- kInputEventModifierNumLockKey = 1 << 10,
- kInputEventModifierIsLeft = 1 << 11,
- kInputEventModifierIsRight = 1 << 12,
- kInputEventModifierIsPen = 1 << 13,
- kInputEventModifierIsEraser = 1 << 14
-};
-
-enum class InputEventType {
- kNone,
-
- // Notification that a mouse button was pressed.
- kMouseDown,
-
- // Notification that a mouse button was released.
- kMouseUp,
-
- // Notification that a mouse button was moved when it is over the instance
- // or dragged out of it.
- kMouseMove,
-
- // Notification that the mouse entered the pdf view's bounds.
- kMouseEnter,
-
- // Notification that a mouse left the pdf view's bounds.
- kMouseLeave,
-
- // Notification that the scroll wheel was used.
- kWheel,
-
- // Notification that a key transitioned from "up" to "down".
- kRawKeyDown,
-
- // Notification that a key was pressed. This does not necessarily correspond
- // to a character depending on the key and language. Use the
- // kChar for character input.
- kKeyDown,
-
- // Notification that a key was released.
- kKeyUp,
-
- // Notification that a character was typed. Use this for text input. Key
- // down events may generate 0, 1, or more than one character event depending
- // on the key, locale, and operating system.
- kChar,
-
- kContextMenu,
-
- // Notification that an input method composition process has just started.
- kImeCompositionStart,
-
- // Notification that the input method composition string is updated.
- kImeCompositionUpdate,
-
- // Notification that an input method composition process has completed.
- kImeCompositionEnd,
-
- // Notification that an input method committed a string.
- kImeText,
-
- // Notification that a finger was placed on a touch-enabled device.
- kTouchStart,
-
- // Notification that a finger was moved on a touch-enabled device.
- kTouchMove,
-
- // Notification that a finger was released on a touch-enabled device.
- kTouchEnd,
-
- // Notification that a touch event was canceled.
- kTouchCancel
-};
-
-enum class InputEventMouseButtonType {
- kNone = 0,
- kLeft,
- kMiddle,
- kRight,
-};
-
-class InputEvent {
- public:
- InputEventType GetEventType() const { return event_type_; }
-
- double GetTimeStamp() const { return time_stamp_; }
-
- uint32_t GetModifiers() const { return modifiers_; }
-
- protected:
- // Base class is not intended to be instantiated directly. Use
- // `NoneInputEvent` to get an event of type `InputEventType::kNone`.
- InputEvent(InputEventType event_type, double time_stamp, uint32_t modifiers);
- InputEvent(const InputEvent& other);
- InputEvent& operator=(const InputEvent& other);
- ~InputEvent();
-
- private:
- InputEventType event_type_;
- // The units are in seconds, but are not measured relative to any particular
- // epoch, so the most you can do is compare two values.
- double time_stamp_;
- uint32_t modifiers_;
-};
-
-class KeyboardInputEvent : public InputEvent {
- public:
- KeyboardInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers,
- uint32_t keyboard_code,
- const std::string& key_char);
- KeyboardInputEvent(const KeyboardInputEvent& other);
- KeyboardInputEvent& operator=(const KeyboardInputEvent& other);
- ~KeyboardInputEvent();
-
- uint32_t GetKeyCode() const { return keyboard_code_; }
-
- const std::string& GetKeyChar() const { return key_char_; }
-
- private:
- uint32_t keyboard_code_;
- std::string key_char_;
-};
-
-class MouseInputEvent : public InputEvent {
- public:
- MouseInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifier,
- InputEventMouseButtonType mouse_button_type,
- const gfx::Point& point,
- int32_t click_count,
- const gfx::Point& movement);
- MouseInputEvent(const MouseInputEvent& other);
- MouseInputEvent& operator=(const MouseInputEvent& other);
- ~MouseInputEvent();
-
- const InputEventMouseButtonType& GetButton() const {
- return mouse_button_type_;
- }
-
- const gfx::Point& GetPosition() const { return point_; }
-
- int32_t GetClickCount() const { return click_count_; }
-
- const gfx::Point& GetMovement() const { return movement_; }
-
- private:
- InputEventMouseButtonType mouse_button_type_;
- gfx::Point point_;
- int32_t click_count_ = 0;
- gfx::Point movement_;
-};
-
-class TouchInputEvent : public InputEvent {
- public:
- TouchInputEvent(InputEventType event_type,
- double time_stamp,
- uint32_t modifiers,
- const gfx::PointF& target_touch_point,
- int32_t touch_count);
- TouchInputEvent(const TouchInputEvent& other);
- TouchInputEvent& operator=(const TouchInputEvent& other);
- ~TouchInputEvent();
-
- // `pp::TouchInputEvent` exposes a collection of target touch points. We can
- // get all the points by passing the index of the point in the collection.
- // However, with `chrome_pdf::TouchEvent` the number of target touch points
- // are restricted to the first point. This is because PDFiumeEngine at present
- // is dependent on only the first target touch point.
- const gfx::PointF& GetTargetTouchPoint() const { return target_touch_point_; }
-
- int32_t GetTouchCount() const { return touch_count_; }
-
- private:
- gfx::PointF target_touch_point_;
- int32_t touch_count_ = 0;
-};
-
-class NoneInputEvent : public InputEvent {
- public:
- NoneInputEvent();
- NoneInputEvent(const NoneInputEvent& other);
- NoneInputEvent& operator=(const NoneInputEvent& other);
- ~NoneInputEvent();
-};
-
-KeyboardInputEvent GetKeyboardInputEvent(const pp::KeyboardInputEvent& event);
-
-MouseInputEvent GetMouseInputEvent(const pp::MouseInputEvent& event);
-
-TouchInputEvent GetTouchInputEvent(const pp::TouchInputEvent& event);
+std::unique_ptr<blink::WebInputEvent> GetWebInputEvent(
+ const pp::InputEvent& event);
PP_CursorType_Dev PPCursorTypeFromCursorType(ui::mojom::CursorType cursor_type);
diff --git a/chromium/pdf/ppapi_migration/ppapi_assert_matching_enums.cc b/chromium/pdf/ppapi_migration/ppapi_assert_matching_enums.cc
new file mode 100644
index 00000000000..f57beff3228
--- /dev/null
+++ b/chromium/pdf/ppapi_migration/ppapi_assert_matching_enums.cc
@@ -0,0 +1,106 @@
+// Copyright 2021 The Chromium 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 "pdf/accessibility_structs.h"
+#include "pdf/content_restriction.h"
+#include "ppapi/c/private/ppb_pdf.h"
+#include "ppapi/c/private/ppp_pdf.h"
+
+namespace chrome_pdf {
+
+#define STATIC_ASSERT_ENUM(a, b) \
+ static_assert(static_cast<int>(a) == static_cast<int>(b), \
+ "mismatching enums: " #a)
+
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kUnknown,
+ PP_TEXTRENDERINGMODE_UNKNOWN);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kFill,
+ PP_TEXTRENDERINGMODE_FILL);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kStroke,
+ PP_TEXTRENDERINGMODE_STROKE);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kFillStroke,
+ PP_TEXTRENDERINGMODE_FILLSTROKE);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kInvisible,
+ PP_TEXTRENDERINGMODE_INVISIBLE);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kFillClip,
+ PP_TEXTRENDERINGMODE_FILLCLIP);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kStrokeClip,
+ PP_TEXTRENDERINGMODE_STROKECLIP);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kFillStrokeClip,
+ PP_TEXTRENDERINGMODE_FILLSTROKECLIP);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kClip,
+ PP_TEXTRENDERINGMODE_CLIP);
+STATIC_ASSERT_ENUM(AccessibilityTextRenderMode::kMaxValue,
+ PP_TEXTRENDERINGMODE_LAST);
+
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kNone, PP_PRIVATEDIRECTION_NONE);
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kLeftToRight,
+ PP_PRIVATEDIRECTION_LTR);
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kRightToLeft,
+ PP_PRIVATEDIRECTION_RTL);
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kTopToBottom,
+ PP_PRIVATEDIRECTION_TTB);
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kBottomToTop,
+ PP_PRIVATEDIRECTION_BTT);
+STATIC_ASSERT_ENUM(AccessibilityTextDirection::kMaxValue,
+ PP_PRIVATEDIRECTION_LAST);
+
+STATIC_ASSERT_ENUM(ChoiceFieldType::kListBox, PP_PRIVATECHOICEFIELD_LISTBOX);
+STATIC_ASSERT_ENUM(ChoiceFieldType::kComboBox, PP_PRIVATECHOICEFIELD_COMBOBOX);
+STATIC_ASSERT_ENUM(ChoiceFieldType::kMaxValue, PP_PRIVATECHOICEFIELD_LAST);
+
+STATIC_ASSERT_ENUM(ButtonType::kPushButton, PP_PRIVATEBUTTON_PUSHBUTTON);
+STATIC_ASSERT_ENUM(ButtonType::kPushButton, PP_PRIVATEBUTTON_FIRST);
+STATIC_ASSERT_ENUM(ButtonType::kCheckBox, PP_PRIVATEBUTTON_CHECKBOX);
+STATIC_ASSERT_ENUM(ButtonType::kRadioButton, PP_PRIVATEBUTTON_RADIOBUTTON);
+STATIC_ASSERT_ENUM(ButtonType::kMaxValue, PP_PRIVATEBUTTON_LAST);
+
+STATIC_ASSERT_ENUM(FocusObjectType::kNone, PP_PRIVATEFOCUSOBJECT_NONE);
+STATIC_ASSERT_ENUM(FocusObjectType::kDocument, PP_PRIVATEFOCUSOBJECT_DOCUMENT);
+STATIC_ASSERT_ENUM(FocusObjectType::kLink, PP_PRIVATEFOCUSOBJECT_LINK);
+STATIC_ASSERT_ENUM(FocusObjectType::kHighlight,
+ PP_PRIVATEFOCUSOBJECT_HIGHLIGHT);
+STATIC_ASSERT_ENUM(FocusObjectType::kTextField,
+ PP_PRIVATEFOCUSOBJECT_TEXT_FIELD);
+STATIC_ASSERT_ENUM(FocusObjectType::kMaxValue, PP_PRIVATEFOCUSOBJECT_LAST);
+
+STATIC_ASSERT_ENUM(AccessibilityAction::kNone, PP_PDF_ACTION_NONE);
+STATIC_ASSERT_ENUM(AccessibilityAction::kScrollToMakeVisible,
+ PP_PDF_SCROLL_TO_MAKE_VISIBLE);
+STATIC_ASSERT_ENUM(AccessibilityAction::kDoDefaultAction,
+ PP_PDF_DO_DEFAULT_ACTION);
+STATIC_ASSERT_ENUM(AccessibilityAction::kScrollToGlobalPoint,
+ PP_PDF_SCROLL_TO_GLOBAL_POINT);
+STATIC_ASSERT_ENUM(AccessibilityAction::kSetSelection, PP_PDF_SET_SELECTION);
+STATIC_ASSERT_ENUM(AccessibilityAction::kMaxValue,
+ PP_PDF_ACCESSIBILITYACTION_LAST);
+
+STATIC_ASSERT_ENUM(AccessibilityAnnotationType::kNone, PP_PDF_TYPE_NONE);
+STATIC_ASSERT_ENUM(AccessibilityAnnotationType::kLink, PP_PDF_LINK);
+STATIC_ASSERT_ENUM(AccessibilityAnnotationType::kMaxValue,
+ PP_PDF_ACCESSIBILITY_ANNOTATIONTYPE_LAST);
+
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kNone, PP_PDF_SCROLL_NONE);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kCenter,
+ PP_PDF_SCROLL_ALIGNMENT_CENTER);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kTop,
+ PP_PDF_SCROLL_ALIGNMENT_TOP);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kBottom,
+ PP_PDF_SCROLL_ALIGNMENT_BOTTOM);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kLeft,
+ PP_PDF_SCROLL_ALIGNMENT_LEFT);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kRight,
+ PP_PDF_SCROLL_ALIGNMENT_RIGHT);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kClosestToEdge,
+ PP_PDF_SCROLL_ALIGNMENT_CLOSEST_EDGE);
+STATIC_ASSERT_ENUM(AccessibilityScrollAlignment::kMaxValue,
+ PP_PDF_ACCESSIBILITYSCROLLALIGNMENT_LAST);
+
+STATIC_ASSERT_ENUM(kContentRestrictionCopy, PP_CONTENT_RESTRICTION_COPY);
+STATIC_ASSERT_ENUM(kContentRestrictionCut, PP_CONTENT_RESTRICTION_CUT);
+STATIC_ASSERT_ENUM(kContentRestrictionPaste, PP_CONTENT_RESTRICTION_PASTE);
+STATIC_ASSERT_ENUM(kContentRestrictionPrint, PP_CONTENT_RESTRICTION_PRINT);
+STATIC_ASSERT_ENUM(kContentRestrictionSave, PP_CONTENT_RESTRICTION_SAVE);
+
+} // namespace chrome_pdf
diff --git a/chromium/pdf/ppapi_migration/value_conversions.cc b/chromium/pdf/ppapi_migration/value_conversions.cc
index c0b894eadf2..60bb8bac8f7 100644
--- a/chromium/pdf/ppapi_migration/value_conversions.cc
+++ b/chromium/pdf/ppapi_migration/value_conversions.cc
@@ -50,10 +50,6 @@ pp::Var VarFromValue(const base::Value& value) {
}
return var_array;
}
- // TODO(crbug.com/859477): Remove after root cause is found.
- case base::Value::Type::DEAD:
- CHECK(false);
- return pp::Var();
}
}
diff --git a/chromium/pdf/ui/document_properties.cc b/chromium/pdf/ui/document_properties.cc
index 87f7f83af45..2727c6b6ebb 100644
--- a/chromium/pdf/ui/document_properties.cc
+++ b/chromium/pdf/ui/document_properties.cc
@@ -8,11 +8,11 @@
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
-#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "components/strings/grit/components_strings.h"
#include "pdf/document_metadata.h"
#include "printing/units.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/size.h"
@@ -71,7 +71,7 @@ bool ShowInches() {
} // namespace
-std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points) {
+std::u16string FormatPageSize(const absl::optional<gfx::Size>& size_points) {
if (!size_points.has_value())
return l10n_util::GetStringUTF16(IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE);
diff --git a/chromium/pdf/ui/document_properties.h b/chromium/pdf/ui/document_properties.h
index 33bc17687c9..e8c99adbb68 100644
--- a/chromium/pdf/ui/document_properties.h
+++ b/chromium/pdf/ui/document_properties.h
@@ -7,8 +7,8 @@
#include <string>
-#include "base/optional.h"
#include "pdf/document_metadata.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace gfx {
class Size;
@@ -23,8 +23,8 @@ namespace chrome_pdf {
// -> 210 x 297 mm (portrait)
// -> 11.00 x 8.50 in (landscape)
//
-// Returns the string "Varies" if `size_points` is `base::nullopt`.
-std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points);
+// Returns the string "Varies" if `size_points` is `absl::nullopt`.
+std::u16string FormatPageSize(const absl::optional<gfx::Size>& size_points);
// Formats `version` to a string suitable for display to a user. Version numbers
// do not require localization.
diff --git a/chromium/pdf/ui/document_properties_unittest.cc b/chromium/pdf/ui/document_properties_unittest.cc
index 173eff54790..90562863594 100644
--- a/chromium/pdf/ui/document_properties_unittest.cc
+++ b/chromium/pdf/ui/document_properties_unittest.cc
@@ -8,11 +8,11 @@
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
-#include "base/optional.h"
#include "components/strings/grit/components_strings.h"
#include "pdf/document_metadata.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/resource/mock_resource_bundle_delegate.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/size.h"
@@ -89,7 +89,7 @@ class FormatPageSizeTest : public testing::Test {
} // namespace
TEST_F(FormatPageSizeTest, NoUniformSize) {
- EXPECT_EQ(FormatPageSize(base::nullopt), u"Varies");
+ EXPECT_EQ(FormatPageSize(absl::nullopt), u"Varies");
}
class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
diff --git a/chromium/pdf/ui/thumbnail.cc b/chromium/pdf/ui/thumbnail.cc
index 11d82d527c7..780c9c1b579 100644
--- a/chromium/pdf/ui/thumbnail.cc
+++ b/chromium/pdf/ui/thumbnail.cc
@@ -59,8 +59,8 @@ gfx::Size LimitAspectRatio(gfx::Size page_size) {
return page_size;
}
-// Calculate the size of a thumbnail image in device pixels using |page_size| in
-// any units and |device_pixel_ratio|.
+// Calculate the size of a thumbnail image in device pixels using `page_size` in
+// any units and `device_pixel_ratio`.
gfx::Size CalculateBestFitSize(const gfx::Size& page_size,
float device_pixel_ratio) {
gfx::Size safe_page_size = LimitAspectRatio(page_size);
diff --git a/chromium/pdf/url_loader_wrapper.h b/chromium/pdf/url_loader_wrapper.h
index 58cc94ab4ec..c2f21fce350 100644
--- a/chromium/pdf/url_loader_wrapper.h
+++ b/chromium/pdf/url_loader_wrapper.h
@@ -38,8 +38,8 @@ class URLLoaderWrapper {
// Returns if the response contains multi parts.
virtual bool IsMultipart() const = 0;
- // If true, |start| contains the start of the byte range.
- // If false, response contains full document and |start| will be undefined.
+ // If true, `start` contains the start of the byte range.
+ // If false, response contains full document and `start` will be undefined.
virtual bool GetByteRangeStart(int* start) const = 0;
// Close connection.