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

Unified Diff: chrome/views/controls/label.cc

Issue 92004: Fix focus rects for checkboxes and radio buttons:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/views/controls/label.h ('k') | chrome/views/controls/label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/views/controls/label.cc
===================================================================
--- chrome/views/controls/label.cc (revision 14145)
+++ chrome/views/controls/label.cc (working copy)
@@ -22,6 +22,7 @@
static const SkColor kEnabledColor = SK_ColorBLACK;
static const SkColor kDisabledColor = SkColorSetRGB(161, 161, 146);
+static const int kFocusBorderPadding = 1;
Label::Label() {
Init(L"", GetDefaultFont());
@@ -46,6 +47,7 @@
is_multi_line_ = false;
collapse_when_hidden_ = false;
rtl_alignment_mode_ = USE_UI_ALIGNMENT;
+ paint_as_focused_ = false;
}
Label::~Label() {
@@ -143,15 +145,21 @@
text_bounds.height(),
flags);
- if (is_multi_line_) {
- PaintFocusBorder(canvas);
- } else {
- // We'll draw the focus border ourselves, so it is around the text.
- if (HasFocus())
- canvas->DrawFocusRect(text_bounds.x(),
- text_bounds.y(),
- text_bounds.width(),
- text_bounds.height());
+ // The focus border always hugs the text, regardless of the label's bounds.
+ if (HasFocus() || paint_as_focused_) {
+ int w = text_bounds.width();
+ int h = 0;
+ // We explicitly OR in MULTI_LINE here since SizeStringInt seems to return
+ // an incorrect height for single line text when the MULTI_LINE flag isn't
+ // specified. o_O...
+ ChromeCanvas::SizeStringInt(paint_text, font_, &w, &h,
+ flags | ChromeCanvas::MULTI_LINE);
+ gfx::Rect focus_rect = text_bounds;
+ focus_rect.set_width(w);
+ focus_rect.set_height(h);
+ focus_rect.Inset(-kFocusBorderPadding, -kFocusBorderPadding);
+ canvas->DrawFocusRect(focus_rect.x(), focus_rect.y(), focus_rect.width(),
+ focus_rect.height());
}
}
@@ -325,6 +333,15 @@
SetColor(enabled ? kEnabledColor : kDisabledColor);
}
+gfx::Insets Label::GetInsets() const {
+ gfx::Insets insets = View::GetInsets();
+ if (IsFocusable() || paint_as_focused_) {
+ insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding,
+ kFocusBorderPadding, kFocusBorderPadding);
+ }
+ return insets;
+}
+
// static
ChromeFont Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
« no previous file with comments | « chrome/views/controls/label.h ('k') | chrome/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698