Commit ac08b147 authored by dmazzoni@chromium.org's avatar dmazzoni@chromium.org

Make infobar controls focusable by default.

This also fixes views::TextButton so that the focus rect is drawn
with an appropriate inset.

TEST=Trigger an infobar (Translate, Save Password, etc.), type Ctrl+L to focus location bar, press Tab to focus controls in info bar.

Review URL: http://codereview.chromium.org/8439015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108202 0039d316-1c4b-4281-b951-d872f2087c98
parent 9931875b
...@@ -76,6 +76,7 @@ void ExtensionInfoBar::ViewHierarchyChanged(bool is_add, ...@@ -76,6 +76,7 @@ void ExtensionInfoBar::ViewHierarchyChanged(bool is_add,
menu_ = new views::MenuButton(NULL, string16(), this, false); menu_ = new views::MenuButton(NULL, string16(), this, false);
menu_->SetVisible(false); menu_->SetVisible(false);
menu_->set_focusable(true);
AddChildView(menu_); AddChildView(menu_);
ExtensionHost* extension_host = GetDelegate()->extension_host(); ExtensionHost* extension_host = GetDelegate()->extension_host();
......
...@@ -94,6 +94,7 @@ views::Link* InfoBarView::CreateLink(const string16& text, ...@@ -94,6 +94,7 @@ views::Link* InfoBarView::CreateLink(const string16& text,
link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
link->set_listener(listener); link->set_listener(listener);
link->SetBackgroundColor(background()->get_color()); link->SetBackgroundColor(background()->get_color());
link->set_focusable(true);
return link; return link;
} }
...@@ -112,6 +113,7 @@ views::MenuButton* InfoBarView::CreateMenuButton( ...@@ -112,6 +113,7 @@ views::MenuButton* InfoBarView::CreateMenuButton(
menu_button->SetHighlightColor(SK_ColorBLACK); menu_button->SetHighlightColor(SK_ColorBLACK);
menu_button->SetHoverColor(SK_ColorBLACK); menu_button->SetHoverColor(SK_ColorBLACK);
menu_button->SetFont(rb.GetFont(ResourceBundle::MediumFont)); menu_button->SetFont(rb.GetFont(ResourceBundle::MediumFont));
menu_button->set_focusable(true);
return menu_button; return menu_button;
} }
...@@ -151,6 +153,7 @@ views::TextButton* InfoBarView::CreateTextButton( ...@@ -151,6 +153,7 @@ views::TextButton* InfoBarView::CreateTextButton(
} }
} }
#endif #endif
text_button->set_focusable(true);
return text_button; return text_button;
} }
......
...@@ -34,14 +34,22 @@ static const int kMinHeightDLUs = 14; ...@@ -34,14 +34,22 @@ static const int kMinHeightDLUs = 14;
// Default space between the icon and text. // Default space between the icon and text.
static const int kDefaultIconTextSpacing = 5; static const int kDefaultIconTextSpacing = 5;
// Preferred padding between text and edge // Preferred padding between text and edge.
static const int kPreferredPaddingHorizontal = 6; static const int kPreferredPaddingHorizontal = 6;
static const int kPreferredPaddingVertical = 5; static const int kPreferredPaddingVertical = 5;
// Preferred padding between text and edge for NativeTheme border // Preferred padding between text and edge for NativeTheme border.
static const int kPreferredNativeThemePaddingHorizontal = 12; static const int kPreferredNativeThemePaddingHorizontal = 12;
static const int kPreferredNativeThemePaddingVertical = 5; static const int kPreferredNativeThemePaddingVertical = 5;
// By default the focus rect is drawn at the border of the view.
// For a button, we inset the focus rect by 3 pixels so that it
// doesn't draw on top of the button's border. This roughly matches
// how the Windows native focus rect for buttons looks. A subclass
// that draws a button with different padding may need to
// override OnPaintFocusBorder and do something different.
static const int kFocusRectInset = 3;
// Default background color for buttons. // Default background color for buttons.
const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde);
...@@ -744,6 +752,14 @@ std::string TextButton::GetClassName() const { ...@@ -744,6 +752,14 @@ std::string TextButton::GetClassName() const {
return kViewClassName; return kViewClassName;
} }
void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) {
gfx::Rect rect(GetLocalBounds());
rect.Inset(kFocusRectInset, kFocusRectInset);
canvas->DrawFocusRect(rect);
}
}
gfx::NativeTheme::Part TextButton::GetThemePart() const { gfx::NativeTheme::Part TextButton::GetThemePart() const {
return gfx::NativeTheme::kPushButton; return gfx::NativeTheme::kPushButton;
} }
...@@ -825,11 +841,9 @@ std::string NativeTextButton::GetClassName() const { ...@@ -825,11 +841,9 @@ std::string NativeTextButton::GetClassName() const {
void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) { void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
#if defined(OS_WIN) #if defined(OS_WIN)
// On windows, make sure the focus border is inset wrt the entire button so
// that the native text button appears more like a windows button.
if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) { if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) {
gfx::Rect rect(GetLocalBounds()); gfx::Rect rect(GetLocalBounds());
rect.Inset(3, 3); rect.Inset(kFocusRectInset, kFocusRectInset);
canvas->DrawFocusRect(rect); canvas->DrawFocusRect(rect);
} }
#else #else
......
...@@ -348,6 +348,7 @@ class VIEWS_EXPORT TextButton : public TextButtonBase { ...@@ -348,6 +348,7 @@ class VIEWS_EXPORT TextButton : public TextButtonBase {
// Overridden from View: // Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual std::string GetClassName() const OVERRIDE; virtual std::string GetClassName() const OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
// Overridden from TextButtonBase: // Overridden from TextButtonBase:
virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment