summaryrefslogtreecommitdiffstats
path: root/ui/views
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-07 20:26:50 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-07 20:26:50 +0000
commit8919c55c25dda90fcc7443855f8f96e4a0947e86 (patch)
tree61f004f948397a75e878d5792456ea0db654a57e /ui/views
parentfde2cb0bc16de6a5be9e671f90370fed30dc83e5 (diff)
downloadchromium_src-8919c55c25dda90fcc7443855f8f96e4a0947e86.zip
chromium_src-8919c55c25dda90fcc7443855f8f96e4a0947e86.tar.gz
chromium_src-8919c55c25dda90fcc7443855f8f96e4a0947e86.tar.bz2
Change how ui::Clipboard is accessed so there's only one per thread.
Currently, there can be any number of Clipboard objects, which can be massively simplified. This removes interfaces for fetching the Clipboard and makes everyone go through a single static ui::Clipboard::GetForCurrentThread() access point. BUG=130805 TBR=tc (change in webkit/ is trivial) Review URL: https://chromiumcodereview.appspot.com/10911074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r--ui/views/controls/message_box_view.cc6
-rw-r--r--ui/views/controls/textfield/native_textfield_views.cc5
-rw-r--r--ui/views/controls/textfield/native_textfield_views_unittest.cc7
-rw-r--r--ui/views/controls/textfield/native_textfield_win.cc9
-rw-r--r--ui/views/controls/textfield/textfield_views_model.cc7
-rw-r--r--ui/views/controls/textfield/textfield_views_model_unittest.cc3
-rw-r--r--ui/views/test/test_views_delegate.cc9
-rw-r--r--ui/views/test/test_views_delegate.h2
-rw-r--r--ui/views/view_unittest.cc16
-rw-r--r--ui/views/views_delegate.h7
10 files changed, 21 insertions, 50 deletions
diff --git a/ui/views/controls/message_box_view.cc b/ui/views/controls/message_box_view.cc
index 960b316..5d5e909 100644
--- a/ui/views/controls/message_box_view.cc
+++ b/ui/views/controls/message_box_view.cc
@@ -17,7 +17,6 @@
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/client_view.h"
@@ -140,10 +139,7 @@ bool MessageBoxView::AcceleratorPressed(const ui::Accelerator& accelerator) {
if (prompt_field_ && prompt_field_->HasFocus())
return false;
- if (!ViewsDelegate::views_delegate)
- return false;
-
- ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (!clipboard)
return false;
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc
index f1cdf26..80474c9 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -37,7 +37,6 @@
#include "ui/views/controls/textfield/textfield_views_model.h"
#include "ui/views/ime/input_method.h"
#include "ui/views/metrics.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "unicode/uchar.h"
@@ -586,8 +585,8 @@ bool NativeTextfieldViews::IsCommandIdEnabled(int command_id) const {
case IDS_APP_COPY:
return model_->HasSelection() && !textfield_->IsObscured();
case IDS_APP_PASTE:
- ViewsDelegate::views_delegate->GetClipboard()
- ->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ ui::Clipboard::GetForCurrentThread()->ReadText(
+ ui::Clipboard::BUFFER_STANDARD, &result);
return editable && !result.empty();
case IDS_APP_DELETE:
return editable && model_->HasSelection();
diff --git a/ui/views/controls/textfield/native_textfield_views_unittest.cc b/ui/views/controls/textfield/native_textfield_views_unittest.cc
index c78bbf8..392c010 100644
--- a/ui/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/ui/views/controls/textfield/native_textfield_views_unittest.cc
@@ -34,7 +34,6 @@
#include "ui/views/ime/mock_input_method.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/widget.h"
@@ -235,14 +234,14 @@ class NativeTextfieldViewsTest : public ViewsTestBase,
string16 GetClipboardText() const {
string16 text;
- views::ViewsDelegate::views_delegate->GetClipboard()->
+ ui::Clipboard::GetForCurrentThread()->
ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
return text;
}
void SetClipboardText(const std::string& text) {
ui::ScopedClipboardWriter clipboard_writer(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
clipboard_writer.WriteText(ASCIIToUTF16(text));
}
@@ -1103,7 +1102,7 @@ TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) {
EXPECT_STR_NE(" one two three ", str);
SendKeyEvent(ui::VKEY_C, false, true);
- views::ViewsDelegate::views_delegate->GetClipboard()->
+ ui::Clipboard::GetForCurrentThread()->
ReadText(ui::Clipboard::BUFFER_STANDARD, &str);
EXPECT_STR_EQ(" one two three ", str);
diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc
index c356451..d5277d9 100644
--- a/ui/views/controls/textfield/native_textfield_win.cc
+++ b/ui/views/controls/textfield/native_textfield_win.cc
@@ -33,7 +33,6 @@
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/metrics.h"
-#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
namespace views {
@@ -560,9 +559,9 @@ void NativeTextfieldWin::OnCopy() {
return;
const string16 text(GetSelectedText());
- if (!text.empty() && ViewsDelegate::views_delegate) {
+ if (!text.empty()) {
ui::ScopedClipboardWriter scw(
- ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD);
scw.WriteText(text);
}
@@ -975,10 +974,10 @@ void NativeTextfieldWin::OnNonLButtonDown(UINT keys, const CPoint& point) {
}
void NativeTextfieldWin::OnPaste() {
- if (textfield_->read_only() || !ViewsDelegate::views_delegate)
+ if (textfield_->read_only())
return;
- ui::Clipboard* clipboard = ViewsDelegate::views_delegate->GetClipboard();
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
if (!clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
ui::Clipboard::BUFFER_STANDARD))
return;
diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc
index d51e417..89fe947 100644
--- a/ui/views/controls/textfield/textfield_views_model.cc
+++ b/ui/views/controls/textfield/textfield_views_model.cc
@@ -20,7 +20,6 @@
#include "ui/gfx/render_text.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/views_delegate.h"
namespace views {
@@ -511,7 +510,7 @@ bool TextfieldViewsModel::Redo() {
bool TextfieldViewsModel::Cut() {
if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
ui::ScopedClipboardWriter(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
// A trick to let undo/redo handle cursor correctly.
// Undoing CUT moves the cursor to the end of the change rather
@@ -529,7 +528,7 @@ bool TextfieldViewsModel::Cut() {
bool TextfieldViewsModel::Copy() {
if (!HasCompositionText() && HasSelection() && !render_text_->is_obscured()) {
ui::ScopedClipboardWriter(
- views::ViewsDelegate::views_delegate->GetClipboard(),
+ ui::Clipboard::GetForCurrentThread(),
ui::Clipboard::BUFFER_STANDARD).WriteText(GetSelectedText());
return true;
}
@@ -538,7 +537,7 @@ bool TextfieldViewsModel::Copy() {
bool TextfieldViewsModel::Paste() {
string16 result;
- views::ViewsDelegate::views_delegate->GetClipboard()
+ ui::Clipboard::GetForCurrentThread()
->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
if (!result.empty()) {
InsertTextInternal(result, false);
diff --git a/ui/views/controls/textfield/textfield_views_model_unittest.cc b/ui/views/controls/textfield/textfield_views_model_unittest.cc
index 376f7d4..a94bf4d 100644
--- a/ui/views/controls/textfield/textfield_views_model_unittest.cc
+++ b/ui/views/controls/textfield/textfield_views_model_unittest.cc
@@ -18,7 +18,6 @@
#include "ui/views/controls/textfield/textfield_views_model.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
-#include "ui/views/views_delegate.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
@@ -495,7 +494,7 @@ TEST_F(TextfieldViewsModelTest, SetText) {
#endif
TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) {
ui::Clipboard* clipboard
- = views::ViewsDelegate::views_delegate->GetClipboard();
+ = ui::Clipboard::GetForCurrentThread();
string16 initial_clipboard_text = ASCIIToUTF16("initial text");
ui::ScopedClipboardWriter(
clipboard,
diff --git a/ui/views/test/test_views_delegate.cc b/ui/views/test/test_views_delegate.cc
index 2ae2aa4..e87f18d 100644
--- a/ui/views/test/test_views_delegate.cc
+++ b/ui/views/test/test_views_delegate.cc
@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "content/public/test/web_contents_tester.h"
-#include "ui/base/clipboard/clipboard.h"
namespace views {
@@ -24,14 +23,6 @@ void TestViewsDelegate::SetUseTransparentWindows(bool transparent) {
use_transparent_windows_ = transparent;
}
-ui::Clipboard* TestViewsDelegate::GetClipboard() const {
- if (!clipboard_.get()) {
- // Note that we need a MessageLoop for the next call to work.
- clipboard_.reset(new ui::Clipboard);
- }
- return clipboard_.get();
-}
-
void TestViewsDelegate::SaveWindowPlacement(const Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h
index 54ae0be..6568196 100644
--- a/ui/views/test/test_views_delegate.h
+++ b/ui/views/test/test_views_delegate.h
@@ -28,7 +28,6 @@ class TestViewsDelegate : public ViewsDelegate {
void SetUseTransparentWindows(bool transparent);
// Overridden from ViewsDelegate:
- virtual ui::Clipboard* GetClipboard() const OVERRIDE;
virtual void SaveWindowPlacement(const Widget* window,
const std::string& window_name,
const gfx::Rect& bounds,
@@ -69,7 +68,6 @@ class TestViewsDelegate : public ViewsDelegate {
content::SiteInstance* site_instance) OVERRIDE;
private:
- mutable scoped_ptr<ui::Clipboard> clipboard_;
bool use_transparent_windows_;
DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate);
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 45d83b5..5b08793 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -1168,8 +1168,6 @@ TEST_F(ViewTest, Textfield) {
const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!");
const string16 kEmptyString;
- ui::Clipboard clipboard;
-
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(0, 0, 100, 100);
@@ -1206,7 +1204,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
const string16 kReadOnlyText = ASCIIToUTF16("Read only");
const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **");
- ui::Clipboard clipboard;
+ ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
Widget* widget = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
@@ -1235,7 +1233,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0);
string16 result;
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kNormalText, result);
normal->SetText(kNormalText); // Let's revert to the original content.
@@ -1243,7 +1241,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// Cut should have failed, so the clipboard content should not have changed.
EXPECT_EQ(kNormalText, result);
@@ -1251,7 +1249,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// Cut should have failed, so the clipboard content should not have changed.
EXPECT_EQ(kNormalText, result);
@@ -1264,19 +1262,19 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kReadOnlyText, result);
normal->SelectAll(false);
::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kNormalText, result);
password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
- clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
// We don't let you copy from an obscured field, clipboard should not have
// changed.
EXPECT_EQ(kNormalText, result);
diff --git a/ui/views/views_delegate.h b/ui/views/views_delegate.h
index 5fb3929..a3f8430 100644
--- a/ui/views/views_delegate.h
+++ b/ui/views/views_delegate.h
@@ -26,10 +26,6 @@ namespace gfx {
class Rect;
}
-namespace ui {
-class Clipboard;
-}
-
namespace views {
class NonClientFrameView;
@@ -54,9 +50,6 @@ class VIEWS_EXPORT ViewsDelegate {
virtual ~ViewsDelegate() {}
- // Gets the clipboard.
- virtual ui::Clipboard* GetClipboard() const = 0;
-
// Saves the position, size and "show" state for the window with the
// specified name.
virtual void SaveWindowPlacement(const Widget* widget,