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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 int page_index = 0; | 232 int page_index = 0; |
233 if (!base::StringToInt(url_substr[1], &page_index)) | 233 if (!base::StringToInt(url_substr[1], &page_index)) |
234 return -1; | 234 return -1; |
235 return page_index; | 235 return page_index; |
236 } | 236 } |
237 | 237 |
238 bool IsPrintPreviewUrl(base::StringPiece url) { | 238 bool IsPrintPreviewUrl(base::StringPiece url) { |
239 return url.starts_with(kChromePrint); | 239 return url.starts_with(kChromePrint); |
240 } | 240 } |
241 | 241 |
| 242 void ScaleFloatPoint(float scale, pp::FloatPoint* point) { |
| 243 point->set_x(point->x() * scale); |
| 244 point->set_y(point->y() * scale); |
| 245 } |
| 246 |
242 void ScalePoint(float scale, pp::Point* point) { | 247 void ScalePoint(float scale, pp::Point* point) { |
243 point->set_x(static_cast<int>(point->x() * scale)); | 248 point->set_x(static_cast<int>(point->x() * scale)); |
244 point->set_y(static_cast<int>(point->y() * scale)); | 249 point->set_y(static_cast<int>(point->y() * scale)); |
245 } | 250 } |
246 | 251 |
247 void ScaleRect(float scale, pp::Rect* rect) { | 252 void ScaleRect(float scale, pp::Rect* rect) { |
248 int left = static_cast<int>(floorf(rect->x() * scale)); | 253 int left = static_cast<int>(floorf(rect->x() * scale)); |
249 int top = static_cast<int>(floorf(rect->y() * scale)); | 254 int top = static_cast<int>(floorf(rect->y() * scale)); |
250 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale)); | 255 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale)); |
251 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale)); | 256 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale)); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType)); | 573 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType)); |
569 if (page_number >= 0) | 574 if (page_number >= 0) |
570 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); | 575 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); |
571 PostMessage(reply); | 576 PostMessage(reply); |
572 } else { | 577 } else { |
573 NOTREACHED(); | 578 NOTREACHED(); |
574 } | 579 } |
575 } | 580 } |
576 | 581 |
577 bool OutOfProcessInstance::HandleInputEvent(const pp::InputEvent& event) { | 582 bool OutOfProcessInstance::HandleInputEvent(const pp::InputEvent& event) { |
578 // To simplify things, convert the event into device coordinates if it is | 583 // To simplify things, convert the event into device coordinates. |
579 // a mouse event. | |
580 pp::InputEvent event_device_res(event); | 584 pp::InputEvent event_device_res(event); |
581 { | 585 { |
582 pp::MouseInputEvent mouse_event(event); | 586 pp::MouseInputEvent mouse_event(event); |
583 if (!mouse_event.is_null()) { | 587 if (!mouse_event.is_null()) { |
584 pp::Point point = mouse_event.GetPosition(); | 588 pp::Point point = mouse_event.GetPosition(); |
585 pp::Point movement = mouse_event.GetMovement(); | 589 pp::Point movement = mouse_event.GetMovement(); |
586 ScalePoint(device_scale_, &point); | 590 ScalePoint(device_scale_, &point); |
| 591 point.set_x(point.x() - available_area_.x()); |
| 592 |
587 ScalePoint(device_scale_, &movement); | 593 ScalePoint(device_scale_, &movement); |
588 mouse_event = | 594 mouse_event = |
589 pp::MouseInputEvent(this, event.GetType(), event.GetTimeStamp(), | 595 pp::MouseInputEvent(this, event.GetType(), event.GetTimeStamp(), |
590 event.GetModifiers(), mouse_event.GetButton(), | 596 event.GetModifiers(), mouse_event.GetButton(), |
591 point, mouse_event.GetClickCount(), movement); | 597 point, mouse_event.GetClickCount(), movement); |
592 event_device_res = mouse_event; | 598 event_device_res = mouse_event; |
593 } | 599 } |
594 } | 600 } |
| 601 { |
| 602 pp::TouchInputEvent touch_event(event); |
| 603 if (!touch_event.is_null()) { |
| 604 pp::TouchInputEvent new_touch_event = pp::TouchInputEvent( |
| 605 this, touch_event.GetType(), touch_event.GetTimeStamp(), |
| 606 touch_event.GetModifiers()); |
595 | 607 |
596 pp::InputEvent offset_event(event_device_res); | 608 for (uint32_t i = 0; |
597 switch (offset_event.GetType()) { | 609 i < touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES); |
598 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 610 i++) { |
599 case PP_INPUTEVENT_TYPE_MOUSEUP: | 611 pp::TouchPoint touch_point = |
600 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 612 touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, i); |
601 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 613 |
602 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | 614 pp::FloatPoint point = touch_point.position(); |
603 pp::MouseInputEvent mouse_event(event_device_res); | 615 |
604 pp::MouseInputEvent mouse_event_dip(event); | 616 // Account for the scroll position. Touch events are in DOM coordinates |
605 pp::Point point = mouse_event.GetPosition(); | 617 // where mouse events appear to be in screen coordinates. |
606 point.set_x(point.x() - available_area_.x()); | 618 point.set_x(scroll_offset_.x() + point.x()); |
607 offset_event = pp::MouseInputEvent( | 619 point.set_y(scroll_offset_.y() + point.y()); |
608 this, event.GetType(), event.GetTimeStamp(), event.GetModifiers(), | 620 ScaleFloatPoint(device_scale_, &point); |
609 mouse_event.GetButton(), point, mouse_event.GetClickCount(), | 621 |
610 mouse_event.GetMovement()); | 622 point.set_x(point.x() - available_area_.x()); |
611 break; | 623 |
| 624 new_touch_event.AddTouchPoint( |
| 625 PP_TOUCHLIST_TYPE_TARGETTOUCHES, |
| 626 {touch_point.id(), point, touch_point.radii(), |
| 627 touch_point.rotation_angle(), touch_point.pressure()}); |
| 628 } |
| 629 event_device_res = new_touch_event; |
612 } | 630 } |
613 default: | |
614 break; | |
615 } | 631 } |
616 if (engine_->HandleEvent(offset_event)) | 632 |
| 633 if (engine_->HandleEvent(event_device_res)) |
617 return true; | 634 return true; |
618 | 635 |
619 // Middle click is used for scrolling and is handled by the container page. | 636 // Middle click is used for scrolling and is handled by the container page. |
620 pp::MouseInputEvent mouse_event(event_device_res); | 637 pp::MouseInputEvent mouse_event(event_device_res); |
621 if (!mouse_event.is_null() && | 638 if (!mouse_event.is_null() && |
622 mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { | 639 mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { |
623 return false; | 640 return false; |
624 } | 641 } |
625 | 642 |
626 // Return true for unhandled clicks so the plugin takes focus. | 643 // Return true for unhandled clicks so the plugin takes focus. |
(...skipping 24 matching lines...) Expand all Loading... |
651 | 668 |
652 if (image_data_.is_null()) { | 669 if (image_data_.is_null()) { |
653 DCHECK(plugin_size_.IsEmpty()); | 670 DCHECK(plugin_size_.IsEmpty()); |
654 return; | 671 return; |
655 } | 672 } |
656 | 673 |
657 OnGeometryChanged(zoom_, old_device_scale); | 674 OnGeometryChanged(zoom_, old_device_scale); |
658 } | 675 } |
659 | 676 |
660 if (!stop_scrolling_) { | 677 if (!stop_scrolling_) { |
661 pp::Point scroll_offset(view.GetScrollOffset()); | 678 scroll_offset_ = view.GetScrollOffset(); |
662 // Because view messages come from the DOM, the coordinates of the viewport | 679 // Because view messages come from the DOM, the coordinates of the viewport |
663 // are 0-based (i.e. they do not correspond to the viewport's coordinates in | 680 // are 0-based (i.e. they do not correspond to the viewport's coordinates in |
664 // JS), so we need to subtract the toolbar height to convert them into | 681 // JS), so we need to subtract the toolbar height to convert them into |
665 // viewport coordinates. | 682 // viewport coordinates. |
666 pp::FloatPoint scroll_offset_float(scroll_offset.x(), | 683 pp::FloatPoint scroll_offset_float( |
667 scroll_offset.y() - top_toolbar_height_); | 684 scroll_offset_.x(), scroll_offset_.y() - top_toolbar_height_); |
668 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); | 685 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); |
669 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); | 686 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); |
670 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); | 687 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); |
671 } | 688 } |
672 } | 689 } |
673 | 690 |
674 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( | 691 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( |
675 PP_PdfPrintPresetOptions_Dev* options) { | 692 PP_PdfPrintPresetOptions_Dev* options) { |
676 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | 693 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
677 options->duplex = | 694 options->duplex = |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 void OutOfProcessInstance::DidOpenPreview(int32_t result) { | 971 void OutOfProcessInstance::DidOpenPreview(int32_t result) { |
955 if (result == PP_OK) { | 972 if (result == PP_OK) { |
956 preview_client_ = base::MakeUnique<PreviewModeClient>(this); | 973 preview_client_ = base::MakeUnique<PreviewModeClient>(this); |
957 preview_engine_ = PDFEngine::Create(preview_client_.get()); | 974 preview_engine_ = PDFEngine::Create(preview_client_.get()); |
958 preview_engine_->HandleDocumentLoad(embed_preview_loader_); | 975 preview_engine_->HandleDocumentLoad(embed_preview_loader_); |
959 } else { | 976 } else { |
960 NOTREACHED(); | 977 NOTREACHED(); |
961 } | 978 } |
962 } | 979 } |
963 | 980 |
| 981 void OutOfProcessInstance::OnClientTouchTimerFired(int32_t id) { |
| 982 engine_->OnTouchTimerCallback(id); |
| 983 } |
| 984 |
964 void OutOfProcessInstance::OnClientTimerFired(int32_t id) { | 985 void OutOfProcessInstance::OnClientTimerFired(int32_t id) { |
965 engine_->OnCallback(id); | 986 engine_->OnCallback(id); |
966 } | 987 } |
967 | 988 |
968 void OutOfProcessInstance::CalculateBackgroundParts() { | 989 void OutOfProcessInstance::CalculateBackgroundParts() { |
969 background_parts_.clear(); | 990 background_parts_.clear(); |
970 int left_width = available_area_.x(); | 991 int left_width = available_area_.x(); |
971 int right_start = available_area_.right(); | 992 int right_start = available_area_.right(); |
972 int right_width = abs(plugin_size_.width() - available_area_.right()); | 993 int right_width = abs(plugin_size_.width() - available_area_.right()); |
973 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); | 994 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 // Disable save and print until the document is fully loaded, since they | 1263 // Disable save and print until the document is fully loaded, since they |
1243 // would generate an incomplete document. Need to do this each time we | 1264 // would generate an incomplete document. Need to do this each time we |
1244 // call DidStartLoading since that resets the content restrictions. | 1265 // call DidStartLoading since that resets the content restrictions. |
1245 pp::PDF::SetContentRestriction( | 1266 pp::PDF::SetContentRestriction( |
1246 this, CONTENT_RESTRICTION_SAVE | CONTENT_RESTRICTION_PRINT); | 1267 this, CONTENT_RESTRICTION_SAVE | CONTENT_RESTRICTION_PRINT); |
1247 } | 1268 } |
1248 | 1269 |
1249 return CreateURLLoaderInternal(); | 1270 return CreateURLLoaderInternal(); |
1250 } | 1271 } |
1251 | 1272 |
| 1273 void OutOfProcessInstance::ScheduleTouchTimerCallback(int id, int delay_in_ms) { |
| 1274 pp::CompletionCallback callback = callback_factory_.NewCallback( |
| 1275 &OutOfProcessInstance::OnClientTouchTimerFired); |
| 1276 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); |
| 1277 } |
| 1278 |
1252 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { | 1279 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { |
1253 pp::CompletionCallback callback = | 1280 pp::CompletionCallback callback = |
1254 callback_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); | 1281 callback_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); |
1255 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); | 1282 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); |
1256 } | 1283 } |
1257 | 1284 |
1258 void OutOfProcessInstance::SearchString( | 1285 void OutOfProcessInstance::SearchString( |
1259 const base::char16* string, | 1286 const base::char16* string, |
1260 const base::char16* term, | 1287 const base::char16* term, |
1261 bool case_sensitive, | 1288 bool case_sensitive, |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 const pp::FloatPoint& scroll_offset) { | 1637 const pp::FloatPoint& scroll_offset) { |
1611 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1638 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1612 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1639 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1613 float min_y = -top_toolbar_height_; | 1640 float min_y = -top_toolbar_height_; |
1614 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1641 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1615 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1642 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1616 return pp::FloatPoint(x, y); | 1643 return pp::FloatPoint(x, y); |
1617 } | 1644 } |
1618 | 1645 |
1619 } // namespace chrome_pdf | 1646 } // namespace chrome_pdf |
OLD | NEW |