Cannot focus on an empty editable span in a non editable div.
https://bugs.webkit.org/show_bug.cgi?id=33411
<rdar://problem/5982901>

Reviewed by Darin Adler.

WebCore: 

We now allow to set the focus inside an empty inline element if it is the only
editable element inside non-editable content.

* dom/Position.cpp:
(WebCore::Position::isCandidate): Extended to allow positions in inline elements when
at the border between editable and non editable content.
(WebCore::Position::getInlineBoxAndOffset): Modified to be able to calculate the caret
position inside an empty inline.
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::mergeParagraphs): When merging, we don't always find a break
element, since now an editable inline is a VisiblePosition if it is at editability boundary.
* editing/VisibleSelection.h: Updated comment on the use of Position member variables
instead of VisiblePosition.
* page/Frame.cpp:
(WebCore::Frame::selectionLayoutChanged): Changed to avoid multiple calls to upstream and
downstream on the same position.

LayoutTests: 

* editing/deleting/6026335-expected.txt: Updated to reflect the lack of extra break element.
* editing/selection/mixed-editability-10-expected.txt: Updated to cover the new case.
* editing/selection/mixed-editability-10.html: Updated to cover the new case.
* platform/mac/editing/deleting/5115601-expected.txt: Updated to reflect the lack of extra break element.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53085 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index b71e3a6..b172318 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2010-01-08  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Cannot focus on an empty editable span in a non editable div.
+        https://bugs.webkit.org/show_bug.cgi?id=33411
+        <rdar://problem/5982901>
+
+        * editing/deleting/6026335-expected.txt: Updated to reflect the lack of extra break element.
+        * editing/selection/mixed-editability-10-expected.txt: Updated to cover the new case.
+        * editing/selection/mixed-editability-10.html: Updated to cover the new case.
+        * platform/mac/editing/deleting/5115601-expected.txt: Updated to reflect the lack of extra break element.
+
 2010-01-08  Nate Chapin  <japhet@chromium.org>
 
         Reviewed by Dimitri Glazkov.
diff --git a/LayoutTests/editing/deleting/6026335-expected.txt b/LayoutTests/editing/deleting/6026335-expected.txt
index fc13bb8..ba7fada 100644
--- a/LayoutTests/editing/deleting/6026335-expected.txt
+++ b/LayoutTests/editing/deleting/6026335-expected.txt
@@ -1,4 +1,4 @@
 This tests deleting a selection that starts at the beginning of an editable pocket inside a non-editable table. The caret should not disappear during the delete and should be placed inside the editable span. When text is then inserted, it should be placed inside that span.
 
-<div contenteditable="false"><span>&nbsp;</span><span contenteditable="true" id="start">Text<br></span></div>
+<div contenteditable="false"><span>&nbsp;</span><span contenteditable="true" id="start">Text</span></div>
 
diff --git a/LayoutTests/editing/selection/mixed-editability-10-expected.txt b/LayoutTests/editing/selection/mixed-editability-10-expected.txt
index c739819..09bb276 100644
--- a/LayoutTests/editing/selection/mixed-editability-10-expected.txt
+++ b/LayoutTests/editing/selection/mixed-editability-10-expected.txt
@@ -12,6 +12,9 @@
 Hello World
 #5 DIV element empty
 
+#6 non editable DIV element with an editable empty span element
+
+Hello: 
 Anchor ([object HTMLDivElement], 0 caret[40,540] refpos=40) is correct.
 Anchor ([object HTMLDivElement], 3 caret[75,540] refpos=75) is correct.
 Anchor ([object HTMLDivElement], 1 caret[43,472] refpos=43) is correct.
@@ -19,3 +22,4 @@
 Anchor ([object HTMLDivElement], 0 caret[73,404] refpos=73) is correct.
 Anchor ([object HTMLDivElement], 3 caret[47,336] refpos=47) is correct.
 Anchor ([object HTMLDivElement], 0 caret[58,268] refpos=58) is correct.
+Anchor ([object HTMLElement], 0 caret[0,600] refpos=0) is correct.
diff --git a/LayoutTests/editing/selection/mixed-editability-10.html b/LayoutTests/editing/selection/mixed-editability-10.html
index fb7c1e7..9e390d5 100644
--- a/LayoutTests/editing/selection/mixed-editability-10.html
+++ b/LayoutTests/editing/selection/mixed-editability-10.html
@@ -20,6 +20,10 @@
   <p>#5 DIV element empty</p>
   <div style="width:100px;background-color:#cee;text-align: center;" contenteditable="true" id="edit5">
   </div>
+  <p>#6 non editable DIV element with an editable empty span element</p>
+  <div id="nonedit6" style="width:100px;background-color:#cee;">
+    Hello:&nbsp;<span id="edit6" contenteditable="true"> </span>
+  </div>
   <ul id="console"></ul>
 </body>
 <script>
@@ -98,6 +102,12 @@
         x = elem.offsetLeft;
         y = elem.offsetTop + elem.offsetHeight / 2;
         runTest(x, y, elem, 0, (elem.offsetLeft + elem.offsetWidth)/2 + 4);
+
+        // the div is non editable and contains an empty editable span
+        elem = document.getElementById("edit6");
+        x = document.getElementById("nonedit6").offsetLeft + document.getElementById("nonedit6").offsetWidth / 2;
+        y = document.getElementById("nonedit6").offsetTop + document.getElementById("nonedit6").offsetHeight / 2;
+        runTest(x, y, elem, 0, 0);
     }
 }
 
diff --git a/LayoutTests/platform/mac/editing/deleting/5115601-expected.txt b/LayoutTests/platform/mac/editing/deleting/5115601-expected.txt
index 95a97d8..adcc69f 100644
--- a/LayoutTests/platform/mac/editing/deleting/5115601-expected.txt
+++ b/LayoutTests/platform/mac/editing/deleting/5115601-expected.txt
@@ -16,6 +16,5 @@
                   RenderInline {SPAN} at (0,0) size 298x18
                     RenderText {#text} at (2,2) size 298x18
                       text run at (2,2) width 298: "This sentence should be inside the editable cell."
-                  RenderBR {BR} at (300,16) size 0x0
         RenderBlock (anonymous) at (0,28) size 784x0
 caret: position 0 of child 0 {#text} of child 0 {SPAN} of child 0 {SPAN} of child 0 {TD} of child 0 {TR} of child 0 {TBODY} of child 1 {TABLE} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document