summaryrefslogtreecommitdiffstats
path: root/pdf/out_of_process_instance.cc
diff options
context:
space:
mode:
authorraymes <raymes@chromium.org>2015-08-05 00:05:18 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-05 07:09:02 +0000
commitbd82a94bbc1738c60459dec25f4d9aa73f7baeab (patch)
tree20b89ede12a9abc6452d80446d5838d732ebbf11 /pdf/out_of_process_instance.cc
parentfa9f7f47739724fe1cba8ad17668edcabe9e213c (diff)
downloadchromium_src-bd82a94bbc1738c60459dec25f4d9aa73f7baeab.zip
chromium_src-bd82a94bbc1738c60459dec25f4d9aa73f7baeab.tar.gz
chromium_src-bd82a94bbc1738c60459dec25f4d9aa73f7baeab.tar.bz2
Add a scroll offset to PDF documents to account for the top material design toolbar.
Previously the toolbar in the material design PDF UI would always cover the top of pages when it was first loaded or when a page was navigated to using the page selector. Now we ensure that a blank region is left at the very top of the document when it is first loaded. This is the region that the toolbar covers, so the document is not obscured at all. When pages are navigated to, we ensure that the top of the selected page is always underneath the toolbar so that it is not obscured. The one exception to this is when in fit-to-page mode which causes the page to be zoomed to cover the entire screen, ignoring the toolbar. This is so that users can take advantaging of filling all of the screen real-estate with a page when that is what they want. This is implemented by initially scrolling the document to a negative offset (which is equal to the toolbar height). All subsequent scrolls are relative to this initial scroll. A few small bugs that assumed there was no blank space above the first page have also been fixed. BUG=439114 Committed: https://crrev.com/daad0f1f879b13c8b55797ae5ce106d382283047 Cr-Commit-Position: refs/heads/master@{#341685} Review URL: https://codereview.chromium.org/1255403002 Cr-Commit-Position: refs/heads/master@{#341861}
Diffstat (limited to 'pdf/out_of_process_instance.cc')
-rw-r--r--pdf/out_of_process_instance.cc35
1 files changed, 26 insertions, 9 deletions
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index df18f17..1d782be 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -278,7 +278,8 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
received_viewport_message_(false),
did_call_start_loading_(false),
stop_scrolling_(false),
- background_color_(kBackgroundColor) {
+ background_color_(kBackgroundColor),
+ top_toolbar_height_(0) {
loader_factory_.Initialize(this);
timer_factory_.Initialize(this);
form_factory_.Initialize(this);
@@ -355,6 +356,8 @@ bool OutOfProcessInstance::Init(uint32_t argc,
headers = argv[i];
else if (strcmp(argn[i], "is-material") == 0)
is_material = true;
+ else if (strcmp(argn[i], "top-toolbar-height") == 0)
+ base::StringToInt(argv[i], &top_toolbar_height_);
}
if (is_material)
@@ -592,8 +595,12 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
if (!stop_scrolling_) {
pp::Point scroll_offset(view.GetScrollOffset());
+ // Because view messages come from the DOM, the coordinates of the viewport
+ // are 0-based (i.e. they do not correspond to the viewport's coordinates in
+ // JS), so we need to subtract the toolbar height to convert them into
+ // viewport coordinates.
pp::FloatPoint scroll_offset_float(scroll_offset.x(),
- scroll_offset.y());
+ scroll_offset.y() - top_toolbar_height_);
scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
@@ -726,6 +733,16 @@ void OutOfProcessInstance::OnPaint(
}
}
+ // Ensure the region above the first page (if any) is filled;
+ int32_t first_page_ypos = engine_->GetNumberOfPages() == 0 ?
+ 0 : engine_->GetPageScreenRect(0).y();
+ if (rect.y() < first_page_ypos) {
+ pp::Rect region = rect.Intersect(pp::Rect(
+ pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos)));
+ ready->push_back(PaintManager::ReadyRect(region, image_data_, false));
+ FillRect(region, background_color_);
+ }
+
for (size_t j = 0; j < background_parts_.size(); ++j) {
pp::Rect intersection = background_parts_[j].location.Intersect(rect);
if (!intersection.IsEmpty()) {
@@ -1137,8 +1154,7 @@ void OutOfProcessInstance::DocumentLoadComplete(int page_count) {
pp::PDF::SetContentRestriction(this, content_restrictions);
- uma_.HistogramCustomCounts("PDF.PageCount", page_count,
- 1, 1000000, 50);
+ uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50);
}
void OutOfProcessInstance::RotateClockwise() {
@@ -1284,10 +1300,10 @@ void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
available_area_.set_width(doc_width);
}
- int doc_height = GetDocumentPixelHeight();
- if (doc_height < available_area_.height()) {
- available_area_.set_height(doc_height);
- }
+ int bottom_of_document =
+ GetDocumentPixelHeight() + (top_toolbar_height_ * device_scale_);
+ if (bottom_of_document < available_area_.height())
+ available_area_.set_height(bottom_of_document);
CalculateBackgroundParts();
engine_->PageOffsetUpdated(available_area_.point());
@@ -1413,8 +1429,9 @@ pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
const pp::FloatPoint& scroll_offset) {
float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
+ float min_y = -top_toolbar_height_;
float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
- float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
+ float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
return pp::FloatPoint(x, y);
}