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

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

Issue 2760133002: ui: Remove a bunch of uses of gfx::Canvas::ExtractImageRep() (Closed)
Patch Set: canvasbounds: nits Created 3 years, 9 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/common/frame/caption_buttons/frame_caption_button.cc
diff --git a/ash/common/frame/caption_buttons/frame_caption_button.cc b/ash/common/frame/caption_buttons/frame_caption_button.cc
index 0e854d5bfb3e9b18a51f666bf3ad8fa184a61f9e..63185b17a1b2c13e7a58dee32d7d0527a8bc59a8 100644
--- a/ash/common/frame/caption_buttons/frame_caption_button.cc
+++ b/ash/common/frame/caption_buttons/frame_caption_button.cc
@@ -124,22 +124,25 @@ void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) {
if (icon_alpha < static_cast<int>(kFadeOutRatio * 255))
crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio);
+ int centered_x = (width() - icon_image_.width()) / 2;
+ int centered_y = (height() - icon_image_.height()) / 2;
oshima 2017/03/21 15:47:24 The name centered_ is misleading. It's origin of t
danakj 2017/03/21 15:55:31 Done.
+
if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) {
- gfx::Canvas icon_canvas(icon_image_.size(), canvas->image_scale(), false);
+ canvas->SaveLayerAlpha(GetAlphaForIcon(alpha_));
cc::PaintFlags flags;
flags.setAlpha(icon_alpha);
- icon_canvas.DrawImageInt(icon_image_, 0, 0, flags);
+ canvas->DrawImageInt(icon_image_, centered_x, centered_y, flags);
flags.setAlpha(crossfade_icon_alpha);
flags.setBlendMode(SkBlendMode::kPlus);
- icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, flags);
-
- PaintCentered(canvas, gfx::ImageSkia(icon_canvas.ExtractImageRep()),
- alpha_);
+ canvas->DrawImageInt(crossfade_icon_image_, centered_x, centered_y, flags);
+ canvas->Restore();
} else {
if (!swap_images_animation_->is_animating())
icon_alpha = alpha_;
- PaintCentered(canvas, icon_image_, icon_alpha);
+ cc::PaintFlags flags;
+ flags.setAlpha(GetAlphaForIcon(icon_alpha));
+ canvas->DrawImageInt(icon_image_, centered_x, centered_y, flags);
}
}
@@ -166,25 +169,19 @@ void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) {
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;
+int FrameCaptionButton::GetAlphaForIcon(int base_alpha) const {
+ if (paint_as_active_)
+ return base_alpha;
+
+ // 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;
}
-
- cc::PaintFlags flags;
- flags.setAlpha(alpha);
- canvas->DrawImageInt(to_center, (width() - to_center.width()) / 2,
- (height() - to_center.height()) / 2, flags);
+ return base_alpha * inactive_alpha;
}
} // namespace ash
« no previous file with comments | « ash/common/frame/caption_buttons/frame_caption_button.h ('k') | chrome/browser/ui/app_list/extension_app_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698