Selectively retrieve text around a touched point.
authorleandrogracia@chromium.org <leandrogracia@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Apr 2012 19:44:17 +0000 (19:44 +0000)
committerleandrogracia@chromium.org <leandrogracia@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Apr 2012 19:44:17 +0000 (19:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82460

Reviewed by Darin Fisher.

Implements an embedding API to WebCore's SurroundingText, adding also
the possibility of select and highlight the retrieved text range.

* WebKit.gyp:
* public/WebFrame.h:
(WebFrame):
* public/WebHitTestResult.h: Added.
(WebCore):
(WebKit):
(WebHitTestResult):
(WebKit::WebHitTestResult::WebHitTestResult):
(WebKit::WebHitTestResult::~WebHitTestResult):
* public/WebRange.h:
(WebKit):
(WebRange):
* public/WebSurroundingText.h: Added.
(WebCore):
(WebKit):
(WebSurroundingText):
(WebKit::WebSurroundingText::WebSurroundingText):
(WebKit::WebSurroundingText::~WebSurroundingText):
* public/WebView.h:
(WebKit):
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::selectRange):
(WebKit):
* src/WebFrameImpl.h:
(WebFrameImpl):
* src/WebHitTestResult.cpp: Added.
(WebKit):
(WebKit::WebHitTestResult::node):
(WebKit::WebHitTestResult::localPoint):
(WebKit::WebHitTestResult::WebHitTestResult):
(WebKit::WebHitTestResult::operator=):
(WebKit::WebHitTestResult::operator HitTestResult):
(WebKit::WebHitTestResult::isNull):
(WebKit::WebHitTestResult::assign):
(WebKit::WebHitTestResult::reset):
* src/WebRange.cpp:
(WebKit::WebRange::textQuads):
(WebKit):
* src/WebSurroundingText.cpp: Added.
(WebKit):
(WebKit::WebSurroundingText::initialize):
(WebKit::WebSurroundingText::textContent):
(WebKit::WebSurroundingText::hitOffsetInTextContent):
(WebKit::WebSurroundingText::rangeFromContentOffsets):
(WebKit::WebSurroundingText::isNull):
(WebKit::WebSurroundingText::reset):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@115472 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gyp
Source/WebKit/chromium/public/WebFrame.h
Source/WebKit/chromium/public/WebHitTestResult.h [new file with mode: 0644]
Source/WebKit/chromium/public/WebRange.h
Source/WebKit/chromium/public/WebSurroundingText.h [new file with mode: 0644]
Source/WebKit/chromium/public/WebView.h
Source/WebKit/chromium/src/WebFrameImpl.cpp
Source/WebKit/chromium/src/WebFrameImpl.h
Source/WebKit/chromium/src/WebHitTestResult.cpp [new file with mode: 0644]
Source/WebKit/chromium/src/WebRange.cpp
Source/WebKit/chromium/src/WebSurroundingText.cpp [new file with mode: 0644]

index 7e3c1c5..d02a216 100644 (file)
@@ -1,3 +1,60 @@
+2012-04-27  Leandro Gracia Gil  <leandrogracia@chromium.org>
+
+        Selectively retrieve text around a touched point.
+        https://bugs.webkit.org/show_bug.cgi?id=82460
+
+        Reviewed by Darin Fisher.
+
+        Implements an embedding API to WebCore's SurroundingText, adding also
+        the possibility of select and highlight the retrieved text range.
+
+        * WebKit.gyp:
+        * public/WebFrame.h:
+        (WebFrame):
+        * public/WebHitTestResult.h: Added.
+        (WebCore):
+        (WebKit):
+        (WebHitTestResult):
+        (WebKit::WebHitTestResult::WebHitTestResult):
+        (WebKit::WebHitTestResult::~WebHitTestResult):
+        * public/WebRange.h:
+        (WebKit):
+        (WebRange):
+        * public/WebSurroundingText.h: Added.
+        (WebCore):
+        (WebKit):
+        (WebSurroundingText):
+        (WebKit::WebSurroundingText::WebSurroundingText):
+        (WebKit::WebSurroundingText::~WebSurroundingText):
+        * public/WebView.h:
+        (WebKit):
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::selectRange):
+        (WebKit):
+        * src/WebFrameImpl.h:
+        (WebFrameImpl):
+        * src/WebHitTestResult.cpp: Added.
+        (WebKit):
+        (WebKit::WebHitTestResult::node):
+        (WebKit::WebHitTestResult::localPoint):
+        (WebKit::WebHitTestResult::WebHitTestResult):
+        (WebKit::WebHitTestResult::operator=):
+        (WebKit::WebHitTestResult::operator HitTestResult):
+        (WebKit::WebHitTestResult::isNull):
+        (WebKit::WebHitTestResult::assign):
+        (WebKit::WebHitTestResult::reset):
+        * src/WebRange.cpp:
+        (WebKit::WebRange::textQuads):
+        (WebKit):
+        * src/WebSurroundingText.cpp: Added.
+        (WebKit):
+        (WebKit::WebSurroundingText::initialize):
+        (WebKit::WebSurroundingText::textContent):
+        (WebKit::WebSurroundingText::hitOffsetInTextContent):
+        (WebKit::WebSurroundingText::rangeFromContentOffsets):
+        (WebKit::WebSurroundingText::isNull):
+        (WebKit::WebSurroundingText::reset):
+
 2012-04-27  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Unreviewed, rolling out r115463.
