Chromium Code Reviews| 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 |
| 53 // around the window within the cell. This margin does not overlap so the | 56 // around the window within the cell. This margin does not overlap so the |
| 54 // closest distance between adjacent windows will be twice this amount. | 57 // closest distance between adjacent windows will be twice this amount. |
| 55 static const int kWindowMargin = 30; | 58 static const int kWindowMargin = 30; |
| 56 static const int kWindowMarginMD = 5; | 59 static const int kWindowMarginMD = 5; |
| 57 | 60 |
| 58 // Cover the transformed window including the gaps between the windows with a | 61 // Cover the transformed window including the gaps between the windows with a |
| 59 // transparent shield to block the input events from reaching the transformed | 62 // transparent shield to block the input events from reaching the transformed |
| 60 // window while in overview. | 63 // window while in overview. |
| 61 static const int kWindowSelectorMargin = kWindowMarginMD * 2; | 64 static const int kWindowSelectorMargin = kWindowMarginMD * 2; |
| 62 | 65 |
| 63 // Foreground label color. | 66 // Foreground label color. |
| 64 static const SkColor kLabelColor = SK_ColorWHITE; | 67 static const SkColor kLabelColor = SK_ColorWHITE; |
| 65 | 68 |
| 66 // TODO(tdanderson): Move this to a central location. | 69 // TODO(tdanderson): Move this to a central location. |
| 67 static const SkColor kCloseButtonColor = SK_ColorWHITE; | 70 static const SkColor kCloseButtonColor = SK_ColorWHITE; |
| 68 | 71 |
| 69 // Label background color used with Material Design. | 72 // Label background color used with Material Design once in overview mode. |
| 70 // TODO(varkha): Make background color conform to window header. | |
| 71 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255); | 73 static const SkColor kLabelBackgroundColor = SkColorSetARGB(25, 255, 255, 255); |
| 72 | 74 |
| 75 // Label background color used with Material Design when exiting overview mode. | |
| 76 static const SkColor kLabelExitColor = SkColorSetARGB(255, 90, 90, 90); | |
| 77 | |
| 73 // Corner radius for the selection tiles used with Material Design. | 78 // Corner radius for the selection tiles used with Material Design. |
| 74 static int kLabelBackgroundRadius = 2; | 79 static int kLabelBackgroundRadius = 2; |
| 75 | 80 |
| 76 // Label shadow color. | 81 // Label shadow color. |
| 77 static const SkColor kLabelShadow = SkColorSetARGB(176, 0, 0, 0); | 82 static const SkColor kLabelShadow = SkColorSetARGB(176, 0, 0, 0); |
| 78 | 83 |
| 79 // Vertical padding for the label, on top of it. | 84 // Vertical padding for the label, on top of it. |
| 80 static const int kVerticalLabelPadding = 20; | 85 static const int kVerticalLabelPadding = 20; |
| 81 | 86 |
| 82 // Horizontal padding for the label, on both sides. Used with Material Design. | 87 // Horizontal padding for the label, on both sides. Used with Material Design. |
| 83 static const int kHorizontalLabelPaddingMD = 8; | 88 static const int kHorizontalLabelPaddingMD = 8; |
| 84 | 89 |
| 85 // Solid shadow length from the label | 90 // Solid shadow length from the label |
| 86 static const int kVerticalShadowOffset = 1; | 91 static const int kVerticalShadowOffset = 1; |
| 87 | 92 |
| 88 // Amount of blur applied to the label shadow | 93 // Amount of blur applied to the label shadow |
| 89 static const int kShadowBlur = 10; | 94 static const int kShadowBlur = 10; |
| 90 | 95 |
| 91 // Height of an item header in Material Design. | 96 // Height of an item header in Material Design. |
| 92 static const int kHeaderHeight = 32; | 97 static const int kHeaderHeight = 32; |
| 93 | 98 |
| 94 // Opacity for dimmed items. | 99 // Opacity for dimmed items. |
| 95 static const float kDimmedItemOpacity = 0.5f; | 100 static const float kDimmedItemOpacity = 0.5f; |
| 96 | 101 |
| 97 // Opacity for fading out during closing a window. | 102 // Opacity for fading out during closing a window. |
| 98 static const float kClosingItemOpacity = 0.8f; | 103 static const float kClosingItemOpacity = 0.8f; |
| 99 | 104 |
| 105 // Opacity for the item header. | |
| 106 static const float kHeaderOpacity = | |
| 107 (SkColorGetA(kLabelBackgroundColor) / 255.f); | |
| 108 | |
| 109 // Duration it takes for the header to shift from opaque header color to | |
| 110 // |kLabelBackgroundColor|. | |
| 111 static const int kSelectorColorSlideMilliseconds = 240; | |
| 112 | |
| 100 // Duration of background opacity transition for the selected label. | 113 // Duration of background opacity transition for the selected label. |
| 101 static const int kSelectorFadeInMilliseconds = 350; | 114 static const int kSelectorFadeInMilliseconds = 350; |
| 102 | 115 |
| 116 // Duration of background opacity transition when exiting overview mode. | |
| 117 static const int kExitFadeInMilliseconds = 30; | |
| 118 | |
| 103 // Before closing a window animate both the window and the caption to shrink by | 119 // Before closing a window animate both the window and the caption to shrink by |
| 104 // this fraction of size. | 120 // this fraction of size. |
| 105 static const float kPreCloseScale = 0.02f; | 121 static const float kPreCloseScale = 0.02f; |
| 106 | 122 |
| 107 // Convenience method to fade in a Window with predefined animation settings. | 123 // 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 | 124 // Note: The fade in animation will occur after a delay where the delay is how |
| 109 // long the lay out animations take. | 125 // long the lay out animations take. |
| 110 void SetupFadeInAfterLayout(views::Widget* widget) { | 126 void SetupFadeInAfterLayout(views::Widget* widget) { |
| 111 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 127 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
| 112 window->SetOpacity(0.0f); | 128 window->SetOpacity(0.0f); |
| 113 std::unique_ptr<ScopedOverviewAnimationSettings> | 129 std::unique_ptr<ScopedOverviewAnimationSettings> |
| 114 scoped_overview_animation_settings = | 130 scoped_overview_animation_settings = |
| 115 ScopedOverviewAnimationSettingsFactory::Get() | 131 ScopedOverviewAnimationSettingsFactory::Get() |
| 116 ->CreateOverviewAnimationSettings( | 132 ->CreateOverviewAnimationSettings( |
| 117 OverviewAnimationType:: | 133 OverviewAnimationType:: |
| 118 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | 134 OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
| 119 window); | 135 window); |
| 120 window->SetOpacity(1.0f); | 136 window->SetOpacity(1.0f); |
| 121 } | 137 } |
| 122 | 138 |
| 123 // An image button with a close window icon. | 139 } // namespace |
| 124 class OverviewCloseButton : public views::ImageButton { | |
| 125 public: | |
| 126 explicit OverviewCloseButton(views::ButtonListener* listener); | |
| 127 ~OverviewCloseButton() override; | |
| 128 | 140 |
| 129 private: | 141 WindowSelectorItem::OverviewCloseButton::OverviewCloseButton( |
| 130 gfx::ImageSkia icon_image_; | 142 views::ButtonListener* listener) |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(OverviewCloseButton); | |
| 133 }; | |
| 134 | |
| 135 OverviewCloseButton::OverviewCloseButton(views::ButtonListener* listener) | |
| 136 : views::ImageButton(listener) { | 143 : views::ImageButton(listener) { |
| 137 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 144 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 138 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, | 145 icon_image_ = gfx::CreateVectorIcon(gfx::VectorIconId::WINDOW_CONTROL_CLOSE, |
| 139 kCloseButtonColor); | 146 kCloseButtonColor); |
| 140 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); | 147 SetImage(views::CustomButton::STATE_NORMAL, &icon_image_); |
| 141 SetImage(views::CustomButton::STATE_HOVERED, &icon_image_); | 148 SetImage(views::CustomButton::STATE_HOVERED, &icon_image_); |
| 142 SetImage(views::CustomButton::STATE_PRESSED, &icon_image_); | 149 SetImage(views::CustomButton::STATE_PRESSED, &icon_image_); |
| 143 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 150 SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 144 views::ImageButton::ALIGN_MIDDLE); | 151 views::ImageButton::ALIGN_MIDDLE); |
| 145 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); | 152 SetMinimumImageSize(gfx::Size(kHeaderHeight, kHeaderHeight)); |
| 146 } else { | 153 } else { |
| 147 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 148 SetImage(views::CustomButton::STATE_NORMAL, | 155 SetImage(views::CustomButton::STATE_NORMAL, |
| 149 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); | 156 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE)); |
| 150 SetImage(views::CustomButton::STATE_HOVERED, | 157 SetImage(views::CustomButton::STATE_HOVERED, |
| 151 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); | 158 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); |
| 152 SetImage(views::CustomButton::STATE_PRESSED, | 159 SetImage(views::CustomButton::STATE_PRESSED, |
| 153 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); | 160 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); |
| 154 } | 161 } |
| 155 } | 162 } |
| 156 | 163 |
| 157 OverviewCloseButton::~OverviewCloseButton() {} | 164 WindowSelectorItem::OverviewCloseButton::~OverviewCloseButton() {} |
| 158 | 165 |
| 159 // A View having rounded corners and a specified background color which is | 166 // A View having rounded top corners and a specified background color which is |
| 160 // only painted within the bounds defined by the rounded corners. | 167 // only painted within the bounds defined by the rounded corners. |
| 161 // TODO(varkha): This duplicates code from RoundedImageView. Refactor these | 168 // This class coordinates the transitions of the overview mode header when |
| 162 // classes and move into ui/views. | 169 // entering the overview mode. Those animations are: |
| 163 class RoundedContainerView : public views::View { | 170 // - Opacity animation. The header is initially same color as the original |
|
sky
2016/09/09 16:13:20
Thanks for improving the description!
varkha
2016/09/09 16:37:46
Acknowledged.
| |
| 171 // window's header. It starts as transparent and is faded in. When the full | |
| 172 // opacity is reached the original header is hidden (which is nearly | |
| 173 // imperceptable because this view obscures the original header) and a color | |
| 174 // animation starts. | |
| 175 // - Color animation is used to change the color from the opaque color of the | |
| 176 // original window's header to semi-transparent color of the overview mode | |
| 177 // header (on entry to overview). It is also used on exit from overview to | |
| 178 // quickly change the color to a close opaque color in parallel with an | |
| 179 // opacity transition to mask the original header reappearing. | |
| 180 class WindowSelectorItem::RoundedContainerView | |
| 181 : public views::View, | |
| 182 public gfx::AnimationDelegate, | |
| 183 public ui::LayerAnimationObserver { | |
| 164 public: | 184 public: |
| 165 RoundedContainerView(int corner_radius, SkColor background) | 185 RoundedContainerView(WindowSelectorItem* item, |
| 166 : corner_radius_(corner_radius), background_(background) {} | 186 WmWindow* item_window, |
| 187 int corner_radius, | |
| 188 SkColor background) | |
| 189 : item_(item), | |
| 190 item_window_(item_window), | |
| 191 corner_radius_(corner_radius), | |
| 192 previous_color_(background), | |
|
sky
2016/09/09 16:13:20
I was mildly confused by these names and what they
varkha
2016/09/09 16:37:46
Done.
| |
| 193 color_(background), | |
| 194 last_alpha_(0), | |
| 195 current_value_(0), | |
| 196 layer_(nullptr), | |
| 197 animation_(new gfx::SlideAnimation(this)) {} | |
| 167 | 198 |
| 168 ~RoundedContainerView() override {} | 199 ~RoundedContainerView() override { StopObservingLayerAnimations(); } |
| 169 | 200 |
| 201 void OnItemRestored() { item_ = nullptr; } | |
| 202 | |
| 203 // Starts observing layer animations so that actions can be taken when | |
| 204 // particular animations (opacity) complete. It should only be called once | |
| 205 // when the initial fade in animation is started. | |
| 206 void ObserveLayerAnimations(ui::Layer* layer) { | |
| 207 DCHECK(!layer_); | |
| 208 layer_ = layer; | |
| 209 layer_->GetAnimator()->AddObserver(this); | |
| 210 } | |
| 211 | |
| 212 void set_color(SkColor color) { color_ = color; } | |
| 213 | |
| 214 // Starts a color animation using |tween_type|. The animation will change the | |
| 215 // color from |previous_color_| to |color_| over |duration| specified in | |
| 216 // milliseconds. | |
| 217 void AnimateColor(gfx::Tween::Type tween_type, int duration) { | |
|
sky
2016/09/09 16:13:19
If this is expected to only be called once and whi
varkha
2016/09/09 16:37:46
Done.
| |
| 218 animation_->SetSlideDuration(duration); | |
| 219 animation_->SetTweenType(tween_type); | |
| 220 animation_->Reset(0); | |
| 221 animation_->Show(); | |
| 222 | |
| 223 // Tests complete animations immediately. Emulate by invoking the callback. | |
| 224 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == | |
| 225 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) { | |
| 226 AnimationEnded(animation_.get()); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 // Changes the view opacity by animating its background color. The animation | |
| 231 // will change the alpha value in |color_| from its current value to | |
| 232 // |opacity| * 255 but preserve the RGB values. | |
| 233 void AnimateBackgroundOpacity(float opacity) { | |
| 234 animation_->SetSlideDuration(kSelectorFadeInMilliseconds); | |
| 235 animation_->SetTweenType(gfx::Tween::EASE_OUT); | |
| 236 animation_->Reset(0); | |
| 237 animation_->Show(); | |
| 238 color_ = SkColorSetA(color_, opacity * 255); | |
| 239 } | |
| 240 | |
| 241 // views::View: | |
| 170 void OnPaint(gfx::Canvas* canvas) override { | 242 void OnPaint(gfx::Canvas* canvas) override { |
| 171 views::View::OnPaint(canvas); | 243 views::View::OnPaint(canvas); |
| 172 | |
| 173 SkScalar radius = SkIntToScalar(corner_radius_); | 244 SkScalar radius = SkIntToScalar(corner_radius_); |
| 174 const SkScalar kRadius[8] = {radius, radius, radius, radius, | 245 const SkScalar kRadius[8] = {radius, radius, radius, radius, 0, 0, 0, 0}; |
| 175 radius, radius, radius, radius}; | |
| 176 SkPath path; | 246 SkPath path; |
| 177 gfx::Rect bounds(size()); | 247 gfx::Rect bounds(size()); |
| 178 bounds.set_height(bounds.height() + radius); | |
| 179 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); | 248 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); |
| 180 | 249 |
| 181 SkPaint paint; | 250 SkPaint paint; |
| 182 paint.setAntiAlias(true); | 251 paint.setAntiAlias(true); |
| 183 canvas->ClipPath(path, true); | 252 canvas->ClipPath(path, true); |
| 184 canvas->DrawColor(background_); | 253 |
| 254 SkColor color = previous_color_; | |
| 255 if (color_ != color) | |
| 256 color = color_utils::AlphaBlend(color_, previous_color_, current_value_); | |
| 257 canvas->DrawColor(color); | |
| 258 last_alpha_ = SkColorGetA(color); | |
|
sky
2016/09/09 16:13:19
You seem to calculate this, but it's never used. I
varkha
2016/09/09 16:37:46
Done. Good catch, thanks! Scaffolding.
| |
| 185 } | 259 } |
| 186 | 260 |
| 187 private: | 261 private: |
| 262 // Stops observing layer animations | |
| 263 void StopObservingLayerAnimations() { | |
| 264 if (!layer_) | |
| 265 return; | |
| 266 layer_->GetAnimator()->RemoveObserver(this); | |
| 267 layer_ = nullptr; | |
| 268 } | |
| 269 | |
| 270 // gfx::AnimationDelegate: | |
| 271 void AnimationEnded(const gfx::Animation* animation) override { | |
| 272 previous_color_ = color_; | |
| 273 WmWindow* label_window = WmLookup::Get()->GetWindowForWidget(GetWidget()); | |
|
sky
2016/09/09 16:13:20
It isn't obvious why you need to restack here. Ple
varkha
2016/09/09 16:37:46
Done.
varkha
2016/09/09 16:47:08
Got the comments wrong. Correcting now...
varkha
2016/09/09 16:51:47
Done.
| |
| 274 if (label_window && item_window_) | |
| 275 label_window->GetParent()->StackChildAbove(label_window, item_window_); | |
| 276 item_window_ = nullptr; | |
| 277 } | |
| 278 | |
| 279 void AnimationProgressed(const gfx::Animation* animation) override { | |
| 280 current_value_ = animation_->CurrentValueBetween(0, 255); | |
| 281 SchedulePaint(); | |
| 282 } | |
| 283 | |
| 284 void AnimationCanceled(const gfx::Animation* animation) override { | |
| 285 item_window_ = nullptr; | |
| 286 previous_color_ = color_; | |
| 287 current_value_ = 255; | |
| 288 SchedulePaint(); | |
| 289 } | |
| 290 | |
| 291 // ui::LayerAnimationObserver: | |
| 292 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override { | |
| 293 if (0 != (sequence->properties() & | |
| 294 ui::LayerAnimationElement::AnimatableProperty::OPACITY)) { | |
| 295 if (item_) | |
| 296 item_->HideHeaderAndSetShape(0); | |
| 297 StopObservingLayerAnimations(); | |
| 298 AnimateColor(gfx::Tween::EASE_IN, kSelectorColorSlideMilliseconds); | |
| 299 } | |
| 300 } | |
| 301 | |
| 302 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override { | |
| 303 if (0 != (sequence->properties() & | |
| 304 ui::LayerAnimationElement::AnimatableProperty::OPACITY)) { | |
| 305 StopObservingLayerAnimations(); | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 void OnLayerAnimationScheduled( | |
| 310 ui::LayerAnimationSequence* sequence) override {} | |
| 311 | |
| 312 WindowSelectorItem* item_; | |
| 313 WmWindow* item_window_; | |
| 188 int corner_radius_; | 314 int corner_radius_; |
| 189 SkColor background_; | 315 SkColor previous_color_; |
| 316 SkColor color_; | |
| 317 int last_alpha_; | |
| 318 int current_value_; | |
| 319 ui::Layer* layer_; | |
| 320 std::unique_ptr<gfx::SlideAnimation> animation_; | |
| 190 | 321 |
| 191 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | 322 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
| 192 }; | 323 }; |
| 193 | 324 |
| 194 } // namespace | |
| 195 | |
| 196 bool WindowSelectorItem::use_mask_ = false; | 325 bool WindowSelectorItem::use_mask_ = false; |
| 197 bool WindowSelectorItem::use_shape_ = false; | 326 bool WindowSelectorItem::use_shape_ = false; |
| 198 | 327 |
| 199 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( | 328 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton( |
| 200 views::ButtonListener* listener, | 329 views::ButtonListener* listener, |
| 201 const base::string16& text) | 330 const base::string16& text) |
| 202 : LabelButton(listener, text) {} | 331 : LabelButton(listener, text) {} |
| 203 | 332 |
| 204 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} | 333 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {} |
| 205 | 334 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 216 bounds.Inset(padding_); | 345 bounds.Inset(padding_); |
| 217 if (ash::MaterialDesignController::IsOverviewMaterial()) | 346 if (ash::MaterialDesignController::IsOverviewMaterial()) |
| 218 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); | 347 bounds.Inset(kHorizontalLabelPaddingMD, 0, kHorizontalLabelPaddingMD, 0); |
| 219 return bounds; | 348 return bounds; |
| 220 } | 349 } |
| 221 | 350 |
| 222 // Container View that has an item label and a close button as children. | 351 // Container View that has an item label and a close button as children. |
| 223 class WindowSelectorItem::CaptionContainerView : public views::View { | 352 class WindowSelectorItem::CaptionContainerView : public views::View { |
| 224 public: | 353 public: |
| 225 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, | 354 CaptionContainerView(WindowSelectorItem::OverviewLabelButton* label, |
| 226 views::ImageButton* close_button) | 355 views::ImageButton* close_button, |
| 227 : label_(label), close_button_(close_button) { | 356 WindowSelectorItem::RoundedContainerView* background) |
| 357 : label_(label), close_button_(close_button), background_(background) { | |
| 358 AddChildView(background_); | |
| 228 AddChildView(label_); | 359 AddChildView(label_); |
| 229 AddChildView(close_button_); | 360 AddChildView(close_button_); |
| 230 } | 361 } |
| 231 | 362 |
| 232 protected: | 363 protected: |
| 233 // views::View: | 364 // views::View: |
| 234 void Layout() override { | 365 void Layout() override { |
| 235 // Position close button in the top right corner sized to its icon size and | 366 // 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 | 367 // the label in the top left corner as tall as the button and extending to |
| 237 // the button's left edge. | 368 // the button's left edge. |
| 238 // The rest of this container view serves as a shield to prevent input | 369 // The rest of this container view serves as a shield to prevent input |
| 239 // events from reaching the transformed window in overview. | 370 // events from reaching the transformed window in overview. |
| 240 gfx::Rect bounds(GetLocalBounds()); | 371 gfx::Rect bounds(GetLocalBounds()); |
| 241 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); | 372 bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); |
| 373 gfx::Rect background_bounds(bounds); | |
| 374 background_bounds.set_height(close_button_->GetPreferredSize().height()); | |
| 375 background_->SetBoundsRect(background_bounds); | |
| 376 | |
| 242 const int visible_height = close_button_->GetPreferredSize().height(); | 377 const int visible_height = close_button_->GetPreferredSize().height(); |
| 243 gfx::Insets label_padding(0, 0, bounds.height() - visible_height, | 378 gfx::Insets label_padding(0, 0, bounds.height() - visible_height, |
| 244 visible_height); | 379 visible_height); |
| 245 label_->set_padding(label_padding); | 380 label_->set_padding(label_padding); |
| 246 label_->SetBoundsRect(bounds); | 381 label_->SetBoundsRect(bounds); |
| 247 bounds.set_x(bounds.right() - visible_height); | 382 bounds.set_x(bounds.right() - visible_height); |
| 248 bounds.set_width(visible_height); | 383 bounds.set_width(visible_height); |
| 249 bounds.set_height(visible_height); | 384 bounds.set_height(visible_height); |
| 250 close_button_->SetBoundsRect(bounds); | 385 close_button_->SetBoundsRect(bounds); |
| 251 } | 386 } |
| 252 | 387 |
| 253 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { Layout(); } | |
| 254 | |
| 255 private: | 388 private: |
| 256 WindowSelectorItem::OverviewLabelButton* label_; | 389 WindowSelectorItem::OverviewLabelButton* label_; |
| 257 views::ImageButton* close_button_; | 390 views::ImageButton* close_button_; |
| 391 WindowSelectorItem::RoundedContainerView* background_; | |
| 258 | 392 |
| 259 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); | 393 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); |
| 260 }; | 394 }; |
| 261 | 395 |
| 262 WindowSelectorItem::WindowSelectorItem(WmWindow* window, | 396 WindowSelectorItem::WindowSelectorItem(WmWindow* window, |
| 263 WindowSelector* window_selector) | 397 WindowSelector* window_selector) |
| 264 : dimmed_(false), | 398 : dimmed_(false), |
| 265 root_window_(window->GetRootWindow()), | 399 root_window_(window->GetRootWindow()), |
| 266 transform_window_(window), | 400 transform_window_(window), |
| 267 in_bounds_update_(false), | 401 in_bounds_update_(false), |
| 402 selected_(false), | |
| 268 caption_container_view_(nullptr), | 403 caption_container_view_(nullptr), |
| 269 window_label_button_view_(nullptr), | 404 window_label_button_view_(nullptr), |
| 270 close_button_(new OverviewCloseButton(this)), | 405 close_button_(new OverviewCloseButton(this)), |
| 271 window_selector_(window_selector) { | 406 window_selector_(window_selector), |
| 407 background_view_(nullptr) { | |
| 272 CreateWindowLabel(window->GetTitle()); | 408 CreateWindowLabel(window->GetTitle()); |
| 273 if (!ash::MaterialDesignController::IsOverviewMaterial()) { | 409 if (!ash::MaterialDesignController::IsOverviewMaterial()) { |
| 274 views::Widget::InitParams params; | 410 views::Widget::InitParams params; |
| 275 params.type = views::Widget::InitParams::TYPE_POPUP; | 411 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 276 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 412 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 277 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 413 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 278 params.name = "OverviewModeCloseButton"; | 414 params.name = "OverviewModeCloseButton"; |
| 279 close_button_widget_.reset(new views::Widget); | 415 close_button_widget_.reset(new views::Widget); |
| 280 close_button_widget_->set_focus_on_creation(false); | 416 close_button_widget_->set_focus_on_creation(false); |
| 281 window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 417 window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 293 close_button_rect.set_x(-close_button_rect.width() / 2); | 429 close_button_rect.set_x(-close_button_rect.width() / 2); |
| 294 close_button_rect.set_y(-close_button_rect.height() / 2); | 430 close_button_rect.set_y(-close_button_rect.height() / 2); |
| 295 WmLookup::Get() | 431 WmLookup::Get() |
| 296 ->GetWindowForWidget(close_button_widget_.get()) | 432 ->GetWindowForWidget(close_button_widget_.get()) |
| 297 ->SetBounds(close_button_rect); | 433 ->SetBounds(close_button_rect); |
| 298 } | 434 } |
| 299 GetWindow()->AddObserver(this); | 435 GetWindow()->AddObserver(this); |
| 300 } | 436 } |
| 301 | 437 |
| 302 WindowSelectorItem::~WindowSelectorItem() { | 438 WindowSelectorItem::~WindowSelectorItem() { |
| 439 if (background_view_) | |
| 440 background_view_->OnItemRestored(); | |
| 303 GetWindow()->RemoveObserver(this); | 441 GetWindow()->RemoveObserver(this); |
| 304 } | 442 } |
| 305 | 443 |
| 306 WmWindow* WindowSelectorItem::GetWindow() { | 444 WmWindow* WindowSelectorItem::GetWindow() { |
| 307 return transform_window_.window(); | 445 return transform_window_.window(); |
| 308 } | 446 } |
| 309 | 447 |
| 310 void WindowSelectorItem::RestoreWindow() { | 448 void WindowSelectorItem::RestoreWindow() { |
| 449 window_label_button_view_->ResetListener(); | |
| 450 close_button_->ResetListener(); | |
| 311 transform_window_.RestoreWindow(); | 451 transform_window_.RestoreWindow(); |
| 452 if (background_view_) | |
| 453 background_view_->OnItemRestored(); | |
| 454 UpdateHeaderLayout( | |
| 455 HeaderFadeInMode::EXIT, | |
| 456 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS); | |
| 457 } | |
| 458 | |
| 459 void WindowSelectorItem::Shutdown() { | |
| 460 if (transform_window_.GetTopInset()) { | |
| 461 WmWindow* label_window = | |
| 462 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | |
| 463 label_window->GetParent()->StackChildAbove(label_window, | |
| 464 transform_window_.window()); | |
| 465 } | |
| 466 FadeOut(std::move(window_label_)); | |
| 312 } | 467 } |
| 313 | 468 |
| 314 void WindowSelectorItem::ShowWindowOnExit() { | 469 void WindowSelectorItem::ShowWindowOnExit() { |
| 315 transform_window_.ShowWindowOnExit(); | 470 transform_window_.ShowWindowOnExit(); |
| 316 } | 471 } |
| 317 | 472 |
| 318 void WindowSelectorItem::PrepareForOverview() { | 473 void WindowSelectorItem::PrepareForOverview() { |
| 319 transform_window_.PrepareForOverview(); | 474 transform_window_.PrepareForOverview(); |
| 320 } | 475 } |
| 321 | 476 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 332 | 487 |
| 333 gfx::Rect inset_bounds(target_bounds); | 488 gfx::Rect inset_bounds(target_bounds); |
| 334 if (ash::MaterialDesignController::IsOverviewMaterial()) | 489 if (ash::MaterialDesignController::IsOverviewMaterial()) |
| 335 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | 490 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); |
| 336 else | 491 else |
| 337 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 492 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 338 SetItemBounds(inset_bounds, animation_type); | 493 SetItemBounds(inset_bounds, animation_type); |
| 339 | 494 |
| 340 // SetItemBounds is called before UpdateHeaderLayout so the header can | 495 // SetItemBounds is called before UpdateHeaderLayout so the header can |
| 341 // properly use the updated windows bounds. | 496 // properly use the updated windows bounds. |
| 342 UpdateHeaderLayout(animation_type); | 497 UpdateHeaderLayout(HeaderFadeInMode::UPDATE, animation_type); |
| 343 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 498 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
| 344 UpdateWindowLabel(target_bounds, animation_type); | 499 UpdateWindowLabel(target_bounds, animation_type); |
| 345 } | 500 } |
| 346 | 501 |
| 347 void WindowSelectorItem::SetSelected(bool selected) { | 502 void WindowSelectorItem::SetSelected(bool selected) { |
| 348 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 503 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
| 349 return; | 504 return; |
| 350 WmWindow* window = | 505 selected_ = selected; |
| 351 WmLookup::Get()->GetWindowForWidget(window_label_selector_.get()); | 506 background_view_->AnimateBackgroundOpacity(selected ? 0.f : 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 | 507 |
| 362 ui::ScopedLayerAnimationSettings animation_settings_shadow( | 508 if (shadow_) { |
| 363 shadow_->shadow_layer()->GetAnimator()); | 509 ui::ScopedLayerAnimationSettings animation_settings_shadow( |
| 364 animation_settings_shadow.SetTransitionDuration( | 510 shadow_->shadow_layer()->GetAnimator()); |
| 365 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); | 511 animation_settings_shadow.SetTransitionDuration( |
| 366 animation_settings_shadow.SetTweenType(selected | 512 base::TimeDelta::FromMilliseconds(kSelectorFadeInMilliseconds)); |
| 367 ? gfx::Tween::FAST_OUT_LINEAR_IN | 513 animation_settings_shadow.SetTweenType( |
| 368 : gfx::Tween::LINEAR_OUT_SLOW_IN); | 514 selected ? gfx::Tween::FAST_OUT_LINEAR_IN |
| 369 animation_settings_shadow.SetPreemptionStrategy( | 515 : gfx::Tween::LINEAR_OUT_SLOW_IN); |
| 370 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 516 animation_settings_shadow.SetPreemptionStrategy( |
| 371 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); | 517 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 518 shadow_->shadow_layer()->SetOpacity(selected ? 0.0f : 1.0f); | |
| 519 } | |
| 372 } | 520 } |
| 373 | 521 |
| 374 void WindowSelectorItem::RecomputeWindowTransforms() { | 522 void WindowSelectorItem::RecomputeWindowTransforms() { |
| 375 if (in_bounds_update_ || target_bounds_.IsEmpty()) | 523 if (in_bounds_update_ || target_bounds_.IsEmpty()) |
| 376 return; | 524 return; |
| 377 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 525 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
| 378 gfx::Rect inset_bounds(target_bounds_); | 526 gfx::Rect inset_bounds(target_bounds_); |
| 379 if (ash::MaterialDesignController::IsOverviewMaterial()) | 527 if (ash::MaterialDesignController::IsOverviewMaterial()) |
| 380 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); | 528 inset_bounds.Inset(kWindowMarginMD, kWindowMarginMD); |
| 381 else | 529 else |
| 382 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 530 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 383 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | 531 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
| 384 UpdateHeaderLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | 532 UpdateHeaderLayout(HeaderFadeInMode::UPDATE, |
| 533 OverviewAnimationType::OVERVIEW_ANIMATION_NONE); | |
| 385 } | 534 } |
| 386 | 535 |
| 387 void WindowSelectorItem::SendAccessibleSelectionEvent() { | 536 void WindowSelectorItem::SendAccessibleSelectionEvent() { |
| 388 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, | 537 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, |
| 389 true); | 538 true); |
| 390 } | 539 } |
| 391 | 540 |
| 392 void WindowSelectorItem::CloseWindow() { | 541 void WindowSelectorItem::CloseWindow() { |
| 393 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 542 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 394 gfx::Rect inset_bounds(target_bounds_); | 543 gfx::Rect inset_bounds(target_bounds_); |
| 395 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, | 544 inset_bounds.Inset(target_bounds_.width() * kPreCloseScale, |
| 396 target_bounds_.height() * kPreCloseScale); | 545 target_bounds_.height() * kPreCloseScale); |
| 397 OverviewAnimationType animation_type = | 546 OverviewAnimationType animation_type = |
| 398 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; | 547 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; |
| 399 // Scale down both the window and label. | 548 // Scale down both the window and label. |
| 400 SetBounds(inset_bounds, animation_type); | 549 SetBounds(inset_bounds, animation_type); |
| 401 // First animate opacity to an intermediate value concurrently with the | 550 // First animate opacity to an intermediate value concurrently with the |
| 402 // scaling animation. | 551 // scaling animation. |
| 403 AnimateOpacity(kClosingItemOpacity, animation_type); | 552 AnimateOpacity(kClosingItemOpacity, animation_type); |
| 404 | 553 |
| 405 // Fade out the window and the label, effectively hiding them. | 554 // Fade out the window and the label, effectively hiding them. |
| 406 AnimateOpacity( | 555 AnimateOpacity( |
| 407 0.0, OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); | 556 0.0, OverviewAnimationType::OVERVIEW_ANIMATION_CLOSE_SELECTOR_ITEM); |
| 408 } | 557 } |
| 409 transform_window_.Close(); | 558 transform_window_.Close(); |
| 410 } | 559 } |
| 411 | 560 |
| 561 void WindowSelectorItem::HideHeaderAndSetShape(int radius) { | |
| 562 transform_window_.HideHeaderAndSetShape(use_mask_, use_shape_, radius); | |
| 563 } | |
| 564 | |
| 412 void WindowSelectorItem::SetDimmed(bool dimmed) { | 565 void WindowSelectorItem::SetDimmed(bool dimmed) { |
| 413 dimmed_ = dimmed; | 566 dimmed_ = dimmed; |
| 414 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); | 567 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); |
| 415 } | 568 } |
| 416 | 569 |
| 417 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 570 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
| 418 const ui::Event& event) { | 571 const ui::Event& event) { |
| 419 if (sender == close_button_) { | 572 if (sender == close_button_) { |
| 420 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); | 573 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); |
| 421 CloseWindow(); | 574 CloseWindow(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 top_view_inset = transform_window_.GetTopInset(); | 619 top_view_inset = transform_window_.GetTopInset(); |
| 467 title_height = close_button_->GetPreferredSize().height(); | 620 title_height = close_button_->GetPreferredSize().height(); |
| 468 } | 621 } |
| 469 gfx::Rect selector_item_bounds = | 622 gfx::Rect selector_item_bounds = |
| 470 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 623 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
| 471 screen_rect, target_bounds, top_view_inset, title_height); | 624 screen_rect, target_bounds, top_view_inset, title_height); |
| 472 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( | 625 gfx::Transform transform = ScopedTransformOverviewWindow::GetTransformForRect( |
| 473 screen_rect, selector_item_bounds); | 626 screen_rect, selector_item_bounds); |
| 474 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 627 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 475 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 628 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 476 // Rounded corners are achieved by using a mask layer on the original window | 629 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); | 630 transform_window_.set_overview_transform(transform); |
| 483 } | 631 } |
| 484 | 632 |
| 485 void WindowSelectorItem::SetOpacity(float opacity) { | 633 void WindowSelectorItem::SetOpacity(float opacity) { |
| 486 window_label_->SetOpacity(opacity); | 634 window_label_->SetOpacity(opacity); |
| 635 if (background_view_) { | |
| 636 background_view_->AnimateBackgroundOpacity( | |
| 637 selected_ ? 0.f : kHeaderOpacity * opacity); | |
| 638 } | |
| 639 | |
| 487 if (!ash::MaterialDesignController::IsOverviewMaterial()) | 640 if (!ash::MaterialDesignController::IsOverviewMaterial()) |
| 488 close_button_widget_->SetOpacity(opacity); | 641 close_button_widget_->SetOpacity(opacity); |
| 489 | 642 |
| 490 transform_window_.SetOpacity(opacity); | 643 transform_window_.SetOpacity(opacity); |
| 491 } | 644 } |
| 492 | 645 |
| 493 void WindowSelectorItem::UpdateWindowLabel( | 646 void WindowSelectorItem::UpdateWindowLabel( |
| 494 const gfx::Rect& window_bounds, | 647 const gfx::Rect& window_bounds, |
| 495 OverviewAnimationType animation_type) { | 648 OverviewAnimationType animation_type) { |
| 496 if (!window_label_->IsVisible()) { | 649 if (!window_label_->IsVisible()) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 507 animation_type, | 660 animation_type, |
| 508 WmLookup::Get()->GetWindowForWidget(window_label_.get())); | 661 WmLookup::Get()->GetWindowForWidget(window_label_.get())); |
| 509 | 662 |
| 510 WmWindow* window_label_window = | 663 WmWindow* window_label_window = |
| 511 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 664 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
| 512 window_label_window->SetBounds(label_bounds); | 665 window_label_window->SetBounds(label_bounds); |
| 513 } | 666 } |
| 514 | 667 |
| 515 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { | 668 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
| 516 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); | 669 const bool material = ash::MaterialDesignController::IsOverviewMaterial(); |
| 517 window_label_.reset(new views::Widget); | 670 if (material) { |
| 518 views::Widget::InitParams params; | 671 background_view_ = new RoundedContainerView( |
| 519 params.type = views::Widget::InitParams::TYPE_POPUP; | 672 this, transform_window_.window(), kLabelBackgroundRadius, |
| 520 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 673 transform_window_.GetTopColor()); |
| 521 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 674 // |background_view_| will get added as a child to CaptionContainerView. |
| 522 params.visible_on_all_workspaces = true; | 675 } |
| 523 params.name = "OverviewModeLabel"; | 676 views::Widget::InitParams params_label; |
| 524 window_label_->set_focus_on_creation(false); | 677 params_label.type = views::Widget::InitParams::TYPE_POPUP; |
| 678 params_label.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 679 params_label.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 680 params_label.visible_on_all_workspaces = true; | |
| 681 params_label.name = "OverviewModeLabel"; | |
| 682 params_label.activatable = | |
| 683 views::Widget::InitParams::Activatable::ACTIVATABLE_DEFAULT; | |
| 684 params_label.accept_events = true; | |
| 525 root_window_->GetRootWindowController() | 685 root_window_->GetRootWindowController() |
| 526 ->ConfigureWidgetInitParamsForContainer( | 686 ->ConfigureWidgetInitParamsForContainer( |
| 527 window_label_.get(), kShellWindowId_StatusContainer, ¶ms); | 687 window_label_.get(), |
| 528 window_label_->Init(params); | 688 transform_window_.window()->GetParent()->GetShellWindowId(), |
| 689 ¶ms_label); | |
| 690 window_label_.reset(new views::Widget); | |
| 691 window_label_->set_focus_on_creation(false); | |
| 692 window_label_->Init(params_label); | |
| 529 window_label_button_view_ = new OverviewLabelButton(this, title); | 693 window_label_button_view_ = new OverviewLabelButton(this, title); |
| 530 window_label_button_view_->SetBorder(views::Border::NullBorder()); | 694 window_label_button_view_->SetBorder(views::Border::NullBorder()); |
| 531 window_label_button_view_->SetEnabledTextColors(kLabelColor); | 695 window_label_button_view_->SetEnabledTextColors(kLabelColor); |
| 532 window_label_button_view_->set_animate_on_state_change(false); | 696 window_label_button_view_->set_animate_on_state_change(false); |
| 533 if (material) { | 697 if (material) { |
| 698 WmWindow* label_window = | |
| 699 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | |
| 700 if (transform_window_.GetTopInset()) { | |
| 701 // For windows with headers the overview header fades in above the | |
| 702 // original window header. | |
| 703 label_window->GetParent()->StackChildAbove(label_window, | |
| 704 transform_window_.window()); | |
| 705 } else { | |
| 706 // For tabbed windows the overview header slides from behind. The stacking | |
| 707 // is then corrected when the animation completes. | |
| 708 label_window->GetParent()->StackChildBelow(label_window, | |
| 709 transform_window_.window()); | |
| 710 } | |
| 534 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 711 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 535 } else { | 712 } else { |
| 536 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 713 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 537 window_label_button_view_->SetTextShadows(gfx::ShadowValues( | 714 window_label_button_view_->SetTextShadows(gfx::ShadowValues( |
| 538 1, gfx::ShadowValue(gfx::Vector2d(0, kVerticalShadowOffset), | 715 1, gfx::ShadowValue(gfx::Vector2d(0, kVerticalShadowOffset), |
| 539 kShadowBlur, kLabelShadow))); | 716 kShadowBlur, kLabelShadow))); |
| 540 } | 717 } |
| 541 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 718 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 542 window_label_button_view_->SetFontList(bundle.GetFontList( | 719 window_label_button_view_->SetFontList(bundle.GetFontList( |
| 543 material ? ui::ResourceBundle::BaseFont : ui::ResourceBundle::BoldFont)); | 720 material ? ui::ResourceBundle::BaseFont : ui::ResourceBundle::BoldFont)); |
| 544 if (material) { | 721 if (material) { |
| 545 // Hint at the background color that the label will be drawn onto (for | 722 // Hint at the background color that the label will be drawn onto (for |
| 546 // subpixel antialiasing). Does not actually set the background color. | 723 // subpixel antialiasing). Does not actually set the background color. |
| 547 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); | 724 window_label_button_view_->SetBackgroundColorHint(kLabelBackgroundColor); |
| 548 caption_container_view_ = | 725 caption_container_view_ = new CaptionContainerView( |
| 549 new CaptionContainerView(window_label_button_view_, close_button_); | 726 window_label_button_view_, close_button_, background_view_); |
| 550 window_label_->SetContentsView(caption_container_view_); | 727 window_label_->SetContentsView(caption_container_view_); |
| 551 window_label_button_view_->SetVisible(false); | 728 window_label_button_view_->SetVisible(false); |
| 729 window_label_->SetOpacity(0); | |
| 552 window_label_->Show(); | 730 window_label_->Show(); |
| 553 | 731 |
| 554 shadow_.reset(new ::wm::Shadow()); | 732 // TODO(varkha): Restore shadows when programmatic shadows exist. |
| 555 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); | 733 // Note: current shadow implementation does not allow proper animation when |
| 556 shadow_->layer()->SetVisible(true); | 734 // the parent layer bounds change during the animation since |
| 557 window_label_->GetLayer()->Add(shadow_->layer()); | 735 // Shadow::UpdateLayerBounds() only happens before the animation starts. |
| 736 if (ash::MaterialDesignController::GetMode() == | |
| 737 ash::MaterialDesignController::Mode::MATERIAL_EXPERIMENTAL) { | |
| 738 shadow_.reset(new ::wm::Shadow()); | |
| 739 shadow_->Init(::wm::Shadow::STYLE_INACTIVE); | |
| 740 shadow_->layer()->SetVisible(true); | |
| 741 window_label_->GetLayer()->Add(shadow_->layer()); | |
| 742 } | |
| 558 window_label_->GetLayer()->SetMasksToBounds(false); | 743 window_label_->GetLayer()->SetMasksToBounds(false); |
| 559 | 744 UpdateHeaderLayout(HeaderFadeInMode::ENTER, |
| 560 views::View* background_view = | 745 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 { | 746 } else { |
| 571 // Indicate that the label will be drawn onto a transparent background | 747 // Indicate that the label will be drawn onto a transparent background |
| 572 // (disables subpixel antialiasing). | 748 // (disables subpixel antialiasing). |
| 573 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); | 749 window_label_button_view_->SetBackgroundColorHint(SK_ColorTRANSPARENT); |
| 574 window_label_->SetContentsView(window_label_button_view_); | 750 window_label_->SetContentsView(window_label_button_view_); |
| 575 } | 751 } |
| 576 } | 752 } |
| 577 | 753 |
| 578 void WindowSelectorItem::UpdateHeaderLayout( | 754 void WindowSelectorItem::UpdateHeaderLayout( |
| 755 HeaderFadeInMode mode, | |
| 579 OverviewAnimationType animation_type) { | 756 OverviewAnimationType animation_type) { |
| 580 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( | 757 gfx::Rect transformed_window_bounds = root_window_->ConvertRectFromScreen( |
| 581 transform_window_.GetTransformedBounds(hide_header())); | 758 transform_window_.GetTransformedBounds(hide_header())); |
| 582 | 759 |
| 583 if (ash::MaterialDesignController::IsOverviewMaterial()) { | 760 if (ash::MaterialDesignController::IsOverviewMaterial()) { |
| 584 gfx::Rect label_rect(close_button_->GetPreferredSize()); | 761 gfx::Rect label_rect(close_button_->GetPreferredSize()); |
| 585 label_rect.set_y(-label_rect.height()); | |
| 586 label_rect.set_width(transformed_window_bounds.width()); | 762 label_rect.set_width(transformed_window_bounds.width()); |
| 587 | 763 // For tabbed windows the initial bounds of the caption are set such that it |
| 764 // appears to be "growing" up from the window content area. | |
| 765 label_rect.set_y( | |
| 766 (mode != HeaderFadeInMode::ENTER || transform_window_.GetTopInset()) | |
| 767 ? -label_rect.height() | |
| 768 : 0); | |
| 769 if (background_view_) { | |
| 770 if (mode == HeaderFadeInMode::ENTER) { | |
| 771 background_view_->ObserveLayerAnimations(window_label_->GetLayer()); | |
| 772 background_view_->set_color(kLabelBackgroundColor); | |
| 773 // The color will be animated only once the label widget is faded in. | |
| 774 } else if (mode == HeaderFadeInMode::EXIT) { | |
| 775 // Make the header visible above the window. It will be faded out when | |
| 776 // the Shutdown() is called. | |
| 777 background_view_->AnimateColor(gfx::Tween::EASE_OUT, | |
| 778 kExitFadeInMilliseconds); | |
| 779 background_view_->set_color(kLabelExitColor); | |
| 780 } | |
| 781 } | |
| 588 if (!window_label_button_view_->visible()) { | 782 if (!window_label_button_view_->visible()) { |
| 589 window_label_button_view_->SetVisible(true); | 783 window_label_button_view_->SetVisible(true); |
| 590 SetupFadeInAfterLayout(window_label_.get()); | 784 SetupFadeInAfterLayout(window_label_.get()); |
| 591 SetupFadeInAfterLayout(window_label_selector_.get()); | |
| 592 } | 785 } |
| 593 WmWindow* window_label_window = | 786 WmWindow* window_label_window = |
| 594 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 787 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 = | 788 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 598 ScopedOverviewAnimationSettingsFactory::Get() | 789 ScopedOverviewAnimationSettingsFactory::Get() |
| 599 ->CreateOverviewAnimationSettings(animation_type, | 790 ->CreateOverviewAnimationSettings(animation_type, |
| 600 window_label_window); | 791 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 | 792 // |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 | 793 // as well as the gap between the windows to prevent events from reaching |
| 609 // the window including its sizing borders. | 794 // the window including its sizing borders. |
| 610 label_rect.set_height(label_rect.height() + | 795 if (mode != HeaderFadeInMode::ENTER) { |
| 611 transformed_window_bounds.height()); | 796 label_rect.set_height(close_button_->GetPreferredSize().height() + |
| 612 gfx::Rect shadow_bounds(label_rect.size()); | 797 transformed_window_bounds.height()); |
| 798 } | |
| 613 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); | 799 label_rect.Inset(-kWindowSelectorMargin, -kWindowSelectorMargin); |
| 614 window_label_window->SetBounds(label_rect); | 800 window_label_window->SetBounds(label_rect); |
| 615 gfx::Transform label_transform; | 801 gfx::Transform label_transform; |
| 616 label_transform.Translate(transformed_window_bounds.x(), | 802 label_transform.Translate(transformed_window_bounds.x(), |
| 617 transformed_window_bounds.y()); | 803 transformed_window_bounds.y()); |
| 618 window_label_window->SetTransform(label_transform); | 804 window_label_window->SetTransform(label_transform); |
| 619 window_label_selector_window->SetTransform(label_transform); | |
| 620 | 805 |
| 621 shadow_bounds.Offset(kWindowSelectorMargin, kWindowSelectorMargin); | 806 gfx::Rect shadow_bounds(label_rect.size()); |
| 622 shadow_->SetContentBounds(shadow_bounds); | 807 shadow_bounds.Inset(kWindowSelectorMargin, kWindowSelectorMargin); |
| 808 if (shadow_) | |
| 809 shadow_->SetContentBounds(shadow_bounds); | |
| 623 } else { | 810 } else { |
| 624 if (!close_button_->visible()) { | 811 if (!close_button_->visible()) { |
| 625 close_button_->SetVisible(true); | 812 close_button_->SetVisible(true); |
| 626 SetupFadeInAfterLayout(close_button_widget_.get()); | 813 SetupFadeInAfterLayout(close_button_widget_.get()); |
| 627 } | 814 } |
| 628 WmWindow* close_button_widget_window = | 815 WmWindow* close_button_widget_window = |
| 629 WmLookup::Get()->GetWindowForWidget(close_button_widget_.get()); | 816 WmLookup::Get()->GetWindowForWidget(close_button_widget_.get()); |
| 630 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | 817 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = |
| 631 ScopedOverviewAnimationSettingsFactory::Get() | 818 ScopedOverviewAnimationSettingsFactory::Get() |
| 632 ->CreateOverviewAnimationSettings(animation_type, | 819 ->CreateOverviewAnimationSettings(animation_type, |
| 633 close_button_widget_window); | 820 close_button_widget_window); |
| 634 | 821 |
| 635 gfx::Transform close_button_transform; | 822 gfx::Transform close_button_transform; |
| 636 close_button_transform.Translate(transformed_window_bounds.right(), | 823 close_button_transform.Translate(transformed_window_bounds.right(), |
| 637 transformed_window_bounds.y()); | 824 transformed_window_bounds.y()); |
| 638 close_button_widget_window->SetTransform(close_button_transform); | 825 close_button_widget_window->SetTransform(close_button_transform); |
| 639 } | 826 } |
| 640 } | 827 } |
| 641 | 828 |
| 642 void WindowSelectorItem::AnimateOpacity(float opacity, | 829 void WindowSelectorItem::AnimateOpacity(float opacity, |
| 643 OverviewAnimationType animation_type) { | 830 OverviewAnimationType animation_type) { |
| 644 DCHECK_GE(opacity, 0.f); | 831 DCHECK_GE(opacity, 0.f); |
| 645 DCHECK_LE(opacity, 1.f); | 832 DCHECK_LE(opacity, 1.f); |
| 646 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; | 833 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; |
| 647 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); | 834 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| 648 transform_window_.SetOpacity(opacity); | 835 transform_window_.SetOpacity(opacity); |
| 649 | 836 |
| 837 const float header_opacity = selected_ ? 0.f : kHeaderOpacity * opacity; | |
| 650 WmWindow* window_label_window = | 838 WmWindow* window_label_window = |
| 651 WmLookup::Get()->GetWindowForWidget(window_label_.get()); | 839 WmLookup::Get()->GetWindowForWidget(window_label_.get()); |
| 652 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = | 840 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings_label = |
| 653 ScopedOverviewAnimationSettingsFactory::Get() | 841 ScopedOverviewAnimationSettingsFactory::Get() |
| 654 ->CreateOverviewAnimationSettings(animation_type, | 842 ->CreateOverviewAnimationSettings(animation_type, |
| 655 window_label_window); | 843 window_label_window); |
| 656 window_label_window->SetOpacity(opacity); | 844 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 } | 845 } |
| 666 | 846 |
| 667 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { | 847 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { |
| 668 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( | 848 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( |
| 669 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, | 849 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, |
| 670 GetWindow()->GetTitle())); | 850 GetWindow()->GetTitle())); |
| 671 } | 851 } |
| 672 | 852 |
| 853 void WindowSelectorItem::FadeOut(std::unique_ptr<views::Widget> widget) { | |
| 854 widget->SetOpacity(1.f); | |
| 855 | |
| 856 // Fade out the widget. This animation continues past the lifetime of |this|. | |
| 857 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | |
| 858 std::unique_ptr<ScopedOverviewAnimationSettings> animation_settings = | |
| 859 ScopedOverviewAnimationSettingsFactory::Get() | |
| 860 ->CreateOverviewAnimationSettings( | |
| 861 OverviewAnimationType:: | |
| 862 OVERVIEW_ANIMATION_EXIT_OVERVIEW_MODE_FADE_OUT, | |
| 863 widget_window); | |
| 864 // CleanupAnimationObserver will delete itself (and the widget) when the | |
| 865 // opacity animation is complete. | |
| 866 // Ownership over the observer is passed to the window_selector_->delegate() | |
| 867 // which has longer lifetime so that animations can continue even after the | |
| 868 // overview mode is shut down. | |
| 869 views::Widget* widget_ptr = widget.get(); | |
| 870 std::unique_ptr<CleanupAnimationObserver> observer( | |
| 871 new CleanupAnimationObserver(std::move(widget))); | |
| 872 animation_settings->AddObserver(observer.get()); | |
| 873 window_selector_->delegate()->AddDelayedAnimationObserver( | |
| 874 std::move(observer)); | |
| 875 widget_ptr->SetOpacity(0.f); | |
| 876 } | |
| 877 | |
| 673 } // namespace ash | 878 } // namespace ash |
| OLD | NEW |