Commit 57c995e6 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[Multipaste] Make colors consistent with the specs

This CL ensures that the colors used by the multipaste menu are
consistent with the specs. In detail, this CL does the following jobs:
(1) Correct the image border color.
(2) Modify the menu item highlight color.
(3) Change the menu text's style and color.

Bug: 1141694, 1131729
Change-Id: I5a55b66cbf9bc0abc97160b4fb7ca2cd030363e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493833
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#821775}
parent bf786ddd
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/clipboard/clipboard_history_util.h" #include "ash/clipboard/clipboard_history_util.h"
#include "ash/public/cpp/rounded_image_view.h" #include "ash/public/cpp/rounded_image_view.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/style/scoped_light_mode_as_default.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
...@@ -48,6 +49,9 @@ constexpr int kRoundedCornerRadius = 4; ...@@ -48,6 +49,9 @@ constexpr int kRoundedCornerRadius = 4;
// The thickness of the image border. // The thickness of the image border.
constexpr int kBorderThickness = 1; constexpr int kBorderThickness = 1;
// The opacity of the image shown in a disabled item view.
constexpr float kDisabledAlpha = 0.38f;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FadeImageView // FadeImageView
// An ImageView which reacts to updates from ClipboardHistoryResourceManager by // An ImageView which reacts to updates from ClipboardHistoryResourceManager by
...@@ -241,9 +245,7 @@ ClipboardHistoryBitmapItemView::CreateContentsView() { ...@@ -241,9 +245,7 @@ ClipboardHistoryBitmapItemView::CreateContentsView() {
image_view->SetPreferredSize(gfx::Size(INT_MAX, kBitmapHeight)); image_view->SetPreferredSize(gfx::Size(INT_MAX, kBitmapHeight));
image_view_ = contents_view->AddChildView(std::move(image_view)); image_view_ = contents_view->AddChildView(std::move(image_view));
image_view_->SetBorder(views::CreateRoundedRectBorder( image_view_->SetBorder(views::CreateRoundedRectBorder(
kBorderThickness, kRoundedCornerRadius, kBorderThickness, kRoundedCornerRadius, gfx::kPlaceholderColor));
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kHairlineBorderColor)));
contents_view->InstallDeleteButton(); contents_view->InstallDeleteButton();
return contents_view; return contents_view;
} }
...@@ -253,6 +255,18 @@ void ClipboardHistoryBitmapItemView::OnBoundsChanged( ...@@ -253,6 +255,18 @@ void ClipboardHistoryBitmapItemView::OnBoundsChanged(
UpdateChildImageViewSize(); UpdateChildImageViewSize();
} }
void ClipboardHistoryBitmapItemView::OnThemeChanged() {
// Use the light mode as default because the light mode is the default mode of
// the native theme which decides the context menu's background color.
// TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed.
ScopedLightModeAsDefault scoped_light_mode_as_default;
ClipboardHistoryItemView::OnThemeChanged();
image_view_->border()->set_color(
AshColorProvider::Get()->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kHairlineBorderColor));
}
std::unique_ptr<RoundedImageView> std::unique_ptr<RoundedImageView>
ClipboardHistoryBitmapItemView::BuildImageView() { ClipboardHistoryBitmapItemView::BuildImageView() {
// `BuildImageView()` achieves the image's rounded corners through // `BuildImageView()` achieves the image's rounded corners through
...@@ -261,21 +275,21 @@ ClipboardHistoryBitmapItemView::BuildImageView() { ...@@ -261,21 +275,21 @@ ClipboardHistoryBitmapItemView::BuildImageView() {
// if menu items have their own layers, the part beyond the container's bounds // if menu items have their own layers, the part beyond the container's bounds
// is still visible when the context menu is in overflow. // is still visible when the context menu is in overflow.
const float image_opacity = IsItemEnabled() ? 1.f : kDisabledAlpha;
switch (ClipboardHistoryUtil::CalculateMainFormat( switch (ClipboardHistoryUtil::CalculateMainFormat(
clipboard_history_item()->data()) clipboard_history_item()->data())
.value()) { .value()) {
case ui::ClipboardInternalFormat::kHtml: case ui::ClipboardInternalFormat::kHtml:
return std::make_unique<FadeImageView>(this, clipboard_history_item(), return std::make_unique<FadeImageView>(this, clipboard_history_item(),
resource_manager_, resource_manager_, image_opacity);
GetContentsOpacity());
case ui::ClipboardInternalFormat::kBitmap: { case ui::ClipboardInternalFormat::kBitmap: {
auto image_view = std::make_unique<RoundedImageView>( auto image_view = std::make_unique<RoundedImageView>(
kRoundedCornerRadius, RoundedImageView::Alignment::kCenter); kRoundedCornerRadius, RoundedImageView::Alignment::kCenter);
gfx::ImageSkia bitmap_image = gfx::ImageSkia::CreateFrom1xBitmap( gfx::ImageSkia bitmap_image = gfx::ImageSkia::CreateFrom1xBitmap(
clipboard_history_item()->data().bitmap()); clipboard_history_item()->data().bitmap());
if (GetContentsOpacity() != 1.f) { if (image_opacity != 1.f) {
bitmap_image = gfx::ImageSkiaOperations::CreateTransparentImage( bitmap_image = gfx::ImageSkiaOperations::CreateTransparentImage(
bitmap_image, GetContentsOpacity()); bitmap_image, image_opacity);
} }
image_view->SetImage(bitmap_image); image_view->SetImage(bitmap_image);
return image_view; return image_view;
......
...@@ -36,6 +36,7 @@ class ClipboardHistoryBitmapItemView : public ClipboardHistoryItemView { ...@@ -36,6 +36,7 @@ class ClipboardHistoryBitmapItemView : public ClipboardHistoryItemView {
const char* GetClassName() const override; const char* GetClassName() const override;
std::unique_ptr<ContentsView> CreateContentsView() override; std::unique_ptr<ContentsView> CreateContentsView() override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnThemeChanged() override;
// Builds `image_view_`. // Builds `image_view_`.
std::unique_ptr<RoundedImageView> BuildImageView(); std::unique_ptr<RoundedImageView> BuildImageView();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/clipboard/views/clipboard_history_text_item_view.h" #include "ash/clipboard/views/clipboard_history_text_item_view.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/style/scoped_light_mode_as_default.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
...@@ -27,15 +28,16 @@ ...@@ -27,15 +28,16 @@
namespace { namespace {
// The opacity of the disabled item view.
constexpr float kDisabledAlpha = 0.38f;
// The insets within the contents view. // The insets within the contents view.
constexpr gfx::Insets kContentsInsets(/*vertical=*/4, /*horizontal=*/16); constexpr gfx::Insets kContentsInsets(/*vertical=*/4, /*horizontal=*/16);
// The size of the `DeleteButton`. // The size of the `DeleteButton`.
constexpr int kDeleteButtonSizeDip = 16; constexpr int kDeleteButtonSizeDip = 16;
// The menu background's color type.
constexpr ash::AshColorProvider::BaseLayerType kMenuBackgroundColorType =
ash::AshColorProvider::BaseLayerType::kOpaque;
} // namespace } // namespace
namespace ash { namespace ash {
...@@ -80,20 +82,32 @@ class ash::ClipboardHistoryItemView::MainButton : public views::Button { ...@@ -80,20 +82,32 @@ class ash::ClipboardHistoryItemView::MainButton : public views::Button {
private: private:
// views::Button: // views::Button:
void OnThemeChanged() override {
views::Button::OnThemeChanged();
SchedulePaint();
}
const char* GetClassName() const override { return "MainButton"; } const char* GetClassName() const override { return "MainButton"; }
void PaintButtonContents(gfx::Canvas* canvas) override { void PaintButtonContents(gfx::Canvas* canvas) override {
if (!container_->ShouldHighlight()) if (!container_->ShouldHighlight())
return; return;
// Use the light mode as default because the light mode is the default mode
// of the native theme which decides the context menu's background color.
// TODO(andrewxu): remove this line after https://crbug.com/1143009 is
// fixed.
ScopedLightModeAsDefault scoped_light_mode_as_default;
// Highlight the background when the menu item is selected or pressed. // Highlight the background when the menu item is selected or pressed.
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setAntiAlias(true); flags.setAntiAlias(true);
const ui::NativeTheme::ColorId color_id = const auto* color_provider = AshColorProvider::Get();
ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor; const AshColorProvider::RippleAttributes ripple_attributes =
flags.setColor(GetNativeTheme()->GetSystemColor(color_id)); color_provider->GetRippleAttributes(
color_provider->GetBaseLayerColor(kMenuBackgroundColorType));
flags.setColor(SkColorSetA(ripple_attributes.base_color,
ripple_attributes.highlight_opacity * 0xFF));
flags.setStyle(cc::PaintFlags::kFill_Style); flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawRect(GetLocalBounds(), flags); canvas->DrawRect(GetLocalBounds(), flags);
} }
...@@ -113,9 +127,6 @@ ClipboardHistoryItemView::DeleteButton::DeleteButton( ...@@ -113,9 +127,6 @@ ClipboardHistoryItemView::DeleteButton::DeleteButton(
SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER); SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE); SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
SetPreferredSize(gfx::Size(kDeleteButtonSizeDip, kDeleteButtonSizeDip)); SetPreferredSize(gfx::Size(kDeleteButtonSizeDip, kDeleteButtonSizeDip));
AshColorProvider::Get()->DecorateCloseButton(this, kDeleteButtonSizeDip,
kCloseButtonIcon);
} }
ClipboardHistoryItemView::DeleteButton::~DeleteButton() = default; ClipboardHistoryItemView::DeleteButton::~DeleteButton() = default;
...@@ -124,6 +135,17 @@ const char* ClipboardHistoryItemView::DeleteButton::GetClassName() const { ...@@ -124,6 +135,17 @@ const char* ClipboardHistoryItemView::DeleteButton::GetClassName() const {
return "DeleteButton"; return "DeleteButton";
} }
void ClipboardHistoryItemView::DeleteButton::OnThemeChanged() {
// Use the light mode as default because the light mode is the default mode of
// the native theme which decides the context menu's background color.
// TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed.
ScopedLightModeAsDefault scoped_light_mode_as_default;
views::ImageButton::OnThemeChanged();
AshColorProvider::Get()->DecorateCloseButton(this, kDeleteButtonSizeDip,
kCloseButtonIcon);
}
// static // static
std::unique_ptr<ClipboardHistoryItemView> std::unique_ptr<ClipboardHistoryItemView>
ClipboardHistoryItemView::CreateFromClipboardHistoryItem( ClipboardHistoryItemView::CreateFromClipboardHistoryItem(
...@@ -230,8 +252,8 @@ void ClipboardHistoryItemView::RecordButtonPressedHistogram( ...@@ -230,8 +252,8 @@ void ClipboardHistoryItemView::RecordButtonPressedHistogram(
*clipboard_history_item_); *clipboard_history_item_);
} }
float ClipboardHistoryItemView::GetContentsOpacity() const { bool ClipboardHistoryItemView::IsItemEnabled() const {
return container_->GetEnabled() ? 1.f : kDisabledAlpha; return container_->GetEnabled();
} }
gfx::Size ClipboardHistoryItemView::CalculatePreferredSize() const { gfx::Size ClipboardHistoryItemView::CalculatePreferredSize() const {
...@@ -263,7 +285,7 @@ int ClipboardHistoryItemView::CalculateCommandId() const { ...@@ -263,7 +285,7 @@ int ClipboardHistoryItemView::CalculateCommandId() const {
} }
bool ClipboardHistoryItemView::ShouldHighlight() const { bool ClipboardHistoryItemView::ShouldHighlight() const {
return pseudo_focus_ == PseudoFocus::kMainButton && container_->GetEnabled(); return pseudo_focus_ == PseudoFocus::kMainButton && IsItemEnabled();
} }
bool ClipboardHistoryItemView::ShouldShowDeleteButton() const { bool ClipboardHistoryItemView::ShouldShowDeleteButton() const {
......
...@@ -58,6 +58,7 @@ class ClipboardHistoryItemView : public views::View { ...@@ -58,6 +58,7 @@ class ClipboardHistoryItemView : public views::View {
private: private:
// views::ImageButton: // views::ImageButton:
const char* GetClassName() const override; const char* GetClassName() const override;
void OnThemeChanged() override;
}; };
// Used by subclasses to draw contents, such as text or bitmaps. // Used by subclasses to draw contents, such as text or bitmaps.
...@@ -98,9 +99,9 @@ class ClipboardHistoryItemView : public views::View { ...@@ -98,9 +99,9 @@ class ClipboardHistoryItemView : public views::View {
// Creates the contents view. // Creates the contents view.
virtual std::unique_ptr<ContentsView> CreateContentsView() = 0; virtual std::unique_ptr<ContentsView> CreateContentsView() = 0;
// Returns the opacity of the menu item view's contents depending on the // Returns whether the item view is enabled. The item view is disabled when
// enabled state. // it is not allowed to read clipboard data.
float GetContentsOpacity() const; bool IsItemEnabled() const;
const ClipboardHistoryItem* clipboard_history_item() { const ClipboardHistoryItem* clipboard_history_item() {
return clipboard_history_item_; return clipboard_history_item_;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "ash/clipboard/clipboard_history_resource_manager.h" #include "ash/clipboard/clipboard_history_resource_manager.h"
#include "ash/clipboard/clipboard_history_util.h" #include "ash/clipboard/clipboard_history_util.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/scoped_light_mode_as_default.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_config.h" #include "ui/views/controls/menu/menu_config.h"
...@@ -79,19 +81,37 @@ ClipboardHistoryTextItemView::CreateContentsView() { ...@@ -79,19 +81,37 @@ ClipboardHistoryTextItemView::CreateContentsView() {
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
auto* label = label_ = contents_view->AddChildView(std::make_unique<views::Label>(text_));
contents_view->AddChildView(std::make_unique<views::Label>(text_)); label_->SetPreferredSize(gfx::Size(INT_MAX, kLabelPreferredHeight));
label->SetPreferredSize(gfx::Size(INT_MAX, kLabelPreferredHeight)); label_->SetFontList(views::style::GetFont(views::style::CONTEXT_TOUCH_MENU,
label->SetFontList(views::MenuConfig::instance().font_list); views::style::STYLE_PRIMARY));
label->SetMultiLine(false); label_->SetMultiLine(false);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetEnabledColor( label_->SetAutoColorReadabilityEnabled(/*enabled=*/false);
SkColorSetA(SK_ColorBLACK, 0xFF * GetContentsOpacity())); layout->SetFlexForView(label_, /*flex_weight=*/1);
layout->SetFlexForView(label, /*flex_weights=*/1);
contents_view->InstallDeleteButton(); contents_view->InstallDeleteButton();
return contents_view; return contents_view;
} }
void ClipboardHistoryTextItemView::OnThemeChanged() {
// Use the light mode as default because the light mode is the default mode of
// the native theme which decides the context menu's background color.
// TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed.
ScopedLightModeAsDefault scoped_light_mode_as_default;
ClipboardHistoryItemView::OnThemeChanged();
// Calculate the text color.
const auto color_type =
IsItemEnabled() ? AshColorProvider::ContentLayerType::kTextColorPrimary
: AshColorProvider::ContentLayerType::kTextColorSecondary;
const SkColor text_color =
AshColorProvider::Get()->GetContentLayerColor(color_type);
label_->SetEnabledColor(text_color);
label_->SchedulePaint();
}
} // namespace ash } // namespace ash
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/clipboard/views/clipboard_history_item_view.h" #include "ash/clipboard/views/clipboard_history_item_view.h"
namespace views { namespace views {
class Label;
class MenuItemView; class MenuItemView;
} // namespace views } // namespace views
...@@ -31,9 +32,12 @@ class ClipboardHistoryTextItemView : public ClipboardHistoryItemView { ...@@ -31,9 +32,12 @@ class ClipboardHistoryTextItemView : public ClipboardHistoryItemView {
// ClipboardHistoryItemView: // ClipboardHistoryItemView:
const char* GetClassName() const override; const char* GetClassName() const override;
std::unique_ptr<ContentsView> CreateContentsView() override; std::unique_ptr<ContentsView> CreateContentsView() override;
void OnThemeChanged() override;
// Text to show. // Text to show.
const base::string16 text_; const base::string16 text_;
views::Label* label_ = nullptr;
}; };
} // namespace ash } // namespace ash
......
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