Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attr is a Node, with consequences for many Node methods #25310

Merged
merged 1 commit into from Jan 7, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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,19 +58,19 @@ impl Attr {
}

pub fn new(
window: &Window,
document: &Document,
local_name: LocalName,
value: AttrValue,
name: LocalName,
namespace: Namespace,
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)]
@@ -3685,7 +3685,7 @@ impl DocumentMethods for Document {
let value = AttrValue::String("".to_owned());

Ok(Attr::new(
&self.window,
&self,
name.clone(),
value,
name,
@@ -3705,7 +3705,7 @@ impl DocumentMethods for Document {
let value = AttrValue::String("".to_owned());
let qualified_name = LocalName::from(qualified_name);
Ok(Attr::new(
&self.window,
&self,
local_name,
value,
qualified_name,
@@ -1336,9 +1336,8 @@ impl Element {
namespace: Namespace,
prefix: Option<Prefix>,
) {
let window = window_from_node(self);
let attr = Attr::new(
&window,
&self.node.owner_doc(),
local_name,
value,
name,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.