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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 1267553004: Revert of 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) {
283 loader_factory_.Initialize(this); 282 loader_factory_.Initialize(this);
284 timer_factory_.Initialize(this); 283 timer_factory_.Initialize(this);
285 form_factory_.Initialize(this); 284 form_factory_.Initialize(this);
286 print_callback_factory_.Initialize(this); 285 print_callback_factory_.Initialize(this);
287 engine_.reset(PDFEngine::Create(this)); 286 engine_.reset(PDFEngine::Create(this));
288 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); 287 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
289 AddPerInstanceObject(kPPPPdfInterface, this); 288 AddPerInstanceObject(kPPPPdfInterface, this);
290 289
291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); 290 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
292 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); 291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 bool is_material = false; 348 bool is_material = false;
350 for (uint32_t i = 0; i < argc; ++i) { 349 for (uint32_t i = 0; i < argc; ++i) {
351 if (strcmp(argn[i], "src") == 0) 350 if (strcmp(argn[i], "src") == 0)
352 original_url = argv[i]; 351 original_url = argv[i];
353 else if (strcmp(argn[i], "stream-url") == 0) 352 else if (strcmp(argn[i], "stream-url") == 0)
354 stream_url = argv[i]; 353 stream_url = argv[i];
355 else if (strcmp(argn[i], "headers") == 0) 354 else if (strcmp(argn[i], "headers") == 0)
356 headers = argv[i]; 355 headers = argv[i];
357 else if (strcmp(argn[i], "is-material") == 0) 356 else if (strcmp(argn[i], "is-material") == 0)
358 is_material = true; 357 is_material = true;
359 else if (strcmp(argn[i], "top-toolbar-height") == 0)
360 base::StringToInt(argv[i], &top_toolbar_height_);
361 } 358 }
362 359
363 if (is_material) 360 if (is_material)
364 background_color_ = kBackgroundColorMaterial; 361 background_color_ = kBackgroundColorMaterial;
365 else 362 else
366 background_color_ = kBackgroundColor; 363 background_color_ = kBackgroundColor;
367 364
368 if (!original_url) 365 if (!original_url)
369 return false; 366 return false;
370 367
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 if (image_data_.is_null()) { 585 if (image_data_.is_null()) {
589 DCHECK(plugin_size_.IsEmpty()); 586 DCHECK(plugin_size_.IsEmpty());
590 return; 587 return;
591 } 588 }
592 589
593 OnGeometryChanged(zoom_, old_device_scale); 590 OnGeometryChanged(zoom_, old_device_scale);
594 } 591 }
595 592
596 if (!stop_scrolling_) { 593 if (!stop_scrolling_) {
597 pp::Point scroll_offset(view.GetScrollOffset()); 594 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.
602 pp::FloatPoint scroll_offset_float(scroll_offset.x(), 595 pp::FloatPoint scroll_offset_float(scroll_offset.x(),
603 scroll_offset.y() - top_toolbar_height_); 596 scroll_offset.y());
604 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); 597 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
605 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); 598 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
606 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); 599 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
607 } 600 }
608 } 601 }
609 602
610 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( 603 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
611 PP_PdfPrintPresetOptions_Dev* options) { 604 PP_PdfPrintPresetOptions_Dev* options) {
612 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); 605 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled());
613 options->duplex = 606 options->duplex =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 pdf_ready[j].Offset(available_area_.point()); 719 pdf_ready[j].Offset(available_area_.point());
727 ready->push_back( 720 ready->push_back(
728 PaintManager::ReadyRect(pdf_ready[j], image_data_, false)); 721 PaintManager::ReadyRect(pdf_ready[j], image_data_, false));
729 } 722 }
730 for (size_t j = 0; j < pdf_pending.size(); ++j) { 723 for (size_t j = 0; j < pdf_pending.size(); ++j) {
731 pdf_pending[j].Offset(available_area_.point()); 724 pdf_pending[j].Offset(available_area_.point());
732 pending->push_back(pdf_pending[j]); 725 pending->push_back(pdf_pending[j]);
733 } 726 }
734 } 727 }
735 728
736 // Ensure the region above the first page (if any) is filled;
737 int32_t first_page_ypos = engine_->GetPageScreenRect(0).y();
738 if (rect.y() < first_page_ypos) {
739 pp::Rect region = rect.Intersect(pp::Rect(
740 pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos)));
741 ready->push_back(PaintManager::ReadyRect(region, image_data_, false));
742 FillRect(region, background_color_);
743 }
744
745 for (size_t j = 0; j < background_parts_.size(); ++j) { 729 for (size_t j = 0; j < background_parts_.size(); ++j) {
746 pp::Rect intersection = background_parts_[j].location.Intersect(rect); 730 pp::Rect intersection = background_parts_[j].location.Intersect(rect);
747 if (!intersection.IsEmpty()) { 731 if (!intersection.IsEmpty()) {
748 FillRect(intersection, background_parts_[j].color); 732 FillRect(intersection, background_parts_[j].color);
749 ready->push_back( 733 ready->push_back(
750 PaintManager::ReadyRect(intersection, image_data_, false)); 734 PaintManager::ReadyRect(intersection, image_data_, false));
751 } 735 }
752 } 736 }
753 } 737 }
754 738
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 did_call_start_loading_ = false; 1125 did_call_start_loading_ = false;
1142 } 1126 }
1143 1127
1144 int content_restrictions = 1128 int content_restrictions =
1145 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; 1129 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE;
1146 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 1130 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY))
1147 content_restrictions |= CONTENT_RESTRICTION_COPY; 1131 content_restrictions |= CONTENT_RESTRICTION_COPY;
1148 1132
1149 pp::PDF::SetContentRestriction(this, content_restrictions); 1133 pp::PDF::SetContentRestriction(this, content_restrictions);
1150 1134
1151 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50); 1135 uma_.HistogramCustomCounts("PDF.PageCount", page_count,
1136 1, 1000000, 50);
1152 } 1137 }
1153 1138
1154 void OutOfProcessInstance::RotateClockwise() { 1139 void OutOfProcessInstance::RotateClockwise() {
1155 engine_->RotateClockwise(); 1140 engine_->RotateClockwise();
1156 } 1141 }
1157 1142
1158 void OutOfProcessInstance::RotateCounterclockwise() { 1143 void OutOfProcessInstance::RotateCounterclockwise() {
1159 engine_->RotateCounterclockwise(); 1144 engine_->RotateCounterclockwise();
1160 } 1145 }
1161 1146
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 float old_device_scale) { 1272 float old_device_scale) {
1288 if (zoom_ != old_zoom || device_scale_ != old_device_scale) 1273 if (zoom_ != old_zoom || device_scale_ != old_device_scale)
1289 engine_->ZoomUpdated(zoom_ * device_scale_); 1274 engine_->ZoomUpdated(zoom_ * device_scale_);
1290 1275
1291 available_area_ = pp::Rect(plugin_size_); 1276 available_area_ = pp::Rect(plugin_size_);
1292 int doc_width = GetDocumentPixelWidth(); 1277 int doc_width = GetDocumentPixelWidth();
1293 if (doc_width < available_area_.width()) { 1278 if (doc_width < available_area_.width()) {
1294 available_area_.Offset((available_area_.width() - doc_width) / 2, 0); 1279 available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
1295 available_area_.set_width(doc_width); 1280 available_area_.set_width(doc_width);
1296 } 1281 }
1297 int bottom_of_document = 1282 int doc_height = GetDocumentPixelHeight();
1298 GetDocumentPixelHeight() + (top_toolbar_height_ * device_scale_); 1283 if (doc_height < available_area_.height()) {
1299 if (bottom_of_document < available_area_.height()) 1284 available_area_.set_height(doc_height);
1300 available_area_.set_height(bottom_of_document); 1285 }
1301 1286
1302 CalculateBackgroundParts(); 1287 CalculateBackgroundParts();
1303 engine_->PageOffsetUpdated(available_area_.point()); 1288 engine_->PageOffsetUpdated(available_area_.point());
1304 engine_->PluginSizeUpdated(available_area_.size()); 1289 engine_->PluginSizeUpdated(available_area_.size());
1305 1290
1306 if (!document_size_.GetArea()) 1291 if (!document_size_.GetArea())
1307 return; 1292 return;
1308 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); 1293 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
1309 } 1294 }
1310 1295
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 void OutOfProcessInstance::UserMetricsRecordAction( 1401 void OutOfProcessInstance::UserMetricsRecordAction(
1417 const std::string& action) { 1402 const std::string& action) {
1418 // TODO(raymes): Move this function to PPB_UMA_Private. 1403 // TODO(raymes): Move this function to PPB_UMA_Private.
1419 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); 1404 pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
1420 } 1405 }
1421 1406
1422 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( 1407 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
1423 const pp::FloatPoint& scroll_offset) { 1408 const pp::FloatPoint& scroll_offset) {
1424 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1409 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1425 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); 1410 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
1426 float min_y = -top_toolbar_height_;
1427 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1411 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1428 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); 1412 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
1429 return pp::FloatPoint(x, y); 1413 return pp::FloatPoint(x, y);
1430 } 1414 }
1431 1415
1432 } // namespace chrome_pdf 1416 } // 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