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

Side by Side Diff: ash/wm/workspace/phantom_window_controller.cc

Issue 2825613002: Update ash phantom window aesthetics. (Closed)
Patch Set: solid color layer Created 3 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/phantom_window_controller.h" 5 #include "ash/wm/workspace/phantom_window_controller.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/resources/grit/ash_resources.h"
11 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
12 #include "ash/wm/root_window_finder.h" 11 #include "ash/wm/root_window_finder.h"
13 #include "ash/wm_window.h" 12 #include "ash/wm_window.h"
14 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
15 #include "ui/compositor/scoped_layer_animation_settings.h" 14 #include "ui/compositor/scoped_layer_animation_settings.h"
16 #include "ui/views/background.h" 15 #include "ui/views/background.h"
17 #include "ui/views/painter.h"
18 #include "ui/views/view.h" 16 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 #include "ui/wm/core/shadow_controller.h"
20 19
21 namespace ash { 20 namespace ash {
22 namespace { 21 namespace {
23 22
24 // The duration of the show animation. 23 // The duration of the show animation.
25 const int kAnimationDurationMs = 200; 24 const int kAnimationDurationMs = 200;
26 25
27 // The size of the phantom window at the beginning of the show animation in 26 // The size of the phantom window at the beginning of the show animation in
28 // relation to the size of the phantom window at the end of the animation. 27 // relation to the size of the phantom window at the end of the animation.
29 const float kStartBoundsRatio = 0.85f; 28 const float kStartBoundsRatio = 0.85f;
30 29
31 // The amount of pixels that the phantom window's shadow should extend past 30 // The elevation of the shadow for the phantom window should match that of an
32 // the bounds passed into Show(). 31 // active window.
33 const int kShadowThickness = 15; 32 constexpr ::wm::ShadowElevation kShadowElevation =
33 ::wm::ShadowController::kActiveNormalShadowElevation;
34 34
35 // The minimum size of a phantom window including the shadow. The minimum size 35 // The shadow ninebox requires a minimum size to work well. See
36 // is derived from the size of the IDR_AURA_PHANTOM_WINDOW image assets. 36 // ui/wm/core/shadow.cc
37 const int kMinSizeWithShadow = 100; 37 constexpr int kMinWidthWithShadow = 2 * static_cast<int>(kShadowElevation);
38 38 constexpr int kMinHeightWithShadow = 4 * static_cast<int>(kShadowElevation);
39 // Adjusts the phantom window's bounds so that the bounds:
40 // - Include the size of the shadow.
41 // - Have a size equal to or larger than the minimum phantom window size.
42 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) {
43 int x_inset = std::max(
44 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)),
45 kShadowThickness);
46 int y_inset = std::max(
47 static_cast<int>(ceil((kMinSizeWithShadow - bounds.height()) / 2.0f)),
48 kShadowThickness);
49
50 gfx::Rect adjusted_bounds(bounds);
51 adjusted_bounds.Inset(-x_inset, -y_inset);
52 return adjusted_bounds;
53 }
54
55 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget|
56 // is NULL.
57 void AnimateToBounds(views::Widget* widget,
58 const gfx::Rect& new_bounds_in_screen) {
59 if (!widget)
60 return;
61
62 ui::ScopedLayerAnimationSettings scoped_setter(
63 WmWindow::Get(widget->GetNativeWindow())->GetLayer()->GetAnimator());
64 scoped_setter.SetTweenType(gfx::Tween::EASE_IN);
65 scoped_setter.SetPreemptionStrategy(
66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
67 scoped_setter.SetTransitionDuration(
68 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
69 widget->SetBounds(new_bounds_in_screen);
70 }
71 39
72 } // namespace 40 } // namespace
73 41
74 // PhantomWindowController ---------------------------------------------------- 42 // PhantomWindowController ----------------------------------------------------
75 43
76 PhantomWindowController::PhantomWindowController(WmWindow* window) 44 PhantomWindowController::PhantomWindowController(WmWindow* window)
77 : window_(window) {} 45 : window_(window) {}
78 46
79 PhantomWindowController::~PhantomWindowController() {} 47 PhantomWindowController::~PhantomWindowController() {}
80 48
81 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { 49 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) {
82 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen); 50 if (bounds_in_screen == target_bounds_in_screen_)
83 if (adjusted_bounds_in_screen == target_bounds_in_screen_)
84 return; 51 return;
85 target_bounds_in_screen_ = adjusted_bounds_in_screen; 52 target_bounds_in_screen_ = bounds_in_screen;
86 53
87 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; 54 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_;
88 int start_width = std::max( 55 int start_width = std::max(
89 kMinSizeWithShadow, 56 kMinWidthWithShadow,
90 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); 57 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio));
91 int start_height = std::max( 58 int start_height = std::max(
92 kMinSizeWithShadow, 59 kMinHeightWithShadow,
93 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); 60 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio));
94 start_bounds_in_screen.Inset( 61 start_bounds_in_screen.Inset(
95 floor((start_bounds_in_screen.width() - start_width) / 2.0f), 62 floor((start_bounds_in_screen.width() - start_width) / 2.0f),
96 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); 63 floor((start_bounds_in_screen.height() - start_height) / 2.0f));
97 phantom_widget_ = 64 phantom_widget_ =
98 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), 65 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_),
99 start_bounds_in_screen); 66 start_bounds_in_screen);
100
101 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_);
102 } 67 }
103 68
104 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( 69 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget(
105 WmWindow* root_window, 70 WmWindow* root_window,
106 const gfx::Rect& bounds_in_screen) { 71 const gfx::Rect& bounds_in_screen) {
107 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); 72 std::unique_ptr<views::Widget> phantom_widget(new views::Widget);
108 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 73 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
109 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 74 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
110 // PhantomWindowController is used by FrameMaximizeButton to highlight the 75 // PhantomWindowController is used by FrameMaximizeButton to highlight the
111 // launcher button. Put the phantom in the same window as the launcher so that 76 // launcher button. Put the phantom in the same window as the launcher so that
112 // the phantom is visible. 77 // the phantom is visible.
113 params.keep_on_top = true; 78 params.keep_on_top = true;
114 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 79 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
115 params.name = "PhantomWindow"; 80 params.name = "PhantomWindow";
81 params.layer_type = ui::LAYER_SOLID_COLOR;
82 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_DROP;
83 params.shadow_elevation = ::wm::ShadowElevation::LARGE;
116 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( 84 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
117 phantom_widget.get(), kShellWindowId_ShelfContainer, &params); 85 phantom_widget.get(), kShellWindowId_ShelfContainer, &params);
118 phantom_widget->set_focus_on_creation(false); 86 phantom_widget->set_focus_on_creation(false);
119 phantom_widget->Init(params); 87 phantom_widget->Init(params);
120 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); 88 phantom_widget->SetVisibilityChangedAnimationsEnabled(false);
121 WmWindow* phantom_widget_window = 89 WmWindow* phantom_widget_window =
122 WmWindow::Get(phantom_widget->GetNativeWindow()); 90 WmWindow::Get(phantom_widget->GetNativeWindow());
123 phantom_widget_window->aura_window()->set_id(kShellWindowId_PhantomWindow); 91 phantom_widget_window->aura_window()->set_id(kShellWindowId_PhantomWindow);
124 phantom_widget->SetBounds(bounds_in_screen); 92 phantom_widget->SetBounds(bounds_in_screen);
125 // TODO(sky): I suspect this is never true, verify that. 93 // TODO(sky): I suspect this is never true, verify that.
126 if (phantom_widget_window->GetParent() == window_->GetParent()) { 94 if (phantom_widget_window->GetParent() == window_->GetParent()) {
127 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, 95 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window,
128 window_); 96 window_);
129 } 97 }
98 ui::Layer* widget_layer = phantom_widget_window->GetLayer();
99 widget_layer->SetColor(SkColorSetA(SK_ColorWHITE, 0.4 * 255));
130 100
131 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW);
132 views::View* content_view = new views::View;
133 content_view->set_background(views::Background::CreateBackgroundPainter(
134 views::Painter::CreateImageGridPainter(kImages)));
135 phantom_widget->SetContentsView(content_view);
136
137 // Show the widget after all the setups.
138 phantom_widget->Show(); 101 phantom_widget->Show();
139 102
140 // Fade the window in. 103 // Fade the window in.
141 ui::Layer* widget_layer = phantom_widget_window->GetLayer();
142 widget_layer->SetOpacity(0); 104 widget_layer->SetOpacity(0);
143 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); 105 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator());
144 scoped_setter.SetTransitionDuration( 106 scoped_setter.SetTransitionDuration(
145 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); 107 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
108 scoped_setter.SetTweenType(gfx::Tween::EASE_IN);
109 scoped_setter.SetPreemptionStrategy(
110 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
146 widget_layer->SetOpacity(1); 111 widget_layer->SetOpacity(1);
112 phantom_widget->SetBounds(target_bounds_in_screen_);
147 113
148 return phantom_widget; 114 return phantom_widget;
149 } 115 }
150 116
151 } // namespace ash 117 } // namespace ash
OLDNEW
« no previous file with comments | « ash/resources/default_200_percent/common/phantom_window_top_right.png ('k') | ui/wm/core/shadow_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698