| 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 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 InstallInkDropMask(ink_drop_layer); | 426 InstallInkDropMask(ink_drop_layer); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 429 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 430 image()->DestroyLayer(); | 430 image()->DestroyLayer(); |
| 431 ResetInkDropMask(); | 431 ResetInkDropMask(); |
| 432 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); | 432 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); |
| 433 } | 433 } |
| 434 | 434 |
| 435 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() { | 435 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() { |
| 436 return UseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl() | 436 return ShouldUseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl() |
| 437 : CustomButton::CreateInkDrop(); | 437 : CustomButton::CreateInkDrop(); |
| 438 } | 438 } |
| 439 | 439 |
| 440 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { | 440 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { |
| 441 return UseFloodFillInkDrop() | 441 return ShouldUseFloodFillInkDrop() |
| 442 ? base::MakeUnique<views::FloodFillInkDropRipple>( | 442 ? base::MakeUnique<views::FloodFillInkDropRipple>( |
| 443 size(), GetInkDropCenterBasedOnLastEvent(), | 443 size(), GetInkDropCenterBasedOnLastEvent(), |
| 444 GetInkDropBaseColor(), ink_drop_visible_opacity()) | 444 GetInkDropBaseColor(), ink_drop_visible_opacity()) |
| 445 : CreateDefaultInkDropRipple( | 445 : CreateDefaultInkDropRipple( |
| 446 image()->GetMirroredBounds().CenterPoint()); | 446 image()->GetMirroredBounds().CenterPoint()); |
| 447 } | 447 } |
| 448 | 448 |
| 449 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() | 449 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() |
| 450 const { | 450 const { |
| 451 return UseFloodFillInkDrop() | 451 return ShouldUseFloodFillInkDrop() |
| 452 ? base::MakeUnique<views::InkDropHighlight>( | 452 ? base::MakeUnique<views::InkDropHighlight>( |
| 453 size(), kInkDropSmallCornerRadius, | 453 size(), kInkDropSmallCornerRadius, |
| 454 gfx::RectF(GetLocalBounds()).CenterPoint(), | 454 gfx::RectF(GetLocalBounds()).CenterPoint(), |
| 455 GetInkDropBaseColor()) | 455 GetInkDropBaseColor()) |
| 456 : CreateDefaultInkDropHighlight( | 456 : CreateDefaultInkDropHighlight( |
| 457 gfx::RectF(image()->GetMirroredBounds()).CenterPoint()); | 457 gfx::RectF(image()->GetMirroredBounds()).CenterPoint()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void LabelButton::StateChanged(ButtonState old_state) { | 460 void LabelButton::StateChanged(ButtonState old_state) { |
| 461 const gfx::Size previous_image_size(image_->GetPreferredSize()); | 461 const gfx::Size previous_image_size(image_->GetPreferredSize()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 555 } |
| 556 | 556 |
| 557 ui::NativeTheme::Part LabelButton::GetThemePart() const { | 557 ui::NativeTheme::Part LabelButton::GetThemePart() const { |
| 558 return ui::NativeTheme::kPushButton; | 558 return ui::NativeTheme::kPushButton; |
| 559 } | 559 } |
| 560 | 560 |
| 561 gfx::Rect LabelButton::GetThemePaintRect() const { | 561 gfx::Rect LabelButton::GetThemePaintRect() const { |
| 562 return GetLocalBounds(); | 562 return GetLocalBounds(); |
| 563 } | 563 } |
| 564 | 564 |
| 565 bool LabelButton::ShouldUseFloodFillInkDrop() const { |
| 566 return !GetText().empty(); |
| 567 } |
| 568 |
| 565 ui::NativeTheme::State LabelButton::GetThemeState( | 569 ui::NativeTheme::State LabelButton::GetThemeState( |
| 566 ui::NativeTheme::ExtraParams* params) const { | 570 ui::NativeTheme::ExtraParams* params) const { |
| 567 GetExtraParams(params); | 571 GetExtraParams(params); |
| 568 switch (state()) { | 572 switch (state()) { |
| 569 case STATE_NORMAL: return ui::NativeTheme::kNormal; | 573 case STATE_NORMAL: return ui::NativeTheme::kNormal; |
| 570 case STATE_HOVERED: return ui::NativeTheme::kHovered; | 574 case STATE_HOVERED: return ui::NativeTheme::kHovered; |
| 571 case STATE_PRESSED: return ui::NativeTheme::kPressed; | 575 case STATE_PRESSED: return ui::NativeTheme::kPressed; |
| 572 case STATE_DISABLED: return ui::NativeTheme::kDisabled; | 576 case STATE_DISABLED: return ui::NativeTheme::kDisabled; |
| 573 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state(); | 577 case STATE_COUNT: NOTREACHED() << "Unknown state: " << state(); |
| 574 } | 578 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 598 | 602 |
| 599 void LabelButton::ResetLabelEnabledColor() { | 603 void LabelButton::ResetLabelEnabledColor() { |
| 600 const SkColor color = | 604 const SkColor color = |
| 601 explicitly_set_colors_[state()] | 605 explicitly_set_colors_[state()] |
| 602 ? button_state_colors_[state()] | 606 ? button_state_colors_[state()] |
| 603 : PlatformStyle::TextColorForButton(button_state_colors_, *this); | 607 : PlatformStyle::TextColorForButton(button_state_colors_, *this); |
| 604 if (state() != STATE_DISABLED && label_->enabled_color() != color) | 608 if (state() != STATE_DISABLED && label_->enabled_color() != color) |
| 605 label_->SetEnabledColor(color); | 609 label_->SetEnabledColor(color); |
| 606 } | 610 } |
| 607 | 611 |
| 608 bool LabelButton::UseFloodFillInkDrop() const { | |
| 609 return !GetText().empty(); | |
| 610 } | |
| 611 | |
| 612 } // namespace views | 612 } // namespace views |
| OLD | NEW |