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

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

Issue 224113002: Oilpan: move Range object to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: heap/Handle.h => platform/heap/Handle.h Created 6 years, 8 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 namespace blink { 111 namespace blink {
112 112
113 NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo int point, WebPoint& baselinePoint) 113 NSAttributedString* WebSubstringUtil::attributedWordAtPoint(WebView* view, WebPo int point, WebPoint& baselinePoint)
114 { 114 {
115 HitTestResult result = view->hitTestResultAt(point); 115 HitTestResult result = view->hitTestResultAt(point);
116 LocalFrame* frame = result.targetNode()->document().frame(); 116 LocalFrame* frame = result.targetNode()->document().frame();
117 FrameView* frameView = frame->view(); 117 FrameView* frameView = frame->view();
118 118
119 RefPtr<Range> range = frame->rangeForPoint(result.roundedPointInInnerNodeFra me()); 119 RefPtrWillBeRawPtr<Range> range = frame->rangeForPoint(result.roundedPointIn InnerNodeFrame());
120 if (!range) 120 if (!range)
121 return nil; 121 return nil;
122 122
123 // Expand to word under point. 123 // Expand to word under point.
124 VisibleSelection selection(range.get()); 124 VisibleSelection selection(range.get());
125 selection.expandUsingGranularity(WordGranularity); 125 selection.expandUsingGranularity(WordGranularity);
126 RefPtr<Range> wordRange = selection.toNormalizedRange(); 126 RefPtrWillBeRawPtr<Range> wordRange = selection.toNormalizedRange();
127 127
128 // Convert to NSAttributedString. 128 // Convert to NSAttributedString.
129 NSAttributedString* string = attributedSubstringFromRange(wordRange.get()); 129 NSAttributedString* string = attributedSubstringFromRange(wordRange.get());
130 130
131 // Compute bottom left corner and convert to AppKit coordinates. 131 // Compute bottom left corner and convert to AppKit coordinates.
132 IntRect stringRect = enclosingIntRect(wordRange->boundingRect()); 132 IntRect stringRect = enclosingIntRect(wordRange->boundingRect());
133 IntPoint stringPoint = frameView->contentsToWindow(stringRect).minXMaxYCorne r(); 133 IntPoint stringPoint = frameView->contentsToWindow(stringRect).minXMaxYCorne r();
134 stringPoint.setY(frameView->height() - stringPoint.y()); 134 stringPoint.setY(frameView->height() - stringPoint.y());
135 135
136 // Adjust for the font's descender. AppKit wants the baseline point. 136 // Adjust for the font's descender. AppKit wants the baseline point.
137 if ([string length]) { 137 if ([string length]) {
138 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL]; 138 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL];
139 NSFont* font = [attributes objectForKey:NSFontAttributeName]; 139 NSFont* font = [attributes objectForKey:NSFontAttributeName];
140 if (font) 140 if (font)
141 stringPoint.move(0, ceil(-[font descender])); 141 stringPoint.move(0, ceil(-[font descender]));
142 } 142 }
143 143
144 baselinePoint = stringPoint; 144 baselinePoint = stringPoint;
145 return string; 145 return string;
146 } 146 }
147 147
148 NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebFrame* webFr ame, size_t location, size_t length) 148 NSAttributedString* WebSubstringUtil::attributedSubstringInRange(WebFrame* webFr ame, size_t location, size_t length)
149 { 149 {
150 LocalFrame* frame = toWebFrameImpl(webFrame)->frame(); 150 LocalFrame* frame = toWebFrameImpl(webFrame)->frame();
151 if (frame->view()->needsLayout()) 151 if (frame->view()->needsLayout())
152 frame->view()->layout(); 152 frame->view()->layout();
153 153
154 Element* editable = frame->selection().rootEditableElementOrDocumentElement( ); 154 Element* editable = frame->selection().rootEditableElementOrDocumentElement( );
155 ASSERT(editable); 155 ASSERT(editable);
156 RefPtr<Range> range(PlainTextRange(location, location + length).createRange( *editable)); 156 RefPtrWillBeRawPtr<Range> range(PlainTextRange(location, location + length). createRange(*editable));
157 if (!range) 157 if (!range)
158 return nil; 158 return nil;
159 159
160 return attributedSubstringFromRange(range.get()); 160 return attributedSubstringFromRange(range.get());
161 } 161 }
162 162
163 } // namespace blink 163 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698