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

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

Issue 1018463004: Fix focus rectangle for label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetFocusBounds Created 5 years, 9 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 | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 =
« no previous file with comments | « ui/views/controls/label.h ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698