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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/frame/caption_buttons/frame_caption_button.h" 5 #include "ash/common/frame/caption_buttons/frame_caption_button.h"
6 6
7 #include "ui/gfx/animation/slide_animation.h" 7 #include "ui/gfx/animation/slide_animation.h"
8 #include "ui/gfx/animation/throb_animation.h" 8 #include "ui/gfx/animation/throb_animation.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (bg_alpha != SK_AlphaTRANSPARENT) { 117 if (bg_alpha != SK_AlphaTRANSPARENT) {
118 canvas->DrawColor(SkColorSetA( 118 canvas->DrawColor(SkColorSetA(
119 use_light_images_ ? SK_ColorWHITE : SK_ColorBLACK, bg_alpha)); 119 use_light_images_ ? SK_ColorWHITE : SK_ColorBLACK, bg_alpha));
120 } 120 }
121 121
122 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); 122 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255);
123 int crossfade_icon_alpha = 0; 123 int crossfade_icon_alpha = 0;
124 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) 124 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255))
125 crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio); 125 crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio);
126 126
127 int centered_x = (width() - icon_image_.width()) / 2;
128 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.
129
127 if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) { 130 if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) {
128 gfx::Canvas icon_canvas(icon_image_.size(), canvas->image_scale(), false); 131 canvas->SaveLayerAlpha(GetAlphaForIcon(alpha_));
129 cc::PaintFlags flags; 132 cc::PaintFlags flags;
130 flags.setAlpha(icon_alpha); 133 flags.setAlpha(icon_alpha);
131 icon_canvas.DrawImageInt(icon_image_, 0, 0, flags); 134 canvas->DrawImageInt(icon_image_, centered_x, centered_y, flags);
132 135
133 flags.setAlpha(crossfade_icon_alpha); 136 flags.setAlpha(crossfade_icon_alpha);
134 flags.setBlendMode(SkBlendMode::kPlus); 137 flags.setBlendMode(SkBlendMode::kPlus);
135 icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, flags); 138 canvas->DrawImageInt(crossfade_icon_image_, centered_x, centered_y, flags);
136 139 canvas->Restore();
137 PaintCentered(canvas, gfx::ImageSkia(icon_canvas.ExtractImageRep()),
138 alpha_);
139 } else { 140 } else {
140 if (!swap_images_animation_->is_animating()) 141 if (!swap_images_animation_->is_animating())
141 icon_alpha = alpha_; 142 icon_alpha = alpha_;
142 PaintCentered(canvas, icon_image_, icon_alpha); 143 cc::PaintFlags flags;
144 flags.setAlpha(GetAlphaForIcon(icon_alpha));
145 canvas->DrawImageInt(icon_image_, centered_x, centered_y, flags);
143 } 146 }
144 } 147 }
145 148
146 void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) { 149 void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) {
147 // CustomButton does not become pressed when the user drags off and then back 150 // CustomButton does not become pressed when the user drags off and then back
148 // onto the button. Make FrameCaptionButton pressed in this case because this 151 // onto the button. Make FrameCaptionButton pressed in this case because this
149 // behavior is more consistent with AlternateFrameSizeButton. 152 // behavior is more consistent with AlternateFrameSizeButton.
150 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || 153 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
151 event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 154 event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
152 if (HitTestPoint(event->location())) { 155 if (HitTestPoint(event->location())) {
153 SetState(STATE_PRESSED); 156 SetState(STATE_PRESSED);
154 RequestFocus(); 157 RequestFocus();
155 event->StopPropagation(); 158 event->StopPropagation();
156 } else { 159 } else {
157 SetState(STATE_NORMAL); 160 SetState(STATE_NORMAL);
158 } 161 }
159 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { 162 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
160 if (HitTestPoint(event->location())) { 163 if (HitTestPoint(event->location())) {
161 SetState(STATE_HOVERED); 164 SetState(STATE_HOVERED);
162 NotifyClick(*event); 165 NotifyClick(*event);
163 event->StopPropagation(); 166 event->StopPropagation();
164 } 167 }
165 } 168 }
166 CustomButton::OnGestureEvent(event); 169 CustomButton::OnGestureEvent(event);
167 } 170 }
168 171
169 void FrameCaptionButton::PaintCentered(gfx::Canvas* canvas, 172 int FrameCaptionButton::GetAlphaForIcon(int base_alpha) const {
170 const gfx::ImageSkia& to_center, 173 if (paint_as_active_)
171 int alpha) { 174 return base_alpha;
172 if (!paint_as_active_) { 175
173 // Paint icons as active when they are hovered over or pressed. 176 // Paint icons as active when they are hovered over or pressed.
174 double inactive_alpha = kInactiveIconAlpha; 177 double inactive_alpha = kInactiveIconAlpha;
175 if (hover_animation().is_animating()) { 178 if (hover_animation().is_animating()) {
176 inactive_alpha = 179 inactive_alpha =
177 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f); 180 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f);
178 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { 181 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) {
179 inactive_alpha = 1.0f; 182 inactive_alpha = 1.0f;
180 }
181 alpha *= inactive_alpha;
182 } 183 }
183 184 return base_alpha * inactive_alpha;
184 cc::PaintFlags flags;
185 flags.setAlpha(alpha);
186 canvas->DrawImageInt(to_center, (width() - to_center.width()) / 2,
187 (height() - to_center.height()) / 2, flags);
188 } 185 }
189 186
190 } // namespace ash 187 } // namespace ash
OLDNEW
« 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