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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 void OutOfProcessInstance::HandleMessage(const pp::Var& message) { | 345 void OutOfProcessInstance::HandleMessage(const pp::Var& message) { |
346 pp::VarDictionary dict(message); | 346 pp::VarDictionary dict(message); |
347 if (!dict.Get(kType).is_string()) { | 347 if (!dict.Get(kType).is_string()) { |
348 NOTREACHED(); | 348 NOTREACHED(); |
349 return; | 349 return; |
350 } | 350 } |
351 | 351 |
352 std::string type = dict.Get(kType).AsString(); | 352 std::string type = dict.Get(kType).AsString(); |
353 | 353 |
354 if (type == kJSViewportType && | 354 if (type == kJSViewportType && |
355 dict.Get(pp::Var(kJSXOffset)).is_int() && | 355 dict.Get(pp::Var(kJSXOffset)).is_number() && |
356 dict.Get(pp::Var(kJSYOffset)).is_int() && | 356 dict.Get(pp::Var(kJSYOffset)).is_number() && |
357 dict.Get(pp::Var(kJSZoom)).is_number()) { | 357 dict.Get(pp::Var(kJSZoom)).is_number()) { |
358 received_viewport_message_ = true; | 358 received_viewport_message_ = true; |
359 stop_scrolling_ = false; | 359 stop_scrolling_ = false; |
360 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); | 360 double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble(); |
361 pp::Point scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsInt(), | 361 pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(), |
362 dict.Get(pp::Var(kJSYOffset)).AsInt()); | 362 dict.Get(pp::Var(kJSYOffset)).AsDouble()); |
363 | 363 |
364 // Bound the input parameters. | 364 // Bound the input parameters. |
365 zoom = std::max(kMinZoom, zoom); | 365 zoom = std::max(kMinZoom, zoom); |
366 SetZoom(zoom); | 366 SetZoom(zoom); |
367 scroll_offset = BoundScrollOffsetToDocument(scroll_offset); | 367 scroll_offset = BoundScrollOffsetToDocument(scroll_offset); |
368 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); | 368 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); |
369 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); | 369 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); |
370 } else if (type == kJSGetPasswordCompleteType && | 370 } else if (type == kJSGetPasswordCompleteType && |
371 dict.Get(pp::Var(kJSPassword)).is_string()) { | 371 dict.Get(pp::Var(kJSPassword)).is_string()) { |
372 if (password_callback_) { | 372 if (password_callback_) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 | 523 |
524 if (image_data_.is_null()) { | 524 if (image_data_.is_null()) { |
525 DCHECK(plugin_size_.IsEmpty()); | 525 DCHECK(plugin_size_.IsEmpty()); |
526 return; | 526 return; |
527 } | 527 } |
528 | 528 |
529 OnGeometryChanged(zoom_, old_device_scale); | 529 OnGeometryChanged(zoom_, old_device_scale); |
530 } | 530 } |
531 | 531 |
532 if (!stop_scrolling_) { | 532 if (!stop_scrolling_) { |
533 pp::Point scroll_offset( | 533 pp::Point scroll_offset(view.GetScrollOffset()); |
534 BoundScrollOffsetToDocument(view.GetScrollOffset())); | 534 pp::FloatPoint scroll_offset_float(scroll_offset.x(), |
535 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); | 535 scroll_offset.y()); |
536 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); | 536 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); |
| 537 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); |
| 538 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); |
537 } | 539 } |
538 } | 540 } |
539 | 541 |
540 pp::Var OutOfProcessInstance::GetLinkAtPosition( | 542 pp::Var OutOfProcessInstance::GetLinkAtPosition( |
541 const pp::Point& point) { | 543 const pp::Point& point) { |
542 pp::Point offset_point(point); | 544 pp::Point offset_point(point); |
543 ScalePoint(device_scale_, &offset_point); | 545 ScalePoint(device_scale_, &offset_point); |
544 offset_point.set_x(offset_point.x() - available_area_.x()); | 546 offset_point.set_x(offset_point.x() - available_area_.x()); |
545 return engine_->GetLinkAtPosition(offset_point); | 547 return engine_->GetLinkAtPosition(offset_point); |
546 } | 548 } |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 preview_document_load_state_ = LOAD_STATE_LOADING; | 1352 preview_document_load_state_ = LOAD_STATE_LOADING; |
1351 LoadPreviewUrl(url); | 1353 LoadPreviewUrl(url); |
1352 } | 1354 } |
1353 | 1355 |
1354 void OutOfProcessInstance::UserMetricsRecordAction( | 1356 void OutOfProcessInstance::UserMetricsRecordAction( |
1355 const std::string& action) { | 1357 const std::string& action) { |
1356 // TODO(raymes): Move this function to PPB_UMA_Private. | 1358 // TODO(raymes): Move this function to PPB_UMA_Private. |
1357 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); | 1359 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); |
1358 } | 1360 } |
1359 | 1361 |
1360 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( | 1362 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1361 const pp::Point& scroll_offset) { | 1363 const pp::FloatPoint& scroll_offset) { |
1362 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1364 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1363 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | 1365 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1364 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1366 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1365 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | 1367 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1366 return pp::Point(x, y); | 1368 return pp::FloatPoint(x, y); |
1367 } | 1369 } |
1368 | 1370 |
1369 } // namespace chrome_pdf | 1371 } // namespace chrome_pdf |
OLD | NEW |