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

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

Issue 1329103002: [blink/mac] Support getting baseline point for showing dictionary lookup bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 | public/web/mac/WebSubstringUtil.h » ('j') | 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 c5ea739b1a65dad42e4a08db7f25964d5d8decd3..ba20e3e1de82e5be1b20526b5dacc246c3b18a53 100644
--- a/Source/web/mac/WebSubstringUtil.mm
+++ b/Source/web/mac/WebSubstringUtil.mm
@@ -110,6 +110,24 @@ static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& ra
return [string autorelease];
}
+WebPoint getBaselinePoint(FrameView* frameView, const EphemeralRange& range, const NSAttributedString* string)
+{
+ // Compute bottom left corner and convert to AppKit coordinates.
+ // TODO(yosin) We shold avoid to create |Range| object.
eae 2015/09/09 16:56:04 Could you please file a bug about this and add a l
Shu Chen 2015/09/10 01:14:07 Done.
+ IntRect stringRect = enclosingIntRect(createRange(range)->boundingRect());
+ IntPoint stringPoint = stringRect.minXMaxYCorner();
+ stringPoint.setY(frameView->height() - stringPoint.y());
eae 2015/09/09 16:56:04 You take the bottom left corner of the bounding re
Shu Chen 2015/09/10 01:14:07 Actually, I don't understand why adjust y() by the
+
+ // 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]));
+ }
+ return stringPoint;
+}
+
namespace blink {
NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPoint point, WebPoint& baselinePoint)
@@ -118,8 +136,6 @@ NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo
if (!result.innerNode())
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 +147,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 +169,10 @@ NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebLocalFrame*
if (ephemeralRange.isNull())
return nil;
- return attributedSubstringFromRange(ephemeralRange);
+ NSAttributedString* ret = attributedSubstringFromRange(ephemeralRange);
+ if (baselinePoint)
+ *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, ret);
+ return ret;
}
} // namespace blink
« no previous file with comments | « no previous file | public/web/mac/WebSubstringUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698