Index: ui/views/controls/label.cc |
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc |
index 06f5bac122010995e116357b9a3e639cad66e830..fb182a58384684716091109e64b16159d1022558 100644 |
--- a/ui/views/controls/label.cc |
+++ b/ui/views/controls/label.cc |
@@ -354,11 +354,8 @@ void Label::OnPaint(gfx::Canvas* canvas) { |
PaintText(canvas); |
} |
- if (HasFocus()) { |
- gfx::Rect focus_bounds = GetLocalBounds(); |
- focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); |
- canvas->DrawFocusRect(focus_bounds); |
- } |
+ if (HasFocus()) |
+ canvas->DrawFocusRect(GetFocusBounds()); |
} |
void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
@@ -433,6 +430,8 @@ void Label::MaybeBuildRenderTextLines() { |
return; |
gfx::Rect rect = GetContentsBounds(); |
+ if (focusable()) |
+ rect.Inset(kFocusBorderPadding, kFocusBorderPadding); |
if (rect.IsEmpty()) |
return; |
@@ -479,6 +478,25 @@ void Label::MaybeBuildRenderTextLines() { |
RecalculateColors(); |
} |
+gfx::Rect Label::GetFocusBounds() { |
+ MaybeBuildRenderTextLines(); |
+ |
+ gfx::Rect focus_bounds; |
+ if (lines_.empty()) { |
+ focus_bounds = gfx::Rect(GetTextSize()); |
+ } else { |
+ for (size_t i = 0; i < lines_.size(); ++i) { |
+ gfx::Point origin; |
+ origin += lines_[i]->GetLineOffset(0); |
+ focus_bounds.Union(gfx::Rect(origin, lines_[i]->GetStringSize())); |
+ } |
+ } |
+ |
+ focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); |
+ focus_bounds.Intersect(GetLocalBounds()); |
+ return focus_bounds; |
+} |
+ |
std::vector<base::string16> Label::GetLinesForWidth(int width) const { |
std::vector<base::string16> lines; |
const gfx::WordWrapBehavior wrap = |