diff options
author | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 05:29:44 +0000 |
---|---|---|
committer | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-06 05:29:44 +0000 |
commit | 6f6f64d7d764408b12b5ac96a24522298b71a8db (patch) | |
tree | c1aaef3cc10336f5fa69319522cf272380b2837b | |
parent | 527c7f372a3362b009831407126e34647dbe30bd (diff) | |
download | chromium_src-6f6f64d7d764408b12b5ac96a24522298b71a8db.zip chromium_src-6f6f64d7d764408b12b5ac96a24522298b71a8db.tar.gz chromium_src-6f6f64d7d764408b12b5ac96a24522298b71a8db.tar.bz2 |
Indicate focused state on text buttons with blue outline.
BUG=118040
TEST=Visit http://www.pagetutor.com/keeper/mystash/secretstuff.html and focus the native views text buttons. They should get a blue outline to indicate focus. Examine native web buttons which should be unaffected by this patch.
Review URL: https://chromiumcodereview.appspot.com/10513009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ui/base/native_theme/native_theme.h | 1 | ||||
-rw-r--r-- | ui/base/native_theme/native_theme_base.cc | 14 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.cc | 12 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.h | 6 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_android.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_linux.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_win.cc | 2 |
7 files changed, 30 insertions, 9 deletions
diff --git a/ui/base/native_theme/native_theme.h b/ui/base/native_theme/native_theme.h index b37b1e7..7a7af67 100644 --- a/ui/base/native_theme/native_theme.h +++ b/ui/base/native_theme/native_theme.h @@ -93,6 +93,7 @@ class UI_EXPORT NativeTheme { bool checked; bool indeterminate; // Whether the button state is indeterminate. bool is_default; // Whether the button is default button. + bool is_focused; bool has_border; int classic_state; // Used on Windows when uxtheme is not available. SkColor background_color; diff --git a/ui/base/native_theme/native_theme_base.cc b/ui/base/native_theme/native_theme_base.cc index a44c59e0a..7a446fa 100644 --- a/ui/base/native_theme/native_theme_base.cc +++ b/ui/base/native_theme/native_theme_base.cc @@ -487,9 +487,9 @@ void NativeThemeBase::PaintRadio(SkCanvas* canvas, } void NativeThemeBase::PaintButton(SkCanvas* canvas, - State state, - const gfx::Rect& rect, - const ButtonExtraParams& button) const { + State state, + const gfx::Rect& rect, + const ButtonExtraParams& button) const { SkPaint paint; const int kRight = rect.right(); const int kBottom = rect.bottom(); @@ -531,10 +531,14 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas, paint.setShader(NULL); if (button.has_border) { - const int kBorderAlpha = state == kHovered ? 0x80 : 0x55; + int border_alpha = state == kHovered ? 0x80 : 0x55; + if (button.is_focused) { + border_alpha = 0xff; + paint.setColor(GetSystemColor(kColorId_FocusedBorderColor)); + } paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(SkIntToScalar(1)); - paint.setARGB(kBorderAlpha, 0, 0, 0); + paint.setAlpha(border_alpha); skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); } diff --git a/ui/views/controls/button/text_button.cc b/ui/views/controls/button/text_button.cc index 32f1b21..bb3aa59 100644 --- a/ui/views/controls/button/text_button.cc +++ b/ui/views/controls/button/text_button.cc @@ -469,6 +469,7 @@ void TextButtonBase::GetExtraParams( params->button.checked = false; params->button.indeterminate = false; params->button.is_default = false; + params->button.is_focused = false; params->button.has_border = false; params->button.classic_state = 0; params->button.background_color = @@ -850,7 +851,8 @@ void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { canvas->DrawFocusRect(rect); } #else - TextButton::OnPaintFocusBorder(canvas); + // Paint nothing, focus will be indicated with a border highlight drawn by + // NativeThemeBase::PaintButton. #endif } @@ -858,6 +860,14 @@ void NativeTextButton::GetExtraParams( ui::NativeTheme::ExtraParams* params) const { TextButton::GetExtraParams(params); params->button.has_border = true; +#if !defined(OS_WIN) + // Windows may paint a dotted focus rect in + // NativeTextButton::OnPaintFocusBorder. To avoid getting two focus + // indications (A dotted rect and a highlighted border) only set is_focused on + // non windows platforms. + params->button.is_focused = HasFocus() && + (focusable() || IsAccessibilityFocusable()); +#endif } } // namespace views diff --git a/ui/views/controls/button/text_button.h b/ui/views/controls/button/text_button.h index dcb78ca..ba78db1 100644 --- a/ui/views/controls/button/text_button.h +++ b/ui/views/controls/button/text_button.h @@ -401,6 +401,9 @@ class VIEWS_EXPORT NativeTextButton : public TextButton { explicit NativeTextButton(ButtonListener* listener); NativeTextButton(ButtonListener* listener, const string16& text); + // Overridden from View: + virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; + // Overridden from TextButton: virtual gfx::Size GetMinimumSize() OVERRIDE; virtual std::string GetClassName() const OVERRIDE; @@ -408,9 +411,6 @@ class VIEWS_EXPORT NativeTextButton : public TextButton { private: void Init(); - // Overridden from View: - virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; - // Overridden from TextButton: virtual void GetExtraParams( ui::NativeTheme::ExtraParams* params) const OVERRIDE; diff --git a/webkit/glue/webthemeengine_impl_android.cc b/webkit/glue/webthemeengine_impl_android.cc index 30b3e76..f9fb758 100644 --- a/webkit/glue/webthemeengine_impl_android.cc +++ b/webkit/glue/webthemeengine_impl_android.cc @@ -107,6 +107,8 @@ static void GetNativeThemeExtraParams( extra_params->button.isDefault; native_theme_extra_params->button.has_border = extra_params->button.hasBorder; + // Native buttons have a different focus style. + native_theme_extra_params->button.is_focused = false; native_theme_extra_params->button.background_color = extra_params->button.backgroundColor; break; diff --git a/webkit/glue/webthemeengine_impl_linux.cc b/webkit/glue/webthemeengine_impl_linux.cc index 8bd81f4..4166765 100644 --- a/webkit/glue/webthemeengine_impl_linux.cc +++ b/webkit/glue/webthemeengine_impl_linux.cc @@ -104,6 +104,8 @@ static void GetNativeThemeExtraParams( extra_params->button.isDefault; native_theme_extra_params->button.has_border = extra_params->button.hasBorder; + // Native buttons have a different focus style. + native_theme_extra_params->button.is_focused = false; native_theme_extra_params->button.background_color = extra_params->button.backgroundColor; break; diff --git a/webkit/glue/webthemeengine_impl_win.cc b/webkit/glue/webthemeengine_impl_win.cc index d717b32..30464e0 100644 --- a/webkit/glue/webthemeengine_impl_win.cc +++ b/webkit/glue/webthemeengine_impl_win.cc @@ -30,6 +30,8 @@ static RECT WebRectToRECT(const WebRect& rect) { static ui::NativeTheme::State WebButtonStateToGfx( int part, int state, ui::NativeTheme::ButtonExtraParams* extra) { ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal; + // Native buttons have a different focus style. + extra->is_focused = false; if (part == BP_PUSHBUTTON) { switch (state) { |