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

Side by Side Diff: ash/common/wm_window.cc

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

Powered by Google App Engine
This is Rietveld 408576698