From 669338ae76268d99c564bec1549184871d44110d Mon Sep 17 00:00:00 2001 From: John Schoenick Date: Thu, 6 Mar 2014 15:46:38 -0800 Subject: [PATCH] Bug 870022 - Part 5.1 - Add HTMLPictureElement & atom. r=jst, sr=jst --- content/base/src/nsGkAtomList.h | 1 + .../html/content/src/HTMLPictureElement.cpp | 57 +++++++++++++++++++ content/html/content/src/HTMLPictureElement.h | 43 ++++++++++++++ content/html/content/src/moz.build | 2 + .../html/content/src/nsGenericHTMLElement.h | 1 + dom/interfaces/html/moz.build | 1 + .../html/nsIDOMHTMLPictureElement.idl | 12 ++++ .../mochitest/general/test_interfaces.html | 2 + dom/webidl/HTMLPictureElement.webidl | 9 +++ dom/webidl/moz.build | 1 + 10 files changed, 129 insertions(+) create mode 100644 content/html/content/src/HTMLPictureElement.cpp create mode 100644 content/html/content/src/HTMLPictureElement.h create mode 100644 dom/interfaces/html/nsIDOMHTMLPictureElement.idl create mode 100644 dom/webidl/HTMLPictureElement.webidl diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index e3354c66d76a..7dc9196ce922 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -2220,6 +2220,7 @@ GK_ATOM(menuitemradio, "menuitemradio") GK_ATOM(mixed, "mixed") GK_ATOM(multiline, "multiline") GK_ATOM(password, "password") +GK_ATOM(picture, "picture") GK_ATOM(posinset, "posinset") GK_ATOM(presentation, "presentation") GK_ATOM(progressbar, "progressbar") diff --git a/content/html/content/src/HTMLPictureElement.cpp b/content/html/content/src/HTMLPictureElement.cpp new file mode 100644 index 000000000000..2d4c32478bf1 --- /dev/null +++ b/content/html/content/src/HTMLPictureElement.cpp @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#include "mozilla/dom/HTMLPictureElement.h" +#include "mozilla/dom/HTMLPictureElementBinding.h" +#include "mozilla/dom/HTMLImageElement.h" + +#include "mozilla/Preferences.h" +static const char *kPrefPictureEnabled = "dom.image.picture.enabled"; + +// Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Picture) to add pref check. +nsGenericHTMLElement* +NS_NewHTMLPictureElement(already_AddRefed&& aNodeInfo, + mozilla::dom::FromParser aFromParser) +{ + if (!mozilla::dom::HTMLPictureElement::IsPictureEnabled()) { + return new mozilla::dom::HTMLUnknownElement(aNodeInfo); + } + + return new mozilla::dom::HTMLPictureElement(aNodeInfo); +} + +namespace mozilla { +namespace dom { + +HTMLPictureElement::HTMLPictureElement(already_AddRefed& aNodeInfo) + : nsGenericHTMLElement(aNodeInfo) +{ +} + +HTMLPictureElement::~HTMLPictureElement() +{ +} + +NS_IMPL_ISUPPORTS_INHERITED(HTMLPictureElement, nsGenericHTMLElement, + nsIDOMHTMLPictureElement) + +NS_IMPL_ELEMENT_CLONE(HTMLPictureElement) + +bool +HTMLPictureElement::IsPictureEnabled() +{ + return HTMLImageElement::IsSrcsetEnabled() && + Preferences::GetBool(kPrefPictureEnabled, false); +} + +JSObject* +HTMLPictureElement::WrapNode(JSContext* aCx) +{ + return HTMLPictureElementBinding::Wrap(aCx, this); +} + +} // namespace dom +} // namespace mozilla diff --git a/content/html/content/src/HTMLPictureElement.h b/content/html/content/src/HTMLPictureElement.h new file mode 100644 index 000000000000..be0604011d77 --- /dev/null +++ b/content/html/content/src/HTMLPictureElement.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#ifndef mozilla_dom_HTMLPictureElement_h +#define mozilla_dom_HTMLPictureElement_h + +#include "mozilla/Attributes.h" +#include "nsIDOMHTMLPictureElement.h" +#include "nsGenericHTMLElement.h" + +#include "mozilla/dom/HTMLUnknownElement.h" + +namespace mozilla { +namespace dom { + +class HTMLPictureElement MOZ_FINAL : public nsGenericHTMLElement, + public nsIDOMHTMLPictureElement +{ +public: + HTMLPictureElement(already_AddRefed& aNodeInfo); + virtual ~HTMLPictureElement(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMHTMLPictureElement + NS_DECL_NSIDOMHTMLPICTUREELEMENT + + virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const MOZ_OVERRIDE; + + static bool IsPictureEnabled(); + +protected: + virtual JSObject* WrapNode(JSContext* aCx) MOZ_OVERRIDE; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_HTMLPictureElement_h diff --git a/content/html/content/src/moz.build b/content/html/content/src/moz.build index e48bb1386e23..fd495b3c4036 100644 --- a/content/html/content/src/moz.build +++ b/content/html/content/src/moz.build @@ -47,6 +47,7 @@ EXPORTS.mozilla.dom += [ 'HTMLOptionsCollection.h', 'HTMLOutputElement.h', 'HTMLParagraphElement.h', + 'HTMLPictureElement.h', 'HTMLPreElement.h', 'HTMLProgressElement.h', 'HTMLScriptElement.h', @@ -118,6 +119,7 @@ UNIFIED_SOURCES += [ 'HTMLOptionsCollection.cpp', 'HTMLOutputElement.cpp', 'HTMLParagraphElement.cpp', + 'HTMLPictureElement.cpp', 'HTMLPreElement.cpp', 'HTMLProgressElement.cpp', 'HTMLPropertiesCollection.cpp', diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 34d9009cca47..d1f1485f25c7 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -1764,6 +1764,7 @@ NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup) NS_DECLARE_NS_NEW_HTML_ELEMENT(Option) NS_DECLARE_NS_NEW_HTML_ELEMENT(Output) NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Picture) NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre) NS_DECLARE_NS_NEW_HTML_ELEMENT(Progress) NS_DECLARE_NS_NEW_HTML_ELEMENT(Script) diff --git a/dom/interfaces/html/moz.build b/dom/interfaces/html/moz.build index c6d93c029dd6..679b24ce273d 100644 --- a/dom/interfaces/html/moz.build +++ b/dom/interfaces/html/moz.build @@ -45,6 +45,7 @@ XPIDL_SOURCES += [ 'nsIDOMHTMLOptionElement.idl', 'nsIDOMHTMLOptionsCollection.idl', 'nsIDOMHTMLParagraphElement.idl', + 'nsIDOMHTMLPictureElement.idl', 'nsIDOMHTMLPreElement.idl', 'nsIDOMHTMLQuoteElement.idl', 'nsIDOMHTMLScriptElement.idl', diff --git a/dom/interfaces/html/nsIDOMHTMLPictureElement.idl b/dom/interfaces/html/nsIDOMHTMLPictureElement.idl new file mode 100644 index 000000000000..18f819c0bae6 --- /dev/null +++ b/dom/interfaces/html/nsIDOMHTMLPictureElement.idl @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#include "nsIDOMHTMLElement.idl" + +[scriptable, uuid(e0e5ac7f-b969-494c-a61e-9d740e38abba)] +interface nsIDOMHTMLPictureElement : nsISupports +{ +}; diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index af893b1ebf64..2728449e2ae8 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -501,6 +501,8 @@ var interfaceNamesInGlobalScope = "HTMLParamElement", // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLPreElement", +// IMPORTANT: Do not change this list without review from a DOM peer! + {name: "HTMLPictureElement", pref: "dom.image.picture.enabled"}, // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLProgressElement", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/HTMLPictureElement.webidl b/dom/webidl/HTMLPictureElement.webidl new file mode 100644 index 000000000000..e2964dd1b789 --- /dev/null +++ b/dom/webidl/HTMLPictureElement.webidl @@ -0,0 +1,9 @@ +/* -*- 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/. + */ + +[Pref="dom.image.picture.enabled"] +interface HTMLPictureElement : HTMLElement { +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index ce088f001888..506efc79c8da 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -178,6 +178,7 @@ WEBIDL_FILES = [ 'HTMLOutputElement.webidl', 'HTMLParagraphElement.webidl', 'HTMLParamElement.webidl', + 'HTMLPictureElement.webidl', 'HTMLPreElement.webidl', 'HTMLProgressElement.webidl', 'HTMLPropertiesCollection.webidl',