Changeset 51851 in webkit


Ignore:
Timestamp:
Dec 8, 2009 7:20:55 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-08 Carol Szabo <carol.szabo@nokia.com>

Reviewed by Darin Adler.

CSS Counter Nesting still does not work according to the spec.
https://bugs.webkit.org/show_bug.cgi?id=31723

  • fast/css/counters/nesting-expected.txt: Added.
  • fast/css/counters/nesting.html: Added. This test tests compliance with the CSS2.1 counter scoping and nesting rules.

2009-12-08 Carol Szabo <carol.szabo@nokia.com>

Reviewed by Darin Adler.

CSS Counter Nesting still does not work according to the spec.
https://bugs.webkit.org/show_bug.cgi?id=31723

Test: fast/css/counters/nesting.html

  • rendering/RenderCounter.cpp: (WebCore::findPlaceForCounter): Replaced the faulty counter insertion algorithm with one that works.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r51849 r51851  
     12009-12-08  Carol Szabo  <carol.szabo@nokia.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        CSS Counter Nesting still does not work according to the spec.
     6        https://bugs.webkit.org/show_bug.cgi?id=31723
     7
     8        * fast/css/counters/nesting-expected.txt: Added.
     9        * fast/css/counters/nesting.html: Added.
     10        This test tests compliance with the CSS2.1 counter scoping and nesting rules.
     11
    1122009-12-08  Csaba Osztrogonác  <ossy@webkit.org>
    213
  • trunk/WebCore/ChangeLog

    r51850 r51851  
     12009-12-08  Carol Szabo  <carol.szabo@nokia.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        CSS Counter Nesting still does not work according to the spec.
     6        https://bugs.webkit.org/show_bug.cgi?id=31723
     7
     8        Test: fast/css/counters/nesting.html
     9
     10        * rendering/RenderCounter.cpp:
     11        (WebCore::findPlaceForCounter):
     12        Replaced the faulty counter insertion algorithm with one that works.
     13
    1142009-12-08  John Sullivan  <sullivan@apple.com>
    215
  • trunk/WebCore/rendering/RenderCounter.cpp

    r50966 r51851  
    110110}
    111111
    112 static bool findPlaceForCounter(RenderObject* object, const AtomicString& counterName,
    113     bool isReset, CounterNode*& parent, CounterNode*& previousSibling)
    114 {
    115     // Find the appropriate previous sibling for insertion into the parent node
    116     // by searching in render tree order for a child of the counter.
    117     parent = 0;
     112// - Finds the insertion point for the counter described by counterOwner, isReset and
     113// identifier in the CounterNode tree for identifier and sets parent and
     114// previousSibling accordingly.
     115// - The function returns true if the counter whose insertion point is searched is NOT
     116// the root of the tree.
     117// - The root of the tree is a counter reference that is not in the scope of any other
     118// counter with the same identifier.
     119// - All the counter references with the same identifier as this one that are in
     120// children or subsequent siblings of the renderer that owns the root of the tree
     121// form the rest of of the nodes of the tree.
     122// - The root of the tree is always a reset type reference.
     123// - A subtree rooted at any reset node in the tree is equivalent to all counter
     124// references that are in the scope of the counter or nested counter defined by that
     125// reset node.
     126// - Non-reset CounterNodes cannot have descendants.
     127
     128static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString& identifier, bool isReset, CounterNode*& parent, CounterNode*& previousSibling)
     129{
     130    // We cannot stop searching for counters with the same identifier before we also
     131    // check this renderer, because it may affect the positioning in the tree of our counter.
     132    RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner);
     133    // We check renderers in preOrder from the renderer that our counter is attached to
     134    // towards the begining of the document for counters with the same identifier as the one
     135    // we are trying to find a place for. This is the next renderer to be checked.
     136    RenderObject* currentRenderer = counterOwner->previousInPreOrder();
    118137    previousSibling = 0;
    119     RenderObject* resetCandidate = isReset ? object->parent() : previousSiblingOrParent(object);
    120     RenderObject* prevCounterCandidate = object;
    121     CounterNode* candidateCounter = 0;
    122     // When a reset counter is chosen as candidateCounter, we'll
    123     // decide the new node should be a child of the reset node or a
    124     // sibling or the reset node. This flag controls it.
    125     bool createChildForReset = true;
    126     while ((prevCounterCandidate = prevCounterCandidate->previousInPreOrder())) {
    127         CounterNode* c = makeCounterNode(prevCounterCandidate, counterName, false);
    128         if (prevCounterCandidate == resetCandidate) {
    129             if (!candidateCounter) {
    130                 candidateCounter = c;
    131                 createChildForReset = true;
    132             }
    133             if (candidateCounter) {
    134                 if (createChildForReset && candidateCounter->isReset()) {
    135                     parent = candidateCounter;
    136                     previousSibling = 0;
    137                 } else {
    138                     parent = candidateCounter->parent();
    139                     previousSibling = candidateCounter;
     138    while (currentRenderer) {
     139        CounterNode* currentCounter = makeCounterNode(currentRenderer, identifier, false);
     140        if (searchEndRenderer == currentRenderer) {
     141            // We may be at the end of our search.
     142            if (currentCounter) {
     143                // We have a suitable counter on the EndSearchRenderer.
     144                if (previousSibling) { // But we already found another counter that we come after.
     145                    if (currentCounter->isReset()) {
     146                        // We found a reset counter that is on a renderer that is a sibling of ours or a parent.
     147                        if (isReset && currentRenderer->parent() == counterOwner->parent()) {
     148                            // We are also a reset counter and the previous reset was on a sibling renderer
     149                            // hence we are the next sibling of that counter if that reset is not a root or
     150                            // we are a root node if that reset is a root.
     151                            parent = currentCounter->parent();
     152                            previousSibling = parent ? currentCounter : 0;
     153                            return parent;
     154                        }
     155                        // We are not a reset node or the previous reset must be on an ancestor of our renderer
     156                        // hence we must be a child of that reset counter.
     157                        parent = currentCounter;
     158                        ASSERT(previousSibling->parent() == currentCounter);
     159                        return true;
     160                    }
     161                    // CurrentCounter, the counter at the EndSearchRenderer, is not reset.
     162                    if (!isReset || currentRenderer->parent() != counterOwner->parent()) {
     163                        // If the node we are placing is not reset or we have found a counter that is attached
     164                        // to an ancestor of the placed counter's renderer we know we are a sibling of that node.
     165                        ASSERT(currentCounter->parent() == previousSibling->parent());
     166                        parent = currentCounter->parent();
     167                        return true;
     168                    }
     169                } else {
     170                    // We are at the potential end of the search, but we had no previous sibling candidate
     171                    // In this case we follow pretty much the same logic as above but no ASSERTs about
     172                    // previousSibling, and when we are a sibling of the end counter we must set previousSibling
     173                    // to currentCounter.
     174                    if (currentCounter->isReset()) {
     175                        if (isReset && currentRenderer->parent() == counterOwner->parent()) {
     176                            parent = currentCounter->parent();
     177                            previousSibling = currentCounter;
     178                            return parent;
     179                        }
     180                        parent = currentCounter;
     181                        return true;
     182                    }
     183                    if (!isReset || currentRenderer->parent() != counterOwner->parent()) {
     184                        parent = currentCounter->parent();
     185                        previousSibling = currentCounter;
     186                        return true;
     187                    }
     188                    previousSibling = currentCounter;
    140189                }
    141                 return true;
    142             }
    143             resetCandidate = previousSiblingOrParent(resetCandidate);
    144         } else if (c) {
    145             if (c->isReset()) {
    146                 if (c->parent()) {
    147                     // The new node may be the next sibling of this reset node.
    148                     createChildForReset = false;
    149                     candidateCounter = c;
    150                 } else {
    151                     createChildForReset = true;
    152                     candidateCounter = 0;
    153                 }
    154             } else if (!candidateCounter) {
    155                 createChildForReset = true;
    156                 candidateCounter = c;
    157             }
    158         }
    159     }
    160 
     190            }
     191            // We come here if the previous sibling or parent of our renderer had no
     192            // good counter, or we are a reset node and the counter on the previous sibling
     193            // of our renderer was not a reset counter.
     194            // Set a new goal for the end of the search.
     195            searchEndRenderer = previousSiblingOrParent(currentRenderer);
     196        } else {
     197            // We are searching descendants of a previous sibling of the renderer that the
     198            // counter being placed is attached to.
     199            if (currentCounter) {
     200                // We found a suitable counter.
     201                if (previousSibling) {
     202                    // Since we had a suitable previous counter before, we should only consider this one as our
     203                    // previousSibling if it is a reset counter and hence the current previousSibling is its child.
     204                    if (currentCounter->isReset()) {
     205                        previousSibling = currentCounter;
     206                        // We are no longer interested in previous siblings of the currentRenderer or their children
     207                        // as counters they may have attached cannot be the previous sibling of the counter we are placing.
     208                        currentRenderer = currentRenderer->parent();
     209                        continue;
     210                    }
     211                } else
     212                    previousSibling = currentCounter;
     213                currentRenderer = previousSiblingOrParent(currentRenderer);
     214                continue;
     215            }
     216        }
     217        // This function is designed so that the same test is not done twice in an iteration, except for this one
     218        // which may be done twice in some cases. Rearranging the decision points though, to accommodate this
     219        // performance improvement would create more code duplication than is worthwhile in my oppinion and may further
     220        // impede the readability of this already complex algorithm.
     221        if (previousSibling)
     222            currentRenderer = previousSiblingOrParent(currentRenderer);
     223        else
     224            currentRenderer = currentRenderer->previousInPreOrder();
     225    }
    161226    return false;
    162227}
Note: See TracChangeset for help on using the changeset viewer.