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

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

Issue 10513009: Indicate focused state on text buttons with blue outline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 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"
(...skipping 25 matching lines...) Expand all
36 static const int kDefaultIconTextSpacing = 5; 36 static const int kDefaultIconTextSpacing = 5;
37 37
38 // Preferred padding between text and edge. 38 // Preferred padding between text and edge.
39 static const int kPreferredPaddingHorizontal = 6; 39 static const int kPreferredPaddingHorizontal = 6;
40 static const int kPreferredPaddingVertical = 5; 40 static const int kPreferredPaddingVertical = 5;
41 41
42 // Preferred padding between text and edge for NativeTheme border. 42 // Preferred padding between text and edge for NativeTheme border.
43 static const int kPreferredNativeThemePaddingHorizontal = 12; 43 static const int kPreferredNativeThemePaddingHorizontal = 12;
44 static const int kPreferredNativeThemePaddingVertical = 5; 44 static const int kPreferredNativeThemePaddingVertical = 5;
45 45
46 // By default the focus rect is drawn at the border of the view.
47 // For a button, we inset the focus rect by 3 pixels so that it
48 // doesn't draw on top of the button's border. This roughly matches
49 // how the Windows native focus rect for buttons looks. A subclass
50 // that draws a button with different padding may need to
51 // override OnPaintFocusBorder and do something different.
52 static const int kFocusRectInset = 3;
53
54 // How long the hover fade animation should last. 46 // How long the hover fade animation should last.
55 static const int kHoverAnimationDurationMs = 170; 47 static const int kHoverAnimationDurationMs = 170;
56 48
57 // static 49 // static
58 const char TextButtonBase::kViewClassName[] = "views/TextButtonBase"; 50 const char TextButtonBase::kViewClassName[] = "views/TextButtonBase";
59 // static 51 // static
60 const char TextButton::kViewClassName[] = "views/TextButton"; 52 const char TextButton::kViewClassName[] = "views/TextButton";
61 // static 53 // static
62 const char NativeTextButton::kViewClassName[] = "views/NativeTextButton"; 54 const char NativeTextButton::kViewClassName[] = "views/NativeTextButton";
63 55
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 455
464 return flags; 456 return flags;
465 } 457 }
466 458
467 void TextButtonBase::GetExtraParams( 459 void TextButtonBase::GetExtraParams(
468 ui::NativeTheme::ExtraParams* params) const { 460 ui::NativeTheme::ExtraParams* params) const {
469 params->button.checked = false; 461 params->button.checked = false;
470 params->button.indeterminate = false; 462 params->button.indeterminate = false;
471 params->button.is_default = false; 463 params->button.is_default = false;
472 params->button.has_border = false; 464 params->button.has_border = false;
465 params->button.is_focused = HasFocus();
473 params->button.classic_state = 0; 466 params->button.classic_state = 0;
474 params->button.background_color = 467 params->button.background_color =
475 ui::NativeTheme::instance()->GetSystemColor( 468 ui::NativeTheme::instance()->GetSystemColor(
476 ui::NativeTheme::kColorId_TextButtonBackgroundColor); 469 ui::NativeTheme::kColorId_TextButtonBackgroundColor);
477 } 470 }
478 471
479 gfx::Rect TextButtonBase::GetContentBounds(int extra_width) const { 472 gfx::Rect TextButtonBase::GetContentBounds(int extra_width) const {
480 gfx::Insets insets = GetInsets(); 473 gfx::Insets insets = GetInsets();
481 int available_width = width() - insets.width(); 474 int available_width = width() - insets.width();
482 int content_width = text_size_.width() + extra_width; 475 int content_width = text_size_.width() + extra_width;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 742
750 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) { 743 void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) {
751 ignore_minimum_size_ = ignore_minimum_size; 744 ignore_minimum_size_ = ignore_minimum_size;
752 } 745 }
753 746
754 std::string TextButton::GetClassName() const { 747 std::string TextButton::GetClassName() const {
755 return kViewClassName; 748 return kViewClassName;
756 } 749 }
757 750
758 void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { 751 void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
759 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
tony 2012/06/04 19:20:45 Is it OK to lose the focusable() || IsAccessibilit
xiyuan 2012/06/04 19:46:54 I have the same question. Should we do "params->bu
flackr 2012/06/05 14:13:18 You're absolutely right, I originally had this and
760 gfx::Rect rect(GetLocalBounds());
761 rect.Inset(kFocusRectInset, kFocusRectInset);
762 canvas->DrawFocusRect(rect);
763 }
764 } 752 }
765 753
766 ui::NativeTheme::Part TextButton::GetThemePart() const { 754 ui::NativeTheme::Part TextButton::GetThemePart() const {
767 return ui::NativeTheme::kPushButton; 755 return ui::NativeTheme::kPushButton;
768 } 756 }
769 757
770 void TextButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { 758 void TextButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
771 TextButtonBase::GetExtraParams(params); 759 TextButtonBase::GetExtraParams(params);
772 params->button.is_default = is_default_; 760 params->button.is_default = is_default_;
773 } 761 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 824
837 gfx::Size NativeTextButton::GetMinimumSize() { 825 gfx::Size NativeTextButton::GetMinimumSize() {
838 return GetPreferredSize(); 826 return GetPreferredSize();
839 } 827 }
840 828
841 std::string NativeTextButton::GetClassName() const { 829 std::string NativeTextButton::GetClassName() const {
842 return kViewClassName; 830 return kViewClassName;
843 } 831 }
844 832
845 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { 833 void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
846 #if defined(OS_WIN)
xiyuan 2012/06/04 19:46:54 Would this break Windows?
flackr 2012/06/05 14:13:18 I tried in Windows (7) and it draws a similar look
847 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) {
848 gfx::Rect rect(GetLocalBounds());
849 rect.Inset(kFocusRectInset, kFocusRectInset);
850 canvas->DrawFocusRect(rect);
851 }
852 #else
853 TextButton::OnPaintFocusBorder(canvas);
854 #endif
855 } 834 }
856 835
857 void NativeTextButton::GetExtraParams( 836 void NativeTextButton::GetExtraParams(
858 ui::NativeTheme::ExtraParams* params) const { 837 ui::NativeTheme::ExtraParams* params) const {
859 TextButton::GetExtraParams(params); 838 TextButton::GetExtraParams(params);
860 params->button.has_border = true; 839 params->button.has_border = true;
861 } 840 }
862 841
863 } // namespace views 842 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698