Changeset 104025 in webkit


Ignore:
Timestamp:
Jan 4, 2012 3:31:11 AM (12 years ago)
Author:
kenneth@webkit.org
Message:

[Qt] Clean up Qt specific part of editorState()

Reviewed by Simon Hausmann.

Use unsigned instead of int.
No need to clone the range as we don't modify it.
Support selections which include a composition.
If we are not in editable content make sure to use the document element
as the scope for calculating the positions and lengths.
Remove compositionStart/Length as there cannot be a selection and
composition at the same time.

Only tested manually as we don't have everything in place yet
to properly test this.

  • Shared/EditorState.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::editorState):

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r104022 r104025  
     12012-01-03  Kenneth Rohde Christiansen  <kenneth@webkit.org>
     2
     3        [Qt] Clean up Qt specific part of editorState()
     4
     5        Reviewed by Simon Hausmann.
     6
     7        Use unsigned instead of int.
     8        No need to clone the range as we don't modify it.
     9        Support selections which include a composition.
     10        If we are not in editable content make sure to use the document element
     11        as the scope for calculating the positions and lengths.
     12        Remove compositionStart/Length as there cannot be a selection and
     13        composition at the same time.
     14
     15        Only tested manually as we don't have everything in place yet
     16        to properly test this.
     17
     18        * Shared/EditorState.h:
     19        * WebProcess/WebPage/WebPage.cpp:
     20        (WebKit::WebPage::editorState):
     21
    1222012-01-04  Mihnea Ovidenie  <mihnea@adobe.com>
    223
  • trunk/Source/WebKit2/Shared/EditorState.cpp

    r102334 r104025  
    4747    encoder->encode(microFocus);
    4848    encoder->encode(compositionRect);
    49     encoder->encode(compositionStart);
    50     encoder->encode(compositionLength);
    5149    encoder->encode(selectedText);
    5250    encoder->encode(surroundingText);
     
    9088        return false;
    9189
    92     if (!decoder->decode(result.compositionStart))
    93         return false;
    94 
    95     if (!decoder->decode(result.compositionLength))
    96         return false;
    97 
    9890    if (!decoder->decode(result.selectedText))
    9991        return false;
  • trunk/Source/WebKit2/Shared/EditorState.h

    r102334 r104025  
    4646        , cursorPosition(0)
    4747        , anchorPosition(0)
    48         , compositionStart(0)
    49         , compositionLength(0)
    5048#endif
    5149    {
     
    6159    bool hasComposition;
    6260#if PLATFORM(QT)
    63     int cursorPosition;
    64     int anchorPosition;
     61    // The anchor, cursor represent either the selection or composition, depending
     62    // whether a composition exists or not.
     63    unsigned cursorPosition;
     64    unsigned anchorPosition;
     65
    6566    WebCore::IntRect microFocus;
    6667    WebCore::IntRect compositionRect;
    67     int compositionStart;
    68     int compositionLength;
    6968    WTF::String selectedText;
    7069    WTF::String surroundingText;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r103925 r104025  
    391391    size_t location = 0;
    392392    size_t length = 0;
    393     Element* scope = frame->selection()->rootEditableElement();
     393
     394    Element* selectionRoot = frame->selection()->rootEditableElement();
     395    Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
    394396
    395397    RefPtr<Range> range;
    396398    if (result.hasComposition && (range = frame->editor()->compositionRange())) {
     399        frame->editor()->getCompositionSelection(result.anchorPosition, result.cursorPosition);
     400
     401        result.compositionRect = frame->view()->contentsToWindow(range->boundingBox());
     402    }
     403
     404    if (!result.hasComposition && !result.selectionIsNone && (range = frame->selection()->selection().firstRange())) {
    397405        TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
    398         result.compositionStart = location;
    399         result.compositionLength = length;
    400         result.compositionRect = range->boundingBox();
    401     }
    402 
    403     if (!result.selectionIsNone && (range = frame->selection()->selection().firstRange())) {
    404         TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
    405 
    406         ExceptionCode ec = 0;
    407         RefPtr<Range> tempRange = range->cloneRange(ec);
    408         tempRange->setStart(tempRange->startContainer(ec), tempRange->startOffset(ec) + location, ec);
    409         IntRect rect = frame->editor()->firstRectForRange(tempRange.get());
    410406        bool baseIsFirst = frame->selection()->selection().isBaseFirst();
    411407
    412408        result.cursorPosition = (baseIsFirst) ? location + length : location;
    413409        result.anchorPosition = (baseIsFirst) ? location : location + length;
    414         result.microFocus = frame->view()->contentsToWindow(rect);
    415410        result.selectedText = range->text();
    416411    }
    417412
    418     if (scope && result.isContentEditable && !result.isInPasswordField) {
     413    if (range)
     414        result.microFocus = frame->view()->contentsToWindow(frame->editor()->firstRectForRange(range.get()));
     415
     416    // FIXME: We should only transfer innerText when it changes and do this on the UI side.
     417    if (result.isContentEditable && !result.isInPasswordField) {
    419418        result.surroundingText = scope->innerText();
    420         result.surroundingText.remove(result.compositionStart, result.compositionLength);
     419        if (result.hasComposition) {
     420            // The anchor is always the left position when they represent a composition.
     421            result.surroundingText.remove(result.anchorPosition, result.cursorPosition - result.anchorPosition);
     422        }
    421423    }
    422424#endif
Note: See TracChangeset for help on using the changeset viewer.