mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #25629 - pshaughn:reflect_translate, r=jdm
Implement "translate" attribute This attribute is almost a straightforward enumerated one, but the getter value inherits from parents when the content attribute is absent, even when the parents are non-HTML elements. This initial commit is using LocalName::from on a static string; once html5ever has a release with "translate" in the built-in local name list, a small change will be needed. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #25628 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
e3a2301efe
11 changed files with 38 additions and 44 deletions
|
@ -523,6 +523,25 @@ impl Element {
|
|||
debug_assert!(false, "Trying to detach a non-attached shadow root");
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#translation-mode
|
||||
pub fn is_translate_enabled(&self) -> bool {
|
||||
// TODO change this to local_name! when html5ever updates
|
||||
let name = &LocalName::from("translate");
|
||||
if self.has_attribute(name) {
|
||||
match &*self.get_string_attribute(name) {
|
||||
"yes" | "" => return true,
|
||||
"no" => return false,
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
if let Some(parent) = self.upcast::<Node>().GetParentNode() {
|
||||
if let Some(elem) = parent.downcast::<Element>() {
|
||||
return elem.is_translate_enabled();
|
||||
}
|
||||
}
|
||||
true // whatwg/html#5239
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
|
|
@ -546,6 +546,23 @@ impl HTMLElementMethods for HTMLElement {
|
|||
// Step 7.
|
||||
Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-translate
|
||||
fn Translate(&self) -> bool {
|
||||
self.upcast::<Element>().is_translate_enabled()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-translate
|
||||
fn SetTranslate(&self, yesno: bool) {
|
||||
self.upcast::<Element>().set_string_attribute(
|
||||
// TODO change this to local_name! when html5ever updates
|
||||
&LocalName::from("translate"),
|
||||
match yesno {
|
||||
true => DOMString::from("yes"),
|
||||
false => DOMString::from("no"),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn append_text_node_to_fragment(document: &Document, fragment: &DocumentFragment, text: String) {
|
||||
|
|
|
@ -12,8 +12,8 @@ interface HTMLElement : Element {
|
|||
attribute DOMString title;
|
||||
[CEReactions]
|
||||
attribute DOMString lang;
|
||||
// [CEReactions]
|
||||
// attribute boolean translate;
|
||||
[CEReactions]
|
||||
attribute boolean translate;
|
||||
// [CEReactions]
|
||||
// attribute DOMString dir;
|
||||
readonly attribute DOMStringMap dataset;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue