Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Unified Diff: mash/wm/frame/caption_buttons/frame_caption_button.cc

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: move comment Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mash/wm/frame/caption_buttons/frame_caption_button.cc
diff --git a/mash/wm/frame/caption_buttons/frame_caption_button.cc b/mash/wm/frame/caption_buttons/frame_caption_button.cc
deleted file mode 100644
index 491829fe582a10609eeac4613b507e1db839b781..0000000000000000000000000000000000000000
--- a/mash/wm/frame/caption_buttons/frame_caption_button.cc
+++ /dev/null
@@ -1,193 +0,0 @@
-// 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 "mash/wm/frame/caption_buttons/frame_caption_button.h"
-
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/animation/slide_animation.h"
-#include "ui/gfx/animation/throb_animation.h"
-#include "ui/gfx/canvas.h"
-
-namespace mash {
-namespace wm {
-
-namespace {
-
-// The duration of the crossfade animation when swapping the button's images.
-const int kSwapImagesAnimationDurationMs = 200;
-
-// The duration of the fade out animation of the old icon during a crossfade
-// animation as a ratio of |kSwapImagesAnimationDurationMs|.
-const float kFadeOutRatio = 0.5f;
-
-// The alpha to draw inactive icons with.
-const float kInactiveIconAlpha = 0.2f;
-
-} // namespace
-
-// static
-const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton";
-
-FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener,
- CaptionButtonIcon icon)
- : CustomButton(listener),
- icon_(icon),
- paint_as_active_(false),
- alpha_(255),
- icon_image_id_(-1),
- hovered_background_image_id_(-1),
- pressed_background_image_id_(-1),
- swap_images_animation_(new gfx::SlideAnimation(this)) {
- swap_images_animation_->Reset(1);
-
- // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left
- // and snap right button icons should not be flipped. The other icons are
- // horizontally symmetrical.
-}
-
-FrameCaptionButton::~FrameCaptionButton() {}
-
-void FrameCaptionButton::SetImages(CaptionButtonIcon icon,
- Animate animate,
- int icon_image_id,
- int hovered_background_image_id,
- int pressed_background_image_id) {
- // The early return is dependant on |animate| because callers use SetImages()
- // with ANIMATE_NO to progress the crossfade animation to the end.
- if (icon == icon_ &&
- (animate == ANIMATE_YES || !swap_images_animation_->is_animating()) &&
- icon_image_id == icon_image_id_ &&
- hovered_background_image_id == hovered_background_image_id_ &&
- pressed_background_image_id == pressed_background_image_id_) {
- return;
- }
-
- if (animate == ANIMATE_YES)
- crossfade_icon_image_ = icon_image_;
-
- icon_ = icon;
- icon_image_id_ = icon_image_id;
- // TODO(sky): it doesn't seem like these are used.
- hovered_background_image_id_ = hovered_background_image_id;
- pressed_background_image_id_ = pressed_background_image_id;
-
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- icon_image_ = *rb.GetImageSkiaNamed(icon_image_id);
- hovered_background_image_ =
- *rb.GetImageSkiaNamed(hovered_background_image_id);
- pressed_background_image_ =
- *rb.GetImageSkiaNamed(pressed_background_image_id);
-
- if (animate == ANIMATE_YES) {
- swap_images_animation_->Reset(0);
- swap_images_animation_->SetSlideDuration(kSwapImagesAnimationDurationMs);
- swap_images_animation_->Show();
- } else {
- swap_images_animation_->Reset(1);
- }
- PreferredSizeChanged();
- SchedulePaint();
-}
-
-bool FrameCaptionButton::IsAnimatingImageSwap() const {
- return swap_images_animation_->is_animating();
-}
-
-void FrameCaptionButton::SetAlpha(int alpha) {
- if (alpha_ != alpha) {
- alpha_ = alpha;
- SchedulePaint();
- }
-}
-
-gfx::Size FrameCaptionButton::GetPreferredSize() const {
- return hovered_background_image_.isNull() ? gfx::Size()
- : hovered_background_image_.size();
-}
-
-const char* FrameCaptionButton::GetClassName() const {
- return kViewClassName;
-}
-
-void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) {
- if (hover_animation().is_animating() || state() == STATE_HOVERED) {
- int hovered_background_alpha =
- hover_animation().CurrentValueBetween(0, 255);
- SkPaint paint;
- paint.setAlpha(hovered_background_alpha);
- canvas->DrawImageInt(hovered_background_image_, 0, 0, paint);
- } else if (state() == STATE_PRESSED) {
- canvas->DrawImageInt(pressed_background_image_, 0, 0);
- }
-
- int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255);
- int crossfade_icon_alpha = 0;
- if (icon_alpha < static_cast<int>(kFadeOutRatio * 255))
- crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio);
-
- if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) {
- gfx::Canvas icon_canvas(icon_image_.size(), canvas->image_scale(), false);
- SkPaint paint;
- paint.setAlpha(icon_alpha);
- icon_canvas.DrawImageInt(icon_image_, 0, 0, paint);
-
- paint.setAlpha(crossfade_icon_alpha);
- paint.setXfermodeMode(SkXfermode::kPlus_Mode);
- icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, paint);
-
- PaintCentered(canvas, gfx::ImageSkia(icon_canvas.ExtractImageRep()),
- alpha_);
- } else {
- if (!swap_images_animation_->is_animating())
- icon_alpha = alpha_;
- PaintCentered(canvas, icon_image_, icon_alpha);
- }
-}
-
-void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) {
- // CustomButton does not become pressed when the user drags off and then back
- // onto the button. Make FrameCaptionButton pressed in this case because this
- // behavior is more consistent with AlternateFrameSizeButton.
- if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
- event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
- if (HitTestPoint(event->location())) {
- SetState(STATE_PRESSED);
- RequestFocus();
- event->StopPropagation();
- } else {
- SetState(STATE_NORMAL);
- }
- } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
- if (HitTestPoint(event->location())) {
- SetState(STATE_HOVERED);
- NotifyClick(*event);
- event->StopPropagation();
- }
- }
- CustomButton::OnGestureEvent(event);
-}
-
-void FrameCaptionButton::PaintCentered(gfx::Canvas* canvas,
- const gfx::ImageSkia& to_center,
- int alpha) {
- if (!paint_as_active_) {
- // Paint icons as active when they are hovered over or pressed.
- double inactive_alpha = kInactiveIconAlpha;
- if (hover_animation().is_animating()) {
- inactive_alpha =
- hover_animation().CurrentValueBetween(inactive_alpha, 1.0f);
- } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) {
- inactive_alpha = 1.0f;
- }
- alpha *= inactive_alpha;
- }
-
- SkPaint paint;
- paint.setAlpha(alpha);
- canvas->DrawImageInt(to_center, (width() - to_center.width()) / 2,
- (height() - to_center.height()) / 2, paint);
-}
-
-} // namespace wm
-} // namespace mash

Powered by Google App Engine
This is Rietveld 408576698