aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2020-01-07 18:13:40 -0500
committerGitHub <noreply@github.com>2020-01-07 18:13:40 -0500
commite185423fc7b4e6b69fb27569c1c6ec8d5635d2eb (patch)
tree513c636acec0f4c221635b51894d7e73c68c2c9d /components/script/dom/attr.rs
parent709e06928a3cd09426a54cab66aaa8557d739239 (diff)
parent67e9fc8c0ad5dd54a9947a3048f588a8ea55458e (diff)
downloadservo-e185423fc7b4e6b69fb27569c1c6ec8d5635d2eb.tar.gz
servo-e185423fc7b4e6b69fb27569c1c6ec8d5635d2eb.zip
Auto merge of #25310 - pshaughn:attr_node, r=Manishearth
Attr is a Node, with consequences for many Node methods <!-- Please describe your changes on the following line: --> Attr is now a Node, as current WHATWG specs require. I think I did some unidiomatic things to make compareDocumentPosition work and it could use a look by someone more familiar with how to write concise Rust code. I also think the new cases in compareDocumentPosition lack tests; it is possible to compare the position of two attributes, or of an attribute and an element, and I don't think any tests are exercising that functionality. --- <!-- 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 #25124 <!-- Either: --> - [ ] There are tests for these changes (existing cases of Node methods are well-tested, and there is a WPT test specifically for whether Attr is Node, but I'm not sure about new Node method cases) <!-- 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. -->
Diffstat (limited to 'components/script/dom/attr.rs')
-rw-r--r--components/script/dom/attr.rs48
1 files changed, 15 insertions, 33 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 886f62718e9..a25fcac3667 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -5,15 +5,14 @@
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods};
use crate::dom::bindings::inheritance::Castable;
-use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::customelementregistry::CallbackReaction;
+use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::mutationobserver::{Mutation, MutationObserver};
use crate::dom::node::Node;
use crate::dom::virtualmethods::vtable_for;
-use crate::dom::window::Window;
use crate::script_thread::ScriptThread;
use devtools_traits::AttrInfo;
use dom_struct::dom_struct;
@@ -27,7 +26,7 @@ use style::attr::{AttrIdentifier, AttrValue};
// https://dom.spec.whatwg.org/#interface-attr
#[dom_struct]
pub struct Attr {
- reflector_: Reflector,
+ node_: Node,
identifier: AttrIdentifier,
value: DomRefCell<AttrValue>,
@@ -37,6 +36,7 @@ pub struct Attr {
impl Attr {
fn new_inherited(
+ document: &Document,
local_name: LocalName,
value: AttrValue,
name: LocalName,
@@ -45,7 +45,7 @@ impl Attr {
owner: Option<&Element>,
) -> Attr {
Attr {
- reflector_: Reflector::new(),
+ node_: Node::new_inherited(document),
identifier: AttrIdentifier {
local_name: local_name,
name: name,
@@ -58,7 +58,7 @@ impl Attr {
}
pub fn new(
- window: &Window,
+ document: &Document,
local_name: LocalName,
value: AttrValue,
name: LocalName,
@@ -66,11 +66,11 @@ impl Attr {
prefix: Option<Prefix>,
owner: Option<&Element>,
) -> DomRoot<Attr> {
- reflect_dom_object(
+ Node::reflect_node(
Box::new(Attr::new_inherited(
- local_name, value, name, namespace, prefix, owner,
+ document, local_name, value, name, namespace, prefix, owner,
)),
- window,
+ document,
AttrBinding::Wrap,
)
}
@@ -114,37 +114,12 @@ impl AttrMethods for Attr {
}
}
- // https://dom.spec.whatwg.org/#dom-attr-textcontent
- fn TextContent(&self) -> DOMString {
- self.Value()
- }
-
- // https://dom.spec.whatwg.org/#dom-attr-textcontent
- fn SetTextContent(&self, value: DOMString) {
- self.SetValue(value)
- }
-
- // https://dom.spec.whatwg.org/#dom-attr-nodevalue
- fn NodeValue(&self) -> DOMString {
- self.Value()
- }
-
- // https://dom.spec.whatwg.org/#dom-attr-nodevalue
- fn SetNodeValue(&self, value: DOMString) {
- self.SetValue(value)
- }
-
// https://dom.spec.whatwg.org/#dom-attr-name
fn Name(&self) -> DOMString {
// FIXME(ajeffrey): convert directly from LocalName to DOMString
DOMString::from(&*self.identifier.name)
}
- // https://dom.spec.whatwg.org/#dom-attr-nodename
- fn NodeName(&self) -> DOMString {
- self.Name()
- }
-
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
fn GetNamespaceURI(&self) -> Option<DOMString> {
match self.identifier.namespace {
@@ -250,6 +225,13 @@ impl Attr {
value: String::from(self.Value()),
}
}
+
+ pub fn qualified_name(&self) -> DOMString {
+ match self.prefix() {
+ Some(ref prefix) => DOMString::from(format!("{}:{}", prefix, &**self.local_name())),
+ None => DOMString::from(&**self.local_name()),
+ }
+ }
}
#[allow(unsafe_code)]