summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/html_li_element.cc
blob: 30f2e50b133499878dc5fcb4e9fd9db682c9d1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#include "third_party/blink/renderer/core/html/html_li_element.h"

#include "third_party/blink/renderer/core/css_property_names.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h"
#include "third_party/blink/renderer/core/html/list_item_ordinal.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html_names.h"

namespace blink {

using namespace HTMLNames;

inline HTMLLIElement::HTMLLIElement(Document& document)
    : HTMLElement(liTag, document) {}

DEFINE_NODE_FACTORY(HTMLLIElement)

bool HTMLLIElement::IsPresentationAttribute(const QualifiedName& name) const {
  if (name == typeAttr)
    return true;
  return HTMLElement::IsPresentationAttribute(name);
}

CSSValueID ListTypeToCSSValueID(const AtomicString& value) {
  if (value == "a")
    return CSSValueLowerAlpha;
  if (value == "A")
    return CSSValueUpperAlpha;
  if (value == "i")
    return CSSValueLowerRoman;
  if (value == "I")
    return CSSValueUpperRoman;
  if (value == "1")
    return CSSValueDecimal;
  if (DeprecatedEqualIgnoringCase(value, "disc"))
    return CSSValueDisc;
  if (DeprecatedEqualIgnoringCase(value, "circle"))
    return CSSValueCircle;
  if (DeprecatedEqualIgnoringCase(value, "square"))
    return CSSValueSquare;
  if (DeprecatedEqualIgnoringCase(value, "none"))
    return CSSValueNone;
  return CSSValueInvalid;
}

void HTMLLIElement::CollectStyleForPresentationAttribute(
    const QualifiedName& name,
    const AtomicString& value,
    MutableCSSPropertyValueSet* style) {
  if (name == typeAttr) {
    CSSValueID type_value = ListTypeToCSSValueID(value);
    if (type_value != CSSValueInvalid)
      AddPropertyToPresentationAttributeStyle(style, CSSPropertyListStyleType,
                                              type_value);
  } else {
    HTMLElement::CollectStyleForPresentationAttribute(name, value, style);
  }
}

void HTMLLIElement::ParseAttribute(const AttributeModificationParams& params) {
  if (params.name == valueAttr) {
    if (ListItemOrdinal* ordinal = ListItemOrdinal::Get(*this))
      ParseValue(params.new_value, ordinal);
  } else {
    HTMLElement::ParseAttribute(params);
  }
}

void HTMLLIElement::AttachLayoutTree(AttachContext& context) {
  HTMLElement::AttachLayoutTree(context);

  if (ListItemOrdinal* ordinal = ListItemOrdinal::Get(*this)) {
    DCHECK(!GetDocument().ChildNeedsDistributionRecalc());

    // Find the enclosing list node.
    Element* list_node = nullptr;
    Element* current = this;
    while (!list_node) {
      current = LayoutTreeBuilderTraversal::ParentElement(*current);
      if (!current)
        break;
      if (IsHTMLUListElement(*current) || IsHTMLOListElement(*current))
        list_node = current;
    }

    // If we are not in a list, tell the layoutObject so it can position us
    // inside.  We don't want to change our style to say "inside" since that
    // would affect nested nodes.
    if (!list_node)
      ordinal->SetNotInList(true, *this);

    ParseValue(FastGetAttribute(valueAttr), ordinal);
  }
}

void HTMLLIElement::ParseValue(const AtomicString& value,
                               ListItemOrdinal* ordinal) {
  DCHECK(ListItemOrdinal::IsListItem(*this));

  int requested_value = 0;
  if (ParseHTMLInteger(value, requested_value))
    ordinal->SetExplicitValue(requested_value, *this);
  else
    ordinal->ClearExplicitValue(*this);
}

}  // namespace blink