Commit bda24832 authored by Kristyn Hamasaki's avatar Kristyn Hamasaki Committed by Commit Bot

Convert Link fields to be properties

Change-Id: Iaf08c1356f929605bef59a5e6e9a1829e9b868ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721293Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Kristyn Hamasaki <khamasaki@google.com>
Cr-Commit-Position: refs/heads/master@{#682380}
parent 8790fef2
...@@ -47,6 +47,21 @@ Link::FocusStyle Link::GetFocusStyle() const { ...@@ -47,6 +47,21 @@ Link::FocusStyle Link::GetFocusStyle() const {
return GetDefaultFocusStyle(); return GetDefaultFocusStyle();
} }
SkColor Link::GetColor() const {
// TODO(tapted): Use style::GetColor().
const ui::NativeTheme* theme = GetNativeTheme();
DCHECK(theme);
if (!GetEnabled())
return theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled);
if (requested_enabled_color_set_)
return requested_enabled_color_;
return GetNativeTheme()->GetSystemColor(
pressed_ ? ui::NativeTheme::kColorId_LinkPressed
: ui::NativeTheme::kColorId_LinkEnabled);
}
void Link::PaintFocusRing(gfx::Canvas* canvas) const { void Link::PaintFocusRing(gfx::Canvas* canvas) const {
if (GetFocusStyle() == FocusStyle::RING) { if (GetFocusStyle() == FocusStyle::RING) {
gfx::Rect focus_ring_bounds = GetTextBounds(); gfx::Rect focus_ring_bounds = GetTextBounds();
...@@ -200,11 +215,16 @@ bool Link::IsSelectionSupported() const { ...@@ -200,11 +215,16 @@ bool Link::IsSelectionSupported() const {
return false; return false;
} }
bool Link::GetUnderline() const {
return underline_;
}
void Link::SetUnderline(bool underline) { void Link::SetUnderline(bool underline) {
if (underline_ == underline) if (underline_ == underline)
return; return;
underline_ = underline; underline_ = underline;
RecalculateFont(); RecalculateFont();
OnPropertyChanged(&underline_, kPropertyEffectsPreferredSizeChanged);
} }
void Link::Init() { void Link::Init() {
...@@ -259,23 +279,15 @@ void Link::ConfigureFocus() { ...@@ -259,23 +279,15 @@ void Link::ConfigureFocus() {
} }
} }
SkColor Link::GetColor() { DEFINE_ENUM_CONVERTERS(Link::FocusStyle,
// TODO(tapted): Use style::GetColor(). {Link::FocusStyle::UNDERLINE,
const ui::NativeTheme* theme = GetNativeTheme(); base::ASCIIToUTF16("UNDERLINE")},
DCHECK(theme); {Link::FocusStyle::RING, base::ASCIIToUTF16("RING")})
if (!GetEnabled())
return theme->GetSystemColor(ui::NativeTheme::kColorId_LinkDisabled);
if (requested_enabled_color_set_)
return requested_enabled_color_;
return GetNativeTheme()->GetSystemColor(
pressed_ ? ui::NativeTheme::kColorId_LinkPressed
: ui::NativeTheme::kColorId_LinkEnabled);
}
BEGIN_METADATA(Link) BEGIN_METADATA(Link)
METADATA_PARENT_CLASS(Label) METADATA_PARENT_CLASS(Label)
ADD_READONLY_PROPERTY_METADATA(Link, SkColor, Color)
ADD_READONLY_PROPERTY_METADATA(Link, Link::FocusStyle, FocusStyle)
ADD_PROPERTY_METADATA(Link, bool, Underline)
END_METADATA() END_METADATA()
} // namespace views } // namespace views
...@@ -53,6 +53,8 @@ class VIEWS_EXPORT Link : public Label { ...@@ -53,6 +53,8 @@ class VIEWS_EXPORT Link : public Label {
const LinkListener* listener() { return listener_; } const LinkListener* listener() { return listener_; }
void set_listener(LinkListener* listener) { listener_ = listener; } void set_listener(LinkListener* listener) { listener_ = listener; }
SkColor GetColor() const;
// Label: // Label:
void PaintFocusRing(gfx::Canvas* canvas) const override; void PaintFocusRing(gfx::Canvas* canvas) const override;
gfx::Insets GetInsets() const override; gfx::Insets GetInsets() const override;
...@@ -74,6 +76,7 @@ class VIEWS_EXPORT Link : public Label { ...@@ -74,6 +76,7 @@ class VIEWS_EXPORT Link : public Label {
void SetEnabledColor(SkColor color) override; void SetEnabledColor(SkColor color) override;
bool IsSelectionSupported() const override; bool IsSelectionSupported() const override;
bool GetUnderline() const;
// TODO(estade): almost all the places that call this pass false. With // TODO(estade): almost all the places that call this pass false. With
// Harmony, false is already the default so those callsites can be removed. // Harmony, false is already the default so those callsites can be removed.
// TODO(tapted): Then remove all callsites when client code sets a correct // TODO(tapted): Then remove all callsites when client code sets a correct
...@@ -89,8 +92,6 @@ class VIEWS_EXPORT Link : public Label { ...@@ -89,8 +92,6 @@ class VIEWS_EXPORT Link : public Label {
void ConfigureFocus(); void ConfigureFocus();
SkColor GetColor();
LinkListener* listener_; LinkListener* listener_;
// Whether the link should be underlined when enabled. // Whether the link should be underlined when enabled.
......
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