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

Side by Side Diff: ash/common/wm/maximize_mode/workspace_backdrop_delegate.cc

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (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
OLDNEW
(Empty)
1 // Copyright 2014 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/maximize_mode/workspace_backdrop_delegate.h"
6
7 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
8 #include "ash/common/wm_window.h"
9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/root_window_controller.h"
11 #include "base/auto_reset.h"
12 #include "ui/aura/window_observer.h"
13 #include "ui/compositor/layer.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/views/background.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/wm/core/window_animations.h"
18 #include "ui/wm/core/window_util.h"
19
20 namespace ash {
21 namespace {
22
23 // The opacity of the backdrop.
24 const float kBackdropOpacity = 0.5f;
25
26 } // namespace
27
28 class WorkspaceBackdropDelegate::WindowObserverImpl
29 : public aura::WindowObserver {
30 public:
31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate)
32 : delegate_(delegate) {}
33 ~WindowObserverImpl() override {}
34
35 private:
36 // aura::WindowObserver overrides:
37 void OnWindowBoundsChanged(aura::Window* window,
38 const gfx::Rect& old_bounds,
39 const gfx::Rect& new_bounds) override {
40 // The container size has changed and the layer needs to be adapt to it.
41 delegate_->AdjustToContainerBounds();
42 }
43
44 WorkspaceBackdropDelegate* delegate_;
45
46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl);
47 };
48
49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container)
50 : container_observer_(new WindowObserverImpl(this)),
51 container_(container),
52 in_restacking_(false) {
53 background_ = new views::Widget;
54 views::Widget::InitParams params(
55 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
56 params.bounds = container_->GetBoundsInScreen();
57 params.layer_type = ui::LAYER_SOLID_COLOR;
58 params.name = "WorkspaceBackdropDelegate";
59 // To disallow the MRU list from picking this window up it should not be
60 // activateable.
61 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
62 DCHECK_NE(kShellWindowId_Invalid, container_->GetShellWindowId());
63 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
64 background_, container_->GetShellWindowId(), &params);
65 background_->Init(params);
66 background_window_ = WmWindow::Get(background_->GetNativeWindow());
67 // Do not use the animation system. We don't want the bounds animation and
68 // opacity needs to get set to |kBackdropOpacity|.
69 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE);
70 background_window_->GetLayer()->SetColor(SK_ColorBLACK);
71 // Make sure that the layer covers visibly everything - including the shelf.
72 background_window_->GetLayer()->SetBounds(params.bounds);
73 DCHECK(background_window_->GetBounds() == params.bounds);
74 Show();
75 RestackBackdrop();
76 container_->aura_window()->AddObserver(container_observer_.get());
77 }
78
79 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
80 container_->aura_window()->RemoveObserver(container_observer_.get());
81 // TODO: animations won't work right with mus: http://crbug.com/548396.
82 ::wm::ScopedHidingAnimationSettings hiding_settings(
83 background_->GetNativeView());
84 background_->Close();
85 background_window_->GetLayer()->SetOpacity(0.0f);
86 }
87
88 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) {
89 RestackBackdrop();
90 }
91
92 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) {
93 RestackBackdrop();
94 }
95
96 void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged(WmWindow* child,
97 bool visible) {
98 RestackBackdrop();
99 }
100
101 void WorkspaceBackdropDelegate::OnWindowStackingChanged(WmWindow* window) {
102 RestackBackdrop();
103 }
104
105 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange(
106 wm::WindowState* window_state,
107 wm::WindowStateType old_type) {
108 RestackBackdrop();
109 }
110
111 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() {
112 AdjustToContainerBounds();
113 }
114
115 void WorkspaceBackdropDelegate::RestackBackdrop() {
116 // Avoid recursive calls.
117 if (in_restacking_)
118 return;
119
120 WmWindow* window = GetCurrentTopWindow();
121 if (!window) {
122 // Hide backdrop since no suitable window was found.
123 background_->Hide();
124 return;
125 }
126 if (window == background_window_ && background_->IsVisible())
127 return;
128 if (window->GetRootWindow() != background_window_->GetRootWindow())
129 return;
130 // We are changing the order of windows which will cause recursion.
131 base::AutoReset<bool> lock(&in_restacking_, true);
132 if (!background_->IsVisible())
133 Show();
134 // Since the backdrop needs to be immediately behind the window and the
135 // stacking functions only guarantee a "it's above or below", we need
136 // to re-arrange the two windows twice.
137 container_->StackChildAbove(background_window_, window);
138 container_->StackChildAbove(window, background_window_);
139 }
140
141 WmWindow* WorkspaceBackdropDelegate::GetCurrentTopWindow() {
142 const WmWindow::Windows windows = container_->GetChildren();
143 for (auto window_iter = windows.rbegin(); window_iter != windows.rend();
144 ++window_iter) {
145 WmWindow* window = *window_iter;
146 if (window->GetTargetVisibility() &&
147 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL &&
148 window->CanActivate())
149 return window;
150 }
151 return nullptr;
152 }
153
154 void WorkspaceBackdropDelegate::AdjustToContainerBounds() {
155 // Cover the entire container window.
156 gfx::Rect target_rect(gfx::Point(0, 0), container_->GetBounds().size());
157 if (target_rect != background_window_->GetBounds()) {
158 // TODO: this won't work right with mus: http://crbug.com/548396.
159 // This needs to be instant.
160 ui::ScopedLayerAnimationSettings settings(
161 background_window_->GetLayer()->GetAnimator());
162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0));
163 background_window_->SetBounds(target_rect);
164 if (!background_->IsVisible())
165 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
166 }
167 }
168
169 void WorkspaceBackdropDelegate::Show() {
170 background_window_->GetLayer()->SetOpacity(0.0f);
171 background_->Show();
172 ui::ScopedLayerAnimationSettings settings(
173 background_window_->GetLayer()->GetAnimator());
174 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
175 }
176
177 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/maximize_mode/workspace_backdrop_delegate.h ('k') | ash/common/wm/mru_window_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698