From 77af533feefc2bcb724000eb2746cce03cc44663 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sun, 3 Feb 2013 12:42:40 -0500 Subject: [PATCH] Bug 837416 - Part 2: Move HTMLStyleElement to Web IDL bindings; r=bzbarsky --- content/base/src/nsStyleLinkElement.h | 4 +- content/html/content/src/HTMLStyleElement.cpp | 50 +++++++++++++++---- content/html/content/src/HTMLStyleElement.h | 22 ++++++++ .../html/content/src/nsHTMLLinkElement.cpp | 6 +-- .../src/XMLStylesheetProcessingInstruction.h | 6 --- dom/bindings/Bindings.conf | 7 +++ dom/webidl/HTMLStyleElement.webidl | 22 ++++++++ dom/webidl/LinkStyle.webidl | 14 ++++++ dom/webidl/WebIDL.mk | 2 + 9 files changed, 111 insertions(+), 22 deletions(-) create mode 100644 dom/webidl/HTMLStyleElement.webidl create mode 100644 dom/webidl/LinkStyle.webidl diff --git a/content/base/src/nsStyleLinkElement.h b/content/base/src/nsStyleLinkElement.h index bf6fab086af8..c9fe3ba1b32c 100644 --- a/content/base/src/nsStyleLinkElement.h +++ b/content/base/src/nsStyleLinkElement.h @@ -41,6 +41,8 @@ public: // nsIDOMLinkStyle NS_DECL_NSIDOMLINKSTYLE + nsIStyleSheet* GetSheet() { return mStyleSheet; } + // nsIStyleSheetLinkingElement NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); @@ -78,8 +80,6 @@ protected: bool* aIsScoped, bool* aIsAlternate) = 0; - nsIStyleSheet* GetStyleSheet() { return mStyleSheet; } - virtual mozilla::CORSMode GetCORSMode() const { // Default to no CORS diff --git a/content/html/content/src/HTMLStyleElement.cpp b/content/html/content/src/HTMLStyleElement.cpp index b0c03622f214..668eb970370e 100644 --- a/content/html/content/src/HTMLStyleElement.cpp +++ b/content/html/content/src/HTMLStyleElement.cpp @@ -3,6 +3,7 @@ * 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/. */ #include "mozilla/dom/HTMLStyleElement.h" +#include "mozilla/dom/HTMLStyleElementBinding.h" #include "nsIDOMLinkStyle.h" #include "nsIDOMEventTarget.h" #include "nsGkAtoms.h" @@ -27,6 +28,7 @@ HTMLStyleElement::HTMLStyleElement(already_AddRefed aNodeInfo) : nsGenericHTMLElement(aNodeInfo) { AddMutationObserver(this); + SetIsDOMBinding(); } HTMLStyleElement::~HTMLStyleElement() @@ -64,24 +66,43 @@ NS_IMPL_ELEMENT_CLONE(HTMLStyleElement) NS_IMETHODIMP HTMLStyleElement::GetDisabled(bool* aDisabled) { - nsCOMPtr ss = do_QueryInterface(GetStyleSheet()); - if (!ss) { - *aDisabled = false; - return NS_OK; - } + NS_ENSURE_ARG_POINTER(aDisabled); - return ss->GetDisabled(aDisabled); + *aDisabled = Disabled(); + return NS_OK; } -NS_IMETHODIMP -HTMLStyleElement::SetDisabled(bool aDisabled) +bool +HTMLStyleElement::Disabled() { - nsCOMPtr ss = do_QueryInterface(GetStyleSheet()); + nsCOMPtr ss = do_QueryInterface(GetSheet()); if (!ss) { - return NS_OK; + return false; } - return ss->SetDisabled(aDisabled); + bool disabled = false; + ss->GetDisabled(&disabled); + + return disabled; +} + +NS_IMETHODIMP +HTMLStyleElement::SetDisabled(bool aDisabled) +{ + ErrorResult error; + SetDisabled(aDisabled, error); + return error.ErrorCode(); +} + +void +HTMLStyleElement::SetDisabled(bool aDisabled, ErrorResult& aError) +{ + nsCOMPtr ss = do_QueryInterface(GetSheet()); + if (!ss) { + return; + } + + aError.Throw(ss->SetDisabled(aDisabled)); } NS_IMPL_STRING_ATTR(HTMLStyleElement, Media, media) @@ -260,6 +281,13 @@ HTMLStyleElement::GetStyleSheetInfo(nsAString& aTitle, aType.AssignLiteral("text/css"); } +JSObject* +HTMLStyleElement::WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap) +{ + return HTMLStyleElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + } // namespace dom } // namespace mozilla diff --git a/content/html/content/src/HTMLStyleElement.h b/content/html/content/src/HTMLStyleElement.h index 794f25d31421..44090f3a3048 100644 --- a/content/html/content/src/HTMLStyleElement.h +++ b/content/html/content/src/HTMLStyleElement.h @@ -73,6 +73,28 @@ public: NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED + bool Disabled(); + void SetDisabled(bool aDisabled, ErrorResult& aError); + void SetMedia(const nsAString& aMedia, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::media, aMedia, aError); + } + void SetType(const nsAString& aType, ErrorResult& aError) + { + SetHTMLAttr(nsGkAtoms::type, aType, aError); + } + bool Scoped() + { + return GetBoolAttr(nsGkAtoms::scoped); + } + void SetScoped(bool aScoped, ErrorResult& aError) + { + SetHTMLBoolAttr(nsGkAtoms::scoped, aScoped, aError); + } + + virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap); + virtual nsXPCClassInfo* GetClassInfo(); virtual nsIDOMNode* AsDOMNode() { return this; } diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 54f1a8f5c6bc..9ab72f07a216 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -159,7 +159,7 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLLinkElement) NS_IMETHODIMP nsHTMLLinkElement::GetDisabled(bool* aDisabled) { - nsCOMPtr ss = do_QueryInterface(GetStyleSheet()); + nsCOMPtr ss = do_QueryInterface(GetSheet()); nsresult result = NS_OK; if (ss) { @@ -174,7 +174,7 @@ nsHTMLLinkElement::GetDisabled(bool* aDisabled) NS_IMETHODIMP nsHTMLLinkElement::SetDisabled(bool aDisabled) { - nsCOMPtr ss = do_QueryInterface(GetStyleSheet()); + nsCOMPtr ss = do_QueryInterface(GetSheet()); nsresult result = NS_OK; if (ss) { @@ -332,7 +332,7 @@ nsHTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName, aName == nsGkAtoms::media || aName == nsGkAtoms::type)) { bool dropSheet = false; - if (aName == nsGkAtoms::rel && GetStyleSheet()) { + if (aName == nsGkAtoms::rel && GetSheet()) { uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue); dropSheet = !(linkTypes & STYLESHEET); } diff --git a/content/xml/content/src/XMLStylesheetProcessingInstruction.h b/content/xml/content/src/XMLStylesheetProcessingInstruction.h index 58a520088af8..54dc327e24ed 100644 --- a/content/xml/content/src/XMLStylesheetProcessingInstruction.h +++ b/content/xml/content/src/XMLStylesheetProcessingInstruction.h @@ -33,12 +33,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XMLStylesheetProcessingInstruction, ProcessingInstruction) - using nsStyleLinkElement::GetSheet; - nsIStyleSheet* GetSheet() - { - return GetStyleSheet(); - } - // nsIDOMNode virtual void SetNodeValueInternal(const nsAString& aNodeValue, mozilla::ErrorResult& aError); diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index cb2bbee843f4..bbad212b3201 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -475,6 +475,13 @@ DOMInterfaces = { ] }, +'HTMLStyleElement': { + 'hasInstanceInterface': 'nsIDOMHTMLStyleElement', + 'resultNotAddRefed': [ + 'sheet' + ] +}, + 'HTMLUListElement': { 'headerFile' : 'mozilla/dom/HTMLSharedListElement.h' }, diff --git a/dom/webidl/HTMLStyleElement.webidl b/dom/webidl/HTMLStyleElement.webidl new file mode 100644 index 000000000000..29361ca51746 --- /dev/null +++ b/dom/webidl/HTMLStyleElement.webidl @@ -0,0 +1,22 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 origin of this IDL file is + * http://www.whatwg.org/specs/web-apps/current-work/#the-style-element + * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis + */ + +interface HTMLStyleElement : HTMLElement { + [SetterThrows] + attribute boolean disabled; + [SetterThrows] + attribute DOMString media; + [SetterThrows] + attribute DOMString type; + [SetterThrows] + attribute boolean scoped; +}; +HTMLStyleElement implements LinkStyle; + diff --git a/dom/webidl/LinkStyle.webidl b/dom/webidl/LinkStyle.webidl new file mode 100644 index 000000000000..db0bc031adde --- /dev/null +++ b/dom/webidl/LinkStyle.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 origin of this IDL file is + * http://dev.w3.org/csswg/cssom/#the-linkstyle-interface + */ + +[NoInterfaceObject] +interface LinkStyle { + readonly attribute StyleSheet? sheet; +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index e40ee9850dba..e6b09d0f2923 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -76,6 +76,7 @@ webidl_files = \ HTMLPropertiesCollection.webidl \ HTMLScriptElement.webidl \ HTMLSpanElement.webidl \ + HTMLStyleElement.webidl \ HTMLTableCaptionElement.webidl \ HTMLTableCellElement.webidl \ HTMLTableColElement.webidl \ @@ -85,6 +86,7 @@ webidl_files = \ HTMLTitleElement.webidl \ HTMLUListElement.webidl \ ImageData.webidl \ + LinkStyle.webidl \ Location.webidl \ MutationObserver.webidl \ Node.webidl \