2011-04-06 Levi Weintraub <leviw@chromium.org>
authorleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Apr 2011 12:12:58 +0000 (12:12 +0000)
committerleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Apr 2011 12:12:58 +0000 (12:12 +0000)
        Reviewed by Ryosuke Niwa.

        Add member functions for determining line/paragraph separation to InlineIterator
        https://bugs.webkit.org/show_bug.cgi?id=57938

        Adding atTextParagraphSeparator and atParagraphSeparator inline convenience functions to
        InlineIterator, where it makes far more sense for them to be. Also moving
        shouldPreserveNewline to RenderObject and renaming it preservesNewline.

        No new tests as this provides no new functionality.

        * rendering/InlineIterator.h:
        (WebCore::InlineIterator::atTextParagraphSeparator):
        (WebCore::InlineIterator::atParagraphSeparator):
        * rendering/RenderBlockLineLayout.cpp:
        (WebCore::RenderBlock::requiresLineBox):
        (WebCore::RenderBlock::findNextLineBreak):
        * rendering/RenderObject.h:
        (WebCore::RenderObject::preservesNewline):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineIterator.h
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderObject.h

index e48b5cd..0d6c381 100644 (file)
@@ -1,3 +1,25 @@
+2011-04-06  Levi Weintraub  <leviw@chromium.org>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add member functions for determining line/paragraph separation to InlineIterator
+        https://bugs.webkit.org/show_bug.cgi?id=57938
+
+        Adding atTextParagraphSeparator and atParagraphSeparator inline convenience functions to
+        InlineIterator, where it makes far more sense for them to be. Also moving
+        shouldPreserveNewline to RenderObject and renaming it preservesNewline.
+
+        No new tests as this provides no new functionality.
+
+        * rendering/InlineIterator.h:
+        (WebCore::InlineIterator::atTextParagraphSeparator):
+        (WebCore::InlineIterator::atParagraphSeparator):
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::requiresLineBox):
+        (WebCore::RenderBlock::findNextLineBreak):
+        * rendering/RenderObject.h:
+        (WebCore::RenderObject::preservesNewline):
+
 2011-04-05  Alexander Pavlov  <apavlov@chromium.org>
 
         Reviewed by Pavel Feldman.
index a1057c6..2c6aaaf 100644 (file)
@@ -68,6 +68,17 @@ public:
     void increment(InlineBidiResolver* = 0);
     bool atEnd() const;
 
+    inline bool atTextParagraphSeparator()
+    {
+        return m_obj && m_obj->preservesNewline() && m_obj->isText() && toRenderText(m_obj)->textLength()
+            && !toRenderText(m_obj)->isWordBreak() && toRenderText(m_obj)->characters()[m_pos] == '\n';
+    }
+    
+    inline bool atParagraphSeparator()
+    {
+        return (m_obj && m_obj->isBR()) || atTextParagraphSeparator();
+    }
+
     UChar current() const;
     ALWAYS_INLINE WTF::Unicode::Direction direction() const;
 
index 284f89e..2457f14 100644 (file)
@@ -1388,16 +1388,6 @@ static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, bool isLin
     return style->collapseWhiteSpace() || (style->whiteSpace() == PRE_WRAP && (!isLineEmpty || !previousLineBrokeCleanly));
 }
 
-static inline bool shouldPreserveNewline(RenderObject* object)
-{
-#if ENABLE(SVG)
-    if (object->isSVGInlineText())
-        return false;
-#endif
-
-    return object->style()->preserveNewline();
-}
-
 static bool inlineFlowRequiresLineBox(RenderInline* flow)
 {
     // FIXME: Right now, we only allow line boxes for inlines that are truly empty.
@@ -1418,7 +1408,7 @@ bool RenderBlock::requiresLineBox(const InlineIterator& it, bool isLineEmpty, bo
         return true;
 
     UChar current = it.current();
-    return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || shouldPreserveNewline(it.m_obj)) 
+    return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || it.m_obj->preservesNewline()) 
             && !skipNonBreakingSpace(it, isLineEmpty, previousLineBrokeCleanly);
 }
 
@@ -1914,7 +1904,7 @@ InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool
                                 if (hyphenated)
                                     goto end;
                             }
-                            if (lBreak.m_obj && shouldPreserveNewline(lBreak.m_obj) && lBreak.m_obj->isText() && toRenderText(lBreak.m_obj)->textLength() && !toRenderText(lBreak.m_obj)->isWordBreak() && toRenderText(lBreak.m_obj)->characters()[lBreak.m_pos] == '\n') {
+                            if (lBreak.atTextParagraphSeparator()) {
                                 if (!stoppedIgnoringSpaces && pos > 0) {
                                     // We need to stop right before the newline and then start up again.
                                     addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); // Stop
@@ -2055,7 +2045,7 @@ InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool
                     RenderText* nextText = toRenderText(next);
                     if (nextText->textLength()) {
                         UChar c = nextText->characters()[0];
-                        if (c == ' ' || c == '\t' || (c == '\n' && !shouldPreserveNewline(next)))
+                        if (c == ' ' || c == '\t' || (c == '\n' && !next->preservesNewline()))
                             // If the next item on the line is text, and if we did not end with
                             // a space, then the next text run continues our word (and so it needs to
                             // keep adding to |tmpW|.  Just update and continue.
index 2077bc1..5a8d0e7 100644 (file)
@@ -433,6 +433,7 @@ public:
     bool hasTransform() const { return m_hasTransform; }
     bool hasMask() const { return style() && style()->hasMask(); }
 
+    inline bool preservesNewline() const;
     void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
                             Color, EBorderStyle, int adjbw1, int adjbw2);
 #if HAVE(PATH_BASED_BORDER_RADIUS_DRAWING)
@@ -1037,6 +1038,16 @@ inline void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, R
         last->scheduleRelayout();
 }
 
+inline bool RenderObject::preservesNewline() const
+{
+#if ENABLE(SVG)
+    if (isSVGInlineText())
+        return false;
+#endif
+        
+    return style()->preserveNewline();
+}
+
 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
 {
 #if !ENABLE(3D_RENDERING)