Font::primaryFontData() should return a reference
[WebKit-https.git] / Source / WebCore / rendering / InlineFlowBox.cpp
index 812dd0d..8417b51 100644 (file)
@@ -157,11 +157,11 @@ void InlineFlowBox::addToLine(InlineBox* child)
             if (childStyle->letterSpacing() < 0 || childStyle->textShadow() || childStyle->textEmphasisMark() != TextEmphasisMarkNone || childStyle->textStrokeWidth())
                 child->clearKnownToHaveNoOverflow();
         } else if (child->renderer().isReplaced()) {
-            const RenderBox& box = toRenderBox(child->renderer());
+            const RenderBox& box = downcast<RenderBox>(child->renderer());
             if (box.hasRenderOverflow() || box.hasSelfPaintingLayer())
                 child->clearKnownToHaveNoOverflow();
         } else if (!child->renderer().isLineBreak() && (childStyle.boxShadow() || child->boxModelObject()->hasSelfPaintingLayer()
-            || (child->renderer().isListMarker() && !toRenderListMarker(child->renderer()).isInside())
+            || (is<RenderListMarker>(child->renderer()) && !downcast<RenderListMarker>(child->renderer()).isInside())
             || childStyle.hasBorderImageOutsets()))
             child->clearKnownToHaveNoOverflow();
         
@@ -179,6 +179,14 @@ void InlineFlowBox::removeChild(InlineBox* child)
     if (!isDirty())
         dirtyLineBoxes();
 
+    if (child->prevLeafChild() && is<InlineTextBox>(child->prevLeafChild())) {
+        if (is<InlineTextBox>(child))
+            downcast<InlineTextBox>(child->prevLeafChild())->renderer().setContentIsKnownToFollow(downcast<InlineTextBox>(child)->renderer().contentIsKnownToFollow());
+        // FIXME: Handle the case where we remove the last inline box, and it's not a text box. If we're trying to share
+        // expansion opportunites both inside and outside a replaced element (such as for ruby bases), we need to search
+        // outside the current inline box tree to determine if there is content that follows the new last inline item.
+    }
+
     root().childRemoved(child);
 
     if (child == m_firstChild)
@@ -373,6 +381,7 @@ float InlineFlowBox::placeBoxesInInlineDirection(float logicalLeft, bool& needsW
 
 float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, InlineBox* lastChild, float& logicalLeft, float& minLogicalLeft, float& maxLogicalRight, bool& needsWordSpacing)
 {
+    float totalExpansion = 0;
     for (InlineBox* child = firstChild; child && child != lastChild; child = child->nextOnLine()) {
         if (is<RenderText>(child->renderer())) {
             auto& textBox = downcast<InlineTextBox>(*child);
@@ -386,6 +395,7 @@ float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, Inlin
             if (knownToHaveNoOverflow())
                 minLogicalLeft = std::min(logicalLeft, minLogicalLeft);
             logicalLeft += textBox.logicalWidth();
+            totalExpansion += textBox.expansion();
             if (knownToHaveNoOverflow())
                 maxLogicalRight = std::max(logicalLeft, maxLogicalRight);
         } else {
@@ -405,10 +415,11 @@ float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, Inlin
                 if (knownToHaveNoOverflow())
                     minLogicalLeft = std::min(logicalLeft, minLogicalLeft);
                 logicalLeft = flow.placeBoxesInInlineDirection(logicalLeft, needsWordSpacing);
+                totalExpansion += flow.expansion();
                 if (knownToHaveNoOverflow())
                     maxLogicalRight = std::max(logicalLeft, maxLogicalRight);
                 logicalLeft += flow.marginLogicalRight();
-            } else if (!child->renderer().isListMarker() || toRenderListMarker(child->renderer()).isInside()) {
+            } else if (!is<RenderListMarker>(child->renderer()) || downcast<RenderListMarker>(child->renderer()).isInside()) {
                 // The box can have a different writing-mode than the overall line, so this is a bit complicated.
                 // Just get all the physical margin and overflow values by hand based off |isVertical|.
                 LayoutUnit logicalLeftMargin = isHorizontal() ? child->boxModelObject()->marginLeft() : child->boxModelObject()->marginTop();
@@ -427,6 +438,7 @@ float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, Inlin
             }
         }
     }
+    setExpansionWithoutGrowing(totalExpansion);
     return logicalLeft;
 }
 
@@ -437,7 +449,7 @@ bool InlineFlowBox::requiresIdeographicBaseline(const GlyphOverflowAndFallbackFo
 
     const RenderStyle& lineStyle = this->lineStyle();
     if (lineStyle.fontDescription().nonCJKGlyphOrientation() == NonCJKGlyphOrientationUpright
-        || lineStyle.font().primaryFont()->hasVerticalGlyphs())
+        || lineStyle.font().primaryFontData().hasVerticalGlyphs())
         return true;
 
     for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
@@ -448,7 +460,7 @@ bool InlineFlowBox::requiresIdeographicBaseline(const GlyphOverflowAndFallbackFo
             if (downcast<InlineFlowBox>(*child).requiresIdeographicBaseline(textBoxDataMap))
                 return true;
         } else {
-            if (child->lineStyle().font().primaryFont()->hasVerticalGlyphs())
+            if (child->lineStyle().font().primaryFontData().hasVerticalGlyphs())
                 return true;
             
             const Vector<const SimpleFontData*>* usedFonts = nullptr;
@@ -899,7 +911,7 @@ inline void InlineFlowBox::addTextBoxVisualOverflow(InlineTextBox& textBox, Glyp
 
 inline void InlineFlowBox::addReplacedChildOverflow(const InlineBox* inlineBox, LayoutRect& logicalLayoutOverflow, LayoutRect& logicalVisualOverflow)
 {
-    const RenderBox& box = toRenderBox(inlineBox->renderer());
+    const RenderBox& box = downcast<RenderBox>(inlineBox->renderer());
     
     // Visual overflow only propagates if the box doesn't have a self-painting layer.  This rectangle does not include
     // transforms or relative positioning (since those objects always have self-painting layers), but it does need to be adjusted
@@ -1636,6 +1648,20 @@ void InlineFlowBox::collectLeafBoxesInLogicalOrder(Vector<InlineBox*>& leafBoxes
     }
 }
 
+void InlineFlowBox::computeReplacedAndTextLineTopAndBottom(LayoutUnit& lineTop, LayoutUnit& lineBottom) const
+{
+    for (const auto* box = firstChild(); box; box = box->nextOnLine()) {
+        if (is<InlineFlowBox>(*box))
+            downcast<InlineFlowBox>(*box).computeReplacedAndTextLineTopAndBottom(lineTop, lineBottom);
+        else {
+            if (box->logicalTop() < lineTop)
+                lineTop = box->logicalTop();
+            if (box->logicalBottom() > lineBottom)
+                lineBottom = box->logicalBottom();
+        }
+    }
+}
+
 #ifndef NDEBUG
 
 const char* InlineFlowBox::boxName() const