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

Side by Side Diff: ash/aura/wm_window_aura.cc

Issue 2629643002: chromeos: Renames WmWindowAura to WmWindow (Closed)
Patch Set: feedback Created 3 years, 11 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
« no previous file with comments | « ash/aura/wm_window_aura.h ('k') | ash/autoclick/autoclick_controller.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 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 "ash/aura/wm_window_aura.h"
6
7 #include "ash/aura/aura_layout_manager_adapter.h"
8 #include "ash/aura/wm_shell_aura.h"
9 #include "ash/common/ash_constants.h"
10 #include "ash/common/shelf/shelf_item_types.h"
11 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm_layout_manager.h"
13 #include "ash/common/wm_transient_window_observer.h"
14 #include "ash/common/wm_window_observer.h"
15 #include "ash/common/wm_window_property.h"
16 #include "ash/public/cpp/shell_window_ids.h"
17 #include "ash/root_window_controller.h"
18 #include "ash/screen_util.h"
19 #include "ash/shell.h"
20 #include "ash/wm/resize_handle_window_targeter.h"
21 #include "ash/wm/resize_shadow_controller.h"
22 #include "ash/wm/window_animations.h"
23 #include "ash/wm/window_mirror_view.h"
24 #include "ash/wm/window_properties.h"
25 #include "ash/wm/window_state_aura.h"
26 #include "ash/wm/window_util.h"
27 #include "base/memory/ptr_util.h"
28 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
29 #include "ui/aura/client/aura_constants.h"
30 #include "ui/aura/client/focus_client.h"
31 #include "ui/aura/client/window_parenting_client.h"
32 #include "ui/aura/env.h"
33 #include "ui/aura/layout_manager.h"
34 #include "ui/aura/mus/window_manager_delegate.h"
35 #include "ui/aura/mus/window_mus.h"
36 #include "ui/aura/mus/window_tree_client.h"
37 #include "ui/aura/window.h"
38 #include "ui/aura/window_delegate.h"
39 #include "ui/aura/window_property.h"
40 #include "ui/base/hit_test.h"
41 #include "ui/compositor/layer_tree_owner.h"
42 #include "ui/compositor/scoped_layer_animation_settings.h"
43 #include "ui/display/screen.h"
44 #include "ui/gfx/geometry/insets.h"
45 #include "ui/views/widget/widget.h"
46 #include "ui/views/widget/widget_delegate.h"
47 #include "ui/wm/core/coordinate_conversion.h"
48 #include "ui/wm/core/easy_resize_window_targeter.h"
49 #include "ui/wm/core/transient_window_manager.h"
50 #include "ui/wm/core/visibility_controller.h"
51 #include "ui/wm/core/window_util.h"
52
53 DECLARE_WINDOW_PROPERTY_TYPE(ash::WmWindowAura*);
54
55 namespace ash {
56
57 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WmWindowAura, kWmWindowKey, nullptr);
58
59 static_assert(aura::Window::kInitialId == kShellWindowId_Invalid,
60 "ids must match");
61
62 namespace {
63
64 // A tentative class to set the bounds on the window.
65 // TODO(oshima): Once all logic is cleaned up, move this to the real layout
66 // manager with proper friendship.
67 class BoundsSetter : public aura::LayoutManager {
68 public:
69 BoundsSetter() {}
70 ~BoundsSetter() override {}
71
72 // aura::LayoutManager overrides:
73 void OnWindowResized() override {}
74 void OnWindowAddedToLayout(aura::Window* child) override {}
75 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
76 void OnWindowRemovedFromLayout(aura::Window* child) override {}
77 void OnChildWindowVisibilityChanged(aura::Window* child,
78 bool visible) override {}
79 void SetChildBounds(aura::Window* child,
80 const gfx::Rect& requested_bounds) override {}
81
82 void SetBounds(aura::Window* window, const gfx::Rect& bounds) {
83 SetChildBoundsDirect(window, bounds);
84 }
85
86 private:
87 DISALLOW_COPY_AND_ASSIGN(BoundsSetter);
88 };
89
90 } // namespace
91
92 // static
93 bool WmWindowAura::default_use_empty_minimum_size_for_testing_ = false;
94
95 WmWindowAura::~WmWindowAura() {
96 if (added_transient_observer_)
97 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this);
98
99 window_->RemoveObserver(this);
100 }
101
102 // static
103 const WmWindowAura* WmWindowAura::Get(const aura::Window* window) {
104 if (!window)
105 return nullptr;
106
107 const WmWindowAura* wm_window = window->GetProperty(kWmWindowKey);
108 if (wm_window)
109 return wm_window;
110 // WmWindowAura is owned by the aura::Window.
111 // TODO(sky): fix constness.
112 return new WmWindowAura(const_cast<aura::Window*>(window));
113 }
114
115 // static
116 std::vector<WmWindow*> WmWindowAura::FromAuraWindows(
117 const std::vector<aura::Window*>& aura_windows) {
118 std::vector<WmWindow*> result(aura_windows.size());
119 for (size_t i = 0; i < aura_windows.size(); ++i)
120 result[i] = Get(aura_windows[i]);
121 return result;
122 }
123
124 // static
125 std::vector<aura::Window*> WmWindowAura::ToAuraWindows(
126 const std::vector<WmWindow*>& windows) {
127 std::vector<aura::Window*> result(windows.size());
128 for (size_t i = 0; i < windows.size(); ++i)
129 result[i] = WmWindowAura::GetAuraWindow(windows[i]);
130 return result;
131 }
132
133 // static
134 const aura::Window* WmWindowAura::GetAuraWindow(const WmWindow* wm_window) {
135 return wm_window ? static_cast<const WmWindowAura*>(wm_window)->aura_window()
136 : nullptr;
137 }
138
139 bool WmWindowAura::ShouldUseExtendedHitRegion() const {
140 const WmWindow* parent = Get(window_->parent());
141 return parent &&
142 static_cast<const WmWindowAura*>(parent)
143 ->children_use_extended_hit_region_;
144 }
145
146 void WmWindowAura::Destroy() {
147 delete window_;
148 // WARNING: this has been deleted.
149 }
150
151 const WmWindow* WmWindowAura::GetRootWindow() const {
152 return Get(window_->GetRootWindow());
153 }
154
155 RootWindowController* WmWindowAura::GetRootWindowController() {
156 aura::Window* root = window_->GetRootWindow();
157 return root ? RootWindowController::ForWindow(root) : nullptr;
158 }
159
160 WmShell* WmWindowAura::GetShell() const {
161 return WmShell::Get();
162 }
163
164 void WmWindowAura::SetName(const char* name) {
165 window_->SetName(name);
166 }
167
168 std::string WmWindowAura::GetName() const {
169 return window_->GetName();
170 }
171
172 void WmWindowAura::SetTitle(const base::string16& title) {
173 window_->SetTitle(title);
174 }
175
176 base::string16 WmWindowAura::GetTitle() const {
177 return window_->GetTitle();
178 }
179
180 void WmWindowAura::SetShellWindowId(int id) {
181 window_->set_id(id);
182 }
183
184 int WmWindowAura::GetShellWindowId() const {
185 return window_->id();
186 }
187
188 ui::wm::WindowType WmWindowAura::GetType() const {
189 return window_->type();
190 }
191
192 int WmWindowAura::GetAppType() const {
193 return window_->GetProperty(aura::client::kAppType);
194 }
195
196 void WmWindowAura::SetAppType(int app_type) const {
197 window_->SetProperty(aura::client::kAppType, app_type);
198 }
199
200 ui::Layer* WmWindowAura::GetLayer() {
201 return window_->layer();
202 }
203
204 bool WmWindowAura::GetLayerTargetVisibility() {
205 return GetLayer()->GetTargetVisibility();
206 }
207
208 bool WmWindowAura::GetLayerVisible() {
209 return GetLayer()->visible();
210 }
211
212 display::Display WmWindowAura::GetDisplayNearestWindow() {
213 return display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
214 }
215
216 bool WmWindowAura::HasNonClientArea() {
217 return window_->delegate() ? true : false;
218 }
219
220 int WmWindowAura::GetNonClientComponent(const gfx::Point& location) {
221 return window_->delegate()
222 ? window_->delegate()->GetNonClientComponent(location)
223 : HTNOWHERE;
224 }
225
226 gfx::Point WmWindowAura::ConvertPointToTarget(const WmWindow* target,
227 const gfx::Point& point) const {
228 gfx::Point result(point);
229 aura::Window::ConvertPointToTarget(window_, GetAuraWindow(target), &result);
230 return result;
231 }
232
233 gfx::Point WmWindowAura::ConvertPointToScreen(const gfx::Point& point) const {
234 gfx::Point result(point);
235 ::wm::ConvertPointToScreen(window_, &result);
236 return result;
237 }
238
239 gfx::Point WmWindowAura::ConvertPointFromScreen(const gfx::Point& point) const {
240 gfx::Point result(point);
241 ::wm::ConvertPointFromScreen(window_, &result);
242 return result;
243 }
244
245 gfx::Rect WmWindowAura::ConvertRectToScreen(const gfx::Rect& rect) const {
246 return ScreenUtil::ConvertRectToScreen(window_, rect);
247 }
248
249 gfx::Rect WmWindowAura::ConvertRectFromScreen(const gfx::Rect& rect) const {
250 return ScreenUtil::ConvertRectFromScreen(window_, rect);
251 }
252
253 gfx::Size WmWindowAura::GetMinimumSize() const {
254 return window_->delegate() && !use_empty_minimum_size_for_testing_
255 ? window_->delegate()->GetMinimumSize()
256 : gfx::Size();
257 }
258
259 gfx::Size WmWindowAura::GetMaximumSize() const {
260 return window_->delegate() ? window_->delegate()->GetMaximumSize()
261 : gfx::Size();
262 }
263
264 bool WmWindowAura::GetTargetVisibility() const {
265 return window_->TargetVisibility();
266 }
267
268 bool WmWindowAura::IsVisible() const {
269 return window_->IsVisible();
270 }
271
272 void WmWindowAura::SetOpacity(float opacity) {
273 window_->layer()->SetOpacity(opacity);
274 }
275
276 float WmWindowAura::GetTargetOpacity() const {
277 return window_->layer()->GetTargetOpacity();
278 }
279
280 gfx::Rect WmWindowAura::GetMinimizeAnimationTargetBoundsInScreen() const {
281 return ash::GetMinimizeAnimationTargetBoundsInScreen(window_);
282 }
283
284 void WmWindowAura::SetTransform(const gfx::Transform& transform) {
285 window_->SetTransform(transform);
286 }
287
288 gfx::Transform WmWindowAura::GetTargetTransform() const {
289 return window_->layer()->GetTargetTransform();
290 }
291
292 bool WmWindowAura::IsSystemModal() const {
293 return window_->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM;
294 }
295
296 bool WmWindowAura::GetBoolProperty(WmWindowProperty key) {
297 switch (key) {
298 case WmWindowProperty::DRAW_ATTENTION:
299 return window_->GetProperty(aura::client::kDrawAttentionKey);
300
301 case WmWindowProperty::PANEL_ATTACHED:
302 return window_->GetProperty(kPanelAttachedKey);
303
304 case WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY:
305 return window_->GetProperty(kSnapChildrenToPixelBoundary);
306
307 case WmWindowProperty::ALWAYS_ON_TOP:
308 return window_->GetProperty(aura::client::kAlwaysOnTopKey);
309
310 default:
311 NOTREACHED();
312 break;
313 }
314
315 return false;
316 }
317
318 void WmWindowAura::SetBoolProperty(WmWindowProperty key, bool value) {
319 switch (key) {
320 case WmWindowProperty::PANEL_ATTACHED:
321 window_->SetProperty(kPanelAttachedKey, value);
322 break;
323 default:
324 NOTREACHED();
325 break;
326 }
327 }
328
329 SkColor WmWindowAura::GetColorProperty(WmWindowProperty key) {
330 if (key == WmWindowProperty::TOP_VIEW_COLOR)
331 return window_->GetProperty(aura::client::kTopViewColor);
332
333 NOTREACHED();
334 return 0;
335 }
336
337 void WmWindowAura::SetColorProperty(WmWindowProperty key, SkColor value) {
338 if (key == WmWindowProperty::TOP_VIEW_COLOR) {
339 window_->SetProperty(aura::client::kTopViewColor, value);
340 return;
341 }
342
343 NOTREACHED();
344 }
345
346 int WmWindowAura::GetIntProperty(WmWindowProperty key) {
347 if (key == WmWindowProperty::MODAL_TYPE)
348 return window_->GetProperty(aura::client::kModalKey);
349
350 if (key == WmWindowProperty::SHELF_ID)
351 return window_->GetProperty(kShelfIDKey);
352
353 if (key == WmWindowProperty::SHELF_ITEM_TYPE) {
354 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL ||
355 window_->GetProperty(kShelfItemTypeKey) != TYPE_UNDEFINED) {
356 return window_->GetProperty(kShelfItemTypeKey);
357 }
358 // Mash provides a default shelf item type for non-ignored windows.
359 return GetWindowState()->ignored_by_shelf() ? TYPE_UNDEFINED : TYPE_APP;
360 }
361
362 if (key == WmWindowProperty::TOP_VIEW_INSET)
363 return window_->GetProperty(aura::client::kTopViewInset);
364
365 NOTREACHED();
366 return 0;
367 }
368
369 void WmWindowAura::SetIntProperty(WmWindowProperty key, int value) {
370 if (key == WmWindowProperty::SHELF_ID) {
371 window_->SetProperty(kShelfIDKey, value);
372 return;
373 }
374 if (key == WmWindowProperty::SHELF_ITEM_TYPE) {
375 window_->SetProperty(kShelfItemTypeKey, value);
376 return;
377 }
378 if (key == WmWindowProperty::TOP_VIEW_INSET) {
379 window_->SetProperty(aura::client::kTopViewInset, value);
380 return;
381 }
382
383 NOTREACHED();
384 }
385
386 std::string WmWindowAura::GetStringProperty(WmWindowProperty key) {
387 if (key == WmWindowProperty::APP_ID) {
388 std::string* value = window_->GetProperty(aura::client::kAppIdKey);
389 return value ? *value : std::string();
390 }
391
392 NOTREACHED();
393 return std::string();
394 }
395
396 void WmWindowAura::SetStringProperty(WmWindowProperty key,
397 const std::string& value) {
398 if (key == WmWindowProperty::APP_ID) {
399 window_->SetProperty(aura::client::kAppIdKey, new std::string(value));
400 return;
401 }
402
403 NOTREACHED();
404 }
405
406 gfx::ImageSkia WmWindowAura::GetWindowIcon() {
407 gfx::ImageSkia* image = window_->GetProperty(aura::client::kWindowIconKey);
408 return image ? *image : gfx::ImageSkia();
409 }
410
411 gfx::ImageSkia WmWindowAura::GetAppIcon() {
412 gfx::ImageSkia* image = window_->GetProperty(aura::client::kAppIconKey);
413 return image ? *image : gfx::ImageSkia();
414 }
415
416 const wm::WindowState* WmWindowAura::GetWindowState() const {
417 return ash::wm::GetWindowState(window_);
418 }
419
420 WmWindow* WmWindowAura::GetToplevelWindow() {
421 return Get(window_->GetToplevelWindow());
422 }
423
424 WmWindow* WmWindowAura::GetToplevelWindowForFocus() {
425 return Get(::wm::GetToplevelWindow(window_));
426 }
427
428 void WmWindowAura::SetParentUsingContext(WmWindow* context,
429 const gfx::Rect& screen_bounds) {
430 aura::client::ParentWindowWithContext(window_, GetAuraWindow(context),
431 screen_bounds);
432 }
433
434 void WmWindowAura::AddChild(WmWindow* window) {
435 window_->AddChild(GetAuraWindow(window));
436 }
437
438 void WmWindowAura::RemoveChild(WmWindow* child) {
439 window_->RemoveChild(GetAuraWindow(child));
440 }
441
442 const WmWindow* WmWindowAura::GetParent() const {
443 return Get(window_->parent());
444 }
445
446 const WmWindow* WmWindowAura::GetTransientParent() const {
447 return Get(::wm::GetTransientParent(window_));
448 }
449
450 std::vector<WmWindow*> WmWindowAura::GetTransientChildren() {
451 return FromAuraWindows(::wm::GetTransientChildren(window_));
452 }
453
454 bool WmWindowAura::MoveToEventRoot(const ui::Event& event) {
455 return ash::wm::MoveWindowToEventRoot(window_, event);
456 }
457
458 void WmWindowAura::SetLayoutManager(
459 std::unique_ptr<WmLayoutManager> layout_manager) {
460 // See ~AuraLayoutManagerAdapter for why SetLayoutManager(nullptr) is called.
461 window_->SetLayoutManager(nullptr);
462 if (!layout_manager)
463 return;
464
465 // |window_| takes ownership of AuraLayoutManagerAdapter.
466 window_->SetLayoutManager(
467 new AuraLayoutManagerAdapter(window_, std::move(layout_manager)));
468 }
469
470 WmLayoutManager* WmWindowAura::GetLayoutManager() {
471 AuraLayoutManagerAdapter* adapter = AuraLayoutManagerAdapter::Get(window_);
472 return adapter ? adapter->wm_layout_manager() : nullptr;
473 }
474
475 void WmWindowAura::SetVisibilityChangesAnimated() {
476 ::wm::SetWindowVisibilityChangesAnimated(window_);
477 }
478
479 void WmWindowAura::SetVisibilityAnimationType(int type) {
480 ::wm::SetWindowVisibilityAnimationType(window_, type);
481 }
482
483 void WmWindowAura::SetVisibilityAnimationDuration(base::TimeDelta delta) {
484 ::wm::SetWindowVisibilityAnimationDuration(window_, delta);
485 }
486
487 void WmWindowAura::SetVisibilityAnimationTransition(
488 ::wm::WindowVisibilityAnimationTransition transition) {
489 ::wm::SetWindowVisibilityAnimationTransition(window_, transition);
490 }
491
492 void WmWindowAura::Animate(::wm::WindowAnimationType type) {
493 ::wm::AnimateWindow(window_, type);
494 }
495
496 void WmWindowAura::StopAnimatingProperty(
497 ui::LayerAnimationElement::AnimatableProperty property) {
498 window_->layer()->GetAnimator()->StopAnimatingProperty(property);
499 }
500
501 void WmWindowAura::SetChildWindowVisibilityChangesAnimated() {
502 ::wm::SetChildWindowVisibilityChangesAnimated(window_);
503 }
504
505 void WmWindowAura::SetMasksToBounds(bool value) {
506 window_->layer()->SetMasksToBounds(value);
507 }
508
509 void WmWindowAura::SetBounds(const gfx::Rect& bounds) {
510 window_->SetBounds(bounds);
511 }
512
513 void WmWindowAura::SetBoundsWithTransitionDelay(const gfx::Rect& bounds,
514 base::TimeDelta delta) {
515 if (::wm::WindowAnimationsDisabled(window_)) {
516 window_->SetBounds(bounds);
517 return;
518 }
519
520 ui::ScopedLayerAnimationSettings settings(window_->layer()->GetAnimator());
521 settings.SetTransitionDuration(delta);
522 window_->SetBounds(bounds);
523 }
524
525 void WmWindowAura::SetBoundsDirect(const gfx::Rect& bounds) {
526 BoundsSetter().SetBounds(window_, bounds);
527 wm::SnapWindowToPixelBoundary(window_);
528 }
529
530 void WmWindowAura::SetBoundsDirectAnimated(const gfx::Rect& bounds) {
531 const int kBoundsChangeSlideDurationMs = 120;
532
533 ui::Layer* layer = window_->layer();
534 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator());
535 slide_settings.SetPreemptionStrategy(
536 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
537 slide_settings.SetTransitionDuration(
538 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs));
539 SetBoundsDirect(bounds);
540 }
541
542 void WmWindowAura::SetBoundsDirectCrossFade(const gfx::Rect& bounds) {
543 const gfx::Rect old_bounds = window_->bounds();
544
545 // Create fresh layers for the window and all its children to paint into.
546 // Takes ownership of the old layer and all its children, which will be
547 // cleaned up after the animation completes.
548 // Specify |set_bounds| to true here to keep the old bounds in the child
549 // windows of |window|.
550 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner =
551 ::wm::RecreateLayers(window_);
552 ui::Layer* old_layer = old_layer_owner->root();
553 DCHECK(old_layer);
554 ui::Layer* new_layer = window_->layer();
555
556 // Resize the window to the new size, which will force a layout and paint.
557 SetBoundsDirect(bounds);
558
559 // Ensure the higher-resolution layer is on top.
560 bool old_on_top = (old_bounds.width() > bounds.width());
561 if (old_on_top)
562 old_layer->parent()->StackBelow(new_layer, old_layer);
563 else
564 old_layer->parent()->StackAbove(new_layer, old_layer);
565
566 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT);
567 }
568
569 void WmWindowAura::SetBoundsInScreen(const gfx::Rect& bounds_in_screen,
570 const display::Display& dst_display) {
571 window_->SetBoundsInScreen(bounds_in_screen, dst_display);
572 }
573
574 gfx::Rect WmWindowAura::GetBoundsInScreen() const {
575 return window_->GetBoundsInScreen();
576 }
577
578 const gfx::Rect& WmWindowAura::GetBounds() const {
579 return window_->bounds();
580 }
581
582 gfx::Rect WmWindowAura::GetTargetBounds() {
583 return window_->GetTargetBounds();
584 }
585
586 void WmWindowAura::ClearRestoreBounds() {
587 window_->ClearProperty(aura::client::kRestoreBoundsKey);
588 }
589
590 void WmWindowAura::SetRestoreBoundsInScreen(const gfx::Rect& bounds) {
591 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
592 }
593
594 gfx::Rect WmWindowAura::GetRestoreBoundsInScreen() const {
595 gfx::Rect* bounds = window_->GetProperty(aura::client::kRestoreBoundsKey);
596 return bounds ? *bounds : gfx::Rect();
597 }
598
599 bool WmWindowAura::Contains(const WmWindow* other) const {
600 return other
601 ? window_->Contains(
602 static_cast<const WmWindowAura*>(other)->window_)
603 : false;
604 }
605
606 void WmWindowAura::SetShowState(ui::WindowShowState show_state) {
607 window_->SetProperty(aura::client::kShowStateKey, show_state);
608 }
609
610 ui::WindowShowState WmWindowAura::GetShowState() const {
611 return window_->GetProperty(aura::client::kShowStateKey);
612 }
613
614 void WmWindowAura::SetRestoreShowState(ui::WindowShowState show_state) {
615 window_->SetProperty(aura::client::kRestoreShowStateKey, show_state);
616 }
617
618 void WmWindowAura::SetRestoreOverrides(
619 const gfx::Rect& bounds_override,
620 ui::WindowShowState window_state_override) {
621 if (bounds_override.IsEmpty()) {
622 window_->ClearProperty(kRestoreShowStateOverrideKey);
623 window_->ClearProperty(kRestoreBoundsOverrideKey);
624 return;
625 }
626 window_->SetProperty(kRestoreShowStateOverrideKey, window_state_override);
627 window_->SetProperty(kRestoreBoundsOverrideKey,
628 new gfx::Rect(bounds_override));
629 }
630
631 void WmWindowAura::SetLockedToRoot(bool value) {
632 window_->SetProperty(kLockedToRootKey, value);
633 }
634
635 bool WmWindowAura::IsLockedToRoot() const {
636 return window_->GetProperty(kLockedToRootKey);
637 }
638
639 void WmWindowAura::SetCapture() {
640 window_->SetCapture();
641 }
642
643 bool WmWindowAura::HasCapture() {
644 return window_->HasCapture();
645 }
646
647 void WmWindowAura::ReleaseCapture() {
648 window_->ReleaseCapture();
649 }
650
651 bool WmWindowAura::HasRestoreBounds() const {
652 return window_->GetProperty(aura::client::kRestoreBoundsKey) != nullptr;
653 }
654
655 bool WmWindowAura::CanMaximize() const {
656 return (window_->GetProperty(aura::client::kResizeBehaviorKey) &
657 ui::mojom::kResizeBehaviorCanMaximize) != 0;
658 }
659
660 bool WmWindowAura::CanMinimize() const {
661 return (window_->GetProperty(aura::client::kResizeBehaviorKey) &
662 ui::mojom::kResizeBehaviorCanMinimize) != 0;
663 }
664
665 bool WmWindowAura::CanResize() const {
666 return (window_->GetProperty(aura::client::kResizeBehaviorKey) &
667 ui::mojom::kResizeBehaviorCanResize) != 0;
668 }
669
670 bool WmWindowAura::CanActivate() const {
671 // TODO(sky): for aura-mus need to key off CanFocus() as well, which is not
672 // currently mirrored to ash.
673 return ::wm::CanActivateWindow(window_);
674 }
675
676 void WmWindowAura::StackChildAtTop(WmWindow* child) {
677 window_->StackChildAtTop(GetAuraWindow(child));
678 }
679
680 void WmWindowAura::StackChildAtBottom(WmWindow* child) {
681 window_->StackChildAtBottom(GetAuraWindow(child));
682 }
683
684 void WmWindowAura::StackChildAbove(WmWindow* child, WmWindow* target) {
685 window_->StackChildAbove(GetAuraWindow(child), GetAuraWindow(target));
686 }
687
688 void WmWindowAura::StackChildBelow(WmWindow* child, WmWindow* target) {
689 window_->StackChildBelow(GetAuraWindow(child), GetAuraWindow(target));
690 }
691
692 void WmWindowAura::SetPinned(bool trusted) {
693 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) {
694 // TODO: fix, see http://crbug.com/622486. With aura-mus pinning may just
695 // work.
696 NOTIMPLEMENTED();
697 return;
698 }
699 wm::PinWindow(window_, trusted);
700 }
701
702 void WmWindowAura::SetAlwaysOnTop(bool value) {
703 window_->SetProperty(aura::client::kAlwaysOnTopKey, value);
704 }
705
706 bool WmWindowAura::IsAlwaysOnTop() const {
707 return window_->GetProperty(aura::client::kAlwaysOnTopKey);
708 }
709
710 void WmWindowAura::Hide() {
711 window_->Hide();
712 }
713
714 void WmWindowAura::Show() {
715 window_->Show();
716 }
717
718 views::Widget* WmWindowAura::GetInternalWidget() {
719 return window_->GetProperty(kWidgetCreationTypeKey) ==
720 WidgetCreationType::INTERNAL
721 ? views::Widget::GetWidgetForNativeView(window_)
722 : nullptr;
723 }
724
725 void WmWindowAura::CloseWidget() {
726 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
727 aura_window()->GetProperty(kWidgetCreationTypeKey) ==
728 WidgetCreationType::FOR_CLIENT) {
729 // NOTE: in the FOR_CLIENT case there is not necessarily a widget associated
730 // with the window. Mash only creates widgets for top level windows if mash
731 // renders the non-client frame.
732 DCHECK(Shell::window_manager_client());
733 Shell::window_manager_client()->RequestClose(aura_window());
734 return;
735 }
736 DCHECK(GetInternalWidget());
737 GetInternalWidget()->Close();
738 }
739
740 void WmWindowAura::SetFocused() {
741 aura::client::GetFocusClient(window_)->FocusWindow(window_);
742 }
743
744 bool WmWindowAura::IsFocused() const {
745 return window_->HasFocus();
746 }
747
748 bool WmWindowAura::IsActive() const {
749 return wm::IsActiveWindow(window_);
750 }
751
752 void WmWindowAura::Activate() {
753 wm::ActivateWindow(window_);
754 }
755
756 void WmWindowAura::Deactivate() {
757 wm::DeactivateWindow(window_);
758 }
759
760 void WmWindowAura::SetFullscreen() {
761 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
762 }
763
764 void WmWindowAura::Maximize() {
765 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
766 }
767
768 void WmWindowAura::Minimize() {
769 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
770 }
771
772 void WmWindowAura::Unminimize() {
773 window_->SetProperty(
774 aura::client::kShowStateKey,
775 window_->GetProperty(aura::client::kRestoreShowStateKey));
776 window_->ClearProperty(aura::client::kRestoreShowStateKey);
777 }
778
779 std::vector<WmWindow*> WmWindowAura::GetChildren() {
780 return FromAuraWindows(window_->children());
781 }
782
783 WmWindow* WmWindowAura::GetChildByShellWindowId(int id) {
784 return Get(window_->GetChildById(id));
785 }
786
787 void WmWindowAura::ShowResizeShadow(int component) {
788 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) {
789 // TODO: http://crbug.com/640773.
790 return;
791 }
792 ResizeShadowController* resize_shadow_controller =
793 Shell::GetInstance()->resize_shadow_controller();
794 if (resize_shadow_controller)
795 resize_shadow_controller->ShowShadow(window_, component);
796 }
797
798 void WmWindowAura::HideResizeShadow() {
799 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) {
800 // TODO: http://crbug.com/640773.
801 return;
802 }
803 ResizeShadowController* resize_shadow_controller =
804 Shell::GetInstance()->resize_shadow_controller();
805 if (resize_shadow_controller)
806 resize_shadow_controller->HideShadow(window_);
807 }
808
809 void WmWindowAura::InstallResizeHandleWindowTargeter(
810 ImmersiveFullscreenController* immersive_fullscreen_controller) {
811 window_->SetEventTargeter(base::MakeUnique<ResizeHandleWindowTargeter>(
812 window_, immersive_fullscreen_controller));
813 }
814
815 void WmWindowAura::SetBoundsInScreenBehaviorForChildren(
816 BoundsInScreenBehavior behavior) {
817 window_->SetProperty(
818 kUsesScreenCoordinatesKey,
819 behavior == BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
820 }
821
822 void WmWindowAura::SetSnapsChildrenToPhysicalPixelBoundary() {
823 wm::SetSnapsChildrenToPhysicalPixelBoundary(window_);
824 }
825
826 void WmWindowAura::SnapToPixelBoundaryIfNecessary() {
827 wm::SnapWindowToPixelBoundary(window_);
828 }
829
830 void WmWindowAura::SetChildrenUseExtendedHitRegion() {
831 children_use_extended_hit_region_ = true;
832 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
833 -kResizeOutsideBoundsSize,
834 -kResizeOutsideBoundsSize);
835 gfx::Insets touch_extend =
836 mouse_extend.Scale(kResizeOutsideBoundsScaleForTouch);
837 // TODO: EasyResizeWindowTargeter makes it so children get events outside
838 // their bounds. This only works in mash when mash is providing the non-client
839 // frame. Mus needs to support an api for the WindowManager that enables
840 // events to be dispatched to windows outside the windows bounds that this
841 // function calls into. http://crbug.com/679056.
842 window_->SetEventTargeter(base::MakeUnique<::wm::EasyResizeWindowTargeter>(
843 window_, mouse_extend, touch_extend));
844 }
845
846 std::unique_ptr<views::View> WmWindowAura::CreateViewWithRecreatedLayers() {
847 return base::MakeUnique<wm::WindowMirrorView>(this);
848 }
849
850 void WmWindowAura::AddObserver(WmWindowObserver* observer) {
851 observers_.AddObserver(observer);
852 }
853
854 void WmWindowAura::RemoveObserver(WmWindowObserver* observer) {
855 observers_.RemoveObserver(observer);
856 }
857
858 bool WmWindowAura::HasObserver(const WmWindowObserver* observer) const {
859 return observers_.HasObserver(observer);
860 }
861
862 void WmWindowAura::AddTransientWindowObserver(
863 WmTransientWindowObserver* observer) {
864 if (!added_transient_observer_) {
865 added_transient_observer_ = true;
866 ::wm::TransientWindowManager::Get(window_)->AddObserver(this);
867 }
868 transient_observers_.AddObserver(observer);
869 }
870
871 void WmWindowAura::RemoveTransientWindowObserver(
872 WmTransientWindowObserver* observer) {
873 transient_observers_.RemoveObserver(observer);
874 if (added_transient_observer_ &&
875 !transient_observers_.might_have_observers()) {
876 added_transient_observer_ = false;
877 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this);
878 }
879 }
880
881 void WmWindowAura::AddLimitedPreTargetHandler(ui::EventHandler* handler) {
882 // In mus AddPreTargetHandler() only works for windows created by this client.
883 DCHECK(aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL ||
884 Shell::window_tree_client()->WasCreatedByThisClient(
885 aura::WindowMus::Get(window_)));
886 window_->AddPreTargetHandler(handler);
887 }
888
889 void WmWindowAura::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) {
890 window_->RemovePreTargetHandler(handler);
891 }
892
893 WmWindowAura::WmWindowAura(aura::Window* window)
894 : window_(window),
895 // Mirrors that of aura::Window.
896 observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY),
897 use_empty_minimum_size_for_testing_(
898 default_use_empty_minimum_size_for_testing_) {
899 window_->AddObserver(this);
900 window_->SetProperty(kWmWindowKey, this);
901 }
902
903 // static
904 bool WmWindowAura::HasInstance(const aura::Window* window) {
905 return window->GetProperty(kWmWindowKey) != nullptr;
906 }
907
908 void WmWindowAura::OnWindowHierarchyChanging(
909 const HierarchyChangeParams& params) {
910 WmWindowObserver::TreeChangeParams wm_params;
911 wm_params.target = Get(params.target);
912 wm_params.new_parent = Get(params.new_parent);
913 wm_params.old_parent = Get(params.old_parent);
914 for (auto& observer : observers_)
915 observer.OnWindowTreeChanging(this, wm_params);
916 }
917
918 void WmWindowAura::OnWindowHierarchyChanged(
919 const HierarchyChangeParams& params) {
920 WmWindowObserver::TreeChangeParams wm_params;
921 wm_params.target = Get(params.target);
922 wm_params.new_parent = Get(params.new_parent);
923 wm_params.old_parent = Get(params.old_parent);
924 for (auto& observer : observers_)
925 observer.OnWindowTreeChanged(this, wm_params);
926 }
927
928 void WmWindowAura::OnWindowStackingChanged(aura::Window* window) {
929 for (auto& observer : observers_)
930 observer.OnWindowStackingChanged(this);
931 }
932
933 void WmWindowAura::OnWindowPropertyChanged(aura::Window* window,
934 const void* key,
935 intptr_t old) {
936 if (key == aura::client::kShowStateKey) {
937 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged();
938 return;
939 }
940 WmWindowProperty wm_property;
941 if (key == aura::client::kAlwaysOnTopKey) {
942 wm_property = WmWindowProperty::ALWAYS_ON_TOP;
943 } else if (key == aura::client::kAppIconKey) {
944 wm_property = WmWindowProperty::APP_ICON;
945 } else if (key == aura::client::kDrawAttentionKey) {
946 wm_property = WmWindowProperty::DRAW_ATTENTION;
947 } else if (key == aura::client::kModalKey) {
948 wm_property = WmWindowProperty::MODAL_TYPE;
949 } else if (key == kPanelAttachedKey) {
950 wm_property = WmWindowProperty::PANEL_ATTACHED;
951 } else if (key == kShelfIDKey) {
952 wm_property = WmWindowProperty::SHELF_ID;
953 } else if (key == kShelfItemTypeKey) {
954 wm_property = WmWindowProperty::SHELF_ITEM_TYPE;
955 } else if (key == kSnapChildrenToPixelBoundary) {
956 wm_property = WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY;
957 } else if (key == aura::client::kTopViewInset) {
958 wm_property = WmWindowProperty::TOP_VIEW_INSET;
959 } else if (key == aura::client::kWindowIconKey) {
960 wm_property = WmWindowProperty::WINDOW_ICON;
961 } else {
962 return;
963 }
964 for (auto& observer : observers_)
965 observer.OnWindowPropertyChanged(this, wm_property);
966 }
967
968 void WmWindowAura::OnWindowBoundsChanged(aura::Window* window,
969 const gfx::Rect& old_bounds,
970 const gfx::Rect& new_bounds) {
971 for (auto& observer : observers_)
972 observer.OnWindowBoundsChanged(this, old_bounds, new_bounds);
973 }
974
975 void WmWindowAura::OnWindowDestroying(aura::Window* window) {
976 for (auto& observer : observers_)
977 observer.OnWindowDestroying(this);
978 }
979
980 void WmWindowAura::OnWindowDestroyed(aura::Window* window) {
981 for (auto& observer : observers_)
982 observer.OnWindowDestroyed(this);
983 }
984
985 void WmWindowAura::OnWindowVisibilityChanging(aura::Window* window,
986 bool visible) {
987 DCHECK_EQ(window, window_);
988 for (auto& observer : observers_)
989 observer.OnWindowVisibilityChanging(this, visible);
990 }
991
992 void WmWindowAura::OnWindowVisibilityChanged(aura::Window* window,
993 bool visible) {
994 for (auto& observer : observers_)
995 observer.OnWindowVisibilityChanged(Get(window), visible);
996 }
997
998 void WmWindowAura::OnWindowTitleChanged(aura::Window* window) {
999 for (auto& observer : observers_)
1000 observer.OnWindowTitleChanged(this);
1001 }
1002
1003 void WmWindowAura::OnTransientChildAdded(aura::Window* window,
1004 aura::Window* transient) {
1005 for (auto& observer : transient_observers_)
1006 observer.OnTransientChildAdded(this, Get(transient));
1007 }
1008
1009 void WmWindowAura::OnTransientChildRemoved(aura::Window* window,
1010 aura::Window* transient) {
1011 for (auto& observer : transient_observers_)
1012 observer.OnTransientChildRemoved(this, Get(transient));
1013 }
1014
1015 } // namespace ash
OLDNEW
« no previous file with comments | « ash/aura/wm_window_aura.h ('k') | ash/autoclick/autoclick_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698