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