diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/characterdata.rs | 34 | ||||
-rw-r--r-- | components/script/dom/element.rs | 20 | ||||
-rw-r--r-- | components/script/dom/htmlfontelement.rs | 62 | ||||
-rw-r--r-- | components/script/dom/node.rs | 4 | ||||
-rw-r--r-- | components/script/dom/virtualmethods.rs | 10 | ||||
-rw-r--r-- | components/script/dom/webidls/CSSStyleDeclaration.webidl | 1 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLFontElement.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/websocket.rs | 2 | ||||
-rw-r--r-- | components/script/layout_interface.rs | 5 |
9 files changed, 113 insertions, 27 deletions
diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 3ea3609c7d7..017bc79f5a2 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -21,7 +21,6 @@ use util::str::DOMString; use std::borrow::ToOwned; use std::cell::Ref; -use std::cmp; // https://dom.spec.whatwg.org/#characterdata #[dom_struct] @@ -68,47 +67,50 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { data.chars().count() as u32 } - // https://dom.spec.whatwg.org/#dom-characterdata-substringdata + // https://dom.spec.whatwg.org/#dom-characterdata-substringdataoffset-count fn SubstringData(self, offset: u32, count: u32) -> Fallible<DOMString> { let data = self.data.borrow(); // Step 1. - let len = data.chars().count(); - if offset as usize > len { + let length = data.chars().count() as u32; + if offset > length { // Step 2. return Err(IndexSize); } - // Step 3. - let end = cmp::min((offset + count) as usize, len); - // Step 4. - Ok(data.slice_chars(offset as usize, end).to_owned()) + // Steps 3-4. + let end = if length - offset < count { length } else { offset + count }; + Ok(data.slice_chars(offset as usize, end as usize).to_owned()) } - // https://dom.spec.whatwg.org/#dom-characterdata-appenddata + // https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata fn AppendData(self, data: DOMString) { self.data.borrow_mut().push_str(&data); } - // https://dom.spec.whatwg.org/#dom-characterdata-insertdata + // https://dom.spec.whatwg.org/#dom-characterdata-insertdataoffset-data fn InsertData(self, offset: u32, arg: DOMString) -> ErrorResult { self.ReplaceData(offset, 0, arg) } - // https://dom.spec.whatwg.org/#dom-characterdata-deletedata + // https://dom.spec.whatwg.org/#dom-characterdata-deletedataoffset-count fn DeleteData(self, offset: u32, count: u32) -> ErrorResult { self.ReplaceData(offset, count, "".to_owned()) } - // https://dom.spec.whatwg.org/#dom-characterdata-replacedata + // https://dom.spec.whatwg.org/#dom-characterdata-replacedataoffset-count-data fn ReplaceData(self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { + // Step 1. let length = self.data.borrow().chars().count() as u32; if offset > length { + // Step 2. return Err(IndexSize); } - let count = if offset + count > length { - length - offset - } else { - count + // Step 3. + let count = match length - offset { + diff if diff < count => diff, + _ => count, }; + // Step 4: Mutation observers. + // Step 5. let mut data = self.data.borrow().slice_chars(0, offset as usize).to_owned(); data.push_str(&arg); data.push_str(&self.data.borrow().slice_chars((offset + count) as usize, length as usize)); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index f0ff55e2e5b..e8ae592e63c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -17,7 +17,8 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast}; -use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast}; +use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLFontElementDerived}; +use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived}; @@ -45,6 +46,7 @@ use dom::htmlanchorelement::HTMLAnchorElement; use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers}; use dom::htmlcollection::HTMLCollection; use dom::htmlelement::HTMLElementTypeId; +use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementHelpers}; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers, HTMLInputElementHelpers}; use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers}; use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers}; @@ -64,7 +66,7 @@ use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_sty use style::properties::DeclaredValue::SpecifiedValue; use style::properties::longhands::{self, border_spacing}; use style::values::CSSFloat; -use style::values::specified::{self, CSSColor}; +use style::values::specified::{self, CSSColor, CSSRGBA}; use util::geometry::Au; use util::namespace; use util::smallvec::VecLike; @@ -269,6 +271,20 @@ impl RawLayoutElementHelpers for Element { CSSColor { parsed: Color::RGBA(color), authored: None })))); } + let color = if self.is_htmlfontelement() { + let this: &HTMLFontElement = mem::transmute(self); + this.get_color() + } else { + None + }; + + if let Some(color) = color { + hints.push(from_declaration( + PropertyDeclaration::Color(SpecifiedValue(CSSRGBA { + parsed: color, + authored: None, + })))); + } let cellspacing = if self.is_htmltableelement() { let this: &HTMLTableElement = mem::transmute(self); diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index 2df515cbc83..d2faa87441c 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -2,19 +2,26 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::{Attr, AttrHelpers}; use dom::bindings::codegen::Bindings::HTMLFontElementBinding; -use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived; +use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods; +use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived}; use dom::bindings::js::{JSRef, Temporary}; use dom::document::Document; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::element::ElementTypeId; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; -use util::str::DOMString; +use dom::virtualmethods::VirtualMethods; +use util::str::{self, DOMString}; + +use cssparser::RGBA; +use std::cell::Cell; #[dom_struct] pub struct HTMLFontElement { - htmlelement: HTMLElement + htmlelement: HTMLElement, + color: Cell<Option<RGBA>>, } impl HTMLFontElementDerived for EventTarget { @@ -26,7 +33,8 @@ impl HTMLFontElementDerived for EventTarget { impl HTMLFontElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLFontElement { HTMLFontElement { - htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document) + htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document), + color: Cell::new(None), } } @@ -37,3 +45,49 @@ impl HTMLFontElement { } } +impl<'a> HTMLFontElementMethods for JSRef<'a, HTMLFontElement> { + make_getter!(Color, "color"); + make_setter!(SetColor, "color"); +} + +impl<'a> VirtualMethods for JSRef<'a,HTMLFontElement> { + fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> { + let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self); + Some(htmlelement as &VirtualMethods) + } + + fn after_set_attr(&self, attr: JSRef<Attr>) { + if let Some(ref s) = self.super_type() { + s.after_set_attr(attr); + } + + match attr.local_name() { + &atom!("color") => { + self.color.set(str::parse_legacy_color(&attr.value()).ok()) + } + _ => {} + } + } + + fn before_remove_attr(&self, attr: JSRef<Attr>) { + if let Some(ref s) = self.super_type() { + s.before_remove_attr(attr); + } + + match attr.local_name() { + &atom!("color") => self.color.set(None), + _ => () + } + } +} + +pub trait HTMLFontElementHelpers { + fn get_color(&self) -> Option<RGBA>; +} + +impl HTMLFontElementHelpers for HTMLFontElement { + fn get_color(&self) -> Option<RGBA> { + self.color.get() + } +} + diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index f7401c99b11..789d2920832 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -629,7 +629,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { fn set_hover_state(self, state: bool) { self.set_flag(IN_HOVER_STATE, state); - self.dirty(NodeDamage::OtherNodeDamage); + self.dirty(NodeDamage::NodeStyleDamaged); } fn get_focus_state(self) -> bool { @@ -638,7 +638,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { fn set_focus_state(self, state: bool) { self.set_flag(IN_FOCUS_STATE, state); - self.dirty(NodeDamage::OtherNodeDamage); + self.dirty(NodeDamage::NodeStyleDamaged); } fn get_disabled_state(self) -> bool { diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 2147ee07c48..a83c801831d 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -12,6 +12,7 @@ use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementCast; +use dom::bindings::codegen::InheritTypes::HTMLFontElementCast; use dom::bindings::codegen::InheritTypes::HTMLFormElementCast; use dom::bindings::codegen::InheritTypes::HTMLHeadElementCast; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; @@ -42,6 +43,8 @@ use dom::htmlbuttonelement::HTMLButtonElement; use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlfieldsetelement::HTMLFieldSetElement; +use dom::htmlfontelement::HTMLFontElement; +use dom::htmlformelement::HTMLFormElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmliframeelement::HTMLIFrameElement; use dom::htmlimageelement::HTMLImageElement; @@ -169,8 +172,13 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a (VirtualMethods + 'a) { let element: &'a JSRef<'a, HTMLFieldSetElement> = HTMLFieldSetElementCast::to_borrowed_ref(node).unwrap(); element as &'a (VirtualMethods + 'a) } + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFontElement)) => { + let element: &'a JSRef<'a, HTMLFontElement> = HTMLFontElementCast::to_borrowed_ref(node).unwrap(); + element as &'a (VirtualMethods + 'a) + } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => { - HTMLFormElementCast::to_borrowed_ref(node).unwrap() as &'a (VirtualMethods + 'a) + let element: &'a JSRef<'a, HTMLFormElement> = HTMLFormElementCast::to_borrowed_ref(node).unwrap(); + element as &'a (VirtualMethods + 'a) } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => { let element: &'a JSRef<'a, HTMLHeadElement> = HTMLHeadElementCast::to_borrowed_ref(node).unwrap(); diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 57b3e9f43cc..d85dfc8f8ca 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -40,6 +40,7 @@ partial interface CSSStyleDeclaration { [TreatNullAs=EmptyString] attribute DOMString backgroundAttachment; [TreatNullAs=EmptyString] attribute DOMString backgroundSize; [TreatNullAs=EmptyString] attribute DOMString backgroundOrigin; + [TreatNullAs=EmptyString] attribute DOMString backgroundClip; [TreatNullAs=EmptyString] attribute DOMString border; [TreatNullAs=EmptyString] attribute DOMString borderColor; diff --git a/components/script/dom/webidls/HTMLFontElement.webidl b/components/script/dom/webidls/HTMLFontElement.webidl index 9a58672baf5..03b68498db7 100644 --- a/components/script/dom/webidls/HTMLFontElement.webidl +++ b/components/script/dom/webidls/HTMLFontElement.webidl @@ -5,7 +5,7 @@ // https://www.whatwg.org/html/#htmlfontelement interface HTMLFontElement : HTMLElement { - //[TreatNullAs=EmptyString] attribute DOMString color; + [TreatNullAs=EmptyString] attribute DOMString color; // attribute DOMString face; // attribute DOMString size; }; diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 009ca43a78b..75c868b50db 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -247,7 +247,7 @@ impl WebSocketTaskHandler { let event = Event::new(global.r(), "open".to_owned(), EventBubbles::DoesNotBubble, - EventCancelable::Cancelable).root(); + EventCancelable::NotCancelable).root(); let target: JSRef<EventTarget> = EventTargetCast::from_ref(ws); event.r().fire(target); } diff --git a/components/script/layout_interface.rs b/components/script/layout_interface.rs index ad474a0daed..2ebb00d5cf8 100644 --- a/components/script/layout_interface.rs +++ b/components/script/layout_interface.rs @@ -11,6 +11,7 @@ use dom::node::LayoutData; use geom::point::Point2D; use geom::rect::Rect; use libc::uintptr_t; +use msg::compositor_msg::LayerId; use msg::constellation_msg::{PipelineExitType, WindowSizeData}; use msg::compositor_msg::Epoch; use net_traits::PendingAsyncLoad; @@ -47,6 +48,10 @@ pub enum Msg { /// Requests that the layout task render the next frame of all animations. TickAnimations, + /// Updates the layout visible rects, affecting the area that display lists will be constructed + /// for. + SetVisibleRects(Vec<(LayerId, Rect<Au>)>), + /// Destroys layout data associated with a DOM node. /// /// TODO(pcwalton): Maybe think about batching to avoid message traffic. |