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

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

Issue 169643005: Adding a gray semi transparent backdrop behind the topmost window within the default container (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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/wm/maximize_mode/workspace_backdrop_delegate.h"
6
7 #include "ash/wm/window_animations.h"
8 #include "base/auto_reset.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/views/background.h"
13 #include "ui/views/corewm/window_util.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 namespace internal {
19
20 namespace {
21
22 // The opacity of the backdrop.
23 const float kBackdropOpacity = 0.5f;
24
25 } // namespace
26
27 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container)
28 : background_(NULL),
29 container_(container),
30 in_restacking_(false) {
31 background_ = new views::Widget;
32 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
sky 2014/03/07 15:00:10 Seems weird that you're using TYPE_CONTROL here. I
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Done.
33 params.parent = container_;
34 params.bounds = container_->bounds();
35 params.layer_type = aura::WINDOW_LAYER_SOLID_COLOR;
36 // To disallow the MRU list from picking this window up it should not be
37 // activateable.
38 params.can_activate = false;
39 background_->Init(params);
40 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate");
41 background_->GetNativeView()->layer()->SetColor(SK_ColorBLACK);
42 Show();
43 RestackBackdrop();
44 container_->AddObserver(this);
45 }
46
47 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
48 container_->RemoveObserver(this);
49 ui::ScopedLayerAnimationSettings settings(
50 background_->GetNativeView()->layer()->GetAnimator());
51 background_->Close();
52 settings.AddObserver(views::corewm::CreateHidingWindowAnimationObserver(
53 background_->GetNativeView()));
54 background_->GetNativeView()->layer()->SetOpacity(0.0f);
55 }
56
57 void WorkspaceBackdropDelegate::OnWindowBoundsChanged(aura::Window* window,
58 const gfx::Rect& old_bounds,
sky 2014/03/07 15:00:10 nit: spacing
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Done.
59 const gfx::Rect& new_bounds) OVERRIDE {
60 // The container size has changed and the layer needs to be adapt to it.
61 AdjustToContainerBounds();
62 }
63
64 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(aura::Window* child) {
65 RestackBackdrop();
66 }
67
68 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(aura::Window* child) {
69 RestackBackdrop();
70 }
71
72 void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged(
73 aura::Window* child,
74 bool visible) {
75 RestackBackdrop();
76 }
77
78 void WorkspaceBackdropDelegate::OnWindowStackingChanged(aura::Window* window) {
79 RestackBackdrop();
80 }
81
82 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange(
83 wm::WindowState* window_state,
84 wm::WindowStateType old_type) {
85 RestackBackdrop();
86 }
87
88 void WorkspaceBackdropDelegate::RestackBackdrop() {
89 // Avoid recursive calls.
90 if (in_restacking_)
91 return;
92
93 aura::Window* window = GetCurrentTopWindow();
94 if (!window) {
95 // Hide backdrop since no suitable window was found.
96 if (background_->IsVisible())
sky 2014/03/07 15:00:10 nit: you shouldn't need the IsVisible() check, jus
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Done.
97 background_->Hide();
98 return;
99 }
100 if (window == background_->GetNativeWindow() &&
101 background_->IsVisible()) {
102 return;
103 }
104 // We are changing the order of windows which will cause recursion.
105 base::AutoReset<bool> lock(&in_restacking_, true);
106 if (!background_->IsVisible())
107 Show();
108 // Since the backdrop needs to be immediately behind the window and the
109 // stacking functions only guarantee a "it's above or below", we need
110 // to re-arrange the two windows twice.
111 container_->StackChildAbove(background_->GetNativeView(), window);
112 container_->StackChildAbove(window, background_->GetNativeView());
113 }
114
115 aura::Window* WorkspaceBackdropDelegate::GetCurrentTopWindow() {
116 const aura::Window::Windows& windows = container_->children();
117 for (aura::Window::Windows::const_reverse_iterator window_iter =
118 windows.rbegin();
119 window_iter != windows.rend(); ++window_iter) {
120 aura::Window* window = *window_iter;
121 if (window->IsVisible() && window->type() == ui::wm::WINDOW_TYPE_NORMAL)
sky 2014/03/07 15:00:10 How come you stopped checking for active?
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Too many implementations of the same thing. Done.
122 return window;
123 }
124 return NULL;
125 }
126
127 void WorkspaceBackdropDelegate::AdjustToContainerBounds() {
128 // Cover the entire container window.
129 gfx::Rect target_rect(gfx::Point(0, 0), container_->bounds().size());
130 if (target_rect != background_->GetNativeWindow()->bounds()) {
131 // This needs to be instantly.
sky 2014/03/07 15:00:10 instant.
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Done.
132 ui::ScopedLayerAnimationSettings settings(
133 background_->GetNativeView()->layer()->GetAnimator());
134 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0));
135 background_->GetNativeWindow()->SetBounds(target_rect);
136 if (!background_->IsVisible())
137 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity);
138 }
139 }
140
141 void WorkspaceBackdropDelegate::Show() {
142 background_->GetNativeView()->layer()->SetOpacity(0.0f);
143 background_->Show();
144 ui::ScopedLayerAnimationSettings settings(
145 background_->GetNativeView()->layer()->GetAnimator());
146 background_->Show();
sky 2014/03/07 15:00:10 Since you have show on 143, is this necessary?
Mr4D (OOO till 08-26) 2014/03/07 15:55:35 Done.
147 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity);
148 }
149
150 } // namespace internal
151 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/workspace_backdrop_delegate.h ('k') | ash/wm/workspace/workspace_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698