aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlinputelement.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/htmlinputelement.rs')
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 441206c9dad..a5fefa095ae 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -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,36 @@ impl HTMLInputElement {
)
}
+ pub fn auto_directionality(&self) -> Option<String> {
+ match self.input_type() {
+ InputType::Text | InputType::Search | InputType::Url | InputType::Email => {
+ let value: String = self.Value().to_string();
+ Some(HTMLInputElement::directionality_from_value(&value))
+ },
+ _ => None,
+ }
+ }
+
+ pub fn directionality_from_value(value: &str) -> String {
+ if HTMLInputElement::is_first_strong_character_rtl(value) {
+ "rtl".to_owned()
+ } else {
+ "ltr".to_owned()
+ }
+ }
+
+ fn is_first_strong_character_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 {