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