Index: ui/ozone/platform/dri/dri_window.cc |
diff --git a/ui/ozone/platform/dri/dri_window.cc b/ui/ozone/platform/dri/dri_window.cc |
index 326f3ccc74faa1db0c4612dd0ff201800ed1706c..2524e0985728653d4ba00e0d3ed0f2b60b1a94fb 100644 |
--- a/ui/ozone/platform/dri/dri_window.cc |
+++ b/ui/ozone/platform/dri/dri_window.cc |
@@ -22,7 +22,7 @@ namespace ui { |
namespace { |
-void RewriteTouchEvent(TouchEvent* event) { |
+void RewriteTouchEvent(TouchEvent* event, const gfx::PointF& window_offset) { |
float x = event->location_f().x(); |
float y = event->location_f().y(); |
double radius_x = event->radius_x(); |
@@ -36,6 +36,8 @@ void RewriteTouchEvent(TouchEvent* event) { |
event->source_device_id(), &radius_y); |
event->set_location(gfx::PointF(x, y)); |
+ event->set_root_location( |
+ gfx::PointF(x + window_offset.x(), y + window_offset.y())); |
event->set_radius_x(radius_x); |
event->set_radius_y(radius_y); |
} |
@@ -101,9 +103,13 @@ gfx::Rect DriWindow::GetBounds() { |
return bounds_; |
} |
-void DriWindow::SetCapture() {} |
+void DriWindow::SetCapture() { |
+ window_manager_->GrabEvents(widget_); |
+} |
-void DriWindow::ReleaseCapture() {} |
+void DriWindow::ReleaseCapture() { |
+ window_manager_->UngrabEvents(widget_); |
+} |
void DriWindow::ToggleFullscreen() {} |
@@ -130,6 +136,13 @@ void DriWindow::MoveCursorTo(const gfx::Point& location) { |
bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { |
DCHECK(ne); |
Event* event = static_cast<Event*>(ne); |
+ |
+ // If there is a grab, capture relevant events here. |
+ gfx::AcceleratedWidget grabber = window_manager_->event_grabber(); |
+ if (grabber != gfx::kNullAcceleratedWidget) |
+ return grabber == widget_; |
+ |
+ // Otherwise, just consider the position of the cursor. |
if (event->IsMouseEvent() || event->IsScrollEvent()) |
return window_manager_->cursor()->GetCursorWindow() == widget_; |
@@ -162,8 +175,15 @@ uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { |
Event* event = static_cast<Event*>(native_event); |
if (event->IsTouchEvent()) |
- RewriteTouchEvent(static_cast<TouchEvent*>(event)); |
- |
+ RewriteTouchEvent(static_cast<TouchEvent*>(event), bounds_.origin()); |
+ if (event->IsLocatedEvent()) { |
sadrul
2014/11/24 22:27:04
Why do we rewrite the location of the touch-event
|
+ // We need to convert the cursor's position into coordinates |
+ // relative to the window in case of an implicit grab. |
+ LocatedEvent* located_event = static_cast<LocatedEvent*>(event); |
+ gfx::PointF location = located_event->root_location(); |
+ location.Offset(-bounds_.origin().x(), -bounds_.origin().y()); |
sadrul
2014/11/24 22:27:04
Just bounds_.x(), bounds_.y();
|
+ located_event->set_location(location); |
+ } |
DispatchEventFromNativeUiEvent( |
native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
base::Unretained(delegate_))); |