Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: ui/aura/root_window_host_wayland.cc

Issue 17265006: wayland patch for inspection Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/root_window_host_wayland.h ('k') | ui/base/cursor/cursor_wayland.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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/aura/root_window_host_wayland.h"
6
7 #include <strings.h>
8
9 #include <algorithm>
10 #include <limits>
11 #include <string>
12
13 #include "base/wayland/wayland_event.h"
14 #include "ui/wayland/wayland_screen.h"
15 #include "base/command_line.h"
16 #include "base/message_loop.h"
17 #include "base/message_pump_wayland.h"
18 #include "base/stl_util.h"
19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h"
21 #include "base/stringprintf.h"
22 #include "ui/aura/client/capture_client.h"
23 #include "ui/aura/client/cursor_client.h"
24 #include "ui/aura/client/screen_position_client.h"
25 #include "ui/aura/client/user_action_client.h"
26 #include "ui/aura/env.h"
27 #include "ui/aura/root_window.h"
28 #include "ui/base/cursor/cursor.h"
29 #include "ui/base/events/event.h"
30 #include "ui/base/events/event_utils.h"
31 #include "ui/base/keycodes/keyboard_codes.h"
32 #include "ui/base/touch/touch_factory_x11.h"
33 #include "ui/base/ui_base_switches.h"
34 #include "ui/base/view_prop.h"
35 #include "ui/compositor/dip_util.h"
36 #include "ui/compositor/layer.h"
37 #include "ui/gfx/codec/png_codec.h"
38 #include "ui/gfx/screen.h"
39
40 #if defined(OS_CHROMEOS)
41 #include "base/chromeos/chromeos_version.h"
42 #endif
43
44 using std::max;
45 using std::min;
46
47 namespace aura {
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // RootWindowHostWayland
51
52 RootWindowHostWayland::RootWindowHostWayland(const gfx::Rect& bounds)
53 : delegate_(NULL),
54 display_(ui::WaylandDisplay::GetDisplay()),
55 current_cursor_(ui::kCursorNull),
56 bounds_(bounds),
57 focus_when_shown_(false) {
58
59 window_ = new ui::WaylandWindow(NULL, display_);
60 window_->SetParentWindow(NULL);
61 window_->SetBounds(bounds_);
62
63 base::MessagePumpWayland::Current()->AddDispatcherForWindow(this, window_);
64 base::MessagePumpWayland::Current()->AddDispatcherForRootWindow(this);
65
66 Env::GetInstance()->AddObserver(this);
67 }
68
69 RootWindowHostWayland::~RootWindowHostWayland() {
70 Env::GetInstance()->RemoveObserver(this);
71 base::MessagePumpWayland::Current()->RemoveDispatcherForRootWindow(this);
72 base::MessagePumpWayland::Current()->RemoveDispatcherForWindow(window_);
73
74 delete window_;
75 }
76
77 bool RootWindowHostWayland::Dispatch(const base::NativeEvent& event) {
78 return true;
79 }
80
81 void RootWindowHostWayland::SetDelegate(RootWindowHostDelegate* delegate) {
82 delegate_ = delegate;
83 }
84
85 RootWindow* RootWindowHostWayland::GetRootWindow() {
86 return delegate_->AsRootWindow();
87 }
88
89 gfx::AcceleratedWidget RootWindowHostWayland::GetAcceleratedWidget() {
90 return window_;
91 }
92
93 void RootWindowHostWayland::Show() {
94 window_->ScheduleRedraw();
95 }
96
97 void RootWindowHostWayland::Hide() {
98 }
99
100 void RootWindowHostWayland::ToggleFullScreen() {
101 NOTIMPLEMENTED();
102 }
103
104 gfx::Rect RootWindowHostWayland::GetBounds() const {
105 return bounds_;
106 }
107
108 void RootWindowHostWayland::SetBounds(const gfx::Rect& bounds) {
109 // Even if the host window's size doesn't change, aura's root window
110 // size, which is in DIP, changes when the scale changes.
111 float current_scale = delegate_->GetDeviceScaleFactor();
112 float new_scale = gfx::Screen::GetScreenFor(delegate_->AsRootWindow())->
113 GetDisplayNearestWindow(delegate_->AsRootWindow()).device_scale_factor();
114 bool origin_changed = bounds_.origin() != bounds.origin();
115 bool size_changed = bounds_.size() != bounds.size();
116
117 // Assume that the resize will go through as requested, which should be the
118 // case if we're running without a window manager. If there's a window
119 // manager, it can modify or ignore the request, but (per ICCCM) we'll get a
120 // (possibly synthetic) ConfigureNotify about the actual size and correct
121 // |bounds_| later.
122 bounds_ = bounds;
123 UpdateIsInternalDisplay();
124 if (origin_changed)
125 delegate_->OnHostMoved(bounds.origin());
126 if (size_changed || current_scale != new_scale) {
127 delegate_->OnHostResized(bounds.size());
128 } else {
129 delegate_->AsRootWindow()->SchedulePaintInRect(
130 delegate_->AsRootWindow()->bounds());
131 }
132
133 window_->SetBounds(bounds_);
134 }
135
136 gfx::Insets RootWindowHostWayland::GetInsets() const {
137 return insets_;
138 }
139
140 void RootWindowHostWayland::SetInsets(const gfx::Insets& insets) {
141 insets_ = insets;
142 }
143
144 gfx::Point RootWindowHostWayland::GetLocationOnNativeScreen() const {
145 return bounds_.origin();
146 }
147
148 void RootWindowHostWayland::SetCapture() {
149 // TODO(oshima): Grab x input.
150 }
151
152 void RootWindowHostWayland::ReleaseCapture() {
153 // TODO(oshima): Release x input.
154 }
155
156 void RootWindowHostWayland::SetCursor(gfx::NativeCursor cursor) {
157 if (cursor == current_cursor_)
158 return;
159 current_cursor_ = cursor;
160 SetCursorInternal(cursor);
161 }
162
163 bool RootWindowHostWayland::QueryMouseLocation(gfx::Point* location_return) {
164 return false;
165 }
166
167 bool RootWindowHostWayland::ConfineCursorToRootWindow() {
168 return true;
169 }
170
171 void RootWindowHostWayland::UnConfineCursor() {
172 }
173
174 void RootWindowHostWayland::OnCursorVisibilityChanged(bool show) {
175 }
176
177 void RootWindowHostWayland::MoveCursorTo(const gfx::Point& location) {
178 }
179
180 void RootWindowHostWayland::SetFocusWhenShown(bool focus_when_shown) {
181 }
182
183 bool RootWindowHostWayland::CopyAreaToSkCanvas(const gfx::Rect& source_bounds,
184 const gfx::Point& dest_offset,
185 SkCanvas* canvas) {
186 NOTIMPLEMENTED();
187 return false;
188 }
189
190 bool RootWindowHostWayland::GrabSnapshot(
191 const gfx::Rect& snapshot_bounds,
192 std::vector<unsigned char>* png_representation) {
193 return false;
194 }
195
196 void RootWindowHostWayland::PostNativeEvent(
197 const base::NativeEvent& native_event) {
198 DCHECK(window_);
199 DCHECK(display_);
200
201 NOTIMPLEMENTED();
202 }
203
204 void RootWindowHostWayland::OnDeviceScaleFactorChanged(
205 float device_scale_factor) {
206 }
207
208 void RootWindowHostWayland::PrepareForShutdown() {
209 base::MessagePumpWayland::Current()->RemoveDispatcherForWindow(window_);
210 }
211
212 void RootWindowHostWayland::OnWindowInitialized(Window* window) {
213 }
214
215 void RootWindowHostWayland::OnRootWindowInitialized(RootWindow* root_window) {
216 // UpdateIsInternalDisplay relies on:
217 // 1. delegate_ pointing to RootWindow - available after SetDelegate.
218 // 2. RootWindow's kDisplayIdKey property set - available by the time
219 // RootWindow::Init is called.
220 // (set in DisplayManager::CreateRootWindowForDisplay)
221 // Ready when NotifyRootWindowInitialized is called from RootWindow::Init.
222 if (!delegate_ || root_window != GetRootWindow())
223 return;
224 UpdateIsInternalDisplay();
225 }
226
227 bool RootWindowHostWayland::DispatchEventForRootWindow(
228 const base::NativeEvent& event) {
229 NOTIMPLEMENTED();
230
231 return true;
232 }
233
234 bool RootWindowHostWayland::IsWindowManagerPresent() {
235 return true;
236 }
237
238 void RootWindowHostWayland::SetCursorInternal(gfx::NativeCursor cursor) {
239 }
240
241 void RootWindowHostWayland::TranslateAndDispatchMouseEvent(
242 ui::MouseEvent* event) {
243 RootWindow* root_window = GetRootWindow();
244 client::ScreenPositionClient* screen_position_client =
245 GetScreenPositionClient(root_window);
246 gfx::Rect local(bounds_.size());
247
248 if (screen_position_client && !local.Contains(event->location())) {
249 gfx::Point location(event->location());
250 // In order to get the correct point in screen coordinates
251 // during passive grab, we first need to find on which host window
252 // the mouse is on, and find out the screen coordinates on that
253 // host window, then convert it back to this host window's coordinate.
254 screen_position_client->ConvertHostPointToScreen(root_window, &location);
255 screen_position_client->ConvertPointFromScreen(root_window, &location);
256 root_window->ConvertPointToHost(&location);
257 event->set_location(location);
258 event->set_root_location(location);
259 }
260 delegate_->OnHostMouseEvent(event);
261 }
262
263 void RootWindowHostWayland::UpdateIsInternalDisplay() {
264 RootWindow* root_window = GetRootWindow();
265 gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window);
266 gfx::Display display = screen->GetDisplayNearestWindow(root_window);
267 is_internal_display_ = display.IsInternal();
268 }
269
270 // static
271 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) {
272 return new RootWindowHostWayland(bounds);
273 }
274
275 // static
276 gfx::Size RootWindowHost::GetNativeScreenSize() {
277 ui::WaylandDisplay *d = base::MessagePumpWayland::GetDefaultWaylandDisplay();
278 std::list<ui::WaylandScreen*> list = d->GetScreenList();
279
280 if(list.size() < 1)
281 return gfx::Size();
282
283 ui::WaylandScreen *screen = list.front();
284 return screen->GetAllocation().size();
285 }
286
287 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window_host_wayland.h ('k') | ui/base/cursor/cursor_wayland.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698