#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"
#include "ui/gfx/insets.h"
#include "ui/gfx/point.h"
namespace {
+// Duration of the animation of the position of |minimize_button_|.
+const int kPositionAnimationDurationMs = 500;
+
+// Duration of the animation of the alpha of |size_button_|.
+const int kAlphaAnimationDurationMs = 250;
+
+// Delay during |maximize_mode_animation_| hide to wait before beginning to
+// animate the position of |minimize_button_|.
+const int kHidePositionDelayMs = 100;
+
+// Duration of |maximize_mode_animation_| hiding.
+// Hiding size button 250
+// |------------------------|
+// Delay 100 Slide minimize button 500
+// |---------|-------------------------------------------------|
+const int kHideAnimationDurationMs =
+ kHidePositionDelayMs + kPositionAnimationDurationMs;
+
+// Delay during |maximize_mode_animation_| show to wait before beginning to
+// animate the alpha of |size_button_|.
+const int kShowAnimationAlphaDelayMs = 100;
+
+// Duration of |maximize_mode_animation_| showing.
+// Slide minimize button 500
+// |-------------------------------------------------|
+// Delay 100 Show size button 250
+// |---------|-----------------------|
+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;
+}
+
+// Amount of |maximize_mode_animation_| showing to animate the alpha of
+// |size_button_|.
+float SizeButtonShowDuration() {
+ 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;
+}
+
+// Value of |maximize_mode_animation_| hiding to begin animating the position of
+// |minimize_button_|.
+float HidePositionStartValue() {
+ return 1.0f - static_cast<float>(kHidePositionDelayMs)
+ / kHideAnimationDurationMs;
+}
+
// Converts |point| from |src| to |dst| and hittests against |dst|.
bool ConvertPointToViewAndHitTest(const views::View* src,
const views::View* dst,
return dst->HitTestPoint(converted);
}
+// Bounds animation values to the range 0.0 - 1.0. Allows for mapping of offset
+// animations to the expected range so that gfx::Tween::CalculateValue() can be
+// used.
+double CapAnimationValue(double value) {
+ return std::min(1.0, std::max(0.0, value));
+}
+
} // namespace
// static
minimize_button_(NULL),
size_button_(NULL),
close_button_(NULL) {
+ bool size_button_visibility = ShouldSizeButtonBeVisible();
+ maximize_mode_animation_.reset(new gfx::SlideAnimation(this));
+ maximize_mode_animation_->SetTweenType(gfx::Tween::LINEAR);
+
+ // Ensure animation tracks visibility of size button.
+ if (size_button_visibility)
+ maximize_mode_animation_->Reset(1.0f);
+
// Insert the buttons left to right.
minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE);
minimize_button_->SetAccessibleName(
size_button_ = new FrameSizeButton(this, frame, this);
size_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
- UpdateSizeButtonVisibility();
+ size_button_->SetVisible(size_button_visibility);
AddChildView(size_button_);
close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE);
FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() {
}
+void FrameCaptionButtonContainerView::TestApi::EndAnimations() {
+ container_view_->maximize_mode_animation_->End();
+}
+
void FrameCaptionButtonContainerView::SetButtonImages(
CaptionButtonIcon icon,
int icon_image_id,
}
void FrameCaptionButtonContainerView::UpdateSizeButtonVisibility() {
- size_button_->SetVisible(
- !Shell::GetInstance()->maximize_mode_controller()->
- IsMaximizeModeWindowManagerEnabled() &&
- frame_->widget_delegate()->CanMaximize());
+ bool visible = ShouldSizeButtonBeVisible();
+ if (visible) {
+ size_button_->SetVisible(true);
+ maximize_mode_animation_->SetSlideDuration(kShowAnimationDurationMs);
+ maximize_mode_animation_->Show();
+ } else {
+ maximize_mode_animation_->SetSlideDuration(kHideAnimationDurationMs);
+ maximize_mode_animation_->Hide();
+ }
}
gfx::Size FrameCaptionButtonContainerView::GetPreferredSize() const {
child->SetBounds(x, 0, size.width(), size.height());
x += size.width();
}
+ if (maximize_mode_animation_->is_animating()) {
+ AnimationProgressed(maximize_mode_animation_.get());
+ }
}
const char* FrameCaptionButtonContainerView::GetClassName() const {
return kViewClassName;
}
+void FrameCaptionButtonContainerView::AnimationEnded(
+ const gfx::Animation* animation) {
+ // Ensure that position is calculated at least once.
+ AnimationProgressed(animation);
+
+ double current_value = maximize_mode_animation_->GetCurrentValue();
+ if (current_value == 0.0) {
+ size_button_->SetVisible(false);
+ PreferredSizeChanged();
+ }
+}
+
+void FrameCaptionButtonContainerView::AnimationProgressed(
+ const gfx::Animation* animation) {
+ double current_value = animation->GetCurrentValue();
+ int size_alpha = 0;
+ int minimize_x = 0;
+ if (maximize_mode_animation_->IsShowing()) {
+ double scaled_value = CapAnimationValue(
+ (current_value - SizeButtonShowStartValue())
+ / SizeButtonShowDuration());
+ double tweened_value_alpha =
+ gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT,scaled_value);
+ size_alpha = gfx::Tween::LinearIntValueBetween(tweened_value_alpha, 0, 255);
+
+ double tweened_value_slide =
+ gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, current_value);
+ minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_slide,
+ size_button_->x(), 0);
+ } else {
+ 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());
+ double tweened_value_position =
+ gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, scaled_value_position);
+ minimize_x = gfx::Tween::LinearIntValueBetween(tweened_value_position, 0,
+ size_button_->x());
+ }
+ size_button_->SetAlpha(size_alpha);
+ minimize_button_->SetX(minimize_x);
+}
+
void FrameCaptionButtonContainerView::SetButtonIcon(FrameCaptionButton* button,
CaptionButtonIcon icon,
Animate animate) {
}
}
+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) {
// When shift-clicking, slow down animations for visual debugging.