1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 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#ifndef RenderListItem_h
24#define RenderListItem_h
25
26#include "RenderBlockFlow.h"
27#include "RenderPtr.h"
28
29namespace WebCore {
30
31class HTMLOListElement;
32class RenderListMarker;
33
34class RenderListItem final : public RenderBlockFlow {
35public:
36    RenderListItem(Element&, PassRef<RenderStyle>);
37    Element& element() const { return toElement(nodeForNonAnonymous()); }
38
39    int value() const { if (!m_isValueUpToDate) updateValueNow(); return m_value; }
40    void updateValue();
41
42    bool hasExplicitValue() const { return m_hasExplicitValue; }
43    int explicitValue() const { return m_explicitValue; }
44    void setExplicitValue(int value);
45    void clearExplicitValue();
46
47    void setNotInList(bool notInList) { m_notInList = notInList; }
48    bool notInList() const { return m_notInList; }
49
50    const String& markerText() const;
51    String markerTextWithSuffix() const;
52
53    void updateListMarkerNumbers();
54
55    static void updateItemValuesForOrderedList(const HTMLOListElement*);
56    static unsigned itemCountForOrderedList(const HTMLOListElement*);
57
58private:
59    virtual const char* renderName() const override { return "RenderListItem"; }
60
61    virtual bool isListItem() const override { return true; }
62
63    virtual void willBeDestroyed() override;
64
65    virtual void insertedIntoTree() override;
66    virtual void willBeRemovedFromTree() override;
67
68    virtual bool isEmpty() const override;
69    virtual void paint(PaintInfo&, const LayoutPoint&) override;
70
71    virtual void layout() override;
72
73    void positionListMarker();
74
75    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
76
77    virtual bool requiresForcedStyleRecalcPropagation() const override { return true; }
78
79    virtual void addOverflowFromChildren() override;
80    virtual void computePreferredLogicalWidths() override;
81
82    void insertOrMoveMarkerRendererIfNeeded();
83    inline int calcValue() const;
84    void updateValueNow() const;
85    void explicitValueChanged();
86
87    int m_explicitValue;
88    RenderPtr<RenderListMarker> m_marker;
89    mutable int m_value;
90
91    bool m_hasExplicitValue : 1;
92    mutable bool m_isValueUpToDate : 1;
93    bool m_notInList : 1;
94};
95
96RENDER_OBJECT_TYPE_CASTS(RenderListItem, isListItem())
97
98} // namespace WebCore
99
100#endif // RenderListItem_h
101