Fix for 8333, make sure newlines in whitespace:pre (and friends) get
        line boxes created for them.  This resolves all the weird selection/navigation
        issues that arise by not creating lines (and thus not having navigable positions
        on those lines).

        This checkin is also removing all of the layout test hacks that have piled
        up, so layout test results are being regenerated completely.

        Reviewed by eric

        * dom/Position.cpp:
        (WebCore::Position::downstream):
        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::moveParagraph):
        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::doApply):
        * editing/visible_units.cpp:
        (WebCore::startOfParagraph):
        (WebCore::endOfParagraph):
        * kwq/RenderTreeAsText.cpp:
        (getTagName):
        (operator<<):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::selectionState):
        (WebCore::InlineTextBox::isLineBreak):
        (WebCore::InlineTextBox::nodeAtPoint):
        (WebCore::InlineTextBox::paint):
        (WebCore::InlineTextBox::offsetForPosition):
        (WebCore::InlineTextBox::positionForOffset):
        * rendering/InlineTextBox.h:
        * rendering/RenderBR.cpp:
        * rendering/RenderBR.h:
        * rendering/RenderText.cpp:
        (WebCore::RenderText::atLineWrap):
        (WebCore::RenderText::caretRect):
        (WebCore::RenderText::height):
        (WebCore::RenderText::inlineBox):
        * rendering/bidi.cpp:
        (WebCore::RenderBlock::computeHorizontalPositionsForLine):
        (WebCore::RenderBlock::layoutInlineChildren):
        (WebCore::RenderBlock::findNextLineBreak):
        * rendering/render_line.h:
        (WebCore::InlineBox::isLineBreak):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@13868 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/rendering/bidi.cpp b/WebCore/rendering/bidi.cpp
index 2720fc4..f38536f 100644
--- a/WebCore/rendering/bidi.cpp
+++ b/WebCore/rendering/bidi.cpp
@@ -101,7 +101,6 @@
 
 static bool isLineEmpty = true;
 static bool previousLineBrokeCleanly = true;
-static bool skipTrailingNewline = false;
 static bool emptyRun = true;
 static int numSpaces;
 
@@ -854,9 +853,10 @@
     BidiRun* r = 0;
     bool needsWordSpacing = false;
     for (r = sFirstBidiRun; r; r = r->nextRun) {
-        if (!r->box || r->obj->isPositioned())
+        if (!r->box || r->obj->isPositioned() || r->box->isLineBreak())
             continue; // Positioned objects are only participating to figure out their
                       // correct static x position.  They have no effect on the width.
+                      // Similarly, line break boxes have no effect on the width.
         if (r->obj->isText()) {
             RenderText *rt = static_cast<RenderText *>(r->obj);
             int textWidth = rt->width(r->start, r->stop-r->start, totWidth, m_firstLine);
@@ -1630,7 +1630,7 @@
                     }
                 }
                 
-                if (end == start || skipTrailingNewline) {
+                if (end == start) {
                     bidi.adjustEmbedding = true;
                     end.increment(bidi);
                     bidi.adjustEmbedding = false;
@@ -1974,7 +1974,6 @@
 
     bool prevLineBrokeCleanly = previousLineBrokeCleanly;
     previousLineBrokeCleanly = false;
-    skipTrailingNewline = false;
     
     while (o) {
         if (o->isBR()) {
@@ -2186,6 +2185,7 @@
                 bool midWordBreak = breakWords && (w + wrapW > width);
 
                 if (c == '\n' || (o->style()->whiteSpace() != PRE && isBreakable(str, pos, strlen, nextBreakable, breakNBSP)) || midWordBreak) {
+                    bool stoppedIgnoringSpaces = false;
                     if (ignoringSpaces) {
                         if (!currentCharacterIsSpace) {
                             // Stop ignoring spaces and begin at this
@@ -2195,6 +2195,7 @@
                             lastSpace = pos; // e.g., "Foo    goo", don't add in any of the ignored spaces.
                             BidiIterator startMid ( 0, o, pos );
                             addMidpoint(startMid);
+                            stoppedIgnoringSpaces = true;
                         } else {
                             // Just keep ignoring these spaces.
                             pos++;
@@ -2249,8 +2250,14 @@
                                 }
                             }
                             if (lBreak.obj && lBreak.obj->style()->preserveNewline() && lBreak.obj->isText() && static_cast<RenderText*>(lBreak.obj)->text()[lBreak.pos] == '\n') {
+                                if (!stoppedIgnoringSpaces && pos > 0) {
+                                    // We need to stop right before the newline and then start up again.
+                                    BidiIterator midpoint(0, o, pos);
+                                    addMidpoint(BidiIterator(0, o, pos-1)); // Stop
+                                    addMidpoint(BidiIterator(0, o, pos)); // Start
+                                }
+                                lBreak.increment(bidi);
                                 previousLineBrokeCleanly = true;
-                                skipTrailingNewline = true;
                             }
                             goto end; // Didn't fit. Jump to the end.
                         } else {
@@ -2263,10 +2270,16 @@
                     }
 
                     if (c == '\n' && o->style()->preserveNewline()) {
+                        if (!stoppedIgnoringSpaces && pos > 0) {
+                            // We need to stop right before the newline and then start up again.
+                            BidiIterator midpoint(0, o, pos);
+                            addMidpoint(BidiIterator(0, o, pos-1)); // Stop
+                            addMidpoint(BidiIterator(0, o, pos)); // Start
+                        }
                         lBreak.obj = o;
                         lBreak.pos = pos;
+                        lBreak.increment(bidi);
                         previousLineBrokeCleanly = true;
-                        skipTrailingNewline = true;
                         return lBreak;
                     }