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

Side by Side Diff: views/controls/button/text_button.cc

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/controls/button/text_button.h" 5 #include "views/controls/button/text_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const BorderImageSet* set = &normal_set_; 134 const BorderImageSet* set = &normal_set_;
135 if (button->show_multiple_icon_states() && 135 if (button->show_multiple_icon_states() &&
136 ((state == TextButton::BS_HOT) || (state == TextButton::BS_PUSHED))) 136 ((state == TextButton::BS_HOT) || (state == TextButton::BS_PUSHED)))
137 set = (state == TextButton::BS_HOT) ? &hot_set_ : &pushed_set_; 137 set = (state == TextButton::BS_HOT) ? &hot_set_ : &pushed_set_;
138 if (set->top_left) { 138 if (set->top_left) {
139 if (button->GetAnimation()->is_animating()) { 139 if (button->GetAnimation()->is_animating()) {
140 // TODO(pkasting): Really this should crossfade between states so it could 140 // TODO(pkasting): Really this should crossfade between states so it could
141 // handle the case of having a non-NULL |normal_set_|. 141 // handle the case of having a non-NULL |normal_set_|.
142 canvas->SaveLayerAlpha(static_cast<uint8>( 142 canvas->SaveLayerAlpha(static_cast<uint8>(
143 button->GetAnimation()->CurrentValueBetween(0, 255))); 143 button->GetAnimation()->CurrentValueBetween(0, 255)));
144 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, 144 canvas->GetSkCanvas()->drawARGB(0, 255, 255, 255,
145 SkXfermode::kClear_Mode); 145 SkXfermode::kClear_Mode);
146 Paint(view, canvas, *set); 146 Paint(view, canvas, *set);
147 canvas->Restore(); 147 canvas->Restore();
148 } else { 148 } else {
149 Paint(view, canvas, *set); 149 Paint(view, canvas, *set);
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 void TextButtonBorder::Paint(const View& view, 154 void TextButtonBorder::Paint(const View& view,
155 gfx::Canvas* canvas, 155 gfx::Canvas* canvas,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 206 }
207 207
208 TextButtonNativeThemeBorder::~TextButtonNativeThemeBorder() { 208 TextButtonNativeThemeBorder::~TextButtonNativeThemeBorder() {
209 } 209 }
210 210
211 void TextButtonNativeThemeBorder::Paint(const View& view, 211 void TextButtonNativeThemeBorder::Paint(const View& view,
212 gfx::Canvas* canvas) const { 212 gfx::Canvas* canvas) const {
213 const TextButtonBase* tb = static_cast<const TextButton*>(&view); 213 const TextButtonBase* tb = static_cast<const TextButton*>(&view);
214 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 214 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
215 gfx::NativeTheme::Part part = delegate_->GetThemePart(); 215 gfx::NativeTheme::Part part = delegate_->GetThemePart();
216 gfx::CanvasSkia* skia_canvas = canvas->AsCanvasSkia();
217 gfx::Rect rect(delegate_->GetThemePaintRect()); 216 gfx::Rect rect(delegate_->GetThemePaintRect());
218 217
219 if (tb->show_multiple_icon_states() && 218 if (tb->show_multiple_icon_states() &&
220 delegate_->GetThemeAnimation() != NULL && 219 delegate_->GetThemeAnimation() != NULL &&
221 delegate_->GetThemeAnimation()->is_animating()) { 220 delegate_->GetThemeAnimation()->is_animating()) {
222 // Paint background state. 221 // Paint background state.
223 gfx::NativeTheme::ExtraParams prev_extra; 222 gfx::NativeTheme::ExtraParams prev_extra;
224 gfx::NativeTheme::State prev_state = 223 gfx::NativeTheme::State prev_state =
225 delegate_->GetBackgroundThemeState(&prev_extra); 224 delegate_->GetBackgroundThemeState(&prev_extra);
226 native_theme->Paint(skia_canvas, part, prev_state, rect, prev_extra); 225 native_theme->Paint(
226 canvas->GetSkCanvas(), part, prev_state, rect, prev_extra);
227 227
228 // Composite foreground state above it. 228 // Composite foreground state above it.
229 gfx::NativeTheme::ExtraParams extra; 229 gfx::NativeTheme::ExtraParams extra;
230 gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra); 230 gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra);
231 int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255); 231 int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255);
232 skia_canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); 232 canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
233 native_theme->Paint(skia_canvas, part, state, rect, extra); 233 native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
234 skia_canvas->Restore(); 234 canvas->Restore();
235 } else { 235 } else {
236 gfx::NativeTheme::ExtraParams extra; 236 gfx::NativeTheme::ExtraParams extra;
237 gfx::NativeTheme::State state = delegate_->GetThemeState(&extra); 237 gfx::NativeTheme::State state = delegate_->GetThemeState(&extra);
238 native_theme->Paint(skia_canvas, part, state, rect, extra); 238 native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
239 } 239 }
240 } 240 }
241 241
242 void TextButtonNativeThemeBorder::GetInsets(gfx::Insets* insets) const { 242 void TextButtonNativeThemeBorder::GetInsets(gfx::Insets* insets) const {
243 insets->Set(kPreferredNativeThemePaddingVertical, 243 insets->Set(kPreferredNativeThemePaddingVertical,
244 kPreferredNativeThemePaddingHorizontal, 244 kPreferredNativeThemePaddingHorizontal,
245 kPreferredNativeThemePaddingVertical, 245 kPreferredNativeThemePaddingVertical,
246 kPreferredNativeThemePaddingHorizontal); 246 kPreferredNativeThemePaddingHorizontal);
247 } 247 }
248 248
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 #endif 824 #endif
825 } 825 }
826 826
827 void NativeTextButton::GetExtraParams( 827 void NativeTextButton::GetExtraParams(
828 gfx::NativeTheme::ExtraParams* params) const { 828 gfx::NativeTheme::ExtraParams* params) const {
829 TextButton::GetExtraParams(params); 829 TextButton::GetExtraParams(params);
830 params->button.has_border = true; 830 params->button.has_border = true;
831 } 831 }
832 832
833 } // namespace views 833 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698