0

Migrate painting code in pdf/ to gfx:: types

Updates painting classes (PaintAggregator, PaintManager,
PaintReadyRect) to use gfx:: geometry types, instead of pp:: geometry
types. Also updated OutOfProcessInstance and related code that uses the
painting classes.

Beyond renaming from the pp:: to the equivalent gfx:: types, some
special cases needed to be handled:

1. In some cases, a member function of a pp:: or gfx:: type mutated in
   place, while the corresponding member function did not. These cases
   required extra care to find an equivalent replacement.

2. pp::Point was replaced with gfx::Point or gfx::Vector2d, depending on
   usage. pp::Point does not distinguish between these two cases.

In all the remaining cases, the pp:: and gfx:: types behave the same.

Bug: 1099020, 1101101
Change-Id: Ia899e57a728b6a517d7739f10f59825ffe75dfdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305594
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790570}
This commit is contained in:
K. Moon
2020-07-21 21:46:03 +00:00
committed by Commit Bot
parent e5f839075d
commit 30466c9ddb
12 changed files with 182 additions and 133 deletions

@ -32,6 +32,7 @@
#include "pdf/document_metadata.h" #include "pdf/document_metadata.h"
#include "pdf/pdf_features.h" #include "pdf/pdf_features.h"
#include "pdf/ppapi_migration/bitmap.h" #include "pdf/ppapi_migration/bitmap.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_pdf.h"
@ -55,6 +56,9 @@
#include "ppapi/cpp/var_dictionary.h" #include "ppapi/cpp/var_dictionary.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/point_f.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 "url/gurl.h" #include "url/gurl.h"
namespace chrome_pdf { namespace chrome_pdf {
@ -667,13 +671,14 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
plugin_dip_size_ = view_rect.size(); plugin_dip_size_ = view_rect.size();
plugin_size_ = view_device_size; plugin_size_ = view_device_size;
paint_manager_.SetSize(view_device_size, device_scale_); paint_manager_.SetSize(SizeFromPPSize(view_device_size), device_scale_);
pp::Size new_image_data_size = const gfx::Size old_image_data_size = SizeFromPPSize(image_data_.size());
PaintManager::GetNewContextSize(image_data_.size(), plugin_size_); gfx::Size new_image_data_size = PaintManager::GetNewContextSize(
if (new_image_data_size != image_data_.size()) { old_image_data_size, SizeFromPPSize(plugin_size_));
if (new_image_data_size != old_image_data_size) {
image_data_ = pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, image_data_ = pp::ImageData(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
new_image_data_size, false); PPSizeFromSize(new_image_data_size), false);
skia_image_data_ = skia_image_data_ =
SkBitmapFromPPImageData(std::make_unique<pp::ImageData>(image_data_)); SkBitmapFromPPImageData(std::make_unique<pp::ImageData>(image_data_));
first_paint_ = true; first_paint_ = true;
@ -950,17 +955,18 @@ void OutOfProcessInstance::StopFind() {
SetTickmarks(tickmarks_); SetTickmarks(tickmarks_);
} }
pp::Graphics2D OutOfProcessInstance::CreatePaintGraphics(const pp::Size& size) { pp::Graphics2D OutOfProcessInstance::CreatePaintGraphics(
return pp::Graphics2D(this, size, /*is_always_opaque=*/true); const gfx::Size& size) {
return pp::Graphics2D(this, PPSizeFromSize(size), /*is_always_opaque=*/true);
} }
bool OutOfProcessInstance::BindPaintGraphics(pp::Graphics2D& graphics) { bool OutOfProcessInstance::BindPaintGraphics(pp::Graphics2D& graphics) {
return BindGraphics(graphics); return BindGraphics(graphics);
} }
void OutOfProcessInstance::OnPaint(const std::vector<pp::Rect>& paint_rects, void OutOfProcessInstance::OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready, std::vector<PaintReadyRect>* ready,
std::vector<pp::Rect>* pending) { std::vector<gfx::Rect>* pending) {
base::AutoReset<bool> auto_reset_in_paint(&in_paint_, true); base::AutoReset<bool> auto_reset_in_paint(&in_paint_, true);
if (image_data_.is_null()) { if (image_data_.is_null()) {
DCHECK(plugin_size_.IsEmpty()); DCHECK(plugin_size_.IsEmpty());
@ -981,7 +987,8 @@ void OutOfProcessInstance::OnPaint(const std::vector<pp::Rect>& paint_rects,
for (const auto& paint_rect : paint_rects) { for (const auto& paint_rect : paint_rects) {
// Intersect with plugin area since there could be pending invalidates from // Intersect with plugin area since there could be pending invalidates from
// when the plugin area was larger. // when the plugin area was larger.
pp::Rect rect = paint_rect.Intersect(pp::Rect(pp::Point(), plugin_size_)); pp::Rect rect = PPRectFromRect(paint_rect);
rect = rect.Intersect(pp::Rect(pp::Point(), plugin_size_));
if (rect.IsEmpty()) if (rect.IsEmpty())
continue; continue;
@ -998,7 +1005,7 @@ void OutOfProcessInstance::OnPaint(const std::vector<pp::Rect>& paint_rects,
} }
for (auto& pending_rect : pdf_pending) { for (auto& pending_rect : pdf_pending) {
pending_rect.Offset(available_area_.point()); pending_rect.Offset(available_area_.point());
pending->push_back(pending_rect); pending->push_back(RectFromPPRect(pending_rect));
} }
} }
@ -1124,12 +1131,12 @@ void OutOfProcessInstance::Invalidate(const pp::Rect& rect) {
pp::Rect offset_rect(rect); pp::Rect offset_rect(rect);
offset_rect.Offset(available_area_.point()); offset_rect.Offset(available_area_.point());
paint_manager_.InvalidateRect(offset_rect); paint_manager_.InvalidateRect(RectFromPPRect(offset_rect));
} }
void OutOfProcessInstance::DidScroll(const pp::Point& point) { void OutOfProcessInstance::DidScroll(const gfx::Vector2d& offset) {
if (!image_data_.is_null()) if (!image_data_.is_null())
paint_manager_.ScrollRect(available_area_, point); paint_manager_.ScrollRect(RectFromPPRect(available_area_), offset);
} }
void OutOfProcessInstance::ScrollToX(int x_in_screen_coords) { void OutOfProcessInstance::ScrollToX(int x_in_screen_coords) {
@ -1652,7 +1659,7 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage(
engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool()); engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
engine_->New(url_.c_str(), /*headers=*/nullptr); engine_->New(url_.c_str(), /*headers=*/nullptr);
paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); paint_manager_.InvalidateRect(gfx::Rect(SizeFromPPSize(plugin_size_)));
} }
void OutOfProcessInstance::HandleSaveMessage(const pp::VarDictionary& dict) { void OutOfProcessInstance::HandleSaveMessage(const pp::VarDictionary& dict) {
@ -1746,41 +1753,41 @@ void OutOfProcessInstance::HandleViewportMessage(
dict.Get(pp::Var(kJSPinchY)).AsDouble()); dict.Get(pp::Var(kJSPinchY)).AsDouble());
// Pinch vector is the panning caused due to change in pinch // Pinch vector is the panning caused due to change in pinch
// center between start and end of the gesture. // center between start and end of the gesture.
pp::Point pinch_vector = gfx::Vector2d pinch_vector =
pp::Point(dict.Get(kJSPinchVectorX).AsDouble() * zoom_ratio, gfx::Vector2d(dict.Get(kJSPinchVectorX).AsDouble() * zoom_ratio,
dict.Get(kJSPinchVectorY).AsDouble() * zoom_ratio); dict.Get(kJSPinchVectorY).AsDouble() * zoom_ratio);
pp::Point scroll_delta; gfx::Vector2d scroll_delta;
// If the rendered document doesn't fill the display area we will // If the rendered document doesn't fill the display area we will
// use |paint_offset| to anchor the paint vertically into the same place. // use |paint_offset| to anchor the paint vertically into the same place.
// We use the scroll bars instead of the pinch vector to get the actual // We use the scroll bars instead of the pinch vector to get the actual
// position on screen of the paint. // position on screen of the paint.
pp::Point paint_offset; gfx::Vector2d paint_offset;
if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_ratio) { if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_ratio) {
// We want to keep the paint in the middle but it must stay in the same // We want to keep the paint in the middle but it must stay in the same
// position relative to the scroll bars. // position relative to the scroll bars.
paint_offset = pp::Point(0, (1 - zoom_ratio) * pinch_center.y()); paint_offset = gfx::Vector2d(0, (1 - zoom_ratio) * pinch_center.y());
scroll_delta = pp::Point( scroll_delta = gfx::Vector2d(
0, 0,
(scroll_offset.y() - scroll_offset_at_last_raster_.y() * zoom_ratio)); (scroll_offset.y() - scroll_offset_at_last_raster_.y() * zoom_ratio));
pinch_vector = pp::Point(); pinch_vector = gfx::Vector2d();
last_bitmap_smaller_ = true; last_bitmap_smaller_ = true;
} else if (last_bitmap_smaller_) { } else if (last_bitmap_smaller_) {
pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2, pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2,
(plugin_size_.height() / device_scale_) / 2); (plugin_size_.height() / device_scale_) / 2);
const double zoom_when_doc_covers_plugin_width = const double zoom_when_doc_covers_plugin_width =
zoom_ * plugin_size_.width() / GetDocumentPixelWidth(); zoom_ * plugin_size_.width() / GetDocumentPixelWidth();
paint_offset = pp::Point( paint_offset = gfx::Vector2d(
(1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(), (1 - zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(),
(1 - zoom_ratio) * pinch_center.y()); (1 - zoom_ratio) * pinch_center.y());
pinch_vector = pp::Point(); pinch_vector = gfx::Vector2d();
scroll_delta = pp::Point( scroll_delta = gfx::Vector2d(
(scroll_offset.x() - scroll_offset_at_last_raster_.x() * zoom_ratio), (scroll_offset.x() - scroll_offset_at_last_raster_.x() * zoom_ratio),
(scroll_offset.y() - scroll_offset_at_last_raster_.y() * zoom_ratio)); (scroll_offset.y() - scroll_offset_at_last_raster_.y() * zoom_ratio));
} }
paint_manager_.SetTransform(zoom_ratio, pinch_center, paint_manager_.SetTransform(zoom_ratio, PointFromPPPoint(pinch_center),
pinch_vector + paint_offset + scroll_delta, pinch_vector + paint_offset + scroll_delta,
true); true);
needs_reraster_ = false; needs_reraster_ = false;
@ -1840,7 +1847,7 @@ void OutOfProcessInstance::DocumentLoadFailed() {
} }
document_load_state_ = LOAD_STATE_FAILED; document_load_state_ = LOAD_STATE_FAILED;
paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); paint_manager_.InvalidateRect(gfx::Rect(SizeFromPPSize(plugin_size_)));
// Send a progress value of -1 to indicate a failure. // Send a progress value of -1 to indicate a failure.
SendLoadingProgress(-1); SendLoadingProgress(-1);
@ -1949,7 +1956,7 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
if (document_size_.IsEmpty()) if (document_size_.IsEmpty())
return; return;
paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); paint_manager_.InvalidateRect(gfx::Rect(SizeFromPPSize(plugin_size_)));
if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED)
SendAccessibilityViewportInfo(); SendAccessibilityViewportInfo();

