Title: [104025] trunk/Source/WebKit2
Revision
104025
Author
[email protected]
Date
2012-01-04 03:31:11 -0800 (Wed, 04 Jan 2012)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (104024 => 104025)


--- trunk/Source/WebKit2/ChangeLog	2012-01-04 11:24:04 UTC (rev 104024)
+++ trunk/Source/WebKit2/ChangeLog	2012-01-04 11:31:11 UTC (rev 104025)
@@ -1,3 +1,24 @@
+2012-01-03  Kenneth Rohde Christiansen  <[email protected]>
+
+        [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):
+
 2012-01-04  Mihnea Ovidenie  <[email protected]>
 
         [Mac]Fix build after changeset 103997

Modified: trunk/Source/WebKit2/Shared/EditorState.cpp (104024 => 104025)


--- trunk/Source/WebKit2/Shared/EditorState.cpp	2012-01-04 11:24:04 UTC (rev 104024)
+++ trunk/Source/WebKit2/Shared/EditorState.cpp	2012-01-04 11:31:11 UTC (rev 104025)
@@ -46,8 +46,6 @@
     encoder->encode(anchorPosition);
     encoder->encode(microFocus);
     encoder->encode(compositionRect);
-    encoder->encode(compositionStart);
-    encoder->encode(compositionLength);
     encoder->encode(selectedText);
     encoder->encode(surroundingText);
 #endif
@@ -89,12 +87,6 @@
     if (!decoder->decode(result.compositionRect))
         return false;
 
-    if (!decoder->decode(result.compositionStart))
-        return false;
-
-    if (!decoder->decode(result.compositionLength))
-        return false;
-
     if (!decoder->decode(result.selectedText))
         return false;
 

Modified: trunk/Source/WebKit2/Shared/EditorState.h (104024 => 104025)


--- trunk/Source/WebKit2/Shared/EditorState.h	2012-01-04 11:24:04 UTC (rev 104024)
+++ trunk/Source/WebKit2/Shared/EditorState.h	2012-01-04 11:31:11 UTC (rev 104025)
@@ -45,8 +45,6 @@
 #if PLATFORM(QT)
         , cursorPosition(0)
         , anchorPosition(0)
-        , compositionStart(0)
-        , compositionLength(0)
 #endif
     {
     }
@@ -60,12 +58,13 @@
     bool isInPasswordField;
     bool hasComposition;
 #if PLATFORM(QT)
-    int cursorPosition;
-    int anchorPosition;
+    // The anchor, cursor represent either the selection or composition, depending
+    // whether a composition exists or not.
+    unsigned cursorPosition;
+    unsigned anchorPosition;
+
     WebCore::IntRect microFocus;
     WebCore::IntRect compositionRect;
-    int compositionStart;
-    int compositionLength;
     WTF::String selectedText;
     WTF::String surroundingText;
 #endif

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (104024 => 104025)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-01-04 11:24:04 UTC (rev 104024)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-01-04 11:31:11 UTC (rev 104025)
@@ -390,34 +390,36 @@
 #if PLATFORM(QT)
     size_t location = 0;
     size_t length = 0;
-    Element* scope = frame->selection()->rootEditableElement();
 
+    Element* selectionRoot = frame->selection()->rootEditableElement();
+    Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement();
+
     RefPtr<Range> range;
     if (result.hasComposition && (range = frame->editor()->compositionRange())) {
-        TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
-        result.compositionStart = location;
-        result.compositionLength = length;
-        result.compositionRect = range->boundingBox();
+        frame->editor()->getCompositionSelection(result.anchorPosition, result.cursorPosition);
+
+        result.compositionRect = frame->view()->contentsToWindow(range->boundingBox());
     }
 
-    if (!result.selectionIsNone && (range = frame->selection()->selection().firstRange())) {
+    if (!result.hasComposition && !result.selectionIsNone && (range = frame->selection()->selection().firstRange())) {
         TextIterator::getLocationAndLengthFromRange(scope, range.get(), location, length);
-
-        ExceptionCode ec = 0;
-        RefPtr<Range> tempRange = range->cloneRange(ec);
-        tempRange->setStart(tempRange->startContainer(ec), tempRange->startOffset(ec) + location, ec);
-        IntRect rect = frame->editor()->firstRectForRange(tempRange.get());
         bool baseIsFirst = frame->selection()->selection().isBaseFirst();
 
         result.cursorPosition = (baseIsFirst) ? location + length : location;
         result.anchorPosition = (baseIsFirst) ? location : location + length;
-        result.microFocus = frame->view()->contentsToWindow(rect);
         result.selectedText = range->text();
     }
 
-    if (scope && result.isContentEditable && !result.isInPasswordField) {
+    if (range)
+        result.microFocus = frame->view()->contentsToWindow(frame->editor()->firstRectForRange(range.get()));
+
+    // FIXME: We should only transfer innerText when it changes and do this on the UI side.
+    if (result.isContentEditable && !result.isInPasswordField) {
         result.surroundingText = scope->innerText();
-        result.surroundingText.remove(result.compositionStart, result.compositionLength);
+        if (result.hasComposition) {
+            // The anchor is always the left position when they represent a composition.
+            result.surroundingText.remove(result.anchorPosition, result.cursorPosition - result.anchorPosition);
+        }
     }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to