OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/throb_animation.h" | 9 #include "app/throb_animation.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 : CustomButton(listener), | 183 : CustomButton(listener), |
184 alignment_(ALIGN_LEFT), | 184 alignment_(ALIGN_LEFT), |
185 icon_placement_(ICON_ON_LEFT), | 185 icon_placement_(ICON_ON_LEFT), |
186 font_(ResourceBundle::GetSharedInstance().GetFont( | 186 font_(ResourceBundle::GetSharedInstance().GetFont( |
187 ResourceBundle::BaseFont)), | 187 ResourceBundle::BaseFont)), |
188 color_(kEnabledColor), | 188 color_(kEnabledColor), |
189 color_enabled_(kEnabledColor), | 189 color_enabled_(kEnabledColor), |
190 color_disabled_(kDisabledColor), | 190 color_disabled_(kDisabledColor), |
191 color_highlight_(kHighlightColor), | 191 color_highlight_(kHighlightColor), |
192 color_hover_(kHoverColor), | 192 color_hover_(kHoverColor), |
| 193 text_halo_color_(0), |
| 194 has_text_halo_(false), |
193 has_hover_icon_(false), | 195 has_hover_icon_(false), |
194 has_pushed_icon_(false), | 196 has_pushed_icon_(false), |
195 max_width_(0), | 197 max_width_(0), |
196 normal_has_border_(false), | 198 normal_has_border_(false), |
197 show_multiple_icon_states_(true), | 199 show_multiple_icon_states_(true), |
198 prefix_type_(PREFIX_NONE), | 200 prefix_type_(PREFIX_NONE), |
199 icon_text_spacing_(kDefaultIconTextSpacing) { | 201 icon_text_spacing_(kDefaultIconTextSpacing) { |
200 SetText(text); | 202 SetText(text); |
201 set_border(new TextButtonBorder); | 203 set_border(new TextButtonBorder); |
202 SetAnimationDuration(kHoverAnimationDurationMs); | 204 SetAnimationDuration(kHoverAnimationDurationMs); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 243 } |
242 | 244 |
243 void TextButton::SetHighlightColor(SkColor color) { | 245 void TextButton::SetHighlightColor(SkColor color) { |
244 color_highlight_ = color; | 246 color_highlight_ = color; |
245 } | 247 } |
246 | 248 |
247 void TextButton::SetHoverColor(SkColor color) { | 249 void TextButton::SetHoverColor(SkColor color) { |
248 color_hover_ = color; | 250 color_hover_ = color; |
249 } | 251 } |
250 | 252 |
| 253 void TextButton::SetTextHaloColor(SkColor color) { |
| 254 text_halo_color_ = color; |
| 255 has_text_halo_ = true; |
| 256 } |
| 257 |
251 void TextButton::ClearMaxTextSize() { | 258 void TextButton::ClearMaxTextSize() { |
252 max_text_size_ = text_size_; | 259 max_text_size_ = text_size_; |
253 } | 260 } |
254 | 261 |
255 void TextButton::SetNormalHasBorder(bool normal_has_border) { | 262 void TextButton::SetNormalHasBorder(bool normal_has_border) { |
256 normal_has_border_ = normal_has_border; | 263 normal_has_border_ = normal_has_border; |
257 } | 264 } |
258 | 265 |
259 void TextButton::SetShowMultipleIconStates(bool show_multiple_icon_states) { | 266 void TextButton::SetShowMultipleIconStates(bool show_multiple_icon_states) { |
260 show_multiple_icon_states_ = show_multiple_icon_states; | 267 show_multiple_icon_states_ = show_multiple_icon_states; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 #else | 360 #else |
354 canvas->DrawStringInt(text_, | 361 canvas->DrawStringInt(text_, |
355 font_, | 362 font_, |
356 text_color, | 363 text_color, |
357 text_bounds.x(), | 364 text_bounds.x(), |
358 text_bounds.y(), | 365 text_bounds.y(), |
359 text_bounds.width(), | 366 text_bounds.width(), |
360 text_bounds.height(), | 367 text_bounds.height(), |
361 draw_string_flags); | 368 draw_string_flags); |
362 #endif | 369 #endif |
| 370 } else if (has_text_halo_) { |
| 371 canvas->AsCanvasSkia()->DrawStringWithHalo( |
| 372 text_, font_, text_color, text_halo_color_, text_bounds.x(), |
| 373 text_bounds.y(), text_bounds.width(), text_bounds.height(), |
| 374 draw_string_flags); |
363 } else { | 375 } else { |
364 canvas->DrawStringInt(text_, | 376 canvas->DrawStringInt(text_, |
365 font_, | 377 font_, |
366 text_color, | 378 text_color, |
367 text_bounds.x(), | 379 text_bounds.x(), |
368 text_bounds.y(), | 380 text_bounds.y(), |
369 text_bounds.width(), | 381 text_bounds.width(), |
370 text_bounds.height(), | 382 text_bounds.height(), |
371 draw_string_flags); | 383 draw_string_flags); |
372 } | 384 } |
(...skipping 11 matching lines...) Expand all Loading... |
384 | 396 |
385 void TextButton::UpdateColor() { | 397 void TextButton::UpdateColor() { |
386 color_ = IsEnabled() ? color_enabled_ : color_disabled_; | 398 color_ = IsEnabled() ? color_enabled_ : color_disabled_; |
387 } | 399 } |
388 | 400 |
389 void TextButton::UpdateTextSize() { | 401 void TextButton::UpdateTextSize() { |
390 int width = 0, height = 0; | 402 int width = 0, height = 0; |
391 gfx::CanvasSkia::SizeStringInt( | 403 gfx::CanvasSkia::SizeStringInt( |
392 text_, font_, &width, &height, | 404 text_, font_, &width, &height, |
393 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); | 405 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); |
| 406 |
| 407 // Add 2 extra pixels to width and height when text halo is used. |
| 408 if (has_text_halo_) { |
| 409 width += 2; |
| 410 height += 2; |
| 411 } |
| 412 |
394 text_size_.SetSize(width, font_.GetHeight()); | 413 text_size_.SetSize(width, font_.GetHeight()); |
395 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()), | 414 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()), |
396 std::max(max_text_size_.height(), | 415 std::max(max_text_size_.height(), |
397 text_size_.height())); | 416 text_size_.height())); |
398 PreferredSizeChanged(); | 417 PreferredSizeChanged(); |
399 } | 418 } |
400 | 419 |
401 //////////////////////////////////////////////////////////////////////////////// | 420 //////////////////////////////////////////////////////////////////////////////// |
402 // TextButton, View overrides: | 421 // TextButton, View overrides: |
403 | 422 |
(...skipping 30 matching lines...) Expand all Loading... |
434 | 453 |
435 std::string TextButton::GetClassName() const { | 454 std::string TextButton::GetClassName() const { |
436 return kViewClassName; | 455 return kViewClassName; |
437 } | 456 } |
438 | 457 |
439 void TextButton::Paint(gfx::Canvas* canvas) { | 458 void TextButton::Paint(gfx::Canvas* canvas) { |
440 Paint(canvas, false); | 459 Paint(canvas, false); |
441 } | 460 } |
442 | 461 |
443 } // namespace views | 462 } // namespace views |
OLD | NEW |