Commit cbf1658e authored by Wei Li's avatar Wei Li Committed by Commit Bot

Remove unused link focus style

Link class used to have two focus styles: focus ring and underline. Now
we always use underline focus style. So remove all the code related to
supporting different focus styles.

BUG=none
TEST=nothing should change.

Change-Id: I80b826ff246e0fbfd18c73f79b17f7e34f43a740
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2138781
Commit-Queue: Wei Li <weili@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757202}
parent 80d938f7
...@@ -215,7 +215,6 @@ void CardUnmaskPromptViews::ShowNewCardLink() { ...@@ -215,7 +215,6 @@ void CardUnmaskPromptViews::ShowNewCardLink() {
auto new_card_link = std::make_unique<views::Link>( auto new_card_link = std::make_unique<views::Link>(
l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK)); l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_NEW_CARD_LINK));
new_card_link->SetUnderline(false);
new_card_link->set_callback(base::BindRepeating( new_card_link->set_callback(base::BindRepeating(
&CardUnmaskPromptViews::LinkClicked, base::Unretained(this))); &CardUnmaskPromptViews::LinkClicked, base::Unretained(this)));
new_card_link_ = input_row_->AddChildView(std::move(new_card_link)); new_card_link_ = input_row_->AddChildView(std::move(new_card_link));
......
...@@ -265,7 +265,6 @@ void ExtensionInstalledBubbleView::Init() { ...@@ -265,7 +265,6 @@ void ExtensionInstalledBubbleView::Init() {
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS))); l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)));
manage_shortcut->set_callback(base::BindRepeating( manage_shortcut->set_callback(base::BindRepeating(
&ExtensionInstalledBubbleView::LinkClicked, base::Unretained(this))); &ExtensionInstalledBubbleView::LinkClicked, base::Unretained(this)));
manage_shortcut->SetUnderline(false);
} }
if (model_->show_how_to_manage()) { if (model_->show_how_to_manage()) {
......
...@@ -153,7 +153,6 @@ ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews( ...@@ -153,7 +153,6 @@ ScreenCaptureNotificationUIViews::ScreenCaptureNotificationUIViews(
view->GetWidget()->Minimize(); view->GetWidget()->Minimize();
}, },
base::Unretained(this))); base::Unretained(this)));
hide_link->SetUnderline(false);
hide_link_ = AddChildView(std::move(hide_link)); hide_link_ = AddChildView(std::move(hide_link));
// The client rect for NotificationBarClientView uses the bounds for the // The client rect for NotificationBarClientView uses the bounds for the
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
namespace views { namespace views {
// static
constexpr gfx::Insets Link::kFocusBorderPadding;
Link::Link(const base::string16& title, int text_context, int text_style) Link::Link(const base::string16& title, int text_context, int text_style)
: Label(title, text_context, text_style) { : Label(title, text_context, text_style) {
RecalculateFont(); RecalculateFont();
...@@ -39,12 +36,6 @@ Link::Link(const base::string16& title, int text_context, int text_style) ...@@ -39,12 +36,6 @@ Link::Link(const base::string16& title, int text_context, int text_style)
Link::~Link() = default; Link::~Link() = default;
Link::FocusStyle Link::GetFocusStyle() const {
// Use an underline to indicate focus unless the link is always drawn with an
// underline.
return underline_ ? FocusStyle::kRing : FocusStyle::kUnderline;
}
SkColor Link::GetColor() const { SkColor Link::GetColor() const {
// TODO(tapted): Use style::GetColor(). // TODO(tapted): Use style::GetColor().
const ui::NativeTheme* theme = GetNativeTheme(); const ui::NativeTheme* theme = GetNativeTheme();
...@@ -60,25 +51,6 @@ SkColor Link::GetColor() const { ...@@ -60,25 +51,6 @@ SkColor Link::GetColor() const {
: ui::NativeTheme::kColorId_LinkEnabled); : ui::NativeTheme::kColorId_LinkEnabled);
} }
void Link::PaintFocusRing(gfx::Canvas* canvas) const {
if (GetFocusStyle() == FocusStyle::kRing) {
gfx::Rect focus_ring_bounds = GetTextBounds();
focus_ring_bounds.Inset(-kFocusBorderPadding);
focus_ring_bounds.Intersect(GetLocalBounds());
canvas->DrawFocusRect(focus_ring_bounds);
}
}
gfx::Insets Link::GetInsets() const {
gfx::Insets insets = Label::GetInsets();
if (GetFocusStyle() == FocusStyle::kRing &&
GetFocusBehavior() != FocusBehavior::NEVER) {
DCHECK(!GetText().empty());
insets += kFocusBorderPadding;
}
return insets;
}
gfx::NativeCursor Link::GetCursor(const ui::MouseEvent& event) { gfx::NativeCursor Link::GetCursor(const ui::MouseEvent& event) {
if (!GetEnabled()) if (!GetEnabled())
return gfx::kNullCursor; return gfx::kNullCursor;
...@@ -214,18 +186,6 @@ bool Link::IsSelectionSupported() const { ...@@ -214,18 +186,6 @@ bool Link::IsSelectionSupported() const {
return false; return false;
} }
bool Link::GetUnderline() const {
return underline_;
}
void Link::SetUnderline(bool underline) {
if (underline_ == underline)
return;
underline_ = underline;
RecalculateFont();
OnPropertyChanged(&underline_, kPropertyEffectsPreferredSizeChanged);
}
void Link::SetPressed(bool pressed) { void Link::SetPressed(bool pressed) {
if (pressed_ != pressed) { if (pressed_ != pressed) {
pressed_ = pressed; pressed_ = pressed;
...@@ -236,12 +196,8 @@ void Link::SetPressed(bool pressed) { ...@@ -236,12 +196,8 @@ void Link::SetPressed(bool pressed) {
} }
void Link::RecalculateFont() { void Link::RecalculateFont() {
// Underline the link if it is enabled and |underline_| is true. Also
// underline to indicate focus when that's the style.
const int style = font_list().GetFontStyle(); const int style = font_list().GetFontStyle();
const bool underline = const int intended_style = (GetEnabled() && HasFocus())
underline_ || (HasFocus() && GetFocusStyle() == FocusStyle::kUnderline);
const int intended_style = (GetEnabled() && underline)
? (style | gfx::Font::UNDERLINE) ? (style | gfx::Font::UNDERLINE)
: (style & ~gfx::Font::UNDERLINE); : (style & ~gfx::Font::UNDERLINE);
...@@ -262,15 +218,9 @@ void Link::ConfigureFocus() { ...@@ -262,15 +218,9 @@ void Link::ConfigureFocus() {
} }
} }
DEFINE_ENUM_CONVERTERS(Link::FocusStyle,
{Link::FocusStyle::kUnderline,
base::ASCIIToUTF16("UNDERLINE")},
{Link::FocusStyle::kRing, base::ASCIIToUTF16("RING")})
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, SkColor, Color)
ADD_READONLY_PROPERTY_METADATA(Link, Link::FocusStyle, FocusStyle)
ADD_PROPERTY_METADATA(Link, bool, Underline)
END_METADATA() END_METADATA()
} // namespace views } // namespace views
...@@ -35,24 +35,11 @@ class VIEWS_EXPORT Link : public Label { ...@@ -35,24 +35,11 @@ class VIEWS_EXPORT Link : public Label {
using ClickedCallback = using ClickedCallback =
base::RepeatingCallback<void(Link* source, int event_flags)>; base::RepeatingCallback<void(Link* source, int event_flags)>;
// The padding for the focus ring border when rendering a focused Link with
// FocusStyle::kRing.
static constexpr gfx::Insets kFocusBorderPadding = gfx::Insets(1);
// How the Link is styled when focused.
enum class FocusStyle {
kUnderline, // An underline style is added to the text only when focused.
kRing, // A focus ring is drawn around the View.
};
explicit Link(const base::string16& title, explicit Link(const base::string16& title,
int text_context = style::CONTEXT_LABEL, int text_context = style::CONTEXT_LABEL,
int text_style = style::STYLE_LINK); int text_style = style::STYLE_LINK);
~Link() override; ~Link() override;
// Returns the current FocusStyle of this Link.
FocusStyle GetFocusStyle() const;
// Allow providing callbacks that expect either zero or two args, since many // Allow providing callbacks that expect either zero or two args, since many
// callers don't care about the arguments and can avoid adapter functions this // callers don't care about the arguments and can avoid adapter functions this
// way. // way.
...@@ -69,8 +56,6 @@ class VIEWS_EXPORT Link : public Label { ...@@ -69,8 +56,6 @@ class VIEWS_EXPORT Link : public Label {
SkColor GetColor() const; SkColor GetColor() const;
// Label: // Label:
void PaintFocusRing(gfx::Canvas* canvas) const override;
gfx::Insets GetInsets() const override;
gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
bool CanProcessEventsWithinSubtree() const override; bool CanProcessEventsWithinSubtree() const override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
...@@ -89,13 +74,6 @@ class VIEWS_EXPORT Link : public Label { ...@@ -89,13 +74,6 @@ 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
// Harmony, false is already the default so those callsites can be removed.
// TODO(tapted): Then remove all callsites when client code sets a correct
// typography style and derives this from style::GetFont(STYLE_LINK).
void SetUnderline(bool underline);
private: private:
void SetPressed(bool pressed); void SetPressed(bool pressed);
...@@ -105,9 +83,6 @@ class VIEWS_EXPORT Link : public Label { ...@@ -105,9 +83,6 @@ class VIEWS_EXPORT Link : public Label {
ClickedCallback callback_; ClickedCallback callback_;
// Whether the link should be underlined when enabled.
bool underline_ = false;
// Whether the link is currently pressed. // Whether the link is currently pressed.
bool pressed_ = false; bool pressed_ = false;
......
...@@ -556,9 +556,6 @@ std::unique_ptr<Label> StyledLabel::CreateLabel( ...@@ -556,9 +556,6 @@ std::unique_ptr<Label> StyledLabel::CreateLabel(
// Note this ignores |default_text_style_|, in favor of style::STYLE_LINK. // Note this ignores |default_text_style_|, in favor of style::STYLE_LINK.
auto link = std::make_unique<Link>(text, text_context_); auto link = std::make_unique<Link>(text, text_context_);
// Links in a StyledLabel do not get underlines.
link->SetUnderline(false);
layout_views_->link_targets[link.get()] = range; layout_views_->link_targets[link.get()] = range;
result = std::move(link); result = std::move(link);
......
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