diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 21:03:08 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 21:03:08 +0000 |
commit | 8bbe7efe110336916c819fdc7f5566afa3a97495 (patch) | |
tree | 6d473efd35ca0f48584dd3254e8b4e5ebd708fbb /webkit/glue | |
parent | d294668d4c62e94c342cff58b1096af8106113ef (diff) | |
download | chromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.zip chromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.tar.gz chromium_src-8bbe7efe110336916c819fdc7f5566afa3a97495.tar.bz2 |
Enable the X selection clipboard for copying html and text out of a linux test shell.
I implemented it in the webview delegate, so when we switch to the
multiprocess architecture, we will need to find out if the clipboard callback
can be async (the current method would require a sync call from browser to
renderer to get the selected text).
Review URL: http://codereview.chromium.org/12700
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 9 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 4 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 10 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 1 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 2 |
5 files changed, 22 insertions, 4 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index 4bea274..d6b2e2c 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -15,6 +15,7 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "Editor.h" #include "EventHandler.h" #include "EventNames.h" +#include "Frame.h" #include "KeyboardCodes.h" #include "HTMLInputElement.h" #include "HTMLNames.h" @@ -235,8 +236,11 @@ void EditorClientImpl::didBeginEditing() { void EditorClientImpl::respondToChangedSelection() { if (use_editor_delegate_) { WebViewDelegate* d = web_view_->delegate(); - if (d) - d->DidChangeSelection(); + if (d) { + WebCore::Frame* frame = web_view_->GetFocusedWebCoreFrame(); + if (frame) + d->DidChangeSelection(!frame->selection()->isRange()); + } } } @@ -844,4 +848,3 @@ std::wstring EditorClientImpl::Describe(WebCore::CSSStyleDeclaration* style) { // an example. But because none of them use it, it's not yet important. return std::wstring(); } - diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 05fd9327..7c6c1fc 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -272,6 +272,10 @@ class WebFrame : public base::RefCounted<WebFrame> { // Clear any text selection in the frame. virtual void ClearSelection() = 0; + // Returns the selected text if there is any. If |as_html| is true, returns + // the selection as HTML. The return value is encoded in utf-8. + virtual std::string GetSelection(bool as_html) = 0; + // Paints the contents of this web view in a bitmapped image. This image // will not have plugins drawn. Devices are cheap to copy because the data is // internally refcounted so we allocate and return a new copy diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 70cbc61..78ac3d4 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -1340,6 +1340,16 @@ void WebFrameImpl::ClearSelection() { frame()->selection()->clear(); } +std::string WebFrameImpl::GetSelection(bool as_html) { + RefPtr<Range> range = frame()->selection()->toRange(); + if (as_html) { + String markup = WebCore::createMarkup(range.get(), 0); + return webkit_glue::StringToStdString(markup); + } else { + return webkit_glue::StringToStdString(range->text()); + } +} + void WebFrameImpl::CreateFrameView() { ASSERT(frame_); // If frame_ doesn't exist, we probably didn't init properly. diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 320a114..61c9851 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -140,6 +140,7 @@ class WebFrameImpl : public WebFrame { virtual void Undo(); virtual void Redo(); virtual void ClearSelection(); + virtual std::string GetSelection(bool as_html); virtual void SetInViewSourceMode(bool enable); diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index dd6ba52..1987999 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -634,7 +634,7 @@ class WebViewDelegate : virtual public WebWidgetDelegate { return false; } virtual void DidBeginEditing() { } - virtual void DidChangeSelection() { } + virtual void DidChangeSelection(bool is_empty_selection) { } virtual void DidChangeContents() { } virtual void DidEndEditing() { } |