Title: [161790] trunk/Source/WebCore
Revision
161790
Author
aes...@apple.com
Date
2014-01-11 18:51:25 -0800 (Sat, 11 Jan 2014)

Log Message

[iOS] Move text autosizing code from RenderBlock to RenderBlockFlow
https://bugs.webkit.org/show_bug.cgi?id=126829

Reviewed by Sam Weinig.

Some newly-upstreamed iOS text autosizing code needs to move to
RenderBlockFlow in order to build.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::RenderBlock):
* rendering/RenderBlock.h:
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::RenderBlockFlow):
(WebCore::isVisibleRenderText):
(WebCore::resizeTextPermitted):
(WebCore::RenderBlockFlow::immediateLineCount):
(WebCore::isNonBlocksOrNonFixedHeightListItems):
(WebCore::oneLineTextMultiplier):
(WebCore::textMultiplier):
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
* rendering/RenderBlockFlow.h:
(WebCore::RenderBlockFlow::resetComputedFontSize):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::adjustComputedFontSizesOnBlocks):
(WebCore::RenderObject::resetTextAutosizing):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161789 => 161790)


--- trunk/Source/WebCore/ChangeLog	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/ChangeLog	2014-01-12 02:51:25 UTC (rev 161790)
@@ -1,3 +1,31 @@
+2014-01-11  Andy Estes  <aes...@apple.com>
+
+        [iOS] Move text autosizing code from RenderBlock to RenderBlockFlow
+        https://bugs.webkit.org/show_bug.cgi?id=126829
+
+        Reviewed by Sam Weinig.
+
+        Some newly-upstreamed iOS text autosizing code needs to move to
+        RenderBlockFlow in order to build.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::RenderBlock):
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::RenderBlockFlow):
+        (WebCore::isVisibleRenderText):
+        (WebCore::resizeTextPermitted):
+        (WebCore::RenderBlockFlow::immediateLineCount):
+        (WebCore::isNonBlocksOrNonFixedHeightListItems):
+        (WebCore::oneLineTextMultiplier):
+        (WebCore::textMultiplier):
+        (WebCore::RenderBlockFlow::adjustComputedFontSizes):
+        * rendering/RenderBlockFlow.h:
+        (WebCore::RenderBlockFlow::resetComputedFontSize):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::adjustComputedFontSizesOnBlocks):
+        (WebCore::RenderObject::resetTextAutosizing):
+
 2014-01-11  Daniel Bates  <daba...@apple.com>
 
         [iOS] Fix the build

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (161789 => 161790)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2014-01-12 02:51:25 UTC (rev 161790)
@@ -74,10 +74,6 @@
 #include "ShapeOutsideInfo.h"
 #endif
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-#include "HTMLElement.h"
-#endif
-
 using namespace WTF;
 using namespace Unicode;
 
@@ -181,10 +177,6 @@
     , m_hasMarkupTruncation(false)
     , m_hasBorderOrPaddingLogicalWidthChanged(false)
     , m_lineLayoutPath(UndeterminedPath)
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-    , m_widthForTextAutosizing(-1)
-    , m_lineCountForTextAutosizing(NOT_SET)
-#endif
 {
 }
 
@@ -197,10 +189,6 @@
     , m_hasMarkupTruncation(false)
     , m_hasBorderOrPaddingLogicalWidthChanged(false)
     , m_lineLayoutPath(UndeterminedPath)
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-    , m_widthForTextAutosizing(-1)
-    , m_lineCountForTextAutosizing(NOT_SET)
-#endif
 {
 }
 
@@ -5557,120 +5545,4 @@
 
 #endif
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-inline static bool isVisibleRenderText(RenderObject* renderer)
-{
-    if (!renderer->isText())
-        return false;
-    RenderText* renderText = toRenderText(renderer);
-    return !renderText->linesBoundingBox().isEmpty() && !renderText->text()->containsOnlyWhitespace();
-}
-
-inline static bool resizeTextPermitted(RenderObject* render)
-{
-    // We disallow resizing for text input fields and textarea to address <rdar://problem/5792987> and <rdar://problem/8021123>
-    auto renderer = render->parent();
-    while (renderer) {
-        // Get the first non-shadow HTMLElement and see if it's an input.
-        if (renderer->element() && renderer->element()->isHTMLElement() && !renderer->element()->isInShadowTree()) {
-            const HTMLElement& element = toHTMLElement(*renderer->element());
-            return !isHTMLInputElement(element) && !isHTMLTextAreaElement(element);
-        }
-        renderer = renderer->parent();
-    }
-    return true;
-}
-
-int RenderBlock::immediateLineCount()
-{
-    // Copied and modified from RenderBlock::lineCount.
-    // Only descend into list items.
-    int count = 0;
-    if (style().visibility() == VISIBLE) {
-        if (childrenInline()) {
-            for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox())
-                count++;
-        } else {
-            for (RenderObject* obj = firstChild(); obj; obj = obj->nextSibling()) {
-                if (obj->isListItem())
-                    count += toRenderBlock(obj)->lineCount();
-            }
-        }
-    }
-    return count;
-}
-
-static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render)
-{
-    if (!render->isRenderBlock())
-        return true;
-    if (render->isListItem())
-        return render->style().height().type() != Fixed;
-    return false;
-}
-
-//  For now, we auto size single lines of text the same as multiple lines.
-//  We've been experimenting with low values for single lines of text.
-static inline float oneLineTextMultiplier(float specifiedSize)
-{
-    return std::max((1.0f / log10f(specifiedSize) * 1.7f), 1.0f);
-}
-
-static inline float textMultiplier(float specifiedSize)
-{
-    return std::max((1.0f / log10f(specifiedSize) * 1.95f), 1.0f);
-}
-
-void RenderBlock::adjustComputedFontSizes(float size, float visibleWidth)
-{
-    // Don't do any work if the block is smaller than the visible area.
-    if (visibleWidth >= width())
-        return;
-
-    unsigned lineCount;
-    if (m_lineCountForTextAutosizing == NOT_SET) {
-        int count = immediateLineCount();
-        if (!count)
-            lineCount = NO_LINE;
-        else if (count == 1)
-            lineCount = ONE_LINE;
-        else
-            lineCount = MULTI_LINE;
-    } else
-        lineCount = m_lineCountForTextAutosizing;
-
-    ASSERT(lineCount != NOT_SET);
-    if (lineCount == NO_LINE)
-        return;
-
-    float actualWidth = m_widthForTextAutosizing != -1 ? static_cast<float>(m_widthForTextAutosizing) : static_cast<float>(width());
-    float scale = visibleWidth / actualWidth;
-    float minFontSize = roundf(size / scale);   
-
-    for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
-        if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
-            RenderText* text = toRenderText(descendent);
-            RenderStyle& oldStyle = text->style();
-            FontDescription fontDescription = oldStyle.fontDescription();
-            float specifiedSize = fontDescription.specifiedSize();
-            float scaledSize = roundf(specifiedSize * scale);
-            if (scaledSize > 0 && scaledSize < minFontSize) {
-                // Record the width of the block and the line count the first time we resize text and use it from then on for text resizing.
-                // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915).
-                if (m_lineCountForTextAutosizing == NOT_SET)
-                    m_lineCountForTextAutosizing = lineCount;
-                if (m_widthForTextAutosizing == -1)
-                    m_widthForTextAutosizing = actualWidth;
-
-                float candidateNewSize = 0;
-                float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
-                candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
-                if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text->node() && oldStyle.textSizeAdjust().isAuto())
-                    document().addAutoSizingNode(text->node(), candidateNewSize);
-            }
-        }
-    }
-}
-#endif // ENABLE(IOS_TEXT_AUTOSIZING)
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (161789 => 161790)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2014-01-12 02:51:25 UTC (rev 161790)
@@ -51,12 +51,6 @@
 enum CaretType { CursorCaret, DragCaret };
 enum ContainingBlockState { NewContainingBlock, SameContainingBlock };
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-enum LineCount {
-    NOT_SET = 0, NO_LINE = 1, _ONE_LINE_ = 2, MULTI_LINE = 3
-};
-#endif
-
 enum TextRunFlag {
     DefaultTextRunFlags = 0,
     RespectDirection = 1 << 0,
@@ -354,16 +348,6 @@
     virtual void showLineTreeAndMark(const InlineBox* = nullptr, const char* = nullptr, const InlineBox* = nullptr, const char* = nullptr, const RenderObject* = nullptr) const;
 #endif
 
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-    int immediateLineCount();
-    void adjustComputedFontSizes(float size, float visibleWidth);
-    void resetComputedFontSize()
-    {
-        m_widthForTextAutosizing = -1;
-        m_lineCountForTextAutosizing = NOT_SET;
-    }
-#endif
-
 #if ENABLE(CSS_SHAPES)
     ShapeInsideInfo& ensureShapeInsideInfo();
     ShapeInsideInfo* shapeInsideInfo() const;
@@ -630,11 +614,6 @@
     unsigned m_hasBorderOrPaddingLogicalWidthChanged : 1;
     enum LineLayoutPath { UndeterminedPath, SimpleLinesPath, LineBoxesPath, ForceLineBoxesPath };
     unsigned m_lineLayoutPath : 2;
-
-#if ENABLE(IOS_TEXT_AUTOSIZING)
-    int m_widthForTextAutosizing;
-    unsigned m_lineCountForTextAutosizing : 2;
-#endif
     
     // RenderRubyBase objects need to be able to split and merge, moving their children around
     // (calling moveChildTo, moveAllChildrenTo, and makeChildrenNonInline).

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (161789 => 161790)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2014-01-12 02:51:25 UTC (rev 161790)
@@ -44,6 +44,10 @@
 #include "ShapeInsideInfo.h"
 #endif
 
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+#include "HTMLElement.h"
+#endif
+
 namespace WebCore {
 
 bool RenderBlock::s_canPropagateFloatIntoSibling = false;
@@ -91,12 +95,20 @@
 
 RenderBlockFlow::RenderBlockFlow(Element& element, PassRef<RenderStyle> style)
     : RenderBlock(element, std::move(style), RenderBlockFlowFlag)
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+    , m_widthForTextAutosizing(-1)
+    , m_lineCountForTextAutosizing(NOT_SET)
+#endif
 {
     setChildrenInline(true);
 }
 
 RenderBlockFlow::RenderBlockFlow(Document& document, PassRef<RenderStyle> style)
     : RenderBlock(document, std::move(style), RenderBlockFlowFlag)
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+    , m_widthForTextAutosizing(-1)
+    , m_lineCountForTextAutosizing(NOT_SET)
+#endif
 {
     setChildrenInline(true);
 }
@@ -3260,5 +3272,121 @@
     m_rareBlockFlowData = std::make_unique<RenderBlockFlow::RenderBlockFlowRareData>(*this);
 }
 
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+inline static bool isVisibleRenderText(RenderObject* renderer)
+{
+    if (!renderer->isText())
+        return false;
+    RenderText* renderText = toRenderText(renderer);
+    return !renderText->linesBoundingBox().isEmpty() && !renderText->text()->containsOnlyWhitespace();
 }
+
+inline static bool resizeTextPermitted(RenderObject* render)
+{
+    // We disallow resizing for text input fields and textarea to address <rdar://problem/5792987> and <rdar://problem/8021123>
+    auto renderer = render->parent();
+    while (renderer) {
+        // Get the first non-shadow HTMLElement and see if it's an input.
+        if (renderer->element() && renderer->element()->isHTMLElement() && !renderer->element()->isInShadowTree()) {
+            const HTMLElement& element = toHTMLElement(*renderer->element());
+            return !isHTMLInputElement(element) && !isHTMLTextAreaElement(element);
+        }
+        renderer = renderer->parent();
+    }
+    return true;
+}
+
+int RenderBlockFlow::immediateLineCount()
+{
+    // Copied and modified from RenderBlock::lineCount.
+    // Only descend into list items.
+    int count = 0;
+    if (style().visibility() == VISIBLE) {
+        if (childrenInline()) {
+            for (RootInlineBox* box = firstRootBox(); box; box = box->nextRootBox())
+                count++;
+        } else {
+            for (RenderObject* obj = firstChild(); obj; obj = obj->nextSibling()) {
+                if (obj->isListItem())
+                    count += toRenderBlockFlow(obj)->lineCount();
+            }
+        }
+    }
+    return count;
+}
+
+static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render)
+{
+    if (!render->isRenderBlock())
+        return true;
+    if (render->isListItem())
+        return render->style().height().type() != Fixed;
+    return false;
+}
+
+//  For now, we auto size single lines of text the same as multiple lines.
+//  We've been experimenting with low values for single lines of text.
+static inline float oneLineTextMultiplier(float specifiedSize)
+{
+    return std::max((1.0f / log10f(specifiedSize) * 1.7f), 1.0f);
+}
+
+static inline float textMultiplier(float specifiedSize)
+{
+    return std::max((1.0f / log10f(specifiedSize) * 1.95f), 1.0f);
+}
+
+void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
+{
+    // Don't do any work if the block is smaller than the visible area.
+    if (visibleWidth >= width())
+        return;
+    
+    unsigned lineCount;
+    if (m_lineCountForTextAutosizing == NOT_SET) {
+        int count = immediateLineCount();
+        if (!count)
+            lineCount = NO_LINE;
+        else if (count == 1)
+            lineCount = ONE_LINE;
+        else
+            lineCount = MULTI_LINE;
+    } else
+        lineCount = m_lineCountForTextAutosizing;
+    
+    ASSERT(lineCount != NOT_SET);
+    if (lineCount == NO_LINE)
+        return;
+    
+    float actualWidth = m_widthForTextAutosizing != -1 ? static_cast<float>(m_widthForTextAutosizing) : static_cast<float>(width());
+    float scale = visibleWidth / actualWidth;
+    float minFontSize = roundf(size / scale);
+    
+    for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
+        if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
+            RenderText* text = toRenderText(descendent);
+            RenderStyle& oldStyle = text->style();
+            FontDescription fontDescription = oldStyle.fontDescription();
+            float specifiedSize = fontDescription.specifiedSize();
+            float scaledSize = roundf(specifiedSize * scale);
+            if (scaledSize > 0 && scaledSize < minFontSize) {
+                // Record the width of the block and the line count the first time we resize text and use it from then on for text resizing.
+                // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915).
+                if (m_lineCountForTextAutosizing == NOT_SET)
+                    m_lineCountForTextAutosizing = lineCount;
+                if (m_widthForTextAutosizing == -1)
+                    m_widthForTextAutosizing = actualWidth;
+                
+                float candidateNewSize = 0;
+                float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
+                candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
+                if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text->textNode() && oldStyle.textSizeAdjust().isAuto())
+                    document().addAutoSizingNode(text->textNode(), candidateNewSize);
+            }
+        }
+    }
+}
+#endif // ENABLE(IOS_TEXT_AUTOSIZING)
+
+}
 // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.h (161789 => 161790)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.h	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.h	2014-01-12 02:51:25 UTC (rev 161790)
@@ -44,6 +44,12 @@
 template <class Run> class BidiRunList;
 typedef Vector<WordMeasurement, 64> WordMeasurements;
 
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+enum LineCount {
+    NOT_SET = 0, NO_LINE = 1, _ONE_LINE_ = 2, MULTI_LINE = 3
+};
+#endif
+
 class RenderBlockFlow : public RenderBlock {
 public:
     RenderBlockFlow(Element&, PassRef<RenderStyle>);
@@ -526,6 +532,11 @@
     bool namedFlowFragmentNeedsUpdate() const;
     virtual bool canHaveChildren() const OVERRIDE;
 
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+    int m_widthForTextAutosizing;
+    unsigned m_lineCountForTextAutosizing : 2;
+#endif
+
 public:
     // FIXME-BLOCKFLOW: These can be made protected again once all callers have been moved here.
     void adjustLinePositionForPagination(RootInlineBox*, LayoutUnit& deltaOffset, RenderFlowThread*); // Computes a deltaOffset value that put a line at the top of the next page if it doesn't fit on the current page.
@@ -540,6 +551,16 @@
     RenderBlockFlowRareData& ensureRareBlockFlowData();
     void materializeRareBlockFlowData();
 
+#if ENABLE(IOS_TEXT_AUTOSIZING)
+    int immediateLineCount();
+    void adjustComputedFontSizes(float size, float visibleWidth);
+    void resetComputedFontSize()
+    {
+        m_widthForTextAutosizing = -1;
+        m_lineCountForTextAutosizing = NOT_SET;
+    }
+#endif
+
 protected:
     OwnPtr<FloatingObjects> m_floatingObjects;
     std::unique_ptr<RenderBlockFlowRareData> m_rareBlockFlowData;

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (161789 => 161790)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2014-01-12 02:51:19 UTC (rev 161789)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2014-01-12 02:51:25 UTC (rev 161790)
@@ -435,8 +435,8 @@
             depthStack.append(newFixedDepth);
 
         int stackSize = depthStack.size();
-        if (descendent->isRenderBlock() && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
-            static_cast<RenderBlock*>(descendent)->adjustComputedFontSizes(size, visibleWidth);
+        if (descendent->isRenderBlockFlow() && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
+            toRenderBlockFlow(descendent)->adjustComputedFontSizes(size, visibleWidth);
         newFixedDepth = 0;
     }
 
@@ -463,8 +463,8 @@
             depthStack.append(newFixedDepth);
 
         int stackSize = depthStack.size();
-        if (descendent->isRenderBlock() && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
-            toRenderBlock(descendent)->resetComputedFontSize();
+        if (descendent->isRenderBlockFlow() && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))
+            toRenderBlockFlow(descendent)->resetComputedFontSize();
         newFixedDepth = 0;
     }
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to