| Index: mash/wm/frame/caption_buttons/frame_caption_button_container_view.cc
|
| diff --git a/ash/frame/caption_buttons/frame_caption_button_container_view.cc b/mash/wm/frame/caption_buttons/frame_caption_button_container_view.cc
|
| similarity index 68%
|
| copy from ash/frame/caption_buttons/frame_caption_button_container_view.cc
|
| copy to mash/wm/frame/caption_buttons/frame_caption_button_container_view.cc
|
| index 78c5a38ba40fad3fde1f51241a0d95e4ccb558bb..3bd443b000d90a264bf412341b25f1e3d89309e2 100644
|
| --- a/ash/frame/caption_buttons/frame_caption_button_container_view.cc
|
| +++ b/mash/wm/frame/caption_buttons/frame_caption_button_container_view.cc
|
| @@ -1,22 +1,15 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
|
| +#include "mash/wm/frame/caption_buttons/frame_caption_button_container_view.h"
|
|
|
| #include <cmath>
|
| #include <map>
|
|
|
| -#include "ash/ash_switches.h"
|
| -#include "ash/frame/caption_buttons/frame_caption_button.h"
|
| -#include "ash/frame/caption_buttons/frame_size_button.h"
|
| -#include "ash/metrics/user_metrics_recorder.h"
|
| -#include "ash/shell.h"
|
| -#include "ash/touch/touch_uma.h"
|
| -#include "ash/wm/maximize_mode/maximize_mode_controller.h"
|
| +#include "mash/wm/frame/caption_buttons/frame_caption_button.h"
|
| #include "ui/base/hit_test.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| -#include "ui/compositor/scoped_animation_duration_scale_mode.h"
|
| #include "ui/gfx/animation/slide_animation.h"
|
| #include "ui/gfx/animation/tween.h"
|
| #include "ui/gfx/canvas.h"
|
| @@ -26,7 +19,8 @@
|
| #include "ui/views/widget/widget.h"
|
| #include "ui/views/widget/widget_delegate.h"
|
|
|
| -namespace ash {
|
| +namespace mash {
|
| +namespace wm {
|
|
|
| namespace {
|
|
|
| @@ -62,29 +56,29 @@ const int kShowAnimationDurationMs = kPositionAnimationDurationMs;
|
| // Value of |maximize_mode_animation_| showing to begin animating alpha of
|
| // |size_button_|.
|
| float SizeButtonShowStartValue() {
|
| - return static_cast<float>(kShowAnimationAlphaDelayMs)
|
| - / kShowAnimationDurationMs;
|
| + return static_cast<float>(kShowAnimationAlphaDelayMs) /
|
| + kShowAnimationDurationMs;
|
| }
|
|
|
| // Amount of |maximize_mode_animation_| showing to animate the alpha of
|
| // |size_button_|.
|
| float SizeButtonShowDuration() {
|
| - return static_cast<float>(kAlphaAnimationDurationMs)
|
| - / kShowAnimationDurationMs;
|
| + return static_cast<float>(kAlphaAnimationDurationMs) /
|
| + kShowAnimationDurationMs;
|
| }
|
|
|
| // Amount of |maximize_mode_animation_| hiding to animate the alpha of
|
| // |size_button_|.
|
| float SizeButtonHideDuration() {
|
| - return static_cast<float>(kAlphaAnimationDurationMs)
|
| - / kHideAnimationDurationMs;
|
| + return static_cast<float>(kAlphaAnimationDurationMs) /
|
| + kHideAnimationDurationMs;
|
| }
|
|
|
| // Value of |maximize_mode_animation_| hiding to begin animating the position of
|
| // |minimize_button_|.
|
| float HidePositionStartValue() {
|
| - return 1.0f - static_cast<float>(kHidePositionDelayMs)
|
| - / kHideAnimationDurationMs;
|
| + return 1.0f -
|
| + static_cast<float>(kHidePositionDelayMs) / kHideAnimationDurationMs;
|
| }
|
|
|
| // Converts |point| from |src| to |dst| and hittests against |dst|.
|
| @@ -115,7 +109,7 @@ FrameCaptionButtonContainerView::FrameCaptionButtonContainerView(
|
| minimize_button_(NULL),
|
| size_button_(NULL),
|
| close_button_(NULL) {
|
| - bool size_button_visibility = ShouldSizeButtonBeVisible();
|
| + const bool size_button_visibility = ShouldSizeButtonBeVisible();
|
| maximize_mode_animation_.reset(new gfx::SlideAnimation(this));
|
| maximize_mode_animation_->SetTweenType(gfx::Tween::LINEAR);
|
|
|
| @@ -130,7 +124,8 @@ FrameCaptionButtonContainerView::FrameCaptionButtonContainerView(
|
| minimize_button_->SetVisible(frame_->widget_delegate()->CanMinimize());
|
| AddChildView(minimize_button_);
|
|
|
| - size_button_ = new FrameSizeButton(this, frame, this);
|
| + size_button_ =
|
| + new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE);
|
| size_button_->SetAccessibleName(
|
| l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
|
| size_button_->SetVisible(size_button_visibility);
|
| @@ -142,29 +137,20 @@ FrameCaptionButtonContainerView::FrameCaptionButtonContainerView(
|
| AddChildView(close_button_);
|
| }
|
|
|
| -FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {
|
| -}
|
| -
|
| -void FrameCaptionButtonContainerView::TestApi::EndAnimations() {
|
| - container_view_->maximize_mode_animation_->End();
|
| -}
|
| +FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {}
|
|
|
| void FrameCaptionButtonContainerView::SetButtonImages(
|
| CaptionButtonIcon icon,
|
| int icon_image_id,
|
| int hovered_background_image_id,
|
| int pressed_background_image_id) {
|
| - button_icon_id_map_[icon] = ButtonIconIds(icon_image_id,
|
| - hovered_background_image_id,
|
| - pressed_background_image_id);
|
| - FrameCaptionButton* buttons[] = {
|
| - minimize_button_, size_button_, close_button_
|
| - };
|
| + button_icon_id_map_[icon] = ButtonIconIds(
|
| + icon_image_id, hovered_background_image_id, pressed_background_image_id);
|
| + FrameCaptionButton* buttons[] = {minimize_button_, size_button_,
|
| + close_button_};
|
| for (size_t i = 0; i < arraysize(buttons); ++i) {
|
| if (buttons[i]->icon() == icon) {
|
| - buttons[i]->SetImages(icon,
|
| - FrameCaptionButton::ANIMATE_NO,
|
| - icon_image_id,
|
| + buttons[i]->SetImages(icon, FrameCaptionButton::ANIMATE_NO, icon_image_id,
|
| hovered_background_image_id,
|
| pressed_background_image_id);
|
| }
|
| @@ -256,11 +242,11 @@ void FrameCaptionButtonContainerView::AnimationProgressed(
|
| int size_alpha = 0;
|
| int minimize_x = 0;
|
| if (maximize_mode_animation_->IsShowing()) {
|
| - double scaled_value = CapAnimationValue(
|
| - (current_value - SizeButtonShowStartValue())
|
| - / SizeButtonShowDuration());
|
| + double scaled_value =
|
| + CapAnimationValue((current_value - SizeButtonShowStartValue()) /
|
| + SizeButtonShowDuration());
|
| double tweened_value_alpha =
|
| - gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT,scaled_value);
|
| + gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value);
|
| size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255);
|
|
|
| double tweened_value_slide =
|
| @@ -268,15 +254,14 @@ void FrameCaptionButtonContainerView::AnimationProgressed(
|
| minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide,
|
| size_button_->x(), 0);
|
| } else {
|
| - double scaled_value_alpha = CapAnimationValue(
|
| - (1.0f - current_value) / SizeButtonHideDuration());
|
| + double scaled_value_alpha =
|
| + CapAnimationValue((1.0f - current_value) / SizeButtonHideDuration());
|
| double tweened_value_alpha =
|
| gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, scaled_value_alpha);
|
| size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 255, 0);
|
|
|
| double scaled_value_position = CapAnimationValue(
|
| - (HidePositionStartValue() - current_value)
|
| - / HidePositionStartValue());
|
| + (HidePositionStartValue() - current_value) / HidePositionStartValue());
|
| double tweened_value_position =
|
| gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position);
|
| minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0,
|
| @@ -297,66 +282,25 @@ void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button,
|
| return;
|
| }
|
|
|
| - FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ?
|
| - FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO;
|
| + FrameCaptionButton::Animate fcb_animate =
|
| + (animate == ANIMATE_YES) ? FrameCaptionButton::ANIMATE_YES
|
| + : FrameCaptionButton::ANIMATE_NO;
|
| std::map<CaptionButtonIcon, ButtonIconIds>::const_iterator it =
|
| button_icon_id_map_.find(icon);
|
| if (it != button_icon_id_map_.end()) {
|
| - button->SetImages(icon,
|
| - fcb_animate,
|
| - it->second.icon_image_id,
|
| + button->SetImages(icon, fcb_animate, it->second.icon_image_id,
|
| it->second.hovered_background_image_id,
|
| it->second.pressed_background_image_id);
|
| }
|
| }
|
|
|
| bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const {
|
| - return !Shell::GetInstance()->maximize_mode_controller()->
|
| - IsMaximizeModeWindowManagerEnabled() &&
|
| - frame_->widget_delegate()->CanMaximize();
|
| -}
|
| -
|
| -void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender,
|
| - const ui::Event& event) {
|
| - // Abort any animations of the button icons.
|
| - SetButtonsToNormal(ANIMATE_NO);
|
| -
|
| - ash::UserMetricsAction action =
|
| - ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE;
|
| - if (sender == minimize_button_) {
|
| - frame_->Minimize();
|
| - } else if (sender == size_button_) {
|
| - if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen.
|
| - frame_->Restore();
|
| - action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN;
|
| - } else if (frame_->IsMaximized()) {
|
| - frame_->Restore();
|
| - action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE;
|
| - } else {
|
| - frame_->Maximize();
|
| - action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE;
|
| - }
|
| -
|
| - if (event.IsGestureEvent()) {
|
| - TouchUMA::GetInstance()->RecordGestureAction(
|
| - TouchUMA::GESTURE_FRAMEMAXIMIZE_TAP);
|
| - }
|
| - } else if (sender == close_button_) {
|
| - frame_->Close();
|
| - action = ash::UMA_WINDOW_CLOSE_BUTTON_CLICK;
|
| - } else {
|
| - return;
|
| - }
|
| - ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(action);
|
| -}
|
| -
|
| -bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const {
|
| - return minimize_button_->visible();
|
| + return frame_->widget_delegate()->CanMaximize();
|
| }
|
|
|
| void FrameCaptionButtonContainerView::SetButtonsToNormal(Animate animate) {
|
| SetButtonIcons(CAPTION_BUTTON_ICON_MINIMIZE, CAPTION_BUTTON_ICON_CLOSE,
|
| - animate);
|
| + animate);
|
| minimize_button_->SetState(views::Button::STATE_NORMAL);
|
| size_button_->SetState(views::Button::STATE_NORMAL);
|
| close_button_->SetState(views::Button::STATE_NORMAL);
|
| @@ -370,59 +314,30 @@ void FrameCaptionButtonContainerView::SetButtonIcons(
|
| SetButtonIcon(close_button_, close_button_icon, animate);
|
| }
|
|
|
| -const FrameCaptionButton* FrameCaptionButtonContainerView::GetButtonClosestTo(
|
| - const gfx::Point& position_in_screen) const {
|
| - // Since the buttons all have the same size, the closest button is the button
|
| - // with the center point closest to |position_in_screen|.
|
| - // TODO(pkotwicz): Make the caption buttons not overlap.
|
| - gfx::Point position(position_in_screen);
|
| - views::View::ConvertPointFromScreen(this, &position);
|
| -
|
| - FrameCaptionButton* buttons[] = {
|
| - minimize_button_, size_button_, close_button_
|
| - };
|
| - int min_squared_distance = INT_MAX;
|
| - FrameCaptionButton* closest_button = NULL;
|
| - for (size_t i = 0; i < arraysize(buttons); ++i) {
|
| - FrameCaptionButton* button = buttons[i];
|
| - if (!button->visible())
|
| - continue;
|
| +void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender,
|
| + const ui::Event& event) {
|
| + // Abort any animations of the button icons.
|
| + SetButtonsToNormal(ANIMATE_NO);
|
|
|
| - gfx::Point center_point = button->GetLocalBounds().CenterPoint();
|
| - views::View::ConvertPointToTarget(button, this, ¢er_point);
|
| - int squared_distance = static_cast<int>(
|
| - pow(static_cast<double>(position.x() - center_point.x()), 2) +
|
| - pow(static_cast<double>(position.y() - center_point.y()), 2));
|
| - if (squared_distance < min_squared_distance) {
|
| - min_squared_distance = squared_distance;
|
| - closest_button = button;
|
| + if (sender == minimize_button_) {
|
| + frame_->Minimize();
|
| + } else if (sender == size_button_) {
|
| + if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen.
|
| + frame_->Restore();
|
| + } else if (frame_->IsMaximized()) {
|
| + frame_->Restore();
|
| + } else {
|
| + frame_->Maximize();
|
| }
|
| - }
|
| - return closest_button;
|
| -}
|
| -
|
| -void FrameCaptionButtonContainerView::SetHoveredAndPressedButtons(
|
| - const FrameCaptionButton* to_hover,
|
| - const FrameCaptionButton* to_press) {
|
| - FrameCaptionButton* buttons[] = {
|
| - minimize_button_, size_button_, close_button_
|
| - };
|
| - for (size_t i = 0; i < arraysize(buttons); ++i) {
|
| - FrameCaptionButton* button = buttons[i];
|
| - views::Button::ButtonState new_state = views::Button::STATE_NORMAL;
|
| - if (button == to_hover)
|
| - new_state = views::Button::STATE_HOVERED;
|
| - else if (button == to_press)
|
| - new_state = views::Button::STATE_PRESSED;
|
| - button->SetState(new_state);
|
| + } else if (sender == close_button_) {
|
| + frame_->Close();
|
| }
|
| }
|
|
|
| FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds()
|
| : icon_image_id(-1),
|
| hovered_background_image_id(-1),
|
| - pressed_background_image_id(-1) {
|
| -}
|
| + pressed_background_image_id(-1) {}
|
|
|
| FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds(
|
| int icon_id,
|
| @@ -430,10 +345,9 @@ FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds(
|
| int pressed_background_id)
|
| : icon_image_id(icon_id),
|
| hovered_background_image_id(hovered_background_id),
|
| - pressed_background_image_id(pressed_background_id) {
|
| -}
|
| + pressed_background_image_id(pressed_background_id) {}
|
|
|
| -FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() {
|
| -}
|
| +FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() {}
|
|
|
| -} // namespace ash
|
| +} // namespace wm
|
| +} // namespace mash
|
|
|