LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jun 2006 18:33:28 +0000 (18:33 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jun 2006 18:33:28 +0000 (18:33 +0000)
        Reviewed by harrison

        * editing/selection/focus-body-expected.checksum: Added.
        * editing/selection/focus-body-expected.png: Added.
        * editing/selection/focus-body-expected.txt: Added.
        * editing/selection/focus-body.html: Added.
        * editing/selection/focus_editable_html-expected.checksum:
        * editing/selection/focus_editable_html-expected.png:
        * editing/selection/focus_editable_html-expected.txt:

WebCore:

        Reviewed by harrison

        <rdar://problem/4567752> When forwarding a message, pressing TAB key to place caret in body actually selects the entire message instead

        * dom/Element.cpp:
        (WebCore::Element::focus):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14666 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/selection/focus-body-expected.checksum [new file with mode: 0644]
LayoutTests/editing/selection/focus-body-expected.png [new file with mode: 0644]
LayoutTests/editing/selection/focus-body-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/focus-body.html [new file with mode: 0644]
LayoutTests/editing/selection/focus_editable_html-expected.checksum
LayoutTests/editing/selection/focus_editable_html-expected.png
LayoutTests/editing/selection/focus_editable_html-expected.txt
WebCore/ChangeLog
WebCore/dom/Element.cpp

index b8ae2ad2e19859ab3dca365a00634e9b2fe0c95f..1772eb12b7c3634d9c520ab3c7c24af0935be6c9 100644 (file)
@@ -1,3 +1,15 @@
+2006-06-01  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+
+        * editing/selection/focus-body-expected.checksum: Added.
+        * editing/selection/focus-body-expected.png: Added.
+        * editing/selection/focus-body-expected.txt: Added.
+        * editing/selection/focus-body.html: Added.
+        * editing/selection/focus_editable_html-expected.checksum:
+        * editing/selection/focus_editable_html-expected.png:
+        * editing/selection/focus_editable_html-expected.txt:
+
 2006-06-01  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/editing/selection/focus-body-expected.checksum b/LayoutTests/editing/selection/focus-body-expected.checksum
new file mode 100644 (file)
index 0000000..07625c8
--- /dev/null
@@ -0,0 +1 @@
+644ab869c9d1c6eed300c149d45f701c
\ No newline at end of file
diff --git a/LayoutTests/editing/selection/focus-body-expected.png b/LayoutTests/editing/selection/focus-body-expected.png
new file mode 100644 (file)
index 0000000..258d3d5
Binary files /dev/null and b/LayoutTests/editing/selection/focus-body-expected.png differ
diff --git a/LayoutTests/editing/selection/focus-body-expected.txt b/LayoutTests/editing/selection/focus-body-expected.txt
new file mode 100644 (file)
index 0000000..ed359d0
--- /dev/null
@@ -0,0 +1,14 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 2 of BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderText {#text} at (0,0) size 438x18
+        text run at (0,0) width 220: "This test focuses an editable body. "
+        text run at (220,0) width 218: "Its contents should not be selected."
+      RenderText {#text} at (0,0) size 0x0
+caret: position 0 of child 0 {#text} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/selection/focus-body.html b/LayoutTests/editing/selection/focus-body.html
new file mode 100644 (file)
index 0000000..72e65c3
--- /dev/null
@@ -0,0 +1,5 @@
+<body contenteditable="true">This test focuses an editable body.  Its contents should not be selected.
+<script>
+document.body.focus();
+</script>
+</body>
\ No newline at end of file
index e5061dea488a58f1731cf1bc77f9e64296a783cc..6dbdfd926c5c2cd3aacd64346adb16544405bd6f 100644 (file)
@@ -1 +1 @@
-9e5e54bf429185536353247bf42831c1
\ No newline at end of file
+64766d8472ce9c0a9a039ab9874f480d
\ No newline at end of file
index fea3c688b3870144ea30504b60e4b7d586470889..7d7c82973ef82f5b42ca2bf0555841ce8121bcdc 100644 (file)
Binary files a/LayoutTests/editing/selection/focus_editable_html-expected.png and b/LayoutTests/editing/selection/focus_editable_html-expected.png differ
index 6ed0eb056ebfacd827a803060278bb0999dfda30..37cb79a6075c88347904185a6512e2f329fc9785 100644 (file)
@@ -1,6 +1,6 @@
 EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of HTML > #document to 1 of HTML > #document
 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 1 of #text > BODY > HTML > #document to 42 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 layer at (0,0) size 2008x2088
   RenderCanvas at (0,0) size 785x585
@@ -23,6 +23,4 @@ layer at (0,0) size 2008x2088
         RenderText {#text} at (0,0) size 237x18
           text run at (0,0) width 237: "If the document scrolls here, test fails."
         RenderText {#text} at (0,0) size 0x0
-selection start: position 1 of child 0 {#text} of child 0 {BODY} of child 0 {HTML} of document
-selection end:   position 42 of child 8 {#text} of child 0 {BODY} of child 0 {HTML} of document
-scrolled to 0,8
+caret: position 1 of child 0 {#text} of child 0 {BODY} of child 0 {HTML} of document
index ac2e7931cc449df4c9fc3e77a72f0804f698e2c4..59a3a0adc6088c8b37edec2ebdf83b997ab86c78 100644 (file)
@@ -1,3 +1,12 @@
+2006-06-01  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <rdar://problem/4567752> When forwarding a message, pressing TAB key to place caret in body actually selects the entire message instead
+
+        * dom/Element.cpp:
+        (WebCore::Element::focus):
+
 2006-06-01  David Kilzer  <ddkilzer@kilzer.net>
 
         Reviewed by darin.
index 3c37670bfceafa49685f1973bcc3b17aa5d63513..031bbad35fa32d175c6b258e28812b20e2bf2104 100644 (file)
@@ -32,6 +32,7 @@
 #include "HTMLNames.h"
 #include "NamedAttrMap.h"
 #include "RenderBlock.h"
+#include "SelectionController.h"
 #include "KWQTextStream.h"
 
 namespace WebCore {
@@ -820,17 +821,29 @@ CSSStyleDeclaration *Element::style()
 
 void Element::focus()
 {
+    if (!isFocusable())
+        return;
+    
     Document* doc = document();
     doc->updateLayout();
-    if (isFocusable()) {
-        doc->setFocusNode(this);
-        if (rootEditableElement() == this) {
-            // FIXME: we should restore the previous selection if there is one, instead of always selecting all.
-            if (doc->frame()->selectContentsOfNode(this))
-                doc->frame()->revealSelection();
-        } else if (renderer() && !renderer()->isWidget())
-            renderer()->enclosingLayer()->scrollRectToVisible(getRect());
-    }
+                
+    doc->setFocusNode(this);
+    
+    if (this == rootEditableElement()) {    
+        Frame* frame = doc->frame();
+        if (!frame)
+            return;
+        
+        // FIXME: We should restore the previous selection if there is one.
+        Selection s = hasTagName(htmlTag) || hasTagName(bodyTag) ? Selection(Position(this, 0), DOWNSTREAM) : Selection::selectionFromContentsOfNode(this);
+        SelectionController sc(s);
+        
+        if (frame->shouldChangeSelection(sc)) {
+            frame->setSelection(sc);
+            frame->revealSelection();
+        }
+    } else if (renderer() && !renderer()->isWidget())
+        renderer()->enclosingLayer()->scrollRectToVisible(getRect());
 }
 
 void Element::blur()