Commit 7f8cb130 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Allow InstallableInkDrop colors to be configured

This removes placeholder colors and opacities, instead allowing the
user to configure them. ToolbarButton configures its
InstallableInkDrop to match its classic InkDrops as closely as
possible.

Bug: 933384
Change-Id: I3d328e0218793589f829a9187359c4ed21d780b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713865
Auto-Submit: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680494}
parent 8bf51903
...@@ -185,6 +185,7 @@ void AvatarToolbarButton::NotifyClick(const ui::Event& event) { ...@@ -185,6 +185,7 @@ void AvatarToolbarButton::NotifyClick(const ui::Event& event) {
} }
void AvatarToolbarButton::OnThemeChanged() { void AvatarToolbarButton::OnThemeChanged() {
ToolbarButton::OnThemeChanged();
UpdateIcon(); UpdateIcon();
UpdateText(); UpdateText();
} }
......
...@@ -231,6 +231,7 @@ void BrowserAppMenuButton::ShowMenu(int run_types) { ...@@ -231,6 +231,7 @@ void BrowserAppMenuButton::ShowMenu(int run_types) {
} }
void BrowserAppMenuButton::OnThemeChanged() { void BrowserAppMenuButton::OnThemeChanged() {
AppMenuButton::OnThemeChanged();
UpdateIcon(); UpdateIcon();
} }
......
...@@ -50,8 +50,10 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener, ...@@ -50,8 +50,10 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener,
set_has_ink_drop_action_on_click(true); set_has_ink_drop_action_on_click(true);
set_context_menu_controller(this); set_context_menu_controller(this);
if (base::FeatureList::IsEnabled(views::kInstallableInkDropFeature)) if (base::FeatureList::IsEnabled(views::kInstallableInkDropFeature)) {
installable_ink_drop_ = std::make_unique<views::InstallableInkDrop>(this); installable_ink_drop_ = std::make_unique<views::InstallableInkDrop>(this);
installable_ink_drop_->SetConfig(GetToolbarInstallableInkDropConfig(this));
}
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
...@@ -160,6 +162,12 @@ void ToolbarButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -160,6 +162,12 @@ void ToolbarButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
LabelButton::OnBoundsChanged(previous_bounds); LabelButton::OnBoundsChanged(previous_bounds);
} }
void ToolbarButton::OnThemeChanged() {
LabelButton::OnThemeChanged();
if (installable_ink_drop_)
installable_ink_drop_->SetConfig(GetToolbarInstallableInkDropConfig(this));
}
gfx::Rect ToolbarButton::GetAnchorBoundsInScreen() const { gfx::Rect ToolbarButton::GetAnchorBoundsInScreen() const {
gfx::Rect bounds = GetBoundsInScreen(); gfx::Rect bounds = GetBoundsInScreen();
gfx::Insets insets = gfx::Insets insets =
......
...@@ -69,6 +69,7 @@ class ToolbarButton : public views::LabelButton, ...@@ -69,6 +69,7 @@ class ToolbarButton : public views::LabelButton,
// views::LabelButton: // views::LabelButton:
void SetText(const base::string16& text) override; void SetText(const base::string16& text) override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnThemeChanged() override;
gfx::Rect GetAnchorBoundsInScreen() const override; gfx::Rect GetAnchorBoundsInScreen() const override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) override;
......
...@@ -16,10 +16,15 @@ ...@@ -16,10 +16,15 @@
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/installable_ink_drop_config.h"
#include "ui/views/style/platform_style.h" #include "ui/views/style/platform_style.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
namespace {
constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f;
}
gfx::Insets GetToolbarInkDropInsets(const views::View* host_view, gfx::Insets GetToolbarInkDropInsets(const views::View* host_view,
const gfx::Insets& margin_insets) { const gfx::Insets& margin_insets) {
// TODO(pbos): Inkdrop masks and layers should be flipped with RTL. Fix this // TODO(pbos): Inkdrop masks and layers should be flipped with RTL. Fix this
...@@ -54,7 +59,6 @@ void SetToolbarButtonHighlightPath(views::View* host_view, ...@@ -54,7 +59,6 @@ void SetToolbarButtonHighlightPath(views::View* host_view,
std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight( std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
const views::InkDropHostView* host_view) { const views::InkDropHostView* host_view) {
constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f;
auto highlight = host_view->views::InkDropHostView::CreateInkDropHighlight(); auto highlight = host_view->views::InkDropHostView::CreateInkDropHighlight();
highlight->set_visible_opacity(kToolbarInkDropHighlightVisibleOpacity); highlight->set_visible_opacity(kToolbarInkDropHighlightVisibleOpacity);
return highlight; return highlight;
...@@ -70,3 +74,12 @@ SkColor GetToolbarInkDropBaseColor(const views::View* host_view) { ...@@ -70,3 +74,12 @@ SkColor GetToolbarInkDropBaseColor(const views::View* host_view) {
return gfx::kPlaceholderColor; return gfx::kPlaceholderColor;
} }
views::InstallableInkDropConfig GetToolbarInstallableInkDropConfig(
const views::View* host_view) {
views::InstallableInkDropConfig config;
config.base_color = GetToolbarInkDropBaseColor(host_view);
config.ripple_opacity = kToolbarInkDropVisibleOpacity;
config.highlight_opacity = kToolbarInkDropHighlightVisibleOpacity;
return config;
}
...@@ -15,6 +15,7 @@ namespace views { ...@@ -15,6 +15,7 @@ namespace views {
class InkDropHighlight; class InkDropHighlight;
class InkDropHostView; class InkDropHostView;
class View; class View;
struct InstallableInkDropConfig;
} // namespace views } // namespace views
constexpr float kToolbarInkDropVisibleOpacity = 0.06f; constexpr float kToolbarInkDropVisibleOpacity = 0.06f;
...@@ -36,4 +37,7 @@ std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight( ...@@ -36,4 +37,7 @@ std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
// Returns the ink drop base color that should be used by all toolbar buttons. // Returns the ink drop base color that should be used by all toolbar buttons.
SkColor GetToolbarInkDropBaseColor(const views::View* host_view); SkColor GetToolbarInkDropBaseColor(const views::View* host_view);
views::InstallableInkDropConfig GetToolbarInstallableInkDropConfig(
const views::View* host_view);
#endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_INK_DROP_UTIL_H_ #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_INK_DROP_UTIL_H_
...@@ -85,6 +85,7 @@ jumbo_component("views") { ...@@ -85,6 +85,7 @@ jumbo_component("views") {
"animation/ink_drop_util.h", "animation/ink_drop_util.h",
"animation/installable_ink_drop.h", "animation/installable_ink_drop.h",
"animation/installable_ink_drop_animator.h", "animation/installable_ink_drop_animator.h",
"animation/installable_ink_drop_config.h",
"animation/installable_ink_drop_painter.h", "animation/installable_ink_drop_painter.h",
"animation/scroll_animator.h", "animation/scroll_animator.h",
"animation/square_ink_drop_ripple.h", "animation/square_ink_drop_ripple.h",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/animation/animation_container.h" #include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -28,14 +29,27 @@ ...@@ -28,14 +29,27 @@
namespace views { namespace views {
namespace {
InstallableInkDropConfig GetPlaceholderInstallableInkDropConfig() {
InstallableInkDropConfig config{0};
config.base_color = gfx::kPlaceholderColor;
config.ripple_opacity = 1.0f;
config.highlight_opacity = 1.0f;
return config;
}
} // namespace
const base::Feature kInstallableInkDropFeature{ const base::Feature kInstallableInkDropFeature{
"InstallableInkDrop", base::FEATURE_DISABLED_BY_DEFAULT}; "InstallableInkDrop", base::FEATURE_DISABLED_BY_DEFAULT};
InstallableInkDrop::InstallableInkDrop(View* view) InstallableInkDrop::InstallableInkDrop(View* view)
: view_(view), : view_(view),
config_(GetPlaceholderInstallableInkDropConfig()),
layer_(std::make_unique<ui::Layer>()), layer_(std::make_unique<ui::Layer>()),
event_handler_(view_, this), event_handler_(view_, this),
painter_(&visual_state_), painter_(&config_, &visual_state_),
animation_container_(base::MakeRefCounted<gfx::AnimationContainer>()), animation_container_(base::MakeRefCounted<gfx::AnimationContainer>()),
animator_(layer_->size(), animator_(layer_->size(),
&visual_state_, &visual_state_,
...@@ -81,6 +95,11 @@ InstallableInkDrop::~InstallableInkDrop() { ...@@ -81,6 +95,11 @@ InstallableInkDrop::~InstallableInkDrop() {
view_->RemoveObserver(this); view_->RemoveObserver(this);
} }
void InstallableInkDrop::SetConfig(InstallableInkDropConfig config) {
config_ = config;
SchedulePaint();
}
void InstallableInkDrop::HostSizeChanged(const gfx::Size& new_size) { void InstallableInkDrop::HostSizeChanged(const gfx::Size& new_size) {
layer_->SetBounds(gfx::Rect(new_size) + layer_->bounds().OffsetFromOrigin()); layer_->SetBounds(gfx::Rect(new_size) + layer_->bounds().OffsetFromOrigin());
layer_->SchedulePaint(gfx::Rect(layer_->size())); layer_->SchedulePaint(gfx::Rect(layer_->size()));
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/views/animation/ink_drop_event_handler.h" #include "ui/views/animation/ink_drop_event_handler.h"
#include "ui/views/animation/ink_drop_state.h" #include "ui/views/animation/ink_drop_state.h"
#include "ui/views/animation/installable_ink_drop_animator.h" #include "ui/views/animation/installable_ink_drop_animator.h"
#include "ui/views/animation/installable_ink_drop_config.h"
#include "ui/views/animation/installable_ink_drop_painter.h" #include "ui/views/animation/installable_ink_drop_painter.h"
#include "ui/views/view_observer.h" #include "ui/views/view_observer.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -60,6 +61,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop, ...@@ -60,6 +61,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop,
~InstallableInkDrop() override; ~InstallableInkDrop() override;
void SetConfig(InstallableInkDropConfig config);
InstallableInkDropConfig config() const { return config_; }
// Should only be used for inspecting properties of the layer in tests. // Should only be used for inspecting properties of the layer in tests.
const ui::Layer* layer_for_testing() const { return layer_.get(); } const ui::Layer* layer_for_testing() const { return layer_.get(); }
...@@ -107,6 +111,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop, ...@@ -107,6 +111,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop,
// this to to remove our InkDropEventHandler override. // this to to remove our InkDropEventHandler override.
InkDropHostView* ink_drop_host_view_ = nullptr; InkDropHostView* ink_drop_host_view_ = nullptr;
// Contains the colors and opacities used to paint.
InstallableInkDropConfig config_;
// The layer we paint to. // The layer we paint to.
std::unique_ptr<ui::Layer> layer_; std::unique_ptr<ui::Layer> layer_;
......
// Copyright 2019 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_INSTALLABLE_INK_DROP_CONFIG_H_
#define UI_VIEWS_ANIMATION_INSTALLABLE_INK_DROP_CONFIG_H_
#include "third_party/skia/include/core/SkColor.h"
namespace views {
struct InstallableInkDropConfig {
// The color of ink drop effects, modulated by opacity.
SkColor base_color;
// The opacity to paint |base_color| at for a fully-visible ripple.
float ripple_opacity;
// The opacity to paint |base_color| at for a fully-visible hover highlight.
float highlight_opacity;
};
} // namespace views
#endif // UI_VIEWS_ANIMATION_INSTALLABLE_INK_DROP_CONFIG_H_
...@@ -14,15 +14,7 @@ ...@@ -14,15 +14,7 @@
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/geometry/vector2d_f.h"
#include "ui/views/animation/installable_ink_drop_config.h"
namespace {
// Placeholder colors and alphas. TODO(crbug.com/933384): get rid of
// these and make colors configurable, with same defaults as existing
// ink drops.
constexpr SkColor kInstallableInkDropBaseColor = SK_ColorBLACK;
constexpr float kInstallableInkDropHighlightedOpacity = 0.08;
constexpr float kInstallableInkDropActivatedOpacity = 0.16;
} // namespace
namespace views { namespace views {
...@@ -45,19 +37,18 @@ void InstallableInkDropPainter::Paint(gfx::Canvas* canvas, ...@@ -45,19 +37,18 @@ void InstallableInkDropPainter::Paint(gfx::Canvas* canvas,
// If fully filled, there is no need to draw the highlight, and we can draw // If fully filled, there is no need to draw the highlight, and we can draw
// the activated color more efficiently as a rectangle. // the activated color more efficiently as a rectangle.
if (state_->flood_fill_progress == 1.0f) { if (state_->flood_fill_progress == 1.0f) {
canvas->FillRect( canvas->FillRect(gfx::Rect(size),
gfx::Rect(size), SkColorSetA(config_->base_color,
SkColorSetA(kInstallableInkDropBaseColor, config_->ripple_opacity * SK_AlphaOPAQUE));
kInstallableInkDropActivatedOpacity * SK_AlphaOPAQUE));
return; return;
} }
if (state_->highlighted_ratio > 0.0f) { if (state_->highlighted_ratio > 0.0f) {
canvas->FillRect( canvas->FillRect(
gfx::Rect(size), gfx::Rect(size),
SkColorSetA(kInstallableInkDropBaseColor, SkColorSetA(config_->base_color, config_->highlight_opacity *
kInstallableInkDropHighlightedOpacity * state_->highlighted_ratio *
state_->highlighted_ratio * SK_AlphaOPAQUE)); SK_AlphaOPAQUE));
} }
if (state_->flood_fill_progress > 0.0f) { if (state_->flood_fill_progress > 0.0f) {
...@@ -71,9 +62,8 @@ void InstallableInkDropPainter::Paint(gfx::Canvas* canvas, ...@@ -71,9 +62,8 @@ void InstallableInkDropPainter::Paint(gfx::Canvas* canvas,
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setStyle(cc::PaintFlags::kFill_Style); flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor( flags.setColor(SkColorSetA(config_->base_color,
SkColorSetA(kInstallableInkDropBaseColor, config_->ripple_opacity * SK_AlphaOPAQUE));
kInstallableInkDropActivatedOpacity * SK_AlphaOPAQUE));
canvas->DrawCircle(state_->flood_fill_center, cur_radius, flags); canvas->DrawCircle(state_->flood_fill_center, cur_radius, flags);
} }
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
namespace views { namespace views {
struct InstallableInkDropConfig;
// Holds the current visual state of the installable ink drop and handles // Holds the current visual state of the installable ink drop and handles
// painting it. The |Painter::Paint()| implementation draws a rectangular ink // painting it. The |Painter::Paint()| implementation draws a rectangular ink
// drop of the given size; the user should set a clip path via // drop of the given size; the user should set a clip path via
...@@ -26,8 +28,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter { ...@@ -26,8 +28,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter {
float highlighted_ratio = 0.0f; float highlighted_ratio = 0.0f;
}; };
// |state| must outlive |this|. // Pointer arguments must outlive |this|.
explicit InstallableInkDropPainter(const State* state) : state_(state) {} InstallableInkDropPainter(const InstallableInkDropConfig* config,
const State* state)
: config_(config), state_(state) {}
~InstallableInkDropPainter() override = default; ~InstallableInkDropPainter() override = default;
// Painter: // Painter:
...@@ -35,6 +39,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter { ...@@ -35,6 +39,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter {
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
private: private:
// Contains the colors and opacities we use to paint, given the current state.
// This isn't modified inside this class, but it can be modified by our user.
const InstallableInkDropConfig* const config_;
// The current visual state. This isn't modified inside this class, but it can // The current visual state. This isn't modified inside this class, but it can
// be modified by our user. // be modified by our user.
const State* const state_; const State* const state_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment