OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wayland/wayland_window.h" | 5 #include "ui/ozone/platform/wayland/wayland_window.h" |
6 | 6 |
7 #include <xdg-shell-unstable-v5-client-protocol.h> | 7 #include <xdg-shell-unstable-v5-client-protocol.h> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/events/event.h" |
| 11 #include "ui/events/ozone/events_ozone.h" |
10 #include "ui/ozone/platform/wayland/wayland_display.h" | 12 #include "ui/ozone/platform/wayland/wayland_display.h" |
11 #include "ui/platform_window/platform_window_delegate.h" | 13 #include "ui/platform_window/platform_window_delegate.h" |
12 | 14 |
13 namespace ui { | 15 namespace ui { |
14 | 16 |
15 WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate, | 17 WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate, |
16 WaylandDisplay* display, | 18 WaylandDisplay* display, |
17 const gfx::Rect& bounds) | 19 const gfx::Rect& bounds) |
18 : delegate_(delegate), display_(display), bounds_(bounds) {} | 20 : delegate_(delegate), display_(display), bounds_(bounds) {} |
19 | 21 |
20 WaylandWindow::~WaylandWindow() { | 22 WaylandWindow::~WaylandWindow() { |
21 if (xdg_surface_) { | 23 if (xdg_surface_) { |
| 24 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
22 display_->RemoveWindow(surface_.id()); | 25 display_->RemoveWindow(surface_.id()); |
23 } | 26 } |
24 } | 27 } |
25 | 28 |
| 29 // static |
| 30 WaylandWindow* WaylandWindow::FromSurface(wl_surface* surface) { |
| 31 return static_cast<WaylandWindow*>( |
| 32 wl_proxy_get_user_data(reinterpret_cast<wl_proxy*>(surface))); |
| 33 } |
| 34 |
26 bool WaylandWindow::Initialize() { | 35 bool WaylandWindow::Initialize() { |
27 static const xdg_surface_listener xdg_surface_listener = { | 36 static const xdg_surface_listener xdg_surface_listener = { |
28 &WaylandWindow::Configure, &WaylandWindow::Close, | 37 &WaylandWindow::Configure, &WaylandWindow::Close, |
29 }; | 38 }; |
30 | 39 |
31 surface_.reset(wl_compositor_create_surface(display_->compositor())); | 40 surface_.reset(wl_compositor_create_surface(display_->compositor())); |
32 if (!surface_) { | 41 if (!surface_) { |
33 LOG(ERROR) << "Failed to create wl_surface"; | 42 LOG(ERROR) << "Failed to create wl_surface"; |
34 return false; | 43 return false; |
35 } | 44 } |
36 wl_surface_set_user_data(surface_.get(), this); | 45 wl_surface_set_user_data(surface_.get(), this); |
37 xdg_surface_.reset( | 46 xdg_surface_.reset( |
38 xdg_shell_get_xdg_surface(display_->shell(), surface_.get())); | 47 xdg_shell_get_xdg_surface(display_->shell(), surface_.get())); |
39 if (!xdg_surface_) { | 48 if (!xdg_surface_) { |
40 LOG(ERROR) << "Failed to create xdg_surface"; | 49 LOG(ERROR) << "Failed to create xdg_surface"; |
41 return false; | 50 return false; |
42 } | 51 } |
43 xdg_surface_add_listener(xdg_surface_.get(), &xdg_surface_listener, this); | 52 xdg_surface_add_listener(xdg_surface_.get(), &xdg_surface_listener, this); |
44 display_->ScheduleFlush(); | 53 display_->ScheduleFlush(); |
45 | 54 |
46 display_->AddWindow(surface_.id(), this); | 55 display_->AddWindow(surface_.id(), this); |
| 56 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
47 delegate_->OnAcceleratedWidgetAvailable(surface_.id(), 1.f); | 57 delegate_->OnAcceleratedWidgetAvailable(surface_.id(), 1.f); |
48 | 58 |
49 return true; | 59 return true; |
50 } | 60 } |
51 | 61 |
52 void WaylandWindow::ApplyPendingBounds() { | 62 void WaylandWindow::ApplyPendingBounds() { |
53 if (pending_bounds_.IsEmpty()) | 63 if (pending_bounds_.IsEmpty()) |
54 return; | 64 return; |
55 | 65 |
56 SetBounds(pending_bounds_); | 66 SetBounds(pending_bounds_); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 137 |
128 void WaylandWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { | 138 void WaylandWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { |
129 NOTIMPLEMENTED(); | 139 NOTIMPLEMENTED(); |
130 } | 140 } |
131 | 141 |
132 PlatformImeController* WaylandWindow::GetPlatformImeController() { | 142 PlatformImeController* WaylandWindow::GetPlatformImeController() { |
133 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
134 return nullptr; | 144 return nullptr; |
135 } | 145 } |
136 | 146 |
| 147 bool WaylandWindow::CanDispatchEvent(const PlatformEvent& native_event) { |
| 148 Event* event = static_cast<Event*>(native_event); |
| 149 if (event->IsMouseEvent()) |
| 150 return has_pointer_focus_; |
| 151 return false; |
| 152 } |
| 153 |
| 154 uint32_t WaylandWindow::DispatchEvent(const PlatformEvent& native_event) { |
| 155 DispatchEventFromNativeUiEvent( |
| 156 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
| 157 base::Unretained(delegate_))); |
| 158 return POST_DISPATCH_STOP_PROPAGATION; |
| 159 } |
| 160 |
| 161 // static |
137 void WaylandWindow::Configure(void* data, | 162 void WaylandWindow::Configure(void* data, |
138 xdg_surface* obj, | 163 xdg_surface* obj, |
139 int32_t width, | 164 int32_t width, |
140 int32_t height, | 165 int32_t height, |
141 wl_array* states, | 166 wl_array* states, |
142 uint32_t serial) { | 167 uint32_t serial) { |
143 WaylandWindow* window = static_cast<WaylandWindow*>(data); | 168 WaylandWindow* window = static_cast<WaylandWindow*>(data); |
144 | 169 |
145 // Rather than call SetBounds here for every configure event, just save the | 170 // Rather than call SetBounds here for every configure event, just save the |
146 // most recent bounds, and have WaylandDisplay call ApplyPendingBounds when it | 171 // most recent bounds, and have WaylandDisplay call ApplyPendingBounds when it |
147 // has finished processing events. We may get many configure events in a row | 172 // has finished processing events. We may get many configure events in a row |
148 // during an interactive resize, and only the last one matters. | 173 // during an interactive resize, and only the last one matters. |
149 window->pending_bounds_ = gfx::Rect(0, 0, width, height); | 174 window->pending_bounds_ = gfx::Rect(0, 0, width, height); |
150 window->pending_configure_serial_ = serial; | 175 window->pending_configure_serial_ = serial; |
151 } | 176 } |
152 | 177 |
| 178 // static |
153 void WaylandWindow::Close(void* data, xdg_surface* obj) { | 179 void WaylandWindow::Close(void* data, xdg_surface* obj) { |
154 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
155 } | 181 } |
156 | 182 |
157 } // namespace ui | 183 } // namespace ui |
OLD | NEW |