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

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

Issue 111023004: Add GetMinimumSize() for Labels and ensure it's zero for empty Links. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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/link.h ('k') | ui/views/controls/styled_label.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/link.cc
===================================================================
--- ui/views/controls/link.cc (revision 239550)
+++ ui/views/controls/link.cc (working copy)
@@ -43,11 +43,6 @@
#endif
}
-void Link::OnEnabledChanged() {
- RecalculateFont();
- View::OnEnabledChanged();
-}
-
const char* Link::GetClassName() const {
return kViewClassName;
}
@@ -63,25 +58,6 @@
#endif
}
-void Link::OnPaint(gfx::Canvas* canvas) {
- Label::OnPaint(canvas);
-
- if (HasFocus())
- canvas->DrawFocusRect(GetLocalBounds());
-}
-
-void Link::OnFocus() {
- Label::OnFocus();
- // We render differently focused.
- SchedulePaint();
-}
-
-void Link::OnBlur() {
- Label::OnBlur();
- // We render differently focused.
- SchedulePaint();
-}
-
bool Link::HitTestRect(const gfx::Rect& rect) const {
// We need to allow clicks on the link. So we override the implementation in
// Label and use the default implementation of View.
@@ -139,17 +115,6 @@
return true;
}
-bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) {
- // Make sure we don't process space or enter as accelerators.
- return (event.key_code() == ui::VKEY_SPACE) ||
- (event.key_code() == ui::VKEY_RETURN);
-}
-
-void Link::GetAccessibleState(ui::AccessibleViewState* state) {
- Label::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_LINK;
-}
-
void Link::OnGestureEvent(ui::GestureEvent* event) {
if (!enabled())
return;
@@ -167,11 +132,54 @@
event->SetHandled();
}
+bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) {
+ // Make sure we don't process space or enter as accelerators.
+ return (event.key_code() == ui::VKEY_SPACE) ||
+ (event.key_code() == ui::VKEY_RETURN);
+}
+
+void Link::GetAccessibleState(ui::AccessibleViewState* state) {
+ Label::GetAccessibleState(state);
+ state->role = ui::AccessibilityTypes::ROLE_LINK;
+}
+
+void Link::OnEnabledChanged() {
+ RecalculateFont();
+ View::OnEnabledChanged();
+}
+
+void Link::OnPaint(gfx::Canvas* canvas) {
+ Label::OnPaint(canvas);
+
+ if (HasFocus())
+ canvas->DrawFocusRect(GetLocalBounds());
+}
+
+void Link::OnFocus() {
+ Label::OnFocus();
+ // We render differently focused.
+ SchedulePaint();
+}
+
+void Link::OnBlur() {
+ Label::OnBlur();
+ // We render differently focused.
+ SchedulePaint();
+}
+
void Link::SetFont(const gfx::Font& font) {
Label::SetFont(font);
RecalculateFont();
}
+void Link::SetText(const string16& text) {
+ Label::SetText(text);
+ // Disable focusability for empty links. Otherwise Label::GetInsets() will
+ // give them an unconditional 1-px. inset on every side to allow for a focus
+ // border, when in this case we probably wanted zero width.
+ set_focusable(!text.empty());
+}
+
void Link::SetEnabledColor(SkColor color) {
requested_enabled_color_ = color;
if (!pressed_)
@@ -205,7 +213,12 @@
SetPressedColor(SK_ColorRED);
#endif
RecalculateFont();
- set_focusable(true);
+
+ // Label::Init() calls SetText(), but if that's being called from Label(), our
+ // SetText() override will not be reached (because the constructed class is
+ // only a Label at the moment, not yet a Link). So so the set_focusable()
+ // call explicitly here.
+ set_focusable(!text().empty());
}
void Link::SetPressed(bool pressed) {
« no previous file with comments | « ui/views/controls/link.h ('k') | ui/views/controls/styled_label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698