From 2d150c2f55a246db042dba9ded39d090e4fad2e8 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Sat, 9 Feb 2013 17:21:15 -0500 Subject: [PATCH] Bug 839033 - Rename nsHTMLProgressElement to HTMLProgressElement. r=Ms2ger --HG-- rename : content/html/content/src/nsHTMLProgressElement.cpp => content/html/content/src/HTMLProgressElement.cpp rename : content/html/content/src/nsHTMLProgressElement.cpp => content/html/content/src/HTMLProgressElement.h --- .../html/content/src/HTMLProgressElement.cpp | 142 +++++++++++++ .../html/content/src/HTMLProgressElement.h | 70 +++++++ content/html/content/src/Makefile.in | 3 +- .../content/src/nsHTMLProgressElement.cpp | 192 ------------------ 4 files changed, 214 insertions(+), 193 deletions(-) create mode 100644 content/html/content/src/HTMLProgressElement.cpp create mode 100644 content/html/content/src/HTMLProgressElement.h delete mode 100644 content/html/content/src/nsHTMLProgressElement.cpp diff --git a/content/html/content/src/HTMLProgressElement.cpp b/content/html/content/src/HTMLProgressElement.cpp new file mode 100644 index 000000000000..0f9d3c849bed --- /dev/null +++ b/content/html/content/src/HTMLProgressElement.cpp @@ -0,0 +1,142 @@ +/* -*- Mode: C++; 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/. */ + +#include "mozilla/dom/HTMLProgressElement.h" + +NS_IMPL_NS_NEW_HTML_ELEMENT(Progress) +DOMCI_NODE_DATA(HTMLProgressElement, mozilla::dom::HTMLProgressElement) + +namespace mozilla { +namespace dom { + +const double HTMLProgressElement::kIndeterminatePosition = -1.0; +const double HTMLProgressElement::kDefaultValue = 0.0; +const double HTMLProgressElement::kDefaultMax = 1.0; + + +HTMLProgressElement::HTMLProgressElement(already_AddRefed aNodeInfo) + : nsGenericHTMLElement(aNodeInfo) +{ + // We start out indeterminate + AddStatesSilently(NS_EVENT_STATE_INDETERMINATE); +} + +HTMLProgressElement::~HTMLProgressElement() +{ +} + +NS_IMPL_ADDREF_INHERITED(HTMLProgressElement, Element) +NS_IMPL_RELEASE_INHERITED(HTMLProgressElement, Element) + + +NS_INTERFACE_TABLE_HEAD(HTMLProgressElement) + NS_HTML_CONTENT_INTERFACE_TABLE1(HTMLProgressElement, + nsIDOMHTMLProgressElement) + NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(HTMLProgressElement, + nsGenericHTMLElement) +NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLProgressElement) + +NS_IMPL_ELEMENT_CLONE(HTMLProgressElement) + + +nsEventStates +HTMLProgressElement::IntrinsicState() const +{ + nsEventStates state = nsGenericHTMLElement::IntrinsicState(); + + if (IsIndeterminate()) { + state |= NS_EVENT_STATE_INDETERMINATE; + } + + return state; +} + +bool +HTMLProgressElement::ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, + const nsAString& aValue, nsAttrValue& aResult) +{ + if (aNamespaceID == kNameSpaceID_None) { + if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) { + return aResult.ParseDoubleValue(aValue); + } + } + + return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, + aValue, aResult); +} + +NS_IMETHODIMP +HTMLProgressElement::GetValue(double* aValue) +{ + const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value); + if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue || + attrValue->GetDoubleValue() < 0.0) { + *aValue = kDefaultValue; + return NS_OK; + } + + *aValue = attrValue->GetDoubleValue(); + + double max; + GetMax(&max); + + *aValue = std::min(*aValue, max); + + return NS_OK; +} + +NS_IMETHODIMP +HTMLProgressElement::SetValue(double aValue) +{ + return SetDoubleAttr(nsGkAtoms::value, aValue); +} + +NS_IMETHODIMP +HTMLProgressElement::GetMax(double* aValue) +{ + const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max); + if (attrMax && attrMax->Type() == nsAttrValue::eDoubleValue && + attrMax->GetDoubleValue() > 0.0) { + *aValue = attrMax->GetDoubleValue(); + } else { + *aValue = kDefaultMax; + } + + return NS_OK; +} + +NS_IMETHODIMP +HTMLProgressElement::SetMax(double aValue) +{ + return SetDoubleAttr(nsGkAtoms::max, aValue); +} + +NS_IMETHODIMP +HTMLProgressElement::GetPosition(double* aPosition) +{ + if (IsIndeterminate()) { + *aPosition = kIndeterminatePosition; + return NS_OK; + } + + double value; + double max; + GetValue(&value); + GetMax(&max); + + *aPosition = value / max; + + return NS_OK; +} + +bool +HTMLProgressElement::IsIndeterminate() const +{ + const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value); + return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue; +} + +} // namespace dom +} // namespace mozilla diff --git a/content/html/content/src/HTMLProgressElement.h b/content/html/content/src/HTMLProgressElement.h new file mode 100644 index 000000000000..3fbfaac53dc2 --- /dev/null +++ b/content/html/content/src/HTMLProgressElement.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; 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/. */ + +#ifndef mozilla_dom_HTMLProgressElement_h +#define mozilla_dom_HTMLProgressElement_h + +#include "nsIDOMHTMLProgressElement.h" +#include "nsGenericHTMLElement.h" +#include "nsAttrValue.h" +#include "nsAttrValueInlines.h" +#include "nsEventStateManager.h" +#include + +namespace mozilla { +namespace dom { + +class HTMLProgressElement : public nsGenericHTMLElement, + public nsIDOMHTMLProgressElement +{ +public: + HTMLProgressElement(already_AddRefed aNodeInfo); + virtual ~HTMLProgressElement(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMNode + NS_FORWARD_NSIDOMNODE_TO_NSINODE + + // nsIDOMElement + NS_FORWARD_NSIDOMELEMENT_TO_GENERIC + + // nsIDOMHTMLElement + NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC + + // nsIDOMHTMLProgressElement + NS_DECL_NSIDOMHTMLPROGRESSELEMENT + + nsEventStates IntrinsicState() const; + + nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const; + + bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, + const nsAString& aValue, nsAttrValue& aResult); + + virtual nsXPCClassInfo* GetClassInfo(); + + virtual nsIDOMNode* AsDOMNode() { return this; } + +protected: + /** + * Returns whethem the progress element is in the indeterminate state. + * A progress element is in the indeterminate state if its value is ommited + * or is not a floating point number.. + * + * @return whether the progress element is in the indeterminate state. + */ + bool IsIndeterminate() const; + + static const double kIndeterminatePosition; + static const double kDefaultValue; + static const double kDefaultMax; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_HTMLProgressElement_h diff --git a/content/html/content/src/Makefile.in b/content/html/content/src/Makefile.in index 5c004aa2c3a0..e032f8db70a2 100644 --- a/content/html/content/src/Makefile.in +++ b/content/html/content/src/Makefile.in @@ -53,6 +53,7 @@ EXPORTS_mozilla/dom = \ HTMLOptGroupElement.h \ HTMLParagraphElement.h \ HTMLPreElement.h \ + HTMLProgressElement.h \ HTMLScriptElement.h \ HTMLSharedElement.h \ HTMLSharedListElement.h \ @@ -114,7 +115,7 @@ CPPSRCS = \ nsHTMLOutputElement.cpp \ HTMLParagraphElement.cpp \ HTMLPreElement.cpp \ - nsHTMLProgressElement.cpp \ + HTMLProgressElement.cpp \ HTMLScriptElement.cpp \ nsHTMLSelectElement.cpp \ HTMLSharedElement.cpp \ diff --git a/content/html/content/src/nsHTMLProgressElement.cpp b/content/html/content/src/nsHTMLProgressElement.cpp deleted file mode 100644 index fd5e5200fda1..000000000000 --- a/content/html/content/src/nsHTMLProgressElement.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* -*- Mode: C++; 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/. */ - -#include "nsIDOMHTMLProgressElement.h" -#include "nsGenericHTMLElement.h" -#include "nsAttrValue.h" -#include "nsAttrValueInlines.h" -#include "nsEventStateManager.h" -#include - -using namespace mozilla::dom; - -class nsHTMLProgressElement : public nsGenericHTMLElement, - public nsIDOMHTMLProgressElement -{ -public: - nsHTMLProgressElement(already_AddRefed aNodeInfo); - virtual ~nsHTMLProgressElement(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIDOMNode - NS_FORWARD_NSIDOMNODE_TO_NSINODE - - // nsIDOMElement - NS_FORWARD_NSIDOMELEMENT_TO_GENERIC - - // nsIDOMHTMLElement - NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC - - // nsIDOMHTMLProgressElement - NS_DECL_NSIDOMHTMLPROGRESSELEMENT - - nsEventStates IntrinsicState() const; - - nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const; - - bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, - const nsAString& aValue, nsAttrValue& aResult); - - virtual nsXPCClassInfo* GetClassInfo(); - - virtual nsIDOMNode* AsDOMNode() { return this; } - -protected: - /** - * Returns whethem the progress element is in the indeterminate state. - * A progress element is in the indeterminate state if its value is ommited - * or is not a floating point number.. - * - * @return whether the progress element is in the indeterminate state. - */ - bool IsIndeterminate() const; - - static const double kIndeterminatePosition; - static const double kDefaultValue; - static const double kDefaultMax; -}; - -const double nsHTMLProgressElement::kIndeterminatePosition = -1.0; -const double nsHTMLProgressElement::kDefaultValue = 0.0; -const double nsHTMLProgressElement::kDefaultMax = 1.0; - -NS_IMPL_NS_NEW_HTML_ELEMENT(Progress) - - -nsHTMLProgressElement::nsHTMLProgressElement(already_AddRefed aNodeInfo) - : nsGenericHTMLElement(aNodeInfo) -{ - // We start out indeterminate - AddStatesSilently(NS_EVENT_STATE_INDETERMINATE); -} - -nsHTMLProgressElement::~nsHTMLProgressElement() -{ -} - -NS_IMPL_ADDREF_INHERITED(nsHTMLProgressElement, Element) -NS_IMPL_RELEASE_INHERITED(nsHTMLProgressElement, Element) - -DOMCI_NODE_DATA(HTMLProgressElement, nsHTMLProgressElement) - -NS_INTERFACE_TABLE_HEAD(nsHTMLProgressElement) - NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLProgressElement, - nsIDOMHTMLProgressElement) - NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLProgressElement, - nsGenericHTMLElement) -NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLProgressElement) - -NS_IMPL_ELEMENT_CLONE(nsHTMLProgressElement) - - -nsEventStates -nsHTMLProgressElement::IntrinsicState() const -{ - nsEventStates state = nsGenericHTMLElement::IntrinsicState(); - - if (IsIndeterminate()) { - state |= NS_EVENT_STATE_INDETERMINATE; - } - - return state; -} - -bool -nsHTMLProgressElement::ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute, - const nsAString& aValue, nsAttrValue& aResult) -{ - if (aNamespaceID == kNameSpaceID_None) { - if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) { - return aResult.ParseDoubleValue(aValue); - } - } - - return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, - aValue, aResult); -} - -NS_IMETHODIMP -nsHTMLProgressElement::GetValue(double* aValue) -{ - const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value); - if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue || - attrValue->GetDoubleValue() < 0.0) { - *aValue = kDefaultValue; - return NS_OK; - } - - *aValue = attrValue->GetDoubleValue(); - - double max; - GetMax(&max); - - *aValue = std::min(*aValue, max); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLProgressElement::SetValue(double aValue) -{ - return SetDoubleAttr(nsGkAtoms::value, aValue); -} - -NS_IMETHODIMP -nsHTMLProgressElement::GetMax(double* aValue) -{ - const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max); - if (attrMax && attrMax->Type() == nsAttrValue::eDoubleValue && - attrMax->GetDoubleValue() > 0.0) { - *aValue = attrMax->GetDoubleValue(); - } else { - *aValue = kDefaultMax; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLProgressElement::SetMax(double aValue) -{ - return SetDoubleAttr(nsGkAtoms::max, aValue); -} - -NS_IMETHODIMP -nsHTMLProgressElement::GetPosition(double* aPosition) -{ - if (IsIndeterminate()) { - *aPosition = kIndeterminatePosition; - return NS_OK; - } - - double value; - double max; - GetValue(&value); - GetMax(&max); - - *aPosition = value / max; - - return NS_OK; -} - -bool -nsHTMLProgressElement::IsIndeterminate() const -{ - const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value); - return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue; -} -