Commit 97ea8201 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[Multipaste] Create file item view - Part 1

This CL is a part of the efforts to create multipaste menu items
for copied files. This CL does the following jobs:

(1) Create a new type for `ClipboardHistoryDisplayFormat` called `kFile`.

(2) Move the code related to the text label out of ClipboardHistoryText-
ItemView. Instead, create `ClipboardHistoryLabel` for the text label
used by the multipaste menu.

Right now a `ClipboardHistoryTextItemView` instance is built for a
clipboard data whose display format is `kFile`. So this CL does not
introduce any visual difference.

Bug: 1134392
Change-Id: I7fb4b9ce5d37fcd298b5cfefcd9dcee0ad160c26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547225
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#829854}
parent 8a6ee440
...@@ -325,6 +325,8 @@ component("ash") { ...@@ -325,6 +325,8 @@ component("ash") {
"clipboard/views/clipboard_history_bitmap_item_view.h", "clipboard/views/clipboard_history_bitmap_item_view.h",
"clipboard/views/clipboard_history_item_view.cc", "clipboard/views/clipboard_history_item_view.cc",
"clipboard/views/clipboard_history_item_view.h", "clipboard/views/clipboard_history_item_view.h",
"clipboard/views/clipboard_history_label.cc",
"clipboard/views/clipboard_history_label.h",
"clipboard/views/clipboard_history_text_item_view.cc", "clipboard/views/clipboard_history_text_item_view.cc",
"clipboard/views/clipboard_history_text_item_view.h", "clipboard/views/clipboard_history_text_item_view.h",
"dbus/ash_dbus_services.cc", "dbus/ash_dbus_services.cc",
......
...@@ -57,8 +57,11 @@ ClipboardHistoryDisplayFormat CalculateDisplayFormat( ...@@ -57,8 +57,11 @@ ClipboardHistoryDisplayFormat CalculateDisplayFormat(
case ui::ClipboardInternalFormat::kRtf: case ui::ClipboardInternalFormat::kRtf:
case ui::ClipboardInternalFormat::kBookmark: case ui::ClipboardInternalFormat::kBookmark:
case ui::ClipboardInternalFormat::kWeb: case ui::ClipboardInternalFormat::kWeb:
case ui::ClipboardInternalFormat::kCustom:
return ClipboardHistoryDisplayFormat::kText; return ClipboardHistoryDisplayFormat::kText;
case ui::ClipboardInternalFormat::kCustom:
return ContainsFileSystemData(data)
? ClipboardHistoryDisplayFormat::kFile
: ClipboardHistoryDisplayFormat::kText;
} }
} }
......
...@@ -54,7 +54,8 @@ enum class ClipboardHistoryDisplayFormat { ...@@ -54,7 +54,8 @@ enum class ClipboardHistoryDisplayFormat {
kText = 0, kText = 0,
kBitmap = 1, kBitmap = 1,
kHtml = 2, kHtml = 2,
kMaxValue = 2, kFile = 3,
kMaxValue = 3,
}; };
// Returns the main format of the specified clipboard `data`. // Returns the main format of the specified clipboard `data`.
......
...@@ -187,6 +187,8 @@ ClipboardHistoryItemView::CreateFromClipboardHistoryItem( ...@@ -187,6 +187,8 @@ ClipboardHistoryItemView::CreateFromClipboardHistoryItem(
case ClipboardHistoryUtil::ClipboardHistoryDisplayFormat::kHtml: case ClipboardHistoryUtil::ClipboardHistoryDisplayFormat::kHtml:
return std::make_unique<ClipboardHistoryBitmapItemView>( return std::make_unique<ClipboardHistoryBitmapItemView>(
&item, resource_manager, container); &item, resource_manager, container);
case ClipboardHistoryUtil::ClipboardHistoryDisplayFormat::kFile:
return std::make_unique<ClipboardHistoryTextItemView>(&item, container);
} }
} }
......
...@@ -118,7 +118,7 @@ class ClipboardHistoryItemView : public views::View { ...@@ -118,7 +118,7 @@ class ClipboardHistoryItemView : public views::View {
// it is not allowed to read clipboard data. // it is not allowed to read clipboard data.
bool IsItemEnabled() const; bool IsItemEnabled() const;
const ClipboardHistoryItem* clipboard_history_item() { const ClipboardHistoryItem* clipboard_history_item() const {
return clipboard_history_item_; return clipboard_history_item_;
} }
......
// Copyright 2020 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.
#include "ash/clipboard/views/clipboard_history_label.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/scoped_light_mode_as_default.h"
namespace {
// The preferred height for the label.
constexpr int kLabelPreferredHeight = 32;
} // namespace
namespace ash {
ClipboardHistoryLabel::ClipboardHistoryLabel(const base::string16& text)
: views::Label(text) {
SetPreferredSize(gfx::Size(INT_MAX, kLabelPreferredHeight));
SetFontList(views::style::GetFont(views::style::CONTEXT_TOUCH_MENU,
views::style::STYLE_PRIMARY));
SetMultiLine(false);
SetHorizontalAlignment(gfx::ALIGN_LEFT);
SetAutoColorReadabilityEnabled(false);
}
const char* ClipboardHistoryLabel::GetClassName() const {
return "ClipboardHistoryLabel";
}
void ClipboardHistoryLabel::OnThemeChanged() {
views::Label::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.
ash::ScopedLightModeAsDefault scoped_light_mode_as_default;
const auto color_type =
GetEnabled()
? ash::AshColorProvider::ContentLayerType::kTextColorPrimary
: ash::AshColorProvider::ContentLayerType::kTextColorSecondary;
SetEnabledColor(
ash::AshColorProvider::Get()->GetContentLayerColor(color_type));
}
} // namespace ash
// Copyright 2020 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 ASH_CLIPBOARD_VIEWS_CLIPBOARD_HISTORY_LABEL_H_
#define ASH_CLIPBOARD_VIEWS_CLIPBOARD_HISTORY_LABEL_H_
#include "ui/views/controls/label.h"
namespace ash {
// The text label used by the clipboard history menu.
class ClipboardHistoryLabel : public views::Label {
public:
explicit ClipboardHistoryLabel(const base::string16& text);
ClipboardHistoryLabel(const ClipboardHistoryLabel& rhs) = delete;
ClipboardHistoryLabel& operator=(const ClipboardHistoryLabel& rhs) = delete;
~ClipboardHistoryLabel() override = default;
// views::Label:
const char* GetClassName() const override;
void OnThemeChanged() override;
};
} // namespace ash
#endif // ASH_CLIPBOARD_VIEWS_CLIPBOARD_HISTORY_LABEL_H_
...@@ -7,20 +7,14 @@ ...@@ -7,20 +7,14 @@
#include "ash/clipboard/clipboard_history_controller_impl.h" #include "ash/clipboard/clipboard_history_controller_impl.h"
#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/clipboard/views/clipboard_history_label.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/menu/menu_config.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
namespace { namespace {
// The preferred height for the label.
constexpr int kLabelPreferredHeight = 32;
// The margins of the delete button. // The margins of the delete button.
constexpr gfx::Insets kDeleteButtonMargins = constexpr gfx::Insets kDeleteButtonMargins =
gfx::Insets(/*top=*/0, /*left=*/8, /*bottom=*/0, /*right=*/4); gfx::Insets(/*top=*/0, /*left=*/8, /*bottom=*/0, /*right=*/4);
...@@ -34,8 +28,20 @@ namespace ash { ...@@ -34,8 +28,20 @@ namespace ash {
class ClipboardHistoryTextItemView::TextContentsView class ClipboardHistoryTextItemView::TextContentsView
: public ClipboardHistoryTextItemView::ContentsView { : public ClipboardHistoryTextItemView::ContentsView {
public: public:
explicit TextContentsView(ClipboardHistoryItemView* container) explicit TextContentsView(ClipboardHistoryTextItemView* container)
: ContentsView(container) {} : ContentsView(container) {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
auto* label =
AddChildView(std::make_unique<ClipboardHistoryLabel>(container->text_));
layout->SetFlexForView(label, /*flex_weight=*/1);
label->SetEnabled(container->IsItemEnabled());
InstallDeleteButton();
}
TextContentsView(const TextContentsView& rhs) = delete; TextContentsView(const TextContentsView& rhs) = delete;
TextContentsView& operator=(const TextContentsView& rhs) = delete; TextContentsView& operator=(const TextContentsView& rhs) = delete;
~TextContentsView() override = default; ~TextContentsView() override = default;
...@@ -70,25 +76,7 @@ ClipboardHistoryTextItemView::~ClipboardHistoryTextItemView() = default; ...@@ -70,25 +76,7 @@ ClipboardHistoryTextItemView::~ClipboardHistoryTextItemView() = default;
std::unique_ptr<ClipboardHistoryTextItemView::ContentsView> std::unique_ptr<ClipboardHistoryTextItemView::ContentsView>
ClipboardHistoryTextItemView::CreateContentsView() { ClipboardHistoryTextItemView::CreateContentsView() {
auto contents_view = std::make_unique<TextContentsView>(this); return std::make_unique<TextContentsView>(this);
auto* layout =
contents_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
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;
} }
base::string16 ClipboardHistoryTextItemView::GetAccessibleName() const { base::string16 ClipboardHistoryTextItemView::GetAccessibleName() const {
...@@ -99,23 +87,4 @@ const char* ClipboardHistoryTextItemView::GetClassName() const { ...@@ -99,23 +87,4 @@ const char* ClipboardHistoryTextItemView::GetClassName() const {
return "ClipboardHistoryTextItemView"; return "ClipboardHistoryTextItemView";
} }
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,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#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
...@@ -33,12 +32,9 @@ class ClipboardHistoryTextItemView : public ClipboardHistoryItemView { ...@@ -33,12 +32,9 @@ class ClipboardHistoryTextItemView : public ClipboardHistoryItemView {
std::unique_ptr<ContentsView> CreateContentsView() override; std::unique_ptr<ContentsView> CreateContentsView() override;
base::string16 GetAccessibleName() const override; base::string16 GetAccessibleName() const override;
const char* GetClassName() const override; const char* GetClassName() const 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