Simple line layout should not be limited to RenderText.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 23:30:35 +0000 (23:30 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Mar 2015 23:30:35 +0000 (23:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142504

Reviewed by Antti Koivisto.

This is in transition to support br element.

No change in functionality.

* rendering/RenderText.cpp:
(WebCore::RenderText::absoluteRects):
(WebCore::RenderText::absoluteQuadsClippedToEllipsis):
(WebCore::RenderText::absoluteQuads):
(WebCore::RenderText::firstRunLocation):
(WebCore::RenderText::linesBoundingBox):
(WebCore::RenderText::caretMinOffset):
(WebCore::RenderText::caretMaxOffset):
(WebCore::RenderText::containsCaretOffset):
* rendering/SimpleLineLayoutFlowContents.cpp:
(WebCore::SimpleLineLayout::FlowContents::segmentForRenderer):
* rendering/SimpleLineLayoutFlowContents.h:
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::computeBoundingBox):
(WebCore::SimpleLineLayout::computeFirstRunLocation):
(WebCore::SimpleLineLayout::collectAbsoluteRects):
(WebCore::SimpleLineLayout::collectAbsoluteQuads):
(WebCore::SimpleLineLayout::computeTextBoundingBox): Deleted.
(WebCore::SimpleLineLayout::computeTextFirstRunLocation): Deleted.
(WebCore::SimpleLineLayout::collectTextAbsoluteRects): Deleted.
(WebCore::SimpleLineLayout::collectTextAbsoluteQuads): Deleted.
* rendering/SimpleLineLayoutFunctions.h:
(WebCore::SimpleLineLayout::findCaretMinimumOffset):
(WebCore::SimpleLineLayout::findCaretMaximumOffset):
(WebCore::SimpleLineLayout::containsCaretOffset):
(WebCore::SimpleLineLayout::findTextCaretMinimumOffset): Deleted.
(WebCore::SimpleLineLayout::findTextCaretMaximumOffset): Deleted.
(WebCore::SimpleLineLayout::containsTextCaretOffset): Deleted.
* rendering/SimpleLineLayoutResolver.cpp:
(WebCore::SimpleLineLayout::RunResolver::Run::text):
(WebCore::SimpleLineLayout::RunResolver::rangeForRenderer):
* rendering/SimpleLineLayoutResolver.h:
* rendering/SimpleLineLayoutTextFragmentIterator.cpp:
(WebCore::SimpleLineLayout::TextFragmentIterator::textWidth):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp
Source/WebCore/rendering/SimpleLineLayoutFlowContents.h
Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp
Source/WebCore/rendering/SimpleLineLayoutFunctions.h
Source/WebCore/rendering/SimpleLineLayoutResolver.cpp
Source/WebCore/rendering/SimpleLineLayoutResolver.h
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp

index 9efd2fb..02bda83 100644 (file)
@@ -1,3 +1,49 @@
+2015-03-09  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout should not be limited to RenderText.
+        https://bugs.webkit.org/show_bug.cgi?id=142504
+
+        Reviewed by Antti Koivisto.
+
+        This is in transition to support br element.
+
+        No change in functionality.
+
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::absoluteRects):
+        (WebCore::RenderText::absoluteQuadsClippedToEllipsis):
+        (WebCore::RenderText::absoluteQuads):
+        (WebCore::RenderText::firstRunLocation):
+        (WebCore::RenderText::linesBoundingBox):
+        (WebCore::RenderText::caretMinOffset):
+        (WebCore::RenderText::caretMaxOffset):
+        (WebCore::RenderText::containsCaretOffset):
+        * rendering/SimpleLineLayoutFlowContents.cpp:
+        (WebCore::SimpleLineLayout::FlowContents::segmentForRenderer):
+        * rendering/SimpleLineLayoutFlowContents.h:
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::computeBoundingBox):
+        (WebCore::SimpleLineLayout::computeFirstRunLocation):
+        (WebCore::SimpleLineLayout::collectAbsoluteRects):
+        (WebCore::SimpleLineLayout::collectAbsoluteQuads):
+        (WebCore::SimpleLineLayout::computeTextBoundingBox): Deleted.
+        (WebCore::SimpleLineLayout::computeTextFirstRunLocation): Deleted.
+        (WebCore::SimpleLineLayout::collectTextAbsoluteRects): Deleted.
+        (WebCore::SimpleLineLayout::collectTextAbsoluteQuads): Deleted.
+        * rendering/SimpleLineLayoutFunctions.h:
+        (WebCore::SimpleLineLayout::findCaretMinimumOffset):
+        (WebCore::SimpleLineLayout::findCaretMaximumOffset):
+        (WebCore::SimpleLineLayout::containsCaretOffset):
+        (WebCore::SimpleLineLayout::findTextCaretMinimumOffset): Deleted.
+        (WebCore::SimpleLineLayout::findTextCaretMaximumOffset): Deleted.
+        (WebCore::SimpleLineLayout::containsTextCaretOffset): Deleted.
+        * rendering/SimpleLineLayoutResolver.cpp:
+        (WebCore::SimpleLineLayout::RunResolver::Run::text):
+        (WebCore::SimpleLineLayout::RunResolver::rangeForRenderer):
+        * rendering/SimpleLineLayoutResolver.h:
+        * rendering/SimpleLineLayoutTextFragmentIterator.cpp:
+        (WebCore::SimpleLineLayout::TextFragmentIterator::textWidth):
+
 2015-03-09  Myles C. Maxfield  <mmaxfield@apple.com>
 
         svg/custom/svg-fonts-without-missing-glyph.xhtml fails after fonts/font-fallback-prefers-pictographs.html
