Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/dom/MarkerPseudoElement.h" | |
| 7 | |
| 8 #include "core/rendering/RenderBlockFlow.h" | |
| 9 #include "core/rendering/RenderListItem.h" | |
| 10 #include "core/rendering/RenderListMarker.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 MarkerPseudoElement::MarkerPseudoElement(Element* parent) | |
| 15 : PseudoElement(parent, MARKER) | |
| 16 { | |
| 17 } | |
| 18 | |
| 19 MarkerPseudoElement::~MarkerPseudoElement() | |
| 20 { | |
| 21 } | |
| 22 | |
| 23 RenderObject* MarkerPseudoElement::getParentOfFirstLineBox(RenderBlockFlow* curr , const RenderObject* marker) | |
| 24 { | |
| 25 RenderObject* firstChild = curr->firstChild(); | |
| 26 if (!firstChild) | |
| 27 return nullptr; | |
| 28 | |
| 29 bool inQuirksMode = curr->document().inQuirksMode(); | |
| 30 for (RenderObject* currChild = firstChild; currChild; currChild = currChild- >nextSibling()) { | |
| 31 if (currChild == marker) | |
| 32 continue; | |
| 33 | |
| 34 if (currChild->isInline() && (!currChild->isRenderInline() || curr->gene ratesLineBoxesForInlineChild(currChild))) | |
| 35 return curr; | |
| 36 | |
| 37 if (currChild->isFloating() || currChild->isOutOfFlowPositioned()) | |
| 38 continue; | |
| 39 | |
| 40 if (!currChild->isRenderBlockFlow() || (currChild->isBox() && toRenderBo x(currChild)->isWritingModeRoot())) | |
| 41 break; | |
| 42 | |
| 43 if (curr->isListItem() && inQuirksMode && currChild->node() && | |
| 44 (isHTMLUListElement(*currChild->node()) || isHTMLOListElement(*currC hild->node()))) | |
| 45 break; | |
| 46 | |
| 47 if (RenderObject* lineBox = getParentOfFirstLineBox(toRenderBlockFlow(cu rrChild), marker)) | |
| 48 return lineBox; | |
| 49 } | |
| 50 | |
| 51 return nullptr; | |
| 52 } | |
|
Julien - ping for review
2014/12/05 19:44:03
Does that code really still apply with a pseudo?
dsinclair
2015/01/23 20:46:36
Yes, we still have to put the renderer somewhere.
| |
| 53 | |
| 54 RenderObject* MarkerPseudoElement::firstNonMarkerChild(RenderObject* parent) | |
| 55 { | |
| 56 RenderObject* result = parent->slowFirstChild(); | |
| 57 while (result && result->isListMarker()) | |
| 58 result = result->nextSibling(); | |
| 59 return result; | |
| 60 } | |
| 61 | |
| 62 RenderObject* MarkerPseudoElement::createRenderer(RenderStyle* style) | |
| 63 { | |
| 64 ASSERT(parentElement()->renderer()); | |
| 65 RenderListMarker* marker = RenderListMarker::createAnonymous(toRenderListIte m(parentElement()->renderer())); | |
| 66 marker->setStyle(style); | |
| 67 return marker; | |
| 68 } | |
| 69 | |
| 70 void MarkerPseudoElement::attachListMarkerRenderer() | |
| 71 { | |
| 72 RenderListItem* parentRenderer = toRenderListItem(parentElement()->renderer( )); | |
| 73 ASSERT(parentRenderer); | |
| 74 ASSERT(parentRenderer->isListItem()); | |
|
Julien - ping for review
2014/12/05 19:44:03
*cough, cough* toRenderListItem(parentRenderer) *c
dsinclair
2015/01/23 20:46:36
Done.
| |
| 75 | |
| 76 ASSERT(renderer()); | |
|
Julien - ping for review
2014/12/05 19:44:04
Probably bad assumption no? How about changing dis
dsinclair
2015/01/23 20:46:36
I believe this is safe, if we have a pseudo elemen
| |
| 77 RenderListMarker* marker = toRenderListMarker(renderer()); | |
| 78 | |
| 79 RenderObject* markerParent = marker->parent(); | |
| 80 ASSERT(markerParent); | |
|
dsinclair
2015/01/23 20:46:36
This one, on the other hand, is a bad assumption.
| |
| 81 | |
| 82 RenderObject* insertionRenderer = MarkerPseudoElement::getParentOfFirstLineB ox(parentRenderer, marker); | |
| 83 | |
| 84 // We didn't find any line boxes so make the insertion point the LI renderer . | |
| 85 if (!insertionRenderer) | |
| 86 insertionRenderer = parentRenderer; | |
| 87 ASSERT(insertionRenderer); | |
| 88 | |
| 89 // Check if we're already inserted into the right parent as the first child. | |
| 90 if (marker == markerParent->slowFirstChild() && | |
| 91 (markerParent == insertionRenderer || markerParent == insertionRenderer- >slowFirstChild())) | |
| 92 return; | |
| 93 | |
| 94 marker->remove(); | |
| 95 insertionRenderer->addChild(marker, MarkerPseudoElement::firstNonMarkerChild (insertionRenderer)); | |
| 96 marker->updateMarginsAndContent(); | |
| 97 | |
| 98 // If markerParent is an anonymous block with no children, destroy it. | |
| 99 if (markerParent->isAnonymousBlock() && !toRenderBlock(markerParent)->firstC hild() && !toRenderBlock(markerParent)->continuation()) | |
| 100 markerParent->destroy(); | |
| 101 | |
| 102 if (marker->isInside()) | |
| 103 parentRenderer->containingBlock()->updateLogicalWidth(); | |
| 104 } | |
| 105 | |
| 106 void MarkerPseudoElement::attach(const AttachContext& context) | |
| 107 { | |
| 108 PseudoElement::attach(context); | |
| 109 ASSERT(renderer()); | |
|
Julien - ping for review
2014/12/05 19:44:03
Same comment, is this assumption correct?
dsinclair
2015/01/23 20:46:36
As above.
| |
| 110 toRenderListMarker(renderer())->listItemStyleDidChange(); | |
| 111 } | |
| 112 | |
| 113 void MarkerPseudoElement::didRecalcStyle(StyleRecalcChange) | |
| 114 { | |
| 115 attachListMarkerRenderer(); | |
| 116 } | |
| 117 | |
| 118 } // namespace blink | |
| OLD | NEW |