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/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 dri_window_delegate_->OnBoundsChanged(bounds); | 64 dri_window_delegate_->OnBoundsChanged(bounds); |
| 65 | 65 |
| 66 if (window_manager_->cursor()->GetCursorWindow() == widget_) | 66 if (window_manager_->cursor()->GetCursorWindow() == widget_) |
| 67 window_manager_->cursor()->ShowCursor(); | 67 window_manager_->cursor()->ShowCursor(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 gfx::Rect DriWindow::GetBounds() { | 70 gfx::Rect DriWindow::GetBounds() { |
| 71 return bounds_; | 71 return bounds_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void DriWindow::SetCapture() {} | 74 void DriWindow::SetCapture() { |
| 75 window_manager_->GrabMouseEvents(widget_); | |
| 76 } | |
| 75 | 77 |
| 76 void DriWindow::ReleaseCapture() {} | 78 void DriWindow::ReleaseCapture() { |
| 79 window_manager_->UngrabMouseEvents(widget_); | |
| 80 } | |
| 77 | 81 |
| 78 void DriWindow::ToggleFullscreen() {} | 82 void DriWindow::ToggleFullscreen() {} |
| 79 | 83 |
| 80 void DriWindow::Maximize() {} | 84 void DriWindow::Maximize() {} |
| 81 | 85 |
| 82 void DriWindow::Minimize() {} | 86 void DriWindow::Minimize() {} |
| 83 | 87 |
| 84 void DriWindow::Restore() {} | 88 void DriWindow::Restore() {} |
| 85 | 89 |
| 86 void DriWindow::SetCursor(PlatformCursor cursor) { | 90 void DriWindow::SetCursor(PlatformCursor cursor) { |
| 87 window_manager_->cursor()->SetCursor(widget_, cursor); | 91 window_manager_->cursor()->SetCursor(widget_, cursor); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void DriWindow::MoveCursorTo(const gfx::Point& location) { | 94 void DriWindow::MoveCursorTo(const gfx::Point& location) { |
| 91 event_factory_->WarpCursorTo(widget_, location); | 95 event_factory_->WarpCursorTo(widget_, location); |
| 92 } | 96 } |
| 93 | 97 |
| 94 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { | 98 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) { |
| 95 DCHECK(ne); | 99 DCHECK(ne); |
| 96 Event* event = static_cast<Event*>(ne); | 100 Event* event = static_cast<Event*>(ne); |
| 97 if (event->IsMouseEvent() || event->IsScrollEvent()) | 101 if (event->IsMouseEvent() || event->IsScrollEvent()) { |
| 102 // Bail out if there is a grab on mouse events. | |
| 103 gfx::AcceleratedWidget grabber = window_manager_->mouse_events_grabber(); | |
| 104 if (grabber != gfx::kNullAcceleratedWidget) | |
| 105 return grabber == widget_; | |
| 106 | |
| 107 // Otherwise, just consider the position of the cursor. | |
| 98 return window_manager_->cursor()->GetCursorWindow() == widget_; | 108 return window_manager_->cursor()->GetCursorWindow() == widget_; |
| 109 } | |
| 99 | 110 |
| 100 return true; | 111 return true; |
| 101 } | 112 } |
| 102 | 113 |
| 103 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { | 114 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) { |
| 115 // Implement implicit mouse grab on button press | |
| 116 Event* event = static_cast<Event*>(native_event); | |
| 117 if (event->IsMouseEvent()) { | |
| 118 // We need to convert the cursor's position into coordinates | |
|
spang
2014/11/04 23:27:23
Can you change DriCursor to generate the event coo
| |
| 119 // relative to the window in case of an implicit grab. | |
| 120 if (window_manager_->cursor()->GetCursorWindow() != widget_) { | |
| 121 DriWindow* window = window_manager_->GetWindow( | |
| 122 window_manager_->cursor()->GetCursorWindow()); | |
| 123 DCHECK(window); | |
| 124 LocatedEvent* located_event = static_cast<LocatedEvent*>(event); | |
| 125 gfx::Point event_point = located_event->location(); | |
| 126 gfx::Point window_origin = GetBounds().origin(); | |
| 127 gfx::Point cursor_origin = window->GetBounds().origin(); | |
| 128 located_event->set_location( | |
| 129 gfx::Point(event_point.x() + cursor_origin.x() - window_origin.x(), | |
| 130 event_point.y() + cursor_origin.y() - window_origin.y())); | |
| 131 located_event->set_root_location(located_event->root_location()); | |
| 132 } | |
| 133 } | |
| 104 DispatchEventFromNativeUiEvent( | 134 DispatchEventFromNativeUiEvent( |
| 105 native_event, | 135 native_event, |
| 106 base::Bind(&PlatformWindowDelegate::DispatchEvent, | 136 base::Bind(&PlatformWindowDelegate::DispatchEvent, |
| 107 base::Unretained(delegate_))); | 137 base::Unretained(delegate_))); |
| 108 return POST_DISPATCH_STOP_PROPAGATION; | 138 return POST_DISPATCH_STOP_PROPAGATION; |
| 109 } | 139 } |
| 110 | 140 |
| 111 } // namespace ui | 141 } // namespace ui |
| OLD | NEW |