Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: Source/web/mac/WebSubstringUtil.mm

Issue 1311373002: Make WebSubstringUtil to use EphemeralRange instead of Range (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/mac/WebSubstringUtil.mm
diff --git a/Source/web/mac/WebSubstringUtil.mm b/Source/web/mac/WebSubstringUtil.mm
index 30ff0accb18dccbb2a6518d65809b26dc0c402c6..c5ea739b1a65dad42e4a08db7f25964d5d8decd3 100644
--- a/Source/web/mac/WebSubstringUtil.mm
+++ b/Source/web/mac/WebSubstringUtil.mm
@@ -59,14 +59,14 @@
using namespace blink;
-static NSAttributedString* attributedSubstringFromRange(const Range* range)
+static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& range)
{
NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init];
NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
- size_t length = range->endOffset() - range->startOffset();
+ size_t length = range.endPosition().computeOffsetInContainerNode() - range.startPosition().computeOffsetInContainerNode();
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();
if (!numCharacters)
continue;
@@ -127,13 +127,14 @@ NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo
// Expand to word under point.
VisibleSelection selection(range);
selection.expandUsingGranularity(WordGranularity);
- RefPtrWillBeRawPtr<Range> wordRange = selection.toNormalizedRange();
+ const EphemeralRange wordRange = selection.toNormalizedEphemeralRange();
// Convert to NSAttributedString.
- NSAttributedString* string = attributedSubstringFromRange(wordRange.get());
+ NSAttributedString* string = attributedSubstringFromRange(wordRange);
// 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();
stringPoint.setY(frameView->height() - stringPoint.y());
@@ -162,8 +163,7 @@ NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame*
if (ephemeralRange.isNull())
return nil;
- RefPtrWillBeRawPtr<Range> range = Range::create(ephemeralRange.document(), ephemeralRange.startPosition(), ephemeralRange.endPosition());
- return attributedSubstringFromRange(range.get());
+ return attributedSubstringFromRange(ephemeralRange);
}
} // namespace blink
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698