Title: [199149] trunk/Source/WebCore
Revision
199149
Author
[email protected]
Date
2016-04-06 21:59:55 -0700 (Wed, 06 Apr 2016)

Log Message

Rename MidpointState to WhitespaceCollapsingState
https://bugs.webkit.org/show_bug.cgi?id=156304

Reviewed by David Hyatt.

MidpointState has nothing to do with midpoints.

An individual midpoint is now known as a "whitespace collapsing transition."

No new tests because there is no behavior change.

* platform/text/BidiResolver.h:
(WebCore::WhitespaceCollapsingState::reset): (See addMidpoint() below.)
Previously, we were using operator= to destroy old Iterators when their
storage inside the Vector was reused. Now that we are elliminating
m_numMidpoints, we can push destruction earlier to this reset() function.
Because the same amount of destruction happens in both cases, this doesn't
add additional work. (Vector can destroy its contents without shrinking
its storage overcommitment.)
(WebCore::WhitespaceCollapsingState::startIgnoringSpaces):
(WebCore::WhitespaceCollapsingState::stopIgnoringSpaces):
(WebCore::WhitespaceCollapsingState::ensureLineBoxInsideIgnoredSpaces):
(WebCore::WhitespaceCollapsingState::decrementTransitionAt):
(WebCore::WhitespaceCollapsingState::thresholds): Make the return value
const. The only clients of this function which needed mutation were
migrated to using decrementTransitionAt().
(WebCore::WhitespaceCollapsingState::numTransitions):
(WebCore::WhitespaceCollapsingState::currentTransition):
(WebCore::WhitespaceCollapsingState::setCurrentTransition):
(WebCore::WhitespaceCollapsingState::incrementCurrentTransition):
(WebCore::WhitespaceCollapsingState::decrementNumTransitions):
(WebCore::WhitespaceCollapsingState::betweenTransitions):
(WebCore::BidiResolverBase::whitespaceCollapsingState):
(WebCore::Subclass>::setWhitespaceCollapsingTransitionForIsolatedRun):
(WebCore::Subclass>::whitespaceCollapsingTransitionForIsolatedRun):
(WebCore::MidpointState::MidpointState): Deleted.
(WebCore::MidpointState::reset): Deleted.
(WebCore::MidpointState::startIgnoringSpaces): Deleted.
(WebCore::MidpointState::stopIgnoringSpaces): Deleted.
(WebCore::MidpointState::ensureLineBoxInsideIgnoredSpaces): Deleted.
(WebCore::MidpointState::midpoints): Deleted.
(WebCore::MidpointState::numMidpoints): Deleted.
(WebCore::MidpointState::currentMidpoint): Deleted.
(WebCore::MidpointState::setCurrentMidpoint): Deleted.
(WebCore::MidpointState::incrementCurrentMidpoint): Deleted.
(WebCore::MidpointState::decrementNumMidpoints): Deleted.
(WebCore::MidpointState::betweenMidpoints): Deleted.
(WebCore::MidpointState::addMidpoint): Deleted. This code has been around for 13
years (since r3672) where it was using QMemArray. That class doesn't have an
append() class, so it was implemented inside this function. Luckily, Vector
already overcommits its allocation, so we can elliminate m_numMidpoints entirely.
(WebCore::BidiResolverBase::midpointState): Deleted.
(WebCore::Subclass>::setMidpointForIsolatedRun): Deleted.
(WebCore::Subclass>::midpointForIsolatedRun): Deleted.
* rendering/InlineIterator.h:
(WebCore::addPlaceholderRunForIsolatedInline):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlockFlow::appendRunsForObject):
(WebCore::setUpResolverToResumeInIsolate):
(WebCore::constructBidiRunsForSegment):
(WebCore::RenderBlockFlow::layoutRunsAndFloatsInRange):
* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::BreakingContext):
(WebCore::BreakingContext::handleBR):
(WebCore::BreakingContext::handleOutOfFlowPositioned):
(WebCore::shouldSkipWhitespaceAfterStartObject):
(WebCore::BreakingContext::handleEmptyInline):
(WebCore::BreakingContext::handleReplaced):
(WebCore::ensureCharacterGetsLineBox):
(WebCore::BreakingContext::handleText):
(WebCore::checkWhitespaceCollapsingTransitions):
(WebCore::BreakingContext::handleEndOfLine):
(WebCore::checkMidpoints): Deleted.
* rendering/line/TrailingObjects.cpp:
(WebCore::TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes):
(WebCore::TrailingObjects::updateMidpointsForTrailingBoxes): Deleted.
* rendering/line/TrailingObjects.h:
(WebCore::TrailingObjects::appendBoxIfNeeded):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199148 => 199149)


--- trunk/Source/WebCore/ChangeLog	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/ChangeLog	2016-04-07 04:59:55 UTC (rev 199149)
@@ -1,3 +1,84 @@
+2016-04-06  Myles C. Maxfield  <[email protected]>
+
+        Rename MidpointState to WhitespaceCollapsingState
+        https://bugs.webkit.org/show_bug.cgi?id=156304
+
+        Reviewed by David Hyatt.
+
+        MidpointState has nothing to do with midpoints.
+
+        An individual midpoint is now known as a "whitespace collapsing transition."
+
+        No new tests because there is no behavior change.
+
+        * platform/text/BidiResolver.h:
+        (WebCore::WhitespaceCollapsingState::reset): (See addMidpoint() below.)
+        Previously, we were using operator= to destroy old Iterators when their
+        storage inside the Vector was reused. Now that we are elliminating
+        m_numMidpoints, we can push destruction earlier to this reset() function.
+        Because the same amount of destruction happens in both cases, this doesn't
+        add additional work. (Vector can destroy its contents without shrinking
+        its storage overcommitment.)
+        (WebCore::WhitespaceCollapsingState::startIgnoringSpaces):
+        (WebCore::WhitespaceCollapsingState::stopIgnoringSpaces):
+        (WebCore::WhitespaceCollapsingState::ensureLineBoxInsideIgnoredSpaces):
+        (WebCore::WhitespaceCollapsingState::decrementTransitionAt):
+        (WebCore::WhitespaceCollapsingState::thresholds): Make the return value
+        const. The only clients of this function which needed mutation were
+        migrated to using decrementTransitionAt().
+        (WebCore::WhitespaceCollapsingState::numTransitions):
+        (WebCore::WhitespaceCollapsingState::currentTransition):
+        (WebCore::WhitespaceCollapsingState::setCurrentTransition):
+        (WebCore::WhitespaceCollapsingState::incrementCurrentTransition):
+        (WebCore::WhitespaceCollapsingState::decrementNumTransitions):
+        (WebCore::WhitespaceCollapsingState::betweenTransitions):
+        (WebCore::BidiResolverBase::whitespaceCollapsingState):
+        (WebCore::Subclass>::setWhitespaceCollapsingTransitionForIsolatedRun):
+        (WebCore::Subclass>::whitespaceCollapsingTransitionForIsolatedRun):
+        (WebCore::MidpointState::MidpointState): Deleted.
+        (WebCore::MidpointState::reset): Deleted.
+        (WebCore::MidpointState::startIgnoringSpaces): Deleted.
+        (WebCore::MidpointState::stopIgnoringSpaces): Deleted.
+        (WebCore::MidpointState::ensureLineBoxInsideIgnoredSpaces): Deleted.
+        (WebCore::MidpointState::midpoints): Deleted.
+        (WebCore::MidpointState::numMidpoints): Deleted.
+        (WebCore::MidpointState::currentMidpoint): Deleted.
+        (WebCore::MidpointState::setCurrentMidpoint): Deleted.
+        (WebCore::MidpointState::incrementCurrentMidpoint): Deleted.
+        (WebCore::MidpointState::decrementNumMidpoints): Deleted.
+        (WebCore::MidpointState::betweenMidpoints): Deleted.
+        (WebCore::MidpointState::addMidpoint): Deleted. This code has been around for 13
+        years (since r3672) where it was using QMemArray. That class doesn't have an
+        append() class, so it was implemented inside this function. Luckily, Vector
+        already overcommits its allocation, so we can elliminate m_numMidpoints entirely.
+        (WebCore::BidiResolverBase::midpointState): Deleted.
+        (WebCore::Subclass>::setMidpointForIsolatedRun): Deleted.
+        (WebCore::Subclass>::midpointForIsolatedRun): Deleted.
+        * rendering/InlineIterator.h:
+        (WebCore::addPlaceholderRunForIsolatedInline):
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlockFlow::appendRunsForObject):
+        (WebCore::setUpResolverToResumeInIsolate):
+        (WebCore::constructBidiRunsForSegment):
+        (WebCore::RenderBlockFlow::layoutRunsAndFloatsInRange):
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::BreakingContext):
+        (WebCore::BreakingContext::handleBR):
+        (WebCore::BreakingContext::handleOutOfFlowPositioned):
+        (WebCore::shouldSkipWhitespaceAfterStartObject):
+        (WebCore::BreakingContext::handleEmptyInline):
+        (WebCore::BreakingContext::handleReplaced):
+        (WebCore::ensureCharacterGetsLineBox):
+        (WebCore::BreakingContext::handleText):
+        (WebCore::checkWhitespaceCollapsingTransitions):
+        (WebCore::BreakingContext::handleEndOfLine):
+        (WebCore::checkMidpoints): Deleted.
+        * rendering/line/TrailingObjects.cpp:
+        (WebCore::TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes):
+        (WebCore::TrailingObjects::updateMidpointsForTrailingBoxes): Deleted.
+        * rendering/line/TrailingObjects.h:
+        (WebCore::TrailingObjects::appendBoxIfNeeded):
+
 2016-04-06  Gyuyoung Kim  <[email protected]>
 
         Remove duplicated parsePortFromStringPosition()

Modified: trunk/Source/WebCore/platform/text/BidiResolver.h (199148 => 199149)


--- trunk/Source/WebCore/platform/text/BidiResolver.h	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/platform/text/BidiResolver.h	2016-04-07 04:59:55 UTC (rev 199149)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000 Lars Knoll ([email protected])
- * Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc.  All right reserved.
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2016 Apple Inc.  All right reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -34,63 +34,50 @@
 
 class RenderObject;
 
