no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / html / HTMLProgressElement.cpp
blob6ad70c1f39a7b4a5e8a84ac93fe2af5714bafbc2
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/dom/HTMLProgressElement.h"
8 #include "mozilla/dom/HTMLProgressElementBinding.h"
10 NS_IMPL_NS_NEW_HTML_ELEMENT(Progress)
12 namespace mozilla::dom {
14 HTMLProgressElement::HTMLProgressElement(
15 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
16 : nsGenericHTMLElement(std::move(aNodeInfo)) {
17 // We start out indeterminate
18 AddStatesSilently(ElementState::INDETERMINATE);
21 HTMLProgressElement::~HTMLProgressElement() = default;
23 NS_IMPL_ELEMENT_CLONE(HTMLProgressElement)
25 bool HTMLProgressElement::ParseAttribute(int32_t aNamespaceID,
26 nsAtom* aAttribute,
27 const nsAString& aValue,
28 nsIPrincipal* aMaybeScriptedPrincipal,
29 nsAttrValue& aResult) {
30 if (aNamespaceID == kNameSpaceID_None) {
31 if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) {
32 return aResult.ParseDoubleValue(aValue);
36 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
37 aMaybeScriptedPrincipal, aResult);
40 void HTMLProgressElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
41 const nsAttrValue* aValue,
42 const nsAttrValue* aOldValue,
43 nsIPrincipal* aSubjectPrincipal,
44 bool aNotify) {
45 if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::value) {
46 const bool indeterminate =
47 !aValue || aValue->Type() != nsAttrValue::eDoubleValue;
48 SetStates(ElementState::INDETERMINATE, indeterminate, aNotify);
50 return nsGenericHTMLElement::AfterSetAttr(
51 aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
54 double HTMLProgressElement::Value() const {
55 const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
56 if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue ||
57 attrValue->GetDoubleValue() < 0.0) {
58 return 0.0;
61 return std::min(attrValue->GetDoubleValue(), Max());
64 double HTMLProgressElement::Max() const {
65 const nsAttrValue* attrMax = mAttrs.GetAttr(nsGkAtoms::max);
66 if (!attrMax || attrMax->Type() != nsAttrValue::eDoubleValue ||
67 attrMax->GetDoubleValue() <= 0.0) {
68 return 1.0;
71 return attrMax->GetDoubleValue();
74 double HTMLProgressElement::Position() const {
75 if (State().HasState(ElementState::INDETERMINATE)) {
76 return -1.0;
79 return Value() / Max();
82 JSObject* HTMLProgressElement::WrapNode(JSContext* aCx,
83 JS::Handle<JSObject*> aGivenProto) {
84 return HTMLProgressElement_Binding::Wrap(aCx, this, aGivenProto);
87 } // namespace mozilla::dom