| 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/frame/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "ash/frame/caption_buttons/frame_caption_button.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button.h" |
| 11 #include "ash/frame/caption_buttons/frame_size_button.h" | 11 #include "ash/frame/caption_buttons/frame_size_button.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_port.h" | 13 #include "ash/shell_port.h" |
| 14 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 14 #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
| 15 #include "ui/base/hit_test.h" | 15 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 18 #include "ui/gfx/animation/slide_animation.h" | 18 #include "ui/gfx/animation/slide_animation.h" |
| 19 #include "ui/gfx/animation/tween.h" | 19 #include "ui/gfx/animation/tween.h" |
| 20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/geometry/insets.h" | 21 #include "ui/gfx/geometry/insets.h" |
| 22 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 23 #include "ui/gfx/vector_icon_types.h" | 23 #include "ui/gfx/vector_icon_types.h" |
| 24 #include "ui/strings/grit/ui_strings.h" // Accessibility names | 24 #include "ui/strings/grit/ui_strings.h" // Accessibility names |
| 25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
| 27 | 27 |
| 28 namespace ash { | 28 namespace ash { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Duration of the animation of the position of |minimize_button_|. | 32 // Duration of the animation of the position of |minimize_button_|. |
| 33 const int kPositionAnimationDurationMs = 500; | 33 const int kPositionAnimationDurationMs = 500; |
| 34 | 34 |
| 35 // Duration of the animation of the alpha of |size_button_|. | 35 // Duration of the animation of the alpha of |size_button_|. |
| 36 const int kAlphaAnimationDurationMs = 250; | 36 const int kAlphaAnimationDurationMs = 250; |
| 37 | 37 |
| 38 // Delay during |maximize_mode_animation_| hide to wait before beginning to | 38 // Delay during |tablet_mode_animation_| hide to wait before beginning to |
| 39 // animate the position of |minimize_button_|. | 39 // animate the position of |minimize_button_|. |
| 40 const int kHidePositionDelayMs = 100; | 40 const int kHidePositionDelayMs = 100; |
| 41 | 41 |
| 42 // Duration of |maximize_mode_animation_| hiding. | 42 // Duration of |tablet_mode_animation_| hiding. |
| 43 // Hiding size button 250 | 43 // Hiding size button 250 |
| 44 // |------------------------| | 44 // |------------------------| |
| 45 // Delay 100 Slide minimize button 500 | 45 // Delay 100 Slide minimize button 500 |
| 46 // |---------|-------------------------------------------------| | 46 // |---------|-------------------------------------------------| |
| 47 const int kHideAnimationDurationMs = | 47 const int kHideAnimationDurationMs = |
| 48 kHidePositionDelayMs + kPositionAnimationDurationMs; | 48 kHidePositionDelayMs + kPositionAnimationDurationMs; |
| 49 | 49 |
| 50 // Delay during |maximize_mode_animation_| show to wait before beginning to | 50 // Delay during |tablet_mode_animation_| show to wait before beginning to |
| 51 // animate the alpha of |size_button_|. | 51 // animate the alpha of |size_button_|. |
| 52 const int kShowAnimationAlphaDelayMs = 100; | 52 const int kShowAnimationAlphaDelayMs = 100; |
| 53 | 53 |
| 54 // Duration of |maximize_mode_animation_| showing. | 54 // Duration of |tablet_mode_animation_| showing. |
| 55 // Slide minimize button 500 | 55 // Slide minimize button 500 |
| 56 // |-------------------------------------------------| | 56 // |-------------------------------------------------| |
| 57 // Delay 100 Show size button 250 | 57 // Delay 100 Show size button 250 |
| 58 // |---------|-----------------------| | 58 // |---------|-----------------------| |
| 59 const int kShowAnimationDurationMs = kPositionAnimationDurationMs; | 59 const int kShowAnimationDurationMs = kPositionAnimationDurationMs; |
| 60 | 60 |
| 61 // Value of |maximize_mode_animation_| showing to begin animating alpha of | 61 // Value of |tablet_mode_animation_| showing to begin animating alpha of |
| 62 // |size_button_|. | 62 // |size_button_|. |
| 63 float SizeButtonShowStartValue() { | 63 float SizeButtonShowStartValue() { |
| 64 return static_cast<float>(kShowAnimationAlphaDelayMs) / | 64 return static_cast<float>(kShowAnimationAlphaDelayMs) / |
| 65 kShowAnimationDurationMs; | 65 kShowAnimationDurationMs; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Amount of |maximize_mode_animation_| showing to animate the alpha of | 68 // Amount of |tablet_mode_animation_| showing to animate the alpha of |
| 69 // |size_button_|. | 69 // |size_button_|. |
| 70 float SizeButtonShowDuration() { | 70 float SizeButtonShowDuration() { |
| 71 return static_cast<float>(kAlphaAnimationDurationMs) / | 71 return static_cast<float>(kAlphaAnimationDurationMs) / |
| 72 kShowAnimationDurationMs; | 72 kShowAnimationDurationMs; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Amount of |maximize_mode_animation_| hiding to animate the alpha of | 75 // Amount of |tablet_mode_animation_| hiding to animate the alpha of |
| 76 // |size_button_|. | 76 // |size_button_|. |
| 77 float SizeButtonHideDuration() { | 77 float SizeButtonHideDuration() { |
| 78 return static_cast<float>(kAlphaAnimationDurationMs) / | 78 return static_cast<float>(kAlphaAnimationDurationMs) / |
| 79 kHideAnimationDurationMs; | 79 kHideAnimationDurationMs; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Value of |maximize_mode_animation_| hiding to begin animating the position of | 82 // Value of |tablet_mode_animation_| hiding to begin animating the position of |
| 83 // |minimize_button_|. | 83 // |minimize_button_|. |
| 84 float HidePositionStartValue() { | 84 float HidePositionStartValue() { |
| 85 return 1.0f - | 85 return 1.0f - |
| 86 static_cast<float>(kHidePositionDelayMs) / kHideAnimationDurationMs; | 86 static_cast<float>(kHidePositionDelayMs) / kHideAnimationDurationMs; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Converts |point| from |src| to |dst| and hittests against |dst|. | 89 // Converts |point| from |src| to |dst| and hittests against |dst|. |
| 90 bool ConvertPointToViewAndHitTest(const views::View* src, | 90 bool ConvertPointToViewAndHitTest(const views::View* src, |
| 91 const views::View* dst, | 91 const views::View* dst, |
| 92 const gfx::Point& point) { | 92 const gfx::Point& point) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 const char FrameCaptionButtonContainerView::kViewClassName[] = | 108 const char FrameCaptionButtonContainerView::kViewClassName[] = |
| 109 "FrameCaptionButtonContainerView"; | 109 "FrameCaptionButtonContainerView"; |
| 110 | 110 |
| 111 FrameCaptionButtonContainerView::FrameCaptionButtonContainerView( | 111 FrameCaptionButtonContainerView::FrameCaptionButtonContainerView( |
| 112 views::Widget* frame) | 112 views::Widget* frame) |
| 113 : frame_(frame), | 113 : frame_(frame), |
| 114 minimize_button_(NULL), | 114 minimize_button_(NULL), |
| 115 size_button_(NULL), | 115 size_button_(NULL), |
| 116 close_button_(NULL) { | 116 close_button_(NULL) { |
| 117 bool size_button_visibility = ShouldSizeButtonBeVisible(); | 117 bool size_button_visibility = ShouldSizeButtonBeVisible(); |
| 118 maximize_mode_animation_.reset(new gfx::SlideAnimation(this)); | 118 tablet_mode_animation_.reset(new gfx::SlideAnimation(this)); |
| 119 maximize_mode_animation_->SetTweenType(gfx::Tween::LINEAR); | 119 tablet_mode_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 120 | 120 |
| 121 // Ensure animation tracks visibility of size button. | 121 // Ensure animation tracks visibility of size button. |
| 122 if (size_button_visibility) | 122 if (size_button_visibility) |
| 123 maximize_mode_animation_->Reset(1.0f); | 123 tablet_mode_animation_->Reset(1.0f); |
| 124 | 124 |
| 125 // Insert the buttons left to right. | 125 // Insert the buttons left to right. |
| 126 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); | 126 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); |
| 127 minimize_button_->SetAccessibleName( | 127 minimize_button_->SetAccessibleName( |
| 128 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 128 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 129 minimize_button_->SetVisible(frame_->widget_delegate()->CanMinimize()); | 129 minimize_button_->SetVisible(frame_->widget_delegate()->CanMinimize()); |
| 130 AddChildView(minimize_button_); | 130 AddChildView(minimize_button_); |
| 131 | 131 |
| 132 size_button_ = new FrameSizeButton(this, frame, this); | 132 size_button_ = new FrameSizeButton(this, frame, this); |
| 133 size_button_->SetAccessibleName( | 133 size_button_->SetAccessibleName( |
| 134 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); | 134 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); |
| 135 size_button_->SetVisible(size_button_visibility); | 135 size_button_->SetVisible(size_button_visibility); |
| 136 AddChildView(size_button_); | 136 AddChildView(size_button_); |
| 137 | 137 |
| 138 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); | 138 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); |
| 139 close_button_->SetAccessibleName( | 139 close_button_->SetAccessibleName( |
| 140 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 140 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 141 AddChildView(close_button_); | 141 AddChildView(close_button_); |
| 142 } | 142 } |
| 143 | 143 |
| 144 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {} | 144 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {} |
| 145 | 145 |
| 146 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { | 146 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { |
| 147 container_view_->maximize_mode_animation_->End(); | 147 container_view_->tablet_mode_animation_->End(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void FrameCaptionButtonContainerView::SetButtonImage( | 150 void FrameCaptionButtonContainerView::SetButtonImage( |
| 151 CaptionButtonIcon icon, | 151 CaptionButtonIcon icon, |
| 152 const gfx::VectorIcon& icon_definition) { | 152 const gfx::VectorIcon& icon_definition) { |
| 153 button_icon_map_[icon] = &icon_definition; | 153 button_icon_map_[icon] = &icon_definition; |
| 154 | 154 |
| 155 FrameCaptionButton* buttons[] = {minimize_button_, size_button_, | 155 FrameCaptionButton* buttons[] = {minimize_button_, size_button_, |
| 156 close_button_}; | 156 close_button_}; |
| 157 for (size_t i = 0; i < arraysize(buttons); ++i) { | 157 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 ConvertPointToViewAndHitTest(this, minimize_button_, point)) { | 189 ConvertPointToViewAndHitTest(this, minimize_button_, point)) { |
| 190 return HTMINBUTTON; | 190 return HTMINBUTTON; |
| 191 } | 191 } |
| 192 return HTNOWHERE; | 192 return HTNOWHERE; |
| 193 } | 193 } |
| 194 | 194 |
| 195 void FrameCaptionButtonContainerView::UpdateSizeButtonVisibility() { | 195 void FrameCaptionButtonContainerView::UpdateSizeButtonVisibility() { |
| 196 bool visible = ShouldSizeButtonBeVisible(); | 196 bool visible = ShouldSizeButtonBeVisible(); |
| 197 if (visible) { | 197 if (visible) { |
| 198 size_button_->SetVisible(true); | 198 size_button_->SetVisible(true); |
| 199 maximize_mode_animation_->SetSlideDuration(kShowAnimationDurationMs); | 199 tablet_mode_animation_->SetSlideDuration(kShowAnimationDurationMs); |
| 200 maximize_mode_animation_->Show(); | 200 tablet_mode_animation_->Show(); |
| 201 } else { | 201 } else { |
| 202 maximize_mode_animation_->SetSlideDuration(kHideAnimationDurationMs); | 202 tablet_mode_animation_->SetSlideDuration(kHideAnimationDurationMs); |
| 203 maximize_mode_animation_->Hide(); | 203 tablet_mode_animation_->Hide(); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 void FrameCaptionButtonContainerView::SetButtonSize(const gfx::Size& size) { | 207 void FrameCaptionButtonContainerView::SetButtonSize(const gfx::Size& size) { |
| 208 minimize_button_->set_preferred_size(size); | 208 minimize_button_->set_preferred_size(size); |
| 209 size_button_->set_preferred_size(size); | 209 size_button_->set_preferred_size(size); |
| 210 close_button_->set_preferred_size(size); | 210 close_button_->set_preferred_size(size); |
| 211 } | 211 } |
| 212 | 212 |
| 213 gfx::Size FrameCaptionButtonContainerView::CalculatePreferredSize() const { | 213 gfx::Size FrameCaptionButtonContainerView::CalculatePreferredSize() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 224 int x = 0; | 224 int x = 0; |
| 225 for (int i = 0; i < child_count(); ++i) { | 225 for (int i = 0; i < child_count(); ++i) { |
| 226 views::View* child = child_at(i); | 226 views::View* child = child_at(i); |
| 227 if (!child->visible()) | 227 if (!child->visible()) |
| 228 continue; | 228 continue; |
| 229 | 229 |
| 230 gfx::Size size = child->GetPreferredSize(); | 230 gfx::Size size = child->GetPreferredSize(); |
| 231 child->SetBounds(x, 0, size.width(), size.height()); | 231 child->SetBounds(x, 0, size.width(), size.height()); |
| 232 x += size.width(); | 232 x += size.width(); |
| 233 } | 233 } |
| 234 if (maximize_mode_animation_->is_animating()) { | 234 if (tablet_mode_animation_->is_animating()) { |
| 235 AnimationProgressed(maximize_mode_animation_.get()); | 235 AnimationProgressed(tablet_mode_animation_.get()); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 const char* FrameCaptionButtonContainerView::GetClassName() const { | 239 const char* FrameCaptionButtonContainerView::GetClassName() const { |
| 240 return kViewClassName; | 240 return kViewClassName; |
| 241 } | 241 } |
| 242 | 242 |
| 243 void FrameCaptionButtonContainerView::AnimationEnded( | 243 void FrameCaptionButtonContainerView::AnimationEnded( |
| 244 const gfx::Animation* animation) { | 244 const gfx::Animation* animation) { |
| 245 // Ensure that position is calculated at least once. | 245 // Ensure that position is calculated at least once. |
| 246 AnimationProgressed(animation); | 246 AnimationProgressed(animation); |
| 247 | 247 |
| 248 double current_value = maximize_mode_animation_->GetCurrentValue(); | 248 double current_value = tablet_mode_animation_->GetCurrentValue(); |
| 249 if (current_value == 0.0) { | 249 if (current_value == 0.0) { |
| 250 size_button_->SetVisible(false); | 250 size_button_->SetVisible(false); |
| 251 PreferredSizeChanged(); | 251 PreferredSizeChanged(); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 void FrameCaptionButtonContainerView::AnimationProgressed( | 255 void FrameCaptionButtonContainerView::AnimationProgressed( |
| 256 const gfx::Animation* animation) { | 256 const gfx::Animation* animation) { |
| 257 double current_value = animation->GetCurrentValue(); | 257 double current_value = animation->GetCurrentValue(); |
| 258 int size_alpha = 0; | 258 int size_alpha = 0; |
| 259 int minimize_x = 0; | 259 int minimize_x = 0; |
| 260 if (maximize_mode_animation_->IsShowing()) { | 260 if (tablet_mode_animation_->IsShowing()) { |
| 261 double scaled_value = | 261 double scaled_value = |
| 262 CapAnimationValue((current_value - SizeButtonShowStartValue()) / | 262 CapAnimationValue((current_value - SizeButtonShowStartValue()) / |
| 263 SizeButtonShowDuration()); | 263 SizeButtonShowDuration()); |
| 264 double tweened_value_alpha = | 264 double tweened_value_alpha = |
| 265 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value); | 265 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value); |
| 266 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255); | 266 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255); |
| 267 | 267 |
| 268 double tweened_value_slide = | 268 double tweened_value_slide = |
| 269 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value); | 269 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value); |
| 270 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide, | 270 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 301 FrameCaptionButton::Animate fcb_animate = | 301 FrameCaptionButton::Animate fcb_animate = |
| 302 (animate == ANIMATE_YES) ? FrameCaptionButton::ANIMATE_YES | 302 (animate == ANIMATE_YES) ? FrameCaptionButton::ANIMATE_YES |
| 303 : FrameCaptionButton::ANIMATE_NO; | 303 : FrameCaptionButton::ANIMATE_NO; |
| 304 auto it = button_icon_map_.find(icon); | 304 auto it = button_icon_map_.find(icon); |
| 305 if (it != button_icon_map_.end()) | 305 if (it != button_icon_map_.end()) |
| 306 button->SetImage(icon, fcb_animate, *it->second); | 306 button->SetImage(icon, fcb_animate, *it->second); |
| 307 } | 307 } |
| 308 | 308 |
| 309 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { | 309 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { |
| 310 return !Shell::Get() | 310 return !Shell::Get() |
| 311 ->maximize_mode_controller() | 311 ->tablet_mode_controller() |
| 312 ->IsMaximizeModeWindowManagerEnabled() && | 312 ->IsTabletModeWindowManagerEnabled() && |
| 313 frame_->widget_delegate()->CanMaximize(); | 313 frame_->widget_delegate()->CanMaximize(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, | 316 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, |
| 317 const ui::Event& event) { | 317 const ui::Event& event) { |
| 318 // Abort any animations of the button icons. | 318 // Abort any animations of the button icons. |
| 319 SetButtonsToNormal(ANIMATE_NO); | 319 SetButtonsToNormal(ANIMATE_NO); |
| 320 | 320 |
| 321 UserMetricsAction action = UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; | 321 UserMetricsAction action = UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; |
| 322 if (sender == minimize_button_) { | 322 if (sender == minimize_button_) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; | 404 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; |
| 405 if (button == to_hover) | 405 if (button == to_hover) |
| 406 new_state = views::Button::STATE_HOVERED; | 406 new_state = views::Button::STATE_HOVERED; |
| 407 else if (button == to_press) | 407 else if (button == to_press) |
| 408 new_state = views::Button::STATE_PRESSED; | 408 new_state = views::Button::STATE_PRESSED; |
| 409 button->SetState(new_state); | 409 button->SetState(new_state); |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 } // namespace ash | 413 } // namespace ash |
| OLD | NEW |