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

Unified Diff: ash/frame/caption_buttons/frame_caption_button.cc

Issue 1505223004: Do not use assets for Ash window control button backgrounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for owners review Created 4 years, 12 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: ash/frame/caption_buttons/frame_caption_button.cc
diff --git a/ash/frame/caption_buttons/frame_caption_button.cc b/ash/frame/caption_buttons/frame_caption_button.cc
index 99ac55482acaca453bca6ff1d223f2f4a75ec421..7bc2e038c0b1b50f0a0c797365855dda8e17b070 100644
--- a/ash/frame/caption_buttons/frame_caption_button.cc
+++ b/ash/frame/caption_buttons/frame_caption_button.cc
@@ -23,6 +23,13 @@ const float kFadeOutRatio = 0.5f;
// The alpha to draw inactive icons with.
const float kInactiveIconAlpha = 0.2f;
+// The colors and alpha values used for the button background hovered and
+// pressed states.
+// TODO(tdanderson|estade): Request these colors from ThemeProvider.
+const int kHoveredAlpha = 0x14;
+const SkColor kHoveredPressedColor = SK_ColorBLACK;
+const int kPressedAlpha = 0x24;
+
} // namespace
// static
@@ -35,8 +42,6 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener,
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);
@@ -48,18 +53,14 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener,
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()
+void FrameCaptionButton::SetImage(CaptionButtonIcon icon,
+ Animate animate,
+ int icon_image_id) {
+ // The early return is dependant on |animate| because callers use SetImage()
// 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_) {
+ icon_image_id == icon_image_id_) {
return;
}
@@ -68,15 +69,9 @@ void FrameCaptionButton::SetImages(CaptionButtonIcon icon,
icon_ = icon;
icon_image_id_ = icon_image_id;
- 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);
@@ -101,8 +96,7 @@ void FrameCaptionButton::SetAlpha(int alpha) {
}
gfx::Size FrameCaptionButton::GetPreferredSize() const {
- return hovered_background_image_.isNull() ?
- gfx::Size() : hovered_background_image_.size();
+ return size_;
}
const char* FrameCaptionButton::GetClassName() const {
@@ -113,13 +107,12 @@ void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) {
if (hover_animation().is_animating() || state() == STATE_HOVERED) {
Evan Stade 2016/01/04 23:53:17 further refined as: SkAlpha bg_alpha = SK_AlphaTR
tdanderson 2016/01/05 16:47:26 Done. (Though technically this would cause a probl
Evan Stade 2016/01/05 19:41:56 how so? if fully transparent, we might as well not
int hovered_background_alpha =
hover_animation().is_animating()
- ? hover_animation().CurrentValueBetween(0, 255)
- : 255;
- SkPaint paint;
- paint.setAlpha(hovered_background_alpha);
- canvas->DrawImageInt(hovered_background_image_, 0, 0, paint);
+ ? hover_animation().CurrentValueBetween(0, kHoveredAlpha)
+ : kHoveredAlpha;
+ canvas->DrawColor(
+ SkColorSetA(kHoveredPressedColor, hovered_background_alpha));
} else if (state() == STATE_PRESSED) {
- canvas->DrawImageInt(pressed_background_image_, 0, 0);
+ canvas->DrawColor(SkColorSetA(kHoveredPressedColor, kPressedAlpha));
}
int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255);

Powered by Google App Engine
This is Rietveld 408576698