Implement dirname for form submit and directionality for element

This commit is contained in:
Dmitry Kolupaev 2020-01-28 10:34:10 +03:00
parent 6bc4a7df24
commit ef49f2e0eb
14 changed files with 178 additions and 19 deletions

View file

@ -75,6 +75,7 @@ use std::ptr::NonNull;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style::str::{split_commas, str_join};
use unicode_bidi::{bidi_class, BidiClass};
const DEFAULT_SUBMIT_VALUE: &'static str = "Submit";
const DEFAULT_RESET_VALUE: &'static str = "Reset";
@ -327,6 +328,41 @@ impl HTMLInputElement {
)
}
pub fn directionality(&self, element_direction: &str) -> String {
match self.input_type() {
InputType::Tel => return "ltr".to_owned(),
InputType::Text | InputType::Search | InputType::Url | InputType::Email => {
if element_direction == "auto" {
let value: String = self.Value().to_string();
return HTMLInputElement::auto_directionality(&value);
}
},
_ => {},
}
return "ltr".to_owned();
}
pub fn auto_directionality(value: &str) -> String {
if HTMLInputElement::first_strong_character_is_rtl(value) {
"rtl".to_owned()
} else {
"ltr".to_owned()
}
}
fn first_strong_character_is_rtl(value: &str) -> bool {
for ch in value.chars() {
return match bidi_class(ch) {
BidiClass::L => false,
BidiClass::AL => true,
BidiClass::R => true,
_ => continue,
};
}
false
}
// https://html.spec.whatwg.org/multipage/#dom-input-value
// https://html.spec.whatwg.org/multipage/#concept-input-apply
fn value_mode(&self) -> ValueMode {