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/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 9 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
10 #include "ui/events/ozone/events_ozone.h" | 10 #include "ui/events/ozone/events_ozone.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds)); | 67 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds)); |
68 | 68 |
69 if (window_manager_->cursor()->GetCursorWindow() == widget_) | 69 if (window_manager_->cursor()->GetCursorWindow() == widget_) |
70 window_manager_->cursor()->ShowCursor(); | 70 window_manager_->cursor()->ShowCursor(); |
71 } | 71 } |
72 | 72 |
73 gfx::Rect DriWindow::GetBounds() { | 73 gfx::Rect DriWindow::GetBounds() { |
74 return bounds_; | 74 return bounds_; |
75 } | 75 } |
76 | 76 |
77 void DriWindow::SetCapture() {} | 77 void DriWindow::SetCapture() { |
78 window_manager_->GrabMouseEvents(widget_); | |
79 } | |
78 | 80 |
79 void DriWindow::ReleaseCapture() {} | 81 void DriWindow::ReleaseCapture() { |
82 window_manager_->UngrabMouseEvents(widget_); | |
83 } | |
80 | 84 |
81 void DriWindow::ToggleFullscreen() {} | 85 void DriWindow::ToggleFullscreen() {} |
82 | 86 |
83 void DriWindow::Maximize() {} | 87 void DriWindow::Maximize() {} |
84 | 88 |
85 void DriWindow::Minimize() {} | 89 void DriWindow::Minimize() {} |
86 | 90 |
87 void DriWindow::Restore() {} | 91 void DriWindow::Restore() {} |
88 | 92 |
89 void DriWindow::SetCursor(PlatformCursor cursor) { | 93 void DriWindow::SetCursor(PlatformCursor cursor) { |
90 DriCursor* dri_cursor = window_manager_->cursor(); | 94 DriCursor* dri_cursor = window_manager_->cursor(); |
91 dri_cursor->SetCursor(widget_, cursor); | 95 dri_cursor->SetCursor(widget_, cursor); |
92 // ShowCursor results in a IPC call to GPU. So, we make sure the channel | 96 // ShowCursor results in a IPC call to GPU. So, we make sure the channel |
93 // is connected. OnChannelEstablished guarantees that ShowCursor is called | 97 // is connected. OnChannelEstablished guarantees that ShowCursor is called |
94 // eventually. | 98 // eventually. |
95 if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_) | 99 if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_) |
96 dri_cursor->ShowCursor(); | 100 dri_cursor->ShowCursor(); |
97 } | 101 } |
98 | 102 |
99 void DriWindow::MoveCursorTo(const gfx::Point& location) { | 103 void DriWindow::MoveCursorTo(const gfx::Point& location) { |
100 event_factory_->WarpCursorTo(widget_, location); | 104 event_factory_->WarpCursorTo(widget_, location); |
101 } | 105 } |
102 | 106 |
103 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { | 107 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { |
104 DCHECK(ne); | 108 DCHECK(ne); |
105 Event* event = static_cast<Event*>(ne); | 109 Event* event = static_cast<Event*>(ne); |
106 if (event->IsMouseEvent() || event->IsScrollEvent()) | 110 if (event->IsMouseEvent() || event->IsScrollEvent()) { |
111 // Bail out if there is a grab on mouse events. | |
112 gfx::AcceleratedWidget grabber = window_manager_->mouse_events_grabber(); | |
sadrul
2014/11/11 14:41:14
Should you look at the capture window for other ev
llandwerlin-old
2014/11/11 18:29:17
Done.
| |
113 if (grabber != gfx::kNullAcceleratedWidget) | |
114 return grabber == widget_; | |
115 | |
116 // Otherwise, just consider the position of the cursor. | |
107 return window_manager_->cursor()->GetCursorWindow() == widget_; | 117 return window_manager_->cursor()->GetCursorWindow() == widget_; |
118 } | |
108 | 119 |
109 return true; | 120 return true; |
110 } | 121 } |
111 | 122 |
112 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { | 123 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { |
124 // Implement implicit mouse grab on button press | |
125 Event* event = static_cast<Event*>(native_event); | |
126 if (event->IsMouseEvent() || event->IsScrollEvent()) { | |
sadrul
2014/11/11 14:41:14
You shouldn't need a grab for scroll events.
| |
127 // We need to convert the cursor's position into coordinates | |
128 // relative to the window in case of an implicit grab. | |
129 if (window_manager_->cursor()->GetCursorWindow() != widget_) { | |
130 LocatedEvent* located_event = static_cast<LocatedEvent*>(event); | |
131 gfx::PointF location = located_event->root_location(); | |
132 location.Offset(-bounds_.origin().x(), -bounds_.origin().y()); | |
133 located_event->set_location(location); | |
134 } | |
135 } | |
113 DispatchEventFromNativeUiEvent( | 136 DispatchEventFromNativeUiEvent( |
114 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, | 137 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
115 base::Unretained(delegate_))); | 138 base::Unretained(delegate_))); |
116 return POST_DISPATCH_STOP_PROPAGATION; | 139 return POST_DISPATCH_STOP_PROPAGATION; |
117 } | 140 } |
118 | 141 |
119 void DriWindow::OnChannelEstablished() { | 142 void DriWindow::OnChannelEstablished() { |
120 sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_)); | 143 sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_)); |
121 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_)); | 144 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_)); |
122 | 145 |
123 DriCursor* dri_cursor = window_manager_->cursor(); | 146 DriCursor* dri_cursor = window_manager_->cursor(); |
124 if (dri_cursor->GetCursorWindow() == widget_) | 147 if (dri_cursor->GetCursorWindow() == widget_) |
125 dri_cursor->ShowCursor(); | 148 dri_cursor->ShowCursor(); |
126 } | 149 } |
127 | 150 |
128 void DriWindow::OnChannelDestroyed() { | 151 void DriWindow::OnChannelDestroyed() { |
129 } | 152 } |
130 | 153 |
131 } // namespace ui | 154 } // namespace ui |
OLD | NEW |