| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 void WebPage::getMarkedRange(uint64_t& location, uint64_t& length) | 156 void WebPage::getMarkedRange(uint64_t& location, uint64_t& length) |
| 157 { | 157 { |
| 158 location = NSNotFound; | 158 location = NSNotFound; |
| 159 length = 0; | 159 length = 0; |
| 160 Frame* frame = m_page->focusController()->focusedOrMainFrame(); | 160 Frame* frame = m_page->focusController()->focusedOrMainFrame(); |
| 161 if (!frame) | 161 if (!frame) |
| 162 return; | 162 return; |
| 163 | |
| 164 getLocationAndLengthFromRange(frame->editor()->compositionRange().get(), loc
ation, length); | |
| 165 } | |
| 166 | 163 |
| 167 static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& poi
nt) | 164 Range* range = frame->editor()->compositionRange().get(); |
| 168 { | 165 if (range) |
| 169 VisiblePosition position = frame->visiblePositionForPoint(point); | 166 range->getLocationAndLength(location, length); |
| 170 if (position.isNull()) | |
| 171 return 0; | |
| 172 | |
| 173 VisiblePosition previous = position.previous(); | |
| 174 if (previous.isNotNull()) { | |
| 175 RefPtr<Range> previousCharacterRange = makeRange(previous, position); | |
| 176 IntRect rect = frame->editor()->firstRectForRange(previousCharacterRange
.get()); | |
| 177 if (rect.contains(point)) | |
| 178 return previousCharacterRange.release(); | |
| 179 } | |
| 180 | |
| 181 VisiblePosition next = position.next(); | |
| 182 if (next.isNotNull()) { | |
| 183 RefPtr<Range> nextCharacterRange = makeRange(position, next); | |
| 184 IntRect rect = frame->editor()->firstRectForRange(nextCharacterRange.get
()); | |
| 185 if (rect.contains(point)) | |
| 186 return nextCharacterRange.release(); | |
| 187 } | |
| 188 | |
| 189 return 0; | |
| 190 } | 167 } |
| 191 | 168 |
| 192 void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index) | 169 void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index) |
| 193 { | 170 { |
| 194 index = NSNotFound; | 171 index = NSNotFound; |
| 195 Frame* frame = m_page->mainFrame(); | 172 Frame* frame = m_page->mainFrame(); |
| 196 if (!frame) | 173 if (!frame) |
| 197 return; | 174 return; |
| 198 | 175 |
| 199 HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, fa
lse); | 176 HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, fa
lse); |
| 200 frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document(
)->frame() : m_page->focusController()->focusedOrMainFrame(); | 177 frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document(
)->frame() : m_page->focusController()->focusedOrMainFrame(); |
| 201 | 178 |
| 202 RefPtr<Range> range = characterRangeAtPoint(frame, result.point()); | 179 RefPtr<Range> range = frame->rangeForPoint(frame, result.point()); |
| 203 if (!range) | 180 if (!range) |
| 204 return; | 181 return; |
| 205 | 182 |
| 206 uint64_t length; | 183 uint64_t length; |
| 207 getLocationAndLengthFromRange(range.get(), index, length); | 184 range->getLocationAndLength(index, length); |
| 208 } | 185 } |
| 209 | 186 |
| 210 static PassRefPtr<Range> convertToRange(Frame* frame, NSRange nsrange) | 187 static PassRefPtr<Range> convertToRange(Frame* frame, NSRange nsrange) |
| 211 { | 188 { |
| 212 if (nsrange.location > INT_MAX) | 189 if (nsrange.location > INT_MAX) |
| 213 return 0; | 190 return 0; |
| 214 if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX) | 191 if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX) |
| 215 nsrange.length = INT_MAX - nsrange.location; | 192 nsrange.length = INT_MAX - nsrange.location; |
| 216 | 193 |
| 217 // our critical assumption is that we are only called by input methods that | 194 // our critical assumption is that we are only called by input methods that |
| (...skipping 30 matching lines...) Expand all Loading... |
| 248 if (!frame) | 225 if (!frame) |
| 249 return; | 226 return; |
| 250 | 227 |
| 251 // Find the frame the point is over. | 228 // Find the frame the point is over. |
| 252 IntPoint point = roundedIntPoint(floatPoint); | 229 IntPoint point = roundedIntPoint(floatPoint); |
| 253 | 230 |
| 254 HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, fa
lse); | 231 HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(point, fa
lse); |
| 255 frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document(
)->frame() : m_page->focusController()->focusedOrMainFrame(); | 232 frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document(
)->frame() : m_page->focusController()->focusedOrMainFrame(); |
| 256 | 233 |
| 257 // Figure out if there are any characters under the point. | 234 // Figure out if there are any characters under the point. |
| 258 RefPtr<Range> characterRange = characterRangeAtPoint(frame, frame->view()->w
indowToContents(point)); | 235 RefPtr<Range> characterRange = frame->rangeForPoint(frame, frame->view()->wi
ndowToContents(point)); |
| 259 if (!characterRange) | 236 if (!characterRange) |
| 260 return; | 237 return; |
| 261 | 238 |
| 262 // Grab the currently selected text. | 239 // Grab the currently selected text. |
| 263 RefPtr<Range> selectedRange = m_page->focusController()->focusedOrMainFrame(
)->selection()->selection().toNormalizedRange(); | 240 RefPtr<Range> selectedRange = m_page->focusController()->focusedOrMainFrame(
)->selection()->selection().toNormalizedRange(); |
| 264 | 241 |
| 265 // Use the selected text if the point was anywhere in it. Assertain this by
seeing if either character range | 242 // Use the selected text if the point was anywhere in it. Assertain this by
seeing if either character range |
| 266 // the mouse is over is contained by the selection range. | 243 // the mouse is over is contained by the selection range. |
| 267 if (characterRange && selectedRange) { | 244 if (characterRange && selectedRange) { |
| 268 ExceptionCode ec = 0; | 245 ExceptionCode ec = 0; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 465 |
| 489 void WebPage::platformDragEnded() | 466 void WebPage::platformDragEnded() |
| 490 { | 467 { |
| 491 // The drag source we care about here is NSFilePromiseDragSource, which does
n't look at | 468 // The drag source we care about here is NSFilePromiseDragSource, which does
n't look at |
| 492 // the arguments. It's OK to just pass arbitrary constant values, so we just
pass all zeroes. | 469 // the arguments. It's OK to just pass arbitrary constant values, so we just
pass all zeroes. |
| 493 [m_dragSource.get() draggedImage:nil endedAt:NSZeroPoint operation:NSDragOpe
rationNone]; | 470 [m_dragSource.get() draggedImage:nil endedAt:NSZeroPoint operation:NSDragOpe
rationNone]; |
| 494 m_dragSource = nullptr; | 471 m_dragSource = nullptr; |
| 495 } | 472 } |
| 496 | 473 |
| 497 } // namespace WebKit | 474 } // namespace WebKit |
| OLD | NEW |