Index: Source/web/mac/WebSubstringUtil.mm |
diff --git a/Source/web/mac/WebSubstringUtil.mm b/Source/web/mac/WebSubstringUtil.mm |
index c5ea739b1a65dad42e4a08db7f25964d5d8decd3..92121facd292eacd2de662288b309858ff00e434 100644 |
--- a/Source/web/mac/WebSubstringUtil.mm |
+++ b/Source/web/mac/WebSubstringUtil.mm |
@@ -110,16 +110,31 @@ static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& ra |
return [string autorelease]; |
} |
+WebPoint getBaselinePoint(FrameView* frameView, const EphemeralRange& range, NSAttributedString* string) |
+{ |
+ // Compute bottom left corner and convert to AppKit coordinates. |
+ // TODO(yosin) We shold avoid to create |Range| object. See crbug.com/529985. |
+ IntRect stringRect = enclosingIntRect(createRange(range)->boundingRect()); |
+ IntPoint stringPoint = stringRect.minXMaxYCorner(); |
+ stringPoint.setY(frameView->height() - stringPoint.y()); |
+ |
+ // Adjust for the font's descender. AppKit wants the baseline point. |
+ if ([string length]) { |
+ NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NULL]; |
+ if (NSFont* font = [attributes objectForKey:NSFontAttributeName]) |
+ stringPoint.move(0, ceil(-[font descender])); |
+ } |
+ return stringPoint; |
+} |
+ |
namespace blink { |
NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPoint point, WebPoint& baselinePoint) |
{ |
HitTestResult result = static_cast<WebViewImpl*>(view)->coreHitTestResultAt(point); |
if (!result.innerNode()) |
- return nil; |
+ return nil; |
LocalFrame* frame = result.innerNode()->document().frame(); |
- FrameView* frameView = frame->view(); |
- |
EphemeralRange range = frame->rangeForPoint(result.roundedPointInInnerNodeFrame()); |
if (range.isNull()) |
return nil; |
@@ -131,27 +146,17 @@ NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo |
// Convert to NSAttributedString. |
NSAttributedString* string = attributedSubstringFromRange(wordRange); |
- |
- // Compute bottom left corner and convert to AppKit coordinates. |
- // 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()); |
- |
- // Adjust for the font's descender. AppKit wants the baseline point. |
- if ([string length]) { |
- NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NULL]; |
- NSFont* font = [attributes objectForKey:NSFontAttributeName]; |
- if (font) |
- stringPoint.move(0, ceil(-[font descender])); |
- } |
- |
- baselinePoint = stringPoint; |
+ baselinePoint = getBaselinePoint(frame->view(), wordRange, string); |
return string; |
} |
NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame* webFrame, size_t location, size_t length) |
{ |
+ return WebSubstringUtil::attributedSubstringInRange(webFrame, location, length, nil); |
+} |
+ |
+NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame* webFrame, size_t location, size_t length, WebPoint* baselinePoint) |
+{ |
LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
if (frame->view()->needsLayout()) |
frame->view()->layout(); |
@@ -163,7 +168,10 @@ NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame* |
if (ephemeralRange.isNull()) |
return nil; |
- return attributedSubstringFromRange(ephemeralRange); |
+ NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); |
+ if (baselinePoint) |
+ *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result); |
+ return result; |
} |
} // namespace blink |