Changeset 83081 in webkit
- Timestamp:
- Apr 6, 2011 12:24:20 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r83079 r83081 1 2011-04-06 Robert Sesek <rsesek@chromium.org> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too 6 https://bugs.webkit.org/show_bug.cgi?id=54969 7 8 No change in behavior; no new tests. 9 10 * editing/TextIterator.cpp: 11 (WebCore::TextIterator::locationAndLengthFromRange): New method from duplicated code in WebKits 12 * editing/TextIterator.h: 13 * page/Frame.cpp: 14 (WebCore::Frame::rangeForPoint): New method from duplicated code in WebKits 15 1 16 2011-04-06 Leandro Gracia Gil <leandrogracia@chromium.org> 2 17 -
trunk/Source/WebCore/WebCore.exp.in
r83000 r83081 299 299 __ZN7WebCore12TextIterator11rangeLengthEPKNS_5RangeEb 300 300 __ZN7WebCore12TextIterator26rangeFromLocationAndLengthEPNS_7ElementEiib 301 __ZN7WebCore12TextIterator26locationAndLengthFromRangeEPKNS_5RangeERmS4_ 301 302 __ZN7WebCore12TextIterator7advanceEv 302 303 __ZN7WebCore12TextIterator8subrangeEPNS_5RangeEii … … 721 722 __ZN7WebCore5Frame9nodeImageEPNS_4NodeE 722 723 __ZN7WebCore5Frame9scalePageEfRKNS_8IntPointE 724 __ZN7WebCore5Frame13rangeForPointERKNS_8IntPointE 723 725 __ZN7WebCore5FrameD1Ev 724 726 __ZN7WebCore5Image12supportsTypeERKN3WTF6StringE -
trunk/Source/WebCore/editing/TextIterator.cpp
r81905 r83081 29 29 30 30 #include "Document.h" 31 #include "Frame.h" 31 32 #include "HTMLElement.h" 32 33 #include "HTMLNames.h" … … 2370 2371 } 2371 2372 2373 bool TextIterator::locationAndLengthFromRange(const Range* range, size_t& location, size_t& length) 2374 { 2375 location = notFound; 2376 length = 0; 2377 2378 if (!range->startContainer()) 2379 return false; 2380 2381 Element* selectionRoot = range->ownerDocument()->frame()->selection()->rootEditableElement(); 2382 Element* scope = selectionRoot ? selectionRoot : range->ownerDocument()->documentElement(); 2383 2384 // The critical assumption is that this only gets called with ranges that 2385 // concentrate on a given area containing the selection root. This is done 2386 // because of text fields and textareas. The DOM for those is not 2387 // directly in the document DOM, so ensure that the range does not cross a 2388 // boundary of one of those. 2389 if (range->startContainer() != scope && !range->startContainer()->isDescendantOf(scope)) 2390 return false; 2391 if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope)) 2392 return false; 2393 2394 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset()); 2395 ASSERT(testRange->startContainer() == scope); 2396 location = TextIterator::rangeLength(testRange.get()); 2397 2398 ExceptionCode ec; 2399 testRange->setEnd(range->endContainer(), range->endOffset(), ec); 2400 ASSERT(testRange->startContainer() == scope); 2401 length = TextIterator::rangeLength(testRange.get()) - location; 2402 return true; 2403 } 2404 2372 2405 // -------- 2373 2406 -
trunk/Source/WebCore/editing/TextIterator.h
r81905 r83081 99 99 static int rangeLength(const Range*, bool spacesForReplacedElements = false); 100 100 static PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, bool spacesForReplacedElements = false); 101 static bool locationAndLengthFromRange(const Range*, size_t& location, size_t& length); 101 102 static PassRefPtr<Range> subrange(Range* entireRange, int characterOffset, int characterCount); 102 103 -
trunk/Source/WebCore/page/Frame.cpp
r82795 r83081 805 805 } 806 806 807 PassRefPtr<Range> Frame::rangeForPoint(const IntPoint& framePoint) 808 { 809 VisiblePosition position = visiblePositionForPoint(framePoint); 810 if (position.isNull()) 811 return 0; 812 813 VisiblePosition previous = position.previous(); 814 if (previous.isNotNull()) { 815 RefPtr<Range> previousCharacterRange = makeRange(previous, position); 816 IntRect rect = editor()->firstRectForRange(previousCharacterRange.get()); 817 if (rect.contains(framePoint)) 818 return previousCharacterRange.release(); 819 } 820 821 VisiblePosition next = position.next(); 822 if (next.isNotNull()) { 823 RefPtr<Range> nextCharacterRange = makeRange(position, next); 824 IntRect rect = editor()->firstRectForRange(nextCharacterRange.get()); 825 if (rect.contains(framePoint)) 826 return nextCharacterRange.release(); 827 } 828 829 return 0; 830 } 831 807 832 void Frame::createView(const IntSize& viewportSize, 808 833 const Color& backgroundColor, bool transparent, -
trunk/Source/WebCore/page/Frame.h
r81603 r83081 185 185 VisiblePosition visiblePositionForPoint(const IntPoint& framePoint); 186 186 Document* documentAtPoint(const IntPoint& windowPoint); 187 PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint); 187 188 188 189 String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell); -
trunk/Source/WebKit/mac/ChangeLog
r83000 r83081 1 2011-04-06 Robert Sesek <rsesek@chromium.org> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too 6 https://bugs.webkit.org/show_bug.cgi?id=54969 7 8 * WebView/WebFrame.mm: 9 (-[WebFrame _convertToNSRange:]): Moved duplicated code to WebCore 10 (-[WebFrame _characterRangeAtPoint:]): Moved duplicated code to WebCore 11 1 12 2011-04-05 Alexey Proskuryakov <ap@apple.com> 2 13 -
trunk/Source/WebKit/mac/WebView/WebFrame.mm
r82159 r83081 671 671 - (NSRange)_convertToNSRange:(Range *)range 672 672 { 673 if (!range || !range->startContainer())673 if (!range) 674 674 return NSMakeRange(NSNotFound, 0); 675 675 676 Element* selectionRoot = _private->coreFrame->selection()->rootEditableElement(); 677 Element* scope = selectionRoot ? selectionRoot : _private->coreFrame->document()->documentElement(); 678 679 // Mouse events may cause TSM to attempt to create an NSRange for a portion of the view 680 // that is not inside the current editable region. These checks ensure we don't produce 681 // potentially invalid data when responding to such requests. 682 if (range->startContainer() != scope && !range->startContainer()->isDescendantOf(scope)) 676 size_t location; 677 size_t length; 678 if (!TextIterator::locationAndLengthFromRange(range, location, length)) 683 679 return NSMakeRange(NSNotFound, 0); 684 if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope)) 685 return NSMakeRange(NSNotFound, 0); 686 687 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset()); 688 ASSERT(testRange->startContainer() == scope); 689 int startPosition = TextIterator::rangeLength(testRange.get()); 690 691 ExceptionCode ec; 692 testRange->setEnd(range->endContainer(), range->endOffset(), ec); 693 ASSERT(testRange->startContainer() == scope); 694 int endPosition = TextIterator::rangeLength(testRange.get()); 695 696 return NSMakeRange(startPosition, endPosition - startPosition); 680 681 return NSMakeRange(location, length); 697 682 } 698 683 … … 821 806 - (DOMRange *)_characterRangeAtPoint:(NSPoint)point 822 807 { 823 VisiblePosition position = [self _visiblePositionForPoint:point]; 824 if (position.isNull()) 825 return nil; 826 827 VisiblePosition previous = position.previous(); 828 if (previous.isNotNull()) { 829 DOMRange *previousCharacterRange = kit(makeRange(previous, position).get()); 830 NSRect rect = [self _firstRectForDOMRange:previousCharacterRange]; 831 if (NSPointInRect(point, rect)) 832 return previousCharacterRange; 833 } 834 835 VisiblePosition next = position.next(); 836 if (next.isNotNull()) { 837 DOMRange *nextCharacterRange = kit(makeRange(position, next).get()); 838 NSRect rect = [self _firstRectForDOMRange:nextCharacterRange]; 839 if (NSPointInRect(point, rect)) 840 return nextCharacterRange; 841 } 842 843 return nil; 808 return kit(_private->coreFrame->rangeForPoint(IntPoint(point)).get()); 844 809 } 845 810 -
trunk/Source/WebKit2/ChangeLog
r83071 r83081 1 2011-04-06 Robert Sesek <rsesek@chromium.org> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too 6 https://bugs.webkit.org/show_bug.cgi?id=54969 7 8 * WebProcess/WebCoreSupport/WebEditorClient.cpp: 9 (WebKit::WebEditorClient::respondToChangedSelection): Moved duplicated code to WebCore 10 * WebProcess/WebPage/mac/WebPageMac.mm: Moved duplicated code to WebCore 11 (WebKit::WebPage::getMarkedRange): 12 (WebKit::WebPage::getSelectedRange): 13 (WebKit::WebPage::characterIndexForPoint): 14 (WebKit::WebPage::performDictionaryLookupAtLocation): 15 1 16 2011-04-06 Chang Shu <cshu@webkit.org> 2 17 -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
r82952 r83081 44 44 #include <WebCore/NotImplemented.h> 45 45 #include <WebCore/Page.h> 46 #include <WebCore/TextIterator.h> 46 47 #include <WebCore/UserTypingGestureIndicator.h> 47 48 … … 197 198 selectionState.hasComposition = frame->editor()->hasComposition(); 198 199 199 WebPage::getLocationAndLengthFromRange(frame->selection()->toNormalizedRange().get(), selectionState.selectedRangeStart, selectionState.selectedRangeLength); 200 Range* range = frame->selection()->toNormalizedRange().get(); 201 if (range) { 202 size_t location; 203 size_t length; 204 if (!TextIterator::locationAndLengthFromRange(range, location, length)) 205 return; 206 selectionState.selectedRangeStart = static_cast<uint64_t>(location); 207 selectionState.selectedRangeLength = static_cast<uint64_t>(length); 208 } 200 209 201 210 m_page->send(Messages::WebPageProxy::SelectionStateChanged(selectionState)); -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r82982 r83081 825 825 } 826 826 827 void WebPage::getLocationAndLengthFromRange(Range* range, uint64_t& location, uint64_t& length)828 {829 location = notFound;830 length = 0;831 832 if (!range || !range->startContainer())833 return;834 835 Element* selectionRoot = range->ownerDocument()->frame()->selection()->rootEditableElement();836 Element* scope = selectionRoot ? selectionRoot : range->ownerDocument()->documentElement();837 838 // Mouse events may cause TSM to attempt to create an NSRange for a portion of the view839 // that is not inside the current editable region. These checks ensure we don't produce840 // potentially invalid data when responding to such requests.841 if (range->startContainer() != scope && !range->startContainer()->isDescendantOf(scope))842 return;843 if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))844 return;845 846 RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());847 ASSERT(testRange->startContainer() == scope);848 location = TextIterator::rangeLength(testRange.get());849 850 ExceptionCode ec;851 testRange->setEnd(range->endContainer(), range->endOffset(), ec);852 ASSERT(testRange->startContainer() == scope);853 length = TextIterator::rangeLength(testRange.get()) - location;854 }855 856 827 // Events 857 828 -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r82933 r83081 301 301 SandboxExtensionTracker& sandboxExtensionTracker() { return m_sandboxExtensionTracker; } 302 302 303 static void getLocationAndLengthFromRange(WebCore::Range*, uint64_t& location, uint64_t& length);304 305 303 #if PLATFORM(MAC) 306 304 void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken); -
trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
r83004 r83081 277 277 if (!frame) 278 278 return; 279 280 getLocationAndLengthFromRange(frame->editor()->compositionRange().get(), location, length); 279 280 Range* range = frame->editor()->compositionRange().get(); 281 size_t locationSize; 282 size_t lengthSize; 283 if (range && TextIterator::locationAndLengthFromRange(range, locationSize, lengthSize)) { 284 location = static_cast<uint64_t>(locationSize); 285 length = static_cast<uint64_t>(lengthSize); 286 } 281 287 } 282 288 … … 288 294 if (!frame) 289 295 return; 290 291 getLocationAndLengthFromRange(frame->selection()->toNormalizedRange().get(), location, length); 292 } 293 294 static PassRefPtr<Range> characterRangeAtPositionForPoint(Frame* frame, const VisiblePosition& position, const IntPoint& point) 295 { 296 if (position.isNull()) 297 return 0; 298 299 VisiblePosition previous = position.previous(); 300 if (previous.isNotNull()) { 301 RefPtr<Range> previousCharacterRange = makeRange(previous, position); 302 IntRect rect = frame->editor()->firstRectForRange(previousCharacterRange.get()); 303 if (rect.contains(point)) 304 return previousCharacterRange.release(); 305 } 306 307 VisiblePosition next = position.next(); 308 if (next.isNotNull()) { 309 RefPtr<Range> nextCharacterRange = makeRange(position, next); 310 IntRect rect = frame->editor()->firstRectForRange(nextCharacterRange.get()); 311 if (rect.contains(point)) 312 return nextCharacterRange.release(); 313 } 314 315 return 0; 316 } 317 318 static PassRefPtr<Range> characterRangeAtPoint(Frame* frame, const IntPoint& point) 319 { 320 return characterRangeAtPositionForPoint(frame, frame->visiblePositionForPoint(point), point); 296 297 size_t locationSize; 298 size_t lengthSize; 299 if (TextIterator::locationAndLengthFromRange(frame->selection()->toNormalizedRange().get(), locationSize, lengthSize)) { 300 location = static_cast<uint64_t>(locationSize); 301 length = static_cast<uint64_t>(lengthSize); 302 } 321 303 } 322 304 … … 331 313 frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame(); 332 314 333 RefPtr<Range> range = characterRangeAtPoint(frame,result.point());315 RefPtr<Range> range = frame->rangeForPoint(result.point()); 334 316 if (!range) 335 317 return; 336 318 337 uint64_t length; 338 getLocationAndLengthFromRange(range.get(), index, length); 319 size_t location; 320 size_t length; 321 if (TextIterator::locationAndLengthFromRange(range.get(), location, length)) 322 index = static_cast<uint64_t>(location); 339 323 } 340 324 … … 421 405 422 406 IntPoint translatedPoint = frame->view()->windowToContents(point); 407 408 // Don't do anything if there is no character at the point. 409 if (!frame->rangeForPoint(translatedPoint)) 410 return; 411 423 412 VisiblePosition position = frame->visiblePositionForPoint(translatedPoint); 424 425 // Don't do anything if there is no character at the point.426 if (!characterRangeAtPositionForPoint(frame, position, translatedPoint))427 return;428 429 413 VisibleSelection selection = m_page->focusController()->focusedOrMainFrame()->selection()->selection(); 430 414 if (shouldUseSelection(position, selection)) {
Note: See TracChangeset
for help on using the changeset viewer.