Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/dri_window.h" | 5 #include "ui/ozone/platform/dri/dri_window.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ui/events/devices/device_data_manager.h" | 8 #include "ui/events/devices/device_data_manager.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 10 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 11 #include "ui/events/ozone/events_ozone.h" | 11 #include "ui/events/ozone/events_ozone.h" |
| 12 #include "ui/events/platform/platform_event_source.h" | 12 #include "ui/events/platform/platform_event_source.h" |
| 13 #include "ui/gfx/display.h" | 13 #include "ui/gfx/display.h" |
| 14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 14 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
| 15 #include "ui/ozone/platform/dri/display_manager.h" | 15 #include "ui/ozone/platform/dri/display_manager.h" |
| 16 #include "ui/ozone/platform/dri/dri_cursor.h" | 16 #include "ui/ozone/platform/dri/dri_cursor.h" |
| 17 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" | 17 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" |
| 18 #include "ui/ozone/platform/dri/dri_window_manager.h" | 18 #include "ui/ozone/platform/dri/dri_window_manager.h" |
| 19 #include "ui/platform_window/platform_window_delegate.h" | 19 #include "ui/platform_window/platform_window_delegate.h" |
| 20 | 20 |
| 21 namespace ui { | 21 namespace ui { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 void RewriteTouchEvent(TouchEvent* event) { | 25 void RewriteTouchEvent(TouchEvent* event, const gfx::PointF& window_offset) { |
| 26 float x = event->location_f().x(); | 26 float x = event->location_f().x(); |
| 27 float y = event->location_f().y(); | 27 float y = event->location_f().y(); |
| 28 double radius_x = event->radius_x(); | 28 double radius_x = event->radius_x(); |
| 29 double radius_y = event->radius_y(); | 29 double radius_y = event->radius_y(); |
| 30 | 30 |
| 31 DeviceDataManager::GetInstance()->ApplyTouchTransformer( | 31 DeviceDataManager::GetInstance()->ApplyTouchTransformer( |
| 32 event->source_device_id(), &x, &y); | 32 event->source_device_id(), &x, &y); |
| 33 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( | 33 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( |
| 34 event->source_device_id(), &radius_x); | 34 event->source_device_id(), &radius_x); |
| 35 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( | 35 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale( |
| 36 event->source_device_id(), &radius_y); | 36 event->source_device_id(), &radius_y); |
| 37 | 37 |
| 38 event->set_location(gfx::PointF(x, y)); | 38 event->set_location(gfx::PointF(x, y)); |
| 39 event->set_root_location( | |
| 40 gfx::PointF(x + window_offset.x(), y + window_offset.y())); | |
| 39 event->set_radius_x(radius_x); | 41 event->set_radius_x(radius_x); |
| 40 event->set_radius_y(radius_y); | 42 event->set_radius_y(radius_y); |
| 41 } | 43 } |
| 42 | 44 |
| 43 } // namespace | 45 } // namespace |
| 44 | 46 |
| 45 DriWindow::DriWindow(PlatformWindowDelegate* delegate, | 47 DriWindow::DriWindow(PlatformWindowDelegate* delegate, |
| 46 const gfx::Rect& bounds, | 48 const gfx::Rect& bounds, |
| 47 DriGpuPlatformSupportHost* sender, | 49 DriGpuPlatformSupportHost* sender, |
| 48 EventFactoryEvdev* event_factory, | 50 EventFactoryEvdev* event_factory, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds)); | 96 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds)); |
| 95 | 97 |
| 96 if (window_manager_->cursor()->GetCursorWindow() == widget_) | 98 if (window_manager_->cursor()->GetCursorWindow() == widget_) |
| 97 window_manager_->cursor()->ShowCursor(); | 99 window_manager_->cursor()->ShowCursor(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 gfx::Rect DriWindow::GetBounds() { | 102 gfx::Rect DriWindow::GetBounds() { |
| 101 return bounds_; | 103 return bounds_; |
| 102 } | 104 } |
| 103 | 105 |
| 104 void DriWindow::SetCapture() {} | 106 void DriWindow::SetCapture() { |
| 107 window_manager_->GrabEvents(widget_); | |
| 108 } | |
| 105 | 109 |
| 106 void DriWindow::ReleaseCapture() {} | 110 void DriWindow::ReleaseCapture() { |
| 111 window_manager_->UngrabEvents(widget_); | |
| 112 } | |
| 107 | 113 |
| 108 void DriWindow::ToggleFullscreen() {} | 114 void DriWindow::ToggleFullscreen() {} |
| 109 | 115 |
| 110 void DriWindow::Maximize() {} | 116 void DriWindow::Maximize() {} |
| 111 | 117 |
| 112 void DriWindow::Minimize() {} | 118 void DriWindow::Minimize() {} |
| 113 | 119 |
| 114 void DriWindow::Restore() {} | 120 void DriWindow::Restore() {} |
| 115 | 121 |
| 116 void DriWindow::SetCursor(PlatformCursor cursor) { | 122 void DriWindow::SetCursor(PlatformCursor cursor) { |
| 117 DriCursor* dri_cursor = window_manager_->cursor(); | 123 DriCursor* dri_cursor = window_manager_->cursor(); |
| 118 dri_cursor->SetCursor(widget_, cursor); | 124 dri_cursor->SetCursor(widget_, cursor); |
| 119 // ShowCursor results in a IPC call to GPU. So, we make sure the channel | 125 // ShowCursor results in a IPC call to GPU. So, we make sure the channel |
| 120 // is connected. OnChannelEstablished guarantees that ShowCursor is called | 126 // is connected. OnChannelEstablished guarantees that ShowCursor is called |
| 121 // eventually. | 127 // eventually. |
| 122 if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_) | 128 if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_) |
| 123 dri_cursor->ShowCursor(); | 129 dri_cursor->ShowCursor(); |
| 124 } | 130 } |
| 125 | 131 |
| 126 void DriWindow::MoveCursorTo(const gfx::Point& location) { | 132 void DriWindow::MoveCursorTo(const gfx::Point& location) { |
| 127 event_factory_->WarpCursorTo(widget_, location); | 133 event_factory_->WarpCursorTo(widget_, location); |
| 128 } | 134 } |
| 129 | 135 |
| 130 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { | 136 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { |
| 131 DCHECK(ne); | 137 DCHECK(ne); |
| 132 Event* event = static_cast<Event*>(ne); | 138 Event* event = static_cast<Event*>(ne); |
| 139 | |
| 140 // If there is a grab, capture relevant events here. | |
| 141 gfx::AcceleratedWidget grabber = window_manager_->event_grabber(); | |
| 142 if (grabber != gfx::kNullAcceleratedWidget) | |
| 143 return grabber == widget_; | |
| 144 | |
| 145 // Otherwise, just consider the position of the cursor. | |
| 133 if (event->IsMouseEvent() || event->IsScrollEvent()) | 146 if (event->IsMouseEvent() || event->IsScrollEvent()) |
| 134 return window_manager_->cursor()->GetCursorWindow() == widget_; | 147 return window_manager_->cursor()->GetCursorWindow() == widget_; |
| 135 | 148 |
| 136 if (event->IsTouchEvent()) { | 149 if (event->IsTouchEvent()) { |
| 137 int64_t display_id = | 150 int64_t display_id = |
| 138 DeviceDataManager::GetInstance()->GetDisplayForTouchDevice( | 151 DeviceDataManager::GetInstance()->GetDisplayForTouchDevice( |
| 139 event->source_device_id()); | 152 event->source_device_id()); |
| 140 | 153 |
| 141 if (display_id == gfx::Display::kInvalidDisplayID) | 154 if (display_id == gfx::Display::kInvalidDisplayID) |
| 142 return false; | 155 return false; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 155 } | 168 } |
| 156 | 169 |
| 157 return true; | 170 return true; |
| 158 } | 171 } |
| 159 | 172 |
| 160 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { | 173 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { |
| 161 DCHECK(native_event); | 174 DCHECK(native_event); |
| 162 | 175 |
| 163 Event* event = static_cast<Event*>(native_event); | 176 Event* event = static_cast<Event*>(native_event); |
| 164 if (event->IsTouchEvent()) | 177 if (event->IsTouchEvent()) |
| 165 RewriteTouchEvent(static_cast<TouchEvent*>(event)); | 178 RewriteTouchEvent(static_cast<TouchEvent*>(event), bounds_.origin()); |
| 166 | 179 if (event->IsLocatedEvent()) { |
|
sadrul
2014/11/24 22:27:04
Why do we rewrite the location of the touch-event
| |
| 180 // We need to convert the cursor's position into coordinates | |
| 181 // relative to the window in case of an implicit grab. | |
| 182 LocatedEvent* located_event = static_cast<LocatedEvent*>(event); | |
| 183 gfx::PointF location = located_event->root_location(); | |
| 184 location.Offset(-bounds_.origin().x(), -bounds_.origin().y()); | |
|
sadrul
2014/11/24 22:27:04
Just bounds_.x(), bounds_.y();
| |
| 185 located_event->set_location(location); | |
| 186 } | |
| 167 DispatchEventFromNativeUiEvent( | 187 DispatchEventFromNativeUiEvent( |
| 168 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, | 188 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
| 169 base::Unretained(delegate_))); | 189 base::Unretained(delegate_))); |
| 170 return POST_DISPATCH_STOP_PROPAGATION; | 190 return POST_DISPATCH_STOP_PROPAGATION; |
| 171 } | 191 } |
| 172 | 192 |
| 173 void DriWindow::OnChannelEstablished() { | 193 void DriWindow::OnChannelEstablished() { |
| 174 sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_)); | 194 sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_)); |
| 175 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_)); | 195 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_)); |
| 176 | 196 |
| 177 DriCursor* dri_cursor = window_manager_->cursor(); | 197 DriCursor* dri_cursor = window_manager_->cursor(); |
| 178 if (dri_cursor->GetCursorWindow() == widget_) | 198 if (dri_cursor->GetCursorWindow() == widget_) |
| 179 dri_cursor->ShowCursor(); | 199 dri_cursor->ShowCursor(); |
| 180 } | 200 } |
| 181 | 201 |
| 182 void DriWindow::OnChannelDestroyed() { | 202 void DriWindow::OnChannelDestroyed() { |
| 183 } | 203 } |
| 184 | 204 |
| 185 } // namespace ui | 205 } // namespace ui |
| OLD | NEW |