-template <class Iterator> class MidpointState {
+template <class Iterator> class WhitespaceCollapsingState {
 public:
-    MidpointState()
-    {
-        reset();
-    }
-    
     void reset()
     {
-        m_numMidpoints = 0;
-        m_currentMidpoint = 0;
+        m_transitions.clear();
+        m_currentTransition = 0;
     }
     
-    void startIgnoringSpaces(const Iterator& midpoint)
+    void startIgnoringSpaces(const Iterator& transition)
     {
-        ASSERT(!(m_numMidpoints % 2));
-        addMidpoint(midpoint);
+        ASSERT(!(m_transitions.size() % 2));
+        m_transitions.append(transition);
     }
 
-    void stopIgnoringSpaces(const Iterator& midpoint)
+    void stopIgnoringSpaces(const Iterator& transition)
     {
-        ASSERT(m_numMidpoints % 2);
-        addMidpoint(midpoint);
+        ASSERT(m_transitions.size() % 2);
+        m_transitions.append(transition);
     }
 
     // When ignoring spaces, this needs to be called for objects that need line boxes such as RenderInlines or
     // hard line breaks to ensure that they're not ignored.
-    void ensureLineBoxInsideIgnoredSpaces(RenderObject* renderer)
+    void ensureLineBoxInsideIgnoredSpaces(RenderObject& renderer)
     {
-        Iterator midpoint(0, renderer, 0);
-        stopIgnoringSpaces(midpoint);
-        startIgnoringSpaces(midpoint);
+        Iterator transition(0, &renderer, 0);
+        stopIgnoringSpaces(transition);
+        startIgnoringSpaces(transition);
     }
 
-    Vector<Iterator>& midpoints() { return m_midpoints; }
-    unsigned numMidpoints() const { return m_numMidpoints; }
-    unsigned currentMidpoint() const { return m_currentMidpoint; }
-    void setCurrentMidpoint(unsigned currentMidpoint) { m_currentMidpoint = currentMidpoint; }
-    void incrementCurrentMidpoint() { ++m_currentMidpoint; }
-    void decrementNumMidpoints() { --m_numMidpoints; }
-    bool betweenMidpoints() const { return m_currentMidpoint % 2; }
-private:
-    // The goal is to reuse the line state across multiple
-    // lines so we just keep an array around for midpoints and never clear it across multiple
-    // lines. We track the number of items and position using the two other variables.
-    Vector<Iterator> m_midpoints;
-    unsigned m_numMidpoints;
-    unsigned m_currentMidpoint;
-
-    void addMidpoint(const Iterator& midpoint)
+    void decrementTransitionAt(size_t index)
     {
-        if (m_midpoints.size() <= m_numMidpoints)
-            m_midpoints.grow(m_numMidpoints + 10);
-
-        Iterator* midpointsIterator = m_midpoints.data();
-        midpointsIterator[m_numMidpoints++] = midpoint;
+        m_transitions[index].fastDecrement();
     }
+
+    const Vector<Iterator>& transitions() { return m_transitions; }
+    size_t numTransitions() const { return m_transitions.size(); }
+    size_t currentTransition() const { return m_currentTransition; }
+    void setCurrentTransition(size_t currentTransition) { m_currentTransition = currentTransition; }
+    void incrementCurrentTransition() { ++m_currentTransition; }
+    void decrementNumTransitions() { m_transitions.shrink(m_transitions.size() - 1); }
+    bool betweenTransitions() const { return m_currentTransition % 2; }
+private:
+    Vector<Iterator> m_transitions;
+    size_t m_currentTransition { 0 };
 };
 
 // The BidiStatus at a given position (typically the end of a line) can
@@ -247,7 +234,7 @@
     const BidiStatus& status() const { return m_status; }
     void setStatus(const BidiStatus s) { m_status = s; }
 
-    MidpointState<Iterator>& midpointState() { return m_midpointState; }
+    WhitespaceCollapsingState<Iterator>& whitespaceCollapsingState() { return m_whitespaceCollapsingState; }
 
     // The current algorithm handles nested isolates one layer of nesting at a time.
     // But when we layout each isolated span, we will walk into (and ignore) all
@@ -267,8 +254,8 @@
     // It's unclear if this is still needed.
     void markCurrentRunEmpty() { m_emptyRun = true; }
 
-    void setMidpointForIsolatedRun(Run&, unsigned);
-    unsigned midpointForIsolatedRun(Run&);
+    void setWhitespaceCollapsingTransitionForIsolatedRun(Run&, size_t);
+    unsigned whitespaceCollapsingTransitionForIsolatedRun(Run&);
 
 protected:
     // FIXME: Instead of InlineBidiResolvers subclassing this method, we should
@@ -292,10 +279,10 @@
     // into createBidiRunsForLine by the caller.
     BidiRunList<Run> m_runs;
 
-    MidpointState<Iterator> m_midpointState;
+    WhitespaceCollapsingState<Iterator> m_whitespaceCollapsingState;
 
     unsigned m_nestedIsolateCount;
-    HashMap<Run*, unsigned> m_midpointForIsolatedRun;
+    HashMap<Run*, unsigned> m_whitespaceCollapsingTransitionForIsolatedRun;
 
 private:
     void raiseExplicitEmbeddingLevel(UCharDirection from, UCharDirection to);
@@ -982,16 +969,16 @@
 }
 
 template <class Iterator, class Run, class Subclass>
-void BidiResolverBase<Iterator, Run, Subclass>::setMidpointForIsolatedRun(Run& run, unsigned midpoint)
+void BidiResolverBase<Iterator, Run, Subclass>::setWhitespaceCollapsingTransitionForIsolatedRun(Run& run, size_t transition)
 {
-    ASSERT(!m_midpointForIsolatedRun.contains(&run));
-    m_midpointForIsolatedRun.add(&run, midpoint);
+    ASSERT(!m_whitespaceCollapsingTransitionForIsolatedRun.contains(&run));
+    m_whitespaceCollapsingTransitionForIsolatedRun.add(&run, transition);
 }
 
 template<class Iterator, class Run, class Subclass>
-unsigned BidiResolverBase<Iterator, Run, Subclass>::midpointForIsolatedRun(Run& run)
+unsigned BidiResolverBase<Iterator, Run, Subclass>::whitespaceCollapsingTransitionForIsolatedRun(Run& run)
 {
-    return m_midpointForIsolatedRun.take(&run);
+    return m_whitespaceCollapsingTransitionForIsolatedRun.take(&run);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/InlineIterator.h (199148 => 199149)


--- trunk/Source/WebCore/rendering/InlineIterator.h	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/rendering/InlineIterator.h	2016-04-07 04:59:55 UTC (rev 199149)
@@ -495,7 +495,7 @@
     std::unique_ptr<BidiRun> isolatedRun = std::make_unique<BidiRun>(pos, 0, obj, resolver.context(), resolver.dir());
     // FIXME: isolatedRuns() could be a hash of object->run and then we could cheaply
     // ASSERT here that we didn't create multiple objects for the same inline.
-    resolver.setMidpointForIsolatedRun(*isolatedRun, resolver.midpointState().currentMidpoint());
+    resolver.setWhitespaceCollapsingTransitionForIsolatedRun(*isolatedRun, resolver.whitespaceCollapsingState().currentTransition());
     resolver.isolatedRuns().append(BidiIsolatedRun(obj, pos, root, *isolatedRun));
     resolver.runs().appendRun(WTFMove(isolatedRun));
 }

Modified: trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp (199148 => 199149)


--- trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp	2016-04-07 04:59:55 UTC (rev 199149)
@@ -81,38 +81,38 @@
     if (start > end || shouldSkipCreatingRunsForObject(obj))
         return;
 
-    LineMidpointState& lineMidpointState = resolver.midpointState();
-    bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints());
-    InlineIterator nextMidpoint;
-    if (haveNextMidpoint)
-        nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()];
-    if (lineMidpointState.betweenMidpoints()) {
-        if (!haveNextMidpoint || (&obj != nextMidpoint.renderer()))
+    LineWhitespaceCollapsingState& lineWhitespaceCollapsingState = resolver.whitespaceCollapsingState();
+    bool haveNextTransition = (lineWhitespaceCollapsingState.currentTransition() < lineWhitespaceCollapsingState.numTransitions());
+    InlineIterator nextTransition;
+    if (haveNextTransition)
+        nextTransition = lineWhitespaceCollapsingState.transitions()[lineWhitespaceCollapsingState.currentTransition()];
+    if (lineWhitespaceCollapsingState.betweenTransitions()) {
+        if (!haveNextTransition || (&obj != nextTransition.renderer()))
             return;
         // This is a new start point. Stop ignoring objects and
         // adjust our start.
-        start = nextMidpoint.offset();
-        lineMidpointState.incrementCurrentMidpoint();
+        start = nextTransition.offset();
+        lineWhitespaceCollapsingState.incrementCurrentTransition();
         if (start < end) {
             appendRunsForObject(runs, start, end, obj, resolver);
             return;
         }
     } else {
-        if (!haveNextMidpoint || (&obj != nextMidpoint.renderer())) {
+        if (!haveNextTransition || (&obj != nextTransition.renderer())) {
             if (runs)
                 runs->appendRun(createRun(start, end, obj, resolver));
             return;
         }
 
-        // An end midpoint has been encountered within our object. We need to append a run with our endpoint.
-        if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
-            lineMidpointState.incrementCurrentMidpoint();
+        // An end transition has been encountered within our object. We need to append a run with our endpoint.
+        if (static_cast<int>(nextTransition.offset() + 1) <= end) {
+            lineWhitespaceCollapsingState.incrementCurrentTransition();
             // The end of the line is before the object we're inspecting. Skip everything and return
-            if (nextMidpoint.refersToEndOfPreviousNode())
+            if (nextTransition.refersToEndOfPreviousNode())
                 return;
-            if (static_cast<int>(nextMidpoint.offset() + 1) > start && runs)
-                runs->appendRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
-            appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
+            if (static_cast<int>(nextTransition.offset() + 1) > start && runs)
+                runs->appendRun(createRun(start, nextTransition.offset() + 1, obj, resolver));
+            appendRunsForObject(runs, nextTransition.offset() + 1, end, obj, resolver);
         } else if (runs)
             runs->appendRun(createRun(start, end, obj, resolver));
     }
@@ -1076,9 +1076,9 @@
 
 static inline void setUpResolverToResumeInIsolate(InlineBidiResolver& resolver, InlineBidiResolver& topResolver, BidiRun& isolatedRun, RenderObject* root, RenderObject* startObject)
 {
-    // Set up m_midpointState
-    resolver.midpointState() = topResolver.midpointState();
-    resolver.midpointState().setCurrentMidpoint(topResolver.midpointForIsolatedRun(isolatedRun));
+    // Set up m_whitespaceCollapsingState
+    resolver.whitespaceCollapsingState() = topResolver.whitespaceCollapsingState();
+    resolver.whitespaceCollapsingState().setCurrentTransition(topResolver.whitespaceCollapsingTransitionForIsolatedRun(isolatedRun));
 
     // Set up m_nestedIsolateCount
     notifyResolverToResumeInIsolate(resolver, root, startObject);
@@ -1145,7 +1145,7 @@
         while (!isolatedResolver.isolatedRuns().isEmpty()) {
             auto runWithContext = WTFMove(isolatedResolver.isolatedRuns().last());
             isolatedResolver.isolatedRuns().removeLast();
-            topResolver.setMidpointForIsolatedRun(runWithContext.runToReplace, isolatedResolver.midpointForIsolatedRun(runWithContext.runToReplace));
+            topResolver.setWhitespaceCollapsingTransitionForIsolatedRun(runWithContext.runToReplace, isolatedResolver.whitespaceCollapsingTransitionForIsolatedRun(runWithContext.runToReplace));
             topResolver.isolatedRuns().append(WTFMove(runWithContext));
         }
     }
@@ -1286,7 +1286,7 @@
 {
     const RenderStyle& styleToUse = style();
     bool paginated = view().layoutState() && view().layoutState()->isPaginated();
-    LineMidpointState& lineMidpointState = resolver.midpointState();
+    LineWhitespaceCollapsingState& lineWhitespaceCollapsingState = resolver.whitespaceCollapsingState();
     InlineIterator end = resolver.position();
     bool checkForEndLineMatch = layoutState.endLine();
     RenderTextInfo renderTextInfo;
@@ -1305,7 +1305,7 @@
             }
         }
 
-        lineMidpointState.reset();
+        lineWhitespaceCollapsingState.reset();
 
         layoutState.lineInfo().setEmpty(true);
         layoutState.lineInfo().resetRunsFromLeadingWhitespace();
@@ -1455,7 +1455,7 @@
             layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr);
         }
 
-        lineMidpointState.reset();
+        lineWhitespaceCollapsingState.reset();
         resolver.setPosition(end, numberOfIsolateAncestors(end));
     }
 

Modified: trunk/Source/WebCore/rendering/line/BreakingContext.h (199148 => 199149)


--- trunk/Source/WebCore/rendering/line/BreakingContext.h	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/rendering/line/BreakingContext.h	2016-04-07 04:59:55 UTC (rev 199149)
@@ -129,7 +129,7 @@
         , m_allowImagesToBreak(!block.document().inQuirksMode() || !block.isTableCell() || !m_blockStyle.logicalWidth().isIntrinsicOrAuto())
         , m_atEnd(false)
         , m_hadUncommittedWidthBeforeCurrent(false)
-        , m_lineMidpointState(resolver.midpointState())
+        , m_lineWhitespaceCollapsingState(resolver.whitespaceCollapsingState())
     {
         m_lineInfo.setPreviousLineBrokeCleanly(false);
     }
@@ -292,7 +292,7 @@
     
     bool m_hangsAtEnd { false };
 
-    LineMidpointState& m_lineMidpointState;
+    LineWhitespaceCollapsingState& m_lineWhitespaceCollapsingState;
 
     TrailingObjects m_trailingObjects;
 };
@@ -334,9 +334,9 @@
 inline void BreakingContext::handleBR(EClear& clear)
 {
     if (fitsOnLineOrHangsAtEnd()) {
-        RenderObject* br = m_current.renderer();
+        RenderObject& br = *m_current.renderer();
         m_lineBreakHistory.push([&](InlineIterator& modifyMe) {
-            modifyMe.moveToStartOf(br);
+            modifyMe.moveToStartOf(&br);
             modifyMe.increment();
         });
 
@@ -354,12 +354,12 @@
         // need to check for floats to clear - so if we're ignoring spaces, stop ignoring them and add a
         // run for this object.
         if (m_ignoringSpaces && m_currentStyle->clear() != CNONE)
-            m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(br);
+            m_lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(br);
         // If we were preceded by collapsing space and are in a right-aligned container we need to ensure the space gets
         // collapsed away so that it doesn't push the text out from the container's right-hand edge.
         // FIXME: Do this regardless of the container's alignment - will require rebaselining a lot of test results.
         else if (m_ignoringSpaces && (m_blockStyle.textAlign() == RIGHT || m_blockStyle.textAlign() == WEBKIT_RIGHT))
-            m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), m_current.offset()));
+            m_lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), m_current.offset()));
 
         if (!m_lineInfo.isEmpty())
             clear = m_currentStyle->clear();
@@ -438,8 +438,8 @@
     // then start ignoring spaces again.
     if (isInlineType || box.container()->isRenderInline()) {
         if (m_ignoringSpaces)
-            m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(&box);
-        m_trailingObjects.appendBoxIfNeeded(&box);
+            m_lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(box);
+        m_trailingObjects.appendBoxIfNeeded(box);
     } else
         positionedObjects.append(&box);
 
@@ -469,7 +469,7 @@
 
 // This is currently just used for list markers and inline flows that have line boxes. Neither should
 // have an effect on whitespace at the start of the line.
-inline bool shouldSkipWhitespaceAfterStartObject(RenderBlockFlow& block, RenderObject* o, LineMidpointState& lineMidpointState)
+inline bool shouldSkipWhitespaceAfterStartObject(RenderBlockFlow& block, RenderObject* o, LineWhitespaceCollapsingState& lineWhitespaceCollapsingState)
 {
     RenderObject* next = bidiNextSkippingEmptyInlines(block, o);
     while (next && next->isFloatingOrOutOfFlowPositioned())
@@ -479,7 +479,7 @@
         RenderText& nextText = downcast<RenderText>(*next);
         UChar nextChar = nextText.characterAt(0);
         if (nextText.style().isCollapsibleWhiteSpace(nextChar)) {
-            lineMidpointState.startIgnoringSpaces(InlineIterator(nullptr, o, 0));
+            lineWhitespaceCollapsingState.startIgnoringSpaces(InlineIterator(nullptr, o, 0));
             return true;
         }
     }
