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

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: avoid |const NSClass*| 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..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
« 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