Commit 744ba8cd authored by Hui Yingst's avatar Hui Yingst Committed by Chromium LUCI CQ

Migrate 3 members from OutOfProcessInstance to PdfViewPluginBase.

This CL migrates `plugin_size_`, `plugin_dip_size_` and `plugin_offset_`
from OutOfProcessInstance to PdfViewPluginBase, and provides accessors
and mutators for them, so that these members can be used by both
PdfViewWebPlugin and OutOfProcessInstance.

Bug: 1140629
Change-Id: I0c3e2e6fa46233eab8e3b25b0d6101c6a557f80e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616732
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841694}
parent 7f4e4026
...@@ -764,18 +764,18 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) { ...@@ -764,18 +764,18 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
gfx::Size view_device_size(view_rect.width() * new_device_scale, gfx::Size view_device_size(view_rect.width() * new_device_scale,
view_rect.height() * new_device_scale); view_rect.height() * new_device_scale);
if (view_device_size != plugin_size_ || new_device_scale != device_scale() || if (view_device_size != plugin_size() || new_device_scale != device_scale() ||
view_rect.origin() != plugin_offset_) { view_rect.origin() != plugin_offset()) {
set_device_scale(new_device_scale); set_device_scale(new_device_scale);
plugin_dip_size_ = view_rect.size(); set_plugin_dip_size(view_rect.size());
plugin_size_ = view_device_size; set_plugin_size(view_device_size);
plugin_offset_ = view_rect.origin(); set_plugin_offset(view_rect.origin());
paint_manager().SetSize(view_device_size, device_scale()); paint_manager().SetSize(view_device_size, device_scale());
const gfx::Size old_image_data_size = SizeFromPPSize(image_data_.size()); const gfx::Size old_image_data_size = SizeFromPPSize(image_data_.size());
gfx::Size new_image_data_size = gfx::Size new_image_data_size =
PaintManager::GetNewContextSize(old_image_data_size, plugin_size_); PaintManager::GetNewContextSize(old_image_data_size, plugin_size());
if (new_image_data_size != old_image_data_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,
PPSizeFromSize(new_image_data_size), false); PPSizeFromSize(new_image_data_size), false);
...@@ -785,7 +785,7 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) { ...@@ -785,7 +785,7 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
} }
if (image_data_.is_null()) { if (image_data_.is_null()) {
DCHECK(plugin_size_.IsEmpty()); DCHECK(plugin_size().IsEmpty());
return; return;
} }
...@@ -913,9 +913,9 @@ void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) { ...@@ -913,9 +913,9 @@ void OutOfProcessInstance::SendNextAccessibilityPage(int32_t page_index) {
void OutOfProcessInstance::SendAccessibilityViewportInfo() { void OutOfProcessInstance::SendAccessibilityViewportInfo() {
PP_PrivateAccessibilityViewportInfo viewport_info; PP_PrivateAccessibilityViewportInfo viewport_info;
viewport_info.scroll.x = -plugin_offset_.x(); viewport_info.scroll.x = -plugin_offset().x();
viewport_info.scroll.y = viewport_info.scroll.y =
-top_toolbar_height_in_viewport_coords() - plugin_offset_.y(); -top_toolbar_height_in_viewport_coords() - plugin_offset().y();
viewport_info.offset.x = available_area_.x() / (device_scale() * zoom()); viewport_info.offset.x = available_area_.x() / (device_scale() * zoom());
viewport_info.offset.y = available_area_.y() / (device_scale() * zoom()); viewport_info.offset.y = available_area_.y() / (device_scale() * zoom());
...@@ -1115,7 +1115,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects, ...@@ -1115,7 +1115,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects,
std::vector<PaintReadyRect>* ready, std::vector<PaintReadyRect>* ready,
std::vector<gfx::Rect>* pending) { std::vector<gfx::Rect>* pending) {
if (image_data_.is_null()) { if (image_data_.is_null()) {
DCHECK(plugin_size_.IsEmpty()); DCHECK(plugin_size().IsEmpty());
return; return;
} }
if (first_paint()) { if (first_paint()) {
...@@ -1133,7 +1133,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects, ...@@ -1133,7 +1133,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::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.
gfx::Rect rect = gfx::IntersectRects(paint_rect, gfx::Rect(plugin_size_)); gfx::Rect rect = gfx::IntersectRects(paint_rect, gfx::Rect(plugin_size()));
if (rect.IsEmpty()) if (rect.IsEmpty())
continue; continue;
...@@ -1160,7 +1160,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects, ...@@ -1160,7 +1160,7 @@ void OutOfProcessInstance::DoPaint(const std::vector<gfx::Rect>& paint_rects,
: engine()->GetPageScreenRect(0).y(); : engine()->GetPageScreenRect(0).y();
if (rect.y() < first_page_ypos) { if (rect.y() < first_page_ypos) {
gfx::Rect region = gfx::IntersectRects( gfx::Rect region = gfx::IntersectRects(
rect, gfx::Rect(gfx::Size(plugin_size_.width(), first_page_ypos))); rect, gfx::Rect(gfx::Size(plugin_size().width(), first_page_ypos)));
ready->push_back(PaintReadyRect(region, image_data_)); ready->push_back(PaintReadyRect(region, image_data_));
FillRect(region, GetBackgroundColor()); FillRect(region, GetBackgroundColor());
} }
...@@ -1190,8 +1190,8 @@ void OutOfProcessInstance::CalculateBackgroundParts() { ...@@ -1190,8 +1190,8 @@ void OutOfProcessInstance::CalculateBackgroundParts() {
background_parts_.clear(); background_parts_.clear();
int left_width = available_area_.x(); int left_width = available_area_.x();
int right_start = available_area_.right(); int right_start = available_area_.right();
int right_width = abs(plugin_size_.width() - available_area_.right()); int right_width = abs(plugin_size().width() - available_area_.right());
int bottom = std::min(available_area_.bottom(), plugin_size_.height()); int bottom = std::min(available_area_.bottom(), plugin_size().height());
// Add the left, right, and bottom rectangles. Note: we assume only // Add the left, right, and bottom rectangles. Note: we assume only
// horizontal centering. // horizontal centering.
...@@ -1202,8 +1202,8 @@ void OutOfProcessInstance::CalculateBackgroundParts() { ...@@ -1202,8 +1202,8 @@ void OutOfProcessInstance::CalculateBackgroundParts() {
part.location = pp::Rect(right_start, 0, right_width, bottom); part.location = pp::Rect(right_start, 0, right_width, bottom);
if (!part.location.IsEmpty()) if (!part.location.IsEmpty())
background_parts_.push_back(part); background_parts_.push_back(part);
part.location = part.location = pp::Rect(0, bottom, plugin_size().width(),
pp::Rect(0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); plugin_size().height() - bottom);
if (!part.location.IsEmpty()) if (!part.location.IsEmpty())
background_parts_.push_back(part); background_parts_.push_back(part);
} }
...@@ -1834,7 +1834,7 @@ void OutOfProcessInstance::HandleResetPrintPreviewModeMessage( ...@@ -1834,7 +1834,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(gfx::Rect(plugin_size_)); paint_manager().InvalidateRect(gfx::Rect(plugin_size()));
} }
void OutOfProcessInstance::HandleSaveAttachmentMessage( void OutOfProcessInstance::HandleSaveAttachmentMessage(
...@@ -2007,7 +2007,7 @@ void OutOfProcessInstance::HandleViewportMessage( ...@@ -2007,7 +2007,7 @@ void OutOfProcessInstance::HandleViewportMessage(
// position on screen of the paint. // position on screen of the paint.
gfx::Vector2d 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 = gfx::Vector2d(0, (1 - zoom_ratio) * pinch_center.y()); paint_offset = gfx::Vector2d(0, (1 - zoom_ratio) * pinch_center.y());
...@@ -2018,10 +2018,10 @@ void OutOfProcessInstance::HandleViewportMessage( ...@@ -2018,10 +2018,10 @@ void OutOfProcessInstance::HandleViewportMessage(
pinch_vector = gfx::Vector2d(); 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 = gfx::Vector2d( paint_offset = gfx::Vector2d(
(1 - new_zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(), (1 - new_zoom / zoom_when_doc_covers_plugin_width) * pinch_center.x(),
(1 - zoom_ratio) * pinch_center.y()); (1 - zoom_ratio) * pinch_center.y());
...@@ -2091,7 +2091,7 @@ void OutOfProcessInstance::DocumentLoadFailed() { ...@@ -2091,7 +2091,7 @@ void OutOfProcessInstance::DocumentLoadFailed() {
} }
document_load_state_ = LOAD_STATE_FAILED; document_load_state_ = LOAD_STATE_FAILED;
paint_manager().InvalidateRect(gfx::Rect(plugin_size_)); paint_manager().InvalidateRect(gfx::Rect(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);
...@@ -2182,7 +2182,7 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom, ...@@ -2182,7 +2182,7 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
if (zoom() != old_zoom || device_scale() != old_device_scale) if (zoom() != old_zoom || device_scale() != old_device_scale)
engine()->ZoomUpdated(zoom() * device_scale()); engine()->ZoomUpdated(zoom() * device_scale());
available_area_ = gfx::Rect(plugin_size_); available_area_ = gfx::Rect(plugin_size());
int doc_width = GetDocumentPixelWidth(); int doc_width = GetDocumentPixelWidth();
if (doc_width < available_area_.width()) { if (doc_width < available_area_.width()) {
available_area_.Offset((available_area_.width() - doc_width) / 2, 0); available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
...@@ -2200,7 +2200,7 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom, ...@@ -2200,7 +2200,7 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
if (document_size().IsEmpty()) if (document_size().IsEmpty())
return; return;
paint_manager().InvalidateRect(gfx::Rect(plugin_size_)); paint_manager().InvalidateRect(gfx::Rect(plugin_size()));
if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED) if (accessibility_state_ == ACCESSIBILITY_STATE_LOADED)
SendAccessibilityViewportInfo(); SendAccessibilityViewportInfo();
...@@ -2419,11 +2419,12 @@ void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) { ...@@ -2419,11 +2419,12 @@ void OutOfProcessInstance::UserMetricsRecordAction(const std::string& action) {
pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
const pp::FloatPoint& scroll_offset) { const pp::FloatPoint& scroll_offset) {
float max_x = std::max( float max_x = std::max(
document_size().width() * float{zoom()} - plugin_dip_size_.width(), 0.0f); document_size().width() * float{zoom()} - plugin_dip_size().width(),
0.0f);
float x = base::ClampToRange(scroll_offset.x(), 0.0f, max_x); float x = base::ClampToRange(scroll_offset.x(), 0.0f, max_x);
float min_y = -top_toolbar_height_in_viewport_coords(); float min_y = -top_toolbar_height_in_viewport_coords();
float max_y = std::max( float max_y = std::max(
document_size().height() * float{zoom()} - plugin_dip_size_.height(), document_size().height() * float{zoom()} - plugin_dip_size().height(),
min_y); min_y);
float y = base::ClampToRange(scroll_offset.y(), min_y, max_y); float y = base::ClampToRange(scroll_offset.y(), min_y, max_y);
return pp::FloatPoint(x, y); return pp::FloatPoint(x, y);
......
...@@ -347,15 +347,9 @@ class OutOfProcessInstance : public PdfViewPluginBase, ...@@ -347,15 +347,9 @@ class OutOfProcessInstance : public PdfViewPluginBase,
// The current cursor. // The current cursor.
PP_CursorType_Dev cursor_ = PP_CURSORTYPE_POINTER; PP_CursorType_Dev cursor_ = PP_CURSORTYPE_POINTER;
// Size, in pixels, of plugin rectangle.
gfx::Size plugin_size_;
// Size, in DIPs, of plugin rectangle.
gfx::Size plugin_dip_size_;
// Remaining area, in pixels, to render the pdf in after accounting for // Remaining area, in pixels, to render the pdf in after accounting for
// horizontal centering. // horizontal centering.
gfx::Rect available_area_; gfx::Rect available_area_;
// Positional offset, in CSS pixels, of the plugin rectangle.
gfx::Point plugin_offset_;
// The scroll offset in CSS pixels. // The scroll offset in CSS pixels.
pp::Point scroll_offset_; pp::Point scroll_offset_;
......
...@@ -91,6 +91,15 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -91,6 +91,15 @@ class PdfViewPluginBase : public PDFEngine::Client,
const gfx::Size& document_size() const { return document_size_; } const gfx::Size& document_size() const { return document_size_; }
void set_document_size(const gfx::Size& size) { document_size_ = size; } void set_document_size(const gfx::Size& size) { document_size_ = size; }
const gfx::Size& plugin_size() const { return plugin_size_; }
void set_plugin_size(const gfx::Size& size) { plugin_size_ = size; }
const gfx::Size& plugin_dip_size() const { return plugin_dip_size_; }
void set_plugin_dip_size(const gfx::Size& size) { plugin_dip_size_ = size; }
const gfx::Point& plugin_offset() const { return plugin_offset_; }
void set_plugin_offset(const gfx::Point& offset) { plugin_offset_ = offset; }
void SetBackgroundColor(uint32_t background_color) { void SetBackgroundColor(uint32_t background_color) {
background_color_ = background_color; background_color_ = background_color;
} }
...@@ -124,6 +133,15 @@ class PdfViewPluginBase : public PDFEngine::Client, ...@@ -124,6 +133,15 @@ class PdfViewPluginBase : public PDFEngine::Client,
// high and there are 10 pages, the height will be 8000). // high and there are 10 pages, the height will be 8000).
gfx::Size document_size_; gfx::Size document_size_;
// Size, in pixels, of plugin rectangle.
gfx::Size plugin_size_;
// Size, in DIPs, of plugin rectangle.
gfx::Size plugin_dip_size_;
// Positional offset, in CSS pixels, of the plugin rectangle.
gfx::Point plugin_offset_;
// The background color of the PDF viewer. // The background color of the PDF viewer.
uint32_t background_color_ = 0; uint32_t background_color_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment