1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/EventStates.h"
8 #include "mozilla/dom/HTMLProgressElement.h"
9 #include "mozilla/dom/HTMLProgressElementBinding.h"
11 NS_IMPL_NS_NEW_HTML_ELEMENT(Progress
)
16 const double HTMLProgressElement::kIndeterminatePosition
= -1.0;
17 const double HTMLProgressElement::kDefaultValue
= 0.0;
18 const double HTMLProgressElement::kDefaultMax
= 1.0;
21 HTMLProgressElement::HTMLProgressElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
22 : nsGenericHTMLElement(std::move(aNodeInfo
))
24 // We start out indeterminate
25 AddStatesSilently(NS_EVENT_STATE_INDETERMINATE
);
28 HTMLProgressElement::~HTMLProgressElement()
32 NS_IMPL_ELEMENT_CLONE(HTMLProgressElement
)
36 HTMLProgressElement::IntrinsicState() const
38 EventStates state
= nsGenericHTMLElement::IntrinsicState();
40 if (IsIndeterminate()) {
41 state
|= NS_EVENT_STATE_INDETERMINATE
;
48 HTMLProgressElement::ParseAttribute(int32_t aNamespaceID
,
50 const nsAString
& aValue
,
51 nsIPrincipal
* aMaybeScriptedPrincipal
,
54 if (aNamespaceID
== kNameSpaceID_None
) {
55 if (aAttribute
== nsGkAtoms::value
|| aAttribute
== nsGkAtoms::max
) {
56 return aResult
.ParseDoubleValue(aValue
);
60 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
,
62 aMaybeScriptedPrincipal
,
67 HTMLProgressElement::Value() const
69 const nsAttrValue
* attrValue
= mAttrs
.GetAttr(nsGkAtoms::value
);
70 if (!attrValue
|| attrValue
->Type() != nsAttrValue::eDoubleValue
||
71 attrValue
->GetDoubleValue() < 0.0) {
75 return std::min(attrValue
->GetDoubleValue(), Max());
79 HTMLProgressElement::Max() const
81 const nsAttrValue
* attrMax
= mAttrs
.GetAttr(nsGkAtoms::max
);
82 if (!attrMax
|| attrMax
->Type() != nsAttrValue::eDoubleValue
||
83 attrMax
->GetDoubleValue() <= 0.0) {
87 return attrMax
->GetDoubleValue();
91 HTMLProgressElement::Position() const
93 if (IsIndeterminate()) {
94 return kIndeterminatePosition
;
97 return Value() / Max();
101 HTMLProgressElement::IsIndeterminate() const
103 const nsAttrValue
* attrValue
= mAttrs
.GetAttr(nsGkAtoms::value
);
104 return !attrValue
|| attrValue
->Type() != nsAttrValue::eDoubleValue
;
108 HTMLProgressElement::WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
)
110 return HTMLProgressElement_Binding::Wrap(aCx
, this, aGivenProto
);
114 } // namespace mozilla