OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/wm/overview/window_selector_item.h" | 5 #include "ash/common/wm/overview/window_selector_item.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
11 #include "ash/common/metrics/user_metrics_action.h" | 11 #include "ash/common/metrics/user_metrics_action.h" |
12 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
13 #include "ash/common/wm/overview/cleanup_animation_observer.h" | |
13 #include "ash/common/wm/overview/overview_animation_type.h" | 14 #include "ash/common/wm/overview/overview_animation_type.h" |
14 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" | 15 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" |
15 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" | 16 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" |
16 #include "ash/common/wm/overview/scoped_transform_overview_window.h" | 17 #include "ash/common/wm/overview/scoped_transform_overview_window.h" |
17 #include "ash/common/wm/overview/window_selector.h" | 18 #include "ash/common/wm/overview/window_selector.h" |
18 #include "ash/common/wm/overview/window_selector_controller.h" | 19 #include "ash/common/wm/overview/window_selector_controller.h" |
19 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
20 #include "ash/common/wm_lookup.h" | 21 #include "ash/common/wm_lookup.h" |
21 #include "ash/common/wm_root_window_controller.h" | 22 #include "ash/common/wm_root_window_controller.h" |
22 #include "ash/common/wm_shell.h" | 23 #include "ash/common/wm_shell.h" |
23 #include "ash/common/wm_window.h" | 24 #include "ash/common/wm_window.h" |
24 #include "ash/common/wm_window_property.h" | 25 #include "ash/common/wm_window_property.h" |
25 #include "base/auto_reset.h" | 26 #include "base/auto_reset.h" |
26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
29 #include "grit/ash_resources.h" | 30 #include "grit/ash_resources.h" |
30 #include "grit/ash_strings.h" | 31 #include "grit/ash_strings.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/compositor/layer_animation_sequence.h" | |
35 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
33 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
37 #include "ui/gfx/color_utils.h" | |
34 #include "ui/gfx/geometry/safe_integer_conversions.h" | 38 #include "ui/gfx/geometry/safe_integer_conversions.h" |
35 #include "ui/gfx/geometry/vector2d.h" | 39 #include "ui/gfx/geometry/vector2d.h" |
36 #include "ui/gfx/paint_vector_icon.h" | 40 #include "ui/gfx/paint_vector_icon.h" |
37 #include "ui/gfx/transform_util.h" | 41 #include "ui/gfx/transform_util.h" |
38 #include "ui/gfx/vector_icons_public.h" | 42 #include "ui/gfx/vector_icons_public.h" |
39 #include "ui/strings/grit/ui_strings.h" | 43 #include "ui/strings/grit/ui_strings.h" |
40 #include "ui/views/background.h" | 44 #include "ui/views/background.h" |
41 #include "ui/views/border.h" | 45 #include "ui/views/border.h" |
42 #include "ui/views/controls/button/image_button.h" | |
43 #include "ui/views/layout/box_layout.h" | 46 #include "ui/views/layout/box_layout.h" |
44 #include "ui/views/window/non_client_view.h" | 47 #include "ui/views/window/non_client_view.h" |
45 #include "ui/wm/core/shadow.h" | 48 #include "ui/wm/core/shadow.h" |
46 #include "ui/wm/core/window_util.h" | 49 #include "ui/wm/core/window_util.h" |
47 | 50 |
48 namespace ash { | 51 namespace ash { |
49 | 52 |
50 namespace { | 53 namespace { |
51 | 54 |
52 // In the conceptual overview table, the window margin is the space reserved | 55 // In the conceptual overview table, the window margin is the space reserved |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 | 93 |
91 // Height of an item header in Material Design. | 94 // Height of an item header in Material Design. |
92 static const int kHeaderHeight = 32; | 95 static const int kHeaderHeight = 32; |
93 | 96 |
94 // Opacity for dimmed items. | 97 // Opacity for dimmed items. |
95 static const float kDimmedItemOpacity = 0.5f; | 98 static const float kDimmedItemOpacity = 0.5f; |
96 | 99 |
97 // Opacity for fading out during closing a window. | 100 // Opacity for fading out during closing a window. |
98 static const float kClosingItemOpacity = 0.8f; | 101 static const float kClosingItemOpacity = 0.8f; |
99 | 102 |
103 // Opacity for the item header. | |
104 static const float kHeaderOpacity = | |
105 (SkColorGetA(kLabelBackgroundColor) / 255.f); | |
106 | |
107 // Duration it takes for the header to shift from opaque header color to | |
108 // |kLabelBackgroundColor|. | |
109 static const int kSelectorColorSlideMilliseconds = 240; | |
110 | |
100 // Duration of background opacity transition for the selected label. | 111 // Duration of background opacity transition for the selected label. |
101 static const int kSelectorFadeInMilliseconds = 350; | 112 static const int kSelectorFadeInMilliseconds = 350; |
102 | 113 |
103 // Before closing a window animate both the window and the caption to shrink by | 114 // Before closing a window animate both the window and the caption to shrink by |
104 // this fraction of size. | 115 // this fraction of size. |
105 static const float kPreCloseScale = 0.02f; | 116 static const float kPreCloseScale = 0.02f; |
106 | 117 |
107 // Convenience method to fade in a Window with predefined animation settings. | 118 // Convenience method to fade in a Window with predefined animation settings. |
108 // Note: The fade in animation will occur after a delay where the delay is how | 119 // Note: The fade in animation will occur after a delay where the delay is how |
109 // long the lay out animations take. | 120 // long the lay out animations take. |
110 void SetupFadeInAfterLayout(views::Widget* widget) { | 121 void SetupFadeInAfterLayout(views::Widget* widget) { |
111 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 122 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
112 window->SetOpacity(0.0f); | 123 window->SetOpacity(0.0f); |
113 std::unique_ptr<ScopedOverviewAnimationSettings> | 124 std::unique_ptr<ScopedOverviewAnimationSettings> |
114 scoped_overview_animation_settings = | 125 scoped_overview_animation_settings = |
115 ScopedOverviewAnimationSettingsFactory::Get() | 126 ScopedOverviewAnimationSettingsFactory::Get() |
116 ->CreateOverviewAnimationSettings( | 127 ->CreateOverviewAnimationSettings( |
117 OverviewAnimationType:: | 128 OverviewAnimationType:: |
118 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | 129 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
119 window); | 130 window); |
120 window->SetOpacity(1.0f); | 131 window->SetOpacity(1.0f); |
121 } | 132 } |
122 | 133 |
123 // An image button with a close window icon. | 134 } // namespace |
124 class OverviewCloseButton : public views::ImageButton { | |
125 public: | |
126 explicit OverviewCloseButton(views::ButtonListener* listener); | |
127 ~OverviewCloseButton() override; | |
128 | 135 |
129 private: | 136 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton( |
130 gfx::ImageSkia icon_image_; | 137 views::ButtonListener* listener) |
131 | |
132 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton); | |
133 }; | |
134 | |
135 OverviewCloseButton::OverviewCloseButton(views::ButtonListener* listener) | |
136 : views::ImageButton(listener) { | 138 : views::ImageButton(listener) { |
137 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 139 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
138 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, | 140 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, |
139 kCloseButtonColor); | 141 kCloseButtonColor); |
140 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); | 142 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); |
141 SetImage(views::CustomButton::STATE_HOVERED, &icon_image_); | 143 SetImage(views::CustomButton::STATE_HOVERED, &icon_image_); |
142 SetImage(views::CustomButton::STATE_PRESSED, &icon_image_); | 144 SetImage(views::CustomButton::STATE_PRESSED, &icon_image_); |
143 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 145 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
144 views::ImageButton::ALIGN_MIDDLE); | 146 views::ImageButton::ALIGN_MIDDLE); |
145 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); | 147 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); |
146 } else { | 148 } else { |
147 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
148 SetImage(views::CustomButton::STATE_NORMAL, | 150 SetImage(views::CustomButton::STATE_NORMAL, |
149 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); | 151 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); |
150 SetImage(views::CustomButton::STATE_HOVERED, | 152 SetImage(views::CustomButton::STATE_HOVERED, |
151 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); | 153 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); |
152 SetImage(views::CustomButton::STATE_PRESSED, | 154 SetImage(views::CustomButton::STATE_PRESSED, |
153 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); | 155 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); |
154 } | 156 } |
155 } | 157 } |
156 | 158 |
157 OverviewCloseButton::~OverviewCloseButton() {} | 159 WindowSelectorItem::OverviewCloseButton::~OverviewCloseButton() {} |
158 | 160 |
159 // A View having rounded corners and a specified background color which is | 161 // A View having rounded corners and a specified background color which is |
160 // only painted within the bounds defined by the rounded corners. | 162 // only painted within the bounds defined by the rounded corners. |
161 // TODO(varkha): This duplicates code from RoundedImageView. Refactor these | 163 // TODO(varkha): This duplicates code from RoundedImageView. Refactor these |
162 // classes and move into ui/views. | 164 // classes and move into ui/views. |
163 class RoundedContainerView : public views::View { | 165 class WindowSelectorItem::RoundedContainerView |
166 : public views::View, | |
167 public gfx::AnimationDelegate, | |
168 public ui::LayerAnimationObserver { | |
164 public: | 169 public: |
165 RoundedContainerView(int corner_radius, SkColor background) | 170 RoundedContainerView(WindowSelectorItem* item, |
166 : corner_radius_(corner_radius), background_(background) {} | 171 WmWindow* item_window, |
172 int corner_radius, | |
173 SkColor background) | |
174 : item_(item), | |
175 item_window_(item_window), | |
176 corner_radius_(corner_radius), | |
177 previous_color_(background), | |
178 color_(background), | |
179 last_alpha_(0), | |
180 current_value_(0), | |
181 layer_(nullptr), | |
182 animation_(new gfx::SlideAnimation(this)) {} | |
167 | 183 |
168 ~RoundedContainerView() override {} | 184 ~RoundedContainerView() override {} |
169 | 185 |
186 void OnItemRestored() { item_ = nullptr; } | |
187 | |
188 void ObserveLayer(ui::Layer* layer) { | |
189 layer_ = layer; | |
190 layer_->GetAnimator()->AddObserver(this); | |
bruthig
2016/09/08 18:32:49
nit: As a reader I wonder about the lifetime of |t
varkha
2016/09/09 02:25:25
Done.
| |
191 } | |
192 | |
193 void set_color(SkColor color) { color_ = color; } | |
194 | |
195 void AnimateColor(gfx::Tween::Type tween_type) { | |
196 animation_->SetSlideDuration(kSelectorColorSlideMilliseconds); | |
197 animation_->SetTweenType(tween_type); | |
198 animation_->Reset(0); | |
199 animation_->Show(); | |
200 | |
201 // Tests complete animations immediately. Emulate by invoking the callback. | |
bruthig
2016/09/08 18:32:49
Won't the layer animations still notify AnimationE
varkha
2016/09/09 02:25:25
This is not an implicit property animation and so
bruthig
2016/09/09 13:58:27
Ah, I think I get it. So |animation_| is a SlideA
| |
202 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == | |
203 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) { | |
204 AnimationEnded(animation_.get()); | |
205 } | |
206 } | |
207 | |
208 void AnimateBackgroundOpacity(float opacity) { | |
209 animation_->SetSlideDuration(kSelectorFadeInMilliseconds); | |
210 animation_->SetTweenType(gfx::Tween::EASE_OUT); | |
211 animation_->Reset(0); | |
212 animation_->Show(); | |
213 color_ = SkColorSetA(color_, opacity * 255); | |
214 } | |
215 | |
170 void OnPaint(gfx::Canvas* canvas) override { | 216 void OnPaint(gfx::Canvas* canvas) override { |
171 views::View::OnPaint(canvas); | 217 views::View::OnPaint(canvas); |
172 | |
173 SkScalar radius = SkIntToScalar(corner_radius_); | 218 SkScalar radius = SkIntToScalar(corner_radius_); |
174 const SkScalar kRadius[8] = {radius, radius, radius, radius, | 219 const SkScalar kRadius[8] = {radius, radius, radius, radius, 0, 0, 0, 0}; |
175 radius, radius, radius, radius}; | |
176 SkPath path; | 220 SkPath path; |
177 gfx::Rect bounds(size()); | 221 gfx::Rect bounds(size()); |
178 bounds.set_height(bounds.height() + radius); | |
179 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); | 222 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); |
180 | 223 |
181 SkPaint paint; | 224 SkPaint paint; |
182 paint.setAntiAlias(true); | 225 paint.setAntiAlias(true); |
183 canvas->ClipPath(path, true); | 226 canvas->ClipPath(path, true); |
184 canvas->DrawColor(background_); | 227 |
228 SkColor color = previous_color_; | |
229 if (color_ != color) | |
230 color = color_utils::AlphaBlend(color_, previous_color_, current_value_); | |
231 canvas->DrawColor(color); | |
232 last_alpha_ = SkColorGetA(color); | |
185 } | 233 } |
186 | 234 |
187 private: | 235 private: |
236 // gfx::AnimationDelegate: | |
237 void AnimationEnded(const gfx::Animation* animation) override { | |
238 previous_color_ = color_; | |
239 WmWindow* label_window = WmLookup::Get()->GetWindowForWidget(GetWidget()); | |
240 if (label_window && item_window_) | |
241 label_window->GetParent()->StackChildAbove(label_window, item_window_); | |
242 item_window_ = nullptr; | |
243 } | |
244 | |
245 void AnimationProgressed(const gfx::Animation* animation) override { | |
246 current_value_ = animation_->CurrentValueBetween(0, 255); | |
247 SchedulePaintInRect(GetLocalBounds()); | |
248 } | |
249 | |
250 void AnimationCanceled(const gfx::Animation* animation) override { | |
251 item_window_ = nullptr; | |
252 previous_color_ = color_; | |
253 current_value_ = 255; | |
254 SchedulePaintInRect(GetLocalBounds()); | |
255 } | |
256 | |
257 // ui::LayerAnimationObserver: | |
258 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override { | |
259 if (0 != (sequence->properties() & | |
260 ui::LayerAnimationElement::AnimatableProperty::OPACITY)) { | |
261 if (item_) | |
262 item_->HideHeaderAndSetShape(0); | |
263 if (layer_) { | |
264 layer_->GetAnimator()->RemoveObserver(this); | |
265 layer_ = nullptr; | |
266 } | |
267 AnimateColor(gfx::Tween::EASE_IN); | |
268 } | |
269 } | |
270 | |
271 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override { | |
272 if (0 != (sequence->properties() & | |
273 ui::LayerAnimationElement::AnimatableProperty::OPACITY)) { | |
274 if (layer_) { | |
275 layer_->GetAnimator()->RemoveObserver(this); | |
276 layer_ = nullptr; | |
277 } | |
278 } | |
279 } | |
280 | |
281 void OnLayerAnimationScheduled( | |
282 ui::LayerAnimationSequence* sequence) override {} | |
283 | |
284 WindowSelectorItem* item_; | |
285 WmWindow* item_window_; | |
188 int corner_radius_; | 286 int corner_radius_; |
189 SkColor background_; | 287 SkColor previous_color_; |
288 SkColor color_; | |
289 int last_alpha_; | |
290 int current_value_; | |
291 ui::Layer* layer_; | |
292 std::unique_ptr<gfx::SlideAnimation> animation_; | |
190 | 293 |
191 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | 294 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
192 }; | 295 }; |
193 | 296 |
194 } // namespace | |
195 | |
196 bool WindowSelectorItem::use_mask_ = false; | 297 bool WindowSelectorItem::use_mask_ = false; |
197 bool WindowSelectorItem::use_shape_ = false; | 298 bool WindowSelectorItem::use_shape_ = false; |
198 | 299 |
199 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( | 300 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( |
200 views::ButtonListener* listener, | 301 views::ButtonListener* listener, |
201 const base::string16& text) | 302 const base::string16& text) |
202 : LabelButton(listener, text) {} | 303 : LabelButton(listener, text) {} |
203 | 304 |
204 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} | 305 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} |
205 | 306 |
(...skipping 10 matching lines...) Expand all Loading... | |
216 bounds.Inset(padding_); | 317 bounds.Inset(padding_); |
217 if (ash::MaterialDesignController::IsOverviewMaterial()) | 318 if (ash::MaterialDesignController::IsOverviewMaterial()) |
218 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); | 319 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); |
219 return bounds; | 320 return bounds; |
220 } | 321 } |
221 | 322 |
222 // Container View that has an item label and a close button as children. | 323 // Container View that has an item label and a close button as children. |
223 class WindowSelectorItem::CaptionContainerView : public views::View { | 324 class WindowSelectorItem::CaptionContainerView : public views::View { |
224 public: | 325 public: |
225 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, | 326 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, |
226 views::ImageButton* close_button) | 327 views::ImageButton* close_button, |
227 : label_(label), close_button_(close_button) { | 328 WindowSelectorItem::RoundedContainerView* background) |
329 : label_(label), close_button_(close_button), background_(background) { | |
330 AddChildView(background_); | |
228 AddChildView(label_); | 331 AddChildView(label_); |
229 AddChildView(close_button_); | 332 AddChildView(close_button_); |
230 } | 333 } |
231 | 334 |
232 protected: | 335 protected: |
233 // views::View: | 336 // views::View: |
234 void Layout() override { | 337 void Layout() override { |
235 // Position close button in the top right corner sized to its icon size and | 338 // Position close button in the top right corner sized to its icon size and |
236 // the label in the top left corner as tall as the button and extending to | 339 // the label in the top left corner as tall as the button and extending to |
237 // the button's left edge. | 340 // the button's left edge. |
238 // The rest of this container view serves as a shield to prevent input | 341 // The rest of this container view serves as a shield to prevent input |
239 // events from reaching the transformed window in overview. | 342 // events from reaching the transformed window in overview. |
240 gfx::Rect bounds(GetLocalBounds()); | 343 gfx::Rect bounds(GetLocalBounds()); |
241 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); | 344 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); |
345 gfx::Rect background_bounds(bounds); | |
346 background_bounds.set_height(close_button_->GetPreferredSize().height()); | |
347 background_->SetBoundsRect(background_bounds); | |
348 | |
242 const int visible_height = close_button_->GetPreferredSize().height(); | 349 const int visible_height = close_button_->GetPreferredSize().height(); |
243 gfx::Insets label_padding(0, 0, bounds.height() - visible_height, | 350 gfx::Insets label_padding(0, 0, bounds.height() - visible_height, |
244 visible_height); | 351 visible_height); |
245 label_->set_padding(label_padding); | 352 label_->set_padding(label_padding); |
246 label_->SetBoundsRect(bounds); | 353 label_->SetBoundsRect(bounds); |
247 bounds.set_x(bounds.right() - visible_height); | 354 bounds.set_x(bounds.right() - visible_height); |
248 bounds.set_width(visible_height); | 355 bounds.set_width(visible_height); |
249 bounds.set_height(visible_height); | 356 bounds.set_height(visible_height); |
250 close_button_->SetBoundsRect(bounds); | 357 close_button_->SetBoundsRect(bounds); |
251 } | 358 } |
252 | 359 |
253 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { Layout(); } | |
254 | |
255 private: | 360 private: |
256 WindowSelectorItem::OverviewLabelButton* label_; | 361 WindowSelectorItem::OverviewLabelButton* label_; |
257 views::ImageButton* close_button_; | 362 views::ImageButton* close_button_; |
363 WindowSelectorItem::RoundedContainerView* background_; | |
258 | 364 |
259 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); | 365 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); |
260 }; | 366 }; |
261 | 367 |
262 WindowSelectorItem::WindowSelectorItem(WmWindow* window, | 368 WindowSelectorItem::WindowSelectorItem(WmWindow* window, |
263 WindowSelector* window_selector) | 369 WindowSelector* window_selector) |
264 : dimmed_(false), | 370 : dimmed_(false), |
265 root_window_(window->GetRootWindow()), | 371 root_window_(window->GetRootWindow()), |
266 transform_window_(window), | 372 transform_window_(window), |
267 in_bounds_update_(false), | 373 in_bounds_update_(false), |
374 selected_(false), | |
268 caption_container_view_(nullptr), | 375 caption_container_view_(nullptr), |
269 window_label_button_view_(nullptr), | 376 window_label_button_view_(nullptr), |
270 close_button_(new OverviewCloseButton(this)), | 377 close_button_(new OverviewCloseButton(this)), |
271 window_selector_(window_selector) { | 378 window_selector_(window_selector), |
379 background_view_(nullptr) { | |
272 CreateWindowLabel(window->GetTitle()); | 380 CreateWindowLabel(window->GetTitle()); |
273 if (!ash::MaterialDesignController::IsOverviewMaterial()) { | 381 if (!ash::MaterialDesignController::IsOverviewMaterial()) { |
274 views::Widget::InitParams params; | 382 views::Widget::InitParams params; |
275 params.type = views::Widget::InitParams::TYPE_POPUP; | 383 params.type = views::Widget::InitParams::TYPE_POPUP; |
276 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 384 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
277 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 385 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
278 params.name = "OverviewModeCloseButton"; | 386 params.name = "OverviewModeCloseButton"; |
279 close_button_widget_.reset(new views::Widget); | 387 close_button_widget_.reset(new views::Widget); |
280 close_button_widget_->set_focus_on_creation(false); | 388 close_button_widget_->set_focus_on_creation(false); |
281 window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 389 window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
(...skipping 11 matching lines...) Expand all Loading... | |
293 close_button_rect.set_x(-close_button_rect.width() / 2); | 401 close_button_rect.set_x(-close_button_rect.width() / 2); |
294 close_button_rect.set_y(-close_button_rect.height() / 2); | 402 close_button_rect.set_y(-close_button_rect.height() / 2); |
295 WmLookup::Get() | 403 WmLookup::Get() |
296 ->GetWindowForWidget(close_button_widget_.get()) | 404 ->GetWindowForWidget(close_button_widget_.get()) |
297 ->SetBounds(close_button_rect); | 405 ->SetBounds(close_button_rect); |
298 } | 406 } |
299 GetWindow()->AddObserver(this); | 407 GetWindow()->AddObserver(this); |
300 } | 408 } |
301 | 409 |
302 WindowSelectorItem::~WindowSelectorItem() { | 410 WindowSelectorItem::~WindowSelectorItem() { |
411 if (background_view_) | |
412 background_view_->OnItemRestored(); | |
303 GetWindow()->RemoveObserver(this); | 413 GetWindow()->RemoveObserver(this); |
304 } | 414 } |
305 | 415 |
306 WmWindow* WindowSelectorItem::GetWindow() { | 416 WmWindow* WindowSelectorItem::GetWindow() { |
307 return transform_window_.window(); | 417 return transform_window_.window(); |
308 } | 418 } |
309 | 419 |
310 void WindowSelectorItem::RestoreWindow() { | 420 void WindowSelectorItem::RestoreWindow() { |
421 window_label_button_view_->Disconnect(); | |
422 close_button_->Disconnect(); | |
311 transform_window_.RestoreWindow(); | 423 transform_window_.RestoreWindow(); |
424 if (background_view_) | |
425 background_view_->OnItemRestored(); | |
426 UpdateHeaderLayout( | |
427 HeaderFadeInMode::Exit, | |
428 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS); | |
429 FadeOut(std::move(window_label_)); | |
312 } | 430 } |
313 | 431 |
314 void WindowSelectorItem::ShowWindowOnExit() { | 432 void WindowSelectorItem::ShowWindowOnExit() { |
315 transform_window_.ShowWindowOnExit(); | 433 transform_window_.ShowWindowOnExit(); |
316 } | 434 } |
317 | 435 |
318 void WindowSelectorItem::PrepareForOverview() { | 436 void WindowSelectorItem::PrepareForOverview() { |
319 transform_window_.PrepareForOverview(); | 437 transform_window_.PrepareForOverview(); |
320 } | 438 } |
321 | 439 |
(...skipping 10 matching lines...) Expand all Loading... | |
332 | 450 |
333 gfx::Rect inset_bounds(target_bounds); | 451 gfx::Rect inset_bounds(target_bounds); |
334 if (ash::MaterialDesignController::IsOverviewMaterial()) | 452 if (ash::MaterialDesignController::IsOverviewMaterial()) |
335 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | 453 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); |
336 else | 454 else |
337 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 455 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
338 SetItemBounds(inset_bounds, animation_type); | 456 SetItemBounds(inset_bounds, animation_type); |
339 | 457 |
340 // SetItemBounds is called before UpdateHeaderLayout so the header can | 458 // SetItemBounds is called before UpdateHeaderLayout so the header can |
341 // properly use the updated windows bounds. | 459 // properly use the updated windows bounds. |
342 UpdateHeaderLayout(animation_type); | 460 UpdateHeaderLayout(HeaderFadeInMode::Update, animation_type); |
343 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 461 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
344 UpdateWindowLabel(target_bounds, animation_type); | 462 UpdateWindowLabel(target_bounds, animation_type); |
345 } | 463 } |
346 | 464 |
347 void WindowSelectorItem::SetSelected(bool selected) { | 465 void WindowSelectorItem::SetSelected(bool selected) { |
348 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 466 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
349 return; | 467 return; |
350 WmWindow* window = | 468 selected_ = selected; |
351 WmLookup::Get()->GetWindowForWidget(window_label_selector_.get()); | 469 background_view_->AnimateBackgroundOpacity(selected ? 0.0f : kHeaderOpacity); |
352 ui::ScopedLayerAnimationSettings animation_settings( | |
353 window->GetLayer()->GetAnimator()); | |
354 animation_settings.SetTransitionDuration( | |
355 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); | |
356 animation_settings.SetTweenType(selected ? gfx::Tween::FAST_OUT_LINEAR_IN | |
357 : gfx::Tween::LINEAR_OUT_SLOW_IN); | |
358 animation_settings.SetPreemptionStrategy( | |
359 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
360 window->SetOpacity(selected ? 0.0f : 1.0f); | |
361 | 470 |
362 ui::ScopedLayerAnimationSettings animation_settings_shadow( | 471 if (shadow_) { |
363 shadow_->shadow_layer()->GetAnimator()); | 472 ui::ScopedLayerAnimationSettings animation_settings_shadow( |
364 animation_settings_shadow.SetTransitionDuration( | 473 shadow_->shadow_layer()->GetAnimator()); |
365 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); | 474 animation_settings_shadow.SetTransitionDuration( |
366 animation_settings_shadow.SetTweenType(selected | 475 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); |
367 ? gfx::Tween::FAST_OUT_LINEAR_IN | 476 animation_settings_shadow.SetTweenType( |
368 : gfx::Tween::LINEAR_OUT_SLOW_IN); | 477 selected ? gfx::Tween::FAST_OUT_LINEAR_IN |
369 animation_settings_shadow.SetPreemptionStrategy( | 478 : gfx::Tween::LINEAR_OUT_SLOW_IN); |
370 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 479 animation_settings_shadow.SetPreemptionStrategy( |
371 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); | 480 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
481 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); | |
482 } | |
372 } | 483 } |
373 | 484 |
374 void WindowSelectorItem::RecomputeWindowTransforms() { | 485 void WindowSelectorItem::RecomputeWindowTransforms() { |
375 if (in_bounds_update_ || target_bounds_.IsEmpty()) | 486 if (in_bounds_update_ || target_bounds_.IsEmpty()) |
376 return; | 487 return; |
377 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 488 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
378 gfx::Rect inset_bounds(target_bounds_); | 489 gfx::Rect inset_bounds(target_bounds_); |
379 if (ash::MaterialDesignController::IsOverviewMaterial()) | 490 if (ash::MaterialDesignController::IsOverviewMaterial()) |
380 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | 491 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); |
381 else | 492 else |
382 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 493 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
383 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | 494 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
384 UpdateHeaderLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | 495 UpdateHeaderLayout(HeaderFadeInMode::Update, |
496 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | |
385 } | 497 } |
386 | 498 |
387 void WindowSelectorItem::SendAccessibleSelectionEvent() { | 499 void WindowSelectorItem::SendAccessibleSelectionEvent() { |
388 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, | 500 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, |
389 true); | 501 true); |
390 } | 502 } |
391 | 503 |
392 void WindowSelectorItem::CloseWindow() { | 504 void WindowSelectorItem::CloseWindow() { |
393 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 505 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
394 gfx::Rect inset_bounds(target_bounds_); | 506 gfx::Rect inset_bounds(target_bounds_); |
395 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, | 507 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, |
396 target_bounds_.height() * kPreCloseScale); | 508 target_bounds_.height() * kPreCloseScale); |
397 OverviewAnimationType animation_type = | 509 OverviewAnimationType animation_type = |
398 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; | 510 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; |
399 // Scale down both the window and label. | 511 // Scale down both the window and label. |
400 SetBounds(inset_bounds, animation_type); | 512 SetBounds(inset_bounds, animation_type); |
401 // First animate opacity to an intermediate value concurrently with the | 513 // First animate opacity to an intermediate value concurrently with the |
402 // scaling animation. | 514 // scaling animation. |
403 AnimateOpacity(kClosingItemOpacity, animation_type); | 515 AnimateOpacity(kClosingItemOpacity, animation_type); |
404 | 516 |
405 // Fade out the window and the label, effectively hiding them. | 517 // Fade out the window and the label, effectively hiding them. |
406 AnimateOpacity( | 518 AnimateOpacity( |
407 0.0, OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); | 519 0.0, OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); |
408 } | 520 } |
409 transform_window_.Close(); | 521 transform_window_.Close(); |
410 } | 522 } |
411 | 523 |
524 void WindowSelectorItem::HideHeaderAndSetShape(int radius) { | |
525 transform_window_.HideHeaderAndSetShape(use_mask_, use_shape_, radius); | |
526 } | |
527 | |
412 void WindowSelectorItem::SetDimmed(bool dimmed) { | 528 void WindowSelectorItem::SetDimmed(bool dimmed) { |
413 dimmed_ = dimmed; | 529 dimmed_ = dimmed; |
414 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); | 530 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); |
415 } | 531 } |
416 | 532 |
417 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 533 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
418 const ui::Event& event) { | 534 const ui::Event& event) { |
419 if (sender == close_button_) { | 535 if (sender == close_button_) { |
420 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); | 536 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); |
421 CloseWindow(); | 537 CloseWindow(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 top_view_inset = transform_window_.GetTopInset(); | 582 top_view_inset = transform_window_.GetTopInset(); |
467 title_height = close_button_->GetPreferredSize().height(); | 583 title_height = close_button_->GetPreferredSize().height(); |
468 } | 584 } |
469 gfx::Rect selector_item_bounds = | 585 gfx::Rect selector_item_bounds = |
470 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 586 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
471 screen_rect, target_bounds, top_view_inset, title_height); | 587 screen_rect, target_bounds, top_view_inset, title_height); |
472 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 588 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
473 screen_rect, selector_item_bounds); | 589 screen_rect, selector_item_bounds); |
474 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 590 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
475 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 591 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
476 // Rounded corners are achieved by using a mask layer on the original window | 592 transform_window_.SetTransform(root_window_, transform, use_mask_); |
477 // before the transform. Dividing by scale factor obtains the corner radius | |
478 // which when scaled will yield |kLabelBackgroundRadius|. | |
479 transform_window_.SetTransform( | |
480 root_window_, transform, use_mask_, use_shape_, | |
481 (kLabelBackgroundRadius / GetItemScale(target_bounds.size()))); | |
482 transform_window_.set_overview_transform(transform); | 593 transform_window_.set_overview_transform(transform); |
483 } | 594 } |
484 | 595 |
485 void WindowSelectorItem::SetOpacity(float opacity) { | 596 void WindowSelectorItem::SetOpacity(float opacity) { |
486 window_label_->SetOpacity(opacity); | 597 window_label_->SetOpacity(opacity); |
598 if (background_view_) { | |
599 background_view_->AnimateBackgroundOpacity( | |
600 selected_ ? 0.f : kHeaderOpacity * opacity); | |
601 } | |
602 | |
487 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 603 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
488 close_button_widget_->SetOpacity(opacity); | 604 close_button_widget_->SetOpacity(opacity); |
489 | 605 |
490 transform_window_.SetOpacity(opacity); | 606 transform_window_.SetOpacity(opacity); |
491 } | 607 } |
492 | 608 |
493 void WindowSelectorItem::UpdateWindowLabel( | 609 void WindowSelectorItem::UpdateWindowLabel( |
494 const gfx::Rect& window_bounds, | 610 const gfx::Rect& window_bounds, |
495 OverviewAnimationType animation_type) { | 611 OverviewAnimationType animation_type) { |
496 if (!window_label_->IsVisible()) { | 612 if (!window_label_->IsVisible()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
507 animation_type, | 623 animation_type, |
508 WmLookup::Get()->GetWindowForWidget(window_label_.get())); | 624 WmLookup::Get()->GetWindowForWidget(window_label_.get())); |
509 | 625 |
510 WmWindow* window_label_window = | 626 WmWindow* window_label_window = |
511 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 627 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
512 window_label_window->SetBounds(label_bounds); | 628 window_label_window->SetBounds(label_bounds); |
513 } | 629 } |
514 | 630 |
515 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { | 631 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
516 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | 632 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); |
517 window_label_.reset(new views::Widget); | 633 if (material) { |
518 views::Widget::InitParams params; | 634 background_view_ = new RoundedContainerView( |
519 params.type = views::Widget::InitParams::TYPE_POPUP; | 635 this, transform_window_.window(), kLabelBackgroundRadius, |
520 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 636 transform_window_.GetTopColor()); |
521 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 637 // |background_view_| will get added as a child to CaptionContainerView. |
522 params.visible_on_all_workspaces = true; | 638 } |
523 params.name = "OverviewModeLabel"; | 639 views::Widget::InitParams params_label; |
524 window_label_->set_focus_on_creation(false); | 640 params_label.type = views::Widget::InitParams::TYPE_POPUP; |
641 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
642 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
643 params_label.visible_on_all_workspaces = true; | |
644 params_label.name = "OverviewModeLabel"; | |
645 params_label.activatable = | |
646 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; | |
647 params_label.accept_events = true; | |
525 root_window_->GetRootWindowController() | 648 root_window_->GetRootWindowController() |
526 ->ConfigureWidgetInitParamsForContainer( | 649 ->ConfigureWidgetInitParamsForContainer( |
527 window_label_.get(), kShellWindowId_StatusContainer, ¶ms); | 650 window_label_.get(), |
528 window_label_->Init(params); | 651 transform_window_.window()->GetParent()->GetShellWindowId(), |
652 ¶ms_label); | |
653 window_label_.reset(new views::Widget); | |
654 window_label_->set_focus_on_creation(false); | |
655 window_label_->Init(params_label); | |
529 window_label_button_view_ = new OverviewLabelButton(this, title); | 656 window_label_button_view_ = new OverviewLabelButton(this, title); |
530 window_label_button_view_->SetBorder(views::Border::NullBorder()); | 657 window_label_button_view_->SetBorder(views::Border::NullBorder()); |
531 window_label_button_view_->SetEnabledTextColors(kLabelColor); | 658 window_label_button_view_->SetEnabledTextColors(kLabelColor); |
532 window_label_button_view_->set_animate_on_state_change(false); | 659 window_label_button_view_->set_animate_on_state_change(false); |
533 if (material) { | 660 if (material) { |
661 WmWindow* label_window = | |
662 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | |
663 if (transform_window_.GetTopInset()) { | |
664 // For windows with headers the overview header fades in above the | |
665 // original window header. | |
666 label_window->GetParent()->StackChildAbove(label_window, | |
667 transform_window_.window()); | |
668 } else { | |
669 // For tabbed windows the overview header slides from behind. The stacking | |
670 // is then corrected when the animation completes. | |
671 label_window->GetParent()->StackChildBelow(label_window, | |
672 transform_window_.window()); | |
673 } | |
534 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 674 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
535 } else { | 675 } else { |
536 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 676 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
537 window_label_button_view_->SetTextShadows(gfx::ShadowValues( | 677 window_label_button_view_->SetTextShadows(gfx::ShadowValues( |
538 1, gfx::ShadowValue(gfx::Vector2d(0, kVerticalShadowOffset), | 678 1, gfx::ShadowValue(gfx::Vector2d(0, kVerticalShadowOffset), |
539 kShadowBlur, kLabelShadow))); | 679 kShadowBlur, kLabelShadow))); |
540 } | 680 } |
541 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 681 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
542 window_label_button_view_->SetFontList(bundle.GetFontList( | 682 window_label_button_view_->SetFontList(bundle.GetFontList( |
543 material ? ui::ResourceBundle::BaseFont : ui::ResourceBundle::BoldFont)); | 683 material ? ui::ResourceBundle::BaseFont : ui::ResourceBundle::BoldFont)); |
544 if (material) { | 684 if (material) { |
545 // Hint at the background color that the label will be drawn onto (for | 685 // Hint at the background color that the label will be drawn onto (for |
546 // subpixel antialiasing). Does not actually set the background color. | 686 // subpixel antialiasing). Does not actually set the background color. |
547 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); | 687 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); |
548 caption_container_view_ = | 688 caption_container_view_ = new CaptionContainerView( |
549 new CaptionContainerView(window_label_button_view_, close_button_); | 689 window_label_button_view_, close_button_, background_view_); |
550 window_label_->SetContentsView(caption_container_view_); | 690 window_label_->SetContentsView(caption_container_view_); |
551 window_label_button_view_->SetVisible(false); | 691 window_label_button_view_->SetVisible(false); |
692 window_label_->SetOpacity(0); | |
552 window_label_->Show(); | 693 window_label_->Show(); |
553 | 694 |
554 shadow_.reset(new ::wm::Shadow()); | 695 // TODO(varkha): Restore shadows when programmatic shadows exist. |
555 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); | 696 // Note: current shadow implementation does not allow proper animation when |
556 shadow_->layer()->SetVisible(true); | 697 // the parent layer bounds change during the animation since |
557 window_label_->GetLayer()->Add(shadow_->layer()); | 698 // Shadow::UpdateLayerBounds() only happens before the animation starts. |
699 if (ash::MaterialDesignController::GetMode() == | |
700 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) { | |
701 shadow_.reset(new ::wm::Shadow()); | |
702 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); | |
703 shadow_->layer()->SetVisible(true); | |
704 window_label_->GetLayer()->Add(shadow_->layer()); | |
705 } | |
558 window_label_->GetLayer()->SetMasksToBounds(false); | 706 window_label_->GetLayer()->SetMasksToBounds(false); |
559 | 707 UpdateHeaderLayout(HeaderFadeInMode::Enter, |
560 views::View* background_view = | 708 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
561 new RoundedContainerView(kLabelBackgroundRadius, kLabelBackgroundColor); | |
562 window_label_selector_.reset(new views::Widget); | |
563 params.activatable = views::Widget::InitParams::Activatable::ACTIVATABLE_NO; | |
564 params.accept_events = false; | |
565 params.name = "OverviewModeLabelSelector"; | |
566 window_label_selector_->Init(params); | |
567 window_label_selector_->set_focus_on_creation(false); | |
568 window_label_selector_->SetContentsView(background_view); | |
569 window_label_selector_->Show(); | |
570 } else { | 709 } else { |
571 // Indicate that the label will be drawn onto a transparent background | 710 // Indicate that the label will be drawn onto a transparent background |
572 // (disables subpixel antialiasing). | 711 // (disables subpixel antialiasing). |
573 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); | 712 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); |
574 window_label_->SetContentsView(window_label_button_view_); | 713 window_label_->SetContentsView(window_label_button_view_); |
575 } | 714 } |
576 } | 715 } |
577 | 716 |
578 void WindowSelectorItem::UpdateHeaderLayout( | 717 void WindowSelectorItem::UpdateHeaderLayout( |
718 HeaderFadeInMode mode, | |
579 OverviewAnimationType animation_type) { | 719 OverviewAnimationType animation_type) { |
580 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( | 720 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
581 transform_window_.GetTransformedBounds(hide_header())); | 721 transform_window_.GetTransformedBounds(hide_header())); |
582 | 722 |
583 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 723 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
584 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 724 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
585 label_rect.set_y(-label_rect.height()); | |
586 label_rect.set_width(transformed_window_bounds.width()); | 725 label_rect.set_width(transformed_window_bounds.width()); |
587 | 726 // For tabbed windows the initial bounds of the caption are set such that it |
588 if (!window_label_button_view_->visible()) { | 727 // appears to be "growing" up from the window content area. |
728 label_rect.set_y( | |
729 (mode != HeaderFadeInMode::Enter || transform_window_.GetTopInset()) | |
730 ? -label_rect.height() | |
731 : 0); | |
732 if (background_view_ && mode == HeaderFadeInMode::Exit) { | |
733 background_view_->AnimateColor(gfx::Tween::EASE_OUT); | |
734 background_view_->set_color(transform_window_.GetTopColor()); | |
735 } else if (!window_label_button_view_->visible()) { | |
589 window_label_button_view_->SetVisible(true); | 736 window_label_button_view_->SetVisible(true); |
737 if (background_view_) { | |
738 background_view_->ObserveLayer(window_label_->GetLayer()); | |
739 if (mode == HeaderFadeInMode::Enter) | |
740 background_view_->AnimateColor(gfx::Tween::EASE_IN); | |
741 background_view_->set_color(kLabelBackgroundColor); | |
742 } | |
590 SetupFadeInAfterLayout(window_label_.get()); | 743 SetupFadeInAfterLayout(window_label_.get()); |
591 SetupFadeInAfterLayout(window_label_selector_.get()); | |
592 } | 744 } |
593 WmWindow* window_label_window = | 745 WmWindow* window_label_window = |
594 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 746 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
595 WmWindow* window_label_selector_window = | |
596 WmLookup::Get()->GetWindowForWidget(window_label_selector_.get()); | |
597 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 747 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
598 ScopedOverviewAnimationSettingsFactory::Get() | 748 ScopedOverviewAnimationSettingsFactory::Get() |
599 ->CreateOverviewAnimationSettings(animation_type, | 749 ->CreateOverviewAnimationSettings(animation_type, |
600 window_label_window); | 750 window_label_window); |
601 std::unique_ptr<ScopedOverviewAnimationSettings> | |
602 animation_settings_selector = | |
603 ScopedOverviewAnimationSettingsFactory::Get() | |
604 ->CreateOverviewAnimationSettings(animation_type, | |
605 window_label_selector_window); | |
606 window_label_selector_window->SetBounds(label_rect); | |
607 // |window_label_window| covers both the transformed window and the header | 751 // |window_label_window| covers both the transformed window and the header |
608 // as well as the gap between the windows to prevent events from reaching | 752 // as well as the gap between the windows to prevent events from reaching |
609 // the window including its sizing borders. | 753 // the window including its sizing borders. |
610 label_rect.set_height(label_rect.height() + | 754 if (mode != HeaderFadeInMode::Enter) { |
611 transformed_window_bounds.height()); | 755 label_rect.set_height(close_button_->GetPreferredSize().height() + |
612 gfx::Rect shadow_bounds(label_rect.size()); | 756 transformed_window_bounds.height()); |
757 } | |
613 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 758 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
614 window_label_window->SetBounds(label_rect); | 759 window_label_window->SetBounds(label_rect); |
615 gfx::Transform label_transform; | 760 gfx::Transform label_transform; |
616 label_transform.Translate(transformed_window_bounds.x(), | 761 label_transform.Translate(transformed_window_bounds.x(), |
617 transformed_window_bounds.y()); | 762 transformed_window_bounds.y()); |
618 window_label_window->SetTransform(label_transform); | 763 window_label_window->SetTransform(label_transform); |
619 window_label_selector_window->SetTransform(label_transform); | |
620 | 764 |
621 shadow_bounds.Offset(kWindowSelectorMargin, kWindowSelectorMargin); | 765 gfx::Rect shadow_bounds(label_rect.size()); |
622 shadow_->SetContentBounds(shadow_bounds); | 766 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); |
767 if (shadow_) | |
768 shadow_->SetContentBounds(shadow_bounds); | |
623 } else { | 769 } else { |
624 if (!close_button_->visible()) { | 770 if (!close_button_->visible()) { |
625 close_button_->SetVisible(true); | 771 close_button_->SetVisible(true); |
626 SetupFadeInAfterLayout(close_button_widget_.get()); | 772 SetupFadeInAfterLayout(close_button_widget_.get()); |
627 } | 773 } |
628 WmWindow* close_button_widget_window = | 774 WmWindow* close_button_widget_window = |
629 WmLookup::Get()->GetWindowForWidget(close_button_widget_.get()); | 775 WmLookup::Get()->GetWindowForWidget(close_button_widget_.get()); |
630 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 776 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
631 ScopedOverviewAnimationSettingsFactory::Get() | 777 ScopedOverviewAnimationSettingsFactory::Get() |
632 ->CreateOverviewAnimationSettings(animation_type, | 778 ->CreateOverviewAnimationSettings(animation_type, |
633 close_button_widget_window); | 779 close_button_widget_window); |
634 | 780 |
635 gfx::Transform close_button_transform; | 781 gfx::Transform close_button_transform; |
636 close_button_transform.Translate(transformed_window_bounds.right(), | 782 close_button_transform.Translate(transformed_window_bounds.right(), |
637 transformed_window_bounds.y()); | 783 transformed_window_bounds.y()); |
638 close_button_widget_window->SetTransform(close_button_transform); | 784 close_button_widget_window->SetTransform(close_button_transform); |
639 } | 785 } |
640 } | 786 } |
641 | 787 |
642 void WindowSelectorItem::AnimateOpacity(float opacity, | 788 void WindowSelectorItem::AnimateOpacity(float opacity, |
643 OverviewAnimationType animation_type) { | 789 OverviewAnimationType animation_type) { |
644 DCHECK_GE(opacity, 0.f); | 790 DCHECK_GE(opacity, 0.f); |
645 DCHECK_LE(opacity, 1.f); | 791 DCHECK_LE(opacity, 1.f); |
646 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 792 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
647 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 793 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
648 transform_window_.SetOpacity(opacity); | 794 transform_window_.SetOpacity(opacity); |
649 | 795 |
796 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; | |
650 WmWindow* window_label_window = | 797 WmWindow* window_label_window = |
651 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 798 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
652 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 799 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
653 ScopedOverviewAnimationSettingsFactory::Get() | 800 ScopedOverviewAnimationSettingsFactory::Get() |
654 ->CreateOverviewAnimationSettings(animation_type, | 801 ->CreateOverviewAnimationSettings(animation_type, |
655 window_label_window); | 802 window_label_window); |
656 window_label_window->SetOpacity(opacity); | 803 window_label_window->SetOpacity(header_opacity); |
657 | |
658 WmWindow* window_label_selector_window = | |
659 WmLookup::Get()->GetWindowForWidget(window_label_selector_.get()); | |
660 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_selector = | |
661 ScopedOverviewAnimationSettingsFactory::Get() | |
662 ->CreateOverviewAnimationSettings(animation_type, | |
663 window_label_selector_window); | |
664 window_label_selector_window->SetOpacity(opacity); | |
665 } | 804 } |
666 | 805 |
667 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 806 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
668 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( | 807 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( |
669 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, | 808 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, |
670 GetWindow()->GetTitle())); | 809 GetWindow()->GetTitle())); |
671 } | 810 } |
672 | 811 |
812 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { | |
813 widget->SetOpacity(1.f); | |
814 | |
815 // Fade out the widget. This animation continues past the lifetime of |this|. | |
816 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | |
817 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | |
818 ScopedOverviewAnimationSettingsFactory::Get() | |
819 ->CreateOverviewAnimationSettings( | |
820 OverviewAnimationType:: | |
821 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, | |
822 widget_window); | |
823 // CleanupAnimationObserver will delete itself (and the widget) when the | |
824 // opacity animation is complete. | |
825 // Ownership over the observer is passed to the window_selector_->delegate() | |
826 // which has longer lifetime so that animations can continue even after the | |
827 // overview mode is shut down. | |
828 views::Widget* widget_ptr = widget.get(); | |
829 std::unique_ptr<CleanupAnimationObserver> observer( | |
830 new CleanupAnimationObserver(std::move(widget))); | |
831 animation_settings->AddObserver(observer.get()); | |
bruthig
2016/09/08 18:32:49
Out of curiosity I looked into how long the layer
varkha
2016/09/09 02:25:25
The subtlety is that the observer is removed from
bruthig
2016/09/09 13:58:27
Acknowledged.
| |
832 window_selector_->delegate()->AddDelayedAnimationObserver( | |
833 std::move(observer)); | |
834 widget_ptr->SetOpacity(0.f); | |
835 } | |
836 | |
673 } // namespace ash | 837 } // namespace ash |
OLD | NEW |