@ -29,11 +29,17 @@
#include "ppapi/utility/completion_callback_factory.h" #include "ppapi/utility/completion_callback_factory.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace gfx {
class Rect;
class Size;
class Vector2d;
} // namespace gfx
namespace pp { namespace pp {
class Graphics2D; class Graphics2D;
class Size; class Size;
class TextInput_Dev; class TextInput_Dev;
} } // namespace pp
namespace chrome_pdf { namespace chrome_pdf {
@ -62,11 +68,11 @@ class OutOfProcessInstance : public pp::Instance,
void StopFind() override; void StopFind() override;
// pp::PaintManager::Client implementation. // pp::PaintManager::Client implementation.
pp::Graphics2D CreatePaintGraphics(const pp::Size& size) override; pp::Graphics2D CreatePaintGraphics(const gfx::Size& size) override;
bool BindPaintGraphics(pp::Graphics2D& graphics) override; bool BindPaintGraphics(pp::Graphics2D& graphics) override;
void OnPaint(const std::vector<pp::Rect>& paint_rects, void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready, std::vector<PaintReadyRect>* ready,
std::vector<pp::Rect>* pending) override; std::vector<gfx::Rect>* pending) override;
// pp::Printing_Dev implementation. // pp::Printing_Dev implementation.
uint32_t QuerySupportedPrintOutputFormats() override; uint32_t QuerySupportedPrintOutputFormats() override;
@ -103,7 +109,7 @@ class OutOfProcessInstance : public pp::Instance,
// PDFEngine::Client implementation. // PDFEngine::Client implementation.
void ProposeDocumentLayout(const DocumentLayout& layout) override; void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const pp::Rect& rect) override; void Invalidate(const pp::Rect& rect) override;
void DidScroll(const pp::Point& point) override; void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override; void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override; void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
void ScrollBy(const pp::Point& point) override; void ScrollBy(const pp::Point& point) override;

