OLD | NEW |
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 Loading... |
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 Loading... |
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 HitTestResult result = viewImpl->mainFrameImpl() ? viewImpl->coreHitTestResu
ltAt(point) : static_cast<WebFrameWidgetImpl*>(widget)->coreHitTestResultAt(poin
t); |
142 if (!result.innerNode()) | 151 if (!result.innerNode()) |
143 return nil; | 152 return nil; |
144 LocalFrame* frame = result.innerNode()->document().frame(); | 153 LocalFrame* frame = result.innerNode()->document().frame(); |
145 EphemeralRange range = frame->rangeForPoint(result.roundedPointInInnerNodeFr
ame()); | 154 EphemeralRange range = frame->rangeForPoint(result.roundedPointInInnerNodeFr
ame()); |
146 if (range.isNull()) | 155 if (range.isNull()) |
147 return nil; | 156 return nil; |
148 | 157 |
149 // Expand to word under point. | 158 // Expand to word under point. |
150 VisibleSelection selection(range); | 159 VisibleSelection selection(range); |
151 selection.expandUsingGranularity(WordGranularity); | 160 selection.expandUsingGranularity(WordGranularity); |
(...skipping 23 matching lines...) Expand all Loading... |
175 if (ephemeralRange.isNull()) | 184 if (ephemeralRange.isNull()) |
176 return nil; | 185 return nil; |
177 | 186 |
178 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); | 187 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); |
179 if (baselinePoint) | 188 if (baselinePoint) |
180 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result)
; | 189 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result)
; |
181 return result; | 190 return result; |
182 } | 191 } |
183 | 192 |
184 } // namespace blink | 193 } // namespace blink |
OLD | NEW |