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 27 matching lines...) Expand all Loading... |
38 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
39 #include "core/dom/Node.h" | 39 #include "core/dom/Node.h" |
40 #include "core/dom/Range.h" | 40 #include "core/dom/Range.h" |
41 #include "core/editing/FrameSelection.h" | 41 #include "core/editing/FrameSelection.h" |
42 #include "core/editing/PlainTextRange.h" | 42 #include "core/editing/PlainTextRange.h" |
43 #include "core/editing/iterators/TextIterator.h" | 43 #include "core/editing/iterators/TextIterator.h" |
44 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
45 #include "core/frame/LocalFrameView.h" | 45 #include "core/frame/LocalFrameView.h" |
46 #include "core/frame/VisualViewport.h" | 46 #include "core/frame/VisualViewport.h" |
47 #include "core/frame/WebFrameWidgetBase.h" | 47 #include "core/frame/WebFrameWidgetBase.h" |
| 48 #include "core/frame/WebLocalFrameBase.h" |
48 #include "core/html/HTMLElement.h" | 49 #include "core/html/HTMLElement.h" |
49 #include "core/layout/HitTestResult.h" | 50 #include "core/layout/HitTestResult.h" |
50 #include "core/layout/LayoutObject.h" | 51 #include "core/layout/LayoutObject.h" |
51 #include "core/page/Page.h" | 52 #include "core/page/Page.h" |
52 #include "core/style/ComputedStyle.h" | 53 #include "core/style/ComputedStyle.h" |
53 #include "platform/fonts/Font.h" | 54 #include "platform/fonts/Font.h" |
54 #include "platform/mac/ColorMac.h" | 55 #include "platform/mac/ColorMac.h" |
55 #include "public/platform/WebRect.h" | 56 #include "public/platform/WebRect.h" |
56 #include "public/web/WebFrameWidget.h" | 57 #include "public/web/WebFrameWidget.h" |
57 #include "public/web/WebHitTestResult.h" | 58 #include "public/web/WebHitTestResult.h" |
58 #include "public/web/WebLocalFrame.h" | 59 #include "public/web/WebLocalFrame.h" |
59 #include "public/web/WebRange.h" | 60 #include "public/web/WebRange.h" |
60 #include "web/WebLocalFrameImpl.h" | |
61 | 61 |
62 using namespace blink; | 62 using namespace blink; |
63 | 63 |
64 static NSAttributedString* attributedSubstringFromRange( | 64 static NSAttributedString* attributedSubstringFromRange( |
65 const EphemeralRange& range, | 65 const EphemeralRange& range, |
66 float fontScale) { | 66 float fontScale) { |
67 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]; | 67 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]; |
68 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; | 68 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; |
69 size_t length = range.EndPosition().ComputeOffsetInContainerNode() - | 69 size_t length = range.EndPosition().ComputeOffsetInContainerNode() - |
70 range.StartPosition().ComputeOffsetInContainerNode(); | 70 range.StartPosition().ComputeOffsetInContainerNode(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 size_t length) { | 191 size_t length) { |
192 return WebSubstringUtil::AttributedSubstringInRange(web_frame, location, | 192 return WebSubstringUtil::AttributedSubstringInRange(web_frame, location, |
193 length, nil); | 193 length, nil); |
194 } | 194 } |
195 | 195 |
196 NSAttributedString* WebSubstringUtil::AttributedSubstringInRange( | 196 NSAttributedString* WebSubstringUtil::AttributedSubstringInRange( |
197 WebLocalFrame* web_frame, | 197 WebLocalFrame* web_frame, |
198 size_t location, | 198 size_t location, |
199 size_t length, | 199 size_t length, |
200 WebPoint* baseline_point) { | 200 WebPoint* baseline_point) { |
201 LocalFrame* frame = ToWebLocalFrameImpl(web_frame)->GetFrame(); | 201 LocalFrame* frame = ToWebLocalFrameBase(web_frame)->GetFrame(); |
202 if (frame->View()->NeedsLayout()) | 202 if (frame->View()->NeedsLayout()) |
203 frame->View()->UpdateLayout(); | 203 frame->View()->UpdateLayout(); |
204 | 204 |
205 Element* editable = frame->Selection().RootEditableElementOrDocumentElement(); | 205 Element* editable = frame->Selection().RootEditableElementOrDocumentElement(); |
206 if (!editable) | 206 if (!editable) |
207 return nil; | 207 return nil; |
208 const EphemeralRange ephemeral_range( | 208 const EphemeralRange ephemeral_range( |
209 PlainTextRange(location, location + length).CreateRange(*editable)); | 209 PlainTextRange(location, location + length).CreateRange(*editable)); |
210 if (ephemeral_range.IsNull()) | 210 if (ephemeral_range.IsNull()) |
211 return nil; | 211 return nil; |
212 | 212 |
213 NSAttributedString* result = attributedSubstringFromRange( | 213 NSAttributedString* result = attributedSubstringFromRange( |
214 ephemeral_range, frame->GetPage()->GetVisualViewport().Scale()); | 214 ephemeral_range, frame->GetPage()->GetVisualViewport().Scale()); |
215 if (baseline_point) | 215 if (baseline_point) |
216 *baseline_point = getBaselinePoint(frame->View(), ephemeral_range, result); | 216 *baseline_point = getBaselinePoint(frame->View(), ephemeral_range, result); |
217 return result; | 217 return result; |
218 } | 218 } |
219 | 219 |
220 } // namespace blink | 220 } // namespace blink |
OLD | NEW |