| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/wm/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/ash_switches.h" | 10 #include "mash/wm/frame/caption_buttons/frame_caption_button.h" |
| 11 #include "ash/frame/caption_buttons/frame_caption_button.h" | |
| 12 #include "ash/frame/caption_buttons/frame_size_button.h" | |
| 13 #include "ash/metrics/user_metrics_recorder.h" | |
| 14 #include "ash/shell.h" | |
| 15 #include "ash/touch/touch_uma.h" | |
| 16 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
| 17 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 20 #include "ui/gfx/animation/slide_animation.h" | 13 #include "ui/gfx/animation/slide_animation.h" |
| 21 #include "ui/gfx/animation/tween.h" | 14 #include "ui/gfx/animation/tween.h" |
| 22 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/geometry/insets.h" | 16 #include "ui/gfx/geometry/insets.h" |
| 24 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
| 25 #include "ui/strings/grit/ui_strings.h" // Accessibility names | 18 #include "ui/strings/grit/ui_strings.h" // Accessibility names |
| 26 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/widget/widget_delegate.h" | 20 #include "ui/views/widget/widget_delegate.h" |
| 28 | 21 |
| 29 namespace ash { | 22 namespace mash { |
| 23 namespace wm { |
| 30 | 24 |
| 31 namespace { | 25 namespace { |
| 32 | 26 |
| 33 // Duration of the animation of the position of |minimize_button_|. | 27 // Duration of the animation of the position of |minimize_button_|. |
| 34 const int kPositionAnimationDurationMs = 500; | 28 const int kPositionAnimationDurationMs = 500; |
| 35 | 29 |
| 36 // Duration of the animation of the alpha of |size_button_|. | 30 // Duration of the animation of the alpha of |size_button_|. |
| 37 const int kAlphaAnimationDurationMs = 250; | 31 const int kAlphaAnimationDurationMs = 250; |
| 38 | 32 |
| 39 // Delay during |maximize_mode_animation_| hide to wait before beginning to | 33 // Delay during |maximize_mode_animation_| hide to wait before beginning to |
| (...skipping 15 matching lines...) Expand all Loading... |
| 55 // Duration of |maximize_mode_animation_| showing. | 49 // Duration of |maximize_mode_animation_| showing. |
| 56 // Slide minimize button 500 | 50 // Slide minimize button 500 |
| 57 // |-------------------------------------------------| | 51 // |-------------------------------------------------| |
| 58 // Delay 100 Show size button 250 | 52 // Delay 100 Show size button 250 |
| 59 // |---------|-----------------------| | 53 // |---------|-----------------------| |
| 60 const int kShowAnimationDurationMs = kPositionAnimationDurationMs; | 54 const int kShowAnimationDurationMs = kPositionAnimationDurationMs; |
| 61 | 55 |
| 62 // Value of |maximize_mode_animation_| showing to begin animating alpha of | 56 // Value of |maximize_mode_animation_| showing to begin animating alpha of |
| 63 // |size_button_|. | 57 // |size_button_|. |
| 64 float SizeButtonShowStartValue() { | 58 float SizeButtonShowStartValue() { |
| 65 return static_cast<float>(kShowAnimationAlphaDelayMs) | 59 return static_cast<float>(kShowAnimationAlphaDelayMs) / |
| 66 / kShowAnimationDurationMs; | 60 kShowAnimationDurationMs; |
| 67 } | 61 } |
| 68 | 62 |
| 69 // Amount of |maximize_mode_animation_| showing to animate the alpha of | 63 // Amount of |maximize_mode_animation_| showing to animate the alpha of |
| 70 // |size_button_|. | 64 // |size_button_|. |
| 71 float SizeButtonShowDuration() { | 65 float SizeButtonShowDuration() { |
| 72 return static_cast<float>(kAlphaAnimationDurationMs) | 66 return static_cast<float>(kAlphaAnimationDurationMs) / |
| 73 / kShowAnimationDurationMs; | 67 kShowAnimationDurationMs; |
| 74 } | 68 } |
| 75 | 69 |
| 76 // Amount of |maximize_mode_animation_| hiding to animate the alpha of | 70 // Amount of |maximize_mode_animation_| hiding to animate the alpha of |
| 77 // |size_button_|. | 71 // |size_button_|. |
| 78 float SizeButtonHideDuration() { | 72 float SizeButtonHideDuration() { |
| 79 return static_cast<float>(kAlphaAnimationDurationMs) | 73 return static_cast<float>(kAlphaAnimationDurationMs) / |
| 80 / kHideAnimationDurationMs; | 74 kHideAnimationDurationMs; |
| 81 } | 75 } |
| 82 | 76 |
| 83 // Value of |maximize_mode_animation_| hiding to begin animating the position of | 77 // Value of |maximize_mode_animation_| hiding to begin animating the position of |
| 84 // |minimize_button_|. | 78 // |minimize_button_|. |
| 85 float HidePositionStartValue() { | 79 float HidePositionStartValue() { |
| 86 return 1.0f - static_cast<float>(kHidePositionDelayMs) | 80 return 1.0f - |
| 87 / kHideAnimationDurationMs; | 81 static_cast<float>(kHidePositionDelayMs) / kHideAnimationDurationMs; |
| 88 } | 82 } |
| 89 | 83 |
| 90 // Converts |point| from |src| to |dst| and hittests against |dst|. | 84 // Converts |point| from |src| to |dst| and hittests against |dst|. |
| 91 bool ConvertPointToViewAndHitTest(const views::View* src, | 85 bool ConvertPointToViewAndHitTest(const views::View* src, |
| 92 const views::View* dst, | 86 const views::View* dst, |
| 93 const gfx::Point& point) { | 87 const gfx::Point& point) { |
| 94 gfx::Point converted(point); | 88 gfx::Point converted(point); |
| 95 views::View::ConvertPointToTarget(src, dst, &converted); | 89 views::View::ConvertPointToTarget(src, dst, &converted); |
| 96 return dst->HitTestPoint(converted); | 90 return dst->HitTestPoint(converted); |
| 97 } | 91 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 108 // static | 102 // static |
| 109 const char FrameCaptionButtonContainerView::kViewClassName[] = | 103 const char FrameCaptionButtonContainerView::kViewClassName[] = |
| 110 "FrameCaptionButtonContainerView"; | 104 "FrameCaptionButtonContainerView"; |
| 111 | 105 |
| 112 FrameCaptionButtonContainerView::FrameCaptionButtonContainerView( | 106 FrameCaptionButtonContainerView::FrameCaptionButtonContainerView( |
| 113 views::Widget* frame) | 107 views::Widget* frame) |
| 114 : frame_(frame), | 108 : frame_(frame), |
| 115 minimize_button_(NULL), | 109 minimize_button_(NULL), |
| 116 size_button_(NULL), | 110 size_button_(NULL), |
| 117 close_button_(NULL) { | 111 close_button_(NULL) { |
| 118 bool size_button_visibility = ShouldSizeButtonBeVisible(); | 112 const bool size_button_visibility = ShouldSizeButtonBeVisible(); |
| 119 maximize_mode_animation_.reset(new gfx::SlideAnimation(this)); | 113 maximize_mode_animation_.reset(new gfx::SlideAnimation(this)); |
| 120 maximize_mode_animation_->SetTweenType(gfx::Tween::LINEAR); | 114 maximize_mode_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 121 | 115 |
| 122 // Ensure animation tracks visibility of size button. | 116 // Ensure animation tracks visibility of size button. |
| 123 if (size_button_visibility) | 117 if (size_button_visibility) |
| 124 maximize_mode_animation_->Reset(1.0f); | 118 maximize_mode_animation_->Reset(1.0f); |
| 125 | 119 |
| 126 // Insert the buttons left to right. | 120 // Insert the buttons left to right. |
| 127 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); | 121 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); |
| 128 minimize_button_->SetAccessibleName( | 122 minimize_button_->SetAccessibleName( |
| 129 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 123 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 130 minimize_button_->SetVisible(frame_->widget_delegate()->CanMinimize()); | 124 minimize_button_->SetVisible(frame_->widget_delegate()->CanMinimize()); |
| 131 AddChildView(minimize_button_); | 125 AddChildView(minimize_button_); |
| 132 | 126 |
| 133 size_button_ = new FrameSizeButton(this, frame, this); | 127 size_button_ = |
| 128 new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE); |
| 134 size_button_->SetAccessibleName( | 129 size_button_->SetAccessibleName( |
| 135 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); | 130 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); |
| 136 size_button_->SetVisible(size_button_visibility); | 131 size_button_->SetVisible(size_button_visibility); |
| 137 AddChildView(size_button_); | 132 AddChildView(size_button_); |
| 138 | 133 |
| 139 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); | 134 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); |
| 140 close_button_->SetAccessibleName( | 135 close_button_->SetAccessibleName( |
| 141 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 136 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 142 AddChildView(close_button_); | 137 AddChildView(close_button_); |
| 143 } | 138 } |
| 144 | 139 |
| 145 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { | 140 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {} |
| 146 } | |
| 147 | |
| 148 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { | |
| 149 container_view_->maximize_mode_animation_->End(); | |
| 150 } | |
| 151 | 141 |
| 152 void FrameCaptionButtonContainerView::SetButtonImages( | 142 void FrameCaptionButtonContainerView::SetButtonImages( |
| 153 CaptionButtonIcon icon, | 143 CaptionButtonIcon icon, |
| 154 int icon_image_id, | 144 int icon_image_id, |
| 155 int hovered_background_image_id, | 145 int hovered_background_image_id, |
| 156 int pressed_background_image_id) { | 146 int pressed_background_image_id) { |
| 157 button_icon_id_map_[icon] = ButtonIconIds(icon_image_id, | 147 button_icon_id_map_[icon] = ButtonIconIds( |
| 158 hovered_background_image_id, | 148 icon_image_id, hovered_background_image_id, pressed_background_image_id); |
| 159 pressed_background_image_id); | 149 FrameCaptionButton* buttons[] = {minimize_button_, size_button_, |
| 160 FrameCaptionButton* buttons[] = { | 150 close_button_}; |
| 161 minimize_button_, size_button_, close_button_ | |
| 162 }; | |
| 163 for (size_t i = 0; i < arraysize(buttons); ++i) { | 151 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| 164 if (buttons[i]->icon() == icon) { | 152 if (buttons[i]->icon() == icon) { |
| 165 buttons[i]->SetImages(icon, | 153 buttons[i]->SetImages(icon, FrameCaptionButton::ANIMATE_NO, icon_image_id, |
| 166 FrameCaptionButton::ANIMATE_NO, | |
| 167 icon_image_id, | |
| 168 hovered_background_image_id, | 154 hovered_background_image_id, |
| 169 pressed_background_image_id); | 155 pressed_background_image_id); |
| 170 } | 156 } |
| 171 } | 157 } |
| 172 } | 158 } |
| 173 | 159 |
| 174 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) { | 160 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) { |
| 175 minimize_button_->set_paint_as_active(paint_as_active); | 161 minimize_button_->set_paint_as_active(paint_as_active); |
| 176 size_button_->set_paint_as_active(paint_as_active); | 162 size_button_->set_paint_as_active(paint_as_active); |
| 177 close_button_->set_paint_as_active(paint_as_active); | 163 close_button_->set_paint_as_active(paint_as_active); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 PreferredSizeChanged(); | 235 PreferredSizeChanged(); |
| 250 } | 236 } |
| 251 } | 237 } |
| 252 | 238 |
| 253 void FrameCaptionButtonContainerView::AnimationProgressed( | 239 void FrameCaptionButtonContainerView::AnimationProgressed( |
| 254 const gfx::Animation* animation) { | 240 const gfx::Animation* animation) { |
| 255 double current_value = animation->GetCurrentValue(); | 241 double current_value = animation->GetCurrentValue(); |
| 256 int size_alpha = 0; | 242 int size_alpha = 0; |
| 257 int minimize_x = 0; | 243 int minimize_x = 0; |
| 258 if (maximize_mode_animation_->IsShowing()) { | 244 if (maximize_mode_animation_->IsShowing()) { |
| 259 double scaled_value = CapAnimationValue( | 245 double scaled_value = |
| 260 (current_value - SizeButtonShowStartValue()) | 246 CapAnimationValue((current_value - SizeButtonShowStartValue()) / |
| 261 / SizeButtonShowDuration()); | 247 SizeButtonShowDuration()); |
| 262 double tweened_value_alpha = | 248 double tweened_value_alpha = |
| 263 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT,scaled_value); | 249 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value); |
| 264 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255); | 250 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255); |
| 265 | 251 |
| 266 double tweened_value_slide = | 252 double tweened_value_slide = |
| 267 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value); | 253 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value); |
| 268 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide, | 254 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide, |
| 269 size_button_->x(), 0); | 255 size_button_->x(), 0); |
| 270 } else { | 256 } else { |
| 271 double scaled_value_alpha = CapAnimationValue( | 257 double scaled_value_alpha = |
| 272 (1.0f - current_value) / SizeButtonHideDuration()); | 258 CapAnimationValue((1.0f - current_value) / SizeButtonHideDuration()); |
| 273 double tweened_value_alpha = | 259 double tweened_value_alpha = |
| 274 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, scaled_value_alpha); | 260 gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, scaled_value_alpha); |
| 275 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 255, 0); | 261 size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 255, 0); |
| 276 | 262 |
| 277 double scaled_value_position = CapAnimationValue( | 263 double scaled_value_position = CapAnimationValue( |
| 278 (HidePositionStartValue() - current_value) | 264 (HidePositionStartValue() - current_value) / HidePositionStartValue()); |
| 279 / HidePositionStartValue()); | |
| 280 double tweened_value_position = | 265 double tweened_value_position = |
| 281 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position); | 266 gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position); |
| 282 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0, | 267 minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0, |
| 283 size_button_->x()); | 268 size_button_->x()); |
| 284 } | 269 } |
| 285 size_button_->SetAlpha(size_alpha); | 270 size_button_->SetAlpha(size_alpha); |
| 286 minimize_button_->SetX(minimize_x); | 271 minimize_button_->SetX(minimize_x); |
| 287 } | 272 } |
| 288 | 273 |
| 289 void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button, | 274 void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button, |
| 290 CaptionButtonIcon icon, | 275 CaptionButtonIcon icon, |
| 291 Animate animate) { | 276 Animate animate) { |
| 292 // The early return is dependant on |animate| because callers use | 277 // The early return is dependant on |animate| because callers use |
| 293 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation | 278 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation |
| 294 // to the end. | 279 // to the end. |
| 295 if (button->icon() == icon && | 280 if (button->icon() == icon && |
| 296 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) { | 281 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) { |
| 297 return; | 282 return; |
| 298 } | 283 } |
| 299 | 284 |
| 300 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? | 285 FrameCaptionButton::Animate fcb_animate = |
| 301 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; | 286 (animate == ANIMATE_YES) ? FrameCaptionButton::ANIMATE_YES |
| 287 : FrameCaptionButton::ANIMATE_NO; |
| 302 std::map<CaptionButtonIcon, ButtonIconIds>::const_iterator it = | 288 std::map<CaptionButtonIcon, ButtonIconIds>::const_iterator it = |
| 303 button_icon_id_map_.find(icon); | 289 button_icon_id_map_.find(icon); |
| 304 if (it != button_icon_id_map_.end()) { | 290 if (it != button_icon_id_map_.end()) { |
| 305 button->SetImages(icon, | 291 button->SetImages(icon, fcb_animate, it->second.icon_image_id, |
| 306 fcb_animate, | |
| 307 it->second.icon_image_id, | |
| 308 it->second.hovered_background_image_id, | 292 it->second.hovered_background_image_id, |
| 309 it->second.pressed_background_image_id); | 293 it->second.pressed_background_image_id); |
| 310 } | 294 } |
| 311 } | 295 } |
| 312 | 296 |
| 313 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { | 297 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { |
| 314 return !Shell::GetInstance()->maximize_mode_controller()-> | 298 return frame_->widget_delegate()->CanMaximize(); |
| 315 IsMaximizeModeWindowManagerEnabled() && | |
| 316 frame_->widget_delegate()->CanMaximize(); | |
| 317 } | |
| 318 | |
| 319 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, | |
| 320 const ui::Event& event) { | |
| 321 // Abort any animations of the button icons. | |
| 322 SetButtonsToNormal(ANIMATE_NO); | |
| 323 | |
| 324 ash::UserMetricsAction action = | |
| 325 ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; | |
| 326 if (sender == minimize_button_) { | |
| 327 frame_->Minimize(); | |
| 328 } else if (sender == size_button_) { | |
| 329 if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen. | |
| 330 frame_->Restore(); | |
| 331 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN; | |
| 332 } else if (frame_->IsMaximized()) { | |
| 333 frame_->Restore(); | |
| 334 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE; | |
| 335 } else { | |
| 336 frame_->Maximize(); | |
| 337 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE; | |
| 338 } | |
| 339 | |
| 340 if (event.IsGestureEvent()) { | |
| 341 TouchUMA::GetInstance()->RecordGestureAction( | |
| 342 TouchUMA::GESTURE_FRAMEMAXIMIZE_TAP); | |
| 343 } | |
| 344 } else if (sender == close_button_) { | |
| 345 frame_->Close(); | |
| 346 action = ash::UMA_WINDOW_CLOSE_BUTTON_CLICK; | |
| 347 } else { | |
| 348 return; | |
| 349 } | |
| 350 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(action); | |
| 351 } | |
| 352 | |
| 353 bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const { | |
| 354 return minimize_button_->visible(); | |
| 355 } | 299 } |
| 356 | 300 |
| 357 void FrameCaptionButtonContainerView::SetButtonsToNormal(Animate animate) { | 301 void FrameCaptionButtonContainerView::SetButtonsToNormal(Animate animate) { |
| 358 SetButtonIcons(CAPTION_BUTTON_ICON_MINIMIZE, CAPTION_BUTTON_ICON_CLOSE, | 302 SetButtonIcons(CAPTION_BUTTON_ICON_MINIMIZE, CAPTION_BUTTON_ICON_CLOSE, |
| 359 animate); | 303 animate); |
| 360 minimize_button_->SetState(views::Button::STATE_NORMAL); | 304 minimize_button_->SetState(views::Button::STATE_NORMAL); |
| 361 size_button_->SetState(views::Button::STATE_NORMAL); | 305 size_button_->SetState(views::Button::STATE_NORMAL); |
| 362 close_button_->SetState(views::Button::STATE_NORMAL); | 306 close_button_->SetState(views::Button::STATE_NORMAL); |
| 363 } | 307 } |
| 364 | 308 |
| 365 void FrameCaptionButtonContainerView::SetButtonIcons( | 309 void FrameCaptionButtonContainerView::SetButtonIcons( |
| 366 CaptionButtonIcon minimize_button_icon, | 310 CaptionButtonIcon minimize_button_icon, |
| 367 CaptionButtonIcon close_button_icon, | 311 CaptionButtonIcon close_button_icon, |
| 368 Animate animate) { | 312 Animate animate) { |
| 369 SetButtonIcon(minimize_button_, minimize_button_icon, animate); | 313 SetButtonIcon(minimize_button_, minimize_button_icon, animate); |
| 370 SetButtonIcon(close_button_, close_button_icon, animate); | 314 SetButtonIcon(close_button_, close_button_icon, animate); |
| 371 } | 315 } |
| 372 | 316 |
| 373 const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo( | 317 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, |
| 374 const gfx::Point& position_in_screen) const { | 318 const ui::Event& event) { |
| 375 // Since the buttons all have the same size, the closest button is the button | 319 // Abort any animations of the button icons. |
| 376 // with the center point closest to |position_in_screen|. | 320 SetButtonsToNormal(ANIMATE_NO); |
| 377 // TODO(pkotwicz): Make the caption buttons not overlap. | |
| 378 gfx::Point position(position_in_screen); | |
| 379 views::View::ConvertPointFromScreen(this, &position); | |
| 380 | 321 |
| 381 FrameCaptionButton* buttons[] = { | 322 if (sender == minimize_button_) { |
| 382 minimize_button_, size_button_, close_button_ | 323 frame_->Minimize(); |
| 383 }; | 324 } else if (sender == size_button_) { |
| 384 int min_squared_distance = INT_MAX; | 325 if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen. |
| 385 FrameCaptionButton* closest_button = NULL; | 326 frame_->Restore(); |
| 386 for (size_t i = 0; i < arraysize(buttons); ++i) { | 327 } else if (frame_->IsMaximized()) { |
| 387 FrameCaptionButton* button = buttons[i]; | 328 frame_->Restore(); |
| 388 if (!button->visible()) | 329 } else { |
| 389 continue; | 330 frame_->Maximize(); |
| 390 | |
| 391 gfx::Point center_point = button->GetLocalBounds().CenterPoint(); | |
| 392 views::View::ConvertPointToTarget(button, this, ¢er_point); | |
| 393 int squared_distance = static_cast<int>( | |
| 394 pow(static_cast<double>(position.x() - center_point.x()), 2) + | |
| 395 pow(static_cast<double>(position.y() - center_point.y()), 2)); | |
| 396 if (squared_distance < min_squared_distance) { | |
| 397 min_squared_distance = squared_distance; | |
| 398 closest_button = button; | |
| 399 } | 331 } |
| 400 } | 332 } else if (sender == close_button_) { |
| 401 return closest_button; | 333 frame_->Close(); |
| 402 } | |
| 403 | |
| 404 void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons( | |
| 405 const FrameCaptionButton* to_hover, | |
| 406 const FrameCaptionButton* to_press) { | |
| 407 FrameCaptionButton* buttons[] = { | |
| 408 minimize_button_, size_button_, close_button_ | |
| 409 }; | |
| 410 for (size_t i = 0; i < arraysize(buttons); ++i) { | |
| 411 FrameCaptionButton* button = buttons[i]; | |
| 412 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; | |
| 413 if (button == to_hover) | |
| 414 new_state = views::Button::STATE_HOVERED; | |
| 415 else if (button == to_press) | |
| 416 new_state = views::Button::STATE_PRESSED; | |
| 417 button->SetState(new_state); | |
| 418 } | 334 } |
| 419 } | 335 } |
| 420 | 336 |
| 421 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds() | 337 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds() |
| 422 : icon_image_id(-1), | 338 : icon_image_id(-1), |
| 423 hovered_background_image_id(-1), | 339 hovered_background_image_id(-1), |
| 424 pressed_background_image_id(-1) { | 340 pressed_background_image_id(-1) {} |
| 425 } | |
| 426 | 341 |
| 427 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds( | 342 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds( |
| 428 int icon_id, | 343 int icon_id, |
| 429 int hovered_background_id, | 344 int hovered_background_id, |
| 430 int pressed_background_id) | 345 int pressed_background_id) |
| 431 : icon_image_id(icon_id), | 346 : icon_image_id(icon_id), |
| 432 hovered_background_image_id(hovered_background_id), | 347 hovered_background_image_id(hovered_background_id), |
| 433 pressed_background_image_id(pressed_background_id) { | 348 pressed_background_image_id(pressed_background_id) {} |
| 434 } | |
| 435 | 349 |
| 436 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() { | 350 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() {} |
| 437 } | |
| 438 | 351 |
| 439 } // namespace ash | 352 } // namespace wm |
| 353 } // namespace mash |
| OLD | NEW |