| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 cached_bold_font_list_ = font_list.DeriveWithWeight( | 384 cached_bold_font_list_ = font_list.DeriveWithWeight( |
| 385 GetValueBolderThan(font_list.GetFontWeight())); | 385 GetValueBolderThan(font_list.GetFontWeight())); |
| 386 if (is_default_) { | 386 if (is_default_) { |
| 387 label_->SetFontList(cached_bold_font_list_); | 387 label_->SetFontList(cached_bold_font_list_); |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 label_->SetFontList(cached_normal_font_list_); | 391 label_->SetFontList(cached_normal_font_list_); |
| 392 } | 392 } |
| 393 | 393 |
| 394 bool LabelButton::ShouldUseFloodFillInkDrop() const { |
| 395 return !GetText().empty(); |
| 396 } |
| 397 |
| 394 void LabelButton::OnPaint(gfx::Canvas* canvas) { | 398 void LabelButton::OnPaint(gfx::Canvas* canvas) { |
| 395 View::OnPaint(canvas); | 399 View::OnPaint(canvas); |
| 396 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 400 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 397 } | 401 } |
| 398 | 402 |
| 399 void LabelButton::OnFocus() { | 403 void LabelButton::OnFocus() { |
| 400 CustomButton::OnFocus(); | 404 CustomButton::OnFocus(); |
| 401 // Typically the border renders differently when focused. | 405 // Typically the border renders differently when focused. |
| 402 SchedulePaint(); | 406 SchedulePaint(); |
| 403 } | 407 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 426 InstallInkDropMask(ink_drop_layer); | 430 InstallInkDropMask(ink_drop_layer); |
| 427 } | 431 } |
| 428 | 432 |
| 429 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 433 void LabelButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 430 image()->DestroyLayer(); | 434 image()->DestroyLayer(); |
| 431 ResetInkDropMask(); | 435 ResetInkDropMask(); |
| 432 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); | 436 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); |
| 433 } | 437 } |
| 434 | 438 |
| 435 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() { | 439 std::unique_ptr<InkDrop> LabelButton::CreateInkDrop() { |
| 436 return UseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl() | 440 return ShouldUseFloodFillInkDrop() ? CreateDefaultFloodFillInkDropImpl() |
| 437 : CustomButton::CreateInkDrop(); | 441 : CustomButton::CreateInkDrop(); |
| 438 } | 442 } |
| 439 | 443 |
| 440 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { | 444 std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const { |
| 441 return UseFloodFillInkDrop() | 445 return ShouldUseFloodFillInkDrop() |
| 442 ? base::MakeUnique<views::FloodFillInkDropRipple>( | 446 ? base::MakeUnique<views::FloodFillInkDropRipple>( |
| 443 size(), GetInkDropCenterBasedOnLastEvent(), | 447 size(), GetInkDropCenterBasedOnLastEvent(), |
| 444 GetInkDropBaseColor(), ink_drop_visible_opacity()) | 448 GetInkDropBaseColor(), ink_drop_visible_opacity()) |
| 445 : CreateDefaultInkDropRipple( | 449 : CreateDefaultInkDropRipple( |
| 446 image()->GetMirroredBounds().CenterPoint()); | 450 image()->GetMirroredBounds().CenterPoint()); |
| 447 } | 451 } |
| 448 | 452 |
| 449 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() | 453 std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight() |
| 450 const { | 454 const { |
| 451 return UseFloodFillInkDrop() | 455 return ShouldUseFloodFillInkDrop() |
| 452 ? base::MakeUnique<views::InkDropHighlight>( | 456 ? base::MakeUnique<views::InkDropHighlight>( |
| 453 size(), kInkDropSmallCornerRadius, | 457 size(), kInkDropSmallCornerRadius, |
| 454 gfx::RectF(GetLocalBounds()).CenterPoint(), | 458 gfx::RectF(GetLocalBounds()).CenterPoint(), |
| 455 GetInkDropBaseColor()) | 459 GetInkDropBaseColor()) |
| 456 : CreateDefaultInkDropHighlight( | 460 : CreateDefaultInkDropHighlight( |
| 457 gfx::RectF(image()->GetMirroredBounds()).CenterPoint()); | 461 gfx::RectF(image()->GetMirroredBounds()).CenterPoint()); |
| 458 } | 462 } |
| 459 | 463 |
| 460 void LabelButton::StateChanged(ButtonState old_state) { | 464 void LabelButton::StateChanged(ButtonState old_state) { |
| 461 const gfx::Size previous_image_size(image_->GetPreferredSize()); | 465 const gfx::Size previous_image_size(image_->GetPreferredSize()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |