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(this); | 25 display_->RemoveWindow(this); |
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 | 53 |
45 display_->AddWindow(this); | 54 display_->AddWindow(this); |
| 55 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
46 delegate_->OnAcceleratedWidgetAvailable(surface_.id(), 1.f); | 56 delegate_->OnAcceleratedWidgetAvailable(surface_.id(), 1.f); |
47 | 57 |
48 return true; | 58 return true; |
49 } | 59 } |
50 | 60 |
51 wl_surface* WaylandWindow::GetSurface() { | 61 wl_surface* WaylandWindow::GetSurface() { |
52 DCHECK(surface_); | 62 DCHECK(surface_); |
53 return surface_.get(); | 63 return surface_.get(); |
54 } | 64 } |
55 | 65 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 141 |
132 void WaylandWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { | 142 void WaylandWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { |
133 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
134 } | 144 } |
135 | 145 |
136 PlatformImeController* WaylandWindow::GetPlatformImeController() { | 146 PlatformImeController* WaylandWindow::GetPlatformImeController() { |
137 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
138 return nullptr; | 148 return nullptr; |
139 } | 149 } |
140 | 150 |
| 151 bool WaylandWindow::CanDispatchEvent(const PlatformEvent& native_event) { |
| 152 Event* event = static_cast<Event*>(native_event); |
| 153 if (event->IsMouseEvent()) |
| 154 return has_pointer_focus_; |
| 155 return false; |
| 156 } |
| 157 |
| 158 uint32_t WaylandWindow::DispatchEvent(const PlatformEvent& native_event) { |
| 159 DispatchEventFromNativeUiEvent( |
| 160 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
| 161 base::Unretained(delegate_))); |
| 162 return POST_DISPATCH_STOP_PROPAGATION; |
| 163 } |
| 164 |
| 165 // static |
141 void WaylandWindow::Configure(void* data, | 166 void WaylandWindow::Configure(void* data, |
142 xdg_surface* obj, | 167 xdg_surface* obj, |
143 int32_t width, | 168 int32_t width, |
144 int32_t height, | 169 int32_t height, |
145 wl_array* states, | 170 wl_array* states, |
146 uint32_t serial) { | 171 uint32_t serial) { |
147 WaylandWindow* window = static_cast<WaylandWindow*>(data); | 172 WaylandWindow* window = static_cast<WaylandWindow*>(data); |
148 | 173 |
149 // Rather than call SetBounds here for every configure event, just save the | 174 // Rather than call SetBounds here for every configure event, just save the |
150 // most recent bounds, and have WaylandDisplay call ApplyPendingBounds when it | 175 // most recent bounds, and have WaylandDisplay call ApplyPendingBounds when it |
151 // has finished processing events. We may get many configure events in a row | 176 // has finished processing events. We may get many configure events in a row |
152 // during an interactive resize, and only the last one matters. | 177 // during an interactive resize, and only the last one matters. |
153 window->pending_bounds_ = gfx::Rect(0, 0, width, height); | 178 window->pending_bounds_ = gfx::Rect(0, 0, width, height); |
154 window->pending_configure_serial_ = serial; | 179 window->pending_configure_serial_ = serial; |
155 } | 180 } |
156 | 181 |
| 182 // static |
157 void WaylandWindow::Close(void* data, xdg_surface* obj) { | 183 void WaylandWindow::Close(void* data, xdg_surface* obj) { |
158 NOTIMPLEMENTED(); | 184 NOTIMPLEMENTED(); |
159 } | 185 } |
160 | 186 |
161 } // namespace ui | 187 } // namespace ui |
OLD | NEW |