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

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

Issue 10933085: Update ConstrainedWindowViews appearance according to mock (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Browser test fixes Created 8 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
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | ui/views/controls/message_box_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/button/text_button.h" 5 #include "ui/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 "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
11 #include "ui/base/animation/throb_animation.h" 11 #include "ui/base/animation/throb_animation.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/image/image.h" 14 #include "ui/gfx/image/image.h"
15 #include "ui/views/controls/button/button.h" 15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/focus_border.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "skia/ext/skia_utils_win.h" 20 #include "skia/ext/skia_utils_win.h"
20 #include "ui/base/native_theme/native_theme_win.h" 21 #include "ui/base/native_theme/native_theme_win.h"
21 #include "ui/gfx/platform_font_win.h" 22 #include "ui/gfx/platform_font_win.h"
22 #endif 23 #endif
23 24
24 namespace views { 25 namespace views {
25 26
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 color_highlight_(ui::NativeTheme::instance()->GetSystemColor( 261 color_highlight_(ui::NativeTheme::instance()->GetSystemColor(
261 ui::NativeTheme::kColorId_TextButtonHighlightColor)), 262 ui::NativeTheme::kColorId_TextButtonHighlightColor)),
262 color_hover_(ui::NativeTheme::instance()->GetSystemColor( 263 color_hover_(ui::NativeTheme::instance()->GetSystemColor(
263 ui::NativeTheme::kColorId_TextButtonHoverColor)), 264 ui::NativeTheme::kColorId_TextButtonHoverColor)),
264 text_halo_color_(0), 265 text_halo_color_(0),
265 has_text_halo_(false), 266 has_text_halo_(false),
266 active_text_shadow_color_(0), 267 active_text_shadow_color_(0),
267 inactive_text_shadow_color_(0), 268 inactive_text_shadow_color_(0),
268 has_shadow_(false), 269 has_shadow_(false),
269 shadow_offset_(gfx::Point(1, 1)), 270 shadow_offset_(gfx::Point(1, 1)),
271 min_width_(0),
272 min_height_(0),
270 max_width_(0), 273 max_width_(0),
271 show_multiple_icon_states_(true), 274 show_multiple_icon_states_(true),
272 is_default_(false), 275 is_default_(false),
273 multi_line_(false), 276 multi_line_(false),
274 prefix_type_(PREFIX_NONE) { 277 prefix_type_(PREFIX_NONE) {
275 SetText(text); 278 SetText(text);
276 SetAnimationDuration(kHoverAnimationDurationMs); 279 SetAnimationDuration(kHoverAnimationDurationMs);
277 } 280 }
278 281
279 TextButtonBase::~TextButtonBase() { 282 TextButtonBase::~TextButtonBase() {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // In multiline mode max size can be undefined while 369 // In multiline mode max size can be undefined while
367 // width() is 0, so max it out with current text size. 370 // width() is 0, so max it out with current text size.
368 gfx::Size prefsize(std::max(max_text_size_.width(), 371 gfx::Size prefsize(std::max(max_text_size_.width(),
369 text_size_.width()) + insets.width(), 372 text_size_.width()) + insets.width(),
370 std::max(max_text_size_.height(), 373 std::max(max_text_size_.height(),
371 text_size_.height()) + insets.height()); 374 text_size_.height()) + insets.height());
372 375
373 if (max_width_ > 0) 376 if (max_width_ > 0)
374 prefsize.set_width(std::min(max_width_, prefsize.width())); 377 prefsize.set_width(std::min(max_width_, prefsize.width()));
375 378
379 prefsize.set_width(std::max(prefsize.height(), min_width_));
380 prefsize.set_height(std::max(prefsize.height(), min_height_));
381
376 return prefsize; 382 return prefsize;
377 } 383 }
378 384
379 int TextButtonBase::GetHeightForWidth(int w) { 385 int TextButtonBase::GetHeightForWidth(int w) {
380 if (!multi_line_) 386 if (!multi_line_)
381 return View::GetHeightForWidth(w); 387 return View::GetHeightForWidth(w);
382 388
383 if (max_width_ > 0) 389 if (max_width_ > 0)
384 w = std::min(max_width_, w); 390 w = std::min(max_width_, w);
385 391
386 gfx::Size text_size; 392 gfx::Size text_size;
387 CalculateTextSize(&text_size, w); 393 CalculateTextSize(&text_size, w);
388 return text_size.height() + GetInsets().height(); 394 int height = text_size.height() + GetInsets().height();
395
396 return std::max(height, min_height_);
389 } 397 }
390 398
391 void TextButtonBase::OnPaint(gfx::Canvas* canvas) { 399 void TextButtonBase::OnPaint(gfx::Canvas* canvas) {
392 PaintButton(canvas, PB_NORMAL); 400 PaintButton(canvas, PB_NORMAL);
393 } 401 }
394 402
395 void TextButtonBase::OnBoundsChanged(const gfx::Rect& previous_bounds) { 403 void TextButtonBase::OnBoundsChanged(const gfx::Rect& previous_bounds) {
396 if (multi_line_) 404 if (multi_line_)
397 UpdateTextSize(); 405 UpdateTextSize();
398 } 406 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 //////////////////////////////////////////////////////////////////////////////// 673 ////////////////////////////////////////////////////////////////////////////////
666 674
667 TextButton::TextButton(ButtonListener* listener, const string16& text) 675 TextButton::TextButton(ButtonListener* listener, const string16& text)
668 : TextButtonBase(listener, text), 676 : TextButtonBase(listener, text),
669 icon_placement_(ICON_ON_LEFT), 677 icon_placement_(ICON_ON_LEFT),
670 has_hover_icon_(false), 678 has_hover_icon_(false),
671 has_pushed_icon_(false), 679 has_pushed_icon_(false),
672 icon_text_spacing_(kDefaultIconTextSpacing), 680 icon_text_spacing_(kDefaultIconTextSpacing),
673 ignore_minimum_size_(true) { 681 ignore_minimum_size_(true) {
674 set_border(new TextButtonBorder); 682 set_border(new TextButtonBorder);
683 set_focus_border(FocusBorder::CreateDashedFocusBorder(kFocusRectInset,
684 kFocusRectInset,
685 kFocusRectInset,
686 kFocusRectInset));
675 } 687 }
676 688
677 TextButton::~TextButton() { 689 TextButton::~TextButton() {
678 } 690 }
679 691
680 void TextButton::SetIcon(const gfx::ImageSkia& icon) { 692 void TextButton::SetIcon(const gfx::ImageSkia& icon) {
681 icon_ = icon; 693 icon_ = icon;
682 SchedulePaint(); 694 SchedulePaint();
683 } 695 }
684 696
(...skipping 28 matching lines...) Expand all
713 static_cast<gfx::PlatformFontWin*>(font_.platform_font()); 725 static_cast<gfx::PlatformFontWin*>(font_.platform_font());
714 prefsize.set_width(std::max( 726 prefsize.set_width(std::max(
715 prefsize.width(), 727 prefsize.width(),
716 platform_font->horizontal_dlus_to_pixels(kMinWidthDLUs))); 728 platform_font->horizontal_dlus_to_pixels(kMinWidthDLUs)));
717 prefsize.set_height(std::max( 729 prefsize.set_height(std::max(
718 prefsize.height(), 730 prefsize.height(),
719 platform_font->vertical_dlus_to_pixels(kMinHeightDLUs))); 731 platform_font->vertical_dlus_to_pixels(kMinHeightDLUs)));
720 } 732 }
721 #endif 733 #endif
722 734
735 prefsize.set_width(std::max(prefsize.height(), min_width_));
hshi1 2012/10/04 02:29:35 Shouldn't the above be prefsize.set_width(std::max
736 prefsize.set_height(std::max(prefsize.height(), min_height_));
737
723 return prefsize; 738 return prefsize;
724 } 739 }
725 740
726 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { 741 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
727 TextButtonBase::PaintButton(canvas, mode); 742 TextButtonBase::PaintButton(canvas, mode);
728 743
729 const gfx::ImageSkia& icon = GetImageToPaint(); 744 const gfx::ImageSkia& icon = GetImageToPaint();
730 745
731 if (icon.width() > 0) { 746 if (icon.width() > 0) {
732 gfx::Rect text_bounds = GetTextBounds(); 747 gfx::Rect text_bounds = GetTextBounds();
(...skipping 20 matching lines...) Expand all
753 } 768 }
754 769
755 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { 770 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) {
756 ignore_minimum_size_ = ignore_minimum_size; 771 ignore_minimum_size_ = ignore_minimum_size;
757 } 772 }
758 773
759 std::string TextButton::GetClassName() const { 774 std::string TextButton::GetClassName() const {
760 return kViewClassName; 775 return kViewClassName;
761 } 776 }
762 777
763 void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
764 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
765 gfx::Rect rect(GetLocalBounds());
766 rect.Inset(kFocusRectInset, kFocusRectInset);
767 canvas->DrawFocusRect(rect);
768 }
769 }
770
771 ui::NativeTheme::Part TextButton::GetThemePart() const { 778 ui::NativeTheme::Part TextButton::GetThemePart() const {
772 return ui::NativeTheme::kPushButton; 779 return ui::NativeTheme::kPushButton;
773 } 780 }
774 781
775 void TextButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 782 void TextButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
776 TextButtonBase::GetExtraParams(params); 783 TextButtonBase::GetExtraParams(params);
777 params->button.is_default = is_default_; 784 params->button.is_default = is_default_;
778 } 785 }
779 786
780 gfx::Rect TextButton::GetTextBounds() const { 787 gfx::Rect TextButton::GetTextBounds() const {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 834
828 void NativeTextButton::Init() { 835 void NativeTextButton::Init() {
829 #if defined(OS_WIN) 836 #if defined(OS_WIN)
830 // Windows will like to show its own colors. 837 // Windows will like to show its own colors.
831 // Halos and such are ignored as they are always set by specific calls. 838 // Halos and such are ignored as they are always set by specific calls.
832 color_enabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT)); 839 color_enabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT));
833 color_disabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_GRAYTEXT)); 840 color_disabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_GRAYTEXT));
834 color_hover_ = color_ = color_enabled_; 841 color_hover_ = color_ = color_enabled_;
835 #endif 842 #endif
836 set_border(new TextButtonNativeThemeBorder(this)); 843 set_border(new TextButtonNativeThemeBorder(this));
844 #if !defined(OS_WIN)
845 // Paint nothing, focus will be indicated with a border highlight drawn by
846 // NativeThemeBase::PaintButton.
847 set_focus_border(NULL);
848 #endif
837 set_ignore_minimum_size(false); 849 set_ignore_minimum_size(false);
838 set_alignment(ALIGN_CENTER); 850 set_alignment(ALIGN_CENTER);
839 set_focusable(true); 851 set_focusable(true);
840 } 852 }
841 853
842 gfx::Size NativeTextButton::GetMinimumSize() { 854 gfx::Size NativeTextButton::GetMinimumSize() {
843 return GetPreferredSize(); 855 return GetPreferredSize();
844 } 856 }
845 857
846 std::string NativeTextButton::GetClassName() const { 858 std::string NativeTextButton::GetClassName() const {
847 return kViewClassName; 859 return kViewClassName;
848 } 860 }
849 861
850 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
851 #if defined(OS_WIN)
852 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
853 gfx::Rect rect(GetLocalBounds());
854 rect.Inset(kFocusRectInset, kFocusRectInset);
855 canvas->DrawFocusRect(rect);
856 }
857 #else
858 // Paint nothing, focus will be indicated with a border highlight drawn by
859 // NativeThemeBase::PaintButton.
860 #endif
861 }
862
863 void NativeTextButton::GetExtraParams( 862 void NativeTextButton::GetExtraParams(
864 ui::NativeTheme::ExtraParams* params) const { 863 ui::NativeTheme::ExtraParams* params) const {
865 TextButton::GetExtraParams(params); 864 TextButton::GetExtraParams(params);
866 params->button.has_border = true; 865 params->button.has_border = true;
867 #if !defined(OS_WIN) 866 #if !defined(OS_WIN)
868 // Windows may paint a dotted focus rect in 867 // Windows may paint a dotted focus rect in
869 // NativeTextButton::OnPaintFocusBorder. To avoid getting two focus 868 // NativeTextButton::OnPaintFocusBorder. To avoid getting two focus
870 // indications (A dotted rect and a highlighted border) only set is_focused on 869 // indications (A dotted rect and a highlighted border) only set is_focused on
871 // non windows platforms. 870 // non windows platforms.
872 params->button.is_focused = HasFocus() && 871 params->button.is_focused = HasFocus() &&
873 (focusable() || IsAccessibilityFocusable()); 872 (focusable() || IsAccessibilityFocusable());
874 #endif 873 #endif
875 } 874 }
876 875
877 } // namespace views 876 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | ui/views/controls/message_box_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698