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

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

Issue 2514303004: WIP - mask a view's layer by its view coordinates
Patch Set: manual clip Created 4 years, 1 month 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
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/compositor/paint_context.h"
10 #include "ui/compositor/paint_recorder.h"
9 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_palette.h" 12 #include "ui/gfx/color_palette.h"
11 #include "ui/gfx/color_utils.h" 13 #include "ui/gfx/color_utils.h"
12 #include "ui/native_theme/native_theme.h" 14 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 15 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
14 #include "ui/views/animation/ink_drop_highlight.h" 16 #include "ui/views/animation/ink_drop_highlight.h"
15 #include "ui/views/animation/ink_drop_impl.h" 17 #include "ui/views/animation/ink_drop_impl.h"
16 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" 18 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
17 #include "ui/views/background.h" 19 #include "ui/views/background.h"
18 #include "ui/views/border.h" 20 #include "ui/views/border.h"
19 #include "ui/views/controls/button/blue_button.h" 21 #include "ui/views/controls/button/blue_button.h"
20 #include "ui/views/controls/focus_ring.h" 22 #include "ui/views/controls/focus_ring.h"
21 #include "ui/views/painter.h" 23 #include "ui/views/painter.h"
22 #include "ui/views/style/platform_style.h" 24 #include "ui/views/style/platform_style.h"
23 25
24 namespace views { 26 namespace views {
25 27
26 namespace { 28 namespace {
27 29
28 // Minimum size to reserve for the button contents. 30 // Minimum size to reserve for the button contents.
29 const int kMinWidth = 48; 31 const int kMinWidth = 48;
30 32
33 class VisibleMaskLayerDelegate : public ui::LayerDelegate {
34 public:
35 explicit VisibleMaskLayerDelegate(views::View* view, const ui::Layer* layer)
36 : view_(view), layer_(layer) {}
37 ~VisibleMaskLayerDelegate() override {}
38
39 // ui::LayerDelegate:
40 void OnPaintLayer(const ui::PaintContext& context) override {
41 ui::PaintRecorder recorder(context, layer_->size());
42 gfx::Rect bounds = view_->GetVisibleBounds();
43 recorder.canvas()->FillRect(bounds, SK_ColorBLACK);
44 }
45
46 void OnDelegatedFrameDamage(
47 const gfx::Rect& damage_rect_in_dip) override {}
48 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
49
50 private:
51 views::View* view_;
52 const ui::Layer* const layer_;
53 DISALLOW_COPY_AND_ASSIGN(VisibleMaskLayerDelegate);
54 };
55
31 LabelButton* CreateButton(ButtonListener* listener, 56 LabelButton* CreateButton(ButtonListener* listener,
32 const base::string16& text, 57 const base::string16& text,
33 bool md) { 58 bool md) {
34 if (md) 59 if (md)
35 return MdTextButton::Create(listener, text); 60 return MdTextButton::Create(listener, text);
36 61
37 LabelButton* button = new LabelButton(listener, text); 62 LabelButton* button = new LabelButton(listener, text);
38 button->SetStyle(CustomButton::STYLE_BUTTON); 63 button->SetStyle(CustomButton::STYLE_BUTTON);
39 return button; 64 return button;
40 } 65 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 121
97 void MdTextButton::OnPaintBackground(gfx::Canvas* canvas) { 122 void MdTextButton::OnPaintBackground(gfx::Canvas* canvas) {
98 LabelButton::OnPaintBackground(canvas); 123 LabelButton::OnPaintBackground(canvas);
99 if (hover_animation().is_animating() || state() == STATE_HOVERED) { 124 if (hover_animation().is_animating() || state() == STATE_HOVERED) {
100 const int kHoverAlpha = is_prominent_ ? 0x0c : 0x05; 125 const int kHoverAlpha = is_prominent_ ? 0x0c : 0x05;
101 SkScalar alpha = hover_animation().CurrentValueBetween(0, kHoverAlpha); 126 SkScalar alpha = hover_animation().CurrentValueBetween(0, kHoverAlpha);
102 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, alpha)); 127 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, alpha));
103 } 128 }
104 } 129 }
105 130
131 bool MdTextButton::GetNeedsNotificationWhenVisibleBoundsChange() const {
132 return true;
133 }
134
135 void MdTextButton::OnVisibleBoundsChanged() {
136 gfx::Rect visible_bounds = GetVisibleBounds();
137 if (last_visible_bounds_ != visible_bounds)
138 SchedulePaint();
139 last_visible_bounds_ = visible_bounds;
140 }
141
142 void MdTextButton::OnLayerBoundsChanged(const gfx::Rect& old_bounds) {
143 LabelButton::OnLayerBoundsChanged(old_bounds);
144 // mask_layer_.SetBounds(layer()->bounds());
145 }
146
106 void MdTextButton::OnFocus() { 147 void MdTextButton::OnFocus() {
107 LabelButton::OnFocus(); 148 LabelButton::OnFocus();
108 FocusRing::Install(this); 149 FocusRing::Install(this);
109 } 150 }
110 151
111 void MdTextButton::OnBlur() { 152 void MdTextButton::OnBlur() {
112 LabelButton::OnBlur(); 153 LabelButton::OnBlur();
113 FocusRing::Uninstall(this); 154 FocusRing::Uninstall(this);
114 } 155 }
115 156
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 label()->SetAutoColorReadabilityEnabled(false); 240 label()->SetAutoColorReadabilityEnabled(false);
200 set_request_focus_on_press(false); 241 set_request_focus_on_press(false);
201 LabelButton::SetFontList(GetMdFontList()); 242 LabelButton::SetFontList(GetMdFontList());
202 243
203 set_animate_on_state_change(true); 244 set_animate_on_state_change(true);
204 245
205 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful 246 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful
206 // for fractional DSF). 247 // for fractional DSF).
207 SetPaintToLayer(true); 248 SetPaintToLayer(true);
208 layer()->SetFillsBoundsOpaquely(false); 249 layer()->SetFillsBoundsOpaquely(false);
250 /*
251 mask_layer_.SetFillsBoundsOpaquely(false);
252 mask_layer_delegate_.reset(new VisibleMaskLayerDelegate(this, &mask_layer_));
253 mask_layer_.set_delegate(mask_layer_delegate_.get());
254 layer()->SetMaskLayer(&mask_layer_);
255 */
209 } 256 }
210 257
211 void MdTextButton::UpdatePadding() { 258 void MdTextButton::UpdatePadding() {
212 // Don't use font-based padding when there's no text visible. 259 // Don't use font-based padding when there's no text visible.
213 if (GetText().empty()) { 260 if (GetText().empty()) {
214 SetBorder(NullBorder()); 261 SetBorder(NullBorder());
215 return; 262 return;
216 } 263 }
217 264
218 // Text buttons default to 28dp in height on all platforms when the base font 265 // Text buttons default to 28dp in height on all platforms when the base font
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 stroke_color, gfx::kDisabledControlAlpha); 340 stroke_color, gfx::kDisabledControlAlpha);
294 } 341 }
295 342
296 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); 343 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color)));
297 set_background(Background::CreateBackgroundPainter( 344 set_background(Background::CreateBackgroundPainter(
298 true, Painter::CreateRoundRectWith1PxBorderPainter( 345 true, Painter::CreateRoundRectWith1PxBorderPainter(
299 bg_color, stroke_color, kInkDropSmallCornerRadius))); 346 bg_color, stroke_color, kInkDropSmallCornerRadius)));
300 } 347 }
301 348
302 } // namespace views 349 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/view.cc » ('j') | ui/views/view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698