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) {
}
void AvatarToolbarButton::OnThemeChanged() {
ToolbarButton::OnThemeChanged();
UpdateIcon();
UpdateText();
}
......
......@@ -231,6 +231,7 @@ void BrowserAppMenuButton::ShowMenu(int run_types) {
}
void BrowserAppMenuButton::OnThemeChanged() {
AppMenuButton::OnThemeChanged();
UpdateIcon();
}
......
......@@ -50,8 +50,10 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener,
set_has_ink_drop_action_on_click(true);
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_->SetConfig(GetToolbarInstallableInkDropConfig(this));
}
SetInkDropMode(InkDropMode::ON);
......@@ -160,6 +162,12 @@ void ToolbarButton::OnBoundsChanged(const gfx::Rect& 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 bounds = GetBoundsInScreen();
gfx::Insets insets =
......
......@@ -69,6 +69,7 @@ class ToolbarButton : public views::LabelButton,
// views::LabelButton:
void SetText(const base::string16& text) override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnThemeChanged() override;
gfx::Rect GetAnchorBoundsInScreen() const override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
......
......@@ -16,10 +16,15 @@
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop_host_view.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/view.h"
#include "ui/views/view_class_properties.h"
namespace {
constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f;
}
gfx::Insets GetToolbarInkDropInsets(const views::View* host_view,
const gfx::Insets& margin_insets) {
// TODO(pbos): Inkdrop masks and layers should be flipped with RTL. Fix this
......@@ -54,7 +59,6 @@ void SetToolbarButtonHighlightPath(views::View* host_view,
std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
const views::InkDropHostView* host_view) {
constexpr float kToolbarInkDropHighlightVisibleOpacity = 0.08f;
auto highlight = host_view->views::InkDropHostView::CreateInkDropHighlight();
highlight->set_visible_opacity(kToolbarInkDropHighlightVisibleOpacity);
return highlight;
......@@ -70,3 +74,12 @@ SkColor GetToolbarInkDropBaseColor(const views::View* host_view) {
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 {
class InkDropHighlight;
class InkDropHostView;
class View;
struct InstallableInkDropConfig;
} // namespace views
constexpr float kToolbarInkDropVisibleOpacity = 0.06f;
......@@ -36,4 +37,7 @@ std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
// Returns the ink drop base color that should be used by all toolbar buttons.
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_
......@@ -85,6 +85,7 @@ jumbo_component("views") {
"animation/ink_drop_util.h",
"animation/installable_ink_drop.h",
"animation/installable_ink_drop_animator.h",
"animation/installable_ink_drop_config.h",
"animation/installable_ink_drop_painter.h",
"animation/scroll_animator.h",
"animation/square_ink_drop_ripple.h",
......
......@@ -16,6 +16,7 @@
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
......@@ -28,14 +29,27 @@
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{
"InstallableInkDrop", base::FEATURE_DISABLED_BY_DEFAULT};
InstallableInkDrop::InstallableInkDrop(View* view)
: view_(view),
config_(GetPlaceholderInstallableInkDropConfig()),
layer_(std::make_unique<ui::Layer>()),
event_handler_(view_, this),
painter_(&visual_state_),
painter_(&config_, &visual_state_),
animation_container_(base::MakeRefCounted<gfx::AnimationContainer>()),
animator_(layer_->size(),
&visual_state_,
......@@ -81,6 +95,11 @@ InstallableInkDrop::~InstallableInkDrop() {
view_->RemoveObserver(this);
}
void InstallableInkDrop::SetConfig(InstallableInkDropConfig config) {
config_ = config;
SchedulePaint();
}
void InstallableInkDrop::HostSizeChanged(const gfx::Size& new_size) {
layer_->SetBounds(gfx::Rect(new_size) + layer_->bounds().OffsetFromOrigin());
layer_->SchedulePaint(gfx::Rect(layer_->size()));
......
......@@ -14,6 +14,7 @@
#include "ui/views/animation/ink_drop_event_handler.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_config.h"
#include "ui/views/animation/installable_ink_drop_painter.h"
#include "ui/views/view_observer.h"
#include "ui/views/views_export.h"
......@@ -60,6 +61,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop,
~InstallableInkDrop() override;
void SetConfig(InstallableInkDropConfig config);
InstallableInkDropConfig config() const { return config_; }
// Should only be used for inspecting properties of the layer in tests.
const ui::Layer* layer_for_testing() const { return layer_.get(); }
......@@ -107,6 +111,9 @@ class VIEWS_EXPORT InstallableInkDrop : public InkDrop,
// this to to remove our InkDropEventHandler override.
InkDropHostView* ink_drop_host_view_ = nullptr;
// Contains the colors and opacities used to paint.
InstallableInkDropConfig config_;
// The layer we paint to.
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 @@
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_f.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
#include "ui/views/animation/installable_ink_drop_config.h"
namespace views {
......@@ -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
// the activated color more efficiently as a rectangle.
if (state_->flood_fill_progress == 1.0f) {
canvas->FillRect(
gfx::Rect(size),
SkColorSetA(kInstallableInkDropBaseColor,
kInstallableInkDropActivatedOpacity * SK_AlphaOPAQUE));
canvas->FillRect(gfx::Rect(size),
SkColorSetA(config_->base_color,
config_->ripple_opacity * SK_AlphaOPAQUE));
return;
}
if (state_->highlighted_ratio > 0.0f) {
canvas->FillRect(
gfx::Rect(size),
SkColorSetA(kInstallableInkDropBaseColor,
kInstallableInkDropHighlightedOpacity *
state_->highlighted_ratio * SK_AlphaOPAQUE));
SkColorSetA(config_->base_color, config_->highlight_opacity *
state_->highlighted_ratio *
SK_AlphaOPAQUE));
}
if (state_->flood_fill_progress > 0.0f) {
......@@ -71,9 +62,8 @@ void InstallableInkDropPainter::Paint(gfx::Canvas* canvas,
cc::PaintFlags flags;
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(
SkColorSetA(kInstallableInkDropBaseColor,
kInstallableInkDropActivatedOpacity * SK_AlphaOPAQUE));
flags.setColor(SkColorSetA(config_->base_color,
config_->ripple_opacity * SK_AlphaOPAQUE));
canvas->DrawCircle(state_->flood_fill_center, cur_radius, flags);
}
}
......
......@@ -11,6 +11,8 @@
namespace views {
struct InstallableInkDropConfig;
// Holds the current visual state of the installable ink drop and handles
// painting it. The |Painter::Paint()| implementation draws a rectangular ink
// drop of the given size; the user should set a clip path via
......@@ -26,8 +28,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter {
float highlighted_ratio = 0.0f;
};
// |state| must outlive |this|.
explicit InstallableInkDropPainter(const State* state) : state_(state) {}
// Pointer arguments must outlive |this|.
InstallableInkDropPainter(const InstallableInkDropConfig* config,
const State* state)
: config_(config), state_(state) {}
~InstallableInkDropPainter() override = default;
// Painter:
......@@ -35,6 +39,10 @@ class VIEWS_EXPORT InstallableInkDropPainter : public Painter {
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
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
// be modified by our user.
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