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

Side by Side Diff: third_party/WebKit/Source/web/mac/WebSubstringUtil.mm

Issue 2278283002: Implement Mac Pop-up Dictionary for OOPIF. (Closed)
Patch Set: Rebased Created 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "core/html/HTMLElement.h" 46 #include "core/html/HTMLElement.h"
47 #include "core/layout/HitTestResult.h" 47 #include "core/layout/HitTestResult.h"
48 #include "core/layout/LayoutObject.h" 48 #include "core/layout/LayoutObject.h"
49 #include "core/style/ComputedStyle.h" 49 #include "core/style/ComputedStyle.h"
50 #include "platform/fonts/Font.h" 50 #include "platform/fonts/Font.h"
51 #include "platform/mac/ColorMac.h" 51 #include "platform/mac/ColorMac.h"
52 #include "public/platform/WebRect.h" 52 #include "public/platform/WebRect.h"
53 #include "public/web/WebHitTestResult.h" 53 #include "public/web/WebHitTestResult.h"
54 #include "public/web/WebRange.h" 54 #include "public/web/WebRange.h"
55 #include "public/web/WebView.h" 55 #include "public/web/WebView.h"
56 #include "public/web/WebWidget.h"
57 #include "web/WebFrameWidgetBase.h"
58 #include "web/WebFrameWidgetImpl.h"
56 #include "web/WebLocalFrameImpl.h" 59 #include "web/WebLocalFrameImpl.h"
57 #include "web/WebViewImpl.h" 60 #include "web/WebViewImpl.h"
58 61
59 using namespace blink; 62 using namespace blink;
60 63
61 static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& ra nge) 64 static NSAttributedString* attributedSubstringFromRange(const EphemeralRange& ra nge)
62 { 65 {
63 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init] ; 66 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init] ;
64 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; 67 NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
65 size_t length = range.endPosition().computeOffsetInContainerNode() - range.s tartPosition().computeOffsetInContainerNode(); 68 size_t length = range.endPosition().computeOffsetInContainerNode() - range.s tartPosition().computeOffsetInContainerNode();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if ([string length]) { 132 if ([string length]) {
130 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL]; 133 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL];
131 if (NSFont* font = [attributes objectForKey:NSFontAttributeName]) 134 if (NSFont* font = [attributes objectForKey:NSFontAttributeName])
132 stringPoint.move(0, ceil(-[font descender])); 135 stringPoint.move(0, ceil(-[font descender]));
133 } 136 }
134 return stringPoint; 137 return stringPoint;
135 } 138 }
136 139
137 namespace blink { 140 namespace blink {
138 141
139 NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo int point, WebPoint& baselinePoint) 142 NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebWi dget* widget, WebPoint point, WebPoint& baselinePoint)
140 { 143 {
141 HitTestResult result = static_cast<WebViewImpl*>(view)->coreHitTestResultAt( point); 144 WebViewImpl* viewImpl = static_cast<WebViewImpl*>(view);
145
146 // Either this call is for a main frame's WebView or a local roots WebFrameW idgetImpl.
147 if (!viewImpl->mainFrameImpl() && !widget)
148 return nil;
149
150 // Either we are in the main frame, where |widget| is a WebViewImpl equal to |view|, or, |widget| is a WebFrameWidget.
151 HitTestResult result = widget->isWebView() ? viewImpl->coreHitTestResultAt(p oint) : static_cast<WebFrameWidgetImpl*>(widget)->coreHitTestResultAt(point);
kenrb 2016/09/12 17:28:13 It looks like you dereference widget without first
EhsanK 2016/09/13 18:52:15 I believe neither |view| nor (specifically) |widge
152
142 if (!result.innerNode()) 153 if (!result.innerNode())
143 return nil; 154 return nil;
144 LocalFrame* frame = result.innerNode()->document().frame(); 155 LocalFrame* frame = result.innerNode()->document().frame();
145 EphemeralRange range = frame->rangeForPoint(result.roundedPointInInnerNodeFr ame()); 156 EphemeralRange range = frame->rangeForPoint(result.roundedPointInInnerNodeFr ame());
146 if (range.isNull()) 157 if (range.isNull())
147 return nil; 158 return nil;
148 159
149 // Expand to word under point. 160 // Expand to word under point.
150 VisibleSelection selection(range); 161 VisibleSelection selection(range);
151 selection.expandUsingGranularity(WordGranularity); 162 selection.expandUsingGranularity(WordGranularity);
(...skipping 23 matching lines...) Expand all
175 if (ephemeralRange.isNull()) 186 if (ephemeralRange.isNull())
176 return nil; 187 return nil;
177 188
178 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); 189 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange);
179 if (baselinePoint) 190 if (baselinePoint)
180 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result) ; 191 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result) ;
181 return result; 192 return result;
182 } 193 }
183 194
184 } // namespace blink 195 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698