summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/custom/element_internals.h
blob: dc4133e64e71b762202fbfd636e69afe168fbcce (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
132
133
134
135
136
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CUSTOM_ELEMENT_INTERNALS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CUSTOM_ELEMENT_INTERNALS_H_

#include "third_party/blink/renderer/bindings/core/v8/file_or_usv_string_or_form_data.h"
#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/core/html/forms/labels_node_list.h"
#include "third_party/blink/renderer/core/html/forms/listed_element.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"

namespace blink {

class DOMTokenList;
class HTMLElement;
class ValidityStateFlags;

class CORE_EXPORT ElementInternals : public ScriptWrappable,
                                     public ListedElement {
  DEFINE_WRAPPERTYPEINFO();
  USING_GARBAGE_COLLECTED_MIXIN(ElementInternals);

 public:
  ElementInternals(HTMLElement& target);
  void Trace(Visitor* visitor) override;

  HTMLElement& Target() const { return *target_; }
  void DidUpgrade();

  using ControlValue = FileOrUSVStringOrFormData;
  // IDL attributes/operations
  void setFormValue(const ControlValue& value, ExceptionState& exception_state);
  void setFormValue(const ControlValue& value,
                    const ControlValue& state,
                    ExceptionState& exception_state);
  HTMLFormElement* form(ExceptionState& exception_state) const;
  void setValidity(ValidityStateFlags* flags, ExceptionState& exception_state);
  void setValidity(ValidityStateFlags* flags,
                   const String& message,
                   ExceptionState& exception_state);
  void setValidity(ValidityStateFlags* flags,
                   const String& message,
                   Element* anchor,
                   ExceptionState& exception_state);
  bool willValidate(ExceptionState& exception_state) const;
  ValidityState* validity(ExceptionState& exception_state);
  String ValidationMessageForBinding(ExceptionState& exception_state);
  bool checkValidity(ExceptionState& exception_state);
  bool reportValidity(ExceptionState& exception_state);
  LabelsNodeList* labels(ExceptionState& exception_state);
  DOMTokenList* states();

  bool HasState(const AtomicString& state) const;

  // We need these functions because we are reflecting ARIA attributes.
  // See dom/aria_attributes.idl.
  const AtomicString& FastGetAttribute(const QualifiedName&) const;
  void setAttribute(const QualifiedName& attribute, const AtomicString& value);

  void SetElementAttribute(const QualifiedName& name, Element* element);
  Element* GetElementAttribute(const QualifiedName& name);
  base::Optional<HeapVector<Member<Element>>> GetElementArrayAttribute(
      const QualifiedName& name) const;
  void SetElementArrayAttribute(
      const QualifiedName& name,
      const base::Optional<HeapVector<Member<Element>>>& elements);
  // TODO(crbug.com/1060971): Remove |is_null| version.
  HeapVector<Member<Element>> GetElementArrayAttribute(
      const QualifiedName& name,
      bool is_null);  // DEPRECATED
  void SetElementArrayAttribute(const QualifiedName&,
                                HeapVector<Member<Element>>,
                                bool is_null);  // DEPRECATED
  bool HasAttribute(const QualifiedName& attribute) const;
  const HashMap<QualifiedName, AtomicString>& GetAttributes() const;

 private:
  bool IsTargetFormAssociated() const;

  // ListedElement overrides:
  bool IsFormControlElement() const override;
  bool IsElementInternals() const override;
  bool IsEnumeratable() const override;
  void AppendToFormData(FormData& form_data) override;
  void DidChangeForm() override;
  bool HasBadInput() const override;
  bool PatternMismatch() const override;
  bool RangeOverflow() const override;
  bool RangeUnderflow() const override;
  bool StepMismatch() const override;
  bool TooLong() const override;
  bool TooShort() const override;
  bool TypeMismatch() const override;
  bool ValueMissing() const override;
  bool CustomError() const override;
  String validationMessage() const override;
  String ValidationSubMessage() const override;
  Element& ValidationAnchor() const override;
  void DisabledStateMightBeChanged() override;
  bool ClassSupportsStateRestore() const override;
  bool ShouldSaveAndRestoreFormControlState() const override;
  FormControlState SaveFormControlState() const override;
  void RestoreFormControlState(const FormControlState& state) override;

  Member<HTMLElement> target_;

  ControlValue value_;
  ControlValue state_;
  bool is_disabled_ = false;
  Member<ValidityStateFlags> validity_flags_;
  Member<Element> validation_anchor_;

  Member<DOMTokenList> custom_states_;

  HashMap<QualifiedName, AtomicString> accessibility_semantics_map_;

  // See
  // https://whatpr.org/html/3917/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:element
  HeapHashMap<QualifiedName, Member<HeapVector<Member<Element>>>>
      explicitly_set_attr_elements_map_;

  DISALLOW_COPY_AND_ASSIGN(ElementInternals);
};

template <>
struct DowncastTraits<ElementInternals> {
  static bool AllowFrom(const ListedElement& listed_element) {
    return listed_element.IsElementInternals();
  }
};

}  // namespace blink
#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CUSTOM_ELEMENT_INTERNALS_H_