Diff
Modified: trunk/Source/WebCore/ChangeLog (176316 => 176317)
--- trunk/Source/WebCore/ChangeLog 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/ChangeLog 2014-11-19 15:40:35 UTC (rev 176317)
@@ -1,3 +1,38 @@
+2014-11-19 Zalan Bujtas <[email protected]>
+
+ Simple line layout: Add renderer based rect collecting to RunResolver.
+ https://bugs.webkit.org/show_bug.cgi?id=138818
+
+ Reviewed by Antti Koivisto.
+
+ This is in preparation to multiple renderers support.
+ RunResolver should be able to collect rects for a particular renderer
+ that might overlap multiple runs. (or might just be a subset of a Run)
+
+ Covered by existing tests.
+
+ * rendering/SimpleLineLayoutFlowContents.cpp:
+ (WebCore::SimpleLineLayout::FlowContents::renderer): It operates on a single renderer currently.
+ (WebCore::SimpleLineLayout::FlowContents::resolveRendererPositions): It operates on a single renderer currently.
+ * rendering/SimpleLineLayoutFlowContents.h:
+ * rendering/SimpleLineLayoutFunctions.cpp:
+ (WebCore::SimpleLineLayout::computeTextBoundingBox):
+ (WebCore::SimpleLineLayout::computeTextFirstRunLocation):
+ (WebCore::SimpleLineLayout::collectTextAbsoluteRects):
+ (WebCore::SimpleLineLayout::collectTextAbsoluteQuads):
+ (WebCore::SimpleLineLayout::showLineLayoutForFlow):
+ * rendering/SimpleLineLayoutResolver.cpp:
+ (WebCore::SimpleLineLayout::baselinePosition):
+ (WebCore::SimpleLineLayout::linePosition):
+ (WebCore::SimpleLineLayout::lineSize):
+ (WebCore::SimpleLineLayout::RunResolver::Run::rect):
+ (WebCore::SimpleLineLayout::RunResolver::Run::rectForTextRenderer):
+ (WebCore::SimpleLineLayout::RunResolver::Run::baseline):
+ (WebCore::SimpleLineLayout::RunResolver::Run::text):
+ (WebCore::SimpleLineLayout::RunResolver::Run::computeRect):
+ (WebCore::SimpleLineLayout::RunResolver::RunResolver):
+ * rendering/SimpleLineLayoutResolver.h:
+
2014-11-19 Dhi Aurrahman <[email protected]>
Add selector checker for :lang pseudo class in Selectors level 4
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp (176316 => 176317)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp 2014-11-19 15:40:35 UTC (rev 176317)
@@ -77,5 +77,18 @@
return m_style.font.width(run);
}
+bool FlowContents::resolveRendererPositions(const RenderText& renderer, unsigned& startPosition, unsigned& endPosition) const
+{
+ ASSERT(&renderer == downcast<RenderText>(m_flow.firstChild()));
+ startPosition = 0;
+ endPosition = renderer.text()->length();
+ return true;
}
+
+const RenderText& FlowContents::renderer(unsigned) const
+{
+ return downcast<RenderText>(*m_flow.firstChild());
}
+
+}
+}
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h (176316 => 176317)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h 2014-11-19 15:40:35 UTC (rev 176317)
@@ -48,6 +48,9 @@
bool isNewlineCharacter(unsigned position) const;
bool isEndOfContent(unsigned position) const;
+ bool resolveRendererPositions(const RenderText&, unsigned& startPosition, unsigned& endPosition) const;
+ const RenderText& renderer(unsigned position) const;
+
class Style {
public:
Style(const RenderStyle& style)
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp (176316 => 176317)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp 2014-11-19 15:40:35 UTC (rev 176317)
@@ -136,37 +136,26 @@
IntRect computeTextBoundingBox(const RenderText& textRenderer, const Layout& layout)
{
- auto resolver = lineResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
- auto it = resolver.begin();
- auto end = resolver.end();
- if (it == end)
- return IntRect();
- auto firstLineRect = *it;
- float left = firstLineRect.x();
- float right = firstLineRect.maxX();
- float bottom = firstLineRect.maxY();
- for (++it; it != end; ++it) {
- auto rect = *it;
- if (rect.x() < left)
- left = rect.x();
- if (rect.maxX() > right)
- right = rect.maxX();
- if (rect.maxY() > bottom)
- bottom = rect.maxY();
+ auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
+ FloatRect boundingBoxRect;
+ for (const auto& run : resolver.rangeForRenderer(textRenderer)) {
+ FloatRect rect = run.rect();
+ if (boundingBoxRect == FloatRect())
+ boundingBoxRect = rect;
+ else
+ boundingBoxRect.uniteEvenIfEmpty(rect);
}
- float x = left;
- float y = firstLineRect.y();
- float width = right - left;
- float height = bottom - y;
- return enclosingIntRect(FloatRect(x, y, width, height));
+ return enclosingIntRect(boundingBoxRect);
}
IntPoint computeTextFirstRunLocation(const RenderText& textRenderer, const Layout& layout)
{
auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
- auto begin = resolver.begin();
- if (begin == resolver.end())
- return IntPoint();
+ const auto& it = resolver.rangeForRenderer(textRenderer);
+ auto begin = it.begin();
+ if (begin == it.end())
+ return IntPoint(0, 0);
+
return flooredIntPoint((*begin).rect().location());
}
@@ -174,9 +163,8 @@
{
Vector<IntRect> rects;
auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
- for (auto it = resolver.begin(), end = resolver.end(); it != end; ++it) {
- const auto& run = *it;
- auto rect = run.rect();
+ for (const auto& run : resolver.rangeForRenderer(textRenderer)) {
+ LayoutRect rect = run.rect();
rects.append(enclosingIntRect(FloatRect(accumulatedOffset + rect.location(), rect.size())));
}
return rects;
@@ -186,11 +174,8 @@
{
Vector<FloatQuad> quads;
auto resolver = runResolver(downcast<RenderBlockFlow>(*textRenderer.parent()), layout);
- for (auto it = resolver.begin(), end = resolver.end(); it != end; ++it) {
- const auto& run = *it;
- auto rect = run.rect();
- quads.append(textRenderer.localToAbsoluteQuad(FloatQuad(rect), 0, wasFixed));
- }
+ for (const auto& run : resolver.rangeForRenderer(textRenderer))
+ quads.append(textRenderer.localToAbsoluteQuad(FloatQuad(run.rect()), 0, wasFixed));
return quads;
}
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp (176316 => 176317)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp 2014-11-19 15:40:35 UTC (rev 176317)
@@ -33,6 +33,21 @@
namespace WebCore {
namespace SimpleLineLayout {
+static float baselinePosition(float lineHeight, float baseline, int lineIndex)
+{
+ return lineHeight * lineIndex + baseline;
+}
+
+static LayoutPoint linePosition(float logicalLeft, float logicalTop)
+{
+ return LayoutPoint(LayoutUnit::fromFloatFloor(logicalLeft), roundToInt(logicalTop));
+}
+
+static LayoutSize lineSize(float logicalLeft, float logicalRight, float height)
+{
+ return LayoutSize(LayoutUnit::fromFloatCeil(logicalRight) - LayoutUnit::fromFloatFloor(logicalLeft), height);
+}
+
RunResolver::Run::Run(const Iterator& iterator)
: m_iterator(iterator)
{
@@ -40,13 +55,12 @@
LayoutRect RunResolver::Run::rect() const
{
+ auto& run = m_iterator.simpleRun();
auto& resolver = m_iterator.resolver();
- auto& run = m_iterator.simpleRun();
-
- float baselinePosition = resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline;
- LayoutPoint linePosition(LayoutUnit::fromFloatFloor(run.logicalLeft), roundToInt(baselinePosition - resolver.m_ascent + resolver.m_borderAndPaddingBefore));
- LayoutSize lineSize(LayoutUnit::fromFloatCeil(run.logicalRight) - LayoutUnit::fromFloatFloor(run.logicalLeft), resolver.m_ascent + resolver.m_descent);
- return LayoutRect(linePosition, lineSize);
+ float baseline = baselinePosition(resolver.m_lineHeight, resolver.m_baseline, m_iterator.lineIndex());
+ LayoutPoint position = linePosition(run.logicalLeft, baseline - resolver.m_ascent + resolver.m_borderAndPaddingBefore);
+ LayoutSize size = lineSize(run.logicalLeft, run.logicalRight, resolver.m_ascent + resolver.m_descent);
+ return LayoutRect(position, size);
}
FloatPoint RunResolver::Run::baseline() const
@@ -54,15 +68,17 @@
auto& resolver = m_iterator.resolver();
auto& run = m_iterator.simpleRun();
- float baselinePosition = resolver.m_lineHeight * m_iterator.lineIndex() + resolver.m_baseline;
- return FloatPoint(run.logicalLeft, roundToInt(baselinePosition + resolver.m_borderAndPaddingBefore));
+ float baseline = baselinePosition(resolver.m_lineHeight, resolver.m_baseline, m_iterator.lineIndex());
+ return FloatPoint(run.logicalLeft, roundToInt(baseline + resolver.m_borderAndPaddingBefore));
}
StringView RunResolver::Run::text() const
{
auto& resolver = m_iterator.resolver();
auto& run = m_iterator.simpleRun();
- return StringView(resolver.m_string).substring(run.start, run.end - run.start);
+ const auto& renderer = resolver.m_flowContents.renderer(run.start);
+ ASSERT(renderer.is8Bit());
+ return StringView(renderer.characters8(), renderer.textLength()).substring(run.start, run.end - run.start);
}
RunResolver::Iterator::Iterator(const RunResolver& resolver, unsigned runIndex, unsigned lineIndex)
@@ -97,7 +113,7 @@
RunResolver::RunResolver(const RenderBlockFlow& flow, const Layout& layout)
: m_layout(layout)
- , m_string(downcast<RenderText>(*flow.firstChild()).text())
+ , m_flowContents(flow)
, m_lineHeight(lineHeightFromFlow(flow))
, m_baseline(baselineFromFlow(flow))
, m_borderAndPaddingBefore(flow.borderAndPaddingBefore())
@@ -136,6 +152,18 @@
return Range<Iterator>(rangeBegin, rangeEnd);
}
+Range<RunResolver::Iterator> RunResolver::rangeForRenderer(const RenderText& renderer) const
+{
+ unsigned startPosition = 0;
+ unsigned endPosition = 0;
+ m_flowContents.resolveRendererPositions(renderer, startPosition, endPosition);
+ auto rangeBegin = begin();
+ for (;(*rangeBegin).start() < startPosition && rangeBegin != end(); ++rangeBegin) { }
+ auto rangeEnd = rangeBegin;
+ for (;(*rangeEnd).end() <= endPosition && rangeEnd != end(); ++rangeEnd) { }
+ return Range<Iterator>(rangeBegin, rangeEnd);
+}
+
LineResolver::Iterator::Iterator(RunResolver::Iterator runIterator)
: m_runIterator(runIterator)
{
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h (176316 => 176317)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h 2014-11-19 14:24:10 UTC (rev 176316)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h 2014-11-19 15:40:35 UTC (rev 176317)
@@ -29,6 +29,7 @@
#include "LayoutRect.h"
#include "RenderBlockFlow.h"
#include "RenderText.h"
+#include "SimpleLineLayoutFlowContents.h"
#include "SimpleLineLayoutFunctions.h"
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
@@ -100,13 +101,14 @@
Iterator end() const;
Range<Iterator> rangeForRect(const LayoutRect&) const;
+ Range<Iterator> rangeForRenderer(const RenderText&) const;
private:
enum class IndexType { First, Last };
unsigned lineIndexForHeight(LayoutUnit, IndexType) const;
const Layout& m_layout;
- const String m_string;
+ const FlowContents m_flowContents;
const LayoutUnit m_lineHeight;
const LayoutUnit m_baseline;
const LayoutUnit m_borderAndPaddingBefore;