| OLD | NEW |
| 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/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
| 16 #include "ui/gfx/animation/throb_animation.h" | 16 #include "ui/gfx/animation/throb_animation.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 19 #include "ui/gfx/font_list.h" | 19 #include "ui/gfx/font_list.h" |
| 20 #include "ui/gfx/geometry/vector2d.h" | 20 #include "ui/gfx/geometry/vector2d.h" |
| 21 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
| 22 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 22 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 23 #include "ui/views/animation/ink_drop_highlight.h" | 23 #include "ui/views/animation/ink_drop_highlight.h" |
| 24 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 24 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
| 25 #include "ui/views/controls/button/label_button_border.h" | 26 #include "ui/views/controls/button/label_button_border.h" |
| 26 #include "ui/views/painter.h" | 27 #include "ui/views/painter.h" |
| 27 #include "ui/views/style/platform_style.h" | 28 #include "ui/views/style/platform_style.h" |
| 28 #include "ui/views/window/dialog_delegate.h" | 29 #include "ui/views/window/dialog_delegate.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // The default spacing between the icon and text. | 33 // The default spacing between the icon and text. |
| 33 const int kSpacing = 5; | 34 const int kSpacing = 5; |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 ink_drop_container_->layer()->Add(ink_drop_layer); | 433 ink_drop_container_->layer()->Add(ink_drop_layer); |
| 433 } | 434 } |
| 434 | 435 |
| 435 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 436 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 436 image()->SetPaintToLayer(false); | 437 image()->SetPaintToLayer(false); |
| 437 ink_drop_container_->layer()->Remove(ink_drop_layer); | 438 ink_drop_container_->layer()->Remove(ink_drop_layer); |
| 438 ink_drop_container_->SetVisible(false); | 439 ink_drop_container_->SetVisible(false); |
| 439 } | 440 } |
| 440 | 441 |
| 441 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { | 442 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { |
| 442 return GetText().empty() ? CustomButton::CreateInkDropRipple() | 443 return GetText().empty() |
| 443 : base::WrapUnique(new views::FloodFillInkDropRipple( | 444 ? CreateDefaultInkDropRipple( |
| 444 GetLocalBounds(), GetInkDropCenter(), | 445 image()->GetMirroredBounds().CenterPoint()) |
| 445 GetInkDropBaseColor())); | 446 : std::unique_ptr<views::InkDropRipple>( |
| 447 new views::FloodFillInkDropRipple( |
| 448 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), |
| 449 GetInkDropBaseColor())); |
| 446 } | 450 } |
| 447 | 451 |
| 448 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() | 452 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() |
| 449 const { | 453 const { |
| 450 if (!ShouldShowInkDropHighlight()) | 454 if (!ShouldShowInkDropHighlight()) |
| 451 return nullptr; | 455 return nullptr; |
| 452 return GetText().empty() ? CustomButton::CreateInkDropHighlight() | 456 return GetText().empty() |
| 453 : base::WrapUnique(new views::InkDropHighlight( | 457 ? CreateDefaultInkDropHighlight( |
| 454 size(), kInkDropSmallCornerRadius, | 458 image()->GetMirroredBounds().CenterPoint()) |
| 455 GetInkDropCenter(), GetInkDropBaseColor())); | 459 : base::WrapUnique(new views::InkDropHighlight( |
| 456 } | 460 size(), kInkDropSmallCornerRadius, |
| 457 | 461 GetLocalBounds().CenterPoint(), GetInkDropBaseColor())); |
| 458 gfx::Point LabelButton::GetInkDropCenter() const { | |
| 459 // TODO(bruthig): Make the flood fill ink drops centered on the LocatedEvent | |
| 460 // that triggered them. | |
| 461 return GetText().empty() ? image()->GetMirroredBounds().CenterPoint() | |
| 462 : CustomButton::GetInkDropCenter(); | |
| 463 } | 462 } |
| 464 | 463 |
| 465 void LabelButton::StateChanged() { | 464 void LabelButton::StateChanged() { |
| 466 const gfx::Size previous_image_size(image_->GetPreferredSize()); | 465 const gfx::Size previous_image_size(image_->GetPreferredSize()); |
| 467 UpdateImage(); | 466 UpdateImage(); |
| 468 ResetLabelEnabledColor(); | 467 ResetLabelEnabledColor(); |
| 469 label_->SetEnabled(state() != STATE_DISABLED); | 468 label_->SetEnabled(state() != STATE_DISABLED); |
| 470 if (image_->GetPreferredSize() != previous_image_size) | 469 if (image_->GetPreferredSize() != previous_image_size) |
| 471 Layout(); | 470 Layout(); |
| 472 } | 471 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 void LabelButton::ResetLabelEnabledColor() { | 589 void LabelButton::ResetLabelEnabledColor() { |
| 591 const SkColor color = | 590 const SkColor color = |
| 592 explicitly_set_colors_[state()] | 591 explicitly_set_colors_[state()] |
| 593 ? button_state_colors_[state()] | 592 ? button_state_colors_[state()] |
| 594 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 593 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 595 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 594 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 596 label_->SetEnabledColor(color); | 595 label_->SetEnabledColor(color); |
| 597 } | 596 } |
| 598 | 597 |
| 599 } // namespace views | 598 } // namespace views |
| OLD | NEW |