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

Unified Diff: ui/views/controls/button/md_text_button.cc

Issue 2383243002: Refactor MdFocusRing to make it easier to reuse on other controls. (Closed)
Patch Set: install Created 4 years, 2 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/button/md_text_button.h ('k') | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/md_text_button.cc
diff --git a/ui/views/controls/button/md_text_button.cc b/ui/views/controls/button/md_text_button.cc
index b81c989fcee101f38a8106eb0311648cb7af6c48..43d7b153fc274eb01c463d866b5be109677c3bb3 100644
--- a/ui/views/controls/button/md_text_button.cc
+++ b/ui/views/controls/button/md_text_button.cc
@@ -16,6 +16,7 @@
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/blue_button.h"
+#include "ui/views/controls/focus_ring.h"
#include "ui/views/painter.h"
#include "ui/views/style/platform_style.h"
@@ -26,12 +27,6 @@ namespace {
// Minimum size to reserve for the button contents.
const int kMinWidth = 48;
-// The stroke width of the focus border in dp.
-const int kFocusBorderThickness = 2;
-
-// The corner radius of the focus border roundrect.
-const int kFocusBorderCornerRadius = 3;
-
LabelButton* CreateButton(ButtonListener* listener,
const base::string16& text,
bool md) {
@@ -54,39 +49,6 @@ const gfx::FontList& GetMdFontList() {
} // namespace
-namespace internal {
-
-class MdFocusRing : public View {
- public:
- MdFocusRing() {
- SetPaintToLayer(true);
- layer()->SetFillsBoundsOpaquely(false);
- }
- ~MdFocusRing() override {}
-
- // View:
- bool CanProcessEventsWithinSubtree() const override { return false; }
-
- void OnPaint(gfx::Canvas* canvas) override {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(
- SkColorSetA(GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_FocusedBorderColor),
- 0x66));
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(kFocusBorderThickness);
- gfx::RectF rect(GetLocalBounds());
- rect.Inset(gfx::InsetsF(kFocusBorderThickness / 2.f));
- canvas->DrawRoundRect(rect, kFocusBorderCornerRadius, paint);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MdFocusRing);
-};
-
-} // namespace internal
-
// static
LabelButton* MdTextButton::CreateSecondaryUiButton(ButtonListener* listener,
const base::string16& text) {
@@ -124,21 +86,14 @@ void MdTextButton::SetProminent(bool is_prominent) {
UpdateColors();
}
-void MdTextButton::Layout() {
- LabelButton::Layout();
- gfx::Rect focus_bounds = GetLocalBounds();
- focus_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
- focus_ring_->SetBoundsRect(focus_bounds);
-}
-
void MdTextButton::OnFocus() {
LabelButton::OnFocus();
- focus_ring_->SetVisible(true);
+ FocusRing::Install(this);
}
void MdTextButton::OnBlur() {
LabelButton::OnBlur();
- focus_ring_->SetVisible(false);
+ FocusRing::Uninstall(this);
}
void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
@@ -188,7 +143,7 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
}
bool MdTextButton::ShouldShowInkDropForFocus() const {
- // These types of button use |focus_ring_|.
+ // These types of button use FocusRing.
return false;
}
@@ -219,7 +174,6 @@ void MdTextButton::SetFontList(const gfx::FontList& font_list) {
MdTextButton::MdTextButton(ButtonListener* listener)
: LabelButton(listener, base::string16()),
- focus_ring_(new internal::MdFocusRing()),
is_prominent_(false) {
SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON
: InkDropMode::OFF);
@@ -229,8 +183,6 @@ MdTextButton::MdTextButton(ButtonListener* listener)
SetMinSize(gfx::Size(kMinWidth, 0));
SetFocusPainter(nullptr);
label()->SetAutoColorReadabilityEnabled(false);
- AddChildView(focus_ring_);
- focus_ring_->SetVisible(false);
set_request_focus_on_press(false);
LabelButton::SetFontList(GetMdFontList());
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698