OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/ozone/platform/wayland/wayland_display.h" |
| 9 #include "ui/platform_window/platform_window_delegate.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate, |
| 14 WaylandDisplay* display, |
| 15 const gfx::Rect& bounds) |
| 16 : delegate_(delegate), display_(display), bounds_(bounds) {} |
| 17 |
| 18 WaylandWindow::~WaylandWindow() { |
| 19 if (xdg_surface_) { |
| 20 display_->RemoveWindow(this); |
| 21 } |
| 22 } |
| 23 |
| 24 bool WaylandWindow::Initialize() { |
| 25 static const xdg_surface_listener xdg_surface_listener = { |
| 26 .configure = &WaylandWindow::Configure, .close = &WaylandWindow::Close, |
| 27 }; |
| 28 |
| 29 surface_.reset(wl_compositor_create_surface(display_->GetCompositor())); |
| 30 if (!surface_) { |
| 31 LOG(ERROR) << "Failed to create wl_surface"; |
| 32 return false; |
| 33 } |
| 34 wl_surface_set_user_data(surface_.get(), this); |
| 35 xdg_surface_.reset( |
| 36 xdg_shell_get_xdg_surface(display_->GetShell(), surface_.get())); |
| 37 if (!xdg_surface_) { |
| 38 LOG(ERROR) << "Failed to create xdg_surface"; |
| 39 return false; |
| 40 } |
| 41 xdg_surface_add_listener(xdg_surface_.get(), &xdg_surface_listener, this); |
| 42 |
| 43 delegate_->OnAcceleratedWidgetAvailable(surface_.id(), 1.f); |
| 44 display_->AddWindow(this); |
| 45 |
| 46 return true; |
| 47 } |
| 48 |
| 49 wl_surface* WaylandWindow::GetSurface() { |
| 50 DCHECK(surface_); |
| 51 return surface_.get(); |
| 52 } |
| 53 |
| 54 gfx::AcceleratedWidget WaylandWindow::GetWidget() { |
| 55 DCHECK(surface_); |
| 56 return surface_.id(); |
| 57 } |
| 58 |
| 59 void WaylandWindow::ApplyPendingBounds() { |
| 60 if (pending_bounds_.IsEmpty()) |
| 61 return; |
| 62 |
| 63 SetBounds(pending_bounds_); |
| 64 DCHECK(xdg_surface_); |
| 65 xdg_surface_ack_configure(xdg_surface_.get(), pending_configure_serial_); |
| 66 pending_bounds_ = gfx::Rect(); |
| 67 } |
| 68 |
| 69 void WaylandWindow::Show() {} |
| 70 |
| 71 void WaylandWindow::Hide() { |
| 72 NOTIMPLEMENTED(); |
| 73 } |
| 74 |
| 75 void WaylandWindow::Close() { |
| 76 NOTIMPLEMENTED(); |
| 77 } |
| 78 |
| 79 void WaylandWindow::SetBounds(const gfx::Rect& bounds) { |
| 80 if (bounds == bounds_) |
| 81 return; |
| 82 bounds_ = bounds; |
| 83 delegate_->OnBoundsChanged(bounds); |
| 84 } |
| 85 |
| 86 gfx::Rect WaylandWindow::GetBounds() { |
| 87 return bounds_; |
| 88 } |
| 89 |
| 90 void WaylandWindow::SetTitle(const base::string16& title) { |
| 91 DCHECK(xdg_surface_); |
| 92 xdg_surface_set_title(xdg_surface_.get(), UTF16ToUTF8(title).c_str()); |
| 93 } |
| 94 |
| 95 void WaylandWindow::SetCapture() { |
| 96 NOTIMPLEMENTED(); |
| 97 } |
| 98 |
| 99 void WaylandWindow::ReleaseCapture() { |
| 100 NOTIMPLEMENTED(); |
| 101 } |
| 102 |
| 103 void WaylandWindow::ToggleFullscreen() { |
| 104 NOTIMPLEMENTED(); |
| 105 } |
| 106 |
| 107 void WaylandWindow::Maximize() { |
| 108 xdg_surface_set_maximized(xdg_surface_.get()); |
| 109 } |
| 110 |
| 111 void WaylandWindow::Minimize() { |
| 112 xdg_surface_set_minimized(xdg_surface_.get()); |
| 113 } |
| 114 |
| 115 void WaylandWindow::Restore() { |
| 116 xdg_surface_unset_maximized(xdg_surface_.get()); |
| 117 } |
| 118 |
| 119 void WaylandWindow::SetCursor(PlatformCursor cursor) { |
| 120 NOTIMPLEMENTED(); |
| 121 } |
| 122 |
| 123 void WaylandWindow::MoveCursorTo(const gfx::Point& location) { |
| 124 NOTIMPLEMENTED(); |
| 125 } |
| 126 |
| 127 void WaylandWindow::ConfineCursorToBounds(const gfx::Rect& bounds) { |
| 128 NOTIMPLEMENTED(); |
| 129 } |
| 130 |
| 131 PlatformImeController* WaylandWindow::GetPlatformImeController() { |
| 132 NOTIMPLEMENTED(); |
| 133 return nullptr; |
| 134 } |
| 135 |
| 136 void WaylandWindow::Configure(void* data, |
| 137 xdg_surface* obj, |
| 138 int32_t width, |
| 139 int32_t height, |
| 140 wl_array* states, |
| 141 uint32_t serial) { |
| 142 WaylandWindow* window = static_cast<WaylandWindow*>(data); |
| 143 window->pending_bounds_ = gfx::Rect(0, 0, width, height); |
| 144 window->pending_configure_serial_ = serial; |
| 145 } |
| 146 |
| 147 void WaylandWindow::Close(void* data, xdg_surface* obj) { |
| 148 NOTIMPLEMENTED(); |
| 149 } |
| 150 |
| 151 } // namespace ui |
OLD | NEW |