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

Side by Side Diff: ui/views/mus/desktop_window_tree_host_mus.cc

Issue 2471033005: Adds DesktopWindowTreeHostMus (Closed)
Patch Set: fix Created 4 years, 1 month 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 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/views/mus/desktop_window_tree_host_mus.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/drag_drop_client.h"
10 #include "ui/aura/client/focus_client.h"
11 #include "ui/aura/mus/window_tree_host_mus.h"
12 #include "ui/aura/window.h"
13 #include "ui/display/screen.h"
14 #include "ui/views/corewm/tooltip_aura.h"
15 #include "ui/views/mus/mus_client.h"
16 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
17 #include "ui/views/widget/widget_delegate.h"
18 #include "ui/wm/core/window_util.h"
19 #include "ui/wm/public/activation_client.h"
20
21 namespace views {
22
23 DesktopWindowTreeHostMus::DesktopWindowTreeHostMus(
24 internal::NativeWidgetDelegate* native_widget_delegate,
25 DesktopNativeWidgetAura* desktop_native_widget_aura)
26 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client()),
27 native_widget_delegate_(native_widget_delegate),
28 desktop_native_widget_aura_(desktop_native_widget_aura),
29 fullscreen_restore_state_(ui::SHOW_STATE_DEFAULT),
30 close_widget_factory_(this) {
31 // TODO: use display id and bounds if available, likely need to pass in
32 // InitParams for that.
33 }
34
35 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() {
36 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
37 }
38
39 bool DesktopWindowTreeHostMus::IsDocked() const {
40 return window()->GetProperty(aura::client::kShowStateKey) ==
41 ui::SHOW_STATE_DOCKED;
42 }
43
44 void DesktopWindowTreeHostMus::Init(aura::Window* content_window,
45 const Widget::InitParams& params) {}
46
47 void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
48 const Widget::InitParams& params) {}
49
50 std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostMus::CreateTooltip() {
51 return base::MakeUnique<corewm::TooltipAura>();
52 }
53
54 std::unique_ptr<aura::client::DragDropClient>
55 DesktopWindowTreeHostMus::CreateDragDropClient(
56 DesktopNativeCursorManager* cursor_manager) {
57 // aura-mus handles installing a DragDropClient.
58 return nullptr;
59 }
60
61 void DesktopWindowTreeHostMus::Close() {
62 if (close_widget_factory_.HasWeakPtrs())
63 return;
64
65 // Close doesn't delete this immediately, as 'this' may still be on the stack
66 // resulting in possible crashes when the stack unwindes.
67 base::ThreadTaskRunnerHandle::Get()->PostTask(
68 FROM_HERE, base::Bind(&DesktopWindowTreeHostMus::CloseNow,
69 close_widget_factory_.GetWeakPtr()));
70 }
71
72 void DesktopWindowTreeHostMus::CloseNow() {
73 native_widget_delegate_->OnNativeWidgetDestroying();
74 DestroyCompositor();
75 desktop_native_widget_aura_->OnHostClosed();
76 }
77
78 aura::WindowTreeHost* DesktopWindowTreeHostMus::AsWindowTreeHost() {
79 return this;
80 }
81
82 void DesktopWindowTreeHostMus::ShowWindowWithState(ui::WindowShowState state) {
83 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN ||
84 state == ui::SHOW_STATE_DOCKED) {
85 window()->SetProperty(aura::client::kShowStateKey, state);
86 }
87 window()->Show();
88 if (compositor())
89 compositor()->SetVisible(true);
90 // TODO: likely needs code to activate, but after content_window_ is shown.
91 // See NativeWidgetAura::ShowWithWindowState().
92 }
93
94 void DesktopWindowTreeHostMus::ShowMaximizedWithBounds(
95 const gfx::Rect& restored_bounds) {
96 window()->SetProperty(aura::client::kRestoreBoundsKey,
97 new gfx::Rect(restored_bounds));
98 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED);
99 }
100
101 bool DesktopWindowTreeHostMus::IsVisible() const {
102 return window()->IsVisible();
103 }
104
105 void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) {
106 window()->SetBounds(gfx::Rect(window()->bounds().origin(), size));
107 }
108
109 void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) {
110 NOTIMPLEMENTED();
111 }
112
113 void DesktopWindowTreeHostMus::StackAtTop() {
114 NOTIMPLEMENTED();
115 }
116
117 void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) {
118 NOTIMPLEMENTED();
119 }
120 void DesktopWindowTreeHostMus::GetWindowPlacement(
121 gfx::Rect* bounds,
122 ui::WindowShowState* show_state) const {
123 NOTIMPLEMENTED();
124 }
125 gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const {
126 // TODO: convert to dips.
127 return GetBounds();
128 }
129
130 gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const {
131 // View-to-screen coordinate system transformations depend on this returning
132 // the full window bounds, for example View::ConvertPointToScreen().
133 return GetWindowBoundsInScreen();
134 }
135
136 gfx::Rect DesktopWindowTreeHostMus::GetRestoredBounds() const {
137 // Restored bounds should only be relevant if the window is minimized,
138 // maximized, fullscreen or docked. However, in some places the code expects
139 // GetRestoredBounds() to return the current window bounds if the window is
140 // not in either state.
141 if (IsMinimized() || IsMaximized() || IsFullscreen()) {
142 // Restore bounds are in screen coordinates, no need to convert.
143 gfx::Rect* restore_bounds =
144 window()->GetProperty(aura::client::kRestoreBoundsKey);
145 if (restore_bounds)
146 return *restore_bounds;
147 }
148 gfx::Rect bounds = GetWindowBoundsInScreen();
149 if (IsDocked()) {
150 // Restore bounds are in screen coordinates, no need to convert.
151 gfx::Rect* restore_bounds =
152 window()->GetProperty(aura::client::kRestoreBoundsKey);
153 // Use current window horizontal offset origin in order to preserve docked
154 // alignment but preserve restored size and vertical offset for the time
155 // when the |window_| gets undocked.
156 if (restore_bounds) {
157 bounds.set_size(restore_bounds->size());
158 bounds.set_y(restore_bounds->y());
159 }
160 }
161 return bounds;
162 }
163
164 std::string DesktopWindowTreeHostMus::GetWorkspace() const {
165 // Only used on x11.
166 return std::string();
167 }
168
169 gfx::Rect DesktopWindowTreeHostMus::GetWorkAreaBoundsInScreen() const {
170 // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*.
171 return display::Screen::GetScreen()
172 ->GetDisplayNearestWindow(const_cast<aura::Window*>(window()))
173 .work_area();
174 }
175
176 void DesktopWindowTreeHostMus::SetShape(
177 std::unique_ptr<SkRegion> native_region) {
178 NOTIMPLEMENTED();
179 }
180
181 void DesktopWindowTreeHostMus::Activate() {
182 window()->Focus();
183 if (window()->GetProperty(aura::client::kDrawAttentionKey))
184 window()->SetProperty(aura::client::kDrawAttentionKey, false);
185 }
186
187 void DesktopWindowTreeHostMus::Deactivate() {
188 aura::client::GetActivationClient(window()->GetRootWindow())
189 ->DeactivateWindow(window());
190 }
191
192 bool DesktopWindowTreeHostMus::IsActive() const {
193 return wm::IsActiveWindow(const_cast<aura::Window*>(window()));
194 }
195
196 void DesktopWindowTreeHostMus::Maximize() {
197 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
198 }
199 void DesktopWindowTreeHostMus::Minimize() {
200 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
201 }
202
203 void DesktopWindowTreeHostMus::Restore() {
204 window()->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
205 }
206
207 bool DesktopWindowTreeHostMus::IsMaximized() const {
208 return window()->GetProperty(aura::client::kShowStateKey) ==
209 ui::SHOW_STATE_MAXIMIZED;
210 }
211
212 bool DesktopWindowTreeHostMus::IsMinimized() const {
213 return window()->GetProperty(aura::client::kShowStateKey) ==
214 ui::SHOW_STATE_MINIMIZED;
215 }
216
217 bool DesktopWindowTreeHostMus::HasCapture() const {
218 return const_cast<aura::Window*>(window())->HasCapture();
219 }
220
221 void DesktopWindowTreeHostMus::SetAlwaysOnTop(bool always_on_top) {
222 window()->SetProperty(aura::client::kAlwaysOnTopKey, always_on_top);
223 }
224
225 bool DesktopWindowTreeHostMus::IsAlwaysOnTop() const {
226 return window()->GetProperty(aura::client::kAlwaysOnTopKey);
227 }
228
229 void DesktopWindowTreeHostMus::SetVisibleOnAllWorkspaces(bool always_visible) {
230 // Not applicable to chromeos.
231 }
232
233 bool DesktopWindowTreeHostMus::IsVisibleOnAllWorkspaces() const {
234 return false;
235 }
236
237 bool DesktopWindowTreeHostMus::SetWindowTitle(const base::string16& title) {
238 if (window()->title() == title)
239 return false;
240 window()->SetTitle(title);
241 return true;
242 }
243
244 void DesktopWindowTreeHostMus::ClearNativeFocus() {
245 aura::client::FocusClient* client = aura::client::GetFocusClient(window());
246 if (client && window()->Contains(client->GetFocusedWindow()))
247 client->ResetFocusWithinActiveWindow(window());
248 }
249
250 Widget::MoveLoopResult DesktopWindowTreeHostMus::RunMoveLoop(
251 const gfx::Vector2d& drag_offset,
252 Widget::MoveLoopSource source,
253 Widget::MoveLoopEscapeBehavior escape_behavior) {
254 NOTIMPLEMENTED();
255 return Widget::MOVE_LOOP_CANCELED;
256 }
257
258 void DesktopWindowTreeHostMus::EndMoveLoop() {
259 NOTIMPLEMENTED();
260 }
261
262 void DesktopWindowTreeHostMus::SetVisibilityChangedAnimationsEnabled(
263 bool value) {
264 window()->SetProperty(aura::client::kAnimationsDisabledKey, !value);
265 }
266
267 bool DesktopWindowTreeHostMus::ShouldUseNativeFrame() const {
268 return false;
269 }
270
271 bool DesktopWindowTreeHostMus::ShouldWindowContentsBeTransparent() const {
272 return false;
273 }
274
275 void DesktopWindowTreeHostMus::FrameTypeChanged() {}
276
277 void DesktopWindowTreeHostMus::SetFullscreen(bool fullscreen) {
278 if (IsFullscreen() == fullscreen)
279 return; // Nothing to do.
280
281 // Save window state before entering full screen so that it could restored
282 // when exiting full screen.
283 if (fullscreen) {
284 fullscreen_restore_state_ =
285 window()->GetProperty(aura::client::kShowStateKey);
286 }
287
288 window()->SetProperty(
289 aura::client::kShowStateKey,
290 fullscreen ? ui::SHOW_STATE_FULLSCREEN : fullscreen_restore_state_);
291 }
292
293 bool DesktopWindowTreeHostMus::IsFullscreen() const {
294 return window()->GetProperty(aura::client::kShowStateKey) ==
295 ui::SHOW_STATE_FULLSCREEN;
296 }
297 void DesktopWindowTreeHostMus::SetOpacity(float opacity) {
298 // TODO: this likely need to go to server so that non-client decorations get
299 // opacity.
300 window()->layer()->SetOpacity(opacity);
301 }
302
303 void DesktopWindowTreeHostMus::SetWindowIcons(const gfx::ImageSkia& window_icon,
304 const gfx::ImageSkia& app_icon) {
305 if (window_icon.isNull() && app_icon.isNull()) {
306 window()->ClearProperty(aura::client::kWindowIconKey);
307 return;
308 }
309
310 window()->SetProperty(
311 aura::client::kWindowIconKey,
312 new gfx::ImageSkia(!window_icon.isNull() ? window_icon : app_icon));
313 }
314
315 void DesktopWindowTreeHostMus::InitModalType(ui::ModalType modal_type) {
316 window()->SetProperty(aura::client::kModalKey, modal_type);
317 }
318
319 void DesktopWindowTreeHostMus::FlashFrame(bool flash_frame) {
320 window()->SetProperty(aura::client::kDrawAttentionKey, flash_frame);
321 }
322
323 void DesktopWindowTreeHostMus::OnRootViewLayout() {}
324
325 bool DesktopWindowTreeHostMus::IsAnimatingClosed() const {
326 return false;
327 }
328
329 bool DesktopWindowTreeHostMus::IsTranslucentWindowOpacitySupported() const {
330 return true;
331 }
332
333 void DesktopWindowTreeHostMus::SizeConstraintsChanged() {
334 Widget* widget = native_widget_delegate_->AsWidget();
335 window()->SetProperty(aura::client::kCanMaximizeKey,
336 widget->widget_delegate()->CanMaximize());
337 window()->SetProperty(aura::client::kCanMinimizeKey,
338 widget->widget_delegate()->CanMinimize());
339 window()->SetProperty(aura::client::kCanResizeKey,
340 widget->widget_delegate()->CanResize());
341 }
342
343 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698