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

Introduce VirtualMethods::attribute_mutated() #7452

Merged
merged 4 commits into from Sep 2, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutNullableHeap};
use dom::bindings::js::{Root, RootedReference, LayoutJS};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::element::Element;
use dom::element::{AttributeMutation, Element};
use dom::virtualmethods::vtable_for;
use dom::window::Window;

@@ -23,12 +23,6 @@ use std::cell::Ref;
use std::mem;
use std::ops::Deref;

#[derive(HeapSizeOf)]
pub enum AttrSettingType {
FirstSetAttr,
ReplacedAttr,
}

#[derive(JSTraceable, PartialEq, Clone, HeapSizeOf)]
pub enum AttrValue {
String(DOMString),
@@ -94,6 +88,17 @@ impl AttrValue {
_ => None
}
}

/// Return the AttrValue as its integer representation, if any.
/// This corresponds to attribute values returned as `AttrValue::UInt(_)`
/// by `VirtualMethods::parse_plain_attribute()`.
pub fn uint(&self) -> Option<u32> {
if let AttrValue::UInt(_, value) = *self {
Some(value)
} else {
None
}
}
}

impl Deref for AttrValue {
@@ -179,7 +184,7 @@ impl AttrMethods for Attr {
None => *self.value.borrow_mut() = AttrValue::String(value),
Some(owner) => {
let value = owner.r().parse_attribute(&self.namespace, self.local_name(), value);
self.set_value(AttrSettingType::ReplacedAttr, value, owner.r());
self.set_value(value, owner.r());
}
}
}
@@ -236,22 +241,12 @@ impl AttrMethods for Attr {


impl Attr {
pub fn set_value(&self, set_type: AttrSettingType, value: AttrValue, owner: &Element) {
pub fn set_value(&self, mut value: AttrValue, owner: &Element) {
assert!(Some(owner) == self.owner().r());

let node = NodeCast::from_ref(owner);
let namespace_is_null = self.namespace == ns!("");

match set_type {
AttrSettingType::ReplacedAttr if namespace_is_null =>
vtable_for(&node).before_remove_attr(self),
_ => ()
}

*self.value.borrow_mut() = value;

if namespace_is_null {
vtable_for(&node).after_set_attr(self)
mem::swap(&mut *self.value.borrow_mut(), &mut value);
if self.namespace == ns!("") {
vtable_for(NodeCast::from_ref(owner)).attribute_mutated(
self, AttributeMutation::Set(Some(&value)));
}
}

@@ -123,9 +123,10 @@ impl BlobMethods for Blob {
};
let relativeContentType = match contentType {
None => "".to_owned(),
Some(str) => {
Some(mut str) => {
if is_ascii_printable(&str) {
str.to_ascii_lowercase()
str.make_ascii_lowercase();
str
} else {
"".to_owned()
}
@@ -122,11 +122,12 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}

// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
fn GetPropertyValue(&self, property: DOMString) -> DOMString {
fn GetPropertyValue(&self, mut property: DOMString) -> DOMString {
let owner = self.owner.root();

// Step 1
let property = Atom::from_slice(&property.to_ascii_lowercase());
property.make_ascii_lowercase();
let property = Atom::from_slice(&property);

if self.readonly {
// Readonly style declarations are used for getComputedStyle.
@@ -165,9 +166,10 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}

// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority
fn GetPropertyPriority(&self, property: DOMString) -> DOMString {
fn GetPropertyPriority(&self, mut property: DOMString) -> DOMString {
// Step 1
let property = Atom::from_slice(&property.to_ascii_lowercase());
property.make_ascii_lowercase();
let property = Atom::from_slice(&property);

// Step 2
let longhand_properties = longhands_from_shorthand(&property);
@@ -193,15 +195,15 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}

// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty
fn SetProperty(&self, property: DOMString, value: DOMString,
fn SetProperty(&self, mut property: DOMString, value: DOMString,
priority: DOMString) -> ErrorResult {
// Step 1
if self.readonly {
return Err(Error::NoModificationAllowed);
}

// Step 2
let property = property.to_ascii_lowercase();
property.make_ascii_lowercase();

// Step 3
if !is_supported_property(&property) {
@@ -287,14 +289,14 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}

// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty
fn RemoveProperty(&self, property: DOMString) -> Fallible<DOMString> {
fn RemoveProperty(&self, mut property: DOMString) -> Fallible<DOMString> {
// Step 1
if self.readonly {
return Err(Error::NoModificationAllowed);
}

// Step 2
let property = property.to_ascii_lowercase();
property.make_ascii_lowercase();

// Step 3
let value = self.GetPropertyValue(property.clone());
@@ -297,6 +297,7 @@ impl Document {
}

/// Refresh the cached first base element in the DOM.
/// https://github.com/w3c/web-platform-tests/issues/2122
pub fn refresh_base_element(&self) {
let base = NodeCast::from_ref(self)
.traverse_preorder()
@@ -1243,7 +1244,7 @@ impl DocumentMethods for Document {
return Err(InvalidCharacter);
}
if self.is_html_document {
local_name = local_name.to_ascii_lowercase()
local_name.make_ascii_lowercase();
}
let name = QualName::new(ns!(HTML), Atom::from_slice(&local_name));
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
@@ -1350,10 +1351,11 @@ impl DocumentMethods for Document {
}

// https://dom.spec.whatwg.org/#dom-document-createevent
fn CreateEvent(&self, interface: DOMString) -> Fallible<Root<Event>> {
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
let window = self.window.root();

match &*interface.to_ascii_lowercase() {
interface.make_ascii_lowercase();
match &*interface {
"uievents" | "uievent" => Ok(EventCast::from_root(
UIEvent::new_uninitialized(window.r()))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_root(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.