mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Handle dynamic font color change
This commit is contained in:
parent
54cd23adb8
commit
8161d1931d
7 changed files with 80 additions and 4 deletions
|
@ -88,6 +88,7 @@ use dom::touchevent::TouchEvent;
|
||||||
use dom::touchlist::TouchList;
|
use dom::touchlist::TouchList;
|
||||||
use dom::treewalker::TreeWalker;
|
use dom::treewalker::TreeWalker;
|
||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
|
use dom::virtualmethods::vtable_for;
|
||||||
use dom::webglcontextevent::WebGLContextEvent;
|
use dom::webglcontextevent::WebGLContextEvent;
|
||||||
use dom::window::{ReflowReason, Window};
|
use dom::window::{ReflowReason, Window};
|
||||||
use dom::windowproxy::WindowProxy;
|
use dom::windowproxy::WindowProxy;
|
||||||
|
@ -2499,10 +2500,7 @@ impl Document {
|
||||||
entry.hint.insert(RESTYLE_STYLE_ATTRIBUTE);
|
entry.hint.insert(RESTYLE_STYLE_ATTRIBUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(emilio): This should become something like
|
if vtable_for(el.upcast()).attribute_is_mapped(attr) {
|
||||||
// element.is_attribute_mapped(attr.local_name()).
|
|
||||||
if attr.local_name() == &local_name!("width") ||
|
|
||||||
attr.local_name() == &local_name!("height") {
|
|
||||||
entry.hint.insert(RESTYLE_SELF);
|
entry.hint.insert(RESTYLE_SELF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2303,6 +2303,16 @@ impl VirtualMethods for Element {
|
||||||
Some(self.upcast::<Node>() as &VirtualMethods)
|
Some(self.upcast::<Node>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn attribute_is_mapped(&self, attr: &Attr) -> bool {
|
||||||
|
// FIXME: This should be more fine-grained, not all elements care about these.
|
||||||
|
if attr.local_name() == &local_name!("width") ||
|
||||||
|
attr.local_name() == &local_name!("height") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.super_type().unwrap().attribute_is_mapped(attr)
|
||||||
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
let node = self.upcast::<Node>();
|
let node = self.upcast::<Node>();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
|
@ -70,6 +71,15 @@ impl VirtualMethods for HTMLFontElement {
|
||||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn attribute_is_mapped(&self, attr: &Attr) -> bool {
|
||||||
|
if attr.local_name() == &local_name!("color") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should also return true for `size` and `face` changes!
|
||||||
|
self.super_type().unwrap().attribute_is_mapped(attr)
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
|
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
|
||||||
match name {
|
match name {
|
||||||
&local_name!("face") => AttrValue::from_atomic(value.into()),
|
&local_name!("face") => AttrValue::from_atomic(value.into()),
|
||||||
|
|
|
@ -70,6 +70,15 @@ pub trait VirtualMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if given attribute `attr` affects style of the
|
||||||
|
/// given element.
|
||||||
|
fn attribute_is_mapped(&self, attr: &Attr) -> bool {
|
||||||
|
match self.super_type() {
|
||||||
|
Some(s) => s.attribute_is_mapped(attr),
|
||||||
|
None => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the right AttrValue variant for the attribute with name `name`
|
/// Returns the right AttrValue variant for the attribute with name `name`
|
||||||
/// on this element.
|
/// on this element.
|
||||||
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
|
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
|
||||||
|
|
|
@ -2231,6 +2231,18 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"css/font_color_attribute_change.html": [
|
||||||
|
[
|
||||||
|
"/_mozilla/css/font_color_attribute_change.html",
|
||||||
|
[
|
||||||
|
[
|
||||||
|
"/_mozilla/css/font_color_attribute_change_ref.html",
|
||||||
|
"=="
|
||||||
|
]
|
||||||
|
],
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"css/font_face_attribute.html": [
|
"css/font_face_attribute.html": [
|
||||||
[
|
[
|
||||||
"/_mozilla/css/font_face_attribute.html",
|
"/_mozilla/css/font_face_attribute.html",
|
||||||
|
@ -8768,6 +8780,11 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"css/font_color_attribute_change_ref.html": [
|
||||||
|
[
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"css/font_color_attribute_ref.html": [
|
"css/font_color_attribute_ref.html": [
|
||||||
[
|
[
|
||||||
{}
|
{}
|
||||||
|
@ -24031,6 +24048,14 @@
|
||||||
"c26b839b729cae2d01ba7f2588852170bcc0b82e",
|
"c26b839b729cae2d01ba7f2588852170bcc0b82e",
|
||||||
"reftest"
|
"reftest"
|
||||||
],
|
],
|
||||||
|
"css/font_color_attribute_change.html": [
|
||||||
|
"87c9ff1745eaecbbf2ac61d5d37a9c7e82c729a9",
|
||||||
|
"reftest"
|
||||||
|
],
|
||||||
|
"css/font_color_attribute_change_ref.html": [
|
||||||
|
"0c84fb819c07853ec125e52df465701ad6da7424",
|
||||||
|
"support"
|
||||||
|
],
|
||||||
"css/font_color_attribute_ref.html": [
|
"css/font_color_attribute_ref.html": [
|
||||||
"4a07819ffd7c7629ee13f428cf7243c99f3dfc63",
|
"4a07819ffd7c7629ee13f428cf7243c99f3dfc63",
|
||||||
"support"
|
"support"
|
||||||
|
|
15
tests/wpt/mozilla/tests/css/font_color_attribute_change.html
Normal file
15
tests/wpt/mozilla/tests/css/font_color_attribute_change.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
<link rel="match" href="font_color_attribute_change_ref.html">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<font color="red">I should be green</font>
|
||||||
|
<script>
|
||||||
|
document.body.offsetTop;
|
||||||
|
document.querySelector("font").setAttribute("color", "green");
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<font color="green">I should be green</font>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue