Initial letters should clear one another.
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 21:20:12 +0000 (21:20 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 21:20:12 +0000 (21:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136514

Reviewed by Simon Fraser.

Source/WebCore:

Added fast/css-generated-content/initial-letter-clearance.html.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeLogicalLocationForFloat):
Compute the required clearance and add it both to the block's logical height
and to the logical top offset of the float.

(WebCore::RenderBlockFlow::lowestInitialLetterLogicalBottom):
* rendering/RenderBlockFlow.h:
A new method for determining the lowest floating initial letter.

LayoutTests:

* fast/css-generated-content/initial-letter-clearance.html: Added.
* platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png: Added.
* platform/mac/fast/css-generated-content/initial-letter-clearance-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css-generated-content/initial-letter-clearance.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h

index 76401c2..3b15f28 100644 (file)
@@ -1,3 +1,14 @@
+2014-09-03  David Hyatt  <hyatt@apple.com>
+
+        Initial letters should clear one another.
+        https://bugs.webkit.org/show_bug.cgi?id=136514
+
+        Reviewed by Simon Fraser.
+
+        * fast/css-generated-content/initial-letter-clearance.html: Added.
+        * platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png: Added.
+        * platform/mac/fast/css-generated-content/initial-letter-clearance-expected.txt: Added.
+
 2014-09-04  Beth Dakin  <bdakin@apple.com>
 
         REGRESSION (r172832): Poor 2-finger scrolling performance at theverge.com articles 
diff --git a/LayoutTests/fast/css-generated-content/initial-letter-clearance.html b/LayoutTests/fast/css-generated-content/initial-letter-clearance.html
new file mode 100644 (file)
index 0000000..01c7891
--- /dev/null
@@ -0,0 +1,17 @@
+<html>
+<head>
+<style>
+div { width:400px; margin:1em }
+div::first-letter { font-family: Zapfino; -webkit-initial-letter: 2 4; margin-right:2px; margin-left:2; }
+
+</style>
+</head>
+<div>
+Just an example of first-letter. Short paragraph!
+</div>
+<div>
+Just an example of first-letter. This letter should span 3 lines of text, and
+so it should align itself cleanly with the cap-height of the J lining up with
+the cap-height of the first line, and the baseline of the J lining up with the
+baseline of the third line. The descender of the J is still avoided by following lines. This paragraph cleared the short paragraph.
+</div>
diff --git a/LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png b/LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png
new file mode 100644 (file)
index 0000000..0da5b2d
Binary files /dev/null and b/LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.txt b/LayoutTests/platform/mac/fast/css-generated-content/initial-letter-clearance-expected.txt
new file mode 100644 (file)
index 0000000..30d8ded
--- /dev/null
@@ -0,0 +1,22 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,16) size 784x568
+      RenderBlock {DIV} at (16,0) size 400x54
+        RenderBlock (floating) at (2,3) size 48x81
+          RenderText {#text} at (0,-46) size 48x200
+            text run at (0,-46) width 48: "J"
+        RenderText {#text} at (52,36) size 289x18
+          text run at (52,36) width 289: "ust an example of first-letter. Short paragraph!"
+      RenderBlock {DIV} at (16,70) size 400x158
+        RenderBlock (floating) at (2,17) size 48x81
+          RenderText {#text} at (0,-46) size 48x200
+            text run at (0,-46) width 48: "J"
+        RenderText {#text} at (52,50) size 395x108
+          text run at (52,50) width 337: "ust an example of first-letter. This letter should span 3"
+          text run at (52,68) width 330: "lines of text, and so it should align itself cleanly with"
+          text run at (52,86) width 341: "the cap-height of the J lining up with the cap-height of"
+          text run at (0,104) width 348: "the first line, and the baseline of the J lining up with the"
+          text run at (0,122) width 395: "baseline of the third line. The descender of the J is still avoided"
+          text run at (0,140) width 395: "by following lines. This paragraph cleared the short paragraph."
index d31726e..8693253 100644 (file)
@@ -1,3 +1,21 @@
+2014-09-03  David Hyatt  <hyatt@apple.com>
+
+        Initial letters should clear one another.
+        https://bugs.webkit.org/show_bug.cgi?id=136514
+
+        Reviewed by Simon Fraser.
+
+        Added fast/css-generated-content/initial-letter-clearance.html.
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeLogicalLocationForFloat):
+        Compute the required clearance and add it both to the block's logical height
+        and to the logical top offset of the float.
+
+        (WebCore::RenderBlockFlow::lowestInitialLetterLogicalBottom):
+        * rendering/RenderBlockFlow.h:
+        A new method for determining the lowest floating initial letter.
+
 2014-09-04  Joseph Pecoraro  <pecoraro@apple.com>
 
         Use WTFString::find(char) in more places
index 83bf1ae..07e1832 100644 (file)
@@ -2301,7 +2301,16 @@ LayoutPoint RenderBlockFlow::computeLogicalLocationForFloat(const FloatingObject
     LayoutUnit floatLogicalLeft;
 
     bool insideFlowThread = flowThreadContainingBlock();
-
+    bool isInitialLetter = childBox.style().styleType() == FIRST_LETTER && childBox.style().initialLetterDrop() > 0;
+    
+    if (isInitialLetter) {
+        int letterClearance = lowestInitialLetterLogicalBottom() - logicalTopOffset;
+        if (letterClearance > 0) {
+            logicalTopOffset += letterClearance;
+            setLogicalHeight(logicalHeight() + letterClearance);
+        }
+    }
+    
     if (childBox.style().floating() == LeftFloat) {
         LayoutUnit heightRemainingLeft = 1;
         LayoutUnit heightRemainingRight = 1;
@@ -2337,7 +2346,7 @@ LayoutPoint RenderBlockFlow::computeLogicalLocationForFloat(const FloatingObject
         floatLogicalLeft -= logicalWidthForFloat(floatingObject);
     }
     
-    if (childBox.style().styleType() == FIRST_LETTER && childBox.style().initialLetterDrop() > 0) {
+    if (isInitialLetter) {
         const RenderStyle& style = firstLineStyle();
         const FontMetrics& fontMetrics = style.fontMetrics();
         if (fontMetrics.hasCapHeight()) {
@@ -2559,6 +2568,21 @@ LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatT
     return lowestFloatBottom;
 }
 
+LayoutUnit RenderBlockFlow::lowestInitialLetterLogicalBottom() const
+{
+    if (!m_floatingObjects)
+        return 0;
+    LayoutUnit lowestFloatBottom = 0;
+    const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
+    auto end = floatingObjectSet.end();
+    for (auto it = floatingObjectSet.begin(); it != end; ++it) {
+        FloatingObject* floatingObject = it->get();
+        if (floatingObject->isPlaced() && floatingObject->renderer().style().styleType() == FIRST_LETTER && floatingObject->renderer().style().initialLetterDrop() > 0)
+            lowestFloatBottom = std::max(lowestFloatBottom, logicalBottomForFloat(floatingObject));
+    }
+    return lowestFloatBottom;
+}
+
 LayoutUnit RenderBlockFlow::addOverhangingFloats(RenderBlockFlow& child, bool makeChildPaintOtherFloats)
 {
     // Prevent floats from being added to the canvas by the root element, e.g., <html>.
index b3b1278..3f611f7 100644 (file)
@@ -492,6 +492,8 @@ private:
     LayoutUnit logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const;
     LayoutUnit logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const;
 
+    LayoutUnit lowestInitialLetterLogicalBottom() const;
+    
     LayoutUnit lowestFloatLogicalBottom(FloatingObject::Type = FloatingObject::FloatLeftRight) const; 
     LayoutUnit nextFloatLogicalBottomBelow(LayoutUnit) const;
     LayoutUnit nextFloatLogicalBottomBelowForBlock(LayoutUnit) const;