index 7bf4423..569896d 100644 (file)
                 'public/WebGeolocationPosition.h',
                 'public/WebGlyphCache.h',
                 'public/WebHistoryItem.h',
+                'public/WebHitTestResult.h',
                 'public/WebIDBCallbacks.h',
                 'public/WebIDBCursor.h',
                 'public/WebIDBDatabase.h',
                 'public/WebStorageNamespace.h',
                 'public/WebStorageQuotaCallbacks.h',
                 'public/WebStorageQuotaType.h',
+                'public/WebSurroundingText.h',
                 'public/WebStreamTextureClient.h',
                 'public/WebTextAffinity.h',
                 'public/WebTextCaseSensitivity.h',
                 'src/WebGlyphCache.cpp',
                 'src/WebGraphicsContext3D.cpp',
                 'src/WebHistoryItem.cpp',
+                'src/WebHitTestResult.cpp',
                 'src/WebIconLoadingCompletionImpl.cpp',
                 'src/WebIconLoadingCompletionImpl.h',
                 'src/WebIDBCallbacksImpl.cpp',
                 'src/WebStorageEventDispatcherImpl.h',
                 'src/WebStorageQuotaCallbacksImpl.cpp',
                 'src/WebStorageQuotaCallbacksImpl.h',
+                'src/WebSurroundingText.cpp',
                 'src/WebTextRun.cpp',
                 'src/WebURLLoadTiming.cpp',
                 'src/WebScopedUserGesture.cpp',
index 349b1fe..da795ae 100644 (file)
@@ -450,6 +450,8 @@ public:
 
     virtual void selectRange(const WebPoint& start, const WebPoint& end) = 0;
 
+    virtual void selectRange(const WebRange&) = 0;
+
 
     // Printing ------------------------------------------------------------
 
diff --git a/Source/WebKit/chromium/public/WebHitTestResult.h b/Source/WebKit/chromium/public/WebHitTestResult.h
new file mode 100644 (file)
index 0000000..8fb9838
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+* Copyright (C) 2012 Google Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1.  Redistributions of source code must retain the above copyright
+*     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebHitTestResult_h
+#define WebHitTestResult_h
+
+#include "platform/WebPrivateOwnPtr.h"
+
+namespace WebCore {
+class HitTestResult;
+}
+
+namespace WebKit {
+
+class WebNode;
+struct WebPoint;
+
+// Properties of a hit test result, i.e. properties of the nodes at a given point
+// (the hit point) on the page. Both urls may be populated at the same time, for
+// example in the instance of an <img> inside an <a>.
+class WebHitTestResult {
+public:
+    WebHitTestResult() { }
+    WebHitTestResult(const WebHitTestResult& info) { assign(info); }
+    ~WebHitTestResult() { reset(); }
+
+    WEBKIT_EXPORT void assign(const WebHitTestResult&);
+    WEBKIT_EXPORT void reset();
+    WEBKIT_EXPORT bool isNull() const;
+
+    // The node that was hit (only one for point-based tests).
+    WEBKIT_EXPORT WebNode node() const;
+
+    // Coordinates of the point that was hit. Relative to the node.
+    WEBKIT_EXPORT WebPoint localPoint() const;
+
+#if WEBKIT_IMPLEMENTATION
+    WebHitTestResult(const WebCore::HitTestResult&);
+    WebHitTestResult& operator=(const WebCore::HitTestResult&);
+    operator WebCore::HitTestResult() const;
+#endif
+
+protected:
+    WebPrivateOwnPtr<WebCore::HitTestResult> m_private;
+};
+
+} // namespace WebKit
+
+#endif
index 907dfd5..37f05ec 100644 (file)
@@ -32,6 +32,7 @@
 #define WebRange_h
 
 #include "platform/WebCommon.h"
