Skip to content

Commit

Permalink
ui/base: move clipboard to own folder.
Browse files Browse the repository at this point in the history
ClipboardOzone needs to depend on ui/ozone in order to call
OzonePlatform::GetPlatformClipboard, but as long as all the base::clipboard
classes are part of ui/base source set, and ui/ozone depends on
ui/base, it's impossible to depend on ui/ozone. And that
creates a circular dependency.

Thus, factor out clipboard source files and make appropriate source sets,
which will be used by clients on their needs instead of depending on
everything.

Bug: 922465
Change-Id: I97cd4013be096a1dd1af8e1da4678aa83f93ca42
Reviewed-on: https://chromium-review.googlesource.com/c/1369933
Reviewed-by: Cait Phillips <caitkp@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#625654}
  • Loading branch information
msisov authored and Commit Bot committed Jan 24, 2019
1 parent 9be6131 commit a33072d
Show file tree
Hide file tree
Showing 145 changed files with 1,665 additions and 1,465 deletions.
2 changes: 1 addition & 1 deletion ash/app_list/views/apps_grid_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ gfx::Size AppsGridView::CalculatePreferredSize() const {

bool AppsGridView::GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
// TODO(koz): Only accept a specific drag type for app shortcuts.
*formats = OSExchangeData::FILE_NAME;
return true;
Expand Down
5 changes: 2 additions & 3 deletions ash/app_list/views/apps_grid_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
bool OnKeyPressed(const ui::KeyEvent& event) override;
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override;
bool GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override;
bool GetDropFormats(int* formats,
std::set<ui::ClipboardFormatType>* format_types) override;
bool CanDrop(const OSExchangeData& data) override;
int OnDragUpdated(const ui::DropTargetEvent& event) override;
const char* GetClassName() const override;
Expand Down
6 changes: 3 additions & 3 deletions ash/drag_drop/drag_drop_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DragTestView : public views::View {

bool GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override {
std::set<ui::ClipboardFormatType>* format_types) override {
*formats = ui::OSExchangeData::STRING;
return true;
}
Expand Down Expand Up @@ -615,7 +615,7 @@ TEST_F(DragDropControllerTest, DragLeavesClipboardAloneTest) {
ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
scw.WriteText(base::ASCIIToUTF16(clip_str));
}
EXPECT_TRUE(cb->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
EXPECT_TRUE(cb->IsFormatAvailable(ui::ClipboardFormatType::GetPlainTextType(),
ui::CLIPBOARD_TYPE_COPY_PASTE));

std::unique_ptr<views::Widget> widget = CreateTestWidget();
Expand All @@ -636,7 +636,7 @@ TEST_F(DragDropControllerTest, DragLeavesClipboardAloneTest) {

// Verify the clipboard contents haven't changed
std::string result;
EXPECT_TRUE(cb->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
EXPECT_TRUE(cb->IsFormatAvailable(ui::ClipboardFormatType::GetPlainTextType(),
ui::CLIPBOARD_TYPE_COPY_PASTE));
cb->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
EXPECT_EQ(clip_str, result);
Expand Down
2 changes: 1 addition & 1 deletion ash/drag_drop/drag_drop_interactive_uitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TargetView : public views::View {
// views::View overrides:
bool GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override {
std::set<ui::ClipboardFormatType>* format_types) override {
*formats = ui::OSExchangeData::STRING;
return true;
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ jumbo_static_library("extensions") {
"//third_party/zlib/google:zip",
"//ui/accessibility:ax_enums_mojo",
"//ui/base",
"//ui/base/clipboard",
"//ui/base/ime",
"//ui/display/manager",
"//ui/gfx",
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/pdf/pdf_extension_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_tree.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/test/test_clipboard.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/gfx/geometry/point.h"
#include "url/gurl.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ bool RenderViewContextMenu::IsPasteAndMatchStyleEnabled() const {
return false;

return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable(
ui::Clipboard::GetPlainTextFormatType(),
ui::ClipboardFormatType::GetPlainTextType(),
ui::CLIPBOARD_TYPE_COPY_PASTE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,27 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgIsFormatAvailable(
switch (format) {
case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
bool plain = clipboard->IsFormatAvailable(
ui::Clipboard::GetPlainTextFormatType(), type);
ui::ClipboardFormatType::GetPlainTextType(), type);
bool plainw = clipboard->IsFormatAvailable(
ui::Clipboard::GetPlainTextWFormatType(), type);
ui::ClipboardFormatType::GetPlainTextWType(), type);
available = plain || plainw;
break;
}
case PP_FLASH_CLIPBOARD_FORMAT_HTML:
available = clipboard->IsFormatAvailable(
ui::Clipboard::GetHtmlFormatType(), type);
ui::ClipboardFormatType::GetHtmlType(), type);
break;
case PP_FLASH_CLIPBOARD_FORMAT_RTF:
available =
clipboard->IsFormatAvailable(ui::Clipboard::GetRtfFormatType(), type);
available = clipboard->IsFormatAvailable(
ui::ClipboardFormatType::GetRtfType(), type);
break;
case PP_FLASH_CLIPBOARD_FORMAT_INVALID:
break;
default:
if (custom_formats_.IsFormatRegistered(format)) {
std::string format_name = custom_formats_.GetFormatName(format);
std::string clipboard_data;
clipboard->ReadData(ui::Clipboard::GetPepperCustomDataFormatType(),
clipboard->ReadData(ui::ClipboardFormatType::GetPepperCustomDataType(),
&clipboard_data);
base::Pickle pickle(clipboard_data.data(), clipboard_data.size());
available =
Expand All @@ -211,8 +211,8 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgReadData(
int32_t result = PP_ERROR_FAILED;
switch (format) {
case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: {
if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
type)) {
if (clipboard->IsFormatAvailable(
ui::ClipboardFormatType::GetPlainTextWType(), type)) {
base::string16 text;
clipboard->ReadText(type, &text);
if (!text.empty()) {
Expand All @@ -223,15 +223,15 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgReadData(
}
// If the PlainTextW format isn't available or is empty, take the
// ASCII text format.
if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
type)) {
if (clipboard->IsFormatAvailable(
ui::ClipboardFormatType::GetPlainTextType(), type)) {
result = PP_OK;
clipboard->ReadAsciiText(type, &clipboard_string);
}
break;
}
case PP_FLASH_CLIPBOARD_FORMAT_HTML: {
if (!clipboard->IsFormatAvailable(ui::Clipboard::GetHtmlFormatType(),
if (!clipboard->IsFormatAvailable(ui::ClipboardFormatType::GetHtmlType(),
type)) {
break;
}
Expand All @@ -247,7 +247,7 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgReadData(
break;
}
case PP_FLASH_CLIPBOARD_FORMAT_RTF: {
if (!clipboard->IsFormatAvailable(ui::Clipboard::GetRtfFormatType(),
if (!clipboard->IsFormatAvailable(ui::ClipboardFormatType::GetRtfType(),
type)) {
break;
}
Expand All @@ -262,7 +262,7 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgReadData(
base::string16 format_name =
base::UTF8ToUTF16(custom_formats_.GetFormatName(format));
std::string clipboard_data;
clipboard->ReadData(ui::Clipboard::GetPepperCustomDataFormatType(),
clipboard->ReadData(ui::ClipboardFormatType::GetPepperCustomDataType(),
&clipboard_data);
base::Pickle pickle(clipboard_data.data(), clipboard_data.size());
if (IsFormatAvailableInPickle(format_name, pickle)) {
Expand Down Expand Up @@ -342,7 +342,7 @@ int32_t PepperFlashClipboardMessageFilter::OnMsgWriteData(
base::Pickle pickle;
WriteDataToPickle(custom_data_map, &pickle);
scw.WritePickledData(pickle,
ui::Clipboard::GetPepperCustomDataFormatType());
ui::ClipboardFormatType::GetPepperCustomDataType());
}

if (res != PP_OK) {
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ jumbo_split_static_library("ui") {
"//third_party/zlib",
"//ui/accessibility",
"//ui/base",
"//ui/base/clipboard",
"//ui/base/ime",
"//ui/compositor",
"//ui/content_accelerators",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ChromeScreenshotGrabberBrowserTest

bool IsImageClipboardAvailable() {
return ui::Clipboard::GetForCurrentThread()->IsFormatAvailable(
ui::Clipboard::GetBitmapFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE);
ui::ClipboardFormatType::GetBitmapType(),
ui::CLIPBOARD_TYPE_COPY_PASTE);
}

scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/omnibox/clipboard_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
base::string16 GetClipboardText() {
// Try text format.
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
if (clipboard->IsFormatAvailable(ui::ClipboardFormatType::GetPlainTextWType(),
ui::CLIPBOARD_TYPE_COPY_PASTE)) {
base::string16 text;
clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text);
Expand All @@ -26,7 +26,7 @@ base::string16 GetClipboardText() {
// and pastes from the URL bar to itself, the text will get fixed up and
// cannonicalized, which is not what the user expects. By pasting in this
// order, we are sure to paste what the user copied.
if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
if (clipboard->IsFormatAvailable(ui::ClipboardFormatType::GetUrlWType(),
ui::CLIPBOARD_TYPE_COPY_PASTE)) {
std::string url_str;
clipboard->ReadBookmark(NULL, &url_str);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void BookmarkBarView::PaintChildren(const views::PaintInfo& paint_info) {

bool BookmarkBarView::GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
if (!model_ || !model_->loaded())
return false;
*formats = ui::OSExchangeData::URL;
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/views/bookmarks/bookmark_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ class BookmarkBarView : public views::AccessiblePaneView,
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override;
void PaintChildren(const views::PaintInfo& paint_info) override;
bool GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override;
bool GetDropFormats(int* formats,
std::set<ui::ClipboardFormatType>* format_types) override;
bool AreDropTypesRequired() override;
bool CanDrop(const ui::OSExchangeData& data) override;
void OnDragEntered(const ui::DropTargetEvent& event) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "ui/aura/env_observer.h"
#include "ui/aura/window.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/test/test_clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/test/ui_controls.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/views/background.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool BookmarkMenuController::ShouldExecuteCommandWithoutClosingMenu(
bool BookmarkMenuController::GetDropFormats(
MenuItemView* menu,
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
return menu_delegate_->GetDropFormats(menu, formats, format_types);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ class BookmarkMenuController : public bookmarks::BaseBookmarkModelObserver,
void ExecuteCommand(int id, int mouse_event_flags) override;
bool ShouldExecuteCommandWithoutClosingMenu(int id,
const ui::Event& e) override;
bool GetDropFormats(
views::MenuItemView* menu,
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override;
bool GetDropFormats(views::MenuItemView* menu,
int* formats,
std::set<ui::ClipboardFormatType>* format_types) override;
bool AreDropTypesRequired(views::MenuItemView* menu) override;
bool CanDrop(views::MenuItemView* menu,
const ui::OSExchangeData& data) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool BookmarkMenuDelegate::ShouldExecuteCommandWithoutClosingMenu(
bool BookmarkMenuDelegate::GetDropFormats(
MenuItemView* menu,
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
*formats = ui::OSExchangeData::URL;
format_types->insert(BookmarkNodeData::GetBookmarkFormatType());
return true;
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ class BookmarkMenuDelegate : public bookmarks::BaseBookmarkModelObserver,
const ui::Event& e);
void ExecuteCommand(int id, int mouse_event_flags);
bool ShouldExecuteCommandWithoutClosingMenu(int id, const ui::Event& e);
bool GetDropFormats(
views::MenuItemView* menu,
int* formats,
std::set<ui::Clipboard::FormatType>* format_types);
bool GetDropFormats(views::MenuItemView* menu,
int* formats,
std::set<ui::ClipboardFormatType>* format_types);
bool AreDropTypesRequired(views::MenuItemView* menu);
bool CanDrop(views::MenuItemView* menu, const ui::OSExchangeData& data);
int GetDropOperation(views::MenuItemView* item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BrowserActionDragData::BrowserActionDragData(
}

bool BrowserActionDragData::GetDropFormats(
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
format_types->insert(GetBrowserActionFormatType());
return true;
}
Expand Down Expand Up @@ -73,10 +73,10 @@ bool BrowserActionDragData::Read(const ui::OSExchangeData& data) {
}

// static
const ui::Clipboard::FormatType&
const ui::ClipboardFormatType&
BrowserActionDragData::GetBrowserActionFormatType() {
static base::NoDestructor<ui::Clipboard::FormatType> format(
ui::Clipboard::GetFormatType(kClipboardFormatString));
static base::NoDestructor<ui::ClipboardFormatType> format(
ui::ClipboardFormatType::GetType(kClipboardFormatString));

return *format;
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/views/extensions/browser_action_drag_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BrowserActionDragData {
// These mirror the views::View and views::MenuDelegate methods for dropping,
// and return the appropriate results for being able to drop an extension's
// BrowserAction view.
static bool GetDropFormats(std::set<ui::Clipboard::FormatType>* format_types);
static bool GetDropFormats(std::set<ui::ClipboardFormatType>* format_types);
static bool AreDropTypesRequired();
static bool CanDrop(const ui::OSExchangeData& data, const Profile* profile);

Expand All @@ -46,8 +46,8 @@ class BrowserActionDragData {
// Restores this data from the clipboard, returning true on success.
bool Read(const ui::OSExchangeData& data);

// Returns the FormatType this class supports (for Browser Actions).
static const ui::Clipboard::FormatType& GetBrowserActionFormatType();
// Returns the ClipboardFormatType this class supports (for Browser Actions).
static const ui::ClipboardFormatType& GetBrowserActionFormatType();
#endif

private:
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/frame/browser_root_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ BrowserRootView::~BrowserRootView() = default;

bool BrowserRootView::GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) {
std::set<ui::ClipboardFormatType>* format_types) {
if (tabstrip()->visible() || toolbar()->visible()) {
*formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING;
return true;
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/views/frame/browser_root_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class BrowserRootView : public views::internal::RootView {
~BrowserRootView() override;

// views::View:
bool GetDropFormats(
int* formats,
std::set<ui::Clipboard::FormatType>* format_types) override;
bool GetDropFormats(int* formats,
std::set<ui::ClipboardFormatType>* format_types) override;
bool AreDropTypesRequired() override;
bool CanDrop(const ui::OSExchangeData& data) override;
void OnDragEntered(const ui::DropTargetEvent& event) override;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/location_bar/location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "extensions/common/feature_switch.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_keyboard_controller.h"
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/location_bar/location_icon_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/label.h"

Expand Down
Loading

0 comments on commit a33072d

Please sign in to comment.