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

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

Issue 2890733005: Refactor backdrop that is currently used in the maximized mode. (Closed)
Patch Set: fix memory issue in AshTouchExplorationManager Created 3 years, 7 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/wm/maximize_mode/workspace_backdrop_delegate.h"
6
7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
10 #include "ash/wm_window.h"
11 #include "base/auto_reset.h"
12 #include "ui/compositor/layer.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/views/background.h"
15 #include "ui/views/widget/widget.h"
16 #include "ui/wm/core/window_animations.h"
17 #include "ui/wm/core/window_util.h"
18
19 namespace ash {
20 namespace {
21
22 // The opacity of the backdrop.
23 const float kBackdropOpacity = 1.0f;
24
25 } // namespace
26
27 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container)
28 : container_(container), in_restacking_(false) {
29 background_ = new views::Widget;
30 views::Widget::InitParams params(
31 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
32 params.bounds = container_->GetBoundsInScreen();
33 params.layer_type = ui::LAYER_SOLID_COLOR;
34 params.name = "WorkspaceBackdropDelegate";
35 // To disallow the MRU list from picking this window up it should not be
36 // activateable.
37 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
38 DCHECK_NE(kShellWindowId_Invalid, container_->aura_window()->id());
39 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
40 background_, container_->aura_window()->id(), &params);
41 background_->Init(params);
42 background_window_ = WmWindow::Get(background_->GetNativeWindow());
43 // Do not use the animation system. We don't want the bounds animation and
44 // opacity needs to get set to |kBackdropOpacity|.
45 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE);
46 background_window_->GetLayer()->SetColor(SK_ColorBLACK);
47 // Make sure that the layer covers visibly everything - including the shelf.
48 background_window_->GetLayer()->SetBounds(params.bounds);
49 DCHECK(background_window_->GetBounds() == params.bounds);
50 Show();
51 RestackBackdrop();
52 }
53
54 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
55 // TODO: animations won't work right with mus: http://crbug.com/548396.
56 ::wm::ScopedHidingAnimationSettings hiding_settings(
57 background_->GetNativeView());
58 background_->Close();
59 background_window_->GetLayer()->SetOpacity(0.0f);
60 }
61
62 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) {
63 RestackBackdrop();
64 }
65
66 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) {
67 RestackBackdrop();
68 }
69
70 void WorkspaceBackdropDelegate::OnChildWindowVisibilityChanged(WmWindow* child,
71 bool visible) {
72 RestackBackdrop();
73 }
74
75 void WorkspaceBackdropDelegate::OnWindowStackingChanged(WmWindow* window) {
76 RestackBackdrop();
77 }
78
79 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange(
80 wm::WindowState* window_state,
81 wm::WindowStateType old_type) {
82 RestackBackdrop();
83 }
84
85 void WorkspaceBackdropDelegate::RestackBackdrop() {
86 // Avoid recursive calls.
87 if (in_restacking_)
88 return;
89
90 WmWindow* window = GetCurrentTopWindow();
91 if (!window) {
92 // Hide backdrop since no suitable window was found.
93 background_->Hide();
94 return;
95 }
96 if (window == background_window_ && background_->IsVisible())
97 return;
98 if (window->GetRootWindow() != background_window_->GetRootWindow())
99 return;
100 // We are changing the order of windows which will cause recursion.
101 base::AutoReset<bool> lock(&in_restacking_, true);
102 if (!background_->IsVisible())
103 Show();
104 // Since the backdrop needs to be immediately behind the window and the
105 // stacking functions only guarantee a "it's above or below", we need
106 // to re-arrange the two windows twice.
107 container_->StackChildAbove(background_window_, window);
108 container_->StackChildAbove(window, background_window_);
109 }
110
111 WmWindow* WorkspaceBackdropDelegate::GetCurrentTopWindow() {
112 const WmWindow::Windows windows = container_->GetChildren();
113 for (auto window_iter = windows.rbegin(); window_iter != windows.rend();
114 ++window_iter) {
115 WmWindow* window = *window_iter;
116 if (window->GetTargetVisibility() &&
117 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL &&
118 window->CanActivate())
119 return window;
120 }
121 return nullptr;
122 }
123
124 void WorkspaceBackdropDelegate::Show() {
125 background_window_->GetLayer()->SetOpacity(0.0f);
126 background_->Show();
127 background_->SetFullscreen(true);
128 ui::ScopedLayerAnimationSettings settings(
129 background_window_->GetLayer()->GetAnimator());
130 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
131 }
132
133 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/workspace_backdrop_delegate.h ('k') | ash/wm/workspace/backdrop_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698