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

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

Issue 1390883003: aura: Unify WindowTreeHost for some platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2015 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/window_tree_host_platform.h"
6
7
8 #include <algorithm>
9
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #endif
13
14 #include "base/trace_event/trace_event.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/events/event.h"
18
19 #if defined(OS_WIN)
20 #include "base/message_loop/message_loop.h"
21 #include "ui/base/cursor/cursor_loader_win.h"
22 #endif
23
24 using std::max;
25 using std::min;
26
27 namespace aura {
28
29 // static
30 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
31 return new WindowTreeHostPlatform(bounds);
32 }
33
34 // static
35 gfx::Size WindowTreeHost::GetNativeScreenSize() {
36 #if defined(OS_WIN)
37 return gfx::Size(GetSystemMetrics(SM_CXSCREEN),
38 GetSystemMetrics(SM_CYSCREEN));
39 #else
40 NOTIMPLEMENTED();
41 return gfx::Size();
42 #endif
43 }
44
45 WindowTreeHostPlatform::WindowTreeHostPlatform(const gfx::Rect& bounds)
46 : widget_(gfx::kNullAcceleratedWidget),
47 #if defined(USE_OZONE)
48 window_(ui::OzonePlatform::GetInstance()->CreatePlatformWindow(delegate,
49 bounds)),
50 #else
51 window_(PlatformWindow::Create(this, bounds)),
52 #endif
53 current_cursor_(ui::kCursorNull),
54 has_capture_(false) {
55 }
56
57 WindowTreeHostPlatform::~WindowTreeHostPlatform() {
58 DestroyCompositor();
59 DestroyDispatcher();
60 window_.reset();
dnicoara 2015/10/09 15:04:22 Any reason this is needed? The destructor should c
no sievers 2015/10/09 19:31:51 Done.
61 }
62
63 ui::EventSource* WindowTreeHostPlatform::GetEventSource() {
64 return this;
65 }
66
67 gfx::AcceleratedWidget WindowTreeHostPlatform::GetAcceleratedWidget() {
68 return widget_;
69 }
70
71 void WindowTreeHostPlatform::ShowImpl() {
72 window_->Show();
73 }
74
75 void WindowTreeHostPlatform::HideImpl() {
76 window_->Hide();
77 }
78
79 gfx::Rect WindowTreeHostPlatform::GetBounds() const {
80 return window_->GetBounds();
81 }
82
83 void WindowTreeHostPlatform::SetBounds(const gfx::Rect& bounds) {
84 window_->SetBounds(bounds);
85 }
86
87 gfx::Point WindowTreeHostPlatform::GetLocationOnNativeScreen() const {
88 return window_->GetBounds().origin();
89 }
90
91 void WindowTreeHostPlatform::SetCapture() {
92 #if defined(USE_OZONE)
93 window_->SetCapture();
94 #else
95 if (!has_capture_) {
96 has_capture_ = true;
97 window_->SetCapture();
98 }
99 #endif
100 }
101
102 void WindowTreeHostPlatform::ReleaseCapture() {
103 #if !defined(USE_OZONE)
104 if (has_capture_)
105 #endif
106 window_->ReleaseCapture();
107 }
108
109 void WindowTreeHostPlatform::SetCursorNative(gfx::NativeCursor native_cursor) {
110 if (cursor == current_cursor_)
111 return;
112 current_cursor_ = cursor;
113
114 #if defined(OS_WIN)
115 // Custom web cursors are handled directly.
116 if (native_cursor == ui::kCursorCustom)
117 return;
118
119 ui::CursorLoaderWin cursor_loader;
120 cursor_loader.SetPlatformCursor(&native_cursor);
121 ::SetCursor(native_cursor.platform());
122 #else
123 platform_window_->SetCursor(cursor.platform());
124 #endif
125 }
126
127 void WindowTreeHostPlatform::MoveCursorToNative(const gfx::Point& location) {
128 #if defined(OS_WIN)
129 // Deliberately not implemented.
130 #else
131 platform_window_->MoveCursorTo(location);
132 #endif
133 }
134
135 void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) {
136 NOTIMPLEMENTED();
137 }
138
139 void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) {
140 gfx::Rect old_bounds = bounds_;
141 bounds_ = new_bounds;
142 if (bounds_.origin() != old_bounds.origin())
143 OnHostMoved(bounds_.origin());
144 if (bounds_.size() != old_bounds.size())
145 OnHostResized(bounds_.size());
146 }
147
148 void WindowTreeHostPlatform::OnDamageRect(const gfx::Rect& damage_rect) {
149 // TODO: Can the ifdef be removed?
150 #if !defined(USE_OZONE)
dnicoara 2015/10/09 15:04:22 It should be safe to remove the #ifdef and call th
151 compositor()->ScheduleRedrawRect(damage_rect);
152 #endif
153 }
154
155 void WindowTreeHostPlatform::DispatchEvent(ui::Event* event) {
156 TRACE_EVENT0("input", "WindowTreeHostPlatform::DispatchEvent");
157 ui::EventDispatchDetails details = SendEventToProcessor(event);
158 if (details.dispatcher_destroyed)
159 event->SetHandled();
160 }
161
162 void WindowTreeHostPlatform::OnCloseRequest() {
163 #if defined(OS_WIN)
164 // TODO: this obviously shouldn't be here.
165 base::MessageLoopForUI::current()->Quit();
166 #else
167 OnHostCloseRequested();
168 #endif
169 }
170
171 void WindowTreeHostPlatform::OnClosed() {}
172
173 void WindowTreeHostPlatform::OnWindowStateChanged(
174 ui::PlatformWindowState new_state) {}
175
176 void WindowTreeHostPlatform::OnLostCapture() {
177 // TODO: Can the ifdef be removed?
178 #if !defined(USE_OZONE)
dnicoara 2015/10/09 15:04:22 It should be safe to remove the #ifdef (same with
179 if (has_capture_) {
180 has_capture_ = false;
181 OnHostLostWindowCapture();
182 }
183 #endif
184 }
185
186 void WindowTreeHostPlatform::OnAcceleratedWidgetAvailable(
187 gfx::AcceleratedWidget widget,
188 float device_pixel_ratio) {
189 widget_ = widget;
190 CreateCompositor();
191 WindowTreeHost::OnAcceleratedWidgetAvailable();
192 }
193
194 void WindowTreeHostPlatform::OnActivationChanged(bool active) {
195 // TODO: Can the ifdef be removed?
196 #if !defined(USE_OZONE)
dnicoara 2015/10/09 15:04:22 It should be safe to remove the #ifdef. All of th
197 if (active)
198 OnHostActivated();
199 #endif
200 }
201
202 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698