فهرست منبع

LibWeb: Implement indeterminate IDL attribute in HTMLInputElement

Srikavin Ramkumar 2 سال پیش
والد
کامیت
d177d83b44

+ 10 - 1
Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -107,6 +107,13 @@ void HTMLInputElement::set_checked_binding(bool checked)
     }
 }
 
+// https://html.spec.whatwg.org/multipage/input.html#dom-input-indeterminate
+void HTMLInputElement::set_indeterminate(bool value)
+{
+    // On setting, it must be set to the new value. It has no effect except for changing the appearance of checkbox controls.
+    m_indeterminate = value;
+}
+
 // https://html.spec.whatwg.org/multipage/input.html#dom-input-files
 JS::GCPtr<FileAPI::FileList> HTMLInputElement::files()
 {
@@ -797,14 +804,15 @@ void HTMLInputElement::set_checked_within_group()
 void HTMLInputElement::legacy_pre_activation_behavior()
 {
     m_before_legacy_pre_activation_behavior_checked = checked();
+    m_before_legacy_pre_activation_behavior_indeterminate = indeterminate();
 
     // 1. If this element's type attribute is in the Checkbox state, then set
     // this element's checkedness to its opposite value (i.e. true if it is
     // false, false if it is true) and set this element's indeterminate IDL
     // attribute to false.
-    // FIXME: Set indeterminate to false when that exists.
     if (type_state() == TypeAttributeState::Checkbox) {
         set_checked(!checked(), ChangeSource::User);
+        set_indeterminate(false);
     }
 
     // 2. If this element's type attribute is in the Radio Button state, then
@@ -834,6 +842,7 @@ void HTMLInputElement::legacy_cancelled_activation_behavior()
     // to the values they had before the legacy-pre-activation behavior was run.
     if (type_state() == TypeAttributeState::Checkbox) {
         set_checked(m_before_legacy_pre_activation_behavior_checked, ChangeSource::Programmatic);
+        set_indeterminate(m_before_legacy_pre_activation_behavior_indeterminate);
     }
 
     // 2. If this element 's type attribute is in the Radio Button state, then

+ 7 - 0
Userland/Libraries/LibWeb/HTML/HTMLInputElement.h

@@ -78,6 +78,9 @@ public:
     bool checked_binding() const { return checked(); }
     void set_checked_binding(bool);
 
+    bool indeterminate() const { return m_indeterminate; };
+    void set_indeterminate(bool);
+
     void did_edit_text_node(Badge<BrowsingContext>);
 
     JS::GCPtr<FileAPI::FileList> files();
@@ -156,6 +159,9 @@ private:
     JS::GCPtr<DOM::Text> m_text_node;
     bool m_checked { false };
 
+    // https://html.spec.whatwg.org/multipage/input.html#dom-input-indeterminate
+    bool m_indeterminate { false };
+
     // https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag
     bool m_dirty_checkedness { false };
 
@@ -164,6 +170,7 @@ private:
 
     // https://html.spec.whatwg.org/multipage/input.html#the-input-element:legacy-pre-activation-behavior
     bool m_before_legacy_pre_activation_behavior_checked { false };
+    bool m_before_legacy_pre_activation_behavior_indeterminate { false };
     JS::GCPtr<HTMLInputElement> m_legacy_pre_activation_behavior_checked_element_in_group;
 
     // https://html.spec.whatwg.org/multipage/input.html#concept-input-type-file-selected

+ 1 - 0
Userland/Libraries/LibWeb/HTML/HTMLInputElement.idl

@@ -22,6 +22,7 @@ interface HTMLInputElement : HTMLElement {
     [Reflect=value] attribute DOMString defaultValue;
 
     attribute DOMString type;
+    attribute boolean indeterminate;
 
     [LegacyNullToEmptyString] attribute DOMString value;