aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlimageelement.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-03 11:19:44 -0500
committerGitHub <noreply@github.com>2016-11-03 11:19:44 -0500
commit5b4cc9568dbd5c15e5d2fbc62719172f11566ffa (patch)
tree596f3845740221c6748588ae1a79de79640e9922 /components/script/dom/htmlimageelement.rs
parentdafc57e8abb3723e62e32e82ef04eb770eee2ea2 (diff)
parent53b638c0e29ba78448d07695343b7ddfa36c5141 (diff)
downloadservo-5b4cc9568dbd5c15e5d2fbc62719172f11566ffa.tar.gz
servo-5b4cc9568dbd5c15e5d2fbc62719172f11566ffa.zip
Auto merge of #14043 - servo:string-cache-up, r=nox
Update to string-cache 0.3 Previously, `string-cache` defined: * An string-like `Atom` type, * An `atom!("foo")` macro that expands to a value of that type, for a set of strings known at compile-time, * A `struct Namespace(Atom);` type * A `ns!(html)` macro that maps known prefixed to `Namespace` values with the corresponding namespace URL. Adding a string to the static set required making a change to the `string-cache` crate. With 0.3, the `Atom` type is now generic, with a type parameter that provides a set of static strings. We can have multiple such sets, defined in different crates. The `string_cache_codegen` crate, to be used in build scripts, generates code that defines such a set, a new atom type (a type alias for `Atom<_>` with the type parameter set), and an `atom!`-like macro. The html5ever repository has a new `html5ever_atoms` crate that defines three such types: `Prefix`, `Namespace`, and `LocalName` (with respective `namespace_prefix!`, `namespace_url!`, and `local_name!` macros). It also defines the `ns!` macro like before. This repository has a new `servo_atoms` crate in `components/atoms` that, for now, defines a single `Atom` type (and `atom!`) macro. (`servo_atoms::Atom` is defined as something like `type Atom = string_cache::Atom<ServoStaticStringSet>;`, so overall there’s now two types named `Atom`.) In this PR, `servo_atoms::Atom` is used for everything else that was `string_cache::Atom` before. But more atom types can be defined as needed. Two reasons to do this are to auto-generate the set of static strings (I’m planning to do this for CSS property names, which is the motivation for this change), or to have the type system help us avoid mix up unrelated things (this is why we had a `Namespace` type ever before this change). Introducing new types helped me find a bug: when creating a new attribute `dom::Element::set_style_attr`, would pass `Some(atom!("style"))` instead of `None` (now `Option<html5ever_atoms::Prefix>` instead of `Option<string_cache::Atom>`) to the `prefix` argument of `Attr::new`. I suppose the author of that code confused it with the `local_name` argument. --- Note that Stylo is not affected by any of this. The `gecko_string_cache` module is unchanged, with a single `Atom` type. The `style` crate conditionally compiles `Prefix` and `LocalName` re-exports for that are both `gecko_string_cache::Atom` on stylo. --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14043) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmlimageelement.rs')
-rw-r--r--components/script/dom/htmlimageelement.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index 911f305e9f9..373e7ed8480 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -21,6 +21,7 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
use dom::values::UNSIGNED_LONG_MAX;
use dom::virtualmethods::VirtualMethods;
+use html5ever_atoms::LocalName;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use net_traits::image::base::{Image, ImageMetadata};
@@ -30,7 +31,6 @@ use script_runtime::ScriptThreadEventCategory::UpdateReplacedElement;
use script_thread::Runnable;
use std::i32;
use std::sync::Arc;
-use string_cache::Atom;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use task_source::TaskSource;
use url::Url;
@@ -195,7 +195,7 @@ impl HTMLImageElement {
}
}
}
- fn new_inherited(local_name: Atom, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement {
+ fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLImageElement {
HTMLImageElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
current_request: DOMRefCell::new(ImageRequest {
@@ -216,7 +216,7 @@ impl HTMLImageElement {
}
#[allow(unrooted_must_root)]
- pub fn new(local_name: Atom,
+ pub fn new(local_name: LocalName,
prefix: Option<DOMString>,
document: &Document) -> Root<HTMLImageElement> {
Node::reflect_node(box HTMLImageElement::new_inherited(local_name, prefix, document),
@@ -228,7 +228,7 @@ impl HTMLImageElement {
width: Option<u32>,
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
let document = global.as_window().Document();
- let image = HTMLImageElement::new(atom!("img"), None, &document);
+ let image = HTMLImageElement::new(local_name!("img"), None, &document);
if let Some(w) = width {
image.SetWidth(w);
}
@@ -266,7 +266,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
- .get_attr_for_layout(&ns!(), &atom!("width"))
+ .get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@@ -277,7 +277,7 @@ impl LayoutHTMLImageElementHelpers for LayoutJS<HTMLImageElement> {
fn get_height(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
- .get_attr_for_layout(&ns!(), &atom!("height"))
+ .get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
@@ -320,7 +320,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-width
fn SetWidth(&self, value: u32) {
- image_dimension_setter(self.upcast(), atom!("width"), value);
+ image_dimension_setter(self.upcast(), local_name!("width"), value);
}
// https://html.spec.whatwg.org/multipage/#dom-img-height
@@ -332,7 +332,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-height
fn SetHeight(&self, value: u32) {
- image_dimension_setter(self.upcast(), atom!("height"), value);
+ image_dimension_setter(self.upcast(), local_name!("height"), value);
}
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
@@ -415,7 +415,7 @@ impl VirtualMethods for HTMLImageElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
- &atom!("src") => {
+ &local_name!("src") => {
self.update_image(mutation.new_value(attr).map(|value| {
// FIXME(ajeffrey): convert directly from AttrValue to DOMString
(DOMString::from(&**value), document_from_node(self).base_url())
@@ -425,17 +425,17 @@ impl VirtualMethods for HTMLImageElement {
}
}
- fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
+ fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
- &atom!("name") => AttrValue::from_atomic(value.into()),
- &atom!("width") | &atom!("height") => AttrValue::from_dimension(value.into()),
- &atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value.into(), 0),
+ &local_name!("name") => AttrValue::from_atomic(value.into()),
+ &local_name!("width") | &local_name!("height") => AttrValue::from_dimension(value.into()),
+ &local_name!("hspace") | &local_name!("vspace") => AttrValue::from_u32(value.into(), 0),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
}
-fn image_dimension_setter(element: &Element, attr: Atom, value: u32) {
+fn image_dimension_setter(element: &Element, attr: LocalName, value: u32) {
// This setter is a bit weird: the IDL type is unsigned long, but it's parsed as
// a dimension for rendering.
let value = if value > UNSIGNED_LONG_MAX {