Skip to content

Commit

Permalink
Remove ViewWithInkDrop template
Browse files Browse the repository at this point in the history
Moves shared configuration between CaptureModeButton and
CaptureModeToggleButton into CaptureModeButton::ConfigureButton. Some
shared configuration is unfortunately left out due to using protected
members.

Bug: None
Change-Id: Ifd1c548d6d42d3c54bc85f125864461994e6df83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2880834
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#880625}
  • Loading branch information
pbos authored and Chromium LUCI CQ committed May 7, 2021
1 parent f4f3e77 commit eafb28e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 98 deletions.
1 change: 0 additions & 1 deletion ash/BUILD.gn
Expand Up @@ -316,7 +316,6 @@ component("ash") {
"capture_mode/video_file_handler.h",
"capture_mode/video_recording_watcher.cc",
"capture_mode/video_recording_watcher.h",
"capture_mode/view_with_ink_drop.h",
"child_accounts/parent_access_controller_impl.cc",
"child_accounts/parent_access_controller_impl.h",
"clipboard/clipboard_history.cc",
Expand Down
53 changes: 40 additions & 13 deletions ash/capture_mode/capture_mode_button.cc
Expand Up @@ -4,47 +4,74 @@

#include "ash/capture_mode/capture_mode_button.h"

#include "ash/capture_mode/capture_mode_constants.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/style/ash_color_provider.h"
#include "base/bind.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/controls/highlight_path_generator.h"

namespace ash {

CaptureModeButton::CaptureModeButton(views::Button::PressedCallback callback,
const gfx::VectorIcon& icon)
: ViewWithInkDrop(callback) {
SetPreferredSize(capture_mode::kButtonSize);
SetBorder(views::CreateEmptyBorder(capture_mode::kButtonPadding));
auto* color_provider = AshColorProvider::Get();
const SkColor normal_color = color_provider->GetContentLayerColor(
: views::ImageButton(callback) {
ConfigureButton(this, focus_ring());
const SkColor normal_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kButtonIconColor);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, normal_color));
SetImageHorizontalAlignment(ALIGN_CENTER);
SetImageVerticalAlignment(ALIGN_MIDDLE);
GetViewAccessibility().OverrideIsLeaf(true);

// TODO(afakhry): Fix this.
GetViewAccessibility().OverrideName(GetClassName());
}

// static
void CaptureModeButton::ConfigureButton(views::ImageButton* button,
views::FocusRing* focus_ring) {
button->ink_drop()->SetMode(views::InkDropHost::InkDropMode::ON);
button->SetHasInkDropActionOnClick(true);
button->ink_drop()->SetVisibleOpacity(capture_mode::kInkDropVisibleOpacity);
views::InkDrop::UseInkDropForFloodFillRipple(button->ink_drop(),
/*highlight_on_hover=*/false,
/*highlight_on_focus=*/false);
button->ink_drop()->SetCreateHighlightCallback(base::BindRepeating(
[](views::Button* host) {
auto highlight = std::make_unique<views::InkDropHighlight>(
gfx::SizeF(host->size()), host->ink_drop()->GetBaseColor());
highlight->set_visible_opacity(
capture_mode::kInkDropHighlightVisibleOpacity);
return highlight;
},
button));
button->ink_drop()->SetBaseColor(capture_mode::kInkDropBaseColor);

button->SetImageHorizontalAlignment(ALIGN_CENTER);
button->SetImageVerticalAlignment(ALIGN_MIDDLE);
button->SetPreferredSize(capture_mode::kButtonSize);
button->SetBorder(views::CreateEmptyBorder(capture_mode::kButtonPadding));
button->GetViewAccessibility().OverrideIsLeaf(true);

SetInstallFocusRingOnFocus(true);
focus_ring()->SetColor(color_provider->GetControlsLayerColor(
button->SetInstallFocusRingOnFocus(true);
focus_ring->SetColor(AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
focus_ring()->SetPathGenerator(
focus_ring->SetPathGenerator(
std::make_unique<views::CircleHighlightPathGenerator>(
capture_mode::kButtonPadding));
views::InstallCircleHighlightPathGenerator(this,
views::InstallCircleHighlightPathGenerator(button,
capture_mode::kButtonPadding);
}

views::View* CaptureModeButton::GetView() {
return this;
}

BEGIN_METADATA(CaptureModeButton, ViewWithInkDrop<views::ImageButton>)
BEGIN_METADATA(CaptureModeButton, views::ImageButton)
END_METADATA

} // namespace ash
13 changes: 10 additions & 3 deletions ash/capture_mode/capture_mode_button.h
Expand Up @@ -7,20 +7,22 @@

#include "ash/ash_export.h"
#include "ash/capture_mode/capture_mode_session_focus_cycler.h"
#include "ash/capture_mode/view_with_ink_drop.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"

namespace gfx {
struct VectorIcon;
} // namespace gfx

namespace views {
class FocusRing;
} // namespace views

namespace ash {

// A view that shows a button which is part of the CaptureBarView.
class ASH_EXPORT CaptureModeButton
: public ViewWithInkDrop<views::ImageButton>,
: public views::ImageButton,
public CaptureModeSessionFocusCycler::HighlightableView {
public:
METADATA_HEADER(CaptureModeButton);
Expand All @@ -31,6 +33,11 @@ class ASH_EXPORT CaptureModeButton
CaptureModeButton& operator=(const CaptureModeButton&) = delete;
~CaptureModeButton() override = default;

// Common configuration for CaptureModeButton and CaptureModeToggleButton,
// such as InkDrop, preferred size, border, etc.
static void ConfigureButton(views::ImageButton* button,
views::FocusRing* focus_ring);

// CaptureModeSessionFocusCycler::HighlightableView:
views::View* GetView() override;
};
Expand Down
1 change: 1 addition & 0 deletions ash/capture_mode/capture_mode_source_view.cc
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include "ash/capture_mode/capture_mode_constants.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_metrics.h"
#include "ash/capture_mode/capture_mode_toggle_button.h"
Expand Down
25 changes: 6 additions & 19 deletions ash/capture_mode/capture_mode_toggle_button.cc
Expand Up @@ -4,6 +4,8 @@

#include "ash/capture_mode/capture_mode_toggle_button.h"

#include "ash/capture_mode/capture_mode_button.h"
#include "ash/capture_mode/capture_mode_constants.h"
#include "ash/style/ash_color_provider.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/metadata/metadata_impl_macros.h"
Expand All @@ -17,25 +19,11 @@ namespace ash {
CaptureModeToggleButton::CaptureModeToggleButton(
views::Button::PressedCallback callback,
const gfx::VectorIcon& icon)
: ViewWithInkDrop(callback) {
SetPreferredSize(capture_mode::kButtonSize);
SetBorder(views::CreateEmptyBorder(capture_mode::kButtonPadding));
SetImageHorizontalAlignment(ALIGN_CENTER);
SetImageVerticalAlignment(ALIGN_MIDDLE);
GetViewAccessibility().OverrideIsLeaf(true);

SetInstallFocusRingOnFocus(true);
const auto* color_provider = AshColorProvider::Get();
focus_ring()->SetColor(color_provider->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
focus_ring()->SetPathGenerator(
std::make_unique<views::CircleHighlightPathGenerator>(
capture_mode::kButtonPadding));
views::InstallCircleHighlightPathGenerator(this,
capture_mode::kButtonPadding);
: views::ToggleImageButton(callback) {
CaptureModeButton::ConfigureButton(this, focus_ring());

SetIcon(icon);
toggled_background_color_ = color_provider->GetControlsLayerColor(
toggled_background_color_ = AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kControlBackgroundColorActive);
}

Expand Down Expand Up @@ -83,8 +71,7 @@ void CaptureModeToggleButton::SetIcon(const gfx::VectorIcon& icon) {
SetToggledImage(views::Button::STATE_NORMAL, &toggled_icon);
}

BEGIN_METADATA(CaptureModeToggleButton,
ViewWithInkDrop<views::ToggleImageButton>)
BEGIN_METADATA(CaptureModeToggleButton, views::ToggleImageButton)
END_METADATA

} // namespace ash
3 changes: 1 addition & 2 deletions ash/capture_mode/capture_mode_toggle_button.h
Expand Up @@ -7,7 +7,6 @@

#include "ash/ash_export.h"
#include "ash/capture_mode/capture_mode_session_focus_cycler.h"
#include "ash/capture_mode/view_with_ink_drop.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"
Expand All @@ -22,7 +21,7 @@ namespace ash {
// toggle between image and video capture, and between fullscreen, window, and
// region capture sources.
class ASH_EXPORT CaptureModeToggleButton
: public ViewWithInkDrop<views::ToggleImageButton>,
: public views::ToggleImageButton,
public CaptureModeSessionFocusCycler::HighlightableView {
public:
METADATA_HEADER(CaptureModeToggleButton);
Expand Down
60 changes: 0 additions & 60 deletions ash/capture_mode/view_with_ink_drop.h

This file was deleted.

0 comments on commit eafb28e

Please sign in to comment.