Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: sky/viewer/converters/input_event_types.cc

Issue 854603004: Sky events should be in dips rather than ddpxs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/viewer/converters/input_event_types.h ('k') | sky/viewer/document_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/viewer/converters/input_event_types.cc
diff --git a/sky/viewer/converters/input_event_types.cc b/sky/viewer/converters/input_event_types.cc
index 98becfda0974c29ebc52aebc525fa3f4ead5d2ed..7a7e555dc0e88e1474df20727c66f05060afc609 100644
--- a/sky/viewer/converters/input_event_types.cc
+++ b/sky/viewer/converters/input_event_types.cc
@@ -9,7 +9,7 @@
#include "mojo/services/input_events/public/interfaces/input_event_constants.mojom.h"
#include "sky/engine/public/web/WebInputEvent.h"
-namespace mojo {
+namespace sky {
namespace {
// Used for scrolling. This matches Firefox behavior.
@@ -57,7 +57,14 @@ int GetClickCount(int flags) {
return 1;
}
-scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const EventPtr& event) {
+blink::WebFloatPoint ConvertPoint(const mojo::Point& point,
+ float device_pixel_ratio) {
+ return blink::WebFloatPoint(point.x / device_pixel_ratio,
+ point.y / device_pixel_ratio);
+}
+
+scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const mojo::EventPtr& event,
+ float device_pixel_ratio) {
scoped_ptr<blink::WebTouchEvent> web_event(new blink::WebTouchEvent);
web_event->modifiers = EventFlagsToWebInputEventModifiers(event->flags);
@@ -71,19 +78,19 @@ scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const EventPtr& event) {
blink::WebTouchPoint touch;
switch (event->action) {
- case EVENT_TYPE_TOUCH_RELEASED:
+ case mojo::EVENT_TYPE_TOUCH_RELEASED:
web_event->type = blink::WebInputEvent::TouchEnd;
touch.state = blink::WebTouchPoint::StateReleased;
break;
- case EVENT_TYPE_TOUCH_PRESSED:
+ case mojo::EVENT_TYPE_TOUCH_PRESSED:
web_event->type = blink::WebInputEvent::TouchStart;
touch.state = blink::WebTouchPoint::StatePressed;
break;
- case EVENT_TYPE_TOUCH_MOVED:
+ case mojo::EVENT_TYPE_TOUCH_MOVED:
web_event->type = blink::WebInputEvent::TouchMove;
touch.state = blink::WebTouchPoint::StateMoved;
break;
- case EVENT_TYPE_TOUCH_CANCELLED:
+ case mojo::EVENT_TYPE_TOUCH_CANCELLED:
web_event->type = blink::WebInputEvent::TouchCancel;
touch.state = blink::WebTouchPoint::StateCancelled;
break;
@@ -94,12 +101,11 @@ scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const EventPtr& event) {
touch.id = event->touch_data->pointer_id;
- touch.position.x = event->location_data->in_view_location->x;
- touch.position.y = event->location_data->in_view_location->y;
-
+ touch.position =
+ ConvertPoint(*event->location_data->in_view_location, device_pixel_ratio);
if (event->location_data->screen_location) {
- touch.screenPosition.x = event->location_data->screen_location->x;
- touch.screenPosition.y = event->location_data->screen_location->y;
+ touch.screenPosition = ConvertPoint(*event->location_data->screen_location,
+ device_pixel_ratio);
}
if (web_event->touchesLength)
@@ -114,7 +120,9 @@ scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const EventPtr& event) {
return web_event.Pass();
}
-scoped_ptr<blink::WebInputEvent> BuildWebGestureEvent(const EventPtr& event) {
+scoped_ptr<blink::WebInputEvent> BuildWebGestureEvent(
+ const mojo::EventPtr& event,
+ float device_pixel_ratio) {
scoped_ptr<blink::WebGestureEvent> web_event(new blink::WebGestureEvent);
web_event->modifiers = EventFlagsToWebInputEventModifiers(event->flags);
@@ -122,55 +130,55 @@ scoped_ptr<blink::WebInputEvent> BuildWebGestureEvent(const EventPtr& event) {
base::TimeDelta::FromInternalValue(event->time_stamp).InSecondsF();
switch (event->action) {
- case EVENT_TYPE_GESTURE_SCROLL_BEGIN:
+ case mojo::EVENT_TYPE_GESTURE_SCROLL_BEGIN:
web_event->type = blink::WebInputEvent::GestureScrollBegin;
break;
- case EVENT_TYPE_GESTURE_SCROLL_END:
+ case mojo::EVENT_TYPE_GESTURE_SCROLL_END:
web_event->type = blink::WebInputEvent::GestureScrollEnd;
break;
- case EVENT_TYPE_GESTURE_SCROLL_UPDATE:
+ case mojo::EVENT_TYPE_GESTURE_SCROLL_UPDATE:
web_event->type = blink::WebInputEvent::GestureScrollUpdate;
break;
- case EVENT_TYPE_SCROLL_FLING_START:
+ case mojo::EVENT_TYPE_SCROLL_FLING_START:
web_event->type = blink::WebInputEvent::GestureFlingStart;
break;
- case EVENT_TYPE_SCROLL_FLING_CANCEL:
+ case mojo::EVENT_TYPE_SCROLL_FLING_CANCEL:
web_event->type = blink::WebInputEvent::GestureFlingCancel;
break;
- case EVENT_TYPE_GESTURE_SHOW_PRESS:
+ case mojo::EVENT_TYPE_GESTURE_SHOW_PRESS:
web_event->type = blink::WebInputEvent::GestureShowPress;
break;
- case EVENT_TYPE_GESTURE_TAP:
+ case mojo::EVENT_TYPE_GESTURE_TAP:
web_event->type = blink::WebInputEvent::GestureTap;
break;
- case EVENT_TYPE_GESTURE_TAP_UNCONFIRMED:
+ case mojo::EVENT_TYPE_GESTURE_TAP_UNCONFIRMED:
web_event->type = blink::WebInputEvent::GestureTapUnconfirmed;
break;
- case EVENT_TYPE_GESTURE_TAP_DOWN:
+ case mojo::EVENT_TYPE_GESTURE_TAP_DOWN:
web_event->type = blink::WebInputEvent::GestureTapDown;
break;
- case EVENT_TYPE_GESTURE_TAP_CANCEL:
+ case mojo::EVENT_TYPE_GESTURE_TAP_CANCEL:
web_event->type = blink::WebInputEvent::GestureTapCancel;
break;
- case EVENT_TYPE_GESTURE_DOUBLE_TAP:
+ case mojo::EVENT_TYPE_GESTURE_DOUBLE_TAP:
web_event->type = blink::WebInputEvent::GestureDoubleTap;
break;
- case EVENT_TYPE_GESTURE_TWO_FINGER_TAP:
+ case mojo::EVENT_TYPE_GESTURE_TWO_FINGER_TAP:
web_event->type = blink::WebInputEvent::GestureTwoFingerTap;
break;
- case EVENT_TYPE_GESTURE_LONG_PRESS:
+ case mojo::EVENT_TYPE_GESTURE_LONG_PRESS:
web_event->type = blink::WebInputEvent::GestureLongPress;
break;
- case EVENT_TYPE_GESTURE_LONG_TAP:
+ case mojo::EVENT_TYPE_GESTURE_LONG_TAP:
web_event->type = blink::WebInputEvent::GestureLongTap;
break;
- case EVENT_TYPE_GESTURE_PINCH_BEGIN:
+ case mojo::EVENT_TYPE_GESTURE_PINCH_BEGIN:
web_event->type = blink::WebInputEvent::GesturePinchBegin;
break;
- case EVENT_TYPE_GESTURE_PINCH_END:
+ case mojo::EVENT_TYPE_GESTURE_PINCH_END:
web_event->type = blink::WebInputEvent::GesturePinchEnd;
break;
- case EVENT_TYPE_GESTURE_PINCH_UPDATE:
+ case mojo::EVENT_TYPE_GESTURE_PINCH_UPDATE:
web_event->type = blink::WebInputEvent::GesturePinchUpdate;
break;
default:
@@ -178,22 +186,25 @@ scoped_ptr<blink::WebInputEvent> BuildWebGestureEvent(const EventPtr& event) {
break;
}
- web_event->x = event->location_data->in_view_location->x;
- web_event->y = event->location_data->in_view_location->y;
+ web_event->x = event->location_data->in_view_location->x / device_pixel_ratio;
+ web_event->y = event->location_data->in_view_location->y / device_pixel_ratio;
// TODO(erg): Remove this null check as parallel to above.
if (!event->location_data->screen_location.is_null()) {
- web_event->globalX = event->location_data->screen_location->x;
- web_event->globalY = event->location_data->screen_location->y;
+ web_event->globalX =
+ event->location_data->screen_location->x / device_pixel_ratio;
+ web_event->globalY =
+ event->location_data->screen_location->y / device_pixel_ratio;
}
return web_event.Pass();
}
-scoped_ptr<blink::WebInputEvent> BuildWebMouseEvent(const EventPtr& event) {
+scoped_ptr<blink::WebInputEvent> BuildWebMouseEvent(const mojo::EventPtr& event,
+ float device_pixel_ratio) {
scoped_ptr<blink::WebMouseEvent> web_event(new blink::WebMouseEvent);
- web_event->x = event->location_data->in_view_location->x;
- web_event->y = event->location_data->in_view_location->y;
+ web_event->x = event->location_data->in_view_location->x / device_pixel_ratio;
+ web_event->y = event->location_data->in_view_location->y / device_pixel_ratio;
// TODO(erg): Remove this if check once we can rely on screen_location
// actually being passed to us. As written today, getting the screen
@@ -201,8 +212,10 @@ scoped_ptr<blink::WebInputEvent> BuildWebMouseEvent(const EventPtr& event) {
// underlying native events, so all synthesized events don't have screen
// locations.
if (!event->location_data->screen_location.is_null()) {
- web_event->globalX = event->location_data->screen_location->x;
- web_event->globalY = event->location_data->screen_location->y;
+ web_event->globalX =
+ event->location_data->screen_location->x / device_pixel_ratio;
+ web_event->globalY =
+ event->location_data->screen_location->y / device_pixel_ratio;
}
web_event->modifiers = EventFlagsToWebEventModifiers(event->flags);
@@ -218,19 +231,19 @@ scoped_ptr<blink::WebInputEvent> BuildWebMouseEvent(const EventPtr& event) {
web_event->button = blink::WebMouseEvent::ButtonRight;
switch (event->action) {
- case EVENT_TYPE_MOUSE_PRESSED:
+ case mojo::EVENT_TYPE_MOUSE_PRESSED:
web_event->type = blink::WebInputEvent::MouseDown;
break;
- case EVENT_TYPE_MOUSE_RELEASED:
+ case mojo::EVENT_TYPE_MOUSE_RELEASED:
web_event->type = blink::WebInputEvent::MouseUp;
break;
- case EVENT_TYPE_MOUSE_ENTERED:
+ case mojo::EVENT_TYPE_MOUSE_ENTERED:
web_event->type = blink::WebInputEvent::MouseLeave;
web_event->button = blink::WebMouseEvent::ButtonNone;
break;
- case EVENT_TYPE_MOUSE_EXITED:
- case EVENT_TYPE_MOUSE_MOVED:
- case EVENT_TYPE_MOUSE_DRAGGED:
+ case mojo::EVENT_TYPE_MOUSE_EXITED:
+ case mojo::EVENT_TYPE_MOUSE_MOVED:
+ case mojo::EVENT_TYPE_MOUSE_DRAGGED:
web_event->type = blink::WebInputEvent::MouseMove;
break;
default:
@@ -244,7 +257,8 @@ scoped_ptr<blink::WebInputEvent> BuildWebMouseEvent(const EventPtr& event) {
}
scoped_ptr<blink::WebInputEvent> BuildWebKeyboardEvent(
- const EventPtr& event) {
+ const mojo::EventPtr& event,
+ float device_pixel_ratio) {
scoped_ptr<blink::WebKeyboardEvent> web_event(new blink::WebKeyboardEvent);
web_event->modifiers = EventFlagsToWebInputEventModifiers(event->flags);
@@ -252,11 +266,11 @@ scoped_ptr<blink::WebInputEvent> BuildWebKeyboardEvent(
base::TimeDelta::FromInternalValue(event->time_stamp).InSecondsF();
switch (event->action) {
- case EVENT_TYPE_KEY_PRESSED:
+ case mojo::EVENT_TYPE_KEY_PRESSED:
web_event->type = event->key_data->is_char ? blink::WebInputEvent::Char :
blink::WebInputEvent::RawKeyDown;
break;
- case EVENT_TYPE_KEY_RELEASED:
+ case mojo::EVENT_TYPE_KEY_RELEASED:
web_event->type = blink::WebInputEvent::KeyUp;
break;
default:
@@ -276,7 +290,8 @@ scoped_ptr<blink::WebInputEvent> BuildWebKeyboardEvent(
}
scoped_ptr<blink::WebInputEvent> BuildWebMouseWheelEvent(
- const EventPtr& event) {
+ const mojo::EventPtr& event,
+ float device_pixel_ratio) {
scoped_ptr<blink::WebMouseWheelEvent> web_event(
new blink::WebMouseWheelEvent);
web_event->type = blink::WebInputEvent::MouseWheel;
@@ -285,13 +300,15 @@ scoped_ptr<blink::WebInputEvent> BuildWebMouseWheelEvent(
web_event->timeStampSeconds =
base::TimeDelta::FromInternalValue(event->time_stamp).InSecondsF();
- web_event->x = event->location_data->in_view_location->x;
- web_event->y = event->location_data->in_view_location->y;
+ web_event->x = event->location_data->in_view_location->x / device_pixel_ratio;
+ web_event->y = event->location_data->in_view_location->y / device_pixel_ratio;
// TODO(erg): Remove this null check as parallel to above.
if (!event->location_data->screen_location.is_null()) {
- web_event->globalX = event->location_data->screen_location->x;
- web_event->globalY = event->location_data->screen_location->y;
+ web_event->globalX =
+ event->location_data->screen_location->x / device_pixel_ratio;
+ web_event->globalY =
+ event->location_data->screen_location->y / device_pixel_ratio;
}
if ((event->flags & mojo::EVENT_FLAGS_SHIFT_DOWN) != 0 &&
@@ -311,50 +328,48 @@ scoped_ptr<blink::WebInputEvent> BuildWebMouseWheelEvent(
} // namespace
-// static
-scoped_ptr<blink::WebInputEvent>
-TypeConverter<scoped_ptr<blink::WebInputEvent>, EventPtr>::Convert(
- const EventPtr& event) {
- if (event->action == EVENT_TYPE_TOUCH_RELEASED ||
- event->action == EVENT_TYPE_TOUCH_PRESSED ||
- event->action == EVENT_TYPE_TOUCH_MOVED ||
- event->action == EVENT_TYPE_TOUCH_CANCELLED) {
- return BuildWebTouchEvent(event);
- } else if (event->action == EVENT_TYPE_GESTURE_SCROLL_BEGIN ||
- event->action == EVENT_TYPE_GESTURE_SCROLL_END ||
- event->action == EVENT_TYPE_GESTURE_SCROLL_UPDATE ||
- event->action == EVENT_TYPE_GESTURE_TAP ||
- event->action == EVENT_TYPE_GESTURE_TAP_DOWN ||
- event->action == EVENT_TYPE_GESTURE_TAP_CANCEL ||
- event->action == EVENT_TYPE_GESTURE_TAP_UNCONFIRMED ||
- event->action == EVENT_TYPE_GESTURE_DOUBLE_TAP ||
- event->action == EVENT_TYPE_GESTURE_BEGIN ||
- event->action == EVENT_TYPE_GESTURE_END ||
- event->action == EVENT_TYPE_GESTURE_TWO_FINGER_TAP ||
- event->action == EVENT_TYPE_GESTURE_PINCH_BEGIN ||
- event->action == EVENT_TYPE_GESTURE_PINCH_END ||
- event->action == EVENT_TYPE_GESTURE_PINCH_UPDATE ||
- event->action == EVENT_TYPE_GESTURE_LONG_PRESS ||
- event->action == EVENT_TYPE_GESTURE_LONG_TAP ||
- event->action == EVENT_TYPE_GESTURE_SWIPE ||
- event->action == EVENT_TYPE_GESTURE_SHOW_PRESS ||
- event->action == EVENT_TYPE_GESTURE_WIN8_EDGE_SWIPE ||
- event->action == EVENT_TYPE_SCROLL_FLING_START ||
- event->action == EVENT_TYPE_SCROLL_FLING_CANCEL) {
- return BuildWebGestureEvent(event);
- } else if (event->action == EVENT_TYPE_MOUSE_PRESSED ||
- event->action == EVENT_TYPE_MOUSE_RELEASED ||
- event->action == EVENT_TYPE_MOUSE_ENTERED ||
- event->action == EVENT_TYPE_MOUSE_EXITED ||
- event->action == EVENT_TYPE_MOUSE_MOVED ||
- event->action == EVENT_TYPE_MOUSE_DRAGGED) {
- return BuildWebMouseEvent(event);
- } else if ((event->action == EVENT_TYPE_KEY_PRESSED ||
- event->action == EVENT_TYPE_KEY_RELEASED) &&
+scoped_ptr<blink::WebInputEvent> ConvertEvent(const mojo::EventPtr& event,
+ float device_pixel_ratio) {
+ if (event->action == mojo::EVENT_TYPE_TOUCH_RELEASED ||
+ event->action == mojo::EVENT_TYPE_TOUCH_PRESSED ||
+ event->action == mojo::EVENT_TYPE_TOUCH_MOVED ||
+ event->action == mojo::EVENT_TYPE_TOUCH_CANCELLED) {
+ return BuildWebTouchEvent(event, device_pixel_ratio);
+ } else if (event->action == mojo::EVENT_TYPE_GESTURE_SCROLL_BEGIN ||
+ event->action == mojo::EVENT_TYPE_GESTURE_SCROLL_END ||
+ event->action == mojo::EVENT_TYPE_GESTURE_SCROLL_UPDATE ||
+ event->action == mojo::EVENT_TYPE_GESTURE_TAP ||
+ event->action == mojo::EVENT_TYPE_GESTURE_TAP_DOWN ||
+ event->action == mojo::EVENT_TYPE_GESTURE_TAP_CANCEL ||
+ event->action == mojo::EVENT_TYPE_GESTURE_TAP_UNCONFIRMED ||
+ event->action == mojo::EVENT_TYPE_GESTURE_DOUBLE_TAP ||
+ event->action == mojo::EVENT_TYPE_GESTURE_BEGIN ||
+ event->action == mojo::EVENT_TYPE_GESTURE_END ||
+ event->action == mojo::EVENT_TYPE_GESTURE_TWO_FINGER_TAP ||
+ event->action == mojo::EVENT_TYPE_GESTURE_PINCH_BEGIN ||
+ event->action == mojo::EVENT_TYPE_GESTURE_PINCH_END ||
+ event->action == mojo::EVENT_TYPE_GESTURE_PINCH_UPDATE ||
+ event->action == mojo::EVENT_TYPE_GESTURE_LONG_PRESS ||
+ event->action == mojo::EVENT_TYPE_GESTURE_LONG_TAP ||
+ event->action == mojo::EVENT_TYPE_GESTURE_SWIPE ||
+ event->action == mojo::EVENT_TYPE_GESTURE_SHOW_PRESS ||
+ event->action == mojo::EVENT_TYPE_GESTURE_WIN8_EDGE_SWIPE ||
+ event->action == mojo::EVENT_TYPE_SCROLL_FLING_START ||
+ event->action == mojo::EVENT_TYPE_SCROLL_FLING_CANCEL) {
+ return BuildWebGestureEvent(event, device_pixel_ratio);
+ } else if (event->action == mojo::EVENT_TYPE_MOUSE_PRESSED ||
+ event->action == mojo::EVENT_TYPE_MOUSE_RELEASED ||
+ event->action == mojo::EVENT_TYPE_MOUSE_ENTERED ||
+ event->action == mojo::EVENT_TYPE_MOUSE_EXITED ||
+ event->action == mojo::EVENT_TYPE_MOUSE_MOVED ||
+ event->action == mojo::EVENT_TYPE_MOUSE_DRAGGED) {
+ return BuildWebMouseEvent(event, device_pixel_ratio);
+ } else if ((event->action == mojo::EVENT_TYPE_KEY_PRESSED ||
+ event->action == mojo::EVENT_TYPE_KEY_RELEASED) &&
event->key_data) {
- return BuildWebKeyboardEvent(event);
- } else if (event->action == EVENT_TYPE_MOUSEWHEEL) {
- return BuildWebMouseWheelEvent(event);
+ return BuildWebKeyboardEvent(event, device_pixel_ratio);
+ } else if (event->action == mojo::EVENT_TYPE_MOUSEWHEEL) {
+ return BuildWebMouseWheelEvent(event, device_pixel_ratio);
}
return scoped_ptr<blink::WebInputEvent>();
« no previous file with comments | « sky/viewer/converters/input_event_types.h ('k') | sky/viewer/document_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698