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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 int page_index = 0; | 235 int page_index = 0; |
236 if (!base::StringToInt(url_substr[1], &page_index)) | 236 if (!base::StringToInt(url_substr[1], &page_index)) |
237 return -1; | 237 return -1; |
238 return page_index; | 238 return page_index; |
239 } | 239 } |
240 | 240 |
241 bool IsPrintPreviewUrl(const std::string& url) { | 241 bool IsPrintPreviewUrl(const std::string& url) { |
242 return url.substr(0, strlen(kChromePrint)) == kChromePrint; | 242 return url.substr(0, strlen(kChromePrint)) == kChromePrint; |
243 } | 243 } |
244 | 244 |
| 245 void ScaleFloatPoint(float scale, pp::FloatPoint* point) { |
| 246 point->set_x(point->x() * scale); |
| 247 point->set_y(point->y() * scale); |
| 248 } |
| 249 |
245 void ScalePoint(float scale, pp::Point* point) { | 250 void ScalePoint(float scale, pp::Point* point) { |
246 point->set_x(static_cast<int>(point->x() * scale)); | 251 point->set_x(static_cast<int>(point->x() * scale)); |
247 point->set_y(static_cast<int>(point->y() * scale)); | 252 point->set_y(static_cast<int>(point->y() * scale)); |
248 } | 253 } |
249 | 254 |
250 void ScaleRect(float scale, pp::Rect* rect) { | 255 void ScaleRect(float scale, pp::Rect* rect) { |
251 int left = static_cast<int>(floorf(rect->x() * scale)); | 256 int left = static_cast<int>(floorf(rect->x() * scale)); |
252 int top = static_cast<int>(floorf(rect->y() * scale)); | 257 int top = static_cast<int>(floorf(rect->y() * scale)); |
253 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale)); | 258 int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale)); |
254 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale)); | 259 int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale)); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 if (page_number >= 0) | 584 if (page_number >= 0) |
580 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); | 585 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); |
581 PostMessage(reply); | 586 PostMessage(reply); |
582 } else { | 587 } else { |
583 NOTREACHED(); | 588 NOTREACHED(); |
584 } | 589 } |
585 } | 590 } |
586 | 591 |
587 bool OutOfProcessInstance::HandleInputEvent( | 592 bool OutOfProcessInstance::HandleInputEvent( |
588 const pp::InputEvent& event) { | 593 const pp::InputEvent& event) { |
589 // To simplify things, convert the event into device coordinates if it is | 594 // To simplify things, convert the event into device coordinates. |
590 // a mouse event. | |
591 pp::InputEvent event_device_res(event); | 595 pp::InputEvent event_device_res(event); |
592 { | 596 { |
593 pp::MouseInputEvent mouse_event(event); | 597 pp::MouseInputEvent mouse_event(event); |
594 if (!mouse_event.is_null()) { | 598 if (!mouse_event.is_null()) { |
595 pp::Point point = mouse_event.GetPosition(); | 599 pp::Point point = mouse_event.GetPosition(); |
596 pp::Point movement = mouse_event.GetMovement(); | 600 pp::Point movement = mouse_event.GetMovement(); |
597 ScalePoint(device_scale_, &point); | 601 ScalePoint(device_scale_, &point); |
| 602 point.set_x(point.x() - available_area_.x()); |
| 603 |
598 ScalePoint(device_scale_, &movement); | 604 ScalePoint(device_scale_, &movement); |
599 mouse_event = pp::MouseInputEvent( | 605 mouse_event = pp::MouseInputEvent( |
600 this, | 606 this, |
601 event.GetType(), | 607 event.GetType(), |
602 event.GetTimeStamp(), | 608 event.GetTimeStamp(), |
603 event.GetModifiers(), | 609 event.GetModifiers(), |
604 mouse_event.GetButton(), | 610 mouse_event.GetButton(), |
605 point, | 611 point, |
606 mouse_event.GetClickCount(), | 612 mouse_event.GetClickCount(), |
607 movement); | 613 movement); |
608 event_device_res = mouse_event; | 614 event_device_res = mouse_event; |
609 } | 615 } |
610 } | 616 } |
| 617 { |
| 618 pp::TouchInputEvent touch_event(event); |
| 619 if (!touch_event.is_null()) { |
| 620 pp::TouchInputEvent new_touch_event = pp::TouchInputEvent( |
| 621 this, touch_event.GetType(), touch_event.GetTimeStamp(), |
| 622 touch_event.GetModifiers()); |
611 | 623 |
612 pp::InputEvent offset_event(event_device_res); | 624 for (uint32_t i = 0; |
613 switch (offset_event.GetType()) { | 625 i < touch_event.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES); |
614 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 626 i++) { |
615 case PP_INPUTEVENT_TYPE_MOUSEUP: | 627 pp::TouchPoint touch_point = |
616 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 628 touch_event.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, i); |
617 case PP_INPUTEVENT_TYPE_MOUSEENTER: | 629 |
618 case PP_INPUTEVENT_TYPE_MOUSELEAVE: { | 630 pp::FloatPoint point = touch_point.position(); |
619 pp::MouseInputEvent mouse_event(event_device_res); | 631 |
620 pp::MouseInputEvent mouse_event_dip(event); | 632 // Account for the scroll position. Touch events are in DOM coordinates |
621 pp::Point point = mouse_event.GetPosition(); | 633 // where mouse events appear to be in screen coordinates. |
622 point.set_x(point.x() - available_area_.x()); | 634 point.set_x(scroll_offset_.x() + point.x()); |
623 offset_event = pp::MouseInputEvent( | 635 point.set_y(scroll_offset_.y() + point.y()); |
624 this, | 636 ScaleFloatPoint(device_scale_, &point); |
625 event.GetType(), | 637 |
626 event.GetTimeStamp(), | 638 point.set_x(point.x() - available_area_.x()); |
627 event.GetModifiers(), | 639 |
628 mouse_event.GetButton(), | 640 new_touch_event.AddTouchPoint( |
629 point, | 641 PP_TOUCHLIST_TYPE_TARGETTOUCHES, |
630 mouse_event.GetClickCount(), | 642 {touch_point.id(), point, touch_point.radii(), |
631 mouse_event.GetMovement()); | 643 touch_point.rotation_angle(), touch_point.pressure()}); |
632 break; | 644 } |
| 645 event_device_res = new_touch_event; |
633 } | 646 } |
634 default: | |
635 break; | |
636 } | 647 } |
637 if (engine_->HandleEvent(offset_event)) | 648 |
| 649 if (engine_->HandleEvent(event_device_res)) |
638 return true; | 650 return true; |
639 | 651 |
640 // Middle click is used for scrolling and is handled by the container page. | 652 // Middle click is used for scrolling and is handled by the container page. |
641 pp::MouseInputEvent mouse_event(event_device_res); | 653 pp::MouseInputEvent mouse_event(event_device_res); |
642 if (!mouse_event.is_null() && | 654 if (!mouse_event.is_null() && |
643 mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { | 655 mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { |
644 return false; | 656 return false; |
645 } | 657 } |
646 | 658 |
647 // Return true for unhandled clicks so the plugin takes focus. | 659 // Return true for unhandled clicks so the plugin takes focus. |
(...skipping 27 matching lines...) Expand all Loading... |
675 | 687 |
676 if (image_data_.is_null()) { | 688 if (image_data_.is_null()) { |
677 DCHECK(plugin_size_.IsEmpty()); | 689 DCHECK(plugin_size_.IsEmpty()); |
678 return; | 690 return; |
679 } | 691 } |
680 | 692 |
681 OnGeometryChanged(zoom_, old_device_scale); | 693 OnGeometryChanged(zoom_, old_device_scale); |
682 } | 694 } |
683 | 695 |
684 if (!stop_scrolling_) { | 696 if (!stop_scrolling_) { |
685 pp::Point scroll_offset(view.GetScrollOffset()); | 697 scroll_offset_ = view.GetScrollOffset(); |
686 // Because view messages come from the DOM, the coordinates of the viewport | 698 // Because view messages come from the DOM, the coordinates of the viewport |
687 // are 0-based (i.e. they do not correspond to the viewport's coordinates in | 699 // are 0-based (i.e. they do not correspond to the viewport's coordinates in |
688 // JS), so we need to subtract the toolbar height to convert them into | 700 // JS), so we need to subtract the toolbar height to convert them into |
689 // viewport coordinates. | 701 // viewport coordinates. |
690 pp::FloatPoint scroll_offset_float(scroll_offset.x(), | 702 pp::FloatPoint scroll_offset_float( |
691 scroll_offset.y() - top_toolbar_height_); | 703 scroll_offset_.x(), scroll_offset_.y() - top_toolbar_height_); |
692 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); | 704 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); |
693 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); | 705 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); |
694 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); | 706 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); |
695 } | 707 } |
696 } | 708 } |
697 | 709 |
698 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( | 710 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( |
699 PP_PdfPrintPresetOptions_Dev* options) { | 711 PP_PdfPrintPresetOptions_Dev* options) { |
700 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | 712 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
701 options->duplex = | 713 options->duplex = |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 void OutOfProcessInstance::DidOpenPreview(int32_t result) { | 993 void OutOfProcessInstance::DidOpenPreview(int32_t result) { |
982 if (result == PP_OK) { | 994 if (result == PP_OK) { |
983 preview_client_ = base::MakeUnique<PreviewModeClient>(this); | 995 preview_client_ = base::MakeUnique<PreviewModeClient>(this); |
984 preview_engine_.reset(PDFEngine::Create(preview_client_.get())); | 996 preview_engine_.reset(PDFEngine::Create(preview_client_.get())); |
985 preview_engine_->HandleDocumentLoad(embed_preview_loader_); | 997 preview_engine_->HandleDocumentLoad(embed_preview_loader_); |
986 } else { | 998 } else { |
987 NOTREACHED(); | 999 NOTREACHED(); |
988 } | 1000 } |
989 } | 1001 } |
990 | 1002 |
| 1003 void OutOfProcessInstance::OnClientTouchTimerFired(int32_t id) { |
| 1004 engine_->OnTouchTimerCallback(id); |
| 1005 } |
| 1006 |
991 void OutOfProcessInstance::OnClientTimerFired(int32_t id) { | 1007 void OutOfProcessInstance::OnClientTimerFired(int32_t id) { |
992 engine_->OnCallback(id); | 1008 engine_->OnCallback(id); |
993 } | 1009 } |
994 | 1010 |
995 void OutOfProcessInstance::CalculateBackgroundParts() { | 1011 void OutOfProcessInstance::CalculateBackgroundParts() { |
996 background_parts_.clear(); | 1012 background_parts_.clear(); |
997 int left_width = available_area_.x(); | 1013 int left_width = available_area_.x(); |
998 int right_start = available_area_.right(); | 1014 int right_start = available_area_.right(); |
999 int right_width = abs(plugin_size_.width() - available_area_.right()); | 1015 int right_width = abs(plugin_size_.width() - available_area_.right()); |
1000 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); | 1016 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 // Disable save and print until the document is fully loaded, since they | 1288 // Disable save and print until the document is fully loaded, since they |
1273 // would generate an incomplete document. Need to do this each time we | 1289 // would generate an incomplete document. Need to do this each time we |
1274 // call DidStartLoading since that resets the content restrictions. | 1290 // call DidStartLoading since that resets the content restrictions. |
1275 pp::PDF::SetContentRestriction(this, CONTENT_RESTRICTION_SAVE | | 1291 pp::PDF::SetContentRestriction(this, CONTENT_RESTRICTION_SAVE | |
1276 CONTENT_RESTRICTION_PRINT); | 1292 CONTENT_RESTRICTION_PRINT); |
1277 } | 1293 } |
1278 | 1294 |
1279 return CreateURLLoaderInternal(); | 1295 return CreateURLLoaderInternal(); |
1280 } | 1296 } |
1281 | 1297 |
| 1298 void OutOfProcessInstance::ScheduleTouchTimerCallback(int id, int delay_in_ms) { |
| 1299 pp::CompletionCallback callback = timer_factory_.NewCallback( |
| 1300 &OutOfProcessInstance::OnClientTouchTimerFired); |
| 1301 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); |
| 1302 } |
| 1303 |
1282 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { | 1304 void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) { |
1283 pp::CompletionCallback callback = | 1305 pp::CompletionCallback callback = |
1284 timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); | 1306 timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired); |
1285 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); | 1307 pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id); |
1286 } | 1308 } |
1287 | 1309 |
1288 void OutOfProcessInstance::SearchString(const base::char16* string, | 1310 void OutOfProcessInstance::SearchString(const base::char16* string, |
1289 const base::char16* term, | 1311 const base::char16* term, |
1290 bool case_sensitive, | 1312 bool case_sensitive, |
1291 std::vector<SearchStringResult>* results) { | 1313 std::vector<SearchStringResult>* results) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 const pp::FloatPoint& scroll_offset) { | 1675 const pp::FloatPoint& scroll_offset) { |
1654 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1676 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1655 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1677 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1656 float min_y = -top_toolbar_height_; | 1678 float min_y = -top_toolbar_height_; |
1657 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1679 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1658 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1680 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
1659 return pp::FloatPoint(x, y); | 1681 return pp::FloatPoint(x, y); |
1660 } | 1682 } |
1661 | 1683 |
1662 } // namespace chrome_pdf | 1684 } // namespace chrome_pdf |
OLD | NEW |