Commit c78fe095 authored by yosin@chromium.org's avatar yosin@chromium.org

Make WebSubstringUtil to use EphemeralRange instead of Range

This patch changes |WebSubstringUtil| class to use |EphemeralRange| instead
of |Range| object to avoid registering temporary |Range| object into |Document|
for Oilpan friendly.

This patch is also a preparation of making selection to handle granularity for
web component, http://crrev.com/1277863002 to reduce DOM position dependency
from |VisibleSelection| for ease of templatization of |VisibleSelection|.

BUG=388681, 513568
TEST=n/a; no behavior changes

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201120 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 14324a40
...@@ -59,14 +59,14 @@ ...@@ -59,14 +59,14 @@
using namespace blink; using namespace blink;
static NSAttributedString* attributedSubstringFromRange(const Range* range) static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& range)
{ {
NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]; NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init];
NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
size_t length = range->endOffset() - range->startOffset(); size_t length = range.endPosition().computeOffsetInContainerNode() - range.startPosition().computeOffsetInContainerNode();
unsigned position = 0; unsigned position = 0;
for (TextIterator it(range->startPosition(), range->endPosition()); !it.atEnd() && [string length] < length; it.advance()) { for (TextIterator it(range.startPosition(), range.endPosition()); !it.atEnd() && [string length] < length; it.advance()) {
unsigned numCharacters = it.length(); unsigned numCharacters = it.length();
if (!numCharacters) if (!numCharacters)
continue; continue;
...@@ -127,13 +127,14 @@ NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo ...@@ -127,13 +127,14 @@ NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo
// Expand to word under point. // Expand to word under point.
VisibleSelection selection(range); VisibleSelection selection(range);
selection.expandUsingGranularity(WordGranularity); selection.expandUsingGranularity(WordGranularity);
RefPtrWillBeRawPtr<Range> wordRange = selection.toNormalizedRange(); const EphemeralRange wordRange = selection.toNormalizedEphemeralRange();
// Convert to NSAttributedString. // Convert to NSAttributedString.
NSAttributedString* string = attributedSubstringFromRange(wordRange.get()); NSAttributedString* string = attributedSubstringFromRange(wordRange);
// Compute bottom left corner and convert to AppKit coordinates. // Compute bottom left corner and convert to AppKit coordinates.
IntRect stringRect = enclosingIntRect(wordRange->boundingRect()); // TODO(yosin) We shold avoid to create |Range| object.
IntRect stringRect = enclosingIntRect(createRange(wordRange)->boundingRect());
IntPoint stringPoint = stringRect.minXMaxYCorner(); IntPoint stringPoint = stringRect.minXMaxYCorner();
stringPoint.setY(frameView->height() - stringPoint.y()); stringPoint.setY(frameView->height() - stringPoint.y());
...@@ -162,8 +163,7 @@ NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame* ...@@ -162,8 +163,7 @@ NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame*
if (ephemeralRange.isNull()) if (ephemeralRange.isNull())
return nil; return nil;
RefPtrWillBeRawPtr<Range> range = Range::create(ephemeralRange.document(), ephemeralRange.startPosition(), ephemeralRange.endPosition()); return attributedSubstringFromRange(ephemeralRange);
return attributedSubstringFromRange(range.get());
} }
} // namespace blink } // namespace blink
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