Changeset 83081 in webkit


Ignore:
Timestamp:
Apr 6, 2011 12:24:20 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-06 Robert Sesek <rsesek@chromium.org>

Reviewed by Alexey Proskuryakov.

Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too
https://bugs.webkit.org/show_bug.cgi?id=54969

No change in behavior; no new tests.

  • editing/TextIterator.cpp: (WebCore::TextIterator::locationAndLengthFromRange): New method from duplicated code in WebKits
  • editing/TextIterator.h:
  • page/Frame.cpp: (WebCore::Frame::rangeForPoint): New method from duplicated code in WebKits

2011-04-06 Robert Sesek <rsesek@chromium.org>

Reviewed by Alexey Proskuryakov.

Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too
https://bugs.webkit.org/show_bug.cgi?id=54969

  • WebView/WebFrame.mm: (-[WebFrame _convertToNSRange:]): Moved duplicated code to WebCore (-[WebFrame _characterRangeAtPoint:]): Moved duplicated code to WebCore

2011-04-06 Robert Sesek <rsesek@chromium.org>

Reviewed by Alexey Proskuryakov.

Move code duplicated between the WebKit/mac and WebKit2 down to WebCore because Chromium will need it too
https://bugs.webkit.org/show_bug.cgi?id=54969

  • WebProcess/WebCoreSupport/WebEditorClient.cpp: (WebKit::WebEditorClient::respondToChangedSelection): Moved duplicated code to WebCore
  • WebProcess/WebPage/mac/WebPageMac.mm: Moved duplicated code to WebCore (WebKit::WebPage::getMarkedRange): (WebKit::WebPage::getSelectedRange): (WebKit::WebPage::characterIndexForPoint): (WebKit::WebPage::performDictionaryLookupAtLocation):
Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83079 r83081  
     12011-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
    1162011-04-06  Leandro Gracia Gil  <leandrogracia@chromium.org>
    217
  • trunk/Source/WebCore/WebCore.exp.in

    r83000 r83081  
    299299__ZN7WebCore12TextIterator11rangeLengthEPKNS_5RangeEb
    300300__ZN7WebCore12TextIterator26rangeFromLocationAndLengthEPNS_7ElementEiib
     301__ZN7WebCore12TextIterator26locationAndLengthFromRangeEPKNS_5RangeERmS4_
    301302__ZN7WebCore12TextIterator7advanceEv
    302303__ZN7WebCore12TextIterator8subrangeEPNS_5RangeEii
     
    721722__ZN7WebCore5Frame9nodeImageEPNS_4NodeE
    722723__ZN7WebCore5Frame9scalePageEfRKNS_8IntPointE
     724__ZN7WebCore5Frame13rangeForPointERKNS_8IntPointE
    723725__ZN7WebCore5FrameD1Ev
    724726__ZN7WebCore5Image12supportsTypeERKN3WTF6StringE
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r81905 r83081  
    2929
    3030#include "Document.h"
     31#include "Frame.h"
    3132#include "HTMLElement.h"
    3233#include "HTMLNames.h"
     
    23702371}
    23712372
     2373bool 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
    23722405// --------
    23732406   
  • trunk/Source/WebCore/editing/TextIterator.h

    r81905 r83081  
    9999    static int rangeLength(const Range*, bool spacesForReplacedElements = false);
    100100    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);
    101102    static PassRefPtr<Range> subrange(Range* entireRange, int characterOffset, int characterCount);
    102103   
  • trunk/Source/WebCore/page/Frame.cpp

    r82795 r83081  
    805805}
    806806
     807PassRefPtr<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
    807832void Frame::createView(const IntSize& viewportSize,
    808833                       const Color& backgroundColor, bool transparent,
  • trunk/Source/WebCore/page/Frame.h

    r81603 r83081  
    185185        VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
    186186        Document* documentAtPoint(const IntPoint& windowPoint);
     187        PassRefPtr<Range> rangeForPoint(const IntPoint& framePoint);
    187188
    188189        String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
  • trunk/Source/WebKit/mac/ChangeLog

    r83000 r83081  
     12011-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
    1122011-04-05  Alexey Proskuryakov  <ap@apple.com>
    213
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r82159 r83081  
    671671- (NSRange)_convertToNSRange:(Range *)range
    672672{
    673     if (!range || !range->startContainer())
     673    if (!range)
    674674        return NSMakeRange(NSNotFound, 0);
    675675
    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))
    683679        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);
    697682}
    698683
     
    821806- (DOMRange *)_characterRangeAtPoint:(NSPoint)point
    822807{
    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());
    844809}
    845810
  • trunk/Source/WebKit2/ChangeLog

    r83071 r83081  
     12011-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
    1162011-04-06  Chang Shu  <cshu@webkit.org>
    217
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp

    r82952 r83081  
    4444#include <WebCore/NotImplemented.h>
    4545#include <WebCore/Page.h>
     46#include <WebCore/TextIterator.h>
    4647#include <WebCore/UserTypingGestureIndicator.h>
    4748
     
    197198    selectionState.hasComposition = frame->editor()->hasComposition();
    198199
    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    }
    200209
    201210    m_page->send(Messages::WebPageProxy::SelectionStateChanged(selectionState));
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r82982 r83081  
    825825}
    826826
    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 view
    839     // that is not inside the current editable region.  These checks ensure we don't produce
    840     // 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 
    856827// Events
    857828
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r82933 r83081  
    301301    SandboxExtensionTracker& sandboxExtensionTracker() { return m_sandboxExtensionTracker; }
    302302
    303     static void getLocationAndLengthFromRange(WebCore::Range*, uint64_t& location, uint64_t& length);
    304 
    305303#if PLATFORM(MAC)
    306304    void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r83004 r83081  
    277277    if (!frame)
    278278        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    }
    281287}
    282288
     
    288294    if (!frame)
    289295        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    }
    321303}
    322304
     
    331313    frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame();
    332314   
    333     RefPtr<Range> range = characterRangeAtPoint(frame, result.point());
     315    RefPtr<Range> range = frame->rangeForPoint(result.point());
    334316    if (!range)
    335317        return;
    336318
    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);
    339323}
    340324
     
    421405
    422406    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
    423412    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 
    429413    VisibleSelection selection = m_page->focusController()->focusedOrMainFrame()->selection()->selection();
    430414    if (shouldUseSelection(position, selection)) {
Note: See TracChangeset for help on using the changeset viewer.