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 <algorithm> // for min/max() | 7 #include <algorithm> // for min/max() |
8 #define _USE_MATH_DEFINES // for M_PI | 8 #define _USE_MATH_DEFINES // for M_PI |
9 #include <cmath> // for log() and pow() | 9 #include <cmath> // for log() and pow() |
10 #include <math.h> | 10 #include <math.h> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const char kJSRotateClockwiseType[] = "rotateClockwise"; | 133 const char kJSRotateClockwiseType[] = "rotateClockwise"; |
134 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; | 134 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; |
135 // Select all text in the document (Page -> Plugin) | 135 // Select all text in the document (Page -> Plugin) |
136 const char kJSSelectAllType[] = "selectAll"; | 136 const char kJSSelectAllType[] = "selectAll"; |
137 // Get the selected text in the document (Page -> Plugin) | 137 // Get the selected text in the document (Page -> Plugin) |
138 const char kJSGetSelectedTextType[] = "getSelectedText"; | 138 const char kJSGetSelectedTextType[] = "getSelectedText"; |
139 // Reply with selected text (Plugin -> Page) | 139 // Reply with selected text (Plugin -> Page) |
140 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; | 140 const char kJSGetSelectedTextReplyType[] = "getSelectedTextReply"; |
141 const char kJSSelectedText[] = "selectedText"; | 141 const char kJSSelectedText[] = "selectedText"; |
142 | 142 |
143 // List of named destinations (Plugin -> Page) | 143 // Get the named destination with the given name (Page -> Plugin) |
144 const char kJSSetNamedDestinationsType[] = "setNamedDestinations"; | 144 const char KJSGetNamedDestinationType[] = "getNamedDestination"; |
145 const char kJSNamedDestinations[] = "namedDestinations"; | 145 const char KJSGetNamedDestination[] = "namedDestination"; |
| 146 // Reply with the page number of the named destination (Plugin -> Page) |
| 147 const char kJSGetNamedDestinationReplyType[] = "getNamedDestinationReply"; |
| 148 const char kJSNamedDestinationPageNumber[] = "pageNumber"; |
146 | 149 |
147 // Selecting text in document (Plugin -> Page) | 150 // Selecting text in document (Plugin -> Page) |
148 const char kJSSetIsSelectingType[] = "setIsSelecting"; | 151 const char kJSSetIsSelectingType[] = "setIsSelecting"; |
149 const char kJSIsSelecting[] = "isSelecting"; | 152 const char kJSIsSelecting[] = "isSelecting"; |
150 | 153 |
151 const int kFindResultCooldownMs = 100; | 154 const int kFindResultCooldownMs = 100; |
152 | 155 |
153 const double kMinZoom = 0.01; | 156 const double kMinZoom = 0.01; |
154 | 157 |
155 namespace { | 158 namespace { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 } else if (type == kJSStopScrollingType) { | 476 } else if (type == kJSStopScrollingType) { |
474 stop_scrolling_ = true; | 477 stop_scrolling_ = true; |
475 } else if (type == kJSGetSelectedTextType) { | 478 } else if (type == kJSGetSelectedTextType) { |
476 std::string selected_text = engine_->GetSelectedText(); | 479 std::string selected_text = engine_->GetSelectedText(); |
477 // Always return unix newlines to JS. | 480 // Always return unix newlines to JS. |
478 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); | 481 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text); |
479 pp::VarDictionary reply; | 482 pp::VarDictionary reply; |
480 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); | 483 reply.Set(pp::Var(kType), pp::Var(kJSGetSelectedTextReplyType)); |
481 reply.Set(pp::Var(kJSSelectedText), selected_text); | 484 reply.Set(pp::Var(kJSSelectedText), selected_text); |
482 PostMessage(reply); | 485 PostMessage(reply); |
| 486 } else if (type == KJSGetNamedDestinationType && |
| 487 dict.Get(pp::Var(KJSGetNamedDestination)).is_string()) { |
| 488 int page_number = engine_->GetNamedDestinationPage( |
| 489 dict.Get(pp::Var(KJSGetNamedDestination)).AsString()); |
| 490 pp::VarDictionary reply; |
| 491 reply.Set(pp::Var(kType), pp::Var(kJSGetNamedDestinationReplyType)); |
| 492 if (page_number >= 0) |
| 493 reply.Set(pp::Var(kJSNamedDestinationPageNumber), page_number); |
| 494 PostMessage(reply); |
483 } else { | 495 } else { |
484 NOTREACHED(); | 496 NOTREACHED(); |
485 } | 497 } |
486 } | 498 } |
487 | 499 |
488 bool OutOfProcessInstance::HandleInputEvent( | 500 bool OutOfProcessInstance::HandleInputEvent( |
489 const pp::InputEvent& event) { | 501 const pp::InputEvent& event) { |
490 // To simplify things, convert the event into device coordinates if it is | 502 // To simplify things, convert the event into device coordinates if it is |
491 // a mouse event. | 503 // a mouse event. |
492 pp::InputEvent event_device_res(event); | 504 pp::InputEvent event_device_res(event); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 document_load_state_ = LOAD_STATE_COMPLETE; | 1100 document_load_state_ = LOAD_STATE_COMPLETE; |
1089 UserMetricsRecordAction("PDF.LoadSuccess"); | 1101 UserMetricsRecordAction("PDF.LoadSuccess"); |
1090 | 1102 |
1091 // Note: If we are in print preview mode the scroll location is retained | 1103 // Note: If we are in print preview mode the scroll location is retained |
1092 // across document loads so we don't want to scroll again and override it. | 1104 // across document loads so we don't want to scroll again and override it. |
1093 if (IsPrintPreview()) { | 1105 if (IsPrintPreview()) { |
1094 AppendBlankPrintPreviewPages(); | 1106 AppendBlankPrintPreviewPages(); |
1095 OnGeometryChanged(0, 0); | 1107 OnGeometryChanged(0, 0); |
1096 } | 1108 } |
1097 | 1109 |
1098 pp::VarDictionary named_destinations_message; | |
1099 pp::VarDictionary named_destinations = engine_->GetNamedDestinations(); | |
1100 named_destinations_message.Set(pp::Var(kType), | |
1101 pp::Var(kJSSetNamedDestinationsType)); | |
1102 named_destinations_message.Set(pp::Var(kJSNamedDestinations), | |
1103 pp::Var(named_destinations)); | |
1104 PostMessage(named_destinations_message); | |
1105 | |
1106 pp::VarDictionary bookmarks_message; | 1110 pp::VarDictionary bookmarks_message; |
1107 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); | 1111 bookmarks_message.Set(pp::Var(kType), pp::Var(kJSBookmarksType)); |
1108 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); | 1112 bookmarks_message.Set(pp::Var(kJSBookmarks), engine_->GetBookmarks()); |
1109 PostMessage(bookmarks_message); | 1113 PostMessage(bookmarks_message); |
1110 | 1114 |
1111 pp::VarDictionary progress_message; | 1115 pp::VarDictionary progress_message; |
1112 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1116 progress_message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); |
1113 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); | 1117 progress_message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)); |
1114 PostMessage(progress_message); | 1118 PostMessage(progress_message); |
1115 | 1119 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1407 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1404 const pp::FloatPoint& scroll_offset) { | 1408 const pp::FloatPoint& scroll_offset) { |
1405 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1409 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1406 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1410 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1407 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1411 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1408 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1412 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1409 return pp::FloatPoint(x, y); | 1413 return pp::FloatPoint(x, y); |
1410 } | 1414 } |
1411 | 1415 |
1412 } // namespace chrome_pdf | 1416 } // namespace chrome_pdf |
OLD | NEW |