diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 03:48:48 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 03:48:48 +0000 |
commit | ca1a894970b9f958198db39413b852a32b03b44f (patch) | |
tree | ba74132334f50bdd3e2e93590ff62fff9d033f53 /base/clipboard_win.cc | |
parent | 85624c55e5ca0bf002fa9a91f50e89824a3d4db8 (diff) | |
download | chromium_src-ca1a894970b9f958198db39413b852a32b03b44f.zip chromium_src-ca1a894970b9f958198db39413b852a32b03b44f.tar.gz chromium_src-ca1a894970b9f958198db39413b852a32b03b44f.tar.bz2 |
Lazily create the clipboard owner window. CreateWindow can take ~.5ms, and we don't need to do this until the clipboard is actually used (ctrl-c/ctrl-v).
Review URL: http://codereview.chromium.org/11398
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5963 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/clipboard_win.cc')
-rw-r--r-- | base/clipboard_win.cc | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/base/clipboard_win.cc b/base/clipboard_win.cc index adc2c25..907a402 100644 --- a/base/clipboard_win.cc +++ b/base/clipboard_win.cc @@ -131,15 +131,12 @@ Clipboard::Clipboard() { wcex.lpszClassName = L"ClipboardOwnerWindowClass"; ::RegisterClassEx(&wcex); - clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", - L"ClipboardOwnerWindow", - 0, 0, 0, 0, 0, - HWND_MESSAGE, - 0, 0, 0); + clipboard_owner_ = NULL; } Clipboard::~Clipboard() { - ::DestroyWindow(clipboard_owner_); + if (clipboard_owner_) + ::DestroyWindow(clipboard_owner_); clipboard_owner_ = NULL; } @@ -150,7 +147,7 @@ void Clipboard::WriteObjects(const ObjectMap& objects) { void Clipboard::WriteObjects(const ObjectMap& objects, base::ProcessHandle process) { ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; ::EmptyClipboard(); @@ -385,7 +382,7 @@ void Clipboard::ReadText(std::wstring* result) const { // Acquire the clipboard. ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; HANDLE data = ::GetClipboardData(CF_UNICODETEXT); @@ -406,7 +403,7 @@ void Clipboard::ReadAsciiText(std::string* result) const { // Acquire the clipboard. ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; HANDLE data = ::GetClipboardData(CF_TEXT); @@ -426,7 +423,7 @@ void Clipboard::ReadHTML(std::wstring* markup, std::string* src_url) const { // Acquire the clipboard. ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; HANDLE data = ::GetClipboardData(GetHtmlFormatType()); @@ -450,7 +447,7 @@ void Clipboard::ReadBookmark(std::wstring* title, std::string* url) const { // Acquire the clipboard. ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; HANDLE data = ::GetClipboardData(GetUrlWFormatType()); @@ -489,7 +486,7 @@ void Clipboard::ReadFiles(std::vector<std::wstring>* files) const { files->clear(); ScopedClipboard clipboard; - if (!clipboard.Acquire(clipboard_owner_)) + if (!clipboard.Acquire(GetClipboardWindow())) return; HDROP drop = static_cast<HDROP>(::GetClipboardData(CF_HDROP)); @@ -605,3 +602,14 @@ void Clipboard::FreeData(FormatType format, HANDLE data) { else ::GlobalFree(data); } + +HWND Clipboard::GetClipboardWindow() const { + if (!clipboard_owner_) { + clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", + L"ClipboardOwnerWindow", + 0, 0, 0, 0, 0, + HWND_MESSAGE, + 0, 0, 0); + } + return clipboard_owner_; +} |