+#include "platform/WebVector.h"
 
 #if WEBKIT_IMPLEMENTATION
 namespace WebCore { class Range; }
@@ -40,6 +41,7 @@ namespace WTF { template <typename T> class PassRefPtr; }
 
 namespace WebKit {
 
+struct WebFloatQuad;
 class WebFrame;
 class WebNode;
 class WebRangePrivate;
@@ -73,6 +75,8 @@ public:
 
     WEBKIT_EXPORT static WebRange fromDocumentRange(WebFrame*, int start, int length);
 
+    WEBKIT_EXPORT WebVector<WebFloatQuad> textQuads() const;
+
 #if WEBKIT_IMPLEMENTATION
     WebRange(const WTF::PassRefPtr<WebCore::Range>&);
     WebRange& operator=(const WTF::PassRefPtr<WebCore::Range>&);
diff --git a/Source/WebKit/chromium/public/WebSurroundingText.h b/Source/WebKit/chromium/public/WebSurroundingText.h
new file mode 100644 (file)
index 0000000..dd2a3c5
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebSurroundingText_h
+#define WebSurroundingText_h
+
+#include "WebNode.h"
+#include "WebRange.h"
+#include "platform/WebPrivateOwnPtr.h"
+#include "platform/WebString.h"
+
+namespace WebCore {
+class SurroundingText;
+}
+
+namespace WebKit {
+
+class WebHitTestResult;
+
+class WebSurroundingText {
+public:
+    WebSurroundingText() { }
+    ~WebSurroundingText() { reset(); }
+
+    WEBKIT_EXPORT bool isNull() const;
+    WEBKIT_EXPORT void reset();
+
+    // Initializes the object go get the surrounding text centered in the position described by the hit test.
+    // The maximum length of the contents retrieved is defined by maxLength.
+    WEBKIT_EXPORT void initialize(const WebHitTestResult&, size_t maxLength);
+
+    // Initializes the object go get the surrounding text centered in the selected offset of the given node.
+    // The maximum length of the contents retrieved is defined by maxLength.
+    WEBKIT_EXPORT void initialize(WebNode textNode, size_t offset, size_t maxLength);
+
+    // Surrounding text content retrieved.
+    WEBKIT_EXPORT WebString textContent() const;
+
+    // Offset in the text content of the initial hit position (or provided offset in the node).
+    WEBKIT_EXPORT size_t hitOffsetInTextContent() const;
+
+    // Convert start/end positions in the content text string into a WebKit text range.
+    WEBKIT_EXPORT WebRange rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent);
+
+protected:
+    WebPrivateOwnPtr<WebCore::SurroundingText> m_private;
+};
+
+} // namespace WebKit
+
+#endif
index bad8b53..5ee3d10 100644 (file)
@@ -51,6 +51,7 @@ class WebGraphicsContext3D;
 class WebNode;
 class WebPageOverlay;
 class WebPermissionClient;
+class WebRange;
 class WebSettings;
 class WebSpellCheckClient;
 class WebString;
index c26ff8c..79597ff 100644 (file)
@@ -1413,6 +1413,13 @@ void WebFrameImpl::selectRange(const WebPoint& start, const WebPoint& end)
         frame()->selection()->setSelection(selection, CharacterGranularity);
 }
 
