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

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

Issue 2639203007: Update SetPaintToLayer to accept LayerType (Closed)
Patch Set: Refactor Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/label_button.h" 5 #include "ui/views/controls/button/label_button.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "ui/compositor/layer_type.h"
15 #include "ui/gfx/animation/throb_animation.h" 16 #include "ui/gfx/animation/throb_animation.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 18 #include "ui/gfx/color_utils.h"
18 #include "ui/gfx/font_list.h" 19 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/geometry/vector2d.h" 20 #include "ui/gfx/geometry/vector2d.h"
20 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 22 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
22 #include "ui/views/animation/ink_drop.h" 23 #include "ui/views/animation/ink_drop.h"
23 #include "ui/views/animation/ink_drop_highlight.h" 24 #include "ui/views/animation/ink_drop_highlight.h"
24 #include "ui/views/animation/ink_drop_impl.h" 25 #include "ui/views/animation/ink_drop_impl.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 explicitly_set_colors_(), 93 explicitly_set_colors_(),
93 is_default_(false), 94 is_default_(false),
94 style_(STYLE_TEXTBUTTON), 95 style_(STYLE_TEXTBUTTON),
95 border_is_themed_border_(true), 96 border_is_themed_border_(true),
96 image_label_spacing_(kSpacing), 97 image_label_spacing_(kSpacing),
97 horizontal_alignment_(gfx::ALIGN_LEFT) { 98 horizontal_alignment_(gfx::ALIGN_LEFT) {
98 SetAnimationDuration(kHoverAnimationDurationMs); 99 SetAnimationDuration(kHoverAnimationDurationMs);
99 SetTextInternal(text); 100 SetTextInternal(text);
100 101
101 AddChildView(ink_drop_container_); 102 AddChildView(ink_drop_container_);
102 ink_drop_container_->SetPaintToLayer(true); 103 ink_drop_container_->SetPaintToLayer(ui::LAYER_TEXTURED);
103 ink_drop_container_->layer()->SetFillsBoundsOpaquely(false); 104 ink_drop_container_->layer()->SetFillsBoundsOpaquely(false);
104 ink_drop_container_->SetVisible(false); 105 ink_drop_container_->SetVisible(false);
105 106
106 AddChildView(image_); 107 AddChildView(image_);
107 image_->set_interactive(false); 108 image_->set_interactive(false);
108 109
109 AddChildView(label_); 110 AddChildView(label_);
110 label_->SetFontList(cached_normal_font_list_); 111 label_->SetFontList(cached_normal_font_list_);
111 label_->SetAutoColorReadabilityEnabled(false); 112 label_->SetAutoColorReadabilityEnabled(false);
112 label_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); 113 label_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 UpdateThemedBorder(); 417 UpdateThemedBorder();
417 ResetLabelEnabledColor(); 418 ResetLabelEnabledColor();
418 // Invalidate the layout to pickup the new insets from the border. 419 // Invalidate the layout to pickup the new insets from the border.
419 InvalidateLayout(); 420 InvalidateLayout();
420 // The entire button has to be repainted here, since the native theme can 421 // The entire button has to be repainted here, since the native theme can
421 // define the tint for the entire background/border/focus ring. 422 // define the tint for the entire background/border/focus ring.
422 SchedulePaint(); 423 SchedulePaint();
423 } 424 }
424 425
425 void LabelButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { 426 void LabelButton::AddInkDropLayer(ui::Layer* ink_drop_layer) {
426 image()->SetPaintToLayer(true); 427 image()->SetPaintToLayer(ui::LAYER_TEXTURED);
427 image()->layer()->SetFillsBoundsOpaquely(false); 428 image()->layer()->SetFillsBoundsOpaquely(false);
428 ink_drop_container_->AddInkDropLayer(ink_drop_layer); 429 ink_drop_container_->AddInkDropLayer(ink_drop_layer);
429 } 430 }
430 431
431 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 432 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
432 image()->SetPaintToLayer(false); 433 image()->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
433 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); 434 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer);
434 } 435 }
435 436
436 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() { 437 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() {
437 return UseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl() 438 return UseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl()
438 : CustomButton::CreateInkDrop(); 439 : CustomButton::CreateInkDrop();
439 } 440 }
440 441
441 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { 442 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const {
442 return UseFloodFillInkDrop() 443 return UseFloodFillInkDrop()
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 : PlatformStyle::TextColorForButton(button_state_colors_, *this); 605 : PlatformStyle::TextColorForButton(button_state_colors_, *this);
605 if (state() != STATE_DISABLED && label_->enabled_color() != color) 606 if (state() != STATE_DISABLED && label_->enabled_color() != color)
606 label_->SetEnabledColor(color); 607 label_->SetEnabledColor(color);
607 } 608 }
608 609
609 bool LabelButton::UseFloodFillInkDrop() const { 610 bool LabelButton::UseFloodFillInkDrop() const {
610 return !GetText().empty(); 611 return !GetText().empty();
611 } 612 }
612 613
613 } // namespace views 614 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698