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

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: ashnit 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_origin_x = (width() - icon_image_.width()) / 2;
128 int centered_origin_y = (height() - icon_image_.height()) / 2;
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_origin_x, centered_origin_y,
135 flags);
132 136
133 flags.setAlpha(crossfade_icon_alpha); 137 flags.setAlpha(crossfade_icon_alpha);
134 flags.setBlendMode(SkBlendMode::kPlus); 138 flags.setBlendMode(SkBlendMode::kPlus);
135 icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, flags); 139 canvas->DrawImageInt(crossfade_icon_image_, centered_origin_x,
136 140 centered_origin_y, flags);
137 PaintCentered(canvas, gfx::ImageSkia(icon_canvas.ExtractImageRep()), 141 canvas->Restore();
138 alpha_);
139 } else { 142 } else {
140 if (!swap_images_animation_->is_animating()) 143 if (!swap_images_animation_->is_animating())
141 icon_alpha = alpha_; 144 icon_alpha = alpha_;
142 PaintCentered(canvas, icon_image_, icon_alpha); 145 cc::PaintFlags flags;
146 flags.setAlpha(GetAlphaForIcon(icon_alpha));
147 canvas->DrawImageInt(icon_image_, centered_origin_x, centered_origin_y,
148 flags);
143 } 149 }
144 } 150 }
145 151
146 void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) { 152 void FrameCaptionButton::OnGestureEvent(ui::GestureEvent* event) {
147 // CustomButton does not become pressed when the user drags off and then back 153 // 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 154 // onto the button. Make FrameCaptionButton pressed in this case because this
149 // behavior is more consistent with AlternateFrameSizeButton. 155 // behavior is more consistent with AlternateFrameSizeButton.
150 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || 156 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
151 event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 157 event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
152 if (HitTestPoint(event->location())) { 158 if (HitTestPoint(event->location())) {
153 SetState(STATE_PRESSED); 159 SetState(STATE_PRESSED);
154 RequestFocus(); 160 RequestFocus();
155 event->StopPropagation(); 161 event->StopPropagation();
156 } else { 162 } else {
157 SetState(STATE_NORMAL); 163 SetState(STATE_NORMAL);
158 } 164 }
159 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { 165 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
160 if (HitTestPoint(event->location())) { 166 if (HitTestPoint(event->location())) {
161 SetState(STATE_HOVERED); 167 SetState(STATE_HOVERED);
162 NotifyClick(*event); 168 NotifyClick(*event);
163 event->StopPropagation(); 169 event->StopPropagation();
164 } 170 }
165 } 171 }
166 CustomButton::OnGestureEvent(event); 172 CustomButton::OnGestureEvent(event);
167 } 173 }
168 174
169 void FrameCaptionButton::PaintCentered(gfx::Canvas* canvas, 175 int FrameCaptionButton::GetAlphaForIcon(int base_alpha) const {
170 const gfx::ImageSkia& to_center, 176 if (paint_as_active_)
171 int alpha) { 177 return base_alpha;
172 if (!paint_as_active_) { 178
173 // Paint icons as active when they are hovered over or pressed. 179 // Paint icons as active when they are hovered over or pressed.
174 double inactive_alpha = kInactiveIconAlpha; 180 double inactive_alpha = kInactiveIconAlpha;
175 if (hover_animation().is_animating()) { 181 if (hover_animation().is_animating()) {
176 inactive_alpha = 182 inactive_alpha =
177 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f); 183 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f);
178 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { 184 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) {
179 inactive_alpha = 1.0f; 185 inactive_alpha = 1.0f;
180 }
181 alpha *= inactive_alpha;
182 } 186 }
183 187 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 } 188 }
189 189
190 } // namespace ash 190 } // 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