From bb2536cd014676263f5bfd5d98cf0fc69d2abee0 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Tue, 27 Oct 2015 14:56:41 +0900 Subject: [PATCH 1/8] move Castable into dom::bindings::inheritance --- components/script/devtools.rs | 3 +- components/script/dom/activation.rs | 2 +- components/script/dom/attr.rs | 2 +- components/script/dom/bindings/conversions.rs | 27 +-------------- components/script/dom/bindings/inheritance.rs | 34 +++++++++++++++++++ components/script/dom/bindings/js.rs | 3 +- .../script/dom/canvasrenderingcontext2d.rs | 2 +- components/script/dom/characterdata.rs | 2 +- components/script/dom/closeevent.rs | 2 +- components/script/dom/cssstyledeclaration.rs | 2 +- components/script/dom/customevent.rs | 2 +- .../script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/document.rs | 2 +- components/script/dom/documentfragment.rs | 2 +- components/script/dom/documenttype.rs | 2 +- components/script/dom/domimplementation.rs | 2 +- components/script/dom/element.rs | 2 +- components/script/dom/errorevent.rs | 2 +- components/script/dom/eventdispatcher.rs | 2 +- components/script/dom/filereader.rs | 2 +- components/script/dom/formdata.rs | 2 +- components/script/dom/htmlanchorelement.rs | 2 +- components/script/dom/htmlappletelement.rs | 2 +- components/script/dom/htmlareaelement.rs | 2 +- components/script/dom/htmlbaseelement.rs | 2 +- components/script/dom/htmlbodyelement.rs | 2 +- components/script/dom/htmlbuttonelement.rs | 2 +- components/script/dom/htmlcanvaselement.rs | 3 +- components/script/dom/htmlcollection.rs | 2 +- components/script/dom/htmldatalistelement.rs | 2 +- components/script/dom/htmlelement.rs | 2 +- components/script/dom/htmlfieldsetelement.rs | 2 +- components/script/dom/htmlfontelement.rs | 2 +- components/script/dom/htmlformelement.rs | 3 +- components/script/dom/htmlheadelement.rs | 2 +- components/script/dom/htmliframeelement.rs | 3 +- components/script/dom/htmlimageelement.rs | 2 +- components/script/dom/htmlinputelement.rs | 2 +- components/script/dom/htmllabelelement.rs | 2 +- components/script/dom/htmllinkelement.rs | 2 +- components/script/dom/htmlmetaelement.rs | 2 +- components/script/dom/htmlobjectelement.rs | 2 +- components/script/dom/htmloptgroupelement.rs | 2 +- components/script/dom/htmloptionelement.rs | 2 +- components/script/dom/htmlscriptelement.rs | 2 +- components/script/dom/htmlselectelement.rs | 2 +- components/script/dom/htmlstyleelement.rs | 2 +- components/script/dom/htmltablecellelement.rs | 2 +- components/script/dom/htmltableelement.rs | 2 +- components/script/dom/htmltablerowelement.rs | 2 +- .../script/dom/htmltablesectionelement.rs | 2 +- components/script/dom/htmltemplateelement.rs | 2 +- components/script/dom/htmltextareaelement.rs | 2 +- components/script/dom/htmltitleelement.rs | 2 +- components/script/dom/keyboardevent.rs | 2 +- components/script/dom/macros.rs | 26 +++++++------- components/script/dom/messageevent.rs | 2 +- components/script/dom/mod.rs | 2 +- components/script/dom/mouseevent.rs | 2 +- components/script/dom/node.rs | 3 +- components/script/dom/progressevent.rs | 2 +- components/script/dom/range.rs | 2 +- components/script/dom/storage.rs | 2 +- components/script/dom/storageevent.rs | 2 +- components/script/dom/text.rs | 2 +- components/script/dom/touchevent.rs | 2 +- components/script/dom/uievent.rs | 2 +- components/script/dom/userscripts.rs | 2 +- components/script/dom/virtualmethods.rs | 2 +- components/script/dom/webglcontextevent.rs | 2 +- .../script/dom/webglrenderingcontext.rs | 3 +- components/script/dom/websocket.rs | 3 +- components/script/dom/window.rs | 2 +- components/script/dom/worker.rs | 2 +- components/script/dom/workerglobalscope.rs | 2 +- components/script/dom/xmlhttprequest.rs | 3 +- components/script/script_task.rs | 3 +- components/script/webdriver_handlers.rs | 3 +- 78 files changed, 133 insertions(+), 115 deletions(-) create mode 100644 components/script/dom/bindings/inheritance.rs diff --git a/components/script/devtools.rs b/components/script/devtools.rs index bc6dc34ad4f..a05edafe7e7 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -8,8 +8,9 @@ use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker, T use dom::bindings::codegen::Bindings::DOMRectBinding::{DOMRectMethods}; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::ElementBinding::{ElementMethods}; -use dom::bindings::conversions::{Castable, FromJSValConvertible, jsstring_to_str}; +use dom::bindings::conversions::{FromJSValConvertible, jsstring_to_str}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::element::Element; use dom::node::Node; diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index bd843f557bb..15db5e9f3eb 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::element::Element; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 50e028a03b3..f9d85314169 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -6,8 +6,8 @@ use cssparser::RGBA; use devtools_traits::AttrInfo; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods}; -use dom::bindings::conversions::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::js::{LayoutJS, Root, RootedReference}; use dom::bindings::utils::{Reflector, reflect_dom_object}; diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 710a5715fa4..c8f3b986623 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -34,6 +34,7 @@ use core::nonzero::NonZero; use dom::bindings::error::throw_type_error; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::num::Finite; use dom::bindings::str::{ByteString, USVString}; @@ -107,32 +108,6 @@ pub trait IDLInterface { fn derives(&'static DOMClass) -> bool; } -/// A trait to hold the cast functions of IDL interfaces that either derive -/// or are derived from other interfaces. -pub trait Castable: IDLInterface + Reflectable + Sized { - /// Check whether a DOM object implements one of its deriving interfaces. - fn is(&self) -> bool where T: DerivedFrom { - let class = unsafe { - get_dom_class(self.reflector().get_jsobject().get()).unwrap() - }; - T::derives(class) - } - - /// Cast a DOM object upwards to one of the interfaces it derives from. - fn upcast(&self) -> &T where T: Castable, Self: DerivedFrom { - unsafe { mem::transmute(self) } - } - - /// Cast a DOM object downwards to one of the interfaces it might implement. - fn downcast(&self) -> Option<&T> where T: DerivedFrom { - if self.is::() { - Some(unsafe { mem::transmute(self) }) - } else { - None - } - } -} - /// A trait to mark an IDL interface as deriving from another one. #[rustc_on_unimplemented = "The IDL interface `{Self}` is not derived from `{T}`."] pub trait DerivedFrom: Castable {} diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs new file mode 100644 index 00000000000..5878c44c5f3 --- /dev/null +++ b/components/script/dom/bindings/inheritance.rs @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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::bindings::conversions::get_dom_class; +use dom::bindings::conversions::{DerivedFrom, IDLInterface}; +use dom::bindings::utils::Reflectable; +use std::mem; + +/// A trait to hold the cast functions of IDL interfaces that either derive +/// or are derived from other interfaces. +pub trait Castable: IDLInterface + Reflectable + Sized { + /// Check whether a DOM object implements one of its deriving interfaces. + fn is(&self) -> bool where T: DerivedFrom { + let class = unsafe { + get_dom_class(self.reflector().get_jsobject().get()).unwrap() + }; + T::derives(class) + } + + /// Cast a DOM object upwards to one of the interfaces it derives from. + fn upcast(&self) -> &T where T: Castable, Self: DerivedFrom { + unsafe { mem::transmute(self) } + } + + /// Cast a DOM object downwards to one of the interfaces it might implement. + fn downcast(&self) -> Option<&T> where T: DerivedFrom { + if self.is::() { + Some(unsafe { mem::transmute(self) }) + } else { + None + } + } +} diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index a6af7680a96..388a8ba81ef 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -24,7 +24,8 @@ //! use core::nonzero::NonZero; -use dom::bindings::conversions::{Castable, DerivedFrom}; +use dom::bindings::conversions::DerivedFrom; +use dom::bindings::inheritance::Castable; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::trace_reflector; use dom::bindings::utils::{Reflectable, Reflector}; diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index aa7936f69f5..d60e02f921a 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -14,9 +14,9 @@ use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasWin use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::codegen::UnionTypes::HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D; use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern; -use dom::bindings::conversions::Castable; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, Root}; use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 8bc61288a0e..f1fb7269680 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -7,7 +7,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::js::{LayoutJS, Root}; use dom::document::Document; diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs index 75f2f0e5bb0..c903a68262f 100644 --- a/components/script/dom/closeevent.rs +++ b/components/script/dom/closeevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::CloseEventBinding; use dom::bindings::codegen::Bindings::CloseEventBinding::CloseEventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::conversions::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::utils::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index ba6923c1f6f..763cc43059c 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -3,9 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::{self, CSSStyleDeclarationMethods}; -use dom::bindings::conversions::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::element::{Element, StylePriority}; diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 17e834e318a..89edb89e202 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::CustomEventBinding; use dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{MutHeapJSVal, Root}; diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 2c9a6f9f629..596ac6b33de 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -8,9 +8,9 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding; use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; -use dom::bindings::conversions::Castable; use dom::bindings::error::ErrorResult; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootCollection}; use dom::bindings::refcounted::LiveDOMReferences; use dom::bindings::structuredclone::StructuredCloneData; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 2ad0a12262f..8aa8ab08447 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -16,9 +16,9 @@ use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::num::Finite; diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs index 26a0259fab9..31568622600 100644 --- a/components/script/dom/documentfragment.rs +++ b/components/script/dom/documentfragment.rs @@ -6,9 +6,9 @@ use dom::bindings::codegen::Bindings::DocumentFragmentBinding; use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::Castable; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/documenttype.rs b/components/script/dom/documenttype.rs index 1d72d783e7e..1754ad84f66 100644 --- a/components/script/dom/documenttype.rs +++ b/components/script/dom/documenttype.rs @@ -5,8 +5,8 @@ use dom::bindings::codegen::Bindings::DocumentTypeBinding; use dom::bindings::codegen::Bindings::DocumentTypeBinding::DocumentTypeMethods; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::Castable; use dom::bindings::error::ErrorResult; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::node::Node; diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 02c8ad4fa84..62db553454e 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -7,9 +7,9 @@ use dom::bindings::codegen::Bindings::DOMImplementationBinding; use dom::bindings::codegen::Bindings::DOMImplementationBinding::DOMImplementationMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::validate_qualified_name; use dom::bindings::utils::{Reflector, reflect_dom_object}; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 0bdca0714a7..a26a292b7e6 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -21,7 +21,7 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index 39327d967cf..ada456c84c6 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -6,7 +6,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::ErrorEventBinding; use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{MutHeapJSVal, Root}; diff --git a/components/script/dom/eventdispatcher.rs b/components/script/dom/eventdispatcher.rs index 2b0e1942843..14d657a9d4f 100644 --- a/components/script/dom/eventdispatcher.rs +++ b/components/script/dom/eventdispatcher.rs @@ -5,7 +5,7 @@ use devtools_traits::{StartedTimelineMarker, TimelineMarker, TimelineMarkerType}; use dom::bindings::callback::ExceptionHandling::Report; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::{GlobalRoot, global_object_for_reflector}; use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::trace::RootedVec; diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index dce7ef438dc..fa71b76e83a 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{JS, MutNullableHeap, Root}; diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index a51e058b864..14b497fca15 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::FormDataBinding; use dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods; use dom::bindings::codegen::UnionTypes::FileOrString; use dom::bindings::codegen::UnionTypes::FileOrString::{eFile, eString}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{JS, Root}; diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index a269dd948fc..c3438050f9d 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding; use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElementMethods; use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::document::Document; use dom::domtokenlist::DOMTokenList; diff --git a/components/script/dom/htmlappletelement.rs b/components/script/dom/htmlappletelement.rs index 801fafa2593..9c197308e58 100644 --- a/components/script/dom/htmlappletelement.rs +++ b/components/script/dom/htmlappletelement.rs @@ -5,7 +5,7 @@ use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLAppletElementBinding; use dom::bindings::codegen::Bindings::HTMLAppletElementBinding::HTMLAppletElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index c9023bdbb23..871def58e54 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -5,7 +5,7 @@ use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::Reflectable; use dom::document::Document; diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index dd3c79b06cd..d31fb1f8dec 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -4,7 +4,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLBaseElementBinding; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 4b639d0ed42..64719bae903 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -8,7 +8,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods}; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::utils::Reflectable; use dom::document::Document; diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 5146c7e4888..5937f36d3dc 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -6,7 +6,7 @@ use dom::activation::Activatable; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE}; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 47126ed3dd0..3829f036e2d 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -10,8 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; use dom::bindings::num::Finite; diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 4ddc0fef6dd..4cc54c43e73 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::HTMLCollectionBinding; use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::trace::JSTraceable; diff --git a/components/script/dom/htmldatalistelement.rs b/components/script/dom/htmldatalistelement.rs index 9b262ab686f..d0a9a51dce1 100644 --- a/components/script/dom/htmldatalistelement.rs +++ b/components/script/dom/htmldatalistelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::HTMLDataListElementBinding; use dom::bindings::codegen::Bindings::HTMLDataListElementBinding::HTMLDataListElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index b04082eae4d..115b4d88439 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::Reflectable; diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 63c614d308f..617dbb8e4c8 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -6,7 +6,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE}; diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index 6c54bfbc773..0b5e700933f 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -7,7 +7,7 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::HTMLFontElementBinding; use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index be4f092da72..58e82932df0 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -10,8 +10,9 @@ use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::conversions::{Castable, DerivedFrom}; +use dom::bindings::conversions::{DerivedFrom}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root}; use dom::bindings::utils::Reflectable; use dom::document::Document; diff --git a/components/script/dom/htmlheadelement.rs b/components/script/dom/htmlheadelement.rs index a2231a17729..7bb42b0cfea 100644 --- a/components/script/dom/htmlheadelement.rs +++ b/components/script/dom/htmlheadelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::HTMLHeadElementBinding; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index da119309bef..6e4a32e603e 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -6,9 +6,10 @@ use dom::attr::{Attr, AttrHelpersForLayout, AttrValue}; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::conversions::{Castable, ToJSValConvertible}; +use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, LayoutJS}; use dom::bindings::utils::Reflectable; use dom::customevent::CustomEvent; diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 25b93621c02..b8148b43703 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -8,7 +8,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::HTMLImageElementBinding; use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{LayoutJS, Root}; diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index b82f96aed63..686ca1b2f6a 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, LayoutJS, Root, RootedReference}; use dom::document::Document; diff --git a/components/script/dom/htmllabelelement.rs b/components/script/dom/htmllabelelement.rs index bcda8df24cc..fba46fa4a56 100644 --- a/components/script/dom/htmllabelelement.rs +++ b/components/script/dom/htmllabelelement.rs @@ -5,7 +5,7 @@ use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index fc7a1818c00..b0e464b4db0 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -8,7 +8,7 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{RootedReference}; diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 0b0fcd4e4c8..fa981a767ad 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::HTMLMetaElementBinding; use dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 49a16688854..c69329c2148 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -6,7 +6,7 @@ use dom::attr::Attr; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::HTMLObjectElementBinding; use dom::bindings::codegen::Bindings::HTMLObjectElementBinding::HTMLObjectElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 4d9ec9b6ca9..c63d02788d9 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -5,7 +5,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding; use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE}; diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 8c7dea8ac1e..62241f7c4f0 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods use dom::bindings::codegen::Bindings::HTMLOptionElementBinding; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::characterdata::CharacterData; use dom::document::Document; diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 97fefdf30e2..279f5d59536 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, Root}; diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index 04a3d174108..2df77b10719 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::HTMLSelectElementBinding; use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods; use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE}; diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index f33eb938f4e..ee1e38da54c 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -5,7 +5,7 @@ use cssparser::Parser as CssParser; use dom::bindings::codegen::Bindings::HTMLStyleElementBinding; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 3f1b13633f2..c0d04f6f77d 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -6,7 +6,7 @@ use cssparser::RGBA; use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::LayoutJS; use dom::document::Document; use dom::element::AttributeMutation; diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index ddd87314587..de3a4cf0631 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -7,7 +7,7 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableElementBinding; use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index 8db70bd9d2a..943c9055550 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -6,7 +6,7 @@ use cssparser::RGBA; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods}; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; use dom::document::Document; diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 5c6f04ef0ec..2121089d4dc 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -6,7 +6,7 @@ use cssparser::RGBA; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::{self, HTMLTableSectionElementMethods}; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; diff --git a/components/script/dom/htmltemplateelement.rs b/components/script/dom/htmltemplateelement.rs index cd2f7393614..77e7843d0e5 100644 --- a/components/script/dom/htmltemplateelement.rs +++ b/components/script/dom/htmltemplateelement.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::document::Document; use dom::documentfragment::DocumentFragment; diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 2ef5a24775d..855fe59cf3b 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{LayoutJS, Root}; use dom::bindings::refcounted::Trusted; diff --git a/components/script/dom/htmltitleelement.rs b/components/script/dom/htmltitleelement.rs index cb22a7bd9c2..a5e608ca891 100644 --- a/components/script/dom/htmltitleelement.rs +++ b/components/script/dom/htmltitleelement.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::HTMLTitleElementBinding; use dom::bindings::codegen::Bindings::HTMLTitleElementBinding::HTMLTitleElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::characterdata::CharacterData; use dom::document::Document; diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index e3d2bf4f657..db94b451318 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::KeyboardEventBinding; use dom::bindings::codegen::Bindings::KeyboardEventBinding::{KeyboardEventConstants, KeyboardEventMethods}; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{Root, RootedReference}; diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index e5193dcc8f1..13477436a08 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -6,7 +6,7 @@ macro_rules! make_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self) -> DOMString { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -22,7 +22,7 @@ macro_rules! make_getter( macro_rules! make_bool_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self) -> bool { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -39,7 +39,7 @@ macro_rules! make_bool_getter( macro_rules! make_uint_getter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(&self) -> u32 { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -59,7 +59,7 @@ macro_rules! make_uint_getter( macro_rules! make_url_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self) -> DOMString { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -77,7 +77,7 @@ macro_rules! make_url_getter( macro_rules! make_url_or_base_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self) -> DOMString { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -99,7 +99,7 @@ macro_rules! make_url_or_base_getter( macro_rules! make_enumerated_getter( ( $attr:ident, $htmlname:expr, $default:expr, $(($choices: pat))|+) => ( fn $attr(&self) -> DOMString { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use std::ascii::AsciiExt; use std::borrow::ToOwned; @@ -125,7 +125,7 @@ macro_rules! make_enumerated_getter( macro_rules! make_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self, value: DOMString) { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -139,7 +139,7 @@ macro_rules! make_setter( macro_rules! make_bool_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self, value: bool) { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -153,7 +153,7 @@ macro_rules! make_bool_setter( macro_rules! make_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(&self, value: u32) { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use dom::values::UNSIGNED_LONG_MAX; use string_cache::Atom; @@ -176,7 +176,7 @@ macro_rules! make_uint_setter( macro_rules! make_limited_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use dom::values::UNSIGNED_LONG_MAX; use string_cache::Atom; @@ -205,7 +205,7 @@ macro_rules! make_limited_uint_setter( macro_rules! make_atomic_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(&self, value: DOMString) { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::element::Element; use string_cache::Atom; let element = self.upcast::(); @@ -250,14 +250,14 @@ macro_rules! no_jsmanaged_fields( macro_rules! define_event_handler( ($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => ( fn $getter(&self) -> Option<::std::rc::Rc<$handler>> { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::eventtarget::EventTarget; let eventtarget = self.upcast::(); eventtarget.get_event_handler_common(stringify!($event_type)) } fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) { - use dom::bindings::conversions::Castable; + use dom::bindings::inheritance::Castable; use dom::eventtarget::EventTarget; let eventtarget = self.upcast::(); eventtarget.set_event_handler_common(stringify!($event_type), listener) diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index 4af83b3af7d..b767c738f8a 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::MessageEventBinding; use dom::bindings::codegen::Bindings::MessageEventBinding::MessageEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index b248e2dac1c..1bb0eabac6e 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -60,7 +60,7 @@ //! and check whether a given instance is of a given type. //! //! ```ignore -//! use dom::bindings::conversions::Castable; +//! use dom::bindings::inheritance::Castable; //! use dom::element::Element; //! use dom::htmlelement::HTMLElement; //! use dom::htmlinputelement::HTMLInputElement; diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index e34be058cd1..904b9fddb80 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::MouseEventBinding; use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 18c40157514..43f7d0e9449 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -22,9 +22,10 @@ use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingIn use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId}; use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::conversions::{self, Castable, DerivedFrom}; +use dom::bindings::conversions::{self, DerivedFrom}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; diff --git a/components/script/dom/progressevent.rs b/components/script/dom/progressevent.rs index 864fd4285c4..1d03015ffad 100644 --- a/components/script/dom/progressevent.rs +++ b/components/script/dom/progressevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::ProgressEventBinding; use dom::bindings::codegen::Bindings::ProgressEventBinding::ProgressEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 2d89530ef1b..86f8ae8a8bd 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants}; use dom::bindings::codegen::Bindings::TextBinding::TextMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root, RootedReference}; diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 8d0377b30ee..9a21c98e607 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::StorageBinding; use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{Root, RootedReference}; diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs index 8d1e9139254..92a0fb197b5 100644 --- a/components/script/dom/storageevent.rs +++ b/components/script/dom/storageevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventMethods}; use dom::bindings::codegen::Bindings::StorageEventBinding; use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs index d7c21cfa78d..e11a3e7d579 100644 --- a/components/script/dom/text.rs +++ b/components/script/dom/text.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods}; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; diff --git a/components/script/dom/touchevent.rs b/components/script/dom/touchevent.rs index 5244e4c9e35..e87f47c4747 100644 --- a/components/script/dom/touchevent.rs +++ b/components/script/dom/touchevent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::TouchEventBinding; use dom::bindings::codegen::Bindings::TouchEventBinding::TouchEventMethods; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::utils::reflect_dom_object; diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 5f6e8609795..41eb6097005 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::UIEventBinding; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs index 35b1c2333a5..ad03330bd7f 100644 --- a/components/script/dom/userscripts.rs +++ b/components/script/dom/userscripts.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{RootedReference}; use dom::htmlheadelement::HTMLHeadElement; use dom::node::Node; diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 32406205e5d..1e1ee2f03d1 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -6,7 +6,7 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::InheritTypes::ElementTypeId; use dom::bindings::codegen::InheritTypes::HTMLElementTypeId; use dom::bindings::codegen::InheritTypes::NodeTypeId; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::document::Document; use dom::element::{AttributeMutation, Element}; use dom::event::Event; diff --git a/components/script/dom/webglcontextevent.rs b/components/script/dom/webglcontextevent.rs index 6a2e709f765..8f4eda6a535 100644 --- a/components/script/dom/webglcontextevent.rs +++ b/components/script/dom/webglcontextevent.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::WebGLContextEventBinding; use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventInit; use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index aa92967cb1e..03762f887d5 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -9,8 +9,9 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; -use dom::bindings::conversions::{Castable, ToJSValConvertible}; +use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 88f3c6a2f8e..595ee147cdf 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -6,9 +6,10 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::WebSocketBinding; use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMethods}; -use dom::bindings::conversions::{Castable, ToJSValConvertible}; +use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; use dom::bindings::str::USVString; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index abe693696fd..f922a7a5ae3 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::{EventHandlerNonNull, use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions}; use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, Fallible, report_pending_exception}; use dom::bindings::global::GlobalRef; use dom::bindings::global::global_object_for_js_object; diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index b80f89720fa..7745319c19d 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -6,7 +6,7 @@ use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::WorkerBinding; use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::Root; diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index abf7f935240..693b4116756 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -5,7 +5,7 @@ use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg}; use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index a68d9478270..5afd4cb7777 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -12,9 +12,10 @@ use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestRespo use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType::{Json, Text, _empty}; use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams; use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLSearchParams}; -use dom::bindings::conversions::{Castable, ToJSValConvertible}; +use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef, GlobalRoot}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::refcounted::Trusted; diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 30bb371667b..7efed232426 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -23,8 +23,9 @@ use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo}; use document_loader::{DocumentLoader, LoadType}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; -use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior}; +use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, RootCollection, trace_roots}; use dom::bindings::js::{Root, RootCollectionPtr, RootedReference}; use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects}; diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 5e9b87be23a..e8427eb9257 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -7,7 +7,8 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; -use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior}; +use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::element::Element; use dom::htmliframeelement::HTMLIFrameElement; From 45224028dbc1d75e6dfc8add19ff8e997c7ebb99 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Tue, 27 Oct 2015 17:58:34 +0900 Subject: [PATCH 2/8] more refactoring --- components/layout/wrapper.rs | 2 +- components/plugins/reflector.rs | 10 +- components/script/dom/attr.rs | 2 +- components/script/dom/bindings/callback.rs | 2 +- .../dom/bindings/codegen/CodegenRust.py | 7 +- components/script/dom/bindings/conversions.rs | 4 +- components/script/dom/bindings/global.rs | 3 +- components/script/dom/bindings/inheritance.rs | 4 +- components/script/dom/bindings/js.rs | 3 +- components/script/dom/bindings/mod.rs | 3 + components/script/dom/bindings/refcounted.rs | 3 +- components/script/dom/bindings/reflector.rs | 79 ++++ components/script/dom/bindings/trace.rs | 3 +- components/script/dom/bindings/utils.rs | 239 ------------ components/script/dom/bindings/xmlname.rs | 176 +++++++++ components/script/dom/blob.rs | 2 +- components/script/dom/browsercontext.rs | 3 +- components/script/dom/canvasgradient.rs | 2 +- components/script/dom/canvaspattern.rs | 2 +- .../script/dom/canvasrenderingcontext2d.rs | 2 +- components/script/dom/closeevent.rs | 2 +- components/script/dom/console.rs | 2 +- components/script/dom/crypto.rs | 2 +- components/script/dom/css.rs | 2 +- components/script/dom/cssstyledeclaration.rs | 2 +- components/script/dom/customevent.rs | 2 +- .../script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/document.rs | 7 +- components/script/dom/domexception.rs | 2 +- components/script/dom/domimplementation.rs | 4 +- components/script/dom/domparser.rs | 2 +- components/script/dom/dompoint.rs | 2 +- components/script/dom/dompointreadonly.rs | 2 +- components/script/dom/domrect.rs | 2 +- components/script/dom/domrectlist.rs | 2 +- components/script/dom/domrectreadonly.rs | 2 +- components/script/dom/domstringmap.rs | 2 +- components/script/dom/domtokenlist.rs | 2 +- components/script/dom/element.rs | 4 +- components/script/dom/errorevent.rs | 2 +- components/script/dom/event.rs | 2 +- components/script/dom/eventtarget.rs | 3 +- components/script/dom/file.rs | 2 +- components/script/dom/filelist.rs | 2 +- components/script/dom/filereader.rs | 3 +- components/script/dom/formdata.rs | 2 +- components/script/dom/htmlareaelement.rs | 2 +- components/script/dom/htmlbodyelement.rs | 2 +- components/script/dom/htmlcanvaselement.rs | 2 +- .../dom/htmlcanvaselement.rs.BACKUP.20128.rs | 355 ++++++++++++++++++ .../dom/htmlcanvaselement.rs.BACKUP.20237.rs | 355 ++++++++++++++++++ .../dom/htmlcanvaselement.rs.BASE.20128.rs | 307 +++++++++++++++ .../dom/htmlcanvaselement.rs.BASE.20237.rs | 307 +++++++++++++++ .../dom/htmlcanvaselement.rs.LOCAL.20128.rs | 351 +++++++++++++++++ .../dom/htmlcanvaselement.rs.LOCAL.20237.rs | 351 +++++++++++++++++ .../dom/htmlcanvaselement.rs.REMOTE.20128.rs | 307 +++++++++++++++ .../dom/htmlcanvaselement.rs.REMOTE.20237.rs | 307 +++++++++++++++ .../script/dom/htmlcanvaselement.rs.orig | 355 ++++++++++++++++++ components/script/dom/htmlcollection.rs | 3 +- components/script/dom/htmlelement.rs | 2 +- components/script/dom/htmlformelement.rs | 4 +- components/script/dom/htmliframeelement.rs | 2 +- components/script/dom/imagedata.rs | 2 +- components/script/dom/keyboardevent.rs | 3 +- components/script/dom/location.rs | 2 +- components/script/dom/messageevent.rs | 2 +- components/script/dom/mouseevent.rs | 2 +- components/script/dom/namednodemap.rs | 3 +- components/script/dom/navigator.rs | 2 +- components/script/dom/node.rs | 3 +- components/script/dom/nodeiterator.rs | 2 +- components/script/dom/nodelist.rs | 2 +- components/script/dom/performance.rs | 2 +- components/script/dom/performancetiming.rs | 2 +- components/script/dom/progressevent.rs | 2 +- components/script/dom/range.rs | 2 +- components/script/dom/screen.rs | 2 +- components/script/dom/servohtmlparser.rs | 2 +- components/script/dom/storage.rs | 2 +- components/script/dom/storageevent.rs | 2 +- components/script/dom/testbinding.rs | 2 +- components/script/dom/testbindingproxy.rs | 2 +- components/script/dom/textdecoder.rs | 2 +- components/script/dom/textencoder.rs | 2 +- components/script/dom/touch.rs | 2 +- components/script/dom/touchevent.rs | 2 +- components/script/dom/touchlist.rs | 2 +- components/script/dom/treewalker.rs | 2 +- components/script/dom/uievent.rs | 2 +- components/script/dom/url.rs | 2 +- components/script/dom/urlsearchparams.rs | 2 +- components/script/dom/validitystate.rs | 2 +- components/script/dom/webglactiveinfo.rs | 2 +- components/script/dom/webglbuffer.rs | 2 +- components/script/dom/webglcontextevent.rs | 2 +- components/script/dom/webglframebuffer.rs | 2 +- components/script/dom/webglobject.rs | 2 +- components/script/dom/webglprogram.rs | 2 +- components/script/dom/webglrenderbuffer.rs | 2 +- .../script/dom/webglrenderingcontext.rs | 4 +- components/script/dom/webglshader.rs | 2 +- .../script/dom/webglshaderprecisionformat.rs | 2 +- components/script/dom/webgltexture.rs | 2 +- components/script/dom/webgluniformlocation.rs | 2 +- components/script/dom/websocket.rs | 3 +- components/script/dom/window.rs | 3 +- components/script/dom/worker.rs | 3 +- components/script/dom/workerglobalscope.rs | 2 +- components/script/dom/workerlocation.rs | 2 +- components/script/dom/workernavigator.rs | 2 +- components/script/dom/xmlhttprequest.rs | 3 +- components/script/dom/xmlhttprequestupload.rs | 2 +- components/script/mem.rs | 2 +- components/script/parse/html.rs | 2 +- components/script/timers.rs | 2 +- 115 files changed, 3387 insertions(+), 354 deletions(-) create mode 100644 components/script/dom/bindings/reflector.rs create mode 100644 components/script/dom/bindings/xmlname.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.BASE.20128.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.BASE.20237.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs create mode 100644 components/script/dom/htmlcanvaselement.rs.orig diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 8d6467e9b64..4deb9c1aba6 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -39,7 +39,7 @@ use opaque_node::OpaqueNodeMethods; use script::dom::attr::AttrValue; use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId}; use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId}; -use script::dom::bindings::conversions::Castable; +use script::dom::bindings::inheritance::Castable; use script::dom::bindings::js::LayoutJS; use script::dom::characterdata::LayoutCharacterDataHelpers; use script::dom::document::{Document, LayoutDocumentHelpers}; diff --git a/components/plugins/reflector.rs b/components/plugins/reflector.rs index 4e4a0f3b442..027f2ecf172 100644 --- a/components/plugins/reflector.rs +++ b/components/plugins/reflector.rs @@ -16,13 +16,13 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: let struct_name = item.ident; // This path has to be hardcoded, unfortunately, since we can't resolve paths at expansion time match def.fields.iter().find( - |f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) { + |f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "reflector", "Reflector"]).is_some()) { // If it has a field that is a Reflector, use that Some(f) => { let field_name = f.node.ident(); let impl_item = quote_item!(cx, - impl ::dom::bindings::utils::Reflectable for $struct_name { - fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { + impl ::dom::bindings::reflector::Reflectable for $struct_name { + fn reflector<'a>(&'a self) -> &'a ::dom::bindings::reflector::Reflector { &self.$field_name } fn init_reflector(&mut self, obj: *mut ::js::jsapi::JSObject) { @@ -36,8 +36,8 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: None => { let field_name = def.fields[0].node.ident(); let impl_item = quote_item!(cx, - impl ::dom::bindings::utils::Reflectable for $struct_name { - fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { + impl ::dom::bindings::reflector::Reflectable for $struct_name { + fn reflector<'a>(&'a self) -> &'a ::dom::bindings::reflector::Reflector { self.$field_name.reflector() } fn init_reflector(&mut self, obj: *mut ::js::jsapi::JSObject) { diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index f9d85314169..747d5f74013 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -10,7 +10,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::js::{LayoutJS, Root, RootedReference}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::{AttributeMutation, Element}; use dom::values::UNSIGNED_LONG_MAX; use dom::virtualmethods::vtable_for; diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index a879e469e27..1b067c5c596 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -6,7 +6,7 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::global_object_for_js_object; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use js::jsapi::GetGlobalForObjectCrossCompartment; use js::jsapi::{Heap, MutableHandleObject, RootedObject, RootedValue}; use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject}; diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 51a4653279f..bd81592d43c 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5197,6 +5197,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::global::global_object_for_js_object', 'dom::bindings::js::{JS, Root, RootedReference}', 'dom::bindings::js::{OptionalRootedReference}', + 'dom::bindings::reflector::{Reflectable}', 'dom::bindings::utils::{create_dom_global, do_create_interface_objects}', 'dom::bindings::utils::ConstantSpec', 'dom::bindings::utils::{DOMClass}', @@ -5206,7 +5207,6 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::{finalize_global, trace_global}', 'dom::bindings::utils::has_property_on_prototype', 'dom::bindings::utils::is_platform_object', - 'dom::bindings::utils::{Reflectable}', 'dom::bindings::utils::throwing_constructor', 'dom::bindings::utils::get_dictionary_property', 'dom::bindings::utils::set_dictionary_property', @@ -5915,10 +5915,11 @@ class GlobalGenRoots(): descriptors = config.getDescriptors(register=True, isCallback=False) imports = [CGGeneric("use dom::types::*;\n"), - CGGeneric("use dom::bindings::conversions::{Castable, DerivedFrom, get_dom_class};\n"), + CGGeneric("use dom::bindings::conversions::{DerivedFrom, get_dom_class};\n"), + CGGeneric("use dom::bindings::inheritance::Castable;\n"), CGGeneric("use dom::bindings::js::{JS, LayoutJS, Root};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), - CGGeneric("use dom::bindings::utils::Reflectable;\n"), + CGGeneric("use dom::bindings::reflector::Reflectable;\n"), CGGeneric("use js::jsapi::JSTracer;\n\n"), CGGeneric("use std::mem;\n\n")] allprotos = [] diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index c8f3b986623..1da266efe4c 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -38,7 +38,8 @@ use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::num::Finite; use dom::bindings::str::{ByteString, USVString}; -use dom::bindings::utils::{DOMClass, Reflectable, Reflector}; +use dom::bindings::reflector::{Reflectable, Reflector}; +use dom::bindings::utils::DOMClass; use js; use js::glue::{GetProxyPrivate, IsWrapper, RUST_JS_NumberValue}; use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject}; @@ -56,7 +57,6 @@ use libc; use num::Float; use num::traits::{Bounded, Zero}; use std::borrow::ToOwned; -use std::mem; use std::rc::Rc; use std::{char, ptr, slice}; use util::str::DOMString; diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index a1a1c68c8c0..d0b38196608 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -11,7 +11,8 @@ use devtools_traits::ScriptToDevtoolsControlMsg; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::conversions::native_from_reflector_jsmanaged; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflectable, Reflector}; +use dom::bindings::reflector::Reflector; +use dom::bindings::reflector::Reflectable; use dom::window::{self, ScriptHelpers}; use dom::workerglobalscope::WorkerGlobalScope; use ipc_channel::ipc::IpcSender; diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs index 5878c44c5f3..6ee06999563 100644 --- a/components/script/dom/bindings/inheritance.rs +++ b/components/script/dom/bindings/inheritance.rs @@ -2,9 +2,11 @@ * 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/. */ +//! The `Castable` trait. + use dom::bindings::conversions::get_dom_class; use dom::bindings::conversions::{DerivedFrom, IDLInterface}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use std::mem; /// A trait to hold the cast functions of IDL interfaces that either derive diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 388a8ba81ef..d347b00bb4f 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -28,7 +28,8 @@ use dom::bindings::conversions::DerivedFrom; use dom::bindings::inheritance::Castable; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::trace_reflector; -use dom::bindings::utils::{Reflectable, Reflector}; +use dom::bindings::reflector::Reflector; +use dom::bindings::reflector::Reflectable; use dom::node::Node; use js::jsapi::{Heap, JSObject, JSTracer}; use js::jsval::JSVal; diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index 394c7b722bf..f4b795f8c58 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -137,14 +137,17 @@ pub mod cell; pub mod conversions; pub mod error; pub mod global; +pub mod inheritance; pub mod js; pub mod num; pub mod proxyhandler; pub mod refcounted; +pub mod reflector; pub mod str; pub mod structuredclone; pub mod trace; pub mod utils; +pub mod xmlname; /// Generated JS-Rust bindings. #[allow(missing_docs, non_snake_case)] diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index ee8647be3ce..e101d2bbd83 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -25,7 +25,8 @@ use core::nonzero::NonZero; use dom::bindings::js::Root; use dom::bindings::trace::trace_reflector; -use dom::bindings::utils::{Reflectable, Reflector}; +use dom::bindings::reflector::Reflector; +use dom::bindings::reflector::Reflectable; use js::jsapi::{JSContext, JSTracer}; use libc; use script_task::{CommonScriptMsg, ScriptChan}; diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs new file mode 100644 index 00000000000..3279f4de55e --- /dev/null +++ b/components/script/dom/bindings/reflector.rs @@ -0,0 +1,79 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +//! The `Reflector` struct. + +use dom::bindings::global::GlobalRef; +use dom::bindings::js::Root; +use js::jsapi::{HandleObject, JSContext, JSObject}; +use std::cell::UnsafeCell; +use std::ptr; + +/// Create the reflector for a new DOM object and yield ownership to the +/// reflector. +pub fn reflect_dom_object + (obj: Box, + global: GlobalRef, + wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box) -> Root) + -> Root { + wrap_fn(global.get_cx(), global, obj) +} + +/// A struct to store a reference to the reflector of a DOM object. +#[allow(raw_pointer_derive, unrooted_must_root)] +#[must_root] +#[servo_lang = "reflector"] +#[derive(HeapSizeOf)] +// If you're renaming or moving this field, update the path in plugins::reflector as well +pub struct Reflector { + #[ignore_heap_size_of = "defined and measured in rust-mozjs"] + object: UnsafeCell<*mut JSObject>, +} + +#[allow(unrooted_must_root)] +impl PartialEq for Reflector { + fn eq(&self, other: &Reflector) -> bool { + unsafe { *self.object.get() == *other.object.get() } + } +} + +impl Reflector { + /// Get the reflector. + #[inline] + pub fn get_jsobject(&self) -> HandleObject { + unsafe { HandleObject::from_marked_location(self.object.get()) } + } + + /// Initialize the reflector. (May be called only once.) + pub fn set_jsobject(&mut self, object: *mut JSObject) { + unsafe { + let obj = self.object.get(); + assert!((*obj).is_null()); + assert!(!object.is_null()); + *obj = object; + } + } + + /// Return a pointer to the memory location at which the JS reflector + /// object is stored. Used to root the reflector, as + /// required by the JSAPI rooting APIs. + pub fn rootable(&self) -> *mut *mut JSObject { + self.object.get() + } + + /// Create an uninitialized `Reflector`. + pub fn new() -> Reflector { + Reflector { + object: UnsafeCell::new(ptr::null_mut()) + } + } +} + +/// A trait to provide access to the `Reflector` for a DOM object. +pub trait Reflectable { + /// Returns the receiver's reflector. + fn reflector(&self) -> &Reflector; + /// Initializes the Reflector + fn init_reflector(&mut self, obj: *mut JSObject); +} \ No newline at end of file diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index c78429f8368..6ed7e45c45a 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -35,7 +35,8 @@ use canvas_traits::{CompositionOrBlending, LineCapStyle, LineJoinStyle, Repetiti use cssparser::RGBA; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; -use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler}; +use dom::bindings::reflector::{Reflectable, Reflector}; +use dom::bindings::utils::WindowProxyHandler; use encoding::types::EncodingRef; use euclid::length::Length as EuclidLength; use euclid::matrix2d::Matrix2D; diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 6fae276271c..72c0745d3b1 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -49,14 +49,10 @@ use js::rust::{GCMethods, ToString, define_methods, define_properties}; use js::{JSFUN_CONSTRUCTOR, JSPROP_ENUMERATE, JS_CALLEE}; use js::{JSPROP_PERMANENT, JSPROP_READONLY}; use libc::{self, c_uint}; -use std::cell::UnsafeCell; -use std::cmp::PartialEq; use std::default::Default; use std::ffi::CString; use std::ptr; -use string_cache::{Atom, Namespace}; use util::mem::HeapSizeOf; -use util::str::DOMString; /// Proxy handler for a WindowProxy. #[allow(raw_pointer_derive)] @@ -391,74 +387,6 @@ pub fn initialize_global(global: *mut JSObject) { } } -/// A trait to provide access to the `Reflector` for a DOM object. -pub trait Reflectable { - /// Returns the receiver's reflector. - fn reflector(&self) -> &Reflector; - /// Initializes the Reflector - fn init_reflector(&mut self, obj: *mut JSObject); -} - -/// Create the reflector for a new DOM object and yield ownership to the -/// reflector. -pub fn reflect_dom_object - (obj: Box, - global: GlobalRef, - wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box) -> Root) - -> Root { - wrap_fn(global.get_cx(), global, obj) -} - -/// A struct to store a reference to the reflector of a DOM object. -#[allow(raw_pointer_derive, unrooted_must_root)] -#[must_root] -#[servo_lang = "reflector"] -#[derive(HeapSizeOf)] -// If you're renaming or moving this field, update the path in plugins::reflector as well -pub struct Reflector { - #[ignore_heap_size_of = "defined and measured in rust-mozjs"] - object: UnsafeCell<*mut JSObject>, -} - -#[allow(unrooted_must_root)] -impl PartialEq for Reflector { - fn eq(&self, other: &Reflector) -> bool { - unsafe { *self.object.get() == *other.object.get() } - } -} - -impl Reflector { - /// Get the reflector. - #[inline] - pub fn get_jsobject(&self) -> HandleObject { - unsafe { HandleObject::from_marked_location(self.object.get()) } - } - - /// Initialize the reflector. (May be called only once.) - pub fn set_jsobject(&mut self, object: *mut JSObject) { - unsafe { - let obj = self.object.get(); - assert!((*obj).is_null()); - assert!(!object.is_null()); - *obj = object; - } - } - - /// Return a pointer to the memory location at which the JS reflector - /// object is stored. Used to root the reflector, as - /// required by the JSAPI rooting APIs. - pub fn rootable(&self) -> *mut *mut JSObject { - self.object.get() - } - - /// Create an uninitialized `Reflector`. - pub fn new() -> Reflector { - Reflector { - object: UnsafeCell::new(ptr::null_mut()) - } - } -} - /// Gets the property `id` on `proxy`'s prototype. If it exists, `*found` is /// set to true and `*vp` to the value, otherwise `*found` is set to false. /// @@ -800,21 +728,6 @@ pub unsafe extern fn generic_lenient_setter(cx: *mut JSContext, generic_call(cx, argc, vp, true, call_setter) } -/// Validate a qualified name. See https://dom.spec.whatwg.org/#validate for details. -pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { - match xml_name_type(qualified_name) { - XMLName::InvalidXMLName => { - // Step 1. - Err(Error::InvalidCharacter) - }, - XMLName::Name => { - // Step 2. - Err(Error::Namespace) - }, - XMLName::QName => Ok(()) - } -} - unsafe extern "C" fn instance_class_has_proto_at_depth(clasp: *const js::jsapi::Class, proto_id: u32, depth: u32) -> bool { @@ -827,155 +740,3 @@ unsafe extern "C" fn instance_class_has_proto_at_depth(clasp: *const js::jsapi:: pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks { instanceClassMatchesProto: Some(instance_class_has_proto_at_depth), }; - -/// Validate a namespace and qualified name and extract their parts. -/// See https://dom.spec.whatwg.org/#validate-and-extract for details. -pub fn validate_and_extract(namespace: Option, qualified_name: &str) - -> Fallible<(Namespace, Option, Atom)> { - // Step 1. - let namespace = namespace_from_domstring(namespace); - - // Step 2. - try!(validate_qualified_name(qualified_name)); - - let colon = ':'; - - // Step 5. - let mut parts = qualified_name.splitn(2, colon); - - let (maybe_prefix, local_name) = { - let maybe_prefix = parts.next(); - let maybe_local_name = parts.next(); - - debug_assert!(parts.next().is_none()); - - if let Some(local_name) = maybe_local_name { - debug_assert!(!maybe_prefix.unwrap().is_empty()); - - (maybe_prefix, local_name) - } else { - (None, maybe_prefix.unwrap()) - } - }; - - debug_assert!(!local_name.contains(colon)); - - match (namespace, maybe_prefix) { - (ns!(""), Some(_)) => { - // Step 6. - Err(Error::Namespace) - }, - (ref ns, Some("xml")) if ns != &ns!(XML) => { - // Step 7. - Err(Error::Namespace) - }, - (ref ns, p) if ns != &ns!(XMLNS) && - (qualified_name == "xmlns" || p == Some("xmlns")) => { - // Step 8. - Err(Error::Namespace) - }, - (ns!(XMLNS), p) if qualified_name != "xmlns" && p != Some("xmlns") => { - // Step 9. - Err(Error::Namespace) - }, - (ns, p) => { - // Step 10. - Ok((ns, p.map(Atom::from_slice), Atom::from_slice(local_name))) - } - } -} - -/// Results of `xml_name_type`. -#[derive(PartialEq)] -#[allow(missing_docs)] -pub enum XMLName { - QName, - Name, - InvalidXMLName -} - -/// Check if an element name is valid. See http://www.w3.org/TR/xml/#NT-Name -/// for details. -pub fn xml_name_type(name: &str) -> XMLName { - fn is_valid_start(c: char) -> bool { - match c { - ':' | - 'A' ... 'Z' | - '_' | - 'a' ... 'z' | - '\u{C0}' ... '\u{D6}' | - '\u{D8}' ... '\u{F6}' | - '\u{F8}' ... '\u{2FF}' | - '\u{370}' ... '\u{37D}' | - '\u{37F}' ... '\u{1FFF}' | - '\u{200C}' ... '\u{200D}' | - '\u{2070}' ... '\u{218F}' | - '\u{2C00}' ... '\u{2FEF}' | - '\u{3001}' ... '\u{D7FF}' | - '\u{F900}' ... '\u{FDCF}' | - '\u{FDF0}' ... '\u{FFFD}' | - '\u{10000}' ... '\u{EFFFF}' => true, - _ => false, - } - } - - fn is_valid_continuation(c: char) -> bool { - is_valid_start(c) || match c { - '-' | - '.' | - '0' ... '9' | - '\u{B7}' | - '\u{300}' ... '\u{36F}' | - '\u{203F}' ... '\u{2040}' => true, - _ => false, - } - } - - let mut iter = name.chars(); - let mut non_qname_colons = false; - let mut seen_colon = false; - let mut last = match iter.next() { - None => return XMLName::InvalidXMLName, - Some(c) => { - if !is_valid_start(c) { - return XMLName::InvalidXMLName; - } - if c == ':' { - non_qname_colons = true; - } - c - } - }; - - for c in iter { - if !is_valid_continuation(c) { - return XMLName::InvalidXMLName; - } - if c == ':' { - match seen_colon { - true => non_qname_colons = true, - false => seen_colon = true - } - } - last = c - } - - if last == ':' { - non_qname_colons = true - } - - match non_qname_colons { - false => XMLName::QName, - true => XMLName::Name - } -} - -/// Convert a possibly-null URL to a namespace. -/// -/// If the URL is None, returns the empty namespace. -pub fn namespace_from_domstring(url: Option) -> Namespace { - match url { - None => ns!(""), - Some(ref s) => Namespace(Atom::from_slice(s)), - } -} diff --git a/components/script/dom/bindings/xmlname.rs b/components/script/dom/bindings/xmlname.rs new file mode 100644 index 00000000000..e8a53707420 --- /dev/null +++ b/components/script/dom/bindings/xmlname.rs @@ -0,0 +1,176 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +//! Functions for validating and extracting qualified XML names. + +use dom::bindings::error::{Error, ErrorResult, Fallible}; +use string_cache::{Atom, Namespace}; +use util::str::DOMString; + +/// Validate a qualified name. See https://dom.spec.whatwg.org/#validate for details. +pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult { + match xml_name_type(qualified_name) { + XMLName::InvalidXMLName => { + // Step 1. + Err(Error::InvalidCharacter) + }, + XMLName::Name => { + // Step 2. + Err(Error::Namespace) + }, + XMLName::QName => Ok(()) + } +} + +/// Validate a namespace and qualified name and extract their parts. +/// See https://dom.spec.whatwg.org/#validate-and-extract for details. +pub fn validate_and_extract(namespace: Option, qualified_name: &str) + -> Fallible<(Namespace, Option, Atom)> { + // Step 1. + let namespace = namespace_from_domstring(namespace); + + // Step 2. + try!(validate_qualified_name(qualified_name)); + + let colon = ':'; + + // Step 5. + let mut parts = qualified_name.splitn(2, colon); + + let (maybe_prefix, local_name) = { + let maybe_prefix = parts.next(); + let maybe_local_name = parts.next(); + + debug_assert!(parts.next().is_none()); + + if let Some(local_name) = maybe_local_name { + debug_assert!(!maybe_prefix.unwrap().is_empty()); + + (maybe_prefix, local_name) + } else { + (None, maybe_prefix.unwrap()) + } + }; + + debug_assert!(!local_name.contains(colon)); + + match (namespace, maybe_prefix) { + (ns!(""), Some(_)) => { + // Step 6. + Err(Error::Namespace) + }, + (ref ns, Some("xml")) if ns != &ns!(XML) => { + // Step 7. + Err(Error::Namespace) + }, + (ref ns, p) if ns != &ns!(XMLNS) && + (qualified_name == "xmlns" || p == Some("xmlns")) => { + // Step 8. + Err(Error::Namespace) + }, + (ns!(XMLNS), p) if qualified_name != "xmlns" && p != Some("xmlns") => { + // Step 9. + Err(Error::Namespace) + }, + (ns, p) => { + // Step 10. + Ok((ns, p.map(Atom::from_slice), Atom::from_slice(local_name))) + } + } +} + +/// Results of `xml_name_type`. +#[derive(PartialEq)] +#[allow(missing_docs)] +pub enum XMLName { + QName, + Name, + InvalidXMLName +} + +/// Check if an element name is valid. See http://www.w3.org/TR/xml/#NT-Name +/// for details. +pub fn xml_name_type(name: &str) -> XMLName { + fn is_valid_start(c: char) -> bool { + match c { + ':' | + 'A' ... 'Z' | + '_' | + 'a' ... 'z' | + '\u{C0}' ... '\u{D6}' | + '\u{D8}' ... '\u{F6}' | + '\u{F8}' ... '\u{2FF}' | + '\u{370}' ... '\u{37D}' | + '\u{37F}' ... '\u{1FFF}' | + '\u{200C}' ... '\u{200D}' | + '\u{2070}' ... '\u{218F}' | + '\u{2C00}' ... '\u{2FEF}' | + '\u{3001}' ... '\u{D7FF}' | + '\u{F900}' ... '\u{FDCF}' | + '\u{FDF0}' ... '\u{FFFD}' | + '\u{10000}' ... '\u{EFFFF}' => true, + _ => false, + } + } + + fn is_valid_continuation(c: char) -> bool { + is_valid_start(c) || match c { + '-' | + '.' | + '0' ... '9' | + '\u{B7}' | + '\u{300}' ... '\u{36F}' | + '\u{203F}' ... '\u{2040}' => true, + _ => false, + } + } + + let mut iter = name.chars(); + let mut non_qname_colons = false; + let mut seen_colon = false; + let mut last = match iter.next() { + None => return XMLName::InvalidXMLName, + Some(c) => { + if !is_valid_start(c) { + return XMLName::InvalidXMLName; + } + if c == ':' { + non_qname_colons = true; + } + c + } + }; + + for c in iter { + if !is_valid_continuation(c) { + return XMLName::InvalidXMLName; + } + if c == ':' { + match seen_colon { + true => non_qname_colons = true, + false => seen_colon = true + } + } + last = c + } + + if last == ':' { + non_qname_colons = true + } + + match non_qname_colons { + false => XMLName::QName, + true => XMLName::Name + } +} + +/// Convert a possibly-null URL to a namespace. +/// +/// If the URL is None, returns the empty namespace. +pub fn namespace_from_domstring(url: Option) -> Namespace { + match url { + None => ns!(""), + Some(ref s) => Namespace(Atom::from_slice(s)), + } +} diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index efbf1abbc15..0645a146c0f 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::error::Fallible; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use num::ToPrimitive; use std::ascii::AsciiExt; use std::borrow::ToOwned; diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs index 60dbdc5523e..a20b576cc1b 100644 --- a/components/script/dom/browsercontext.rs +++ b/components/script/dom/browsercontext.rs @@ -7,7 +7,8 @@ use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::js::{JS, Root}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; use dom::bindings::utils::get_array_index_from_id; -use dom::bindings::utils::{Reflectable, WindowProxyHandler}; +use dom::bindings::reflector::Reflectable; +use dom::bindings::utils::WindowProxyHandler; use dom::document::Document; use dom::element::Element; use dom::window::Window; diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index 8f8ad3cc99f..a9cf8a2d878 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -10,7 +10,7 @@ use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::canvasrenderingcontext2d::parse_color; // https://html.spec.whatwg.org/multipage/#canvasgradient diff --git a/components/script/dom/canvaspattern.rs b/components/script/dom/canvaspattern.rs index 7457c06a30d..2f385be82bf 100644 --- a/components/script/dom/canvaspattern.rs +++ b/components/script/dom/canvaspattern.rs @@ -6,7 +6,7 @@ use canvas_traits::{FillOrStrokeStyle, RepetitionStyle, SurfaceStyle}; use dom::bindings::codegen::Bindings::CanvasPatternBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::canvasgradient::ToFillOrStrokeStyle; use euclid::size::Size2D; diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index d60e02f921a..131dca45df8 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -19,7 +19,7 @@ use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, Root}; use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle}; use dom::canvaspattern::CanvasPattern; use dom::htmlcanvaselement::HTMLCanvasElement; diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs index c903a68262f..45362ea5741 100644 --- a/components/script/dom/closeevent.rs +++ b/components/script/dom/closeevent.rs @@ -9,7 +9,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use script_task::ScriptChan; use util::str::DOMString; diff --git a/components/script/dom/console.rs b/components/script/dom/console.rs index 8845ecd5b22..9303a433e36 100644 --- a/components/script/dom/console.rs +++ b/components/script/dom/console.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::ConsoleBinding; use dom::bindings::codegen::Bindings::ConsoleBinding::ConsoleMethods; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use util::str::DOMString; // https://developer.mozilla.org/en-US/docs/Web/API/Console diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs index cd5338a1868..5caa678017a 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use js::jsapi::{JSContext, JSObject}; use js::jsapi::{JS_GetArrayBufferViewType, JS_GetObjectAsArrayBufferView, Type}; use rand::{OsRng, Rng}; diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index 527b08315e9..a4cd3a132ec 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -5,7 +5,7 @@ use cssparser::serialize_identifier; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; -use dom::bindings::utils::Reflector; +use dom::bindings::reflector::Reflector; use util::str::DOMString; #[dom_struct] diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 763cc43059c..da8dc78878e 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -7,7 +7,7 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::{Element, StylePriority}; use dom::node::{Node, NodeDamage, document_from_node, window_from_node}; use dom::window::Window; diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 89edb89e202..6f7b04cc8e4 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{MutHeapJSVal, Root}; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::Event; use js::jsapi::{HandleValue, JSContext}; use js::jsval::JSVal; diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 596ac6b33de..5216ff13664 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -14,7 +14,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootCollection}; use dom::bindings::refcounted::LiveDOMReferences; use dom::bindings::structuredclone::StructuredCloneData; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::messageevent::MessageEvent; use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler}; use dom::workerglobalscope::WorkerGlobalScope; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 8aa8ab08447..ad9e51a9c08 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -24,9 +24,10 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::num::Finite; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::RootedVec; -use dom::bindings::utils::XMLName::InvalidXMLName; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; -use dom::bindings::utils::{validate_and_extract, xml_name_type}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; +use dom::bindings::xmlname::{validate_and_extract, xml_name_type}; +use dom::bindings::xmlname::XMLName::InvalidXMLName; use dom::comment::Comment; use dom::customevent::CustomEvent; use dom::documentfragment::DocumentFragment; diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index e63cbedafbc..8bc3497f5c9 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionConstants use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use std::borrow::ToOwned; use util::str::DOMString; diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 62db553454e..caf53a0d749 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -11,8 +11,8 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::validate_qualified_name; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::xmlname::validate_qualified_name; use dom::document::DocumentSource; use dom::document::{Document, IsHTMLDocument}; use dom::documenttype::DocumentType; diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index a66b8ea3962..10ecd077a31 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::document::DocumentSource; use dom::document::{Document, IsHTMLDocument}; use dom::window::Window; diff --git a/components/script/dom/dompoint.rs b/components/script/dom/dompoint.rs index 1f8e85f50ad..3d797598ba0 100644 --- a/components/script/dom/dompoint.rs +++ b/components/script/dom/dompoint.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyM use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::dompointreadonly::{DOMPointReadOnly, DOMPointWriteMethods}; // http://dev.w3.org/fxtf/geometry/Overview.html#dompoint diff --git a/components/script/dom/dompointreadonly.rs b/components/script/dom/dompointreadonly.rs index fd4965402cf..db56e70113d 100644 --- a/components/script/dom/dompointreadonly.rs +++ b/components/script/dom/dompointreadonly.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::{DOMPointReadOnly use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use std::cell::Cell; // http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly diff --git a/components/script/dom/domrect.rs b/components/script/dom/domrect.rs index fa1dcc1b165..aa4758d2b89 100644 --- a/components/script/dom/domrect.rs +++ b/components/script/dom/domrect.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::DOMRectReadOnlyMet use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::domrectreadonly::DOMRectReadOnly; #[dom_struct] diff --git a/components/script/dom/domrectlist.rs b/components/script/dom/domrectlist.rs index cd67dbc28c7..1c9c92ca3e3 100644 --- a/components/script/dom/domrectlist.rs +++ b/components/script/dom/domrectlist.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::DOMRectListBinding; use dom::bindings::codegen::Bindings::DOMRectListBinding::DOMRectListMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::domrect::DOMRect; use dom::window::Window; diff --git a/components/script/dom/domrectreadonly.rs b/components/script/dom/domrectreadonly.rs index a6ba99ead2a..f0bb23a20fe 100644 --- a/components/script/dom/domrectreadonly.rs +++ b/components/script/dom/domrectreadonly.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::DOMRectReadOnlyBinding::{DOMRectReadOnlyMe use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use std::cell::Cell; #[dom_struct] diff --git a/components/script/dom/domstringmap.rs b/components/script/dom/domstringmap.rs index 95f727c93cb..49b7d0f6cf8 100644 --- a/components/script/dom/domstringmap.rs +++ b/components/script/dom/domstringmap.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DOMStringMapBinding::DOMStringMapMethods; use dom::bindings::error::ErrorResult; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::htmlelement::HTMLElement; use dom::node::window_from_node; use util::str::DOMString; diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index c3944b7627c..fca96e5df16 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::element::Element; use dom::node::window_from_node; use std::borrow::ToOwned; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a26a292b7e6..8cdb4910d0d 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -26,8 +26,8 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; use dom::bindings::js::{Root, RootedReference}; -use dom::bindings::utils::XMLName::InvalidXMLName; -use dom::bindings::utils::{namespace_from_domstring, validate_and_extract, xml_name_type}; +use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type}; +use dom::bindings::xmlname::XMLName::InvalidXMLName; use dom::characterdata::CharacterData; use dom::create::create_element; use dom::document::{Document, LayoutDocumentHelpers}; diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index ada456c84c6..edc422e0dd7 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -11,7 +11,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{MutHeapJSVal, Root}; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use js::jsapi::{RootedValue, HandleValue, JSContext}; use js::jsval::JSVal; diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 6b63b3a58ee..34db84f561c 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethod use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::eventtarget::EventTarget; use std::borrow::ToOwned; use std::cell::Cell; diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 179e82917aa..31f603ee105 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -9,7 +9,8 @@ use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::codegen::InheritTypes::EventTargetTypeId; use dom::bindings::error::{Error, Fallible, report_pending_exception}; -use dom::bindings::utils::{Reflectable, Reflector}; +use dom::bindings::reflector::Reflector; +use dom::bindings::reflector::Reflectable; use dom::event::Event; use dom::eventdispatcher::dispatch_event; use dom::virtualmethods::VirtualMethods; diff --git a/components/script/dom/file.rs b/components/script/dom/file.rs index b9ccd721a47..5dfffd62541 100644 --- a/components/script/dom/file.rs +++ b/components/script/dom/file.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::FileBinding; use dom::bindings::codegen::Bindings::FileBinding::FileMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::blob::Blob; use util::str::DOMString; diff --git a/components/script/dom/filelist.rs b/components/script/dom/filelist.rs index d695ac8f43a..bed3d451b94 100644 --- a/components/script/dom/filelist.rs +++ b/components/script/dom/filelist.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::FileListBinding; use dom::bindings::codegen::Bindings::FileListBinding::FileListMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::file::File; use dom::window::Window; diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index fa71b76e83a..ad519c0efc8 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -10,7 +10,8 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::refcounted::Trusted; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; use dom::blob::Blob; use dom::domexception::{DOMErrorName, DOMException}; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 14b497fca15..8c02f132a88 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -11,7 +11,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::{Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::blob::Blob; use dom::file::File; use dom::htmlformelement::HTMLFormElement; diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index 871def58e54..cd01baf4930 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::HTMLAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::document::Document; use dom::domtokenlist::DOMTokenList; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 64719bae903..4ecb3d00225 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyEle use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::document::Document; use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; use dom::eventtarget::EventTarget; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 3829f036e2d..f7bbb1753af 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -14,7 +14,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; +use dom::bindings::reflector::Reflectable; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs b/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs new file mode 100644 index 00000000000..7b6fda591da --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs @@ -0,0 +1,355 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +<<<<<<< HEAD +use dom::bindings::conversions::Castable; +use dom::bindings::error::{Error, Fallible}; +======= +use dom::bindings::inheritance::Castable; +>>>>>>> move Castable into dom::bindings::inheritance +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use image::ColorType; +use image::png::PNGEncoder; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl + fn ToDataURL(&self, + _context: *mut JSContext, + _mime_type: Option, + _arguments: Vec) -> Fallible { + + // Step 1: Check the origin-clean flag (should be set in fillText/strokeText + // and currently unimplemented) + + // Step 2. + if self.Width() == 0 || self.Height() == 0 { + return Ok("data:,".to_owned()); + } + + // Step 3. + if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { + let window = window_from_node(self); + let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), + Finite::wrap(self.Width() as f64), + Finite::wrap(self.Height() as f64))); + let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); + + // Only handle image/png for now. + let mime_type = "image/png"; + + let mut encoded = Vec::new(); + { + let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); + encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); + } + + let encoded = encoded.to_base64(STANDARD); + Ok(format!("data:{};base64,{}", mime_type, encoded)) + } else { + Err(Error::NotSupported) + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs b/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs new file mode 100644 index 00000000000..7b6fda591da --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs @@ -0,0 +1,355 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +<<<<<<< HEAD +use dom::bindings::conversions::Castable; +use dom::bindings::error::{Error, Fallible}; +======= +use dom::bindings::inheritance::Castable; +>>>>>>> move Castable into dom::bindings::inheritance +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use image::ColorType; +use image::png::PNGEncoder; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl + fn ToDataURL(&self, + _context: *mut JSContext, + _mime_type: Option, + _arguments: Vec) -> Fallible { + + // Step 1: Check the origin-clean flag (should be set in fillText/strokeText + // and currently unimplemented) + + // Step 2. + if self.Width() == 0 || self.Height() == 0 { + return Ok("data:,".to_owned()); + } + + // Step 3. + if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { + let window = window_from_node(self); + let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), + Finite::wrap(self.Width() as f64), + Finite::wrap(self.Height() as f64))); + let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); + + // Only handle image/png for now. + let mime_type = "image/png"; + + let mut encoded = Vec::new(); + { + let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); + encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); + } + + let encoded = encoded.to_base64(STANDARD); + Ok(format!("data:{};base64,{}", mime_type, encoded)) + } else { + Err(Error::NotSupported) + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs b/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs new file mode 100644 index 00000000000..2fdb8a129e6 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs @@ -0,0 +1,307 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::conversions::Castable; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs b/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs new file mode 100644 index 00000000000..2fdb8a129e6 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs @@ -0,0 +1,307 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::conversions::Castable; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs b/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs new file mode 100644 index 00000000000..47126ed3dd0 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs @@ -0,0 +1,351 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::conversions::Castable; +use dom::bindings::error::{Error, Fallible}; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use image::ColorType; +use image::png::PNGEncoder; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl + fn ToDataURL(&self, + _context: *mut JSContext, + _mime_type: Option, + _arguments: Vec) -> Fallible { + + // Step 1: Check the origin-clean flag (should be set in fillText/strokeText + // and currently unimplemented) + + // Step 2. + if self.Width() == 0 || self.Height() == 0 { + return Ok("data:,".to_owned()); + } + + // Step 3. + if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { + let window = window_from_node(self); + let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), + Finite::wrap(self.Width() as f64), + Finite::wrap(self.Height() as f64))); + let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); + + // Only handle image/png for now. + let mime_type = "image/png"; + + let mut encoded = Vec::new(); + { + let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); + encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); + } + + let encoded = encoded.to_base64(STANDARD); + Ok(format!("data:{};base64,{}", mime_type, encoded)) + } else { + Err(Error::NotSupported) + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs b/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs new file mode 100644 index 00000000000..47126ed3dd0 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs @@ -0,0 +1,351 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::conversions::Castable; +use dom::bindings::error::{Error, Fallible}; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use image::ColorType; +use image::png::PNGEncoder; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl + fn ToDataURL(&self, + _context: *mut JSContext, + _mime_type: Option, + _arguments: Vec) -> Fallible { + + // Step 1: Check the origin-clean flag (should be set in fillText/strokeText + // and currently unimplemented) + + // Step 2. + if self.Width() == 0 || self.Height() == 0 { + return Ok("data:,".to_owned()); + } + + // Step 3. + if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { + let window = window_from_node(self); + let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), + Finite::wrap(self.Width() as f64), + Finite::wrap(self.Height() as f64))); + let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); + + // Only handle image/png for now. + let mime_type = "image/png"; + + let mut encoded = Vec::new(); + { + let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); + encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); + } + + let encoded = encoded.to_base64(STANDARD); + Ok(format!("data:{};base64,{}", mime_type, encoded)) + } else { + Err(Error::NotSupported) + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs b/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs new file mode 100644 index 00000000000..d15c7096f90 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs @@ -0,0 +1,307 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::inheritance::Castable; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs b/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs new file mode 100644 index 00000000000..d15c7096f90 --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs @@ -0,0 +1,307 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::inheritance::Castable; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcanvaselement.rs.orig b/components/script/dom/htmlcanvaselement.rs.orig new file mode 100644 index 00000000000..7b6fda591da --- /dev/null +++ b/components/script/dom/htmlcanvaselement.rs.orig @@ -0,0 +1,355 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; +use dom::attr::Attr; +use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; +use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; +use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +<<<<<<< HEAD +use dom::bindings::conversions::Castable; +use dom::bindings::error::{Error, Fallible}; +======= +use dom::bindings::inheritance::Castable; +>>>>>>> move Castable into dom::bindings::inheritance +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; +use dom::bindings::utils::{Reflectable}; +use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; +use dom::document::Document; +use dom::element::{AttributeMutation, Element}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, window_from_node}; +use dom::virtualmethods::VirtualMethods; +use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; +use euclid::size::Size2D; +use image::ColorType; +use image::png::PNGEncoder; +use ipc_channel::ipc::{self, IpcSender}; +use js::jsapi::{HandleValue, JSContext}; +use offscreen_gl_context::GLContextAttributes; +use rustc_serialize::base64::{STANDARD, ToBase64}; +use std::cell::Cell; +use std::iter::repeat; +use util::str::{DOMString, parse_unsigned_integer}; + +const DEFAULT_WIDTH: u32 = 300; +const DEFAULT_HEIGHT: u32 = 150; + +#[must_root] +#[derive(JSTraceable, Clone, HeapSizeOf)] +pub enum CanvasContext { + Context2d(JS), + WebGL(JS), +} + +impl HeapGCValue for CanvasContext {} + +#[dom_struct] +pub struct HTMLCanvasElement { + htmlelement: HTMLElement, + context: DOMRefCell>, + width: Cell, + height: Cell, +} + +impl PartialEq for HTMLCanvasElement { + fn eq(&self, other: &HTMLCanvasElement) -> bool { + self as *const HTMLCanvasElement == &*other + } +} + +impl HTMLCanvasElement { + fn new_inherited(localName: DOMString, + prefix: Option, + document: &Document) -> HTMLCanvasElement { + HTMLCanvasElement { + htmlelement: HTMLElement::new_inherited(localName, prefix, document), + context: DOMRefCell::new(None), + width: Cell::new(DEFAULT_WIDTH), + height: Cell::new(DEFAULT_HEIGHT), + } + } + + #[allow(unrooted_must_root)] + pub fn new(localName: DOMString, + prefix: Option, + document: &Document) -> Root { + let element = HTMLCanvasElement::new_inherited(localName, prefix, document); + Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) + } + + fn recreate_contexts(&self) { + let size = self.get_size(); + if let Some(ref context) = *self.context.borrow() { + match *context { + CanvasContext::Context2d(ref context) => context.recreate(size), + CanvasContext::WebGL(ref context) => context.recreate(size), + } + } + } + + pub fn get_size(&self) -> Size2D { + Size2D::new(self.width.get() as i32, self.height.get() as i32) + } +} + +pub struct HTMLCanvasData { + pub renderer_id: Option, + pub ipc_renderer: Option>, + pub width: u32, + pub height: u32, +} + +pub trait LayoutHTMLCanvasElementHelpers { + fn data(&self) -> HTMLCanvasData; +} + +impl LayoutHTMLCanvasElementHelpers for LayoutJS { + #[allow(unsafe_code)] + fn data(&self) -> HTMLCanvasData { + unsafe { + let canvas = &*self.unsafe_get(); + let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { + Some(&CanvasContext::Context2d(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + Some(&CanvasContext::WebGL(ref context)) => { + let context = context.to_layout(); + (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) + }, + None => (None, None), + }; + + HTMLCanvasData { + renderer_id: renderer_id, + ipc_renderer: ipc_renderer, + width: canvas.width.get(), + height: canvas.height.get(), + } + } + } +} + + +impl HTMLCanvasElement { + pub fn ipc_renderer(&self) -> Option> { + self.context.borrow().as_ref().map(|context| { + match *context { + CanvasContext::Context2d(ref context) => context.ipc_renderer(), + CanvasContext::WebGL(ref context) => context.ipc_renderer(), + } + }) + } + + pub fn get_or_init_2d_context(&self) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); + *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); + } + + match *self.context.borrow().as_ref().unwrap() { + CanvasContext::Context2d(ref context) => Some(context.root()), + _ => None, + } + } + + pub fn get_or_init_webgl_context(&self, + cx: *mut JSContext, + attrs: Option) -> Option> { + if self.context.borrow().is_none() { + let window = window_from_node(self); + let size = self.get_size(); + + let attrs = if let Some(webgl_attributes) = attrs { + if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { + From::from(attrs) + } else { + debug!("Unexpected error on conversion of WebGLContextAttributes"); + return None; + } + } else { + GLContextAttributes::default() + }; + + let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); + + *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); + } + + if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { + Some(context.root()) + } else { + None + } + } + + pub fn is_valid(&self) -> bool { + self.height.get() != 0 && self.width.get() != 0 + } + + pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { + let size = self.get_size(); + + if size.width == 0 || size.height == 0 { + return None + } + + let data = if let Some(renderer) = self.ipc_renderer() { + let (sender, receiver) = ipc::channel().unwrap(); + let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); + renderer.send(msg).unwrap(); + + receiver.recv().unwrap().to_vec() + } else { + repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() + }; + + Some((data, size)) + } +} + +impl HTMLCanvasElementMethods for HTMLCanvasElement { + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn Width(&self) -> u32 { + self.width.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-width + fn SetWidth(&self, width: u32) { + self.upcast::().set_uint_attribute(&atom!("width"), width) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn Height(&self) -> u32 { + self.height.get() + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-height + fn SetHeight(&self, height: u32) { + self.upcast::().set_uint_attribute(&atom!("height"), height) + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext + fn GetContext(&self, + cx: *mut JSContext, + id: DOMString, + attributes: Vec) + -> Option { + match &*id { + "2d" => { + self.get_or_init_2d_context() + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) + } + "webgl" | "experimental-webgl" => { + self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) + .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) + } + _ => None + } + } + + // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl + fn ToDataURL(&self, + _context: *mut JSContext, + _mime_type: Option, + _arguments: Vec) -> Fallible { + + // Step 1: Check the origin-clean flag (should be set in fillText/strokeText + // and currently unimplemented) + + // Step 2. + if self.Width() == 0 || self.Height() == 0 { + return Ok("data:,".to_owned()); + } + + // Step 3. + if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { + let window = window_from_node(self); + let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), + Finite::wrap(self.Width() as f64), + Finite::wrap(self.Height() as f64))); + let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); + + // Only handle image/png for now. + let mime_type = "image/png"; + + let mut encoded = Vec::new(); + { + let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); + encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); + } + + let encoded = encoded.to_base64(STANDARD); + Ok(format!("data:{};base64,{}", mime_type, encoded)) + } else { + Err(Error::NotSupported) + } + } +} + +impl VirtualMethods for HTMLCanvasElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::() as &VirtualMethods) + } + + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); + let recreate = match attr.local_name() { + &atom!(width) => { + let width = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.width.set(width.unwrap_or(DEFAULT_WIDTH)); + true + }, + &atom!(height) => { + let height = mutation.new_value(attr).and_then(|value| { + parse_unsigned_integer(value.chars()) + }); + self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); + true + }, + _ => false, + }; + if recreate { + self.recreate_contexts(); + } + } +} + +impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { + fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { + GLContextAttributes { + alpha: attrs.alpha, + depth: attrs.depth, + stencil: attrs.stencil, + antialias: attrs.antialias, + premultiplied_alpha: attrs.premultipliedAlpha, + preserve_drawing_buffer: attrs.preserveDrawingBuffer, + } + } +} + +pub mod utils { + use dom::window::Window; + use ipc_channel::ipc; + use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; + use url::Url; + + pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { + let image_cache = window.image_cache_task(); + let (response_chan, response_port) = ipc::channel().unwrap(); + image_cache.request_image(url, ImageCacheChan(response_chan), None); + let result = response_port.recv().unwrap(); + result.image_response + } +} diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 4cc54c43e73..27c2a88093d 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -8,7 +8,8 @@ use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::{Reflector, namespace_from_domstring, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::xmlname::namespace_from_domstring; use dom::element::Element; use dom::node::{Node, TreeIterator}; use dom::window::Window; diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 115b4d88439..16f46bc68c1 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -13,7 +13,7 @@ use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, Nod use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration}; use dom::document::Document; use dom::domstringmap::DOMStringMap; diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 58e82932df0..b73385bf705 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -10,11 +10,11 @@ use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::conversions::{DerivedFrom}; +use dom::bindings::conversions::DerivedFrom; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::document::Document; use dom::element::Element; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 6e4a32e603e..95fb9bbf2f3 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -11,7 +11,7 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, LayoutJS}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::customevent::CustomEvent; use dom::document::Document; use dom::element::{self, AttributeMutation, Element}; diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs index 7f2b561e85f..ffbe0a4b225 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::ImageDataBinding; use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use euclid::size::Size2D; use js::jsapi::{Heap, JSContext, JSObject}; use js::jsapi::{JS_GetUint8ClampedArrayData, JS_NewUint8ClampedArray}; diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index db94b451318..d09701b9dda 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -9,7 +9,8 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{Root, RootedReference}; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; use dom::event::Event; use dom::uievent::UIEvent; use dom::window::Window; diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index a9e788a7b04..1bab27b9c48 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::str::USVString; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::urlhelper::UrlHelper; use dom::window::Window; use url::{Url, UrlParser}; diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index b767c738f8a..8904cdce139 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::Event; use dom::eventtarget::EventTarget; use js::jsapi::{RootedValue, HandleValue, Heap, JSContext}; diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index 904b9fddb80..b027f8af8d2 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; use dom::uievent::UIEvent; diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index 6070c0bb0c2..e3115223931 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -8,7 +8,8 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, namespace_from_domstring, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::xmlname::namespace_from_domstring; use dom::element::Element; use dom::window::Window; use string_cache::Atom; diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 4f3f3d2c2da..5fa0465d361 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::NavigatorBinding; use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::navigatorinfo; use dom::window::Window; use util::str::DOMString; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 43f7d0e9449..72168536912 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -31,7 +31,8 @@ use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::RootedVec; -use dom::bindings::utils::{Reflectable, namespace_from_domstring, reflect_dom_object}; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; +use dom::bindings::xmlname::namespace_from_domstring; use dom::characterdata::CharacterData; use dom::comment::Comment; use dom::document::{Document, DocumentSource, IsHTMLDocument}; diff --git a/components/script/dom/nodeiterator.rs b/components/script/dom/nodeiterator.rs index 27a99ec3b55..379ce5a3743 100644 --- a/components/script/dom/nodeiterator.rs +++ b/components/script/dom/nodeiterator.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::NodeIteratorBinding::NodeIteratorMethods; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::document::Document; use dom::node::Node; use std::cell::Cell; diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index 490df73bd56..cf5da3b0a3f 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::NodeListBinding; use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::node::{ChildrenMutation, Node}; use dom::window::Window; use std::cell::Cell; diff --git a/components/script/dom/performance.rs b/components/script/dom/performance.rs index b8b6c17ef09..ffcdc7a170e 100644 --- a/components/script/dom/performance.rs +++ b/components/script/dom/performance.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::performancetiming::PerformanceTiming; use dom::window::Window; use time; diff --git a/components/script/dom/performancetiming.rs b/components/script/dom/performancetiming.rs index 9992f87f3c8..1799d6a7f91 100644 --- a/components/script/dom/performancetiming.rs +++ b/components/script/dom/performancetiming.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::PerformanceTimingBinding; use dom::bindings::codegen::Bindings::PerformanceTimingBinding::PerformanceTimingMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::window::Window; #[dom_struct] diff --git a/components/script/dom/progressevent.rs b/components/script/dom/progressevent.rs index 1d03015ffad..4fefde82c47 100644 --- a/components/script/dom/progressevent.rs +++ b/components/script/dom/progressevent.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use util::str::DOMString; diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 86f8ae8a8bd..3a6c823eb2b 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -15,7 +15,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root, RootedReference}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::characterdata::CharacterData; use dom::document::Document; use dom::documentfragment::DocumentFragment; diff --git a/components/script/dom/screen.rs b/components/script/dom/screen.rs index e38dc676afe..158615e84dc 100644 --- a/components/script/dom/screen.rs +++ b/components/script/dom/screen.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::ScreenBinding; use dom::bindings::codegen::Bindings::ScreenBinding::ScreenMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::window::Window; #[dom_struct] diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index 3a4a59ba3af..c7e4cd45b35 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -12,7 +12,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::document::Document; use dom::node::Node; use dom::text::Text; diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 9a21c98e607..17003692e15 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -9,7 +9,7 @@ use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::{Root, RootedReference}; use dom::bindings::refcounted::Trusted; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::storageevent::StorageEvent; use dom::urlhelper::UrlHelper; diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs index 92a0fb197b5..55f2d04d6cc 100644 --- a/components/script/dom/storageevent.rs +++ b/components/script/dom/storageevent.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; -use dom::bindings::utils::{reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::storage::Storage; use util::str::DOMString; diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 7c2038eab3b..9e2da895852 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -18,7 +18,7 @@ use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::Root; use dom::bindings::num::Finite; use dom::bindings::str::{ByteString, USVString}; -use dom::bindings::utils::Reflector; +use dom::bindings::reflector::Reflector; use dom::blob::Blob; use js::jsapi::{HandleValue, JSContext, JSObject}; use js::jsval::{JSVal, NullValue}; diff --git a/components/script/dom/testbindingproxy.rs b/components/script/dom/testbindingproxy.rs index 079e7656f68..0c323a3f4c3 100644 --- a/components/script/dom/testbindingproxy.rs +++ b/components/script/dom/testbindingproxy.rs @@ -5,7 +5,7 @@ // check-tidy: no specs after this line use dom::bindings::codegen::Bindings::TestBindingProxyBinding::TestBindingProxyMethods; -use dom::bindings::utils::Reflector; +use dom::bindings::reflector::Reflector; use util::str::DOMString; diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs index c09fcd25614..ad2f28c9ff5 100644 --- a/components/script/dom/textdecoder.rs +++ b/components/script/dom/textdecoder.rs @@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::str::USVString; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use encoding::Encoding; use encoding::label::encoding_from_whatwg_label; use encoding::types::{DecoderTrap, EncodingRef}; diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs index 913b7c4fe86..1025df5d3d3 100644 --- a/components/script/dom/textencoder.rs +++ b/components/script/dom/textencoder.rs @@ -8,7 +8,7 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::str::USVString; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use encoding::label::encoding_from_whatwg_label; use encoding::types::EncodingRef; use encoding::{EncoderTrap, Encoding}; diff --git a/components/script/dom/touch.rs b/components/script/dom/touch.rs index 9e25dacf422..29bfac34152 100644 --- a/components/script/dom/touch.rs +++ b/components/script/dom/touch.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::TouchBinding::TouchMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::eventtarget::EventTarget; use dom::window::Window; diff --git a/components/script/dom/touchevent.rs b/components/script/dom/touchevent.rs index e87f47c4747..d84d4788eda 100644 --- a/components/script/dom/touchevent.rs +++ b/components/script/dom/touchevent.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{EventBubbles, EventCancelable}; use dom::touchlist::TouchList; use dom::uievent::UIEvent; diff --git a/components/script/dom/touchlist.rs b/components/script/dom/touchlist.rs index 5806f945008..ed40a5ee2ed 100644 --- a/components/script/dom/touchlist.rs +++ b/components/script/dom/touchlist.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::TouchListBinding; use dom::bindings::codegen::Bindings::TouchListBinding::TouchListMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::touch::Touch; use dom::window::Window; diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index f19e8383ddf..35a7291122d 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -12,7 +12,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutHeap}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::document::Document; use dom::node::Node; use std::rc::Rc; diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 41eb6097005..079dbb3a814 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -10,7 +10,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableHeap, RootedReference}; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::window::Window; use std::cell::Cell; diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs index 9ff22b53597..95fc38122f1 100644 --- a/components/script/dom/url.rs +++ b/components/script/dom/url.rs @@ -7,7 +7,7 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::str::USVString; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::urlhelper::UrlHelper; use std::borrow::ToOwned; use std::cell::RefCell; diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index 6ddfe4f5278..88a576814ac 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLS use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use encoding::types::EncodingRef; use url::form_urlencoded::{parse, serialize_with_encoding}; use util::str::DOMString; diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs index 547e7363b82..ae48a1624b0 100644 --- a/components/script/dom/validitystate.rs +++ b/components/script/dom/validitystate.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::ValidityStateBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::window::Window; // https://html.spec.whatwg.org/multipage/#validitystate diff --git a/components/script/dom/webglactiveinfo.rs b/components/script/dom/webglactiveinfo.rs index efac59725b5..3b069407f36 100644 --- a/components/script/dom/webglactiveinfo.rs +++ b/components/script/dom/webglactiveinfo.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::WebGLActiveInfoBinding; use dom::bindings::codegen::Bindings::WebGLActiveInfoBinding::WebGLActiveInfoMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use util::str::DOMString; #[dom_struct] diff --git a/components/script/dom/webglbuffer.rs b/components/script/dom/webglbuffer.rs index 05f8d7263bb..e577c06aa19 100644 --- a/components/script/dom/webglbuffer.rs +++ b/components/script/dom/webglbuffer.rs @@ -7,7 +7,7 @@ use canvas_traits::{CanvasMsg, CanvasWebGLMsg, WebGLError, WebGLResult}; use dom::bindings::codegen::Bindings::WebGLBufferBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; diff --git a/components/script/dom/webglcontextevent.rs b/components/script/dom/webglcontextevent.rs index 8f4eda6a535..905deaaddf2 100644 --- a/components/script/dom/webglcontextevent.rs +++ b/components/script/dom/webglcontextevent.rs @@ -10,7 +10,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; use util::str::DOMString; diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs index a3a9781fbfb..60f550d63c7 100644 --- a/components/script/dom/webglframebuffer.rs +++ b/components/script/dom/webglframebuffer.rs @@ -7,7 +7,7 @@ use canvas_traits::{CanvasMsg, CanvasWebGLMsg, WebGLFramebufferBindingRequest}; use dom::bindings::codegen::Bindings::WebGLFramebufferBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; diff --git a/components/script/dom/webglobject.rs b/components/script/dom/webglobject.rs index c950768e329..c6bc733de62 100644 --- a/components/script/dom/webglobject.rs +++ b/components/script/dom/webglobject.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::WebGLObjectBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; #[dom_struct] pub struct WebGLObject { diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs index 997f48c96b4..88052215254 100644 --- a/components/script/dom/webglprogram.rs +++ b/components/script/dom/webglprogram.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::WebGLProgramBinding; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use dom::webglrenderingcontext::MAX_UNIFORM_AND_ATTRIBUTE_LEN; use dom::webglshader::WebGLShader; diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs index b01bcce896a..9bca4b5972c 100644 --- a/components/script/dom/webglrenderbuffer.rs +++ b/components/script/dom/webglrenderbuffer.rs @@ -7,7 +7,7 @@ use canvas_traits::{CanvasMsg, CanvasWebGLMsg}; use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 03762f887d5..3e9cc0b60b7 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -9,11 +9,11 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; -use dom::bindings::conversions::{ToJSValConvertible}; +use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlcanvaselement::utils as canvas_utils; diff --git a/components/script/dom/webglshader.rs b/components/script/dom/webglshader.rs index e33b27d3839..e272706a95e 100644 --- a/components/script/dom/webglshader.rs +++ b/components/script/dom/webglshader.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLShaderBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::{Cell, RefCell}; diff --git a/components/script/dom/webglshaderprecisionformat.rs b/components/script/dom/webglshaderprecisionformat.rs index e3b8f473bc5..6cd78b8d51a 100644 --- a/components/script/dom/webglshaderprecisionformat.rs +++ b/components/script/dom/webglshaderprecisionformat.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::WebGLShaderPrecisionFormatBinding; use dom::bindings::codegen::Bindings::WebGLShaderPrecisionFormatBinding::WebGLShaderPrecisionFormatMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; #[dom_struct] pub struct WebGLShaderPrecisionFormat { diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index fb8ee4033fd..f6a7acc786b 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi use dom::bindings::codegen::Bindings::WebGLTextureBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; diff --git a/components/script/dom/webgluniformlocation.rs b/components/script/dom/webgluniformlocation.rs index ea30afc8b51..7367f9f1d7d 100644 --- a/components/script/dom/webgluniformlocation.rs +++ b/components/script/dom/webgluniformlocation.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::WebGLUniformLocationBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; #[dom_struct] pub struct WebGLUniformLocation { diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 595ee147cdf..46471b0761c 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -14,7 +14,8 @@ use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; use dom::bindings::str::USVString; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; use dom::blob::Blob; use dom::closeevent::CloseEvent; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index f922a7a5ae3..44c138bb1e5 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -18,7 +18,8 @@ use dom::bindings::global::global_object_for_js_object; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::num::Finite; -use dom::bindings::utils::{GlobalStaticData, Reflectable, WindowProxyHandler}; +use dom::bindings::reflector::Reflectable; +use dom::bindings::utils::{GlobalStaticData, WindowProxyHandler}; use dom::browsercontext::BrowsingContext; use dom::console::Console; use dom::crypto::Crypto; diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 7745319c19d..a16452b5b4f 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -13,7 +13,8 @@ use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::trace::JSTraceable; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, WorkerScriptMsg}; use dom::errorevent::ErrorEvent; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 693b4116756..fb263bbea27 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -9,7 +9,7 @@ use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::console::Console; use dom::crypto::Crypto; use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope; diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs index 477c329cf75..23f9e18f4b0 100644 --- a/components/script/dom/workerlocation.rs +++ b/components/script/dom/workerlocation.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMetho use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::str::USVString; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::urlhelper::UrlHelper; use dom::workerglobalscope::WorkerGlobalScope; use url::Url; diff --git a/components/script/dom/workernavigator.rs b/components/script/dom/workernavigator.rs index 6bef4bdb048..146c098d7d1 100644 --- a/components/script/dom/workernavigator.rs +++ b/components/script/dom/workernavigator.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::WorkerNavigatorBinding; use dom::bindings::codegen::Bindings::WorkerNavigatorBinding::WorkerNavigatorMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::{Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::navigatorinfo; use dom::workerglobalscope::WorkerGlobalScope; use util::str::DOMString; diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 5afd4cb7777..8e0b3c30d0a 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -20,7 +20,8 @@ use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::refcounted::Trusted; use dom::bindings::str::ByteString; -use dom::bindings::utils::{Reflectable, reflect_dom_object}; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::reflector::Reflectable; use dom::document::Document; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; diff --git a/components/script/dom/xmlhttprequestupload.rs b/components/script/dom/xmlhttprequestupload.rs index e426c63c30c..900548f2e05 100644 --- a/components/script/dom/xmlhttprequestupload.rs +++ b/components/script/dom/xmlhttprequestupload.rs @@ -5,7 +5,7 @@ use dom::bindings::codegen::Bindings::XMLHttpRequestUploadBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::utils::reflect_dom_object; +use dom::bindings::reflector::reflect_dom_object; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; #[dom_struct] diff --git a/components/script/mem.rs b/components/script/mem.rs index aae70c5ef45..113f03b8396 100644 --- a/components/script/mem.rs +++ b/components/script/mem.rs @@ -5,7 +5,7 @@ //! Routines for handling measuring the memory usage of arbitrary DOM nodes. use dom::bindings::conversions::get_dom_class; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use libc::c_void; use util::mem::{HeapSizeOf, heap_size_of}; diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 4943fecdb5f..bd2b425fe7c 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::js::{RootedReference}; use dom::characterdata::CharacterData; diff --git a/components/script/timers.rs b/components/script/timers.rs index 6c982cb1ad4..75d7271154d 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -6,7 +6,7 @@ use dom::bindings::callback::ExceptionHandling::Report; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::global::global_object_for_js_object; -use dom::bindings::utils::Reflectable; +use dom::bindings::reflector::Reflectable; use dom::window::ScriptHelpers; use euclid::length::Length; use js::jsapi::{HandleValue, Heap, RootedValue}; From 34b71e55f51c978911041f88e64ec56512ca7c1f Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Wed, 28 Oct 2015 14:50:04 +0900 Subject: [PATCH 3/8] remove unneeded import + reexport InheritTypes from inheritance --- components/script/dom/bindings/inheritance.rs | 2 ++ components/script/dom/htmlcanvaselement.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs index 6ee06999563..920ecb07397 100644 --- a/components/script/dom/bindings/inheritance.rs +++ b/components/script/dom/bindings/inheritance.rs @@ -4,6 +4,8 @@ //! The `Castable` trait. +pub use dom::bindings::codegen::InheritTypes::*; + use dom::bindings::conversions::get_dom_class; use dom::bindings::conversions::{DerivedFrom, IDLInterface}; use dom::bindings::reflector::Reflectable; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index f7bbb1753af..57e56817c82 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -13,7 +13,6 @@ use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRendering use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; use dom::bindings::reflector::Reflectable; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; use dom::document::Document; From 9fd823e44983fc0de5abc28ee898df6257f0f5d0 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Thu, 29 Oct 2015 18:09:41 +0900 Subject: [PATCH 4/8] replace InheritTypes imports with inheritance imports --- components/layout/construct.rs | 4 ++-- components/layout/css/matching.rs | 2 +- components/layout/wrapper.rs | 4 ++-- components/script/dom/bindings/utils.rs | 2 +- components/script/dom/document.rs | 2 +- components/script/dom/element.rs | 2 +- components/script/dom/eventtarget.rs | 2 +- components/script/dom/htmlelement.rs | 2 +- components/script/dom/htmlfieldsetelement.rs | 2 +- components/script/dom/htmlformelement.rs | 2 +- components/script/dom/mod.rs | 6 +++--- components/script/dom/node.rs | 4 ++-- components/script/dom/range.rs | 2 +- components/script/dom/virtualmethods.rs | 6 +++--- components/script/parse/html.rs | 2 +- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index e8f9b8df81c..32f540e1d36 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -33,8 +33,8 @@ use inline::{InlineFragmentNodeInfo, LAST_FRAGMENT_OF_ELEMENT}; use list_item::{ListItemFlow, ListStyleTypeContent}; use multicol::MulticolFlow; use parallel; -use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId}; -use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId}; +use script::dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId}; +use script::dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; use script::dom::htmlobjectelement::is_image_data; use std::borrow::ToOwned; use std::collections::LinkedList; diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 76a25671546..5773fc6630a 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -10,7 +10,7 @@ use animation; use context::SharedLayoutContext; use data::LayoutDataWrapper; use incremental::{self, RestyleDamage}; -use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; +use script::dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; use script::layout_interface::Animation; use selectors::bloom::BloomFilter; use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes}; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4deb9c1aba6..5d20f36d264 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -37,8 +37,8 @@ use incremental::RestyleDamage; use msg::constellation_msg::PipelineId; use opaque_node::OpaqueNodeMethods; use script::dom::attr::AttrValue; -use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId}; -use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId}; +use script::dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId}; +use script::dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; use script::dom::bindings::inheritance::Castable; use script::dom::bindings::js::LayoutJS; use script::dom::characterdata::LayoutCharacterDataHelpers; diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 72c0745d3b1..ca3be0bc00a 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -4,7 +4,7 @@ //! Various utilities to glue JavaScript and the DOM implementation together. -use dom::bindings::codegen::InheritTypes::TopTypeId; +use dom::bindings::inheritance::TopTypeId; use dom::bindings::codegen::PrototypeList; use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH; use dom::bindings::conversions::native_from_handleobject; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index ad9e51a9c08..a41646ab629 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -14,7 +14,7 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 8cdb4910d0d..4289186f9d4 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -19,7 +19,7 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 31f603ee105..2addcbd3261 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -7,7 +7,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; -use dom::bindings::codegen::InheritTypes::EventTargetTypeId; +use dom::bindings::inheritance::EventTargetTypeId; use dom::bindings::error::{Error, Fallible, report_pending_exception}; use dom::bindings::reflector::Reflector; use dom::bindings::reflector::Reflectable; diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 16f46bc68c1..5d63bed6cd2 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::HTMLElementBinding; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::js::{JS, MutNullableHeap, Root}; diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 617dbb8e4c8..ac5d1833315 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -5,7 +5,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index b73385bf705..cd5a7fae8ee 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElemen use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::conversions::DerivedFrom; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 1bb0eabac6e..bacc88834f9 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -81,7 +81,7 @@ //! on the `Node` interface to avoid unnecessary upcasts to `EventTarget`. //! //! ```ignore -//! use dom::bindings::codegen::InheritTypes::{EventTargetTypeId, NodeTypeId}; +//! use dom::bindings::inheritance::{EventTargetTypeId, NodeTypeId}; //! //! match *node.type_id() { //! EventTargetTypeId::Node(NodeTypeId::CharacterData(_)) => ..., @@ -160,11 +160,11 @@ //! ======================= //! //! For all DOM interfaces `Foo` in an inheritance chain, a -//! `dom::bindings::codegen::InheritTypes::FooCast` provides methods to cast +//! `dom::bindings::inheritance::FooCast` provides methods to cast //! to other types in the inheritance chain. For example: //! //! ```ignore -//! # use script::dom::bindings::codegen::InheritTypes::{NodeCast, HTMLElementCast}; +//! # use script::dom::bindings::inheritance::{NodeCast, HTMLElementCast}; //! # use script::dom::element::Element; //! # use script::dom::node::Node; //! # use script::dom::htmlelement::HTMLElement; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 72168536912..167ab3044cb 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -19,8 +19,8 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods}; use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods; -use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId}; -use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId}; +use dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId}; +use dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::conversions::{self, DerivedFrom}; use dom::bindings::error::{Error, ErrorResult, Fallible}; diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 3a6c823eb2b..b5443cccffc 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::RangeBinding::RangeMethods; use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants}; use dom::bindings::codegen::Bindings::TextBinding::TextMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; +use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 1e1ee2f03d1..d7ccd181e9d 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -3,9 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::{Attr, AttrValue}; -use dom::bindings::codegen::InheritTypes::ElementTypeId; -use dom::bindings::codegen::InheritTypes::HTMLElementTypeId; -use dom::bindings::codegen::InheritTypes::NodeTypeId; +use dom::bindings::inheritance::ElementTypeId; +use dom::bindings::inheritance::HTMLElementTypeId; +use dom::bindings::inheritance::NodeTypeId; use dom::bindings::inheritance::Castable; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index bd2b425fe7c..915aa7bb729 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -8,7 +8,7 @@ use document_loader::DocumentLoader; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; +use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::js::{RootedReference}; From 51df8e310be5157263981e0dd368d10ebc693d49 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Fri, 30 Oct 2015 20:16:27 +0900 Subject: [PATCH 5/8] rearrange imports to be in alphabetical order --- components/layout/wrapper.rs | 3 +-- components/script/dom/bindings/conversions.rs | 2 +- components/script/dom/bindings/global.rs | 3 +-- components/script/dom/bindings/js.rs | 3 +-- components/script/dom/bindings/refcounted.rs | 3 +-- components/script/dom/bindings/reflector.rs | 2 +- components/script/dom/bindings/utils.rs | 2 +- components/script/dom/browsercontext.rs | 2 +- components/script/dom/characterdata.rs | 2 +- components/script/dom/customevent.rs | 2 +- components/script/dom/dedicatedworkerglobalscope.rs | 2 +- components/script/dom/document.rs | 8 +++----- components/script/dom/element.rs | 5 ++--- components/script/dom/errorevent.rs | 4 ++-- components/script/dom/eventdispatcher.rs | 2 +- components/script/dom/eventtarget.rs | 5 ++--- components/script/dom/filereader.rs | 5 ++--- components/script/dom/formdata.rs | 2 +- components/script/dom/htmlcanvaselement.rs | 2 +- components/script/dom/htmlcollection.rs | 4 ++-- components/script/dom/htmlelement.rs | 4 ++-- components/script/dom/htmlfieldsetelement.rs | 3 +-- components/script/dom/htmlformelement.rs | 3 +-- components/script/dom/htmlimageelement.rs | 2 +- components/script/dom/htmlinputelement.rs | 2 +- components/script/dom/htmllinkelement.rs | 2 +- components/script/dom/htmlscriptelement.rs | 2 +- components/script/dom/htmltablerowelement.rs | 2 +- components/script/dom/htmltablesectionelement.rs | 2 +- components/script/dom/htmltextareaelement.rs | 2 +- components/script/dom/keyboardevent.rs | 5 ++--- components/script/dom/location.rs | 2 +- components/script/dom/messageevent.rs | 2 +- components/script/dom/mouseevent.rs | 2 +- components/script/dom/node.rs | 7 +++---- components/script/dom/progressevent.rs | 2 +- components/script/dom/range.rs | 4 ++-- components/script/dom/servohtmlparser.rs | 2 +- components/script/dom/storage.rs | 2 +- components/script/dom/storageevent.rs | 2 +- components/script/dom/testbinding.rs | 2 +- components/script/dom/text.rs | 2 +- components/script/dom/textdecoder.rs | 2 +- components/script/dom/textencoder.rs | 2 +- components/script/dom/touchevent.rs | 2 +- components/script/dom/uievent.rs | 2 +- components/script/dom/url.rs | 2 +- components/script/dom/virtualmethods.rs | 2 +- components/script/dom/webglcontextevent.rs | 2 +- components/script/dom/websocket.rs | 3 +-- components/script/dom/window.rs | 2 +- components/script/dom/worker.rs | 5 ++--- components/script/dom/workerglobalscope.rs | 2 +- components/script/dom/workerlocation.rs | 2 +- components/script/dom/xmlhttprequest.rs | 3 +-- components/script/parse/html.rs | 3 +-- 56 files changed, 69 insertions(+), 86 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 5d20f36d264..a7493f6e0c3 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -37,9 +37,8 @@ use incremental::RestyleDamage; use msg::constellation_msg::PipelineId; use opaque_node::OpaqueNodeMethods; use script::dom::attr::AttrValue; -use script::dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId}; +use script::dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTypeId}; use script::dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; -use script::dom::bindings::inheritance::Castable; use script::dom::bindings::js::LayoutJS; use script::dom::characterdata::LayoutCharacterDataHelpers; use script::dom::document::{Document, LayoutDocumentHelpers}; diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 1da266efe4c..591b468c515 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -37,8 +37,8 @@ use dom::bindings::error::throw_type_error; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::num::Finite; -use dom::bindings::str::{ByteString, USVString}; use dom::bindings::reflector::{Reflectable, Reflector}; +use dom::bindings::str::{ByteString, USVString}; use dom::bindings::utils::DOMClass; use js; use js::glue::{GetProxyPrivate, IsWrapper, RUST_JS_NumberValue}; diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index d0b38196608..1f358048831 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -11,8 +11,7 @@ use devtools_traits::ScriptToDevtoolsControlMsg; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::conversions::native_from_reflector_jsmanaged; use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::Reflector; -use dom::bindings::reflector::Reflectable; +use dom::bindings::reflector::{Reflectable, Reflector}; use dom::window::{self, ScriptHelpers}; use dom::workerglobalscope::WorkerGlobalScope; use ipc_channel::ipc::IpcSender; diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index d347b00bb4f..09f1392b762 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -26,10 +26,9 @@ use core::nonzero::NonZero; use dom::bindings::conversions::DerivedFrom; use dom::bindings::inheritance::Castable; +use dom::bindings::reflector::{Reflectable, Reflector}; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::trace_reflector; -use dom::bindings::reflector::Reflector; -use dom::bindings::reflector::Reflectable; use dom::node::Node; use js::jsapi::{Heap, JSObject, JSTracer}; use js::jsval::JSVal; diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index e101d2bbd83..88d853405a0 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -24,9 +24,8 @@ use core::nonzero::NonZero; use dom::bindings::js::Root; +use dom::bindings::reflector::{Reflectable, Reflector}; use dom::bindings::trace::trace_reflector; -use dom::bindings::reflector::Reflector; -use dom::bindings::reflector::Reflectable; use js::jsapi::{JSContext, JSTracer}; use libc; use script_task::{CommonScriptMsg, ScriptChan}; diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index 3279f4de55e..e0a090a8d88 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -76,4 +76,4 @@ pub trait Reflectable { fn reflector(&self) -> &Reflector; /// Initializes the Reflector fn init_reflector(&mut self, obj: *mut JSObject); -} \ No newline at end of file +} diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index ca3be0bc00a..98836d7fe7d 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -4,7 +4,6 @@ //! Various utilities to glue JavaScript and the DOM implementation together. -use dom::bindings::inheritance::TopTypeId; use dom::bindings::codegen::PrototypeList; use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH; use dom::bindings::conversions::native_from_handleobject; @@ -13,6 +12,7 @@ use dom::bindings::conversions::{is_dom_class, jsstring_to_str, DOM_OBJECT_SLOT} use dom::bindings::error::throw_type_error; use dom::bindings::error::{Error, ErrorResult, Fallible, throw_invalid_this}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::TopTypeId; use dom::bindings::js::Root; use dom::bindings::trace::trace_object; use dom::browsercontext; diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs index a20b576cc1b..2c5a5504045 100644 --- a/components/script/dom/browsercontext.rs +++ b/components/script/dom/browsercontext.rs @@ -6,9 +6,9 @@ use dom::bindings::conversions::native_from_handleobject; use dom::bindings::conversions::{ToJSValConvertible}; use dom::bindings::js::{JS, Root}; use dom::bindings::proxyhandler::{fill_property_descriptor, get_property_descriptor}; -use dom::bindings::utils::get_array_index_from_id; use dom::bindings::reflector::Reflectable; use dom::bindings::utils::WindowProxyHandler; +use dom::bindings::utils::get_array_index_from_id; use dom::document::Document; use dom::element::Element; use dom::window::Window; diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index f1fb7269680..8d8fc2e20fa 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -7,8 +7,8 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{LayoutJS, Root}; use dom::document::Document; use dom::element::Element; diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs index 6f7b04cc8e4..d23075565b8 100644 --- a/components/script/dom/customevent.rs +++ b/components/script/dom/customevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::CustomEventBinding; use dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{MutHeapJSVal, Root}; use dom::bindings::reflector::reflect_dom_object; use dom::event::Event; diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 5216ff13664..598654e7ab9 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -13,8 +13,8 @@ use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootCollection}; use dom::bindings::refcounted::LiveDOMReferences; -use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::reflector::Reflectable; +use dom::bindings::structuredclone::StructuredCloneData; use dom::messageevent::MessageEvent; use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler}; use dom::workerglobalscope::WorkerGlobalScope; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a41646ab629..cd6ff08b262 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -14,20 +14,18 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; -use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::num::Finite; use dom::bindings::refcounted::Trusted; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::trace::RootedVec; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; -use dom::bindings::xmlname::{validate_and_extract, xml_name_type}; use dom::bindings::xmlname::XMLName::InvalidXMLName; +use dom::bindings::xmlname::{validate_and_extract, xml_name_type}; use dom::comment::Comment; use dom::customevent::CustomEvent; use dom::documentfragment::DocumentFragment; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 4289186f9d4..67844b9231b 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -19,15 +19,14 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; use dom::bindings::js::{Root, RootedReference}; -use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type}; use dom::bindings::xmlname::XMLName::InvalidXMLName; +use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type}; use dom::characterdata::CharacterData; use dom::create::create_element; use dom::document::{Document, LayoutDocumentHelpers}; diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index edc422e0dd7..21e70ab8436 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -6,12 +6,12 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::ErrorEventBinding; use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{MutHeapJSVal, Root}; -use dom::bindings::trace::JSTraceable; use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::trace::JSTraceable; use dom::event::{Event, EventBubbles, EventCancelable}; use js::jsapi::{RootedValue, HandleValue, JSContext}; use js::jsval::JSVal; diff --git a/components/script/dom/eventdispatcher.rs b/components/script/dom/eventdispatcher.rs index 14d657a9d4f..9faf31c6be6 100644 --- a/components/script/dom/eventdispatcher.rs +++ b/components/script/dom/eventdispatcher.rs @@ -5,8 +5,8 @@ use devtools_traits::{StartedTimelineMarker, TimelineMarker, TimelineMarkerType}; use dom::bindings::callback::ExceptionHandling::Report; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::{GlobalRoot, global_object_for_reflector}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::trace::RootedVec; use dom::event::{Event, EventPhase}; diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 2addcbd3261..161e2315b3b 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -7,10 +7,9 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; -use dom::bindings::inheritance::EventTargetTypeId; use dom::bindings::error::{Error, Fallible, report_pending_exception}; -use dom::bindings::reflector::Reflector; -use dom::bindings::reflector::Reflectable; +use dom::bindings::inheritance::EventTargetTypeId; +use dom::bindings::reflector::{Reflectable, Reflector}; use dom::event::Event; use dom::eventdispatcher::dispatch_event; use dom::virtualmethods::VirtualMethods; diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index ad519c0efc8..8003208e5b2 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -5,13 +5,12 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::refcounted::Trusted; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::blob::Blob; use dom::domexception::{DOMErrorName, DOMException}; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 8c02f132a88..27ba8ff4f0a 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -7,9 +7,9 @@ use dom::bindings::codegen::Bindings::FormDataBinding; use dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods; use dom::bindings::codegen::UnionTypes::FileOrString; use dom::bindings::codegen::UnionTypes::FileOrString::{eFile, eString}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::blob::Blob; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 57e56817c82..ab72e57444a 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -10,8 +10,8 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; use dom::bindings::reflector::Reflectable; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 27c2a88093d..b0949ea64e7 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -4,11 +4,11 @@ use dom::bindings::codegen::Bindings::HTMLCollectionBinding; use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; -use dom::bindings::trace::JSTraceable; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::trace::JSTraceable; use dom::bindings::xmlname::namespace_from_domstring; use dom::element::Element; use dom::node::{Node, TreeIterator}; diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 5d63bed6cd2..8836d3aae69 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -9,9 +9,9 @@ use dom::bindings::codegen::Bindings::HTMLElementBinding; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; +use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::reflector::Reflectable; use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration}; diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index ac5d1833315..d516a647055 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -5,8 +5,7 @@ use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods; -use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE}; diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index cd5a7fae8ee..6c9faa687bb 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -9,10 +9,9 @@ use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElemen use dom::bindings::codegen::Bindings::HTMLFormElementBinding; use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; -use dom::bindings::inheritance::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::conversions::DerivedFrom; use dom::bindings::global::GlobalRef; -use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::{Root}; use dom::bindings::reflector::Reflectable; use dom::document::Document; diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index b8148b43703..871e6335928 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -8,9 +8,9 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::HTMLImageElementBinding; use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{LayoutJS, Root}; use dom::bindings::refcounted::Trusted; use dom::document::Document; diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 686ca1b2f6a..0c262530f3f 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -11,8 +11,8 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, LayoutJS, Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE, RawLayoutElementHelpers}; diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index b0e464b4db0..37b442e6cea 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -8,8 +8,8 @@ use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{RootedReference}; use dom::bindings::refcounted::Trusted; diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 279f5d59536..eed34d14bfd 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -10,8 +10,8 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index 943c9055550..726ad915982 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -6,8 +6,8 @@ use cssparser::RGBA; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods}; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{ErrorResult, Fallible}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 2121089d4dc..50b9f1fc3d0 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -6,8 +6,8 @@ use cssparser::RGBA; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::{self, HTMLTableSectionElementMethods}; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{ErrorResult, Fallible}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; use dom::element::{AttributeMutation, Element}; diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 855fe59cf3b..37617ccc0a6 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -8,8 +8,8 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{LayoutJS, Root}; use dom::bindings::refcounted::Trusted; use dom::document::Document; diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index d09701b9dda..6fbbf1d97db 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -5,12 +5,11 @@ use dom::bindings::codegen::Bindings::KeyboardEventBinding; use dom::bindings::codegen::Bindings::KeyboardEventBinding::{KeyboardEventConstants, KeyboardEventMethods}; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::event::Event; use dom::uievent::UIEvent; use dom::window::Window; diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 1bab27b9c48..fa3cba5cf5c 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -6,8 +6,8 @@ use dom::bindings::codegen::Bindings::LocationBinding; use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; -use dom::bindings::str::USVString; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::str::USVString; use dom::urlhelper::UrlHelper; use dom::window::Window; use url::{Url, UrlParser}; diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index 8904cdce139..2509031abdc 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::MessageEventBinding; use dom::bindings::codegen::Bindings::MessageEventBinding::MessageEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::event::Event; diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index b027f8af8d2..adb0024b889 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::MouseEventBinding; use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 167ab3044cb..f12fe53f1c4 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -19,19 +19,18 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods}; use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods; -use dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId}; -use dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::conversions::{self, DerivedFrom}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; -use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTypeId}; +use dom::bindings::inheritance::{EventTargetTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::js::Root; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::RootedVec; -use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::xmlname::namespace_from_domstring; use dom::characterdata::CharacterData; use dom::comment::Comment; diff --git a/components/script/dom/progressevent.rs b/components/script/dom/progressevent.rs index 4fefde82c47..9c31291a6b2 100644 --- a/components/script/dom/progressevent.rs +++ b/components/script/dom/progressevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::ProgressEventBinding; use dom::bindings::codegen::Bindings::ProgressEventBinding::ProgressEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index b5443cccffc..3ac23d7e4d6 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -10,10 +10,10 @@ use dom::bindings::codegen::Bindings::RangeBinding::RangeMethods; use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants}; use dom::bindings::codegen::Bindings::TextBinding::TextMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; use dom::bindings::js::{JS, MutHeap, Root, RootedReference}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::characterdata::CharacterData; diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs index c7e4cd45b35..5f113c4dd54 100644 --- a/components/script/dom/servohtmlparser.rs +++ b/components/script/dom/servohtmlparser.rs @@ -11,8 +11,8 @@ use dom::bindings::codegen::Bindings::ServoHTMLParserBinding; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; -use dom::bindings::trace::JSTraceable; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::trace::JSTraceable; use dom::document::Document; use dom::node::Node; use dom::text::Text; diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 17003692e15..3bc14c44820 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -4,9 +4,9 @@ use dom::bindings::codegen::Bindings::StorageBinding; use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflector, reflect_dom_object}; diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs index 55f2d04d6cc..13a9c20d060 100644 --- a/components/script/dom/storageevent.rs +++ b/components/script/dom/storageevent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventMethods}; use dom::bindings::codegen::Bindings::StorageEventBinding; use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference}; use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 9e2da895852..e0c95285b34 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -17,8 +17,8 @@ use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::eLong; use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::js::Root; use dom::bindings::num::Finite; -use dom::bindings::str::{ByteString, USVString}; use dom::bindings::reflector::Reflector; +use dom::bindings::str::{ByteString, USVString}; use dom::blob::Blob; use js::jsapi::{HandleValue, JSContext, JSObject}; use js::jsval::{JSVal, NullValue}; diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs index e11a3e7d579..21e2edb8193 100644 --- a/components/script/dom/text.rs +++ b/components/script/dom/text.rs @@ -7,9 +7,9 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods}; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::js::{RootedReference}; use dom::characterdata::CharacterData; diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs index ad2f28c9ff5..d4c49b490f8 100644 --- a/components/script/dom/textdecoder.rs +++ b/components/script/dom/textdecoder.rs @@ -7,9 +7,9 @@ use dom::bindings::codegen::Bindings::TextDecoderBinding::TextDecoderMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; +use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::USVString; use dom::bindings::trace::JSTraceable; -use dom::bindings::reflector::{Reflector, reflect_dom_object}; use encoding::Encoding; use encoding::label::encoding_from_whatwg_label; use encoding::types::{DecoderTrap, EncodingRef}; diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs index 1025df5d3d3..cde2115f40a 100644 --- a/components/script/dom/textencoder.rs +++ b/components/script/dom/textencoder.rs @@ -7,8 +7,8 @@ use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::str::USVString; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::str::USVString; use encoding::label::encoding_from_whatwg_label; use encoding::types::EncodingRef; use encoding::{EncoderTrap, Encoding}; diff --git a/components/script/dom/touchevent.rs b/components/script/dom/touchevent.rs index d84d4788eda..7340316f9fc 100644 --- a/components/script/dom/touchevent.rs +++ b/components/script/dom/touchevent.rs @@ -5,8 +5,8 @@ use dom::bindings::codegen::Bindings::TouchEventBinding; use dom::bindings::codegen::Bindings::TouchEventBinding::TouchEventMethods; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::reflector::reflect_dom_object; use dom::event::{EventBubbles, EventCancelable}; diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 079dbb3a814..602ee6fd02d 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -5,9 +5,9 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::UIEventBinding; use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableHeap, RootedReference}; use dom::bindings::reflector::reflect_dom_object; diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs index 95fc38122f1..448884a88cd 100644 --- a/components/script/dom/url.rs +++ b/components/script/dom/url.rs @@ -6,8 +6,8 @@ use dom::bindings::codegen::Bindings::URLBinding::{self, URLMethods}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::str::USVString; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::str::USVString; use dom::urlhelper::UrlHelper; use std::borrow::ToOwned; use std::cell::RefCell; diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index d7ccd181e9d..7223ffd8b37 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -3,10 +3,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::{Attr, AttrValue}; +use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::ElementTypeId; use dom::bindings::inheritance::HTMLElementTypeId; use dom::bindings::inheritance::NodeTypeId; -use dom::bindings::inheritance::Castable; use dom::document::Document; use dom::element::{AttributeMutation, Element}; use dom::event::Event; diff --git a/components/script/dom/webglcontextevent.rs b/components/script/dom/webglcontextevent.rs index 905deaaddf2..ce42026b5d2 100644 --- a/components/script/dom/webglcontextevent.rs +++ b/components/script/dom/webglcontextevent.rs @@ -6,9 +6,9 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::WebGLContextEventBinding; use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventInit; use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 46471b0761c..b6f9a333521 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -12,10 +12,9 @@ use dom::bindings::global::{GlobalField, GlobalRef}; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::str::USVString; use dom::bindings::trace::JSTraceable; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; use dom::blob::Blob; use dom::closeevent::CloseEvent; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 44c138bb1e5..d91be770454 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -11,10 +11,10 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::{EventHandlerNonNull, use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions}; use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods}; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, Fallible, report_pending_exception}; use dom::bindings::global::GlobalRef; use dom::bindings::global::global_object_for_js_object; +use dom::bindings::inheritance::Castable; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::num::Finite; diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index a16452b5b4f..6441828185c 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -6,15 +6,14 @@ use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::WorkerBinding; use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::{GlobalField, GlobalRef}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::refcounted::Trusted; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::trace::JSTraceable; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, WorkerScriptMsg}; use dom::errorevent::ErrorEvent; use dom::event::{Event, EventBubbles, EventCancelable}; diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index fb263bbea27..f775c335f8c 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -5,9 +5,9 @@ use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg}; use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods; -use dom::bindings::inheritance::Castable; use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception}; use dom::bindings::global::GlobalRef; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::reflector::Reflectable; use dom::console::Console; diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs index 23f9e18f4b0..92b8b8492a3 100644 --- a/components/script/dom/workerlocation.rs +++ b/components/script/dom/workerlocation.rs @@ -6,8 +6,8 @@ use dom::bindings::codegen::Bindings::WorkerLocationBinding; use dom::bindings::codegen::Bindings::WorkerLocationBinding::WorkerLocationMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::str::USVString; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::str::USVString; use dom::urlhelper::UrlHelper; use dom::workerglobalscope::WorkerGlobalScope; use url::Url; diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 8e0b3c30d0a..e835f70dcb5 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -19,9 +19,8 @@ use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::refcounted::Trusted; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::str::ByteString; -use dom::bindings::reflector::reflect_dom_object; -use dom::bindings::reflector::Reflectable; use dom::document::Document; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 915aa7bb729..371ca454cc2 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -8,8 +8,7 @@ use document_loader::DocumentLoader; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId}; -use dom::bindings::inheritance::Castable; +use dom::bindings::inheritance::{Castable, CharacterDataTypeId, NodeTypeId}; use dom::bindings::js::{JS, Root}; use dom::bindings::js::{RootedReference}; use dom::characterdata::CharacterData; From ad14564c683cc22737e4708885f71ce8573168a9 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Fri, 30 Oct 2015 22:12:08 +0900 Subject: [PATCH 6/8] remove rebase-generated temp files --- .../dom/htmlcanvaselement.rs.BACKUP.20128.rs | 355 ------------------ .../dom/htmlcanvaselement.rs.BACKUP.20237.rs | 355 ------------------ .../dom/htmlcanvaselement.rs.BASE.20128.rs | 307 --------------- .../dom/htmlcanvaselement.rs.BASE.20237.rs | 307 --------------- .../dom/htmlcanvaselement.rs.LOCAL.20128.rs | 351 ----------------- .../dom/htmlcanvaselement.rs.LOCAL.20237.rs | 351 ----------------- .../dom/htmlcanvaselement.rs.REMOTE.20128.rs | 307 --------------- .../dom/htmlcanvaselement.rs.REMOTE.20237.rs | 307 --------------- .../script/dom/htmlcanvaselement.rs.orig | 355 ------------------ 9 files changed, 2995 deletions(-) delete mode 100644 components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.BASE.20128.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.BASE.20237.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs delete mode 100644 components/script/dom/htmlcanvaselement.rs.orig diff --git a/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs b/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs deleted file mode 100644 index 7b6fda591da..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.BACKUP.20128.rs +++ /dev/null @@ -1,355 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -<<<<<<< HEAD -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; -======= -use dom::bindings::inheritance::Castable; ->>>>>>> move Castable into dom::bindings::inheritance -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use image::ColorType; -use image::png::PNGEncoder; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl - fn ToDataURL(&self, - _context: *mut JSContext, - _mime_type: Option, - _arguments: Vec) -> Fallible { - - // Step 1: Check the origin-clean flag (should be set in fillText/strokeText - // and currently unimplemented) - - // Step 2. - if self.Width() == 0 || self.Height() == 0 { - return Ok("data:,".to_owned()); - } - - // Step 3. - if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { - let window = window_from_node(self); - let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), - Finite::wrap(self.Width() as f64), - Finite::wrap(self.Height() as f64))); - let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); - - // Only handle image/png for now. - let mime_type = "image/png"; - - let mut encoded = Vec::new(); - { - let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); - encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); - } - - let encoded = encoded.to_base64(STANDARD); - Ok(format!("data:{};base64,{}", mime_type, encoded)) - } else { - Err(Error::NotSupported) - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs b/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs deleted file mode 100644 index 7b6fda591da..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.BACKUP.20237.rs +++ /dev/null @@ -1,355 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -<<<<<<< HEAD -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; -======= -use dom::bindings::inheritance::Castable; ->>>>>>> move Castable into dom::bindings::inheritance -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use image::ColorType; -use image::png::PNGEncoder; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl - fn ToDataURL(&self, - _context: *mut JSContext, - _mime_type: Option, - _arguments: Vec) -> Fallible { - - // Step 1: Check the origin-clean flag (should be set in fillText/strokeText - // and currently unimplemented) - - // Step 2. - if self.Width() == 0 || self.Height() == 0 { - return Ok("data:,".to_owned()); - } - - // Step 3. - if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { - let window = window_from_node(self); - let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), - Finite::wrap(self.Width() as f64), - Finite::wrap(self.Height() as f64))); - let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); - - // Only handle image/png for now. - let mime_type = "image/png"; - - let mut encoded = Vec::new(); - { - let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); - encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); - } - - let encoded = encoded.to_base64(STANDARD); - Ok(format!("data:{};base64,{}", mime_type, encoded)) - } else { - Err(Error::NotSupported) - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs b/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs deleted file mode 100644 index 2fdb8a129e6..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.BASE.20128.rs +++ /dev/null @@ -1,307 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::conversions::Castable; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs b/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs deleted file mode 100644 index 2fdb8a129e6..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.BASE.20237.rs +++ /dev/null @@ -1,307 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::conversions::Castable; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs b/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs deleted file mode 100644 index 47126ed3dd0..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.LOCAL.20128.rs +++ /dev/null @@ -1,351 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use image::ColorType; -use image::png::PNGEncoder; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl - fn ToDataURL(&self, - _context: *mut JSContext, - _mime_type: Option, - _arguments: Vec) -> Fallible { - - // Step 1: Check the origin-clean flag (should be set in fillText/strokeText - // and currently unimplemented) - - // Step 2. - if self.Width() == 0 || self.Height() == 0 { - return Ok("data:,".to_owned()); - } - - // Step 3. - if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { - let window = window_from_node(self); - let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), - Finite::wrap(self.Width() as f64), - Finite::wrap(self.Height() as f64))); - let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); - - // Only handle image/png for now. - let mime_type = "image/png"; - - let mut encoded = Vec::new(); - { - let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); - encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); - } - - let encoded = encoded.to_base64(STANDARD); - Ok(format!("data:{};base64,{}", mime_type, encoded)) - } else { - Err(Error::NotSupported) - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs b/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs deleted file mode 100644 index 47126ed3dd0..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.LOCAL.20237.rs +++ /dev/null @@ -1,351 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use image::ColorType; -use image::png::PNGEncoder; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl - fn ToDataURL(&self, - _context: *mut JSContext, - _mime_type: Option, - _arguments: Vec) -> Fallible { - - // Step 1: Check the origin-clean flag (should be set in fillText/strokeText - // and currently unimplemented) - - // Step 2. - if self.Width() == 0 || self.Height() == 0 { - return Ok("data:,".to_owned()); - } - - // Step 3. - if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { - let window = window_from_node(self); - let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), - Finite::wrap(self.Width() as f64), - Finite::wrap(self.Height() as f64))); - let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); - - // Only handle image/png for now. - let mime_type = "image/png"; - - let mut encoded = Vec::new(); - { - let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); - encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); - } - - let encoded = encoded.to_base64(STANDARD); - Ok(format!("data:{};base64,{}", mime_type, encoded)) - } else { - Err(Error::NotSupported) - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs b/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs deleted file mode 100644 index d15c7096f90..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.REMOTE.20128.rs +++ /dev/null @@ -1,307 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::inheritance::Castable; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs b/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs deleted file mode 100644 index d15c7096f90..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.REMOTE.20237.rs +++ /dev/null @@ -1,307 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -use dom::bindings::inheritance::Castable; -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} diff --git a/components/script/dom/htmlcanvaselement.rs.orig b/components/script/dom/htmlcanvaselement.rs.orig deleted file mode 100644 index 7b6fda591da..00000000000 --- a/components/script/dom/htmlcanvaselement.rs.orig +++ /dev/null @@ -1,355 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 canvas_traits::{CanvasMsg, FromLayoutMsg}; -use dom::attr::Attr; -use dom::bindings::cell::DOMRefCell; -use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; -use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; -use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; -use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; -<<<<<<< HEAD -use dom::bindings::conversions::Castable; -use dom::bindings::error::{Error, Fallible}; -======= -use dom::bindings::inheritance::Castable; ->>>>>>> move Castable into dom::bindings::inheritance -use dom::bindings::global::GlobalRef; -use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; -use dom::bindings::num::Finite; -use dom::bindings::utils::{Reflectable}; -use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; -use dom::document::Document; -use dom::element::{AttributeMutation, Element}; -use dom::htmlelement::HTMLElement; -use dom::node::{Node, window_from_node}; -use dom::virtualmethods::VirtualMethods; -use dom::webglrenderingcontext::{LayoutCanvasWebGLRenderingContextHelpers, WebGLRenderingContext}; -use euclid::size::Size2D; -use image::ColorType; -use image::png::PNGEncoder; -use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{HandleValue, JSContext}; -use offscreen_gl_context::GLContextAttributes; -use rustc_serialize::base64::{STANDARD, ToBase64}; -use std::cell::Cell; -use std::iter::repeat; -use util::str::{DOMString, parse_unsigned_integer}; - -const DEFAULT_WIDTH: u32 = 300; -const DEFAULT_HEIGHT: u32 = 150; - -#[must_root] -#[derive(JSTraceable, Clone, HeapSizeOf)] -pub enum CanvasContext { - Context2d(JS), - WebGL(JS), -} - -impl HeapGCValue for CanvasContext {} - -#[dom_struct] -pub struct HTMLCanvasElement { - htmlelement: HTMLElement, - context: DOMRefCell>, - width: Cell, - height: Cell, -} - -impl PartialEq for HTMLCanvasElement { - fn eq(&self, other: &HTMLCanvasElement) -> bool { - self as *const HTMLCanvasElement == &*other - } -} - -impl HTMLCanvasElement { - fn new_inherited(localName: DOMString, - prefix: Option, - document: &Document) -> HTMLCanvasElement { - HTMLCanvasElement { - htmlelement: HTMLElement::new_inherited(localName, prefix, document), - context: DOMRefCell::new(None), - width: Cell::new(DEFAULT_WIDTH), - height: Cell::new(DEFAULT_HEIGHT), - } - } - - #[allow(unrooted_must_root)] - pub fn new(localName: DOMString, - prefix: Option, - document: &Document) -> Root { - let element = HTMLCanvasElement::new_inherited(localName, prefix, document); - Node::reflect_node(box element, document, HTMLCanvasElementBinding::Wrap) - } - - fn recreate_contexts(&self) { - let size = self.get_size(); - if let Some(ref context) = *self.context.borrow() { - match *context { - CanvasContext::Context2d(ref context) => context.recreate(size), - CanvasContext::WebGL(ref context) => context.recreate(size), - } - } - } - - pub fn get_size(&self) -> Size2D { - Size2D::new(self.width.get() as i32, self.height.get() as i32) - } -} - -pub struct HTMLCanvasData { - pub renderer_id: Option, - pub ipc_renderer: Option>, - pub width: u32, - pub height: u32, -} - -pub trait LayoutHTMLCanvasElementHelpers { - fn data(&self) -> HTMLCanvasData; -} - -impl LayoutHTMLCanvasElementHelpers for LayoutJS { - #[allow(unsafe_code)] - fn data(&self) -> HTMLCanvasData { - unsafe { - let canvas = &*self.unsafe_get(); - let (renderer_id, ipc_renderer) = match canvas.context.borrow_for_layout().as_ref() { - Some(&CanvasContext::Context2d(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - Some(&CanvasContext::WebGL(ref context)) => { - let context = context.to_layout(); - (Some(context.get_renderer_id()), Some(context.get_ipc_renderer())) - }, - None => (None, None), - }; - - HTMLCanvasData { - renderer_id: renderer_id, - ipc_renderer: ipc_renderer, - width: canvas.width.get(), - height: canvas.height.get(), - } - } - } -} - - -impl HTMLCanvasElement { - pub fn ipc_renderer(&self) -> Option> { - self.context.borrow().as_ref().map(|context| { - match *context { - CanvasContext::Context2d(ref context) => context.ipc_renderer(), - CanvasContext::WebGL(ref context) => context.ipc_renderer(), - } - }) - } - - pub fn get_or_init_2d_context(&self) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - let context = CanvasRenderingContext2D::new(GlobalRef::Window(window.r()), self, size); - *self.context.borrow_mut() = Some(CanvasContext::Context2d(JS::from_rooted(&context))); - } - - match *self.context.borrow().as_ref().unwrap() { - CanvasContext::Context2d(ref context) => Some(context.root()), - _ => None, - } - } - - pub fn get_or_init_webgl_context(&self, - cx: *mut JSContext, - attrs: Option) -> Option> { - if self.context.borrow().is_none() { - let window = window_from_node(self); - let size = self.get_size(); - - let attrs = if let Some(webgl_attributes) = attrs { - if let Ok(ref attrs) = WebGLContextAttributes::new(cx, webgl_attributes) { - From::from(attrs) - } else { - debug!("Unexpected error on conversion of WebGLContextAttributes"); - return None; - } - } else { - GLContextAttributes::default() - }; - - let maybe_ctx = WebGLRenderingContext::new(GlobalRef::Window(window.r()), self, size, attrs); - - *self.context.borrow_mut() = maybe_ctx.map( |ctx| CanvasContext::WebGL(JS::from_rooted(&ctx))); - } - - if let Some(CanvasContext::WebGL(ref context)) = *self.context.borrow() { - Some(context.root()) - } else { - None - } - } - - pub fn is_valid(&self) -> bool { - self.height.get() != 0 && self.width.get() != 0 - } - - pub fn fetch_all_data(&self) -> Option<(Vec, Size2D)> { - let size = self.get_size(); - - if size.width == 0 || size.height == 0 { - return None - } - - let data = if let Some(renderer) = self.ipc_renderer() { - let (sender, receiver) = ipc::channel().unwrap(); - let msg = CanvasMsg::FromLayout(FromLayoutMsg::SendPixelContents(sender)); - renderer.send(msg).unwrap(); - - receiver.recv().unwrap().to_vec() - } else { - repeat(0xffu8).take((size.height as usize) * (size.width as usize) * 4).collect() - }; - - Some((data, size)) - } -} - -impl HTMLCanvasElementMethods for HTMLCanvasElement { - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn Width(&self) -> u32 { - self.width.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-width - fn SetWidth(&self, width: u32) { - self.upcast::().set_uint_attribute(&atom!("width"), width) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn Height(&self) -> u32 { - self.height.get() - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-height - fn SetHeight(&self, height: u32) { - self.upcast::().set_uint_attribute(&atom!("height"), height) - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext - fn GetContext(&self, - cx: *mut JSContext, - id: DOMString, - attributes: Vec) - -> Option { - match &*id { - "2d" => { - self.get_or_init_2d_context() - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D) - } - "webgl" | "experimental-webgl" => { - self.get_or_init_webgl_context(cx, attributes.get(0).map(|p| *p)) - .map(CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext) - } - _ => None - } - } - - // https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl - fn ToDataURL(&self, - _context: *mut JSContext, - _mime_type: Option, - _arguments: Vec) -> Fallible { - - // Step 1: Check the origin-clean flag (should be set in fillText/strokeText - // and currently unimplemented) - - // Step 2. - if self.Width() == 0 || self.Height() == 0 { - return Ok("data:,".to_owned()); - } - - // Step 3. - if let Some(CanvasContext::Context2d(ref context)) = *self.context.borrow() { - let window = window_from_node(self); - let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64), - Finite::wrap(self.Width() as f64), - Finite::wrap(self.Height() as f64))); - let raw_data = image_data.get_data_array(&GlobalRef::Window(window.r())); - - // Only handle image/png for now. - let mime_type = "image/png"; - - let mut encoded = Vec::new(); - { - let encoder: PNGEncoder<&mut Vec> = PNGEncoder::new(&mut encoded); - encoder.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8)).unwrap(); - } - - let encoded = encoded.to_base64(STANDARD); - Ok(format!("data:{};base64,{}", mime_type, encoded)) - } else { - Err(Error::NotSupported) - } - } -} - -impl VirtualMethods for HTMLCanvasElement { - fn super_type(&self) -> Option<&VirtualMethods> { - Some(self.upcast::() as &VirtualMethods) - } - - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - let recreate = match attr.local_name() { - &atom!(width) => { - let width = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.width.set(width.unwrap_or(DEFAULT_WIDTH)); - true - }, - &atom!(height) => { - let height = mutation.new_value(attr).and_then(|value| { - parse_unsigned_integer(value.chars()) - }); - self.height.set(height.unwrap_or(DEFAULT_HEIGHT)); - true - }, - _ => false, - }; - if recreate { - self.recreate_contexts(); - } - } -} - -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { - GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, - } - } -} - -pub mod utils { - use dom::window::Window; - use ipc_channel::ipc; - use net_traits::image_cache_task::{ImageCacheChan, ImageResponse}; - use url::Url; - - pub fn request_image_from_cache(window: &Window, url: Url) -> ImageResponse { - let image_cache = window.image_cache_task(); - let (response_chan, response_port) = ipc::channel().unwrap(); - image_cache.request_image(url, ImageCacheChan(response_chan), None); - let result = response_port.recv().unwrap(); - result.image_response - } -} From 7032a5d1dee9bb2ba0bee45f1fda984dadfa0609 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Fri, 30 Oct 2015 22:57:59 +0900 Subject: [PATCH 7/8] more cleanup --- components/script/dom/bindings/utils.rs | 4 +--- components/script/dom/htmlcanvaselement.rs | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 98836d7fe7d..31961ca21b0 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -9,9 +9,7 @@ use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH; use dom::bindings::conversions::native_from_handleobject; use dom::bindings::conversions::private_from_proto_check; use dom::bindings::conversions::{is_dom_class, jsstring_to_str, DOM_OBJECT_SLOT}; -use dom::bindings::error::throw_type_error; -use dom::bindings::error::{Error, ErrorResult, Fallible, throw_invalid_this}; -use dom::bindings::global::GlobalRef; +use dom::bindings::error::{throw_invalid_this, throw_type_error}; use dom::bindings::inheritance::TopTypeId; use dom::bindings::js::Root; use dom::bindings::trace::trace_object; diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index ab72e57444a..51bc5536a3f 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -10,9 +10,11 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext; +use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root}; +use dom::bindings::num::Finite; use dom::bindings::reflector::Reflectable; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; use dom::document::Document; From 425c0b85d9d6d414317ee641080e49d912eb21c2 Mon Sep 17 00:00:00 2001 From: "rohan.prinja" Date: Tue, 3 Nov 2015 19:11:01 +0900 Subject: [PATCH 8/8] make test-tidy happy + fix some merge errors --- components/script/dom/bindings/codegen/CodegenRust.py | 6 +++--- components/script/dom/element.rs | 1 - components/script/dom/htmlmeterelement.rs | 2 +- components/script/dom/htmloutputelement.rs | 2 +- components/script/dom/htmlprogresselement.rs | 2 +- components/script/dom/urlsearchparams.rs | 2 +- components/script/parse/html.rs | 1 - 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index fe8e59d5f1e..4134fb104fe 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5960,8 +5960,8 @@ class GlobalGenRoots(): ("ID used by interfaces that are not castable.", "Alone"), ] topTypeVariants += [ - ("ID used by interfaces that derive from %s." % name, "%s(%sTypeId)" % (name, name)) - for name in topTypes + ("ID used by interfaces that derive from %s." % typeName, "%s(%sTypeId)" % (typeName, typeName)) + for typeName in topTypes ] topTypeVariantsAsStrings = [CGGeneric("/// %s\n%s," % variant) for variant in topTypeVariants] typeIdCode.append(CGWrapper(CGIndenter(CGList(topTypeVariantsAsStrings, "\n"), 4), @@ -5978,7 +5978,7 @@ class GlobalGenRoots(): variants = [] if not config.getInterface(base).getExtendedAttribute("Abstract"): variants.append(CGGeneric(base)) - variants += [CGGeneric(type_id_variant(name)) for name in derived] + variants += [CGGeneric(type_id_variant(derivedName)) for derivedName in derived] derives = "Clone, Copy, Debug" if base != 'EventTarget' and base != 'HTMLElement': derives += ", PartialEq" diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 779b802fc26..6eaea65d154 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -19,7 +19,6 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; diff --git a/components/script/dom/htmlmeterelement.rs b/components/script/dom/htmlmeterelement.rs index 74b48434339..91006fb486b 100644 --- a/components/script/dom/htmlmeterelement.rs +++ b/components/script/dom/htmlmeterelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::HTMLMeterElementBinding::{self, HTMLMeterElementMethods}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/htmloutputelement.rs b/components/script/dom/htmloutputelement.rs index 937fcea3919..9049262aa8c 100644 --- a/components/script/dom/htmloutputelement.rs +++ b/components/script/dom/htmloutputelement.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::Bindings::HTMLOutputElementBinding; use dom::bindings::codegen::Bindings::HTMLOutputElementBinding::HTMLOutputElementMethods; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/htmlprogresselement.rs b/components/script/dom/htmlprogresselement.rs index 669f25942b6..904055a21a0 100644 --- a/components/script/dom/htmlprogresselement.rs +++ b/components/script/dom/htmlprogresselement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::HTMLProgressElementBinding::{self, HTMLProgressElementMethods}; -use dom::bindings::conversions::Castable; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::htmlelement::HTMLElement; diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index 8fc3cdb6778..0e3c21679fd 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -10,8 +10,8 @@ use dom::bindings::codegen::UnionTypes::USVStringOrURLSearchParams::{eUSVString, use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::bindings::str::USVString; use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::str::USVString; use encoding::types::EncodingRef; use url::form_urlencoded::{parse, serialize_with_encoding}; use util::str::DOMString; diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index aa5a03c6a08..680d96a32a8 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -9,7 +9,6 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::inheritance::{Castable, CharacterDataTypeId, NodeTypeId}; - use dom::bindings::js::{JS, RootedReference}; use dom::characterdata::CharacterData; use dom::comment::Comment;