index 15d014d..16fbc09 100644 (file)
@@ -300,7 +300,7 @@ String RenderText::originalText() const
 void RenderText::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
 {
     if (auto layout = simpleLineLayout()) {
-        rects.appendVector(collectTextAbsoluteRects(*this, *layout, accumulatedOffset));
+        rects.appendVector(SimpleLineLayout::collectAbsoluteRects(*this, *layout, accumulatedOffset));
         return;
     }
     rects.appendVector(m_lineBoxes.absoluteRects(accumulatedOffset));
@@ -404,7 +404,7 @@ Vector<FloatQuad> RenderText::absoluteQuadsClippedToEllipsis() const
 {
     if (auto layout = simpleLineLayout()) {
         ASSERT(style().textOverflow() != TextOverflowEllipsis);
-        return collectTextAbsoluteQuads(*this, *layout, nullptr);
+        return SimpleLineLayout::collectAbsoluteQuads(*this, *layout, nullptr);
     }
     return m_lineBoxes.absoluteQuads(*this, nullptr, RenderTextLineBoxes::ClipToEllipsis);
 }
@@ -412,7 +412,7 @@ Vector<FloatQuad> RenderText::absoluteQuadsClippedToEllipsis() const
 void RenderText::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
 {
     if (auto layout = simpleLineLayout()) {
-        quads.appendVector(collectTextAbsoluteQuads(*this, *layout, wasFixed));
+        quads.appendVector(SimpleLineLayout::collectAbsoluteQuads(*this, *layout, wasFixed));
         return;
     }
     quads.appendVector(m_lineBoxes.absoluteQuads(*this, wasFixed, RenderTextLineBoxes::NoClipping));
@@ -961,7 +961,7 @@ bool RenderText::containsOnlyWhitespace(unsigned from, unsigned len) const
 IntPoint RenderText::firstRunLocation() const
 {
     if (auto* layout = simpleLineLayout())
-        return SimpleLineLayout::computeTextFirstRunLocation(*this, *layout);
+        return SimpleLineLayout::computeFirstRunLocation(*this, *layout);
 
     return m_lineBoxes.firstRunLocation();
 }
@@ -1258,7 +1258,7 @@ float RenderText::width(unsigned from, unsigned len, const FontCascade& f, float
 IntRect RenderText::linesBoundingBox() const
 {
     if (auto layout = simpleLineLayout())
-        return SimpleLineLayout::computeTextBoundingBox(*this, *layout);
+        return SimpleLineLayout::computeBoundingBox(*this, *layout);
 
     return m_lineBoxes.boundingBox(*this);
 }
@@ -1346,14 +1346,14 @@ LayoutRect RenderText::selectionRectForRepaint(const RenderLayerModelObject* rep
 int RenderText::caretMinOffset() const
 {
     if (auto layout = simpleLineLayout())
-        return SimpleLineLayout::findTextCaretMinimumOffset(*this, *layout);
+        return SimpleLineLayout::findCaretMinimumOffset(*this, *layout);
     return m_lineBoxes.caretMinOffset();
 }
 
 int RenderText::caretMaxOffset() const
 {
     if (auto layout = simpleLineLayout())
-        return SimpleLineLayout::findTextCaretMaximumOffset(*this, *layout);
+        return SimpleLineLayout::findCaretMaximumOffset(*this, *layout);
     return m_lineBoxes.caretMaxOffset(*this);
 }
 
@@ -1372,7 +1372,7 @@ bool RenderText::containsRenderedCharacterOffset(unsigned offset) const
 bool RenderText::containsCaretOffset(unsigned offset) const
 {
     if (auto layout = simpleLineLayout())
-        return SimpleLineLayout::containsTextCaretOffset(*this, *layout, offset);
+        return SimpleLineLayout::containsCaretOffset(*this, *layout, offset);
     return m_lineBoxes.containsOffset(*this, offset, RenderTextLineBoxes::CaretOffset);
 }
 
index 2209797..123de83 100644 (file)
@@ -62,7 +62,7 @@ unsigned FlowContents::segmentIndexForPositionSlow(unsigned position) const
     return index;
 }
 
-const FlowContents::Segment& FlowContents::segmentForRenderer(const RenderText& renderer) const
+const FlowContents::Segment& FlowContents::segmentForRenderer(const RenderObject& renderer) const
 {
     for (auto& segment : m_segments) {
         if (&segment.renderer == &renderer)
index 4575bd6..1fc3479 100644 (file)
@@ -41,10 +41,10 @@ public:
         unsigned start;
         unsigned end;
         String text;
-        const RenderText& renderer;
+        const RenderObject& renderer;
     };
     const Segment& segmentForPosition(unsigned) const;
-    const Segment& segmentForRenderer(const RenderText&) const;
+    const Segment& segmentForRenderer(const RenderObject&) const;
 
     class Iterator {
     public:
index 9f1dded..63fa8bf 100644 (file)
@@ -134,11 +134,11 @@ void collectFlowOverflow(RenderBlockFlow& flow, const Layout& layout)
     }
 }
 
-IntRect computeTextBoundingBox(const RenderText& textRenderer, const Layout& layout)
+IntRect computeBoundingBox(const RenderObject& renderer, const Layout& layout)
 {
-    auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
+    auto resolver = runResolver(downcast<RenderBlockFlow>(*renderer.parent()), layout);
     FloatRect boundingBoxRect;
-    for (const auto& run : resolver.rangeForRenderer(textRenderer)) {
+    for (const auto& run : resolver.rangeForRenderer(renderer)) {
         FloatRect rect = run.rect();
         if (boundingBoxRect == FloatRect())
             boundingBoxRect = rect;
@@ -148,10 +148,10 @@ IntRect computeTextBoundingBox(const RenderText& textRenderer, const Layout& lay
     return enclosingIntRect(boundingBoxRect);
 }
 
-IntPoint computeTextFirstRunLocation(const RenderText& textRenderer, const Layout& layout)
+IntPoint computeFirstRunLocation(const RenderObject& renderer, const Layout& layout)
 {
-    auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
-    const auto& it = resolver.rangeForRenderer(textRenderer);
+    auto resolver = runResolver(downcast<RenderBlockFlow>(*renderer.parent()), layout);
+    const auto& it = resolver.rangeForRenderer(renderer);
     auto begin = it.begin();
     if (begin == it.end())
         return IntPoint(0, 0);
@@ -159,23 +159,23 @@ IntPoint computeTextFirstRunLocation(const RenderText& textRenderer, const Layou
     return flooredIntPoint((*begin).rect().location());
 }
 
-Vector<IntRect> collectTextAbsoluteRects(const RenderText& textRenderer, const Layout& layout, const LayoutPoint& accumulatedOffset)
+Vector<IntRect> collectAbsoluteRects(const RenderObject& renderer, const Layout& layout, const LayoutPoint& accumulatedOffset)
 {
     Vector<IntRect> rects;
-    auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
-    for (const auto& run : resolver.rangeForRenderer(textRenderer)) {
+    auto resolver = runResolver(downcast<RenderBlockFlow>(*renderer.parent()), layout);
+    for (const auto& run : resolver.rangeForRenderer(renderer)) {
         LayoutRect rect = run.rect();
         rects.append(enclosingIntRect(FloatRect(accumulatedOffset + rect.location(), rect.size())));
     }
     return rects;
 }
 
-Vector<FloatQuad> collectTextAbsoluteQuads(const RenderText& textRenderer, const Layout& layout, bool* wasFixed)
+Vector<FloatQuad> collectAbsoluteQuads(const RenderObject& renderer, const Layout& layout, bool* wasFixed)
 {
     Vector<FloatQuad> quads;
-    auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
-    for (const auto& run : resolver.rangeForRenderer(textRenderer))
-        quads.append(textRenderer.localToAbsoluteQuad(FloatQuad(run.rect()), 0, wasFixed));
+    auto resolver = runResolver(downcast<RenderBlockFlow>(*renderer.parent()), layout);
+    for (const auto& run : resolver.rangeForRenderer(renderer))
+        quads.append(renderer.localToAbsoluteQuad(FloatQuad(run.rect()), 0, wasFixed));
     return quads;
 }
 
index ef389c6..842bc76 100644 (file)
@@ -37,7 +37,6 @@ class HitTestLocation;
 class HitTestRequest;
 class HitTestResult;
 class RenderBlockFlow;
-class RenderText;
 struct PaintInfo;
 
 namespace SimpleLineLayout {
@@ -51,14 +50,14 @@ bool hitTestFlow(const RenderBlockFlow&, const Layout&, const HitTestRequest&, H
 void collectFlowOverflow(RenderBlockFlow&, const Layout&);
 
 bool isTextRendered(const RenderText&, const Layout&);
-bool containsTextCaretOffset(const RenderText&, const Layout&, unsigned);
-unsigned findTextCaretMinimumOffset(const RenderText&, const Layout&);
-unsigned findTextCaretMaximumOffset(const RenderText&, const Layout&);
-IntRect computeTextBoundingBox(const RenderText&, const Layout&);
-IntPoint computeTextFirstRunLocation(const RenderText&, const Layout&);
+bool containsCaretOffset(const RenderObject&, const Layout&, unsigned);
+unsigned findCaretMinimumOffset(const RenderObject&, const Layout&);
+unsigned findCaretMaximumOffset(const RenderObject&, const Layout&);
+IntRect computeBoundingBox(const RenderObject&, const Layout&);
+IntPoint computeFirstRunLocation(const RenderObject&, const Layout&);
 
-Vector<IntRect> collectTextAbsoluteRects(const RenderText&, const Layout&, const LayoutPoint& accumulatedOffset);
-Vector<FloatQuad> collectTextAbsoluteQuads(const RenderText&, const Layout&, bool* wasFixed);
+Vector<IntRect> collectAbsoluteRects(const RenderObject&, const Layout&, const LayoutPoint& accumulatedOffset);
+Vector<FloatQuad> collectAbsoluteQuads(const RenderObject&, const Layout&, bool* wasFixed);
 
 LayoutUnit lineHeightFromFlow(const RenderBlockFlow&);
 LayoutUnit baselineFromFlow(const RenderBlockFlow&);
@@ -88,14 +87,14 @@ inline LayoutUnit computeFlowLastLineBaseline(const RenderBlockFlow& flow, const
     return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.lineCount() - 1) + baselineFromFlow(flow);
 }
 
-inline unsigned findTextCaretMinimumOffset(const RenderText&, const Layout& layout)
+inline unsigned findCaretMinimumOffset(const RenderText&, const Layout& layout)
 {
     if (!layout.runCount())
         return 0;
     return layout.runAt(0).start;
 }
 
-inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
+inline unsigned findCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
 {
     if (!layout.runCount())
         return renderer.textLength();
@@ -103,7 +102,7 @@ inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Lay
     return last.end;
 }
 
-inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
+inline bool containsCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
 {
     for (unsigned i = 0; i < layout.runCount(); ++i) {
         auto& run = layout.runAt(i);
index 6b070d6..e8d25b6 100644 (file)
@@ -27,7 +27,7 @@
 #include "SimpleLineLayoutResolver.h"
 
 #include "RenderBlockFlow.h"
-#include "RenderText.h"
+#include "RenderObject.h"
 #include "SimpleLineLayoutFunctions.h"
 
 namespace WebCore {
@@ -77,7 +77,7 @@ StringView RunResolver::Run::text() const
     auto& resolver = m_iterator.resolver();
     auto& run = m_iterator.simpleRun();
     auto& segment = resolver.m_flowContents.segmentForPosition(run.start);
-    // We currently split runs on segment boundaries (different RenderText).
+    // We currently split runs on segment boundaries (different RenderObject).
     ASSERT(run.end <= segment.end);
     if (segment.text.is8Bit())
         return StringView(segment.text.characters8(), segment.text.length()).substring(run.start - segment.start, run.end - run.start);
@@ -155,7 +155,7 @@ Range<RunResolver::Iterator> RunResolver::rangeForRect(const LayoutRect& rect) c
     return Range<Iterator>(rangeBegin, rangeEnd);
 }
 
-Range<RunResolver::Iterator> RunResolver::rangeForRenderer(const RenderText& renderer) const
+Range<RunResolver::Iterator> RunResolver::rangeForRenderer(const RenderObject& renderer) const
 {
     auto& segment = m_flowContents.segmentForRenderer(renderer);
 
index 7f1787e..0359901 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "LayoutRect.h"
 #include "RenderBlockFlow.h"
-#include "RenderText.h"
 #include "SimpleLineLayoutFlowContents.h"
 #include "SimpleLineLayoutFunctions.h"
 #include <wtf/Vector.h>
@@ -101,7 +100,7 @@ public:
     Iterator end() const;
 
     Range<Iterator> rangeForRect(const LayoutRect&) const;
-    Range<Iterator> rangeForRenderer(const RenderText&) const;
+    Range<Iterator> rangeForRenderer(const RenderObject&) const;
 
 private:
     enum class IndexType { First, Last };
index 9e5f664..b255f5e 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "RenderBlockFlow.h"
 #include "RenderChildIterator.h"
-#include "RenderText.h"
 #include "SimpleLineLayoutFlowContents.h"
 
 namespace WebCore {
@@ -94,8 +93,9 @@ TextFragmentIterator::TextFragment TextFragmentIterator::nextTextFragment(float
 float TextFragmentIterator::textWidth(unsigned from, unsigned to, float xPosition) const
 {
     const auto& fromSegment = m_flowContents.segmentForPosition(from);
+    ASSERT(is<RenderText>(fromSegment.renderer));
     if ((m_style.font.isFixedPitch() && fromSegment.end >= to) || (from == fromSegment.start && to == fromSegment.end))
-        return fromSegment.renderer.width(from - fromSegment.start, to - from, m_style.font, xPosition, nullptr, nullptr);
+        return downcast<RenderText>(fromSegment.renderer).width(from - fromSegment.start, to - from, m_style.font, xPosition, nullptr, nullptr);
 
     const auto* segment = &fromSegment;
     float textWidth = 0;