Skip to content

Commit

Permalink
Implement step 5.13 for dirname correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Feb 24, 2020
1 parent 6188116 commit ab2aeb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
43 changes: 21 additions & 22 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -951,17 +951,6 @@ impl HTMLFormElement {
HTMLElementTypeId::HTMLInputElement => {
let input = child.downcast::<HTMLInputElement>().unwrap();
data_set.append(&mut input.form_datums(submitter, encoding));

let input_element = child.downcast::<Element>().unwrap();
let dirname: DOMString = input.DirName();
if !dirname.is_empty() {
let directionality = DOMString::from(input_element.directionality());
data_set.push(FormDatum {
ty: input.Type().clone(),
name: dirname.clone(),
value: FormDatumValue::String(directionality),
});
}
},
HTMLElementTypeId::HTMLButtonElement => {
let button = child.downcast::<HTMLButtonElement>().unwrap();
Expand All @@ -987,21 +976,31 @@ impl HTMLFormElement {
value: FormDatumValue::String(textarea.Value()),
});
}

let area_element = child.downcast::<Element>().unwrap();
let dirname: DOMString = textarea.DirName();
if !dirname.is_empty() {
let directionality = DOMString::from(area_element.directionality());
data_set.push(FormDatum {
ty: textarea.Type().clone(),
name: dirname.clone(),
value: FormDatumValue::String(directionality),
});
}
},
_ => (),
}
}

// Step: 5.13. Add an entry if element has dirname attribute
// An element can only have a dirname attribute if it is a textarea element
// or an input element whose type attribute is in either the Text state or the Search state
let child_element = child.downcast::<Element>().unwrap();
let input_matches = child_element
.downcast::<HTMLInputElement>()
.map(|input| {
input.input_type() == InputType::Text || input.input_type() == InputType::Search
})
.unwrap_or(false);
let textarea_matches = child_element.is::<HTMLTextAreaElement>();
let dirname = child_element.get_string_attribute(&local_name!("dirname"));
if (input_matches || textarea_matches) && !dirname.is_empty() {
let dir = DOMString::from(child_element.directionality());
data_set.push(FormDatum {
ty: DOMString::from("string"),
name: dirname.clone(),
value: FormDatumValue::String(dir),
});
}
}
data_set
}
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -339,14 +339,14 @@ impl HTMLInputElement {
}

pub fn directionality_from_value(value: &str) -> String {
if HTMLInputElement::first_strong_character_is_rtl(value) {
if HTMLInputElement::is_first_strong_character_rtl(value) {
"rtl".to_owned()
} else {
"ltr".to_owned()
}
}

fn first_strong_character_is_rtl(value: &str) -> bool {
fn is_first_strong_character_rtl(value: &str) -> bool {
for ch in value.chars() {
return match bidi_class(ch) {
BidiClass::L => false,
Expand Down

0 comments on commit ab2aeb6

Please sign in to comment.