Bug 837416 - Part 2: Move HTMLStyleElement to Web IDL bindings; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2013-02-03 12:42:40 -05:00
parent 9ca42db041
commit 77af533fee
9 changed files with 111 additions and 22 deletions

View File

@ -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

View File

@ -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<nsINodeInfo> aNodeInfo)
: nsGenericHTMLElement(aNodeInfo)
{
AddMutationObserver(this);
SetIsDOMBinding();
}
HTMLStyleElement::~HTMLStyleElement()
@ -64,24 +66,43 @@ NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
NS_IMETHODIMP
HTMLStyleElement::GetDisabled(bool* aDisabled)
{
nsCOMPtr<nsIDOMStyleSheet> 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<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
nsCOMPtr<nsIDOMStyleSheet> 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<nsIDOMStyleSheet> 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

View File

@ -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; }

View File

@ -159,7 +159,7 @@ NS_IMPL_ELEMENT_CLONE(nsHTMLLinkElement)
NS_IMETHODIMP
nsHTMLLinkElement::GetDisabled(bool* aDisabled)
{
nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
nsCOMPtr<nsIDOMStyleSheet> 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<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
nsCOMPtr<nsIDOMStyleSheet> 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);
}

View File

@ -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);

View File

@ -475,6 +475,13 @@ DOMInterfaces = {
]
},
'HTMLStyleElement': {
'hasInstanceInterface': 'nsIDOMHTMLStyleElement',
'resultNotAddRefed': [
'sheet'
]
},
'HTMLUListElement': {
'headerFile' : 'mozilla/dom/HTMLSharedListElement.h'
},

View File

@ -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;

View File

@ -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;
};

View File

@ -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 \