2013-02-11 10:56:31 -08:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-02-11 10:56:31 -08:00
|
|
|
#include "mozilla/dom/HTMLProgressElement.h"
|
2013-02-11 10:56:31 -08:00
|
|
|
#include "mozilla/dom/HTMLProgressElementBinding.h"
|
2013-02-11 10:56:31 -08:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Progress)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
const double HTMLProgressElement::kIndeterminatePosition = -1.0;
|
|
|
|
const double HTMLProgressElement::kDefaultValue = 0.0;
|
|
|
|
const double HTMLProgressElement::kDefaultMax = 1.0;
|
|
|
|
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLProgressElement::HTMLProgressElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-11 10:56:31 -08:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
// We start out indeterminate
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_INDETERMINATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLProgressElement::~HTMLProgressElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLProgressElement)
|
|
|
|
|
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates
|
2013-02-11 10:56:31 -08:00
|
|
|
HTMLProgressElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2013-02-11 10:56:31 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Value() const
|
2013-02-11 10:56:31 -08:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
|
|
|
|
if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue ||
|
|
|
|
attrValue->GetDoubleValue() < 0.0) {
|
2013-02-11 10:56:31 -08:00
|
|
|
return kDefaultValue;
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
return std::min(attrValue->GetDoubleValue(), Max());
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Max() const
|
2013-02-11 10:56:31 -08:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max);
|
2013-02-11 10:56:31 -08:00
|
|
|
if (!attrMax || attrMax->Type() != nsAttrValue::eDoubleValue ||
|
|
|
|
attrMax->GetDoubleValue() <= 0.0) {
|
|
|
|
return kDefaultMax;
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
return attrMax->GetDoubleValue();
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Position() const
|
2013-02-11 10:56:31 -08:00
|
|
|
{
|
|
|
|
if (IsIndeterminate()) {
|
2013-02-11 10:56:31 -08:00
|
|
|
return kIndeterminatePosition;
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
return Value() / Max();
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLProgressElement::IsIndeterminate() const
|
|
|
|
{
|
|
|
|
const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
|
|
|
|
return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue;
|
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLProgressElement::WrapNode(JSContext* aCx)
|
2013-02-11 10:56:31 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLProgressElementBinding::Wrap(aCx, this);
|
2013-02-11 10:56:31 -08:00
|
|
|
}
|
|
|
|
|
2013-02-11 10:56:31 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|