// Rotation (Page -> Plugin)
const char kJSRotateClockwiseType[] = "rotateClockwise";
const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
+// Select all text in the document (Page -> Plugin)
+const char kJSSelectAllType[] = "selectAll";
const int kFindResultCooldownMs = 100;
std::string type = dict.Get(kType).AsString();
if (type == kJSViewportType &&
- dict.Get(pp::Var(kJSXOffset)).is_int() &&
- dict.Get(pp::Var(kJSYOffset)).is_int() &&
+ dict.Get(pp::Var(kJSXOffset)).is_number() &&
+ dict.Get(pp::Var(kJSYOffset)).is_number() &&
dict.Get(pp::Var(kJSZoom)).is_number()) {
received_viewport_message_ = true;
stop_scrolling_ = false;
double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble();
- pp::Point scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsInt(),
- dict.Get(pp::Var(kJSYOffset)).AsInt());
+ pp::FloatPoint scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsDouble(),
+ dict.Get(pp::Var(kJSYOffset)).AsDouble());
// Bound the input parameters.
zoom = std::max(kMinZoom, zoom);
RotateClockwise();
} else if (type == kJSRotateCounterclockwiseType) {
RotateCounterclockwise();
+ } else if (type == kJSSelectAllType) {
+ engine_->SelectAll();
} else if (type == kJSResetPrintPreviewModeType &&
dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() &&
dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() &&
// TODO(raymes): Implement this scroll behavior in JS:
// When click+dragging, scroll the document correctly.
- if (event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN &&
- event.GetModifiers() & kDefaultKeyModifier) {
- pp::KeyboardInputEvent keyboard_event(event);
- switch (keyboard_event.GetKeyCode()) {
- case 'A':
- engine_->SelectAll();
- return true;
- }
- }
-
// Return true for unhandled clicks so the plugin takes focus.
return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
}
}
if (!stop_scrolling_) {
- pp::Point scroll_offset(
- BoundScrollOffsetToDocument(view.GetScrollOffset()));
- engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
- engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
+ pp::Point scroll_offset(view.GetScrollOffset());
+ pp::FloatPoint scroll_offset_float(scroll_offset.x(),
+ scroll_offset.y());
+ scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float);
+ engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_);
+ engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_);
}
}
void OutOfProcessInstance::NotifySelectedFindResultChanged(
int current_find_index) {
+ DCHECK_GE(current_find_index, 0);
SelectedFindResultChanged(current_find_index);
}
pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
}
-pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument(
- const pp::Point& scroll_offset) {
- int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
- int x = std::max(std::min(scroll_offset.x(), max_x), 0);
- int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
- int y = std::max(std::min(scroll_offset.y(), max_y), 0);
- return pp::Point(x, y);
+pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument(
+ const pp::FloatPoint& scroll_offset) {
+ float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
+ float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f);
+ float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
+ float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f);
+ return pp::FloatPoint(x, y);
}
} // namespace chrome_pdf