aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlelement.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/htmlelement.rs')
-rw-r--r--components/script/dom/htmlelement.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index ac0f99416c2..00d7a64ed32 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -27,6 +27,7 @@ use crate::dom::htmlframesetelement::HTMLFrameSetElement;
use crate::dom::htmlhtmlelement::HTMLHtmlElement;
use crate::dom::htmlinputelement::{HTMLInputElement, InputType};
use crate::dom::htmllabelelement::HTMLLabelElement;
+use crate::dom::htmltextareaelement::HTMLTextAreaElement;
use crate::dom::node::{document_from_node, window_from_node};
use crate::dom::node::{BindContext, Node, NodeFlags, ShadowIncluding};
use crate::dom::text::Text;
@@ -170,6 +171,11 @@ impl HTMLElementMethods for HTMLElement {
// https://html.spec.whatwg.org/multipage/#dom-hidden
make_bool_setter!(SetHidden, "hidden");
+ // https://html.spec.whatwg.org/multipage/#the-dir-attribute
+ make_getter!(Dir, "dir");
+ // https://html.spec.whatwg.org/multipage/#the-dir-attribute
+ make_setter!(SetDir, "dir");
+
// https://html.spec.whatwg.org/multipage/#globaleventhandlers
global_event_handlers!(NoOnload);
@@ -767,6 +773,48 @@ impl HTMLElement {
})
.count() as u32
}
+
+ // https://html.spec.whatwg.org/multipage/#the-directionality.
+ // returns Some if can infer direction by itself or from child nodes
+ // returns None if requires to go up to parent
+ pub fn directionality(&self) -> Option<String> {
+ let element_direction: &str = &self.Dir();
+
+ if element_direction == "ltr" {
+ return Some("ltr".to_owned());
+ }
+
+ if element_direction == "rtl" {
+ return Some("rtl".to_owned());
+ }
+
+ if let Some(input) = self.downcast::<HTMLInputElement>() {
+ if input.input_type() == InputType::Tel {
+ return Some("ltr".to_owned());
+ }
+ }
+
+ if element_direction == "auto" {
+ if let Some(directionality) = self
+ .downcast::<HTMLInputElement>()
+ .and_then(|input| input.auto_directionality())
+ {
+ return Some(directionality);
+ }
+
+ if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
+ return Some(area.auto_directionality());
+ }
+ }
+
+ // TODO(NeverHappened): Implement condition
+ // If the element's dir attribute is in the auto state OR
+ // If the element is a bdi element and the dir attribute is not in a defined state
+ // (i.e. it is not present or has an invalid value)
+ // Requires bdi element implementation (https://html.spec.whatwg.org/multipage/#the-bdi-element)
+
+ None
+ }
}
impl VirtualMethods for HTMLElement {