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

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 "ui/aura/window.h"
9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h"
11 #include "ui/views/background.h"
12 #include "ui/views/corewm/window_util.h"
13 #include "ui/views/widget/widget.h"
14
15 namespace ash {
16
17 namespace internal {
18
19 namespace {
20
21 // The opacity of the backdrop.
22 const float kBackdropOpacity = 0.5f;
23
24 } // namespace
25
26 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container)
27 : background_(NULL),
28 container_(container),
29 inside_(false) {
30 background_ = new views::Widget;
sky 2014/03/06 21:34:13 Is there a reason why you don't use a layer direct
Mr4D (OOO till 08-26) 2014/03/07 01:00:12 Yes, swallowing events.
31 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
32 params.parent = container_;
33 params.bounds = container_->bounds();
34 // To disallow the MRU list from picking this window up it should not be
35 // activateable.
36 params.can_activate = false;
37 background_->Init(params);
38 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate");
39 views::View* contents_view = new views::View();
40 contents_view->set_background(
sky 2014/03/06 21:34:13 I'm skeptical you need a widget here, but if you d
Mr4D (OOO till 08-26) 2014/03/07 01:00:12 Done.
41 views::Background::CreateSolidBackground(SK_ColorBLACK));
42 contents_view->SetEnabled(true);
43 background_->SetContentsView(contents_view);
44 Show();
45 RestackBackdrop();
46 container_->AddObserver(this);
47 }
48
49 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
50 container_->RemoveObserver(this);
51 ui::ScopedLayerAnimationSettings settings(
52 background_->GetNativeView()->layer()->GetAnimator());
53 background_->Close();
54 settings.AddObserver(views::corewm::CreateHidingWindowAnimationObserver(
55 background_->GetNativeView()));
56 background_->GetNativeView()->layer()->SetOpacity(0.0f);
57 }
58
59 void WorkspaceBackdropDelegate::RestackBackdrop() {
60 // Avoid recursive calls.
61 if (inside_)
62 return;
63 // We are stuffing the backdrop behind the first visible & qualifying
64 // window in the given container.
65 const aura::Window::Windows& windows = container_->children();
66 for (aura::Window::Windows::const_reverse_iterator window_iter =
sky 2014/03/06 21:34:13 nit: I think this would be easier to follow if you
Mr4D (OOO till 08-26) 2014/03/07 01:00:12 Done.
67 windows.rbegin();
68 window_iter != windows.rend(); ++window_iter) {
69 aura::Window* window = *window_iter;
70 if (window->IsVisible() &&
71 window->type() == ui::wm::WINDOW_TYPE_NORMAL) {
sky 2014/03/06 21:34:13 If window has a transient parent in the same conta
Mr4D (OOO till 08-26) 2014/03/07 01:00:12 As long as the transient window can get Alt+Tabbed
72 // Check if the window has already the backdrop directly behind it.
73 if (++window_iter != windows.rend()) {
74 if (*window_iter == background_->GetNativeWindow() &&
75 background_->IsVisible()) {
76 return;
77 }
78 }
79 // We are changing the order of windows which will cause recursion.
80 inside_ = true;
sky 2014/03/06 21:34:13 Use autoreset. Please rename inside_ to better mat
Mr4D (OOO till 08-26) 2014/03/07 01:00:12 Done.
81 if (!background_->IsVisible())
82 Show();
83 // Since the backdrop needs to be immediately behind the window and the
84 // stacking functions only guarantee a "it's above or below", we need
85 // to re-arrange the two windows twice.
86 container_->StackChildAbove(background_->GetNativeView(), window);
87 container_->StackChildAbove(window, background_->GetNativeView());
88 inside_ = false;
89 return;
90 }
91 }
92 // Hide backdrop since no suitable window was found.
93 if (background_->IsVisible())
94 background_->Hide();
95 }
96
97 void WorkspaceBackdropDelegate::OnWindowBoundsChanged(aura::Window* window,
98 const gfx::Rect& old_bounds,
99 const gfx::Rect& new_bounds) OVERRIDE {
100 // The container size has changed and the layer needs to be adapt to it.
101 AdjustToContainerBounds();
102 }
103
104 void WorkspaceBackdropDelegate::AdjustToContainerBounds() {
105 // Cover the entire container window.
106 gfx::Rect target_rect(gfx::Point(0, 0), container_->bounds().size());
107 if (target_rect != background_->GetNativeWindow()->bounds()) {
108 // This needs to be instantly.
109 ui::ScopedLayerAnimationSettings settings(
110 background_->GetNativeView()->layer()->GetAnimator());
111 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0));
112 background_->GetNativeWindow()->SetBounds(target_rect);
113 if (!background_->IsVisible())
114 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity);
115 }
116 }
117
118 void WorkspaceBackdropDelegate::Show() {
119 background_->GetNativeView()->layer()->SetOpacity(0.0f);
120 background_->Show();
121 ui::ScopedLayerAnimationSettings settings(
122 background_->GetNativeView()->layer()->GetAnimator());
123 background_->Show();
124 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity);
125 }
126
127 } // namespace internal
128 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698