@@ -506,16 +506,16 @@
             m_lineInfo.setEmpty(false, &m_block, &m_width);
         if (m_ignoringSpaces) {
             m_trailingObjects.clear();
-            m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_current.renderer());
+            m_lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(*m_current.renderer());
         } else if (m_blockStyle.collapseWhiteSpace() && m_resolver.position().renderer() == m_current.renderer()
-            && shouldSkipWhitespaceAfterStartObject(m_block, m_current.renderer(), m_lineMidpointState)) {
+            && shouldSkipWhitespaceAfterStartObject(m_block, m_current.renderer(), m_lineWhitespaceCollapsingState)) {
             // Like with list markers, we start ignoring spaces to make sure that any
             // additional spaces we see will be discarded.
             m_currentCharacterIsSpace = true;
             m_currentCharacterIsWS = true;
             m_ignoringSpaces = true;
         } else
-            m_trailingObjects.appendBoxIfNeeded(&flowBox);
+            m_trailingObjects.appendBoxIfNeeded(flowBox);
     }
     
     float inlineWidth = inlineLogicalWidth(m_current.renderer()) + borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox);
@@ -549,7 +549,7 @@
             m_lineLayoutState.prevFloatBottomFromAnonymousInlineBlock(), m_lineLayoutState.maxFloatBottomFromAnonymousInlineBlock());
 
     if (m_ignoringSpaces)
-        m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), 0));
+        m_lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), 0));
 
     m_lineInfo.setEmpty(false, &m_block, &m_width);
     m_ignoringSpaces = false;
@@ -561,7 +561,7 @@
     // item, then this is all moot.
     LayoutUnit replacedLogicalWidth = m_block.logicalWidthForChild(replacedBox) + m_block.marginStartForChild(replacedBox) + m_block.marginEndForChild(replacedBox) + inlineLogicalWidth(m_current.renderer());
     if (is<RenderListMarker>(*m_current.renderer())) {
-        if (m_blockStyle.collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, m_current.renderer(), m_lineMidpointState)) {
+        if (m_blockStyle.collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, m_current.renderer(), m_lineWhitespaceCollapsingState)) {
             // Like with inline flows, we start ignoring spaces to make sure that any
             // additional spaces we see will be discarded.
             m_currentCharacterIsSpace = true;
@@ -642,12 +642,12 @@
     return font.width(run, &fallbackFonts, &glyphOverflow);
 }
 
-// Adding a pair of midpoints before a character will split it out into a new line box.
-inline void ensureCharacterGetsLineBox(LineMidpointState& lineMidpointState, InlineIterator& textParagraphSeparator)
+// Adding a pair of whitespace collapsing transitions before a character will split it out into a new line box.
+inline void ensureCharacterGetsLineBox(LineWhitespaceCollapsingState& lineWhitespaceCollapsingState, InlineIterator& textParagraphSeparator)
 {
-    InlineIterator midpoint(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset());
-    lineMidpointState.startIgnoringSpaces(InlineIterator(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset() - 1));
-    lineMidpointState.stopIgnoringSpaces(InlineIterator(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset()));
+    InlineIterator transition(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset());
+    lineWhitespaceCollapsingState.startIgnoringSpaces(InlineIterator(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset() - 1));
+    lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset()));
 }
 
 inline void tryHyphenating(RenderText& text, const FontCascade& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLimit, int minimumSuffixLimit, unsigned lastSpace, unsigned pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated)
@@ -887,7 +887,7 @@
                     m_ignoringSpaces = false;
                     wordSpacingForWordMeasurement = 0;
                     lastSpace = m_current.offset(); // e.g., "Foo    goo", don't add in any of the ignored spaces.
-                    m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), m_current.offset()));
+                    m_lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), m_current.offset()));
                     stoppedIgnoringSpaces = true;
                 } else {
                     // Just keep ignoring these spaces.
@@ -948,7 +948,7 @@
                     }
                     if (m_lineBreakHistory.atTextParagraphSeparator()) {
                         if (!stoppedIgnoringSpaces && m_current.offset() > 0)
-                            ensureCharacterGetsLineBox(m_lineMidpointState, m_current);
+                            ensureCharacterGetsLineBox(m_lineWhitespaceCollapsingState, m_current);
                         m_lineBreakHistory.increment();
                         m_lineInfo.setPreviousLineBrokeCleanly(true);
                         wordMeasurement.endOffset = m_lineBreakHistory.offset();
@@ -1004,7 +1004,7 @@
 
             if (c == '\n' && m_preservesNewline) {
                 if (!stoppedIgnoringSpaces && m_current.offset())
-                    ensureCharacterGetsLineBox(m_lineMidpointState, m_current);
+                    ensureCharacterGetsLineBox(m_lineWhitespaceCollapsingState, m_current);
                 commitLineBreakAtCurrentWidth(*m_current.renderer(), m_current.offset(), m_current.nextBreakablePosition());
                 m_lineBreakHistory.increment();
                 m_lineInfo.setPreviousLineBrokeCleanly(true);
@@ -1039,10 +1039,10 @@
                     m_ignoringSpaces = true;
 
                     // We just entered a mode where we are ignoring
-                    // spaces. Create a midpoint to terminate the run
+                    // spaces. Create a transition to terminate the run
                     // before the second space.
-                    m_lineMidpointState.startIgnoringSpaces(m_startOfIgnoredSpaces);
-                    m_trailingObjects.updateMidpointsForTrailingBoxes(m_lineMidpointState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace);
+                    m_lineWhitespaceCollapsingState.startIgnoringSpaces(m_startOfIgnoredSpaces);
+                    m_trailingObjects.updateWhitespaceCollapsingTransitionsForTrailingBoxes(m_lineWhitespaceCollapsingState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace);
                 }
             }
         } else {
@@ -1052,7 +1052,7 @@
                 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0;
                 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurements.last().width) ? wordSpacing : 0;
                 lastSpace = m_current.offset(); // e.g., "Foo    goo", don't add in any of the ignored spaces.
-                m_lineMidpointState.stopIgnoringSpaces(InlineIterator(nullptr, m_current.renderer(), m_current.offset()));
+                m_lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(nullptr, m_current.renderer(), m_current.offset()));
             }
             if (m_hangsAtEnd && !renderText.isHangableStopOrComma(c))
                 m_hangsAtEnd = false;
@@ -1061,7 +1061,7 @@
         if (isSVGText && m_current.offset()) {
             // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks).
             if (downcast<RenderSVGInlineText>(renderText).characterStartsNewTextChunk(m_current.offset()))
-                ensureCharacterGetsLineBox(m_lineMidpointState, m_current);
+                ensureCharacterGetsLineBox(m_lineWhitespaceCollapsingState, m_current);
         }
 
         if (m_currentCharacterIsSpace && !previousCharacterIsSpace) {
@@ -1074,7 +1074,7 @@
                 m_startOfIgnoredSpaces.setOffset(m_startOfIgnoredSpaces.offset() - 1);
                 // If there's just a single trailing space start ignoring it now so it collapses away.
                 if (m_current.offset() == renderText.textLength() - 1)
-                    m_lineMidpointState.startIgnoringSpaces(m_startOfIgnoredSpaces);
+                    m_lineWhitespaceCollapsingState.startIgnoringSpaces(m_startOfIgnoredSpaces);
             }
         }
 
@@ -1220,23 +1220,23 @@
     }
 }
 
-inline TrailingObjects::CollapseFirstSpaceOrNot checkMidpoints(LineMidpointState& lineMidpointState, const InlineIterator& lBreak)
+inline TrailingObjects::CollapseFirstSpaceOrNot checkWhitespaceCollapsingTransitions(LineWhitespaceCollapsingState& lineWhitespaceCollapsingState, const InlineIterator& lBreak)
 {
-    // Check to see if our last midpoint is a start point beyond the line break. If so,
+    // Check to see if our last transition is a start point beyond the line break. If so,
     // shave it off the list, and shave off a trailing space if the previous end point doesn't
     // preserve whitespace.
-    if (lBreak.renderer() && lineMidpointState.numMidpoints() && !(lineMidpointState.numMidpoints() % 2)) {
-        InlineIterator* midpoints = lineMidpointState.midpoints().data();
-        InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints() - 2];
-        const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints() - 1];
+    if (lBreak.renderer() && lineWhitespaceCollapsingState.numTransitions() && !(lineWhitespaceCollapsingState.numTransitions() % 2)) {
+        const InlineIterator* transitions = lineWhitespaceCollapsingState.transitions().data();
+        const InlineIterator& endpoint = transitions[lineWhitespaceCollapsingState.numTransitions() - 2];
+        const InlineIterator& startpoint = transitions[lineWhitespaceCollapsingState.numTransitions() - 1];
         InlineIterator currpoint = endpoint;
         while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak)
             currpoint.increment();
         if (currpoint == lBreak) {
             // We hit the line break before the start point. Shave off the start point.
-            lineMidpointState.decrementNumMidpoints();
+            lineWhitespaceCollapsingState.decrementNumTransitions();
             if (endpoint.renderer()->style().collapseWhiteSpace() && endpoint.renderer()->isText()) {
-                endpoint.fastDecrement();
+                lineWhitespaceCollapsingState.decrementTransitionAt(lineWhitespaceCollapsingState.numTransitions() - 1);
                 return TrailingObjects::DoNotCollapseFirstSpace;
             }
         }
@@ -1269,10 +1269,10 @@
         m_lineBreakHistory.increment();
     }
 
-    // Sanity check our midpoints.
-    TrailingObjects::CollapseFirstSpaceOrNot collapsed = checkMidpoints(m_lineMidpointState, m_lineBreakHistory.current());
+    // Sanity check our whitespace collapsing transitions.
+    TrailingObjects::CollapseFirstSpaceOrNot collapsed = checkWhitespaceCollapsingTransitions(m_lineWhitespaceCollapsingState, m_lineBreakHistory.current());
 
-    m_trailingObjects.updateMidpointsForTrailingBoxes(m_lineMidpointState, m_lineBreakHistory.current(), collapsed);
+    m_trailingObjects.updateWhitespaceCollapsingTransitionsForTrailingBoxes(m_lineWhitespaceCollapsingState, m_lineBreakHistory.current(), collapsed);
 
     // We might have made lineBreak an iterator that points past the end
     // of the object. Do this adjustment to make it point to the start

Modified: trunk/Source/WebCore/rendering/line/TrailingObjects.cpp (199148 => 199149)


--- trunk/Source/WebCore/rendering/line/TrailingObjects.cpp	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/rendering/line/TrailingObjects.cpp	2016-04-07 04:59:55 UTC (rev 199149)
@@ -29,44 +29,44 @@
 
 namespace WebCore {
 
-void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
+void TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes(LineWhitespaceCollapsingState& lineWhitespaceCollapsingState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
 {
     if (!m_whitespace)
         return;
 
-    // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint.
+    // This object is either going to be part of the last transition, or it is going to be the actual endpoint.
     // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline.
-    if (lineMidpointState.numMidpoints() % 2) {
-        // Find the trailing space object's midpoint.
-        int trailingSpaceMidpoint = lineMidpointState.numMidpoints() - 1;
-        for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints()[trailingSpaceMidpoint].renderer() != m_whitespace; --trailingSpaceMidpoint) { }
-        ASSERT(trailingSpaceMidpoint >= 0);
+    if (lineWhitespaceCollapsingState.numTransitions() % 2) {
+        // Find the trailing space object's transition.
+        int trailingSpaceTransition = lineWhitespaceCollapsingState.numTransitions() - 1;
+        for ( ; trailingSpaceTransition > 0 && lineWhitespaceCollapsingState.transitions()[trailingSpaceTransition].renderer() != m_whitespace; --trailingSpaceTransition) { }
+        ASSERT(trailingSpaceTransition >= 0);
         if (collapseFirstSpace == CollapseFirstSpace)
-            lineMidpointState.midpoints()[trailingSpaceMidpoint].fastDecrement();
+            lineWhitespaceCollapsingState.decrementTransitionAt(trailingSpaceTransition);
 
-        // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts
+        // Now make sure every single trailingPositionedBox following the trailingSpaceTransition properly stops and starts
         // ignoring spaces.
-        size_t currentMidpoint = trailingSpaceMidpoint + 1;
+        size_t currentTransition = trailingSpaceTransition + 1;
         for (size_t i = 0; i < m_boxes.size(); ++i) {
-            if (currentMidpoint >= lineMidpointState.numMidpoints()) {
-                // We don't have a midpoint for this box yet.
-                lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
+            if (currentTransition >= lineWhitespaceCollapsingState.numTransitions()) {
+                // We don't have a transition for this box yet.
+                lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
             } else {
-                ASSERT(lineMidpointState.midpoints()[currentMidpoint].renderer() == m_boxes[i]);
-                ASSERT(lineMidpointState.midpoints()[currentMidpoint + 1].renderer() == m_boxes[i]);
+                ASSERT(lineWhitespaceCollapsingState.transitions()[currentTransition].renderer() == &(m_boxes[i].get()));
+                ASSERT(lineWhitespaceCollapsingState.transitions()[currentTransition + 1].renderer() == &(m_boxes[i].get()));
             }
-            currentMidpoint += 2;
+            currentTransition += 2;
         }
     } else if (!lBreak.renderer()) {
         ASSERT(m_whitespace->isText());
         ASSERT(collapseFirstSpace == CollapseFirstSpace);
-        // Add a new end midpoint that stops right at the very end.
+        // Add a new end transition that stops right at the very end.
         unsigned length = m_whitespace->textLength();
         unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
         InlineIterator endMid(0, m_whitespace, pos);
-        lineMidpointState.startIgnoringSpaces(endMid);
+        lineWhitespaceCollapsingState.startIgnoringSpaces(endMid);
         for (size_t i = 0; i < m_boxes.size(); ++i)
-            lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
+            lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
     }
 }
 

Modified: trunk/Source/WebCore/rendering/line/TrailingObjects.h (199148 => 199149)


--- trunk/Source/WebCore/rendering/line/TrailingObjects.h	2016-04-07 04:33:32 UTC (rev 199148)
+++ trunk/Source/WebCore/rendering/line/TrailingObjects.h	2016-04-07 04:59:55 UTC (rev 199149)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000 Lars Knoll ([email protected])
- * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2016 Apple Inc. All right reserved.
  * Copyright (C) 2010 Google Inc. All rights reserved.
  * Copyright (C) 2013 ChangSeok Oh <[email protected]>
  * Copyright (C) 2013 Adobe Systems Inc. All right reserved.
@@ -38,9 +38,9 @@
 
 template <class Iterator, class Run> class BidiResolver;
 template <class Iterator, class Run, class IsolateRun> class BidiResolverWithIsolate;
-template <class Iterator> class MidpointState;
+template <class Iterator> class WhitespaceCollapsingState;
 typedef BidiResolverWithIsolate<InlineIterator, BidiRun, BidiIsolatedRun> InlineBidiResolver;
-typedef MidpointState<InlineIterator> LineMidpointState;
+typedef WhitespaceCollapsingState<InlineIterator> LineWhitespaceCollapsingState;
 
 class TrailingObjects {
 public:
@@ -60,7 +60,7 @@
         m_boxes.shrink(0); // Use shrink(0) instead of clear() to retain our capacity.
     }
 
-    void appendBoxIfNeeded(RenderBoxModelObject* box)
+    void appendBoxIfNeeded(RenderBoxModelObject& box)
     {
         if (m_whitespace)
             m_boxes.append(box);
@@ -68,11 +68,11 @@
 
     enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace };
 
-    void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot);
+    void updateWhitespaceCollapsingTransitionsForTrailingBoxes(LineWhitespaceCollapsingState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot);
 
 private:
     RenderText* m_whitespace;
-    Vector<RenderBoxModelObject*, 4> m_boxes;
+    Vector<std::reference_wrapper<RenderBoxModelObject>, 4> m_boxes;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to