From 816d9b6046dc999532f4db0e9ca75a1bb0d6c9fd Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Sat, 20 Oct 2018 01:53:46 +0000 Subject: [PATCH] Remove InkDropHost, since in practice all implementations used InkDropHostView. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes a footgun, since InkDropHostView's View overrides provided a lot of functionality that any InkDropHost implementation would want. Also does various other cleanups: * IWYU fixes * Remove unnecessary qualifiers * Reorder InkDropHostView declarations and definitions to match each other and be in a more logical order * Initialize InkDropHostView members in declaration Bug: none Change-Id: Iaf067fbb6361324fbf2da1a82f6658a4b564775e Reviewed-on: https://chromium-review.googlesource.com/c/1282216 Commit-Queue: Peter Kasting Reviewed-by: Mohsen Izadi Reviewed-by: Scott Violet Reviewed-by: Steven Bennetts Reviewed-by: Peter Boström Cr-Commit-Position: refs/heads/master@{#601387} --- ash/app_list/views/expand_arrow_view.cc | 2 +- ash/app_list/views/suggestion_chip_view.cc | 2 +- ash/assistant/ui/base/assistant_button.cc | 2 +- .../lock_screen_action_background_view.cc | 4 +- ash/login/ui/login_button.cc | 2 +- .../ui/login_expanded_public_account_view.cc | 2 +- ash/login/ui/login_pin_view.cc | 8 +- .../caption_buttons/frame_caption_button.h | 4 +- .../screen_rotation_animator_unittest.cc | 1 + ash/shelf/login_shelf_view.cc | 34 +++-- ash/shelf/shelf_view.cc | 1 + ash/system/date/date_view.cc | 2 +- ash/system/ime_menu/ime_list_view.cc | 2 +- .../arc/arc_notification_content_view.cc | 1 + .../overview/overview_button_tray_unittest.cc | 1 + ash/system/rotation/tray_rotation_lock.cc | 2 +- ash/system/tray/hover_highlight_view.cc | 2 +- ash/system/tray/tray_info_label.cc | 4 +- ash/system/tray/tray_item_more.cc | 2 +- ash/system/tray_caps_lock.cc | 2 +- ash/system/tray_tracing.cc | 2 +- ash/system/update/tray_update.cc | 2 +- ash/system/user/button_from_view.cc | 2 +- ash/system/user/user_view.cc | 1 + .../launcher/arc_app_launcher_browsertest.cc | 1 + .../ui/views/frame/hosted_app_menu_button.cc | 1 + .../ui/views/frame/hosted_app_menu_button.h | 2 +- chrome/browser/ui/views/hover_button.cc | 2 +- chrome/browser/ui/views/hover_button.h | 4 - .../ui/views/location_bar/find_bar_icon.cc | 1 + .../location_bar/icon_label_bubble_view.h | 4 +- .../media_router/cast_dialog_sink_button.cc | 2 +- .../views/omnibox/omnibox_tab_switch_button.h | 6 +- chrome/browser/ui/views/tabs/new_tab_button.h | 4 + ui/message_center/views/message_view.h | 8 +- .../views/notification_view_md.cc | 8 +- ui/message_center/views/padded_button.h | 2 +- ui/views/BUILD.gn | 1 - ui/views/animation/ink_drop_host.h | 66 ---------- ui/views/animation/ink_drop_host_view.cc | 122 ++++++++---------- ui/views/animation/ink_drop_host_view.h | 118 ++++++++++------- ui/views/animation/ink_drop_impl.cc | 5 +- ui/views/animation/ink_drop_impl.h | 6 +- ui/views/animation/ink_drop_unittest.cc | 2 +- ui/views/animation/test/test_ink_drop_host.cc | 5 - ui/views/animation/test/test_ink_drop_host.h | 8 +- ui/views/controls/button/button_unittest.cc | 4 +- ui/views/controls/button/menu_button.cc | 1 + 48 files changed, 203 insertions(+), 267 deletions(-) delete mode 100644 ui/views/animation/ink_drop_host.h diff --git a/ash/app_list/views/expand_arrow_view.cc b/ash/app_list/views/expand_arrow_view.cc index 9bb3e135ec6609..a1cd7da5b8c6f4 100644 --- a/ash/app_list/views/expand_arrow_view.cc +++ b/ash/app_list/views/expand_arrow_view.cc @@ -105,7 +105,7 @@ ExpandArrowView::ExpandArrowView(ContentsView* contents_view, SetPaintToLayer(); layer()->SetFillsBoundsOpaquely(false); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); SetAccessibleName(l10n_util::GetStringUTF16(IDS_APP_LIST_EXPAND_BUTTON)); diff --git a/ash/app_list/views/suggestion_chip_view.cc b/ash/app_list/views/suggestion_chip_view.cc index 5489cf7a67c75e..a40ab8aa6af8f1 100644 --- a/ash/app_list/views/suggestion_chip_view.cc +++ b/ash/app_list/views/suggestion_chip_view.cc @@ -65,7 +65,7 @@ SuggestionChipView::SuggestionChipView(const Params& params, text_view_(new views::Label()), assistant_style_(params.assistant_style) { SetFocusBehavior(FocusBehavior::ALWAYS); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); // Set background blur for the chip and use mask layer to clip it into // rounded rect. diff --git a/ash/assistant/ui/base/assistant_button.cc b/ash/assistant/ui/base/assistant_button.cc index d11ea1db6eeb89..83cdead2039fea 100644 --- a/ash/assistant/ui/base/assistant_button.cc +++ b/ash/assistant/ui/base/assistant_button.cc @@ -31,7 +31,7 @@ AssistantButton::AssistantButton(views::ButtonListener* listener) views::ImageButton::ALIGN_MIDDLE); // Ink drop. - SetInkDropMode(views::ImageButton::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); set_has_ink_drop_action_on_click(true); set_ink_drop_base_color(kInkDropBaseColor); set_ink_drop_visible_opacity(kInkDropVisibleOpacity); diff --git a/ash/lock_screen_action/lock_screen_action_background_view.cc b/ash/lock_screen_action/lock_screen_action_background_view.cc index bc61472014d115..99bb04ad62ff6f 100644 --- a/ash/lock_screen_action/lock_screen_action_background_view.cc +++ b/ash/lock_screen_action/lock_screen_action_background_view.cc @@ -48,12 +48,14 @@ class LockScreenActionBackgroundView::NoteBackground gfx::Point center = base::i18n::IsRTL() ? GetLocalBounds().origin() : GetLocalBounds().top_right(); auto ink_drop_ripple = std::make_unique( - size(), gfx::Insets(), center, SK_ColorBLACK, 1); + size(), gfx::Insets(), center, GetInkDropBaseColor(), 1); ink_drop_ripple->set_use_hide_transform_duration_for_hide_fade_out(true); ink_drop_ripple->set_duration_factor(1.5); return ink_drop_ripple; } + SkColor GetInkDropBaseColor() const override { return SK_ColorBLACK; } + private: views::InkDropObserver* observer_; diff --git a/ash/login/ui/login_button.cc b/ash/login/ui/login_button.cc index 9b1ae0f3e1ab1a..2524596df0bf7f 100644 --- a/ash/login/ui/login_button.cc +++ b/ash/login/ui/login_button.cc @@ -29,7 +29,7 @@ LoginButton::LoginButton(views::ButtonListener* listener) views::ImageButton::ALIGN_MIDDLE); SetFocusPainter(views::Painter::CreateSolidFocusPainter( kFocusBorderColor, kFocusBorderThickness, gfx::InsetsF())); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); set_has_ink_drop_action_on_click(true); } diff --git a/ash/login/ui/login_expanded_public_account_view.cc b/ash/login/ui/login_expanded_public_account_view.cc index 3cba5a048042c3..700c5dae00f211 100644 --- a/ash/login/ui/login_expanded_public_account_view.cc +++ b/ash/login/ui/login_expanded_public_account_view.cc @@ -100,7 +100,7 @@ class SelectionButtonView : public LoginButton { layer()->SetFillsBoundsOpaquely(false); SetFocusBehavior(FocusBehavior::ALWAYS); SetLayoutManager(std::make_unique()); - SetInkDropMode(InkDropHostView::InkDropMode::OFF); + SetInkDropMode(InkDropMode::OFF); auto add_horizontal_margin = [&](int width, views::View* parent) -> views::View* { diff --git a/ash/login/ui/login_pin_view.cc b/ash/login/ui/login_pin_view.cc index be6c83ad8bcf4f..9f4d37d1ac6223 100644 --- a/ash/login/ui/login_pin_view.cc +++ b/ash/login/ui/login_pin_view.cc @@ -29,9 +29,6 @@ namespace ash { namespace { -// Color of the ink drop ripple. -constexpr SkColor kInkDropRippleColor = SkColorSetARGB(0x0F, 0xFF, 0xFF, 0xFF); - // Color of the ink drop highlight. constexpr SkColor kInkDropHighlightColor = SkColorSetARGB(0x14, 0xFF, 0xFF, 0xFF); @@ -154,7 +151,7 @@ class BasePinButton : public views::InkDropHostView { return std::make_unique( size(), GetLocalBounds().InsetsFrom(bounds), - GetInkDropCenterBasedOnLastEvent(), kInkDropRippleColor, + GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), 1.f /*visible_opacity*/); } std::unique_ptr CreateInkDropHighlight() @@ -164,6 +161,9 @@ class BasePinButton : public views::InkDropHostView { std::make_unique(kInkDropHighlightColor, GetInkDropRadius())); } + SkColor GetInkDropBaseColor() const override { + return SkColorSetA(SK_ColorWHITE, 0x0F); + } int GetInkDropRadius() const { return kRippleSizeDp / 2; } diff --git a/ash/public/cpp/caption_buttons/frame_caption_button.h b/ash/public/cpp/caption_buttons/frame_caption_button.h index 1273d4c11ba2c0..0c8aacb1b81bae 100644 --- a/ash/public/cpp/caption_buttons/frame_caption_button.h +++ b/ash/public/cpp/caption_buttons/frame_caption_button.h @@ -60,12 +60,10 @@ class ASH_PUBLIC_EXPORT FrameCaptionButton : public views::Button { // Sets the alpha to use for painting. Used to animate visibility changes. void SetAlpha(int alpha); - // views::View overrides: + // views::Button: const char* GetClassName() const override; void OnGestureEvent(ui::GestureEvent* event) override; views::PaintInfo::ScaleType GetPaintScaleType() const override; - - // views::InkDropHostView: std::unique_ptr CreateInkDrop() override; std::unique_ptr CreateInkDropRipple() const override; std::unique_ptr CreateInkDropMask() const override; diff --git a/ash/rotator/screen_rotation_animator_unittest.cc b/ash/rotator/screen_rotation_animator_unittest.cc index 907cd0d8eba0ac..1762bbfb5702ba 100644 --- a/ash/rotator/screen_rotation_animator_unittest.cc +++ b/ash/rotator/screen_rotation_animator_unittest.cc @@ -25,6 +25,7 @@ #include "base/run_loop.h" #include "components/viz/common/frame_sinks/copy_output_request.h" #include "components/viz/common/frame_sinks/copy_output_result.h" +#include "ui/compositor/layer_tree_owner.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/display/display.h" #include "ui/display/manager/display_manager.h" diff --git a/ash/shelf/login_shelf_view.cc b/ash/shelf/login_shelf_view.cc index f49d6d1d374219..0ec15e743f7680 100644 --- a/ash/shelf/login_shelf_view.cc +++ b/ash/shelf/login_shelf_view.cc @@ -154,13 +154,12 @@ class LoginShelfButton : public views::LabelButton { kButtonBackgroundMarginBottomDp, kButtonBackgroundMarginRightDp); } - // views::View: + // views::LabelButton: gfx::Insets GetInsets() const override { return gfx::Insets(kButtonMarginTopDp, kButtonMarginLeftDp, kButtonMarginBottomDp, kButtonMarginRightDp); } - // views::Button: void PaintButtonContents(gfx::Canvas* canvas) override { cc::PaintFlags flags; flags.setAntiAlias(true); @@ -171,7 +170,6 @@ class LoginShelfButton : public views::LabelButton { canvas->DrawRoundRect(bounds, kButtonRoundedBorderRadiusDp, flags); } - // views::InkDropHostView: std::unique_ptr CreateInkDrop() override { auto ink_drop = std::make_unique(this, size()); ink_drop->SetShowHighlightOnHover(false); @@ -244,13 +242,12 @@ class KioskAppsButton : public views::MenuButton, kButtonBackgroundMarginBottomDp, kButtonBackgroundMarginRightDp); } - // views::View: + // views::MenuButton: gfx::Insets GetInsets() const override { return gfx::Insets(kButtonMarginTopDp, kButtonMarginLeftDp, kButtonMarginBottomDp, kButtonMarginRightDp); } - // views::Button: void PaintButtonContents(gfx::Canvas* canvas) override { cc::PaintFlags flags; flags.setAntiAlias(true); @@ -261,13 +258,24 @@ class KioskAppsButton : public views::MenuButton, canvas->DrawRoundRect(bounds, kButtonRoundedBorderRadiusDp, flags); } - // views::MenuButton: void SetVisible(bool visible) override { MenuButton::SetVisible(visible); if (visible) is_launch_enabled_ = true; } + std::unique_ptr CreateInkDrop() override { + auto ink_drop = std::make_unique(this, size()); + ink_drop->SetShowHighlightOnHover(false); + ink_drop->SetShowHighlightOnFocus(false); + return ink_drop; + } + + std::unique_ptr CreateInkDropMask() const override { + return std::make_unique( + size(), GetBackgroundInsets(), kButtonRoundedBorderRadiusDp); + } + // views::MenuButtonListener: void OnMenuButtonClicked(MenuButton* source, const gfx::Point& point, @@ -285,7 +293,7 @@ class KioskAppsButton : public views::MenuButton, views::MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_NONE); } - // ui::MenuModel: + // ui::SimpleMenuModel: void ExecuteCommand(int command_id, int event_flags) override { DCHECK(command_id >= 0 && base::checked_cast(command_id) < kiosk_apps_.size()); @@ -313,18 +321,6 @@ class KioskAppsButton : public views::MenuButton, bool IsCommandIdEnabled(int command_id) const override { return true; } - // views::InkDropHostView: - std::unique_ptr CreateInkDrop() override { - auto ink_drop = std::make_unique(this, size()); - ink_drop->SetShowHighlightOnHover(false); - ink_drop->SetShowHighlightOnFocus(false); - return ink_drop; - } - std::unique_ptr CreateInkDropMask() const override { - return std::make_unique( - size(), GetBackgroundInsets(), kButtonRoundedBorderRadiusDp); - } - private: std::unique_ptr menu_runner_; std::vector kiosk_apps_; diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc index 3b52cbfc6c8b0b..52e111a69732df 100644 --- a/ash/shelf/shelf_view.cc +++ b/ash/shelf/shelf_view.cc @@ -53,6 +53,7 @@ #include "ui/gfx/geometry/point.h" #include "ui/keyboard/keyboard_controller.h" #include "ui/views/animation/bounds_animator.h" +#include "ui/views/animation/ink_drop.h" #include "ui/views/border.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/menu/menu_model_adapter.h" diff --git a/ash/system/date/date_view.cc b/ash/system/date/date_view.cc index 1c0500a7ab352b..4729a6b492c065 100644 --- a/ash/system/date/date_view.cc +++ b/ash/system/date/date_view.cc @@ -181,7 +181,7 @@ void DateView::SetAction(DateAction action) { // Disable |this| when not clickable so that the ripple is not shown. SetEnabled(action_ != DateAction::NONE); if (action_ != DateAction::NONE) - SetInkDropMode(views::InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } void DateView::UpdateTextInternal(const base::Time& now) { diff --git a/ash/system/ime_menu/ime_list_view.cc b/ash/system/ime_menu/ime_list_view.cc index 2ffc8ee28370bf..e10c7f0a137e2e 100644 --- a/ash/system/ime_menu/ime_list_view.cc +++ b/ash/system/ime_menu/ime_list_view.cc @@ -56,7 +56,7 @@ class ImeListItemView : public ActionableView { : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), ime_list_view_(list_view), selected_(selected) { - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); AddChildView(tri_view); diff --git a/ash/system/message_center/arc/arc_notification_content_view.cc b/ash/system/message_center/arc/arc_notification_content_view.cc index fec6e70c9953fa..86cac542bec207 100644 --- a/ash/system/message_center/arc/arc_notification_content_view.cc +++ b/ash/system/message_center/arc/arc_notification_content_view.cc @@ -16,6 +16,7 @@ #include "ui/accessibility/ax_node_data.h" #include "ui/base/l10n/l10n_util.h" #include "ui/compositor/layer_animation_observer.h" +#include "ui/compositor/layer_tree_owner.h" #include "ui/events/event_handler.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/insets.h" diff --git a/ash/system/overview/overview_button_tray_unittest.cc b/ash/system/overview/overview_button_tray_unittest.cc index a486eccb870000..63194d60985c32 100644 --- a/ash/system/overview/overview_button_tray_unittest.cc +++ b/ash/system/overview/overview_button_tray_unittest.cc @@ -28,6 +28,7 @@ #include "services/ws/public/cpp/input_devices/input_device_client_test_api.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" +#include "ui/compositor/layer_tree_owner.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/display/display_switches.h" #include "ui/display/manager/display_manager.h" diff --git a/ash/system/rotation/tray_rotation_lock.cc b/ash/system/rotation/tray_rotation_lock.cc index 7cbb3a7d2765f8..ab170a7c085d59 100644 --- a/ash/system/rotation/tray_rotation_lock.cc +++ b/ash/system/rotation/tray_rotation_lock.cc @@ -89,7 +89,7 @@ RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) Update(); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); SetVisible(IsTabletModeWindowManagerEnabled()); Shell::Get()->tablet_mode_controller()->AddObserver(this); diff --git a/ash/system/tray/hover_highlight_view.cc b/ash/system/tray/hover_highlight_view.cc index d0a6cab6581d31..933c0f095aa3b7 100644 --- a/ash/system/tray/hover_highlight_view.cc +++ b/ash/system/tray/hover_highlight_view.cc @@ -29,7 +29,7 @@ HoverHighlightView::HoverHighlightView(ViewClickListener* listener, listener_(listener), use_unified_theme_(use_unified_theme) { set_notify_enter_exit_on_child(true); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } HoverHighlightView::~HoverHighlightView() = default; diff --git a/ash/system/tray/tray_info_label.cc b/ash/system/tray/tray_info_label.cc index 498444609dfa5d..21bc11b0f24435 100644 --- a/ash/system/tray/tray_info_label.cc +++ b/ash/system/tray/tray_info_label.cc @@ -43,10 +43,10 @@ void TrayInfoLabel::Update(int message_id) { TrayPopupItemStyle::FontStyle font_style; if (IsClickable()) { - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); font_style = TrayPopupItemStyle::FontStyle::CLICKABLE_SYSTEM_INFO; } else { - SetInkDropMode(InkDropHostView::InkDropMode::OFF); + SetInkDropMode(InkDropMode::OFF); font_style = TrayPopupItemStyle::FontStyle::SYSTEM_INFO; } diff --git a/ash/system/tray/tray_item_more.cc b/ash/system/tray/tray_item_more.cc index 68b2c8e4ef65e2..0c6d4c7518e8cd 100644 --- a/ash/system/tray/tray_item_more.cc +++ b/ash/system/tray/tray_item_more.cc @@ -32,7 +32,7 @@ TrayItemMore::TrayItemMore(SystemTrayItem* owner) tri_view_->AddView(TriView::Container::CENTER, label_); tri_view_->AddView(TriView::Container::END, more_); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } TrayItemMore::~TrayItemMore() = default; diff --git a/ash/system/tray_caps_lock.cc b/ash/system/tray_caps_lock.cc index 477e27a5e8ee91..5d6211089f5b93 100644 --- a/ash/system/tray_caps_lock.cc +++ b/ash/system/tray_caps_lock.cc @@ -67,7 +67,7 @@ class CapsLockDefaultView : public ActionableView { TrayPopupItemStyle caption_style(TrayPopupItemStyle::FontStyle::CAPTION); caption_style.SetupLabel(shortcut_label_); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); tri_view->AddView(TriView::Container::START, image); tri_view->AddView(TriView::Container::CENTER, text_label_); diff --git a/ash/system/tray_tracing.cc b/ash/system/tray_tracing.cc index 548ef90f20a715..00575b2ff9d2aa 100644 --- a/ash/system/tray_tracing.cc +++ b/ash/system/tray_tracing.cc @@ -48,7 +48,7 @@ class DefaultTracingView : public ActionableView { image->SetImage( gfx::CreateVectorIcon(kSystemMenuTracingIcon, style.GetIconColor())); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } ~DefaultTracingView() override = default; diff --git a/ash/system/update/tray_update.cc b/ash/system/update/tray_update.cc index e8607a888a3a78..a271e934dc0379 100644 --- a/ash/system/update/tray_update.cc +++ b/ash/system/update/tray_update.cc @@ -99,7 +99,7 @@ class TrayUpdate::UpdateView : public ActionableView { style.SetupLabel(update_label_); tri_view->AddView(TriView::Container::CENTER, update_label_); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } ~UpdateView() override = default; diff --git a/ash/system/user/button_from_view.cc b/ash/system/user/button_from_view.cc index fa6b3f2e199333..36cd8b0ccb880f 100644 --- a/ash/system/user/button_from_view.cc +++ b/ash/system/user/button_from_view.cc @@ -38,7 +38,7 @@ ButtonFromView::ButtonFromView(views::View* content, ink_drop_container_ = new views::InkDropContainerView(); AddChildView(ink_drop_container_); SetLayoutManager(std::make_unique()); - SetInkDropMode(InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); AddChildView(content_); // Only make it focusable when we are active/interested in clicks. if (listener) diff --git a/ash/system/user/user_view.cc b/ash/system/user/user_view.cc index ef89aa64e8a6c7..121591a094711d 100644 --- a/ash/system/user/user_view.cc +++ b/ash/system/user/user_view.cc @@ -35,6 +35,7 @@ #include "ui/gfx/geometry/insets.h" #include "ui/gfx/paint_vector_icon.h" #include "ui/native_theme/native_theme.h" +#include "ui/views/animation/ink_drop.h" #include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_mask.h" #include "ui/views/animation/ink_drop_ripple.h" diff --git a/chrome/browser/ui/ash/launcher/arc_app_launcher_browsertest.cc b/chrome/browser/ui/ash/launcher/arc_app_launcher_browsertest.cc index 0a984ffa9c2865..c00fb76e4a1ed2 100644 --- a/chrome/browser/ui/ash/launcher/arc_app_launcher_browsertest.cc +++ b/chrome/browser/ui/ash/launcher/arc_app_launcher_browsertest.cc @@ -39,6 +39,7 @@ #include "ui/display/types/display_constants.h" #include "ui/events/event_constants.h" #include "ui/events/test/event_generator.h" +#include "ui/views/animation/ink_drop.h" namespace mojo { diff --git a/chrome/browser/ui/views/frame/hosted_app_menu_button.cc b/chrome/browser/ui/views/frame/hosted_app_menu_button.cc index a18319080f6340..f335b1e94a8055 100644 --- a/chrome/browser/ui/views/frame/hosted_app_menu_button.cc +++ b/chrome/browser/ui/views/frame/hosted_app_menu_button.cc @@ -19,6 +19,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/paint_vector_icon.h" +#include "ui/views/animation/ink_drop.h" #include "ui/views/border.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/window/hit_test_utils.h" diff --git a/chrome/browser/ui/views/frame/hosted_app_menu_button.h b/chrome/browser/ui/views/frame/hosted_app_menu_button.h index 202bd285561371..28aaec01ad6434 100644 --- a/chrome/browser/ui/views/frame/hosted_app_menu_button.h +++ b/chrome/browser/ui/views/frame/hosted_app_menu_button.h @@ -31,7 +31,7 @@ class HostedAppMenuButton : public AppMenuButton, const gfx::Point& point, const ui::Event* event) override; - // InkDropHostView: + // AppMenuButton: SkColor GetInkDropBaseColor() const override; private: diff --git a/chrome/browser/ui/views/hover_button.cc b/chrome/browser/ui/views/hover_button.cc index ae128faf00a597..cf5eca501f5db3 100644 --- a/chrome/browser/ui/views/hover_button.cc +++ b/chrome/browser/ui/views/hover_button.cc @@ -79,7 +79,7 @@ HoverButton::HoverButton(views::ButtonListener* button_listener, DISTANCE_CONTROL_LIST_VERTICAL); SetBorder(CreateBorderWithVerticalSpacing(vert_spacing)); - SetInkDropMode(views::InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); } HoverButton::HoverButton(views::ButtonListener* button_listener, diff --git a/chrome/browser/ui/views/hover_button.h b/chrome/browser/ui/views/hover_button.h index 877906250c4c22..6c1c24bb403c5b 100644 --- a/chrome/browser/ui/views/hover_button.h +++ b/chrome/browser/ui/views/hover_button.h @@ -95,12 +95,8 @@ class HoverButton : public views::MenuButton, public views::MenuButtonListener { // views::MenuButton: KeyClickAction GetKeyClickActionForEvent(const ui::KeyEvent& event) override; void StateChanged(ButtonState old_state) override; - - // views::InkDropHostView: SkColor GetInkDropBaseColor() const override; std::unique_ptr CreateInkDrop() override; - - // views::View: void Layout() override; views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override; diff --git a/chrome/browser/ui/views/location_bar/find_bar_icon.cc b/chrome/browser/ui/views/location_bar/find_bar_icon.cc index 8f607658e970a9..ddc1bd94d0d75f 100644 --- a/chrome/browser/ui/views/location_bar/find_bar_icon.cc +++ b/chrome/browser/ui/views/location_bar/find_bar_icon.cc @@ -10,6 +10,7 @@ #include "chrome/grit/generated_resources.h" #include "components/toolbar/vector_icons.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/animation/ink_drop.h" FindBarIcon::FindBarIcon(Browser* browser, PageActionIconView::Delegate* delegate) diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h index 11d7fcd9ff7898..d4c8f724ed98e0 100644 --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.h @@ -130,7 +130,7 @@ class IconLabelBubbleView : public views::InkDropObserver, // Sets the border padding around this view. virtual void UpdateBorder(); - // views::InkDropHostView: + // views::Button: gfx::Size CalculatePreferredSize() const override; void Layout() override; bool OnMousePressed(const ui::MouseEvent& event) override; @@ -144,8 +144,6 @@ class IconLabelBubbleView : public views::InkDropObserver, const override; std::unique_ptr CreateInkDropMask() const override; SkColor GetInkDropBaseColor() const override = 0; - - // views::Button: bool IsTriggerableEvent(const ui::Event& event) override; bool ShouldUpdateInkDropOnClickCanceled() const override; void NotifyClick(const ui::Event& event) override; diff --git a/chrome/browser/ui/views/media_router/cast_dialog_sink_button.cc b/chrome/browser/ui/views/media_router/cast_dialog_sink_button.cc index 662d4f8b957af6..9972369bfa0652 100644 --- a/chrome/browser/ui/views/media_router/cast_dialog_sink_button.cc +++ b/chrome/browser/ui/views/media_router/cast_dialog_sink_button.cc @@ -42,7 +42,7 @@ class StopButton : public views::LabelButton { static const gfx::ImageSkia icon = CreateVectorIcon( kGenericStopIcon, kPrimaryIconSize, gfx::kGoogleBlue500); SetImage(views::Button::STATE_NORMAL, icon); - SetInkDropMode(views::InkDropHostView::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); set_tag(button_tag); SetBorder(views::CreateEmptyBorder(gfx::Insets(kPrimaryIconBorderWidth))); SetEnabled(enabled); diff --git a/chrome/browser/ui/views/omnibox/omnibox_tab_switch_button.h b/chrome/browser/ui/views/omnibox/omnibox_tab_switch_button.h index 4fc6decbf18d54..8431880a72869e 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_tab_switch_button.h +++ b/chrome/browser/ui/views/omnibox/omnibox_tab_switch_button.h @@ -24,14 +24,10 @@ class OmniboxTabSwitchButton : public views::MdTextButton { ~OmniboxTabSwitchButton() override; - // views::View + // views::MdTextButton: gfx::Size CalculatePreferredSize() const override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override; - - // views::InkDropHostView std::unique_ptr CreateInkDropMask() const override; - - // views::Button void AnimationProgressed(const gfx::Animation* animation) override; void StateChanged(ButtonState old_state) override; diff --git a/chrome/browser/ui/views/tabs/new_tab_button.h b/chrome/browser/ui/views/tabs/new_tab_button.h index 9c729b9b79aec8..e7d1d4c4a26726 100644 --- a/chrome/browser/ui/views/tabs/new_tab_button.h +++ b/chrome/browser/ui/views/tabs/new_tab_button.h @@ -14,6 +14,10 @@ class NewTabPromoBubbleView; +namespace views { +class InkDropContainerView; +} + /////////////////////////////////////////////////////////////////////////////// // NewTabButton // diff --git a/ui/message_center/views/message_view.h b/ui/message_center/views/message_view.h index 49138c6780b4d0..3e6e0fc432de2d 100644 --- a/ui/message_center/views/message_view.h +++ b/ui/message_center/views/message_view.h @@ -38,6 +38,10 @@ class NotificationControlButtonsView; // An base class for a notification entry. Contains background and other // elements shared by derived notification views. +// TODO(pkasting): This class only subclasses InkDropHostView because the +// NotificationViewMD subclass needs ink drop functionality. Rework ink drops +// to not need to be the base class of views which use them, and move the +// functionality to the subclass that uses these. class MESSAGE_CENTER_EXPORT MessageView : public views::InkDropHostView, public SlideOutController::Delegate, public views::FocusChangeListener { @@ -104,7 +108,7 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::InkDropHostView, virtual void OnSettingsButtonPressed(const ui::Event& event); virtual void OnSnoozeButtonPressed(const ui::Event& event); - // views::View + // views::InkDropHostView: void GetAccessibleNodeData(ui::AXNodeData* node_data) override; bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) override; @@ -120,7 +124,7 @@ class MESSAGE_CENTER_EXPORT MessageView : public views::InkDropHostView, void AddedToWidget() override; const char* GetClassName() const final; - // message_center::SlideOutController::Delegate + // message_center::SlideOutController::Delegate: ui::Layer* GetSlideOutLayer() override; void OnSlideChanged() override; void OnSlideOut() override; diff --git a/ui/message_center/views/notification_view_md.cc b/ui/message_center/views/notification_view_md.cc index b46099ce0475ea..ae70662fceb4eb 100644 --- a/ui/message_center/views/notification_view_md.cc +++ b/ui/message_center/views/notification_view_md.cc @@ -91,9 +91,6 @@ constexpr SkColor kLargeImageBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5); constexpr SkColor kRegularTextColorMD = SkColorSetRGB(0x21, 0x21, 0x21); constexpr SkColor kDimTextColorMD = SkColorSetRGB(0x75, 0x75, 0x75); -// Background of inline settings area. -const SkColor kSettingsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); - // Text color and icon color of inline reply area when the textfield is empty. constexpr SkColor kTextfieldPlaceholderTextColorMD = SkColorSetA(SK_ColorWHITE, 0x8A); @@ -336,7 +333,7 @@ NotificationButtonMD::NotificationButtonMD( views::style::CONTEXT_BUTTON_MD), placeholder_(placeholder) { SetHorizontalAlignment(gfx::ALIGN_CENTER); - SetInkDropMode(views::LabelButton::InkDropMode::ON); + SetInkDropMode(InkDropMode::ON); set_has_ink_drop_action_on_click(true); set_ink_drop_base_color(SK_ColorBLACK); set_ink_drop_visible_opacity(kActionButtonInkDropRippleVisibleOpacity); @@ -1357,7 +1354,8 @@ std::unique_ptr NotificationViewMD::CreateInkDropMask() } SkColor NotificationViewMD::GetInkDropBaseColor() const { - return kSettingsRowBackgroundColor; + // Background of inline settings area. + return SkColorSetRGB(0xEE, 0xEE, 0xEE); } void NotificationViewMD::InkDropAnimationStarted() { diff --git a/ui/message_center/views/padded_button.h b/ui/message_center/views/padded_button.h index 2d9c6b0a1d2819..3c48a1f6c6ec53 100644 --- a/ui/message_center/views/padded_button.h +++ b/ui/message_center/views/padded_button.h @@ -26,7 +26,7 @@ class MESSAGE_CENTER_EXPORT PaddedButton : public views::ImageButton { PaddedButton(views::ButtonListener* listener); ~PaddedButton() override = default; - // Overridden from InkDropHostView + // views::ImageButton: std::unique_ptr CreateInkDrop() override; std::unique_ptr CreateInkDropRipple() const override; diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn index e708ae12e7320b..38af61da3e7447 100644 --- a/ui/views/BUILD.gn +++ b/ui/views/BUILD.gn @@ -69,7 +69,6 @@ jumbo_component("views") { "animation/ink_drop_animation_ended_reason.h", "animation/ink_drop_highlight.h", "animation/ink_drop_highlight_observer.h", - "animation/ink_drop_host.h", "animation/ink_drop_host_view.h", "animation/ink_drop_impl.h", "animation/ink_drop_mask.h", diff --git a/ui/views/animation/ink_drop_host.h b/ui/views/animation/ink_drop_host.h deleted file mode 100644 index 8360d62fd07d77..00000000000000 --- a/ui/views/animation/ink_drop_host.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_ANIMATION_INK_DROP_HOST_H_ -#define UI_VIEWS_ANIMATION_INK_DROP_HOST_H_ - -#include - -#include "base/macros.h" -#include "ui/gfx/geometry/point.h" -#include "ui/views/views_export.h" - -namespace ui { -class Layer; -} // namespace ui - -namespace views { - -class InkDrop; -class InkDropRipple; -class InkDropHighlight; - -// Used by the InkDrop to add and remove the ink drop layers from a host's layer -// tree. Typically the ink drop layer is added to a View's layer but it can also -// be added to a View's ancestor layer. -// -// Note: Some Views do not own a Layer, but you can use -// View::SetLayer(new ui::Layer(ui::LAYER_NOT_DRAWN)) to force the View to have -// a lightweight Layer that can parent the ink drop layer. -class VIEWS_EXPORT InkDropHost { - public: - InkDropHost() {} - virtual ~InkDropHost() {} - - // Adds the |ink_drop_layer| in to a visible layer tree. - virtual void AddInkDropLayer(ui::Layer* ink_drop_layer) = 0; - - // Removes |ink_drop_layer| from the layer tree. - virtual void RemoveInkDropLayer(ui::Layer* ink_drop_layer) = 0; - - // Returns a configured InkDrop. In general subclasses will return an - // InkDropImpl instance that will use the CreateInkDropRipple() and - // CreateInkDropHighlight() methods to create the visual effects. - // - // Subclasses should override this if they need to configure any properties - // specific to the InkDrop instance. e.g. the AutoHighlightMode of an - // InkDropImpl instance. - virtual std::unique_ptr CreateInkDrop() = 0; - - // Creates and returns the visual effect used for press. Used by InkDropImpl - // instances. - virtual std::unique_ptr CreateInkDropRipple() const = 0; - - // Creates and returns the visual effect used for hover and focus. Used by - // InkDropImpl instances. - // Note: InkDropHostView does not accept null return values. - virtual std::unique_ptr CreateInkDropHighlight() const = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(InkDropHost); -}; - -} // namespace views - -#endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_H_ diff --git a/ui/views/animation/ink_drop_host_view.cc b/ui/views/animation/ink_drop_host_view.cc index 8c51e0fae67d63..a924b5458ba4ee 100644 --- a/ui/views/animation/ink_drop_host_view.cc +++ b/ui/views/animation/ink_drop_host_view.cc @@ -20,20 +20,6 @@ #include "ui/views/view_properties.h" namespace views { -namespace { - -// The scale factor to compute the large size of the default -// SquareInkDropRipple. -constexpr float kLargeInkDropScale = 1.333f; - -// Default opacity of the ink drop when it is visible. -constexpr float kInkDropVisibleOpacity = 0.175f; - -// Default corner radii used for the SquareInkDropRipple. -constexpr int kInkDropSmallCornerRadius = 2; -constexpr int kInkDropLargeCornerRadius = 4; - -} // namespace // An EventHandler that is guaranteed to be invoked and is not prone to // InkDropHostView descendents who do not call @@ -44,7 +30,8 @@ constexpr int kInkDropLargeCornerRadius = 4; class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { public: explicit InkDropGestureHandler(InkDropHostView* host_view) - : target_handler_(new ui::ScopedTargetHandler(host_view, this)), + : target_handler_( + std::make_unique(host_view, this)), host_view_(host_view) {} ~InkDropGestureHandler() override {} @@ -110,21 +97,7 @@ class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); }; -// static - -gfx::Size InkDropHostView::CalculateLargeInkDropSize( - const gfx::Size& small_size) { - return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); -} - -InkDropHostView::InkDropHostView() - : ink_drop_mode_(InkDropMode::OFF), - ink_drop_(nullptr), - ink_drop_visible_opacity_(kInkDropVisibleOpacity), - ink_drop_small_corner_radius_(kInkDropSmallCornerRadius), - ink_drop_large_corner_radius_(kInkDropLargeCornerRadius), - old_paint_to_layer_(false), - destroying_(false) {} +InkDropHostView::InkDropHostView() = default; InkDropHostView::~InkDropHostView() { // TODO(bruthig): Improve InkDropImpl to be safer about calling back to @@ -189,24 +162,9 @@ std::unique_ptr InkDropHostView::CreateInkDropMask() const { return nullptr; } -std::unique_ptr InkDropHostView::CreateDefaultInkDropRipple( - const gfx::Point& center_point, - const gfx::Size& size) const { - std::unique_ptr ripple(new SquareInkDropRipple( - CalculateLargeInkDropSize(size), ink_drop_large_corner_radius_, size, - ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor(), - ink_drop_visible_opacity())); - return ripple; -} - -std::unique_ptr -InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, - const gfx::Size& size) const { - std::unique_ptr highlight( - new InkDropHighlight(size, ink_drop_small_corner_radius_, center_point, - GetInkDropBaseColor())); - highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size))); - return highlight; +SkColor InkDropHostView::GetInkDropBaseColor() const { + NOTREACHED(); + return gfx::kPlaceholderColor; } void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { @@ -219,12 +177,6 @@ void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { gesture_handler_ = std::make_unique(this); } -gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { - return last_ripple_triggering_event_ - ? last_ripple_triggering_event_->location() - : GetMirroredRect(GetContentsBounds()).CenterPoint(); -} - void InkDropHostView::AnimateInkDrop(InkDropState state, const ui::LocatedEvent* event) { #if defined(OS_WIN) @@ -295,9 +247,38 @@ void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) { View::OnMouseEvent(event); } -SkColor InkDropHostView::GetInkDropBaseColor() const { - NOTREACHED(); - return gfx::kPlaceholderColor; +std::unique_ptr InkDropHostView::CreateDefaultInkDropImpl() { + auto ink_drop = std::make_unique(this, size()); + ink_drop->SetAutoHighlightMode( + InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); + return ink_drop; +} + +std::unique_ptr +InkDropHostView::CreateDefaultFloodFillInkDropImpl() { + std::unique_ptr ink_drop = CreateDefaultInkDropImpl(); + ink_drop->SetAutoHighlightMode( + views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); + return ink_drop; +} + +std::unique_ptr InkDropHostView::CreateDefaultInkDropRipple( + const gfx::Point& center_point, + const gfx::Size& size) const { + auto ripple = std::make_unique( + CalculateLargeInkDropSize(size), ink_drop_large_corner_radius_, size, + ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor(), + ink_drop_visible_opacity()); + return ripple; +} + +std::unique_ptr +InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, + const gfx::Size& size) const { + auto highlight = std::make_unique( + size, ink_drop_small_corner_radius_, center_point, GetInkDropBaseColor()); + highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size))); + return highlight; } bool InkDropHostView::HasInkDrop() const { @@ -315,6 +296,12 @@ InkDrop* InkDropHostView::GetInkDrop() { return ink_drop_.get(); } +gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { + return last_ripple_triggering_event_ + ? last_ripple_triggering_event_->location() + : GetMirroredRect(GetContentsBounds()).CenterPoint(); +} + void InkDropHostView::InstallInkDropMask(ui::Layer* ink_drop_layer) { ink_drop_mask_ = CreateInkDropMask(); if (ink_drop_mask_) @@ -330,20 +317,13 @@ void InkDropHostView::UpdateInkDropMaskLayerSize(const gfx::Size& new_size) { ink_drop_mask_->UpdateLayerSize(new_size); } -std::unique_ptr InkDropHostView::CreateDefaultInkDropImpl() { - auto ink_drop = std::make_unique(this, size()); - ink_drop->SetAutoHighlightMode( - InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE); - return ink_drop; -} - -std::unique_ptr -InkDropHostView::CreateDefaultFloodFillInkDropImpl() { - std::unique_ptr ink_drop = - InkDropHostView::CreateDefaultInkDropImpl(); - ink_drop->SetAutoHighlightMode( - views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); - return ink_drop; +// static +gfx::Size InkDropHostView::CalculateLargeInkDropSize( + const gfx::Size& small_size) { + // The scale factor to compute the large size of the default + // SquareInkDropRipple. + constexpr float kLargeInkDropScale = 1.333f; + return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); } } // namespace views diff --git a/ui/views/animation/ink_drop_host_view.h b/ui/views/animation/ink_drop_host_view.h index 14929b2564b719..d3a3aa6c28597d 100644 --- a/ui/views/animation/ink_drop_host_view.h +++ b/ui/views/animation/ink_drop_host_view.h @@ -10,20 +10,32 @@ #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/size.h" -#include "ui/views/animation/ink_drop.h" -#include "ui/views/animation/ink_drop_host.h" #include "ui/views/view.h" +namespace gfx { +class PointF; +} // namespace gfx + +namespace ui { +class Layer; +class LocatedEvent; +} // namespace ui + namespace views { + +class InkDrop; +class InkDropHighlight; class InkDropImpl; class InkDropMask; +class InkDropRipple; +enum class InkDropState; namespace test { class InkDropHostViewTestApi; } // namespace test // A view that provides InkDropHost functionality. -class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { +class VIEWS_EXPORT InkDropHostView : public View { public: // Used in SetInkDropMode() to specify whether the ink drop effect is enabled // or not for the view. In case of having an ink drop, it also specifies @@ -38,12 +50,28 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { InkDropHostView(); ~InkDropHostView() override; - // Overridden from InkDropHost: - void AddInkDropLayer(ui::Layer* ink_drop_layer) override; - void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; - std::unique_ptr CreateInkDrop() override; - std::unique_ptr CreateInkDropRipple() const override; - std::unique_ptr CreateInkDropHighlight() const override; + // Adds the |ink_drop_layer| in to a visible layer tree. + virtual void AddInkDropLayer(ui::Layer* ink_drop_layer); + + // Removes |ink_drop_layer| from the layer tree. + virtual void RemoveInkDropLayer(ui::Layer* ink_drop_layer); + + // Returns a configured InkDrop. In general subclasses will return an + // InkDropImpl instance that will use the CreateInkDropRipple() and + // CreateInkDropHighlight() methods to create the visual effects. + // + // Subclasses should override this if they need to configure any properties + // specific to the InkDrop instance. e.g. the AutoHighlightMode of an + // InkDropImpl instance. + virtual std::unique_ptr CreateInkDrop(); + + // Creates and returns the visual effect used for press. Used by InkDropImpl + // instances. + virtual std::unique_ptr CreateInkDropRipple() const; + + // Creates and returns the visual effect used for hover and focus. Used by + // InkDropImpl instances. + virtual std::unique_ptr CreateInkDropHighlight() const; // Subclasses can override to return a mask for the ink drop. By default, // returns nullptr (i.e no mask). @@ -51,6 +79,9 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { // https://crbug.com/713359. virtual std::unique_ptr CreateInkDropMask() const; + // Returns the base color for the ink drop. + virtual SkColor GetInkDropBaseColor() const; + // Toggle to enable/disable an InkDrop on this View. Descendants can override // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel // of the InkDrop. @@ -88,9 +119,25 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { // Size used for the default SquareInkDropRipple. static constexpr int kDefaultInkDropSize = 24; - // Returns a large ink drop size based on the |small_size| that works well - // with the SquareInkDropRipple animation durations. - static gfx::Size CalculateLargeInkDropSize(const gfx::Size& small_size); + // Called after a new InkDrop instance is created. + virtual void OnInkDropCreated() {} + + // View: + void ViewHierarchyChanged( + const ViewHierarchyChangedDetails& details) override; + void OnBoundsChanged(const gfx::Rect& previous_bounds) override; + void VisibilityChanged(View* starting_from, bool is_visible) override; + void OnFocus() override; + void OnBlur() override; + void OnMouseEvent(ui::MouseEvent* event) override; + + // Returns an InkDropImpl with default configuration. The base implementation + // of CreateInkDrop() delegates to this function. + std::unique_ptr CreateDefaultInkDropImpl(); + + // Returns an InkDropImpl configured to work well with a + // flood-fill ink drop ripple. + std::unique_ptr CreateDefaultFloodFillInkDropImpl(); // Returns the default InkDropRipple centered on |center_point|. std::unique_ptr CreateDefaultInkDropRipple( @@ -104,26 +151,6 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { const gfx::Size& size = gfx::Size(kDefaultInkDropSize, kDefaultInkDropSize)) const; - // Returns the point of the |last_ripple_triggering_event_| if it was a - // LocatedEvent, otherwise the center point of the local bounds is returned. - gfx::Point GetInkDropCenterBasedOnLastEvent() const; - - // View: - void ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) override; - void OnBoundsChanged(const gfx::Rect& previous_bounds) override; - void VisibilityChanged(View* starting_from, bool is_visible) override; - void OnFocus() override; - void OnBlur() override; - void OnMouseEvent(ui::MouseEvent* event) override; - - // Overrideable methods to allow views to provide minor tweaks to the default - // ink drop. - virtual SkColor GetInkDropBaseColor() const; - - // Called after a new InkDrop instance is created. - virtual void OnInkDropCreated() {} - // Returns true if an ink drop instance has been created. bool HasInkDrop() const; @@ -132,6 +159,10 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { // subclasses should be able to call SetInkDropMode() during construction. InkDrop* GetInkDrop(); + // Returns the point of the |last_ripple_triggering_event_| if it was a + // LocatedEvent, otherwise the center point of the local bounds is returned. + gfx::Point GetInkDropCenterBasedOnLastEvent() const; + // Initializes and sets a mask on |ink_drop_layer|. No-op if // CreateInkDropMask() returns null. void InstallInkDropMask(ui::Layer* ink_drop_layer); @@ -142,13 +173,9 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { // |ink_drop_mask_| is null. void UpdateInkDropMaskLayerSize(const gfx::Size& new_size); - // Returns an InkDropImpl configured to work well with a - // flood-fill ink drop ripple. - std::unique_ptr CreateDefaultFloodFillInkDropImpl(); - - // Returns an InkDropImpl with default configuration. The base implementation - // of CreateInkDrop() delegates to this function. - std::unique_ptr CreateDefaultInkDropImpl(); + // Returns a large ink drop size based on the |small_size| that works well + // with the SquareInkDropRipple animation durations. + static gfx::Size CalculateLargeInkDropSize(const gfx::Size& small_size); private: class InkDropGestureHandler; @@ -159,7 +186,7 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { std::unique_ptr last_ripple_triggering_event_; // Defines what type of |ink_drop_| to create. - InkDropMode ink_drop_mode_; + InkDropMode ink_drop_mode_ = InkDropMode::OFF; // Should not be accessed directly. Use GetInkDrop() instead. std::unique_ptr ink_drop_; @@ -168,22 +195,23 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { // destroyed |ink_drop_| during destruction. std::unique_ptr gesture_handler_; - float ink_drop_visible_opacity_; + float ink_drop_visible_opacity_ = 0.175f; // Radii used for the SquareInkDropRipple. - int ink_drop_small_corner_radius_; - int ink_drop_large_corner_radius_; + int ink_drop_small_corner_radius_ = 2; + int ink_drop_large_corner_radius_ = 4; // Determines whether the view was already painting to layer before adding ink // drop layer. - bool old_paint_to_layer_; + bool old_paint_to_layer_ = false; - bool destroying_; + bool destroying_ = false; std::unique_ptr ink_drop_mask_; DISALLOW_COPY_AND_ASSIGN(InkDropHostView); }; + } // namespace views #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ diff --git a/ui/views/animation/ink_drop_impl.cc b/ui/views/animation/ink_drop_impl.cc index 7e00a268fd29c2..6c8fbe73d5b7b1 100644 --- a/ui/views/animation/ink_drop_impl.cc +++ b/ui/views/animation/ink_drop_impl.cc @@ -8,7 +8,7 @@ #include "base/timer/timer.h" #include "ui/compositor/layer.h" #include "ui/views/animation/ink_drop_highlight.h" -#include "ui/views/animation/ink_drop_host.h" +#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/square_ink_drop_ripple.h" #include "ui/views/style/platform_style.h" @@ -584,7 +584,8 @@ InkDropImpl::HighlightStateFactory::CreateVisibleState( return nullptr; } -InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host, const gfx::Size& host_size) +InkDropImpl::InkDropImpl(InkDropHostView* ink_drop_host, + const gfx::Size& host_size) : ink_drop_host_(ink_drop_host), root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), root_layer_added_to_host_(false), diff --git a/ui/views/animation/ink_drop_impl.h b/ui/views/animation/ink_drop_impl.h index 05862e299d8d36..82061d7e778f1d 100644 --- a/ui/views/animation/ink_drop_impl.h +++ b/ui/views/animation/ink_drop_impl.h @@ -22,7 +22,7 @@ class InkDropImplTestApi; } // namespace test class InkDropRipple; -class InkDropHost; +class InkDropHostView; class InkDropHighlight; // A functional implementation of an InkDrop. @@ -50,7 +50,7 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop, // // By default the highlight will be made visible while |this| is hovered but // not focused and the NONE AutoHighlightMode will be used. - InkDropImpl(InkDropHost* ink_drop_host, const gfx::Size& host_size); + InkDropImpl(InkDropHostView* ink_drop_host, const gfx::Size& host_size); ~InkDropImpl() override; // Auto highlighting is a mechanism to show/hide the highlight based on the @@ -274,7 +274,7 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop, // The host of the ink drop. Used to create the ripples and highlights, and to // add/remove the root layer to/from it. - InkDropHost* ink_drop_host_; + InkDropHostView* ink_drop_host_; // The root Layer that parents the InkDropRipple layers and the // InkDropHighlight layers. The |root_layer_| is the one that is added and diff --git a/ui/views/animation/ink_drop_unittest.cc b/ui/views/animation/ink_drop_unittest.cc index 4cee71e8dd7baf..903eef90840a25 100644 --- a/ui/views/animation/ink_drop_unittest.cc +++ b/ui/views/animation/ink_drop_unittest.cc @@ -12,7 +12,7 @@ #include "ui/base/test/material_design_controller_test_api.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/views/animation/ink_drop.h" -#include "ui/views/animation/ink_drop_host.h" +#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_state.h" #include "ui/views/animation/ink_drop_stub.h" diff --git a/ui/views/animation/test/test_ink_drop_host.cc b/ui/views/animation/test/test_ink_drop_host.cc index 69caa0299730fb..9ad133127503d7 100644 --- a/ui/views/animation/test/test_ink_drop_host.cc +++ b/ui/views/animation/test/test_ink_drop_host.cc @@ -89,11 +89,6 @@ void TestInkDropHost::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { ++num_ink_drop_layers_removed_; } -std::unique_ptr TestInkDropHost::CreateInkDrop() { - NOTREACHED(); - return nullptr; -} - std::unique_ptr TestInkDropHost::CreateInkDropRipple() const { gfx::Size size(10, 10); std::unique_ptr ripple(new TestInkDropRipple( diff --git a/ui/views/animation/test/test_ink_drop_host.h b/ui/views/animation/test/test_ink_drop_host.h index 2e5164225baaaa..aaa2a3c2eb8272 100644 --- a/ui/views/animation/test/test_ink_drop_host.h +++ b/ui/views/animation/test/test_ink_drop_host.h @@ -6,7 +6,7 @@ #define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HOST_H_ #include "base/macros.h" -#include "ui/views/animation/ink_drop_host.h" +#include "ui/views/animation/ink_drop_host_view.h" namespace views { @@ -14,7 +14,7 @@ namespace views { // tests. Tracks the number of hosted ink drop layers. // // Note that CreateInkDrop() is not supported. -class TestInkDropHost : public InkDropHost { +class TestInkDropHost : public InkDropHostView { public: TestInkDropHost(); ~TestInkDropHost() override; @@ -28,11 +28,9 @@ class TestInkDropHost : public InkDropHost { disable_timers_for_test_ = disable_timers_for_test; } - // TestInkDropHost: + // InkDropHostView: void AddInkDropLayer(ui::Layer* ink_drop_layer) override; void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; - // Not supported. - std::unique_ptr CreateInkDrop() override; std::unique_ptr CreateInkDropRipple() const override; std::unique_ptr CreateInkDropHighlight() const override; diff --git a/ui/views/controls/button/button_unittest.cc b/ui/views/controls/button/button_unittest.cc index 067653b4945a01..58b132576e5c9a 100644 --- a/ui/views/controls/button/button_unittest.cc +++ b/ui/views/controls/button/button_unittest.cc @@ -13,7 +13,7 @@ #include "ui/display/screen.h" #include "ui/events/event_utils.h" #include "ui/events/test/event_generator.h" -#include "ui/views/animation/ink_drop_host.h" +#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/test/ink_drop_host_view_test_api.h" #include "ui/views/animation/test/test_ink_drop.h" @@ -78,7 +78,7 @@ class TestButton : public Button, public ButtonListener { void OnClickCanceled(const ui::Event& event) override { canceled_ = true; } - // InkDropHostView: + // Button: void AddInkDropLayer(ui::Layer* ink_drop_layer) override { ++ink_drop_layer_add_count_; Button::AddInkDropLayer(ink_drop_layer); diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc index 7f38894e57c63c..27aed587e9a680 100644 --- a/ui/views/controls/button/menu_button.cc +++ b/ui/views/controls/button/menu_button.cc @@ -16,6 +16,7 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/text_constants.h" #include "ui/resources/grit/ui_resources.h" +#include "ui/views/animation/ink_drop.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/mouse_constants.h"