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

Side by Side Diff: ui/views/controls/button/md_text_button.cc

Issue 2311423002: Harmony - update button focus rings. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/button/md_text_button.h" 5 #include "ui/views/controls/button/md_text_button.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
11 #include "ui/native_theme/native_theme.h" 11 #include "ui/native_theme/native_theme.h"
12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
13 #include "ui/views/animation/ink_drop_highlight.h" 13 #include "ui/views/animation/ink_drop_highlight.h"
14 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" 14 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
15 #include "ui/views/background.h" 15 #include "ui/views/background.h"
16 #include "ui/views/border.h" 16 #include "ui/views/border.h"
17 #include "ui/views/controls/button/blue_button.h" 17 #include "ui/views/controls/button/blue_button.h"
18 #include "ui/views/painter.h" 18 #include "ui/views/painter.h"
19 #include "ui/views/style/platform_style.h" 19 #include "ui/views/style/platform_style.h"
20 20
21 namespace views { 21 namespace views {
22 22
23 namespace { 23 namespace {
24 24
25 // Minimum size to reserve for the button contents. 25 // Minimum size to reserve for the button contents.
26 const int kMinWidth = 48; 26 const int kMinWidth = 48;
27 27
28 // The stroke width of the focus border in normal and call to action mode. 28 // The stroke width of the focus border in dp.
29 const int kFocusBorderThickness = 1; 29 const int kFocusBorderThickness = 2;
30 const int kFocusBorderThicknessCta = 2;
31 30
32 // The corner radius of the focus border roundrect. 31 // The corner radius of the focus border roundrect.
33 const int kFocusBorderCornerRadius = 3; 32 const int kFocusBorderCornerRadius = 3;
34 33
35 LabelButton* CreateButton(ButtonListener* listener, 34 LabelButton* CreateButton(ButtonListener* listener,
36 const base::string16& text, 35 const base::string16& text,
37 bool md) { 36 bool md) {
38 if (md) 37 if (md)
39 return MdTextButton::CreateMdButton(listener, text); 38 return MdTextButton::CreateMdButton(listener, text);
40 39
(...skipping 10 matching lines...) Expand all
51 font_list.Get() = font_list.Get().DeriveWithWeight(min_weight); 50 font_list.Get() = font_list.Get().DeriveWithWeight(min_weight);
52 return font_list.Get(); 51 return font_list.Get();
53 } 52 }
54 53
55 } // namespace 54 } // namespace
56 55
57 namespace internal { 56 namespace internal {
58 57
59 class MdFocusRing : public View { 58 class MdFocusRing : public View {
60 public: 59 public:
61 MdFocusRing() : thickness_(kFocusBorderThickness) { 60 MdFocusRing() {
62 SetPaintToLayer(true); 61 SetPaintToLayer(true);
63 layer()->SetFillsBoundsOpaquely(false); 62 layer()->SetFillsBoundsOpaquely(false);
64 } 63 }
65 ~MdFocusRing() override {} 64 ~MdFocusRing() override {}
66 65
67 int thickness() const { return thickness_; }
68 void set_thickness(int thickness) { thickness_ = thickness; }
69
70 // View: 66 // View:
71 bool CanProcessEventsWithinSubtree() const override { return false; } 67 bool CanProcessEventsWithinSubtree() const override { return false; }
72 68
73 void OnPaint(gfx::Canvas* canvas) override { 69 void OnPaint(gfx::Canvas* canvas) override {
74 MdTextButton::PaintMdFocusRing(canvas, this, thickness_, 0x33); 70 SkPaint paint;
71 paint.setAntiAlias(true);
72 paint.setColor(
73 SkColorSetA(GetNativeTheme()->GetSystemColor(
74 ui::NativeTheme::kColorId_FocusedBorderColor),
75 0x66));
76 paint.setStyle(SkPaint::kStroke_Style);
77 paint.setStrokeWidth(kFocusBorderThickness);
78 gfx::RectF rect(GetLocalBounds());
79 rect.Inset(gfx::InsetsF(kFocusBorderThickness / 2.f));
80 canvas->DrawRoundRect(rect, kFocusBorderCornerRadius, paint);
75 } 81 }
76 82
77 private: 83 private:
78 int thickness_;
79
80 DISALLOW_COPY_AND_ASSIGN(MdFocusRing); 84 DISALLOW_COPY_AND_ASSIGN(MdFocusRing);
81 }; 85 };
82 86
83 } // namespace internal 87 } // namespace internal
84 88
85 // static 89 // static
86 LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener, 90 LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener,
87 const base::string16& text) { 91 const base::string16& text) {
88 return CreateButton(listener, text, 92 return CreateButton(listener, text,
89 ui::MaterialDesignController::IsModeMaterial()); 93 ui::MaterialDesignController::IsModeMaterial());
(...skipping 21 matching lines...) Expand all
111 115
112 // static 116 // static
113 MdTextButton* MdTextButton::CreateMdButton(ButtonListener* listener, 117 MdTextButton* MdTextButton::CreateMdButton(ButtonListener* listener,
114 const base::string16& text) { 118 const base::string16& text) {
115 MdTextButton* button = new MdTextButton(listener); 119 MdTextButton* button = new MdTextButton(listener);
116 button->SetText(text); 120 button->SetText(text);
117 button->SetFocusForPlatform(); 121 button->SetFocusForPlatform();
118 return button; 122 return button;
119 } 123 }
120 124
121 // static
122 void MdTextButton::PaintMdFocusRing(gfx::Canvas* canvas,
123 views::View* view,
124 int thickness,
125 SkAlpha alpha) {
126 SkPaint paint;
127 paint.setAntiAlias(true);
128 paint.setColor(SkColorSetA(view->GetNativeTheme()->GetSystemColor(
129 ui::NativeTheme::kColorId_CallToActionColor),
130 alpha));
131 paint.setStyle(SkPaint::kStroke_Style);
132 paint.setStrokeWidth(thickness);
133 gfx::RectF rect(view->GetLocalBounds());
134 rect.Inset(gfx::InsetsF(thickness / 2.f));
135 canvas->DrawRoundRect(rect, kFocusBorderCornerRadius, paint);
136 }
137
138 void MdTextButton::SetCallToAction(bool cta) { 125 void MdTextButton::SetCallToAction(bool cta) {
139 if (is_cta_ == cta) 126 if (is_cta_ == cta)
140 return; 127 return;
141 128
142 is_cta_ = cta; 129 is_cta_ = cta;
143 focus_ring_->set_thickness(cta ? kFocusBorderThicknessCta
144 : kFocusBorderThickness);
145 UpdateColors(); 130 UpdateColors();
146 } 131 }
147 132
148 void MdTextButton::Layout() { 133 void MdTextButton::Layout() {
149 LabelButton::Layout(); 134 LabelButton::Layout();
150 gfx::Rect focus_bounds = GetLocalBounds(); 135 gfx::Rect focus_bounds = GetLocalBounds();
151 focus_bounds.Inset(gfx::Insets(-focus_ring_->thickness())); 136 focus_bounds.Inset(gfx::Insets(-kFocusBorderThickness));
152 focus_ring_->SetBoundsRect(focus_bounds); 137 focus_ring_->SetBoundsRect(focus_bounds);
153 } 138 }
154 139
155 void MdTextButton::OnFocus() { 140 void MdTextButton::OnFocus() {
156 LabelButton::OnFocus(); 141 LabelButton::OnFocus();
157 focus_ring_->SetVisible(true); 142 focus_ring_->SetVisible(true);
158 } 143 }
159 144
160 void MdTextButton::OnBlur() { 145 void MdTextButton::OnBlur() {
161 LabelButton::OnBlur(); 146 LabelButton::OnBlur();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) 304 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
320 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) 305 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
321 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); 306 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
322 307
323 set_background(Background::CreateBackgroundPainter( 308 set_background(Background::CreateBackgroundPainter(
324 true, Painter::CreateRoundRectWith1PxBorderPainter( 309 true, Painter::CreateRoundRectWith1PxBorderPainter(
325 bg_color, stroke_color, kInkDropSmallCornerRadius))); 310 bg_color, stroke_color, kInkDropSmallCornerRadius)));
326 } 311 }
327 312
328 } // namespace views 313 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698