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 const char kJSSelectAllType[] = "selectAll"; | |
|
Nikhil
2014/10/02 12:27:01
How about adding a comment here? Looks to be a pra
Deepak
2014/10/02 12:40:32
Done.
| |
| 130 | 131 |
| 131 const int kFindResultCooldownMs = 100; | 132 const int kFindResultCooldownMs = 100; |
| 132 | 133 |
| 133 const double kMinZoom = 0.01; | 134 const double kMinZoom = 0.01; |
| 134 | 135 |
| 135 namespace { | 136 namespace { |
| 136 | 137 |
| 137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 138 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; |
| 138 | 139 |
| 139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 140 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); | 375 callback.Run(PP_OK); |
| 375 } else { | 376 } else { |
| 376 NOTREACHED(); | 377 NOTREACHED(); |
| 377 } | 378 } |
| 378 } else if (type == kJSPrintType) { | 379 } else if (type == kJSPrintType) { |
| 379 Print(); | 380 Print(); |
| 380 } else if (type == kJSRotateClockwiseType) { | 381 } else if (type == kJSRotateClockwiseType) { |
| 381 RotateClockwise(); | 382 RotateClockwise(); |
| 382 } else if (type == kJSRotateCounterclockwiseType) { | 383 } else if (type == kJSRotateCounterclockwiseType) { |
| 383 RotateCounterclockwise(); | 384 RotateCounterclockwise(); |
| 385 } else if (type == kJSSelectAllType) { | |
| 386 engine_->SelectAll(); | |
| 384 } else if (type == kJSResetPrintPreviewModeType && | 387 } else if (type == kJSResetPrintPreviewModeType && |
| 385 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() && | 388 dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() && |
| 386 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && | 389 dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() && |
| 387 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { | 390 dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) { |
| 388 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); | 391 url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString(); |
| 389 preview_pages_info_ = std::queue<PreviewPageInfo>(); | 392 preview_pages_info_ = std::queue<PreviewPageInfo>(); |
| 390 preview_document_load_state_ = LOAD_STATE_COMPLETE; | 393 preview_document_load_state_ = LOAD_STATE_COMPLETE; |
| 391 document_load_state_ = LOAD_STATE_LOADING; | 394 document_load_state_ = LOAD_STATE_LOADING; |
| 392 LoadUrl(url_); | 395 LoadUrl(url_); |
| 393 preview_engine_.reset(); | 396 preview_engine_.reset(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 mouse_event.GetClickCount(), | 481 mouse_event.GetClickCount(), |
| 479 mouse_event.GetMovement()); | 482 mouse_event.GetMovement()); |
| 480 break; | 483 break; |
| 481 } | 484 } |
| 482 default: | 485 default: |
| 483 break; | 486 break; |
| 484 } | 487 } |
| 485 if (engine_->HandleEvent(offset_event)) | 488 if (engine_->HandleEvent(offset_event)) |
| 486 return true; | 489 return true; |
| 487 | 490 |
| 488 // TODO(raymes): Implement this scroll behavior in JS: | 491 // TODO(raymes): Implement this scroll behavior in JS: |
|
Nikhil
2014/10/02 12:27:00
Is this TODO still valid?
Deepak
2014/10/02 12:40:32
I think this is handles in the js by arrow keys an
| |
| 489 // When click+dragging, scroll the document correctly. | 492 // When click+dragging, scroll the document correctly. |
| 490 | 493 |
| 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. | 494 // Return true for unhandled clicks so the plugin takes focus. |
| 502 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); | 495 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); |
| 503 } | 496 } |
| 504 | 497 |
| 505 void OutOfProcessInstance::DidChangeView(const pp::View& view) { | 498 void OutOfProcessInstance::DidChangeView(const pp::View& view) { |
| 506 pp::Rect view_rect(view.GetRect()); | 499 pp::Rect view_rect(view.GetRect()); |
| 507 float old_device_scale = device_scale_; | 500 float old_device_scale = device_scale_; |
| 508 float device_scale = view.GetDeviceScale(); | 501 float device_scale = view.GetDeviceScale(); |
| 509 pp::Size view_device_size(view_rect.width() * device_scale, | 502 pp::Size view_device_size(view_rect.width() * device_scale, |
| 510 view_rect.height() * device_scale); | 503 view_rect.height() * device_scale); |
| (...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( | 1359 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1367 const pp::Point& scroll_offset) { | 1360 const pp::Point& scroll_offset) { |
| 1368 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1361 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1369 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | 1362 int x = std::max(std::min(scroll_offset.x(), max_x), 0); |
| 1370 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1363 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1371 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | 1364 int y = std::max(std::min(scroll_offset.y(), max_y), 0); |
| 1372 return pp::Point(x, y); | 1365 return pp::Point(x, y); |
| 1373 } | 1366 } |
| 1374 | 1367 |
| 1375 } // namespace chrome_pdf | 1368 } // namespace chrome_pdf |
| OLD | NEW |