2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-02-11 22:56:31 +04:00
|
|
|
/* 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-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-02-11 22:56:31 +04:00
|
|
|
#include "mozilla/dom/HTMLProgressElement.h"
|
2013-02-11 22:56:31 +04:00
|
|
|
#include "mozilla/dom/HTMLProgressElementBinding.h"
|
2013-02-11 22:56:31 +04: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-20 06:01:40 +04:00
|
|
|
HTMLProgressElement::HTMLProgressElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-11 22:56:31 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
// We start out indeterminate
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_INDETERMINATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLProgressElement::~HTMLProgressElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLProgressElement)
|
|
|
|
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-11 22:56:31 +04:00
|
|
|
HTMLProgressElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2013-02-11 22:56:31 +04: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 22:56:31 +04:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Value() const
|
2013-02-11 22:56:31 +04:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
|
|
|
|
if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue ||
|
|
|
|
attrValue->GetDoubleValue() < 0.0) {
|
2013-02-11 22:56:31 +04:00
|
|
|
return kDefaultValue;
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
return std::min(attrValue->GetDoubleValue(), Max());
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Max() const
|
2013-02-11 22:56:31 +04:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max);
|
2013-02-11 22:56:31 +04:00
|
|
|
if (!attrMax || attrMax->Type() != nsAttrValue::eDoubleValue ||
|
|
|
|
attrMax->GetDoubleValue() <= 0.0) {
|
|
|
|
return kDefaultMax;
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
return attrMax->GetDoubleValue();
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
double
|
|
|
|
HTMLProgressElement::Position() const
|
2013-02-11 22:56:31 +04:00
|
|
|
{
|
|
|
|
if (IsIndeterminate()) {
|
2013-02-11 22:56:31 +04:00
|
|
|
return kIndeterminatePosition;
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
return Value() / Max();
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLProgressElement::IsIndeterminate() const
|
|
|
|
{
|
|
|
|
const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
|
|
|
|
return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue;
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
HTMLProgressElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-11 22:56:31 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return HTMLProgressElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-11 22:56:31 +04:00
|
|
|
}
|
|
|
|
|
2013-02-11 22:56:31 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|