Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 // Open the email editor with the given parameters (Plugin -> Page) | 120 // Open the email editor with the given parameters (Plugin -> Page) |
| 121 const char kJSEmailType[] = "email"; | 121 const char kJSEmailType[] = "email"; |
| 122 const char kJSEmailTo[] = "to"; | 122 const char kJSEmailTo[] = "to"; |
| 123 const char kJSEmailCc[] = "cc"; | 123 const char kJSEmailCc[] = "cc"; |
| 124 const char kJSEmailBcc[] = "bcc"; | 124 const char kJSEmailBcc[] = "bcc"; |
| 125 const char kJSEmailSubject[] = "subject"; | 125 const char kJSEmailSubject[] = "subject"; |
| 126 const char kJSEmailBody[] = "body"; | 126 const char kJSEmailBody[] = "body"; |
| 127 // Rotation (Page -> Plugin) | 127 // Rotation (Page -> Plugin) |
| 128 const char kJSRotateClockwiseType[] = "rotateClockwise"; | 128 const char kJSRotateClockwiseType[] = "rotateClockwise"; |
| 129 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; | 129 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; |
| 130 // SelectAll content (Page -> Plugin) | |
|
raymes
2014/10/02 14:18:56
nit: // Select all text in the document (Page -> P
Deepak
2014/10/02 14:57:34
Done.
| |
| 131 const char kJSSelectAllType[] = "selectAll"; | |
| 130 | 132 |
| 131 const int kFindResultCooldownMs = 100; | 133 const int kFindResultCooldownMs = 100; |
| 132 | 134 |
| 133 const double kMinZoom = 0.01; | 135 const double kMinZoom = 0.01; |
| 134 | 136 |
| 135 namespace { | 137 namespace { |
| 136 | 138 |
| 137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 139 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
| 138 | 140 |
| 139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 141 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 callback.Run(PP_OK); | 376 callback.Run(PP_OK); |
| 375 } else { | 377 } else { |
| 376 NOTREACHED(); | 378 NOTREACHED(); |
| 377 } | 379 } |
| 378 } else if (type == kJSPrintType) { | 380 } else if (type == kJSPrintType) { |
| 379 Print(); | 381 Print(); |
| 380 } else if (type == kJSRotateClockwiseType) { | 382 } else if (type == kJSRotateClockwiseType) { |
| 381 RotateClockwise(); | 383 RotateClockwise(); |
| 382 } else if (type == kJSRotateCounterclockwiseType) { | 384 } else if (type == kJSRotateCounterclockwiseType) { |
| 383 RotateCounterclockwise(); | 385 RotateCounterclockwise(); |
| 386 } else if (type == kJSSelectAllType) { | |
| 387 engine_->SelectAll(); | |
| 384 } else if (type == kJSResetPrintPreviewModeType && | 388 } else if (type == kJSResetPrintPreviewModeType && |
| 385 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() && | 389 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() && |
| 386 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && | 390 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && |
| 387 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { | 391 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { |
| 388 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); | 392 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); |
| 389 preview_pages_info_ = std::queue<PreviewPageInfo>(); | 393 preview_pages_info_ = std::queue<PreviewPageInfo>(); |
| 390 preview_document_load_state_ = LOAD_STATE_COMPLETE; | 394 preview_document_load_state_ = LOAD_STATE_COMPLETE; |
| 391 document_load_state_ = LOAD_STATE_LOADING; | 395 document_load_state_ = LOAD_STATE_LOADING; |
| 392 LoadUrl(url_); | 396 LoadUrl(url_); |
| 393 preview_engine_.reset(); | 397 preview_engine_.reset(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 } | 485 } |
| 482 default: | 486 default: |
| 483 break; | 487 break; |
| 484 } | 488 } |
| 485 if (engine_->HandleEvent(offset_event)) | 489 if (engine_->HandleEvent(offset_event)) |
| 486 return true; | 490 return true; |
| 487 | 491 |
| 488 // TODO(raymes): Implement this scroll behavior in JS: | 492 // TODO(raymes): Implement this scroll behavior in JS: |
| 489 // When click+dragging, scroll the document correctly. | 493 // When click+dragging, scroll the document correctly. |
| 490 | 494 |
| 491 if (event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN && | |
| 492 event.GetModifiers() & kDefaultKeyModifier) { | |
| 493 pp::KeyboardInputEvent keyboard_event(event); | |
| 494 switch (keyboard_event.GetKeyCode()) { | |
| 495 case 'A': | |
| 496 engine_->SelectAll(); | |
| 497 return true; | |
| 498 } | |
| 499 } | |
| 500 | |
| 501 // Return true for unhandled clicks so the plugin takes focus. | 495 // Return true for unhandled clicks so the plugin takes focus. |
| 502 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); | 496 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); |
| 503 } | 497 } |
| 504 | 498 |
| 505 void OutOfProcessInstance::DidChangeView(const pp::View& view) { | 499 void OutOfProcessInstance::DidChangeView(const pp::View& view) { |
| 506 pp::Rect view_rect(view.GetRect()); | 500 pp::Rect view_rect(view.GetRect()); |
| 507 float old_device_scale = device_scale_; | 501 float old_device_scale = device_scale_; |
| 508 float device_scale = view.GetDeviceScale(); | 502 float device_scale = view.GetDeviceScale(); |
| 509 pp::Size view_device_size(view_rect.width() * device_scale, | 503 pp::Size view_device_size(view_rect.width() * device_scale, |
| 510 view_rect.height() * device_scale); | 504 view_rect.height() * device_scale); |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( | 1360 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1367 const pp::Point& scroll_offset) { | 1361 const pp::Point& scroll_offset) { |
| 1368 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1362 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1369 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | 1363 int x = std::max(std::min(scroll_offset.x(), max_x), 0); |
| 1370 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1364 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1371 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | 1365 int y = std::max(std::min(scroll_offset.y(), max_y), 0); |
| 1372 return pp::Point(x, y); | 1366 return pp::Point(x, y); |
| 1373 } | 1367 } |
| 1374 | 1368 |
| 1375 } // namespace chrome_pdf | 1369 } // namespace chrome_pdf |
| OLD | NEW |