Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 1255403002: Add a scroll offset to PDF documents to account for the top material design toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <algorithm> // for min/max() 7 #include <algorithm> // for min/max()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 document_load_state_(LOAD_STATE_LOADING), 271 document_load_state_(LOAD_STATE_LOADING),
272 preview_document_load_state_(LOAD_STATE_COMPLETE), 272 preview_document_load_state_(LOAD_STATE_COMPLETE),
273 uma_(this), 273 uma_(this),
274 told_browser_about_unsupported_feature_(false), 274 told_browser_about_unsupported_feature_(false),
275 print_preview_page_count_(0), 275 print_preview_page_count_(0),
276 last_progress_sent_(0), 276 last_progress_sent_(0),
277 recently_sent_find_update_(false), 277 recently_sent_find_update_(false),
278 received_viewport_message_(false), 278 received_viewport_message_(false),
279 did_call_start_loading_(false), 279 did_call_start_loading_(false),
280 stop_scrolling_(false), 280 stop_scrolling_(false),
281 background_color_(kBackgroundColor) { 281 background_color_(kBackgroundColor),
282 top_toolbar_height_(0) {
282 loader_factory_.Initialize(this); 283 loader_factory_.Initialize(this);
283 timer_factory_.Initialize(this); 284 timer_factory_.Initialize(this);
284 form_factory_.Initialize(this); 285 form_factory_.Initialize(this);
285 print_callback_factory_.Initialize(this); 286 print_callback_factory_.Initialize(this);
286 engine_.reset(PDFEngine::Create(this)); 287 engine_.reset(PDFEngine::Create(this));
287 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 288 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
288 AddPerInstanceObject(kPPPPdfInterface, this); 289 AddPerInstanceObject(kPPPPdfInterface, this);
289 290
290 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 292 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 bool is_material = false; 349 bool is_material = false;
349 for (uint32_t i = 0; i < argc; ++i) { 350 for (uint32_t i = 0; i < argc; ++i) {
350 if (strcmp(argn[i], "src") == 0) 351 if (strcmp(argn[i], "src") == 0)
351 original_url = argv[i]; 352 original_url = argv[i];
352 else if (strcmp(argn[i], "stream-url") == 0) 353 else if (strcmp(argn[i], "stream-url") == 0)
353 stream_url = argv[i]; 354 stream_url = argv[i];
354 else if (strcmp(argn[i], "headers") == 0) 355 else if (strcmp(argn[i], "headers") == 0)
355 headers = argv[i]; 356 headers = argv[i];
356 else if (strcmp(argn[i], "is-material") == 0) 357 else if (strcmp(argn[i], "is-material") == 0)
357 is_material = true; 358 is_material = true;
359 else if (strcmp(argn[i], "top-toolbar-height") == 0)
360 base::StringToInt(argv[i], &top_toolbar_height_);
358 } 361 }
359 362
360 if (is_material) 363 if (is_material)
361 background_color_ = kBackgroundColorMaterial; 364 background_color_ = kBackgroundColorMaterial;
362 else 365 else
363 background_color_ = kBackgroundColor; 366 background_color_ = kBackgroundColor;
364 367
365 if (!original_url) 368 if (!original_url)
366 return false; 369 return false;
367 370
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (image_data_.is_null()) { 588 if (image_data_.is_null()) {
586 DCHECK(plugin_size_.IsEmpty()); 589 DCHECK(plugin_size_.IsEmpty());
587 return; 590 return;
588 } 591 }
589 592
590 OnGeometryChanged(zoom_, old_device_scale); 593 OnGeometryChanged(zoom_, old_device_scale);
591 } 594 }
592 595
593 if (!stop_scrolling_) { 596 if (!stop_scrolling_) {
594 pp::Point scroll_offset(view.GetScrollOffset()); 597 pp::Point scroll_offset(view.GetScrollOffset());
598 // Because view messages come from the DOM, the coordinates of the viewport
599 // are 0-based (i.e. they do not correspond to the viewport's coordinates in
600 // JS), so we need to subtract the toolbar height to convert them into
601 // viewport coordinates.
595 pp::FloatPoint scroll_offset_float(scroll_offset.x(), 602 pp::FloatPoint scroll_offset_float(scroll_offset.x(),
596 scroll_offset.y()); 603 scroll_offset.y() - top_toolbar_height_);
597 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); 604 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
598 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); 605 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
599 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); 606 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
600 } 607 }
601 } 608 }
602 609
603 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( 610 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
604 PP_PdfPrintPresetOptions_Dev* options) { 611 PP_PdfPrintPresetOptions_Dev* options) {
605 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); 612 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled());
606 options->duplex = 613 options->duplex =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 pdf_ready[j].Offset(available_area_.point()); 726 pdf_ready[j].Offset(available_area_.point());
720 ready->push_back( 727 ready->push_back(
721 PaintManager::ReadyRect(pdf_ready[j], image_data_, false)); 728 PaintManager::ReadyRect(pdf_ready[j], image_data_, false));
722 } 729 }
723 for (size_t j = 0; j < pdf_pending.size(); ++j) { 730 for (size_t j = 0; j < pdf_pending.size(); ++j) {
724 pdf_pending[j].Offset(available_area_.point()); 731 pdf_pending[j].Offset(available_area_.point());
725 pending->push_back(pdf_pending[j]); 732 pending->push_back(pdf_pending[j]);
726 } 733 }
727 } 734 }
728 735
736 // Ensure the region above the first page (if any) is filled;
737 int32_t first_page_ypos = engine_->GetNumberOfPages() == 0 ?
738 0 : engine_->GetPageScreenRect(0).y();
739 if (rect.y() < first_page_ypos) {
740 pp::Rect region = rect.Intersect(pp::Rect(
741 pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos)));
742 ready->push_back(PaintManager::ReadyRect(region, image_data_, false));
743 FillRect(region, background_color_);
744 }
745
729 for (size_t j = 0; j < background_parts_.size(); ++j) { 746 for (size_t j = 0; j < background_parts_.size(); ++j) {
730 pp::Rect intersection = background_parts_[j].location.Intersect(rect); 747 pp::Rect intersection = background_parts_[j].location.Intersect(rect);
731 if (!intersection.IsEmpty()) { 748 if (!intersection.IsEmpty()) {
732 FillRect(intersection, background_parts_[j].color); 749 FillRect(intersection, background_parts_[j].color);
733 ready->push_back( 750 ready->push_back(
734 PaintManager::ReadyRect(intersection, image_data_, false)); 751 PaintManager::ReadyRect(intersection, image_data_, false));
735 } 752 }
736 } 753 }
737 } 754 }
738 755
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 1147 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY))
1131 content_restrictions |= CONTENT_RESTRICTION_COPY; 1148 content_restrictions |= CONTENT_RESTRICTION_COPY;
1132 1149
1133 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) && 1150 if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
1134 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) { 1151 !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
1135 content_restrictions |= CONTENT_RESTRICTION_PRINT; 1152 content_restrictions |= CONTENT_RESTRICTION_PRINT;
1136 } 1153 }
1137 1154
1138 pp::PDF::SetContentRestriction(this, content_restrictions); 1155 pp::PDF::SetContentRestriction(this, content_restrictions);
1139 1156
1140 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1157 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50);
1141 1, 1000000, 50);
1142 } 1158 }
1143 1159
1144 void OutOfProcessInstance::RotateClockwise() { 1160 void OutOfProcessInstance::RotateClockwise() {
1145 engine_->RotateClockwise(); 1161 engine_->RotateClockwise();
1146 } 1162 }
1147 1163
1148 void OutOfProcessInstance::RotateCounterclockwise() { 1164 void OutOfProcessInstance::RotateCounterclockwise() {
1149 engine_->RotateCounterclockwise(); 1165 engine_->RotateCounterclockwise();
1150 } 1166 }
1151 1167
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 float old_device_scale) { 1293 float old_device_scale) {
1278 if (zoom_ != old_zoom || device_scale_ != old_device_scale) 1294 if (zoom_ != old_zoom || device_scale_ != old_device_scale)
1279 engine_->ZoomUpdated(zoom_ * device_scale_); 1295 engine_->ZoomUpdated(zoom_ * device_scale_);
1280 1296
1281 available_area_ = pp::Rect(plugin_size_); 1297 available_area_ = pp::Rect(plugin_size_);
1282 int doc_width = GetDocumentPixelWidth(); 1298 int doc_width = GetDocumentPixelWidth();
1283 if (doc_width < available_area_.width()) { 1299 if (doc_width < available_area_.width()) {
1284 available_area_.Offset((available_area_.width() - doc_width) / 2, 0); 1300 available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
1285 available_area_.set_width(doc_width); 1301 available_area_.set_width(doc_width);
1286 } 1302 }
1287 int doc_height = GetDocumentPixelHeight(); 1303 int bottom_of_document =
1288 if (doc_height < available_area_.height()) { 1304 GetDocumentPixelHeight() + (top_toolbar_height_ * device_scale_);
1289 available_area_.set_height(doc_height); 1305 if (bottom_of_document < available_area_.height())
1290 } 1306 available_area_.set_height(bottom_of_document);
1291 1307
1292 CalculateBackgroundParts(); 1308 CalculateBackgroundParts();
1293 engine_->PageOffsetUpdated(available_area_.point()); 1309 engine_->PageOffsetUpdated(available_area_.point());
1294 engine_->PluginSizeUpdated(available_area_.size()); 1310 engine_->PluginSizeUpdated(available_area_.size());
1295 1311
1296 if (!document_size_.GetArea()) 1312 if (!document_size_.GetArea())
1297 return; 1313 return;
1298 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 1314 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
1299 } 1315 }
1300 1316
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 void OutOfProcessInstance::UserMetricsRecordAction( 1422 void OutOfProcessInstance::UserMetricsRecordAction(
1407 const std::string& action) { 1423 const std::string& action) {
1408 // TODO(raymes): Move this function to PPB_UMA_Private. 1424 // TODO(raymes): Move this function to PPB_UMA_Private.
1409 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); 1425 pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
1410 } 1426 }
1411 1427
1412 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1428 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1413 const pp::FloatPoint& scroll_offset) { 1429 const pp::FloatPoint& scroll_offset) {
1414 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1430 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1415 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1431 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1432 float min_y = -top_toolbar_height_;
1416 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1433 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1417 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); 1434 float y = std::max(std::min(scroll_offset.y(), max_y), min_y);
1418 return pp::FloatPoint(x, y); 1435 return pp::FloatPoint(x, y);
1419 } 1436 }
1420 1437
1421 } // namespace chrome_pdf 1438 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/out_of_process_instance.h ('k') | pdf/pdf_engine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698