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