+void WebFrameImpl::selectRange(const WebRange& webRange)
+{
+    RefPtr<Range> range = static_cast<PassRefPtr<Range> >(webRange);
+    if (range)
+        frame()->selection()->setSelectedRange(range.get(), WebCore::VP_DEFAULT_AFFINITY, false);
+}
+
 VisiblePosition WebFrameImpl::visiblePositionForWindowPoint(const WebPoint& point)
 {
     HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move;
index 8856d86..c3acc1a 100644 (file)
@@ -175,6 +175,7 @@ public:
     virtual WebString selectionAsMarkup() const;
     virtual bool selectWordAroundCaret();
     virtual void selectRange(const WebPoint& start, const WebPoint& end);
+    virtual void selectRange(const WebRange&);
     virtual int printBegin(const WebSize& pageSize,
                            const WebNode& constrainToNode,
                            int printerDPI,
diff --git a/Source/WebKit/chromium/src/WebHitTestResult.cpp b/Source/WebKit/chromium/src/WebHitTestResult.cpp
new file mode 100644 (file)
index 0000000..a827e25
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+* Copyright (C) 2012 Google Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1.  Redistributions of source code must retain the above copyright
+*     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebHitTestResult.h"
+
+#include "Element.h"
+#include "HitTestResult.h"
+#include "KURL.h"
+#include "Node.h"
+#include "RenderObject.h"
+#include "VisiblePosition.h"
+#include "WebNode.h"
+
+#include "platform/WebPoint.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebNode WebHitTestResult::node() const
+{
+    return WebNode(m_private->innerNode());
+}
+
+WebPoint WebHitTestResult::localPoint() const
+{
+    return WebPoint(m_private->localPoint());
+}
+
+WebHitTestResult::WebHitTestResult(const HitTestResult& result)
+{
+    m_private.reset(new HitTestResult(result));
+}
+
+WebHitTestResult& WebHitTestResult::operator=(const HitTestResult& result)
+{
+    m_private.reset(new HitTestResult(result));
+    return *this;
+}
+
+WebHitTestResult::operator HitTestResult() const
+{
+    return *m_private.get();
+}
+
+bool WebHitTestResult::isNull() const
+{
+    return !m_private.get();
+}
+
+void WebHitTestResult::assign(const WebHitTestResult& info)
+{
+    m_private.reset(new HitTestResult(info));
+}
+
+void WebHitTestResult::reset()
+{
+    m_private.reset(0);
+}
+
+} // namespace WebKit
index 05a4212..be24dd7 100644 (file)
 
 #include "Document.h"
 #include "Frame.h"
+#include "FrameView.h"
 #include "Range.h"
 #include "TextIterator.h"
 #include "WebFrameImpl.h"
 #include "WebNode.h"
+#include "platform/WebFloatQuad.h"
 #include "platform/WebString.h"
 #include <wtf/PassRefPtr.h>
 
@@ -99,6 +101,27 @@ WebRange WebRange::fromDocumentRange(WebFrame* frame, int start, int length)
     return TextIterator::rangeFromLocationAndLength(scope, start, length);
 }
 
+WebVector<WebFloatQuad> WebRange::textQuads() const
+{
+    if (isNull())
+        return WebVector<WebFloatQuad>();
+
+    Frame* frame = m_private->ownerDocument() ? m_private->ownerDocument()->frame() : 0;
+    if (!frame)
+        return WebVector<WebFloatQuad>();
+
+    Vector<FloatQuad> quads;
+    m_private->textQuads(quads);
+    for (unsigned i = 0; i < quads.size(); ++i) {
+        quads[i].setP1(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p1())));
+        quads[i].setP2(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p2())));
+        quads[i].setP3(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p3())));
+        quads[i].setP4(frame->view()->contentsToWindow(roundedIntPoint(quads[i].p4())));
+    }
+
+    return quads;
+}
+
 WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range)
     : m_private(static_cast<WebRangePrivate*>(range.leakRef()))
 {
diff --git a/Source/WebKit/chromium/src/WebSurroundingText.cpp b/Source/WebKit/chromium/src/WebSurroundingText.cpp
new file mode 100644 (file)
index 0000000..30fe09d
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebSurroundingText.h"
+
+#include "Element.h"
+#include "Node.h"
+#include "Range.h"
+#include "RenderObject.h"
+#include "SurroundingText.h"
+#include "Text.h"
+#include "VisiblePosition.h"
+#include "WebHitTestResult.h"
+
+#include "platform/WebPoint.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebSurroundingText::initialize(const WebHitTestResult& hitTestInfo, size_t maxLength)
+{
+    Node* node = hitTestInfo.node().unwrap<Node>();
+    if (!node || !node->renderer())
+        return;
+
+    VisiblePosition visiblePosition(node->renderer()->positionForPoint(hitTestInfo.localPoint()));
+    if (visiblePosition.isNull())
+        return;
+
+    m_private.reset(new SurroundingText(visiblePosition, maxLength));
+}
+
+void WebSurroundingText::initialize(WebNode textNode, size_t offset, size_t maxLength)
+{
+    Node* node = textNode.unwrap<Node>();
+    if (!node || !node->isTextNode() || offset >= node->nodeValue().length())
+        return;
+
+    m_private.reset(new SurroundingText(VisiblePosition(Position(toText(node), offset).parentAnchoredEquivalent(), DOWNSTREAM), maxLength));
+}
+
+WebString WebSurroundingText::textContent() const
+{
+    return m_private->content();
+}
+
+size_t WebSurroundingText::hitOffsetInTextContent() const
+{
+    return m_private->positionOffsetInContent();
+}
+
+WebRange WebSurroundingText::rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent)
+{
+    return m_private->rangeFromContentOffsets(startOffsetInContent, endOffsetInContent);
+}
+
+bool WebSurroundingText::isNull() const
+{
+    return !m_private.get();
+}
+
+void WebSurroundingText::reset()
+{
+    m_private.reset(0);
+}
+
+} // namespace WebKit