1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "RenderBlockFlow.h"
26#include "RenderListMarker.h"
27
28namespace WebCore {
29
30class HTMLOListElement;
31
32class RenderListItem final : public RenderBlockFlow {
33 WTF_MAKE_ISO_ALLOCATED(RenderListItem);
34public:
35 RenderListItem(Element&, RenderStyle&&);
36 virtual ~RenderListItem();
37
38 Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
39
40 int value() const;
41 void updateValue();
42
43 Optional<int> explicitValue() const { return m_valueWasSetExplicitly ? m_value : WTF::nullopt; }
44 void setExplicitValue(Optional<int>);
45
46 void setNotInList(bool notInList) { m_notInList = notInList; }
47 bool notInList() const { return m_notInList; }
48
49 WEBCORE_EXPORT const String& markerText() const;
50 String markerTextWithSuffix() const;
51
52 void updateListMarkerNumbers();
53
54 static void updateItemValuesForOrderedList(const HTMLOListElement&);
55 static unsigned itemCountForOrderedList(const HTMLOListElement&);
56
57 RenderStyle computeMarkerStyle() const;
58
59 RenderListMarker* markerRenderer() const { return m_marker.get(); }
60 void setMarkerRenderer(RenderListMarker& marker) { m_marker = makeWeakPtr(marker); }
61
62 bool isInReversedOrderedList() const;
63
64private:
65
66 const char* renderName() const final { return "RenderListItem"; }
67
68 bool isListItem() const final { return true; }
69
70 void insertedIntoTree() final;
71 void willBeRemovedFromTree() final;
72
73 void paint(PaintInfo&, const LayoutPoint&) final;
74
75 void layout() final;
76
77 void positionListMarker();
78
79 void addOverflowFromChildren() final;
80 void computePreferredLogicalWidths() final;
81
82 void updateValueNow() const;
83 void explicitValueChanged();
84
85 WeakPtr<RenderListMarker> m_marker;
86 mutable Optional<int> m_value;
87 bool m_valueWasSetExplicitly { false };
88 bool m_notInList { false };
89};
90
91bool isHTMLListElement(const Node&);
92
93inline int RenderListItem::value() const
94{
95 if (!m_value)
96 updateValueNow();
97 return m_value.value();
98}
99
100} // namespace WebCore
101
102SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListItem, isListItem())
103