@ -7,9 +7,10 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <algorithm>
#include "base/check.h" #include "base/check.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chrome_pdf { namespace chrome_pdf {
@ -47,11 +48,11 @@ PaintAggregator::InternalPaintUpdate::InternalPaintUpdate()
PaintAggregator::InternalPaintUpdate::~InternalPaintUpdate() = default; PaintAggregator::InternalPaintUpdate::~InternalPaintUpdate() = default;
pp::Rect PaintAggregator::InternalPaintUpdate::GetScrollDamage() const { gfx::Rect PaintAggregator::InternalPaintUpdate::GetScrollDamage() const {
// Should only be scrolling in one direction at a time. // Should only be scrolling in one direction at a time.
DCHECK(!(scroll_delta.x() && scroll_delta.y())); DCHECK(!(scroll_delta.x() && scroll_delta.y()));
pp::Rect damaged_rect; gfx::Rect damaged_rect;
// Compute the region we will expose by scrolling, and paint that into a // Compute the region we will expose by scrolling, and paint that into a
// shared memory section. // shared memory section.
@ -80,7 +81,7 @@ pp::Rect PaintAggregator::InternalPaintUpdate::GetScrollDamage() const {
} }
// In case the scroll offset exceeds the width/height of the scroll rect // In case the scroll offset exceeds the width/height of the scroll rect
return scroll_rect.Intersect(damaged_rect); return gfx::IntersectRects(scroll_rect, damaged_rect);
} }
PaintAggregator::PaintAggregator() = default; PaintAggregator::PaintAggregator() = default;
@ -106,7 +107,7 @@ PaintAggregator::PaintUpdate PaintAggregator::GetPendingUpdate() {
// rects in the next block. // rects in the next block.
if (ret.has_scroll && !update_.synthesized_scroll_damage_rect_) { if (ret.has_scroll && !update_.synthesized_scroll_damage_rect_) {
update_.synthesized_scroll_damage_rect_ = true; update_.synthesized_scroll_damage_rect_ = true;
pp::Rect scroll_damage = update_.GetScrollDamage(); gfx::Rect scroll_damage = update_.GetScrollDamage();
InvalidateRectInternal(scroll_damage, false); InvalidateRectInternal(scroll_damage, false);
} }
@ -119,7 +120,7 @@ PaintAggregator::PaintUpdate PaintAggregator::GetPendingUpdate() {
void PaintAggregator::SetIntermediateResults( void PaintAggregator::SetIntermediateResults(
const std::vector<PaintReadyRect>& ready, const std::vector<PaintReadyRect>& ready,
const std::vector<pp::Rect>& pending) { const std::vector<gfx::Rect>& pending) {
update_.ready_rects.insert(update_.ready_rects.end(), ready.begin(), update_.ready_rects.insert(update_.ready_rects.end(), ready.begin(),
ready.end()); ready.end());
update_.paint_rects = pending; update_.paint_rects = pending;
@ -129,12 +130,12 @@ std::vector<PaintReadyRect> PaintAggregator::GetReadyRects() const {
return update_.ready_rects; return update_.ready_rects;
} }
void PaintAggregator::InvalidateRect(const pp::Rect& rect) { void PaintAggregator::InvalidateRect(const gfx::Rect& rect) {
InvalidateRectInternal(rect, true); InvalidateRectInternal(rect, true);
} }
void PaintAggregator::ScrollRect(const pp::Rect& clip_rect, void PaintAggregator::ScrollRect(const gfx::Rect& clip_rect,
const pp::Point& amount) { const gfx::Vector2d& amount) {
// We only support scrolling along one axis at a time. // We only support scrolling along one axis at a time.
if (amount.x() != 0 && amount.y() != 0) { if (amount.x() != 0 && amount.y() != 0) {
InvalidateRect(clip_rect); InvalidateRect(clip_rect);
@ -180,8 +181,8 @@ void PaintAggregator::ScrollRect(const pp::Rect& clip_rect,
update_.scroll_delta += amount; update_.scroll_delta += amount;
// We might have just wiped out a pre-existing scroll. // We might have just wiped out a pre-existing scroll.
if (update_.scroll_delta == pp::Point()) { if (update_.scroll_delta == gfx::Vector2d()) {
update_.scroll_rect = pp::Rect(); update_.scroll_rect = gfx::Rect();
return; return;
} }
@ -189,22 +190,22 @@ void PaintAggregator::ScrollRect(const pp::Rect& clip_rect,
// paint that is inside the scroll area, move it by the scroll amount and // paint that is inside the scroll area, move it by the scroll amount and
// replace the existing paint with it. For the portion (if any) that is // replace the existing paint with it. For the portion (if any) that is
// outside the scroll, just invalidate it. // outside the scroll, just invalidate it.
std::vector<pp::Rect> leftover_rects; std::vector<gfx::Rect> leftover_rects;
for (size_t i = 0; i < update_.paint_rects.size(); ++i) { for (size_t i = 0; i < update_.paint_rects.size(); ++i) {
if (!update_.scroll_rect.Intersects(update_.paint_rects[i])) if (!update_.scroll_rect.Intersects(update_.paint_rects[i]))
continue; continue;
pp::Rect intersection = gfx::Rect intersection =
update_.paint_rects[i].Intersect(update_.scroll_rect); gfx::IntersectRects(update_.paint_rects[i], update_.scroll_rect);
pp::Rect rect = update_.paint_rects[i]; gfx::Rect rect = update_.paint_rects[i];
while (!rect.IsEmpty()) { while (!rect.IsEmpty()) {
pp::Rect leftover = rect.Subtract(intersection); gfx::Rect leftover = gfx::SubtractRects(rect, intersection);
if (leftover.IsEmpty()) if (leftover.IsEmpty())
break; break;
// Don't want to call InvalidateRectInternal now since it'll modify // Don't want to call InvalidateRectInternal now since it'll modify
// update_.paint_rects, so keep track of this and do it below. // update_.paint_rects, so keep track of this and do it below.
leftover_rects.push_back(leftover); leftover_rects.push_back(leftover);
rect = rect.Subtract(leftover); rect.Subtract(leftover);
} }
update_.paint_rects[i] = ScrollPaintRect(intersection, amount); update_.paint_rects[i] = ScrollPaintRect(intersection, amount);
@ -225,35 +226,33 @@ void PaintAggregator::ScrollRect(const pp::Rect& clip_rect,
} }
if (update_.synthesized_scroll_damage_rect_) { if (update_.synthesized_scroll_damage_rect_) {
pp::Rect damage = update_.GetScrollDamage(); InvalidateRect(update_.GetScrollDamage());
InvalidateRect(damage);
} }
} }
pp::Rect PaintAggregator::ScrollPaintRect(const pp::Rect& paint_rect, gfx::Rect PaintAggregator::ScrollPaintRect(const gfx::Rect& paint_rect,
const pp::Point& amount) const { const gfx::Vector2d& amount) const {
pp::Rect result = paint_rect; gfx::Rect result = paint_rect + amount;
result.Offset(amount); result.Intersect(update_.scroll_rect);
result = update_.scroll_rect.Intersect(result);
return result; return result;
} }
void PaintAggregator::InvalidateScrollRect() { void PaintAggregator::InvalidateScrollRect() {
pp::Rect scroll_rect = update_.scroll_rect; gfx::Rect scroll_rect = update_.scroll_rect;
update_.scroll_rect = pp::Rect(); update_.scroll_rect = gfx::Rect();
update_.scroll_delta = pp::Point(); update_.scroll_delta = gfx::Vector2d();
InvalidateRect(scroll_rect); InvalidateRect(scroll_rect);
} }
void PaintAggregator::InvalidateRectInternal(const pp::Rect& rect_old, void PaintAggregator::InvalidateRectInternal(const gfx::Rect& rect_old,
bool check_scroll) { bool check_scroll) {
pp::Rect rect = rect_old; gfx::Rect rect = rect_old;
// Check if any rects that are ready to be painted overlap. // Check if any rects that are ready to be painted overlap.
for (size_t i = 0; i < update_.ready_rects.size(); ++i) { for (size_t i = 0; i < update_.ready_rects.size(); ++i) {
const pp::Rect& existing_rect = update_.ready_rects[i].rect; const gfx::Rect& existing_rect = update_.ready_rects[i].rect;
if (rect.Intersects(existing_rect)) { if (rect.Intersects(existing_rect)) {
// Re-invalidate in case the union intersects other paint rects. // Re-invalidate in case the union intersects other paint rects.
rect = existing_rect.Union(rect); rect.Union(existing_rect);
update_.ready_rects.erase(update_.ready_rects.begin() + i); update_.ready_rects.erase(update_.ready_rects.begin() + i);
break; break;
} }
@ -263,12 +262,12 @@ void PaintAggregator::InvalidateRectInternal(const pp::Rect& rect_old,
// Combine overlapping paints using smallest bounding box. // Combine overlapping paints using smallest bounding box.
for (size_t i = 0; i < update_.paint_rects.size(); ++i) { for (size_t i = 0; i < update_.paint_rects.size(); ++i) {
const pp::Rect& existing_rect = update_.paint_rects[i]; const gfx::Rect& existing_rect = update_.paint_rects[i];
if (existing_rect.Contains(rect)) // Optimize out redundancy. if (existing_rect.Contains(rect)) // Optimize out redundancy.
add_paint = false; add_paint = false;
if (rect.Intersects(existing_rect) || rect.SharesEdgeWith(existing_rect)) { if (rect.Intersects(existing_rect) || rect.SharesEdgeWith(existing_rect)) {
// Re-invalidate in case the union intersects other paint rects. // Re-invalidate in case the union intersects other paint rects.
pp::Rect combined_rect = existing_rect.Union(rect); gfx::Rect combined_rect = gfx::UnionRects(rect, existing_rect);
update_.paint_rects.erase(update_.paint_rects.begin() + i); update_.paint_rects.erase(update_.paint_rects.begin() + i);
InvalidateRectInternal(combined_rect, check_scroll); InvalidateRectInternal(combined_rect, check_scroll);
add_paint = false; add_paint = false;

@ -8,7 +8,8 @@
#include <vector> #include <vector>
#include "pdf/paint_ready_rect.h" #include "pdf/paint_ready_rect.h"
#include "ppapi/cpp/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chrome_pdf { namespace chrome_pdf {
@ -36,18 +37,18 @@ class PaintAggregator {
// region instead). // region instead).
// //
// If there is no scroll, this will be (0, 0). // If there is no scroll, this will be (0, 0).
pp::Point scroll_delta; gfx::Vector2d scroll_delta;
// The rectangle that should be scrolled by the scroll_delta. If there is no // The rectangle that should be scrolled by the scroll_delta. If there is no
// scroll, this will be (0, 0, 0, 0). We only track one scroll command at // scroll, this will be (0, 0, 0, 0). We only track one scroll command at
// once. If there are multiple ones, they will be converted to invalidates. // once. If there are multiple ones, they will be converted to invalidates.
pp::Rect scroll_rect; gfx::Rect scroll_rect;
// A list of all the individual dirty rectangles. This is an aggregated list // A list of all the individual dirty rectangles. This is an aggregated list
// of all invalidate calls. Different rectangles may be unified to produce a // of all invalidate calls. Different rectangles may be unified to produce a
// minimal list with no overlap that is more efficient to paint. This list // minimal list with no overlap that is more efficient to paint. This list
// also contains the region exposed by any scroll command. // also contains the region exposed by any scroll command.
std::vector<pp::Rect> paint_rects; std::vector<gfx::Rect> paint_rects;
}; };
PaintAggregator(); PaintAggregator();
@ -63,16 +64,16 @@ class PaintAggregator {
// are finished painting (ready), and ones that are still in-progress // are finished painting (ready), and ones that are still in-progress
// (pending). // (pending).
void SetIntermediateResults(const std::vector<PaintReadyRect>& ready, void SetIntermediateResults(const std::vector<PaintReadyRect>& ready,
const std::vector<pp::Rect>& pending); const std::vector<gfx::Rect>& pending);
// Returns the rectangles that are ready to be painted. // Returns the rectangles that are ready to be painted.
std::vector<PaintReadyRect> GetReadyRects() const; std::vector<PaintReadyRect> GetReadyRects() const;
// The given rect should be repainted. // The given rect should be repainted.
void InvalidateRect(const pp::Rect& rect); void InvalidateRect(const gfx::Rect& rect);
// The given rect should be scrolled by the given amounts. // The given rect should be scrolled by the given amounts.
void ScrollRect(const pp::Rect& clip_rect, const pp::Point& amount); void ScrollRect(const gfx::Rect& clip_rect, const gfx::Vector2d& amount);
private: private:
// This structure is an internal version of PaintUpdate. It's different in // This structure is an internal version of PaintUpdate. It's different in
@ -92,14 +93,14 @@ class PaintAggregator {
// Computes the rect damaged by scrolling within |scroll_rect| by // Computes the rect damaged by scrolling within |scroll_rect| by
// |scroll_delta|. This rect must be repainted. It is not included in // |scroll_delta|. This rect must be repainted. It is not included in
// paint_rects. // paint_rects.
pp::Rect GetScrollDamage() const; gfx::Rect GetScrollDamage() const;
pp::Point scroll_delta; gfx::Vector2d scroll_delta;
pp::Rect scroll_rect; gfx::Rect scroll_rect;
// Does not include the scroll damage rect unless // Does not include the scroll damage rect unless
// synthesized_scroll_damage_rect_ is set. // synthesized_scroll_damage_rect_ is set.
std::vector<pp::Rect> paint_rects; std::vector<gfx::Rect> paint_rects;
// Rectangles that are finished painting. // Rectangles that are finished painting.
std::vector<PaintReadyRect> ready_rects; std::vector<PaintReadyRect> ready_rects;
@ -108,14 +109,14 @@ class PaintAggregator {
bool synthesized_scroll_damage_rect_; bool synthesized_scroll_damage_rect_;
}; };
pp::Rect ScrollPaintRect(const pp::Rect& paint_rect, gfx::Rect ScrollPaintRect(const gfx::Rect& paint_rect,
const pp::Point& amount) const; const gfx::Vector2d& amount) const;
void InvalidateScrollRect(); void InvalidateScrollRect();
// Internal method used by InvalidateRect. If |check_scroll| is true, then the // 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| // method checks if there's a pending scroll and if so also invalidates |rect|
// in the new scroll position. // in the new scroll position.
void InvalidateRectInternal(const pp::Rect& rect, bool check_scroll); void InvalidateRectInternal(const gfx::Rect& rect, bool check_scroll);
InternalPaintUpdate update_; InternalPaintUpdate update_;
}; };

@ -12,11 +12,28 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "pdf/paint_ready_rect.h" #include "pdf/paint_ready_rect.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/module.h" #include "ppapi/cpp/module.h"
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/rect.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
namespace chrome_pdf { namespace chrome_pdf {
namespace {
// Not part of ppapi_migration because `gfx::Vector2d` only needs to be
// converted to `pp::Point` at the boundary with `pp::Graphics2D`.
pp::Point ToPepperPoint(const gfx::Vector2d& vector) {
return pp::Point(vector.x(), vector.y());
}
} // namespace
PaintManager::PaintManager(Client* client) : client_(client) { PaintManager::PaintManager(Client* client) : client_(client) {
DCHECK(client_); DCHECK(client_);
@ -28,20 +45,20 @@ PaintManager::PaintManager(Client* client) : client_(client) {
PaintManager::~PaintManager() = default; PaintManager::~PaintManager() = default;
// static // static
pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, gfx::Size PaintManager::GetNewContextSize(const gfx::Size& current_context_size,
const pp::Size& plugin_size) { const gfx::Size& plugin_size) {
// The amount of additional space in pixels to allocate to the right/bottom of // The amount of additional space in pixels to allocate to the right/bottom of
// the context. // the context.
constexpr int kBufferSize = 50; constexpr int kBufferSize = 50;
// Default to returning the same size. // Default to returning the same size.
pp::Size result = current_context_size; gfx::Size result = current_context_size;
// The minimum size of the plugin before resizing the context to ensure we // The minimum size of the plugin before resizing the context to ensure we
// aren't wasting too much memory. We deduct twice the kBufferSize from the // aren't wasting too much memory. We deduct twice the kBufferSize from the
// current context size which gives a threshhold that is kBufferSize below // current context size which gives a threshhold that is kBufferSize below
// the plugin size when the context size was last computed. // the plugin size when the context size was last computed.
pp::Size min_size( gfx::Size min_size(
std::max(current_context_size.width() - 2 * kBufferSize, 0), std::max(current_context_size.width() - 2 * kBufferSize, 0),
std::max(current_context_size.height() - 2 * kBufferSize, 0)); std::max(current_context_size.height() - 2 * kBufferSize, 0));
@ -55,14 +72,14 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
plugin_size.height() < min_size.height()) { plugin_size.height() < min_size.height()) {
// Create a larger context than needed so that if we only resize by a // Create a larger context than needed so that if we only resize by a
// small margin, we don't need a new context. // small margin, we don't need a new context.
result = pp::Size(plugin_size.width() + kBufferSize, result = gfx::Size(plugin_size.width() + kBufferSize,
plugin_size.height() + kBufferSize); plugin_size.height() + kBufferSize);
} }
return result; return result;
} }
void PaintManager::SetSize(const pp::Size& new_size, float device_scale) { void PaintManager::SetSize(const gfx::Size& new_size, float device_scale) {
if (GetEffectiveSize() == new_size && if (GetEffectiveSize() == new_size &&
GetEffectiveDeviceScale() == device_scale) { GetEffectiveDeviceScale() == device_scale) {
return; return;
@ -78,13 +95,14 @@ void PaintManager::SetSize(const pp::Size& new_size, float device_scale) {
} }
void PaintManager::SetTransform(float scale, void PaintManager::SetTransform(float scale,
const pp::Point& origin, const gfx::Point& origin,
const pp::Point& translate, const gfx::Vector2d& translate,
bool schedule_flush) { bool schedule_flush) {
if (graphics_.is_null()) if (graphics_.is_null())
return; return;
graphics_.SetLayerTransform(scale, origin, translate); graphics_.SetLayerTransform(scale, PPPointFromPoint(origin),
ToPepperPoint(translate));
if (!schedule_flush) if (!schedule_flush)
return; return;
@ -97,7 +115,7 @@ void PaintManager::SetTransform(float scale,
} }
void PaintManager::ClearTransform() { void PaintManager::ClearTransform() {
SetTransform(1.f, pp::Point(), pp::Point(), false); SetTransform(1.f, gfx::Point(), gfx::Vector2d(), false);
} }
void PaintManager::Invalidate() { void PaintManager::Invalidate() {
@ -105,17 +123,18 @@ void PaintManager::Invalidate() {
return; return;
EnsureCallbackPending(); EnsureCallbackPending();
aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize())); aggregator_.InvalidateRect(gfx::Rect(GetEffectiveSize()));
} }
void PaintManager::InvalidateRect(const pp::Rect& rect) { void PaintManager::InvalidateRect(const gfx::Rect& rect) {
DCHECK(!in_paint_); DCHECK(!in_paint_);
if (graphics_.is_null() && !has_pending_resize_) if (graphics_.is_null() && !has_pending_resize_)
return; return;
// Clip the rect to the device area. // Clip the rect to the device area.
pp::Rect clipped_rect = rect.Intersect(pp::Rect(GetEffectiveSize())); gfx::Rect clipped_rect =
gfx::IntersectRects(rect, gfx::Rect(GetEffectiveSize()));
if (clipped_rect.IsEmpty()) if (clipped_rect.IsEmpty())
return; // Nothing to do. return; // Nothing to do.
@ -123,8 +142,8 @@ void PaintManager::InvalidateRect(const pp::Rect& rect) {
aggregator_.InvalidateRect(clipped_rect); aggregator_.InvalidateRect(clipped_rect);
} }
void PaintManager::ScrollRect(const pp::Rect& clip_rect, void PaintManager::ScrollRect(const gfx::Rect& clip_rect,
const pp::Point& amount) { const gfx::Vector2d& amount) {
DCHECK(!in_paint_); DCHECK(!in_paint_);
if (graphics_.is_null() && !has_pending_resize_) if (graphics_.is_null() && !has_pending_resize_)
@ -135,7 +154,7 @@ void PaintManager::ScrollRect(const pp::Rect& clip_rect,
aggregator_.ScrollRect(clip_rect, amount); aggregator_.ScrollRect(clip_rect, amount);
} }
pp::Size PaintManager::GetEffectiveSize() const { gfx::Size PaintManager::GetEffectiveSize() const {
return has_pending_resize_ ? pending_size_ : plugin_size_; return has_pending_resize_ ? pending_size_ : plugin_size_;
} }
@ -165,7 +184,7 @@ void PaintManager::DoPaint() {
base::AutoReset<bool> auto_reset_in_paint(&in_paint_, true); base::AutoReset<bool> auto_reset_in_paint(&in_paint_, true);
std::vector<PaintReadyRect> ready_rects; std::vector<PaintReadyRect> ready_rects;
std::vector<pp::Rect> pending_rects; std::vector<gfx::Rect> pending_rects;
DCHECK(aggregator_.HasPendingUpdate()); DCHECK(aggregator_.HasPendingUpdate());
@ -176,11 +195,14 @@ void PaintManager::DoPaint() {
// do this later. // do this later.
if (has_pending_resize_) { if (has_pending_resize_) {
plugin_size_ = pending_size_; plugin_size_ = pending_size_;
// Extra call to pp_size() required here because the operator for converting
// to PP_Size is non-const.
const gfx::Size old_size = SizeFromPPSize(graphics_.size().pp_size());
// Only create a new graphics context if the current context isn't big // Only create a new graphics context if the current context isn't big
// enough or if it is far too big. This avoids creating a new context if // enough or if it is far too big. This avoids creating a new context if
// we only resize by a small amount. // we only resize by a small amount.
pp::Size new_size = GetNewContextSize(graphics_.size(), pending_size_); gfx::Size new_size = GetNewContextSize(old_size, pending_size_);
if (graphics_.size() != new_size) { if (old_size != new_size) {
graphics_ = client_->CreatePaintGraphics(new_size); graphics_ = client_->CreatePaintGraphics(new_size);
graphics_need_to_be_bound_ = true; graphics_need_to_be_bound_ = true;
@ -197,7 +219,7 @@ void PaintManager::DoPaint() {
// This must be cleared before calling into the plugin since it may do // This must be cleared before calling into the plugin since it may do
// additional invalidation or sizing operations. // additional invalidation or sizing operations.
has_pending_resize_ = false; has_pending_resize_ = false;
pending_size_ = pp::Size(); pending_size_ = gfx::Size();
} }
PaintAggregator::PaintUpdate update = aggregator_.GetPendingUpdate(); PaintAggregator::PaintUpdate update = aggregator_.GetPendingUpdate();
@ -208,15 +230,15 @@ void PaintManager::DoPaint() {
std::vector<PaintReadyRect> ready_now; std::vector<PaintReadyRect> ready_now;
if (pending_rects.empty()) { if (pending_rects.empty()) {
std::vector<PaintReadyRect> temp_ready; aggregator_.SetIntermediateResults(ready_rects, pending_rects);
temp_ready.insert(temp_ready.end(), ready_rects.begin(), ready_rects.end());
aggregator_.SetIntermediateResults(temp_ready, pending_rects);
ready_now = aggregator_.GetReadyRects(); ready_now = aggregator_.GetReadyRects();
aggregator_.ClearPendingUpdate(); aggregator_.ClearPendingUpdate();
// Apply any scroll first. // Apply any scroll first.
if (update.has_scroll) if (update.has_scroll) {
graphics_.Scroll(update.scroll_rect, update.scroll_delta); graphics_.Scroll(PPRectFromRect(update.scroll_rect),
ToPepperPoint(update.scroll_delta));
}
view_size_changed_waiting_for_paint_ = false; view_size_changed_waiting_for_paint_ = false;
} else { } else {
@ -246,7 +268,7 @@ void PaintManager::DoPaint() {
for (const auto& ready_rect : ready_now) { for (const auto& ready_rect : ready_now) {
graphics_.PaintImageData(ready_rect.image_data, pp::Point(), graphics_.PaintImageData(ready_rect.image_data, pp::Point(),
ready_rect.rect); PPRectFromRect(ready_rect.rect));
} }
Flush(); Flush();

@ -12,12 +12,13 @@
#include "pdf/paint_aggregator.h" #include "pdf/paint_aggregator.h"
#include "ppapi/cpp/graphics_2d.h" #include "ppapi/cpp/graphics_2d.h"
#include "ppapi/utility/completion_callback_factory.h" #include "ppapi/utility/completion_callback_factory.h"
#include "ui/gfx/geometry/size.h"
namespace pp { namespace gfx {
class Point; class Point;
class Rect; class Rect;
class Size; class Vector2d;
} // namespace pp } // namespace gfx
namespace chrome_pdf { namespace chrome_pdf {
@ -34,7 +35,7 @@ class PaintManager {
public: public:
// Creates a new, unbound `pp::Graphics2D` for the paint manager, with the // Creates a new, unbound `pp::Graphics2D` for the paint manager, with the
// given |size| and always-opaque rendering. // given |size| and always-opaque rendering.
virtual pp::Graphics2D CreatePaintGraphics(const pp::Size& size) = 0; virtual pp::Graphics2D CreatePaintGraphics(const gfx::Size& size) = 0;
// Binds a `pp::Graphics2D` created by `CreatePaintGraphics()`, returning // Binds a `pp::Graphics2D` created by `CreatePaintGraphics()`, returning
// `true` if binding was successful. // `true` if binding was successful.
@ -58,9 +59,9 @@ class PaintManager {
// PaintManager needs to handle the callback. // PaintManager needs to handle the callback.
// //
// Calling Invalidate/Scroll is not allowed while inside an OnPaint // Calling Invalidate/Scroll is not allowed while inside an OnPaint
virtual void OnPaint(const std::vector<pp::Rect>& paint_rects, virtual void OnPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready, std::vector<PaintReadyRect>* ready,
std::vector<pp::Rect>* pending) = 0; std::vector<gfx::Rect>* pending) = 0;
protected: protected:
// You shouldn't be doing deleting through this interface. // You shouldn't be doing deleting through this interface.
@ -81,8 +82,8 @@ class PaintManager {
// size. We may allocated a slightly larger buffer than required so that we // size. We may allocated a slightly larger buffer than required so that we
// don't have to resize the context when scrollbars appear/dissapear due to // don't have to resize the context when scrollbars appear/dissapear due to
// zooming (which can result in flickering). // zooming (which can result in flickering).
static pp::Size GetNewContextSize(const pp::Size& current_context_size, static gfx::Size GetNewContextSize(const gfx::Size& current_context_size,
const pp::Size& plugin_size); const gfx::Size& plugin_size);
// Sets the size of the plugin. If the size is the same as the previous call, // Sets the size of the plugin. If the size is the same as the previous call,
// this will be a NOP. If the size has changed, a new device will be // this will be a NOP. If the size has changed, a new device will be
@ -93,22 +94,22 @@ class PaintManager {
// changes, you can always call this function without worrying about whether // changes, you can always call this function without worrying about whether
// the size changed or ViewChanged is called for another reason (like the // the size changed or ViewChanged is called for another reason (like the
// position changed). // position changed).
void SetSize(const pp::Size& new_size, float new_device_scale); void SetSize(const gfx::Size& new_size, float new_device_scale);
// Invalidate the entire plugin. // Invalidate the entire plugin.
void Invalidate(); void Invalidate();
// Invalidate the given rect. // Invalidate the given rect.
void InvalidateRect(const pp::Rect& rect); void InvalidateRect(const gfx::Rect& rect);
// The given rect should be scrolled by the given amounts. // The given rect should be scrolled by the given amounts.
void ScrollRect(const pp::Rect& clip_rect, const pp::Point& amount); void ScrollRect(const gfx::Rect& clip_rect, const gfx::Vector2d& amount);
// Returns the size of the graphics context for the next paint operation. // Returns the size of the graphics context for the next paint operation.
// This is the pending size if a resize is pending (the plugin has called // This is the pending size if a resize is pending (the plugin has called
// SetSize but we haven't actually painted it yet), or the current size of // SetSize but we haven't actually painted it yet), or the current size of
// no resize is pending. // no resize is pending.
pp::Size GetEffectiveSize() const; gfx::Size GetEffectiveSize() const;
float GetEffectiveDeviceScale() const; float GetEffectiveDeviceScale() const;
// Set the transform for the graphics layer. // Set the transform for the graphics layer.
@ -116,8 +117,8 @@ class PaintManager {
// this change. If |schedule_flush| is false, then the change will not take // this change. If |schedule_flush| is false, then the change will not take
// effect until another change causes a flush. // effect until another change causes a flush.
void SetTransform(float scale, void SetTransform(float scale,
const pp::Point& origin, const gfx::Point& origin,
const pp::Point& translate, const gfx::Vector2d& translate,
bool schedule_flush); bool schedule_flush);
// Resets any transform for the graphics layer. // Resets any transform for the graphics layer.
// This does not schedule a flush. // This does not schedule a flush.
@ -164,8 +165,8 @@ class PaintManager {
// paint operation. When true, the new size is in pending_size_. // paint operation. When true, the new size is in pending_size_.
bool has_pending_resize_ = false; bool has_pending_resize_ = false;
bool graphics_need_to_be_bound_ = false; bool graphics_need_to_be_bound_ = false;
pp::Size pending_size_; gfx::Size pending_size_;
pp::Size plugin_size_; gfx::Size plugin_size_;
float pending_device_scale_ = 1.0f; float pending_device_scale_ = 1.0f;
float device_scale_ = 1.0f; float device_scale_ = 1.0f;

@ -4,6 +4,7 @@
#include "pdf/paint_ready_rect.h" #include "pdf/paint_ready_rect.h"
#include "pdf/ppapi_migration/geometry_conversions.h"
#include "ppapi/cpp/image_data.h" #include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/rect.h" #include "ppapi/cpp/rect.h"
@ -12,7 +13,9 @@ namespace chrome_pdf {
PaintReadyRect::PaintReadyRect(const pp::Rect& rect, PaintReadyRect::PaintReadyRect(const pp::Rect& rect,
const pp::ImageData& image_data, const pp::ImageData& image_data,
bool flush_now) bool flush_now)
: rect(rect), image_data(image_data), flush_now(flush_now) {} : rect(RectFromPPRect(rect)),
image_data(image_data),
flush_now(flush_now) {}
PaintReadyRect::PaintReadyRect(const PaintReadyRect& other) = default; PaintReadyRect::PaintReadyRect(const PaintReadyRect& other) = default;

@ -6,7 +6,11 @@
#define PDF_PAINT_READY_RECT_H_ #define PDF_PAINT_READY_RECT_H_
#include "ppapi/cpp/image_data.h" #include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/rect.h" #include "ui/gfx/geometry/rect.h"
namespace pp {
class Rect;
} // namespace pp
namespace chrome_pdf { namespace chrome_pdf {
@ -20,7 +24,7 @@ struct PaintReadyRect {
PaintReadyRect(const PaintReadyRect& other); PaintReadyRect(const PaintReadyRect& other);
PaintReadyRect& operator=(const PaintReadyRect& other); PaintReadyRect& operator=(const PaintReadyRect& other);
pp::Rect rect; gfx::Rect rect;
pp::ImageData image_data; pp::ImageData image_data;
// Whether to flush to screen immediately; otherwise, when the rest of the // Whether to flush to screen immediately; otherwise, when the rest of the

@ -48,6 +48,7 @@ class SkBitmap;
namespace gfx { namespace gfx {
class Rect; class Rect;
class Size; class Size;
class Vector2d;
} // namespace gfx } // namespace gfx
namespace pp { namespace pp {
@ -134,7 +135,7 @@ class PDFEngine {
virtual void Invalidate(const pp::Rect& rect) {} virtual void Invalidate(const pp::Rect& rect) {}
// Informs the client to scroll the plugin area by the given offset. // Informs the client to scroll the plugin area by the given offset.
virtual void DidScroll(const pp::Point& point) {} virtual void DidScroll(const gfx::Vector2d& offset) {}
// Scroll the horizontal/vertical scrollbars to a given position. // Scroll the horizontal/vertical scrollbars to a given position.
// Values are in screen coordinates, where 0 is the top/left of the document // Values are in screen coordinates, where 0 is the top/left of the document

@ -61,6 +61,7 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
#if defined(OS_LINUX) #if defined(OS_LINUX)
@ -513,7 +514,7 @@ void PDFiumEngine::ScrolledToXPosition(int position) {
int old_x = position_.x(); int old_x = position_.x();
position_.set_x(position); position_.set_x(position);
CalculateVisiblePages(); CalculateVisiblePages();
client_->DidScroll(pp::Point(old_x - position, 0)); client_->DidScroll(gfx::Vector2d(old_x - position, 0));
OnSelectionPositionChanged(); OnSelectionPositionChanged();
} }
@ -523,7 +524,7 @@ void PDFiumEngine::ScrolledToYPosition(int position) {
int old_y = position_.y(); int old_y = position_.y();
position_.set_y(position); position_.set_y(position);
CalculateVisiblePages(); CalculateVisiblePages();
client_->DidScroll(pp::Point(0, old_y - position)); client_->DidScroll(gfx::Vector2d(0, old_y - position));
OnSelectionPositionChanged(); OnSelectionPositionChanged();
} }

@ -26,7 +26,7 @@ void PreviewModeClient::Invalidate(const pp::Rect& rect) {
NOTREACHED(); NOTREACHED();
} }
void PreviewModeClient::DidScroll(const pp::Point& point) { void PreviewModeClient::DidScroll(const gfx::Vector2d& point) {
NOTREACHED(); NOTREACHED();
} }

@ -13,6 +13,10 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "pdf/pdf_engine.h" #include "pdf/pdf_engine.h"
namespace gfx {
class Vector2d;
} // namespace gfx
namespace chrome_pdf { namespace chrome_pdf {
// The interface that's provided to the print preview rendering engine. // The interface that's provided to the print preview rendering engine.
@ -30,7 +34,7 @@ class PreviewModeClient : public PDFEngine::Client {
// PDFEngine::Client implementation. // PDFEngine::Client implementation.
void ProposeDocumentLayout(const DocumentLayout& layout) override; void ProposeDocumentLayout(const DocumentLayout& layout) override;
void Invalidate(const pp::Rect& rect) override; void Invalidate(const pp::Rect& rect) override;
void DidScroll(const pp::Point& point) override; void DidScroll(const gfx::Vector2d& offset) override;
void ScrollToX(int x_in_screen_coords) override; void ScrollToX(int x_in_screen_coords) override;
void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override; void ScrollToY(int y_in_screen_coords, bool compensate_for_toolbar) override;
void ScrollBy(const pp::Point& point) override; void ScrollBy(const pp::Point& point) override;