From f7731bbdd2be68fbd2e2177ed9619af9a8439c95 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 25 Jan 2016 00:03:08 -0800 Subject: [PATCH] Switch whitespace mode back to pre-wrap When we removed position: sticky, we introduced a subtle line breaking bug to pre-wrap that would cause whitespace to accumulate at the beginning of lines that follow unclean breaks. This patch adds back the deleted code (cleansed of the position sticky bits). --- .../rendering/line/BreakingContextInlineHeaders.h | 15 +++++++++++++++ sky/engine/core/rendering/style/RenderStyle.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sky/engine/core/rendering/line/BreakingContextInlineHeaders.h b/sky/engine/core/rendering/line/BreakingContextInlineHeaders.h index 2171e7a0a2d..c11eea05070 100644 --- a/sky/engine/core/rendering/line/BreakingContextInlineHeaders.h +++ b/sky/engine/core/rendering/line/BreakingContextInlineHeaders.h @@ -99,6 +99,8 @@ public: } private: + void skipTrailingWhitespace(InlineIterator&, const LineInfo&); + InlineBidiResolver& m_resolver; InlineIterator m_current; @@ -183,6 +185,18 @@ inline bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo = return notJustWhitespace || isEmptyInline(it.object()); } +// FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building +// line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned +// elements quite right. In other words, we need to build this function's work into the normal line +// object iteration process. +// NB. this function will insert any floating elements that would otherwise +// be skipped but it will not position them. +inline void BreakingContext::skipTrailingWhitespace(InlineIterator& iterator, const LineInfo& lineInfo) +{ + while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhitespace)) + iterator.increment(); +} + inline void BreakingContext::initializeForCurrentObject() { m_currentStyle = m_current.object()->style(); @@ -551,6 +565,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool if (!m_width.fitsOnLine(charWidth)) { lineWasTooWide = true; m_lineBreak.moveTo(m_current.object(), m_current.offset(), m_current.nextBreakablePosition()); + skipTrailingWhitespace(m_lineBreak, m_lineInfo); } } if (lineWasTooWide || !m_width.fitsOnLine()) { diff --git a/sky/engine/core/rendering/style/RenderStyle.h b/sky/engine/core/rendering/style/RenderStyle.h index 9f2aecd14b2..b134b430bb3 100644 --- a/sky/engine/core/rendering/style/RenderStyle.h +++ b/sky/engine/core/rendering/style/RenderStyle.h @@ -966,7 +966,7 @@ public: static EPosition initialPosition() { return StaticPosition; } static EUnicodeBidi initialUnicodeBidi() { return UBNormal; } static EVisibility initialVisibility() { return VISIBLE; } - static EWhiteSpace initialWhiteSpace() { return PRE_LINE; } + static EWhiteSpace initialWhiteSpace() { return PRE_WRAP; } static short initialHorizontalBorderSpacing() { return 0; } static short initialVerticalBorderSpacing() { return 0; } static Color initialColor() { return Color::white; }