Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / html / HTMLProgressElement.cpp
blob2e30be5953caf2b6dc0a416fc7160d065359dc06
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)
13 namespace mozilla {
14 namespace dom {
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)
35 EventStates
36 HTMLProgressElement::IntrinsicState() const
38 EventStates state = nsGenericHTMLElement::IntrinsicState();
40 if (IsIndeterminate()) {
41 state |= NS_EVENT_STATE_INDETERMINATE;
44 return state;
47 bool
48 HTMLProgressElement::ParseAttribute(int32_t aNamespaceID,
49 nsAtom* aAttribute,
50 const nsAString& aValue,
51 nsIPrincipal* aMaybeScriptedPrincipal,
52 nsAttrValue& aResult)
54 if (aNamespaceID == kNameSpaceID_None) {
55 if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) {
56 return aResult.ParseDoubleValue(aValue);
60 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute,
61 aValue,
62 aMaybeScriptedPrincipal,
63 aResult);
66 double
67 HTMLProgressElement::Value() const
69 const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
70 if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue ||
71 attrValue->GetDoubleValue() < 0.0) {
72 return kDefaultValue;
75 return std::min(attrValue->GetDoubleValue(), Max());
78 double
79 HTMLProgressElement::Max() const
81 const nsAttrValue* attrMax = mAttrs.GetAttr(nsGkAtoms::max);
82 if (!attrMax || attrMax->Type() != nsAttrValue::eDoubleValue ||
83 attrMax->GetDoubleValue() <= 0.0) {
84 return kDefaultMax;
87 return attrMax->GetDoubleValue();
90 double
91 HTMLProgressElement::Position() const
93 if (IsIndeterminate()) {
94 return kIndeterminatePosition;
97 return Value() / Max();
100 bool
101 HTMLProgressElement::IsIndeterminate() const
103 const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
104 return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue;
107 JSObject*
108 HTMLProgressElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
110 return HTMLProgressElement_Binding::Wrap(aCx, this, aGivenProto);
113 } // namespace dom
114 } // namespace mozilla