Commit 0bb62b7d authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Extend WebSurroundingText to accept a WebRange.

This will make it possible to get the text surrounding the
current selection by calling WebFrame::selectionRange() and
passing that range to WebSurroundingText.

BUG=330238

Review URL: https://codereview.chromium.org/294073005

git-svn-id: svn://svn.chromium.org/blink/trunk@176168 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent dde63ab6
...@@ -48,6 +48,12 @@ void WebSurroundingText::initialize(const WebNode& webNode, const WebPoint& node ...@@ -48,6 +48,12 @@ void WebSurroundingText::initialize(const WebNode& webNode, const WebPoint& node
m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(nodePoint))).deepEquivalent().parentAnchoredEquivalent(), maxLength)); m_private.reset(new SurroundingText(VisiblePosition(node->renderer()->positionForPoint(static_cast<IntPoint>(nodePoint))).deepEquivalent().parentAnchoredEquivalent(), maxLength));
} }
void WebSurroundingText::initialize(const WebRange& webRange, size_t maxLength)
{
if (RefPtrWillBeRawPtr<Range> range = static_cast<PassRefPtrWillBeRawPtr<Range> >(webRange))
m_private.reset(new SurroundingText(*range, maxLength));
}
WebString WebSurroundingText::textContent() const WebString WebSurroundingText::textContent() const
{ {
return m_private->content(); return m_private->content();
...@@ -59,6 +65,16 @@ size_t WebSurroundingText::hitOffsetInTextContent() const ...@@ -59,6 +65,16 @@ size_t WebSurroundingText::hitOffsetInTextContent() const
return m_private->startOffsetInContent(); return m_private->startOffsetInContent();
} }
size_t WebSurroundingText::startOffsetInTextContent() const
{
return m_private->startOffsetInContent();
}
size_t WebSurroundingText::endOffsetInTextContent() const
{
return m_private->endOffsetInContent();
}
WebRange WebSurroundingText::rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent) WebRange WebSurroundingText::rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent)
{ {
return m_private->rangeFromContentOffsets(startOffsetInContent, endOffsetInContent); return m_private->rangeFromContentOffsets(startOffsetInContent, endOffsetInContent);
......
...@@ -38,8 +38,11 @@ namespace blink { ...@@ -38,8 +38,11 @@ namespace blink {
class WebHitTestResult; class WebHitTestResult;
class WebNode; class WebNode;
class WebRange;
struct WebPoint; struct WebPoint;
// WebSurroundingText is a Blink API that gives access to the SurroundingText
// API. It allows caller to know the text surrounding a point or a range.
class WebSurroundingText { class WebSurroundingText {
public: public:
WebSurroundingText() { } WebSurroundingText() { }
...@@ -48,17 +51,34 @@ public: ...@@ -48,17 +51,34 @@ public:
BLINK_EXPORT bool isNull() const; BLINK_EXPORT bool isNull() const;
BLINK_EXPORT void reset(); BLINK_EXPORT void reset();
// Initializes the object to get the surrounding text centered in the position relative to a provided node. // Initializes the object to get the surrounding text centered in the
// position relative to a provided node.
// The maximum length of the contents retrieved is defined by maxLength. // The maximum length of the contents retrieved is defined by maxLength.
BLINK_EXPORT void initialize(const WebNode&, const WebPoint&, size_t maxLength); BLINK_EXPORT void initialize(const WebNode&, const WebPoint&, size_t maxLength);
// Initializes the object to get the text surrounding a given range.
// The maximum length of the contents retrieved is defined by maxLength.
// It does not include the text inside the range.
BLINK_EXPORT void initialize(const WebRange&, size_t maxLength);
// Surrounding text content retrieved. // Surrounding text content retrieved.
BLINK_EXPORT WebString textContent() const; BLINK_EXPORT WebString textContent() const;
// Offset in the text content of the initial hit position (or provided offset in the node). // Offset in the text content of the initial hit position (or provided
// offset in the node).
// This should only be called when WebSurroundingText has been initialized
// with a WebPoint.
// DEPRECATED: use startOffsetInTextContent() or endOffsetInTextContent().
BLINK_EXPORT size_t hitOffsetInTextContent() const; BLINK_EXPORT size_t hitOffsetInTextContent() const;
// Convert start/end positions in the content text string into a WebKit text range. // Start offset of the initial text in the text content.
BLINK_EXPORT size_t startOffsetInTextContent() const;
// End offset of the initial text in the text content.
BLINK_EXPORT size_t endOffsetInTextContent() const;
// Convert start/end positions in the content text string into a WebKit text
// range.
BLINK_EXPORT WebRange rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent); BLINK_EXPORT WebRange rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent);
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment