OLD | NEW |
---|---|
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> // for min/max() | 10 #include <algorithm> // for min/max() |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 const char kChromeExtension[] = | 49 const char kChromeExtension[] = |
50 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; | 50 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; |
51 | 51 |
52 // Constants used in handling postMessage() messages. | 52 // Constants used in handling postMessage() messages. |
53 const char kType[] = "type"; | 53 const char kType[] = "type"; |
54 // Viewport message arguments. (Page -> Plugin). | 54 // Viewport message arguments. (Page -> Plugin). |
55 const char kJSViewportType[] = "viewport"; | 55 const char kJSViewportType[] = "viewport"; |
56 const char kJSXOffset[] = "xOffset"; | 56 const char kJSXOffset[] = "xOffset"; |
57 const char kJSYOffset[] = "yOffset"; | 57 const char kJSYOffset[] = "yOffset"; |
58 const char kJSZoom[] = "zoom"; | 58 const char kJSZoom[] = "zoom"; |
59 const char kJSPinchPhase[] = "pinchPhase"; | |
60 // kJSPinchX and kJSPinchY represent the center of the pinch gesture. | |
61 const char kJSPinchX[] = "pinchX"; | |
62 const char kJSPinchY[] = "pinchY"; | |
63 // kJSPinchVector represents the amount of panning caused by the pinch gesture. | |
64 const char kJSPinchVectorX[] = "pinchVectorX"; | |
65 const char kJSPinchVectorY[] = "pinchVectorY"; | |
59 // Stop scrolling message (Page -> Plugin) | 66 // Stop scrolling message (Page -> Plugin) |
60 const char kJSStopScrollingType[] = "stopScrolling"; | 67 const char kJSStopScrollingType[] = "stopScrolling"; |
61 // Document dimension arguments (Plugin -> Page). | 68 // Document dimension arguments (Plugin -> Page). |
62 const char kJSDocumentDimensionsType[] = "documentDimensions"; | 69 const char kJSDocumentDimensionsType[] = "documentDimensions"; |
63 const char kJSDocumentWidth[] = "width"; | 70 const char kJSDocumentWidth[] = "width"; |
64 const char kJSDocumentHeight[] = "height"; | 71 const char kJSDocumentHeight[] = "height"; |
65 const char kJSPageDimensions[] = "pageDimensions"; | 72 const char kJSPageDimensions[] = "pageDimensions"; |
66 const char kJSPageX[] = "x"; | 73 const char kJSPageX[] = "x"; |
67 const char kJSPageY[] = "y"; | 74 const char kJSPageY[] = "y"; |
68 const char kJSPageWidth[] = "width"; | 75 const char kJSPageWidth[] = "width"; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 } | 274 } |
268 | 275 |
269 } // namespace | 276 } // namespace |
270 | 277 |
271 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) | 278 OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance) |
272 : pp::Instance(instance), | 279 : pp::Instance(instance), |
273 pp::Find_Private(this), | 280 pp::Find_Private(this), |
274 pp::Printing_Dev(this), | 281 pp::Printing_Dev(this), |
275 cursor_(PP_CURSORTYPE_POINTER), | 282 cursor_(PP_CURSORTYPE_POINTER), |
276 zoom_(1.0), | 283 zoom_(1.0), |
284 needs_reraster_(true), | |
285 last_current_scroll_(0, 0), | |
286 was_smaller_(false), | |
277 device_scale_(1.0), | 287 device_scale_(1.0), |
278 full_(false), | 288 full_(false), |
279 paint_manager_(this, this, true), | 289 paint_manager_(this, this, true), |
280 first_paint_(true), | 290 first_paint_(true), |
281 document_load_state_(LOAD_STATE_LOADING), | 291 document_load_state_(LOAD_STATE_LOADING), |
282 preview_document_load_state_(LOAD_STATE_COMPLETE), | 292 preview_document_load_state_(LOAD_STATE_COMPLETE), |
283 uma_(this), | 293 uma_(this), |
284 told_browser_about_unsupported_feature_(false), | 294 told_browser_about_unsupported_feature_(false), |
285 print_preview_page_count_(0), | 295 print_preview_page_count_(0), |
286 last_progress_sent_(0), | 296 last_progress_sent_(0), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 if (!dict.Get(kType).is_string()) { | 398 if (!dict.Get(kType).is_string()) { |
389 NOTREACHED(); | 399 NOTREACHED(); |
390 return; | 400 return; |
391 } | 401 } |
392 | 402 |
393 std::string type = dict.Get(kType).AsString(); | 403 std::string type = dict.Get(kType).AsString(); |
394 | 404 |
395 if (type == kJSViewportType && | 405 if (type == kJSViewportType && |
396 dict.Get(pp::Var(kJSXOffset)).is_number() && | 406 dict.Get(pp::Var(kJSXOffset)).is_number() && |
397 dict.Get(pp::Var(kJSYOffset)).is_number() && | 407 dict.Get(pp::Var(kJSYOffset)).is_number() && |
398 dict.Get(pp::Var(kJSZoom)).is_number()) { | 408 dict.Get(pp::Var(kJSZoom)).is_number() && |
409 dict.Get(pp::Var(kJSPinchPhase)).is_number()) { | |
399 received_viewport_message_ = true; | 410 received_viewport_message_ = true; |
400 stop_scrolling_ = false; | 411 stop_scrolling_ = false; |
412 PinchPhase pinch_phase = | |
413 static_cast<PinchPhase>(dict.Get(pp::Var(kJSPinchPhase)).AsInt()); | |
401 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); | 414 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); |
415 double zoom_delta = zoom / zoom_; | |
416 | |
402 pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(), | 417 pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(), |
403 dict.Get(pp::Var(kJSYOffset)).AsDouble()); | 418 dict.Get(pp::Var(kJSYOffset)).AsDouble()); |
404 | 419 |
420 if (pinch_phase == PINCH_START) { | |
421 last_current_scroll_ = scroll_offset; | |
422 old_zoom_ = zoom; | |
423 initial_zoom_delta_ = zoom_delta; | |
424 was_smaller_ = false; | |
425 needs_reraster_ = false; | |
426 return; | |
427 } else if (pinch_phase == PINCH_UPDATE_ZOOM_IN) { | |
Lei Zhang
2016/10/27 16:56:35
No else after return
Kevin McNee - google account
2016/10/27 21:40:30
Done.
| |
428 if (!(dict.Get(pp::Var(kJSPinchX)).is_number() && | |
429 dict.Get(pp::Var(kJSPinchY)).is_number() && | |
430 dict.Get(pp::Var(kJSPinchVectorX)).is_number() && | |
431 dict.Get(pp::Var(kJSPinchVectorY)).is_number())) { | |
432 NOTREACHED(); | |
433 return; | |
434 } | |
435 | |
436 pp::Point pinch_center(dict.Get(pp::Var(kJSPinchX)).AsDouble(), | |
437 dict.Get(pp::Var(kJSPinchY)).AsDouble()); | |
438 // Pinch vector is the panning caused due to change in pinch | |
439 // center between start and end of the gesture. | |
440 pp::Point pinch_vector = | |
441 pp::Point(dict.Get(kJSPinchVectorX).AsDouble() * zoom_delta, | |
442 dict.Get(kJSPinchVectorY).AsDouble() * zoom_delta); | |
443 pp::Point scroll_delta(0, 0); | |
444 // If the rendered document doesn't fill the display area we will | |
445 // use paint_offset to anchor the paint vertically into the same place. We | |
446 // use the scroll bars instead of the pinch vector to get the actual | |
447 // position on screen of the paint. | |
448 pp::Point paint_offset(0, 0); | |
449 | |
450 if (plugin_size_.width() > GetDocumentPixelWidth() * zoom_delta) { | |
451 // We want to keep the paint in the middle but it must stay in the same | |
452 // position relative to the scroll bars. | |
453 paint_offset = pp::Point(0, (1 - zoom_delta) * pinch_center.y()); | |
454 scroll_delta = pp::Point(0, | |
455 (scroll_offset.y() - | |
456 last_current_scroll_.y() * zoom_delta / initial_zoom_delta_)); | |
457 | |
458 pinch_vector = pp::Point(); | |
459 old_zoom_ = zoom; | |
460 was_smaller_ = true; | |
461 } else if (was_smaller_) { | |
462 pinch_center = pp::Point((plugin_size_.width() / device_scale_) / 2, | |
463 (plugin_size_.height() / device_scale_) / 2); | |
464 paint_offset = pp::Point((1 - zoom / old_zoom_) * pinch_center.x(), | |
465 (1 - zoom_delta) * pinch_center.y()); | |
466 pinch_vector = pp::Point(0, 0); | |
467 scroll_delta = pp::Point( | |
468 (scroll_offset.x() - | |
469 last_current_scroll_.x() * zoom_delta / initial_zoom_delta_), | |
470 (scroll_offset.y() - | |
471 last_current_scroll_.y() * zoom_delta / initial_zoom_delta_)); | |
472 } | |
473 | |
474 paint_manager_.SetTransform(zoom_delta, pinch_center, | |
475 pinch_vector + paint_offset + scroll_delta); | |
476 needs_reraster_ = false; | |
477 return; | |
478 } else if (pinch_phase == PINCH_UPDATE_ZOOM_OUT || | |
479 pinch_phase == PINCH_END) { | |
480 // We reraster on pinch zoom out in order to solve the invalid regions | |
481 // that appear after zooming out. | |
482 // On pinch end the scale is again 1.f and we request a reraster | |
483 // in the new position. | |
484 paint_manager_.SetTransform(1.f); | |
485 was_smaller_ = false; | |
486 needs_reraster_ = true; | |
487 } | |
488 | |
405 // Bound the input parameters. | 489 // Bound the input parameters. |
406 zoom = std::max(kMinZoom, zoom); | 490 zoom = std::max(kMinZoom, zoom); |
407 SetZoom(zoom); | 491 SetZoom(zoom); |
408 scroll_offset = BoundScrollOffsetToDocument(scroll_offset); | 492 scroll_offset = BoundScrollOffsetToDocument(scroll_offset); |
409 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); | 493 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); |
410 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); | 494 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); |
411 } else if (type == kJSGetPasswordCompleteType && | 495 } else if (type == kJSGetPasswordCompleteType && |
412 dict.Get(pp::Var(kJSPassword)).is_string()) { | 496 dict.Get(pp::Var(kJSPassword)).is_string()) { |
413 if (password_callback_) { | 497 if (password_callback_) { |
414 pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_; | 498 pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_; |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 DCHECK(plugin_size_.IsEmpty()); | 865 DCHECK(plugin_size_.IsEmpty()); |
782 return; | 866 return; |
783 } | 867 } |
784 if (first_paint_) { | 868 if (first_paint_) { |
785 first_paint_ = false; | 869 first_paint_ = false; |
786 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); | 870 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); |
787 FillRect(rect, background_color_); | 871 FillRect(rect, background_color_); |
788 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); | 872 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
789 } | 873 } |
790 | 874 |
791 if (!received_viewport_message_) | 875 if (!received_viewport_message_ || !needs_reraster_) |
792 return; | 876 return; |
793 | 877 |
794 engine_->PrePaint(); | 878 engine_->PrePaint(); |
795 | 879 |
796 for (const auto& paint_rect : paint_rects) { | 880 for (const auto& paint_rect : paint_rects) { |
797 // Intersect with plugin area since there could be pending invalidates from | 881 // Intersect with plugin area since there could be pending invalidates from |
798 // when the plugin area was larger. | 882 // when the plugin area was larger. |
799 pp::Rect rect = | 883 pp::Rect rect = |
800 paint_rect.Intersect(pp::Rect(pp::Point(), plugin_size_)); | 884 paint_rect.Intersect(pp::Rect(pp::Point(), plugin_size_)); |
801 if (rect.IsEmpty()) | 885 if (rect.IsEmpty()) |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1534 const pp::FloatPoint& scroll_offset) { | 1618 const pp::FloatPoint& scroll_offset) { |
1535 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1619 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1536 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1620 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1537 float min_y = -top_toolbar_height_; | 1621 float min_y = -top_toolbar_height_; |
1538 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1622 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1539 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1623 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1540 return pp::FloatPoint(x, y); | 1624 return pp::FloatPoint(x, y); |
1541 } | 1625 } |
1542 | 1626 |
1543 } // namespace chrome_pdf | 1627 } // namespace chrome_pdf |
OLD | NEW |