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