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 16 matching lines...) Expand all Loading... | |
| 27 #include "ppapi/c/private/ppb_instance_private.h" | 27 #include "ppapi/c/private/ppb_instance_private.h" |
| 28 #include "ppapi/c/private/ppp_pdf.h" | 28 #include "ppapi/c/private/ppp_pdf.h" |
| 29 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 29 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
| 30 #include "ppapi/cpp/core.h" | 30 #include "ppapi/cpp/core.h" |
| 31 #include "ppapi/cpp/dev/memory_dev.h" | 31 #include "ppapi/cpp/dev/memory_dev.h" |
| 32 #include "ppapi/cpp/dev/text_input_dev.h" | 32 #include "ppapi/cpp/dev/text_input_dev.h" |
| 33 #include "ppapi/cpp/dev/url_util_dev.h" | 33 #include "ppapi/cpp/dev/url_util_dev.h" |
| 34 #include "ppapi/cpp/module.h" | 34 #include "ppapi/cpp/module.h" |
| 35 #include "ppapi/cpp/point.h" | 35 #include "ppapi/cpp/point.h" |
| 36 #include "ppapi/cpp/private/pdf.h" | 36 #include "ppapi/cpp/private/pdf.h" |
| 37 #include "ppapi/cpp/private/var_private.h" | |
| 37 #include "ppapi/cpp/rect.h" | 38 #include "ppapi/cpp/rect.h" |
| 38 #include "ppapi/cpp/resource.h" | 39 #include "ppapi/cpp/resource.h" |
| 39 #include "ppapi/cpp/url_request_info.h" | 40 #include "ppapi/cpp/url_request_info.h" |
| 40 #include "ppapi/cpp/var_array.h" | 41 #include "ppapi/cpp/var_array.h" |
| 41 #include "ppapi/cpp/var_dictionary.h" | 42 #include "ppapi/cpp/var_dictionary.h" |
| 42 #include "ui/events/keycodes/keyboard_codes.h" | 43 #include "ui/events/keycodes/keyboard_codes.h" |
| 43 | 44 |
| 44 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
| 45 #include "base/mac/mac_util.h" | 46 #include "base/mac/mac_util.h" |
| 46 #endif | 47 #endif |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 63 const char kAccessibleLoaded[] = "loaded"; | 64 const char kAccessibleLoaded[] = "loaded"; |
| 64 const char kAccessibleCopyable[] = "copyable"; | 65 const char kAccessibleCopyable[] = "copyable"; |
| 65 | 66 |
| 66 // Constants used in handling postMessage() messages. | 67 // Constants used in handling postMessage() messages. |
| 67 const char* kType = "type"; | 68 const char* kType = "type"; |
| 68 // Viewport message arguments. (Page -> Plugin). | 69 // Viewport message arguments. (Page -> Plugin). |
| 69 const char* kJSViewportType = "viewport"; | 70 const char* kJSViewportType = "viewport"; |
| 70 const char* kJSXOffset = "xOffset"; | 71 const char* kJSXOffset = "xOffset"; |
| 71 const char* kJSYOffset = "yOffset"; | 72 const char* kJSYOffset = "yOffset"; |
| 72 const char* kJSZoom = "zoom"; | 73 const char* kJSZoom = "zoom"; |
| 74 // Stop scrolling message (Page -> Plugin) | |
| 75 const char* kJSStopScrollingType = "stopScrolling"; | |
| 73 // Document dimension arguments (Plugin -> Page). | 76 // Document dimension arguments (Plugin -> Page). |
| 74 const char* kJSDocumentDimensionsType = "documentDimensions"; | 77 const char* kJSDocumentDimensionsType = "documentDimensions"; |
| 75 const char* kJSDocumentWidth = "width"; | 78 const char* kJSDocumentWidth = "width"; |
| 76 const char* kJSDocumentHeight = "height"; | 79 const char* kJSDocumentHeight = "height"; |
| 77 const char* kJSPageDimensions = "pageDimensions"; | 80 const char* kJSPageDimensions = "pageDimensions"; |
| 78 const char* kJSPageX = "x"; | 81 const char* kJSPageX = "x"; |
| 79 const char* kJSPageY = "y"; | 82 const char* kJSPageY = "y"; |
| 80 const char* kJSPageWidth = "width"; | 83 const char* kJSPageWidth = "width"; |
| 81 const char* kJSPageHeight = "height"; | 84 const char* kJSPageHeight = "height"; |
| 82 // Document load progress arguments (Plugin -> Page) | 85 // Document load progress arguments (Plugin -> Page) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 paint_manager_(this, this, true), | 240 paint_manager_(this, this, true), |
| 238 first_paint_(true), | 241 first_paint_(true), |
| 239 document_load_state_(LOAD_STATE_LOADING), | 242 document_load_state_(LOAD_STATE_LOADING), |
| 240 preview_document_load_state_(LOAD_STATE_COMPLETE), | 243 preview_document_load_state_(LOAD_STATE_COMPLETE), |
| 241 uma_(this), | 244 uma_(this), |
| 242 told_browser_about_unsupported_feature_(false), | 245 told_browser_about_unsupported_feature_(false), |
| 243 print_preview_page_count_(0), | 246 print_preview_page_count_(0), |
| 244 last_progress_sent_(0), | 247 last_progress_sent_(0), |
| 245 recently_sent_find_update_(false), | 248 recently_sent_find_update_(false), |
| 246 received_viewport_message_(false), | 249 received_viewport_message_(false), |
| 247 did_call_start_loading_(false) { | 250 did_call_start_loading_(false), |
| 251 stop_scrolling_(false) { | |
| 248 loader_factory_.Initialize(this); | 252 loader_factory_.Initialize(this); |
| 249 timer_factory_.Initialize(this); | 253 timer_factory_.Initialize(this); |
| 250 form_factory_.Initialize(this); | 254 form_factory_.Initialize(this); |
| 251 print_callback_factory_.Initialize(this); | 255 print_callback_factory_.Initialize(this); |
| 252 engine_.reset(PDFEngine::Create(this)); | 256 engine_.reset(PDFEngine::Create(this)); |
| 253 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 257 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
| 254 AddPerInstanceObject(kPPPPdfInterface, this); | 258 AddPerInstanceObject(kPPPPdfInterface, this); |
| 255 | 259 |
| 256 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 260 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 257 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 261 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 return; | 352 return; |
| 349 } | 353 } |
| 350 | 354 |
| 351 std::string type = dict.Get(kType).AsString(); | 355 std::string type = dict.Get(kType).AsString(); |
| 352 | 356 |
| 353 if (type == kJSViewportType && | 357 if (type == kJSViewportType && |
| 354 dict.Get(pp::Var(kJSXOffset)).is_int() && | 358 dict.Get(pp::Var(kJSXOffset)).is_int() && |
| 355 dict.Get(pp::Var(kJSYOffset)).is_int() && | 359 dict.Get(pp::Var(kJSYOffset)).is_int() && |
| 356 dict.Get(pp::Var(kJSZoom)).is_number()) { | 360 dict.Get(pp::Var(kJSZoom)).is_number()) { |
| 357 received_viewport_message_ = true; | 361 received_viewport_message_ = true; |
| 362 stop_scrolling_ = false; | |
| 358 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); | 363 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); |
| 359 int x = dict.Get(pp::Var(kJSXOffset)).AsInt(); | 364 int x = dict.Get(pp::Var(kJSXOffset)).AsInt(); |
| 360 int y = dict.Get(pp::Var(kJSYOffset)).AsInt(); | 365 int y = dict.Get(pp::Var(kJSYOffset)).AsInt(); |
| 361 | 366 |
| 362 // Bound the input parameters. | 367 // Bound the input parameters. |
| 363 zoom = std::max(kMinZoom, zoom); | 368 zoom = std::max(kMinZoom, zoom); |
| 364 int max_x = document_size_.width() * zoom - plugin_dip_size_.width(); | 369 int max_x = document_size_.width() * zoom - plugin_dip_size_.width(); |
| 365 x = std::max(std::min(x, max_x), 0); | 370 x = std::max(std::min(x, max_x), 0); |
| 366 int max_y = document_size_.height() * zoom - plugin_dip_size_.height(); | 371 int max_y = document_size_.height() * zoom - plugin_dip_size_.height(); |
| 367 y = std::max(std::min(y, max_y), 0); | 372 y = std::max(std::min(y, max_y), 0); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 document_load_state_ != LOAD_STATE_LOADING); | 423 document_load_state_ != LOAD_STATE_LOADING); |
| 419 bool has_permissions = | 424 bool has_permissions = |
| 420 engine_->HasPermission(PDFEngine::PERMISSION_COPY) || | 425 engine_->HasPermission(PDFEngine::PERMISSION_COPY) || |
| 421 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE); | 426 engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE); |
| 422 node.SetBoolean(kAccessibleCopyable, has_permissions); | 427 node.SetBoolean(kAccessibleCopyable, has_permissions); |
| 423 std::string json; | 428 std::string json; |
| 424 base::JSONWriter::Write(&node, &json); | 429 base::JSONWriter::Write(&node, &json); |
| 425 reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json)); | 430 reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json)); |
| 426 } | 431 } |
| 427 PostMessage(reply); | 432 PostMessage(reply); |
| 433 } else if (type == kJSStopScrollingType) { | |
| 434 stop_scrolling_ = true; | |
| 428 } else { | 435 } else { |
| 429 NOTREACHED(); | 436 NOTREACHED(); |
| 430 } | 437 } |
| 431 } | 438 } |
| 432 | 439 |
| 433 bool OutOfProcessInstance::HandleInputEvent( | 440 bool OutOfProcessInstance::HandleInputEvent( |
| 434 const pp::InputEvent& event) { | 441 const pp::InputEvent& event) { |
| 435 // To simplify things, convert the event into device coordinates if it is | 442 // To simplify things, convert the event into device coordinates if it is |
| 436 // a mouse event. | 443 // a mouse event. |
| 437 pp::InputEvent event_device_res(event); | 444 pp::InputEvent event_device_res(event); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); | 507 return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN); |
| 501 } | 508 } |
| 502 | 509 |
| 503 void OutOfProcessInstance::DidChangeView(const pp::View& view) { | 510 void OutOfProcessInstance::DidChangeView(const pp::View& view) { |
| 504 pp::Rect view_rect(view.GetRect()); | 511 pp::Rect view_rect(view.GetRect()); |
| 505 float old_device_scale = device_scale_; | 512 float old_device_scale = device_scale_; |
| 506 float device_scale = view.GetDeviceScale(); | 513 float device_scale = view.GetDeviceScale(); |
| 507 pp::Size view_device_size(view_rect.width() * device_scale, | 514 pp::Size view_device_size(view_rect.width() * device_scale, |
| 508 view_rect.height() * device_scale); | 515 view_rect.height() * device_scale); |
| 509 | 516 |
| 517 if (!stop_scrolling_) { | |
| 518 pp::Point scroll_offset(view.GetScrollOffset()); | |
| 519 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | |
|
Lei Zhang
2014/06/23 09:19:41
Can we share some of the code with line 369?
raymes
2014/06/24 00:41:53
Done.
| |
| 520 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | |
| 521 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | |
| 522 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | |
| 523 engine_->ScrolledToXPosition(x * device_scale_); | |
| 524 engine_->ScrolledToYPosition(y * device_scale_); | |
| 525 } | |
| 526 | |
| 510 if (view_device_size == plugin_size_ && device_scale == device_scale_) | 527 if (view_device_size == plugin_size_ && device_scale == device_scale_) |
| 511 return; // We don't care about the position, only the size. | 528 return; // We don't care about the position, only the size. |
| 512 | 529 |
| 513 device_scale_ = device_scale; | 530 device_scale_ = device_scale; |
| 514 plugin_dip_size_ = view_rect.size(); | 531 plugin_dip_size_ = view_rect.size(); |
| 515 plugin_size_ = view_device_size; | 532 plugin_size_ = view_device_size; |
| 516 | 533 |
| 517 paint_manager_.SetSize(view_device_size, device_scale_); | 534 paint_manager_.SetSize(view_device_size, device_scale_); |
| 518 | 535 |
| 519 pp::Size new_image_data_size = PaintManager::GetNewContextSize( | 536 pp::Size new_image_data_size = PaintManager::GetNewContextSize( |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 LoadPreviewUrl(url); | 1415 LoadPreviewUrl(url); |
| 1399 } | 1416 } |
| 1400 | 1417 |
| 1401 void OutOfProcessInstance::UserMetricsRecordAction( | 1418 void OutOfProcessInstance::UserMetricsRecordAction( |
| 1402 const std::string& action) { | 1419 const std::string& action) { |
| 1403 // TODO(raymes): Move this function to PPB_UMA_Private. | 1420 // TODO(raymes): Move this function to PPB_UMA_Private. |
| 1404 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); | 1421 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); |
| 1405 } | 1422 } |
| 1406 | 1423 |
| 1407 } // namespace chrome_pdf | 1424 } // namespace chrome_pdf |
| OLD | NEW |