Title: [158098] trunk/Source/WebCore
Revision
158098
Author
an...@apple.com
Date
2013-10-27 16:06:41 -0700 (Sun, 27 Oct 2013)

Log Message

Enable center and right text alignment for simple lines
https://bugs.webkit.org/show_bug.cgi?id=123398

Reviewed by Andreas Kling.

Support text-align:center and text-align:right on simple line layout path.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseFor):
        
    text-align:justify is still not supported.

(WebCore::SimpleLineLayout::computeLineLeft):
(WebCore::SimpleLineLayout::createLines):
        
    Do a rounding dance that matches the line boxes.

* rendering/SimpleLineLayout.h:
        
    Add left position to lines.

* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::Resolver::Line::rect):
        
    We now do rounding during layout.

(WebCore::SimpleLineLayout::Resolver::Line::baseline):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (158097 => 158098)


--- trunk/Source/WebCore/ChangeLog	2013-10-27 22:54:07 UTC (rev 158097)
+++ trunk/Source/WebCore/ChangeLog	2013-10-27 23:06:41 UTC (rev 158098)
@@ -1,3 +1,33 @@
+2013-10-27  Antti Koivisto  <an...@apple.com>
+
+        Enable center and right text alignment for simple lines
+        https://bugs.webkit.org/show_bug.cgi?id=123398
+
+        Reviewed by Andreas Kling.
+
+        Support text-align:center and text-align:right on simple line layout path.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseFor):
+        
+            text-align:justify is still not supported.
+
+        (WebCore::SimpleLineLayout::computeLineLeft):
+        (WebCore::SimpleLineLayout::createLines):
+        
+            Do a rounding dance that matches the line boxes.
+
+        * rendering/SimpleLineLayout.h:
+        
+            Add left position to lines.
+
+        * rendering/SimpleLineLayoutResolver.h:
+        (WebCore::SimpleLineLayout::Resolver::Line::rect):
+        
+            We now do rounding during layout.
+
+        (WebCore::SimpleLineLayout::Resolver::Line::baseline):
+
 2013-10-27  Andreas Kling  <akl...@apple.com>
 
         Renderers should receive their style at construction.

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (158097 => 158098)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2013-10-27 22:54:07 UTC (rev 158097)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2013-10-27 23:06:41 UTC (rev 158098)
@@ -88,8 +88,7 @@
             return false;
     }
     const RenderStyle& style = *flow.style();
-    // It shoudn't be hard to support other alignments.
-    if (style.textAlign() != LEFT && style.textAlign() != WEBKIT_LEFT && style.textAlign() != TASTART)
+    if (style.textAlign() == JUSTIFY)
         return false;
     // Non-visible overflow should be pretty easy to support.
     if (style.overflowX() != OVISIBLE || style.overflowY() != OVISIBLE)
@@ -211,6 +210,27 @@
     return style.font().width(run);
 }
 
+static float computeLineLeft(ETextAlign textAlign, float remainingWidth)
+{
+    switch (textAlign) {
+    case LEFT:
+    case WEBKIT_LEFT:
+    case TASTART:
+        return 0;
+    case RIGHT:
+    case WEBKIT_RIGHT:
+    case TAEND:
+        return std::max<float>(remainingWidth, 0);
+    case CENTER:
+    case WEBKIT_CENTER:
+        return std::max<float>(remainingWidth / 2, 0);
+    case JUSTIFY:
+        break;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
 std::unique_ptr<Lines> createLines(RenderBlockFlow& flow)
 {
     auto lines = std::make_unique<Lines>();
@@ -221,6 +241,7 @@
     const RenderStyle& style = *flow.style();
     const unsigned textLength = textRenderer.textLength();
 
+    ETextAlign textAlign = style.textAlign();
     float wordTrailingSpaceWidth = style.font().width(TextRun(&space, 1));
 
     LazyLineBreakIterator lineBreakIterator(textRenderer.text(), style.locale());
@@ -268,10 +289,14 @@
         if (lineStartOffset == lineEndOffset)
             continue;
 
+        float alignedLeft = computeLineLeft(textAlign, lineWidth.availableWidth() - lineWidth.committedWidth());
+        float alignedRight = alignedLeft + lineWidth.committedWidth();
+
         Line line;
         line.textOffset = lineStartOffset;
         line.textLength = lineEndOffset - lineStartOffset;
-        line.width = lineWidth.committedWidth();
+        line.left = floor(alignedLeft);
+        line.width = ceil(alignedRight) - line.left;
 
         lines->append(line);
     }

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.h (158097 => 158098)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.h	2013-10-27 22:54:07 UTC (rev 158097)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.h	2013-10-27 23:06:41 UTC (rev 158098)
@@ -40,6 +40,7 @@
 struct Line {
     unsigned textOffset;
     unsigned textLength;
+    float left;
     float width;
 };
 

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h (158097 => 158098)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h	2013-10-27 22:54:07 UTC (rev 158097)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h	2013-10-27 23:06:41 UTC (rev 158098)
@@ -98,15 +98,17 @@
 {
     auto& line = m_resolver.m_lines[m_lineIndex];
 
-    LayoutPoint linePosition(0, m_resolver.m_lineHeight * m_lineIndex + m_resolver.m_baseline - m_resolver.m_ascent);
-    LayoutSize lineSize(ceiledLayoutUnit(line.width), m_resolver.m_ascent + m_resolver.m_descent);
+    LayoutPoint linePosition(line.left, m_resolver.m_lineHeight * m_lineIndex + m_resolver.m_baseline - m_resolver.m_ascent);
+    LayoutSize lineSize(line.width, m_resolver.m_ascent + m_resolver.m_descent);
     return LayoutRect(linePosition + m_resolver.m_contentOffset, lineSize);
 }
 
 inline LayoutPoint Resolver::Line::baseline() const
 {
+    auto& line = m_resolver.m_lines[m_lineIndex];
+
     float baselineY = m_resolver.m_lineHeight * m_lineIndex + m_resolver.m_baseline;
-    return LayoutPoint(0, baselineY) + m_resolver.m_contentOffset;
+    return LayoutPoint(line.left, baselineY) + m_resolver.m_contentOffset;
 }
 
 inline String Resolver::Line::text() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to