Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: Source/core/dom/MarkerPseudoElement.cpp

Issue 778003003: List marker pseudo elements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/layout/LayoutBlockFlow.h"
9 #include "core/layout/LayoutListItem.h"
10 #include "core/layout/LayoutListMarker.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 LayoutObject* MarkerPseudoElement::getParentOfFirstLineBox(LayoutBlockFlow* curr , const LayoutObject* marker)
esprehn 2015/04/20 16:04:08 Remove get prefix.
dsinclair 2015/04/21 20:23:10 Done.
24 {
25 LayoutObject* firstChild = curr->firstChild();
26 if (!firstChild)
27 return nullptr;
28
29 bool inQuirksMode = curr->document().inQuirksMode();
30 for (LayoutObject* currChild = firstChild; currChild; currChild = currChild- >nextSibling()) {
31 if (currChild == marker)
32 continue;
33
34 if (currChild->isInline() && (!currChild->isLayoutInline() || curr->gene ratesLineBoxesForInlineChild(currChild)))
35 return curr;
36
37 if (currChild->isFloating() || currChild->isOutOfFlowPositioned())
38 continue;
39
40 if (!currChild->isLayoutBlockFlow() || (currChild->isBox() && toLayoutBo x(currChild)->isWritingModeRoot()))
41 break;
42
43 if (curr->isListItem() && inQuirksMode && currChild->node()
44 && (isHTMLUListElement(*currChild->node()) || isHTMLOListElement(*cu rrChild->node())))
45 break;
46
47 if (LayoutObject* lineBox = getParentOfFirstLineBox(toLayoutBlockFlow(cu rrChild), marker))
48 return lineBox;
49 }
50
51 return nullptr;
52 }
53
54 PassRefPtr<ComputedStyle> MarkerPseudoElement::customStyleForLayoutObject()
55 {
56 if (!layoutObject())
57 return nullptr;
58
59 LayoutObject* parent = layoutObject()->parent();
60 if (!parent)
61 return nullptr;
62
63 return styleForListMarkerLayoutObject(*parent, layoutObject()->style());
esprehn 2015/04/20 16:04:08 This isn't right, you're rebuilding what is Inher
dsinclair 2015/04/21 20:23:10 I'm not sure I understand, what is the correct way
64 }
65
66 PassRefPtr<ComputedStyle> MarkerPseudoElement::styleForListMarkerLayoutObject(La youtObject& parent, const ComputedStyle* style)
67 {
68 RefPtr<ComputedStyle> newStyle = ComputedStyle::create();
69
70 // The marker always inherits from the list item, regardless of where it mig ht end
71 // up (e.g., in some deeply nested line box). See CSS3 spec.
72 newStyle->inheritFrom(*parent.style());
73 if (style) {
74 // Reuse the current margins. Otherwise resetting the margins to initial values
75 // would trigger unnecessary layout.
76 newStyle->setMarginStart(style->marginStart());
77 newStyle->setMarginEnd(style->marginRight());
78 }
79 return newStyle;
80 }
81
82 LayoutObject* MarkerPseudoElement::firstNonMarkerChild(LayoutObject* parent)
83 {
84 LayoutObject* result = parent->slowFirstChild();
85 while (result && result->isListMarker())
86 result = result->nextSibling();
87 return result;
88 }
89
90 LayoutObject* MarkerPseudoElement::createLayoutObject(const ComputedStyle& style )
91 {
92 ASSERT(parentElement()->layoutObject());
93 LayoutListMarker* marker = new LayoutListMarker(this, toLayoutListItem(paren tElement()->layoutObject()));
94 marker->setStyle(ComputedStyle::clone(style));
95 return marker;
96 }
97
98 void MarkerPseudoElement::attachListMarkerLayoutObject()
99 {
100 LayoutListItem* parentLayoutObject = toLayoutListItem(parentElement()->layou tObject());
101 ASSERT(parentLayoutObject);
102 ASSERT(layoutObject());
103
104 LayoutListMarker* marker = toLayoutListMarker(layoutObject());
105 LayoutObject* markerParent = marker->parent();
106
107 LayoutObject* insertionLayoutObject = MarkerPseudoElement::getParentOfFirstL ineBox(parentLayoutObject, marker);
108
109 // We didn't find any line boxes so make the insertion point the LI layoutOb ject.
110 if (!insertionLayoutObject)
111 insertionLayoutObject = parentLayoutObject;
112 ASSERT(insertionLayoutObject);
113
114 // Check if we're already inserted into the right parent as the first child.
115 if (markerParent && marker == markerParent->slowFirstChild()
116 && (markerParent == insertionLayoutObject || markerParent == insertionLa youtObject->slowFirstChild()))
117 return;
118
119 marker->remove();
120 insertionLayoutObject->addChild(marker, MarkerPseudoElement::firstNonMarkerC hild(insertionLayoutObject));
121 marker->updateMarginsAndContent();
122
123 // If markerParent is an anonymous block with no children, destroy it.
124 if (markerParent && markerParent->isAnonymousBlock() && !toLayoutBlock(marke rParent)->firstChild() && !toLayoutBlock(markerParent)->continuation())
125 markerParent->destroy();
126
127 if (marker->isInside())
128 parentLayoutObject->containingBlock()->updateLogicalWidth();
129 }
130
131 void MarkerPseudoElement::attach(const AttachContext& context)
132 {
133 PseudoElement::attach(context);
134 ASSERT(layoutObject());
135
136 LayoutListMarker* marker = toLayoutListMarker(layoutObject());
137
138 RefPtr<ComputedStyle> newStyle = MarkerPseudoElement::styleForListMarkerLayo utObject(*(marker->mutableListItem()), marker->style());
139 marker->setStyle(newStyle.release());
140
141 attachListMarkerLayoutObject();
142 }
143
144 void MarkerPseudoElement::didRecalcStyle(StyleRecalcChange)
145 {
146 attachListMarkerLayoutObject();
147 }
148
149 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698