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: */
|
2012-06-11 03:44:50 +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/. */
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
#include "HTMLMeterElement.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-02-07 19:00:39 +04:00
|
|
|
#include "mozilla/dom/HTMLMeterElementBinding.h"
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Meter)
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
const double HTMLMeterElement::kDefaultValue = 0.0;
|
|
|
|
const double HTMLMeterElement::kDefaultMin = 0.0;
|
|
|
|
const double HTMLMeterElement::kDefaultMax = 1.0;
|
2012-05-16 15:18:33 +04:00
|
|
|
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLMeterElement::HTMLMeterElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2012-06-11 03:44:50 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
HTMLMeterElement::~HTMLMeterElement()
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLMeterElement)
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-07 18:59:25 +04:00
|
|
|
HTMLMeterElement::IntrinsicState() const
|
2012-05-16 15:23:31 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2012-05-16 15:23:31 +04:00
|
|
|
|
|
|
|
state |= GetOptimumState();
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-05-16 15:18:33 +04:00
|
|
|
bool
|
2017-11-02 06:35:52 +03:00
|
|
|
HTMLMeterElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
nsAttrValue& aResult)
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max ||
|
|
|
|
aAttribute == nsGkAtoms::min || aAttribute == nsGkAtoms::low ||
|
|
|
|
aAttribute == nsGkAtoms::high || aAttribute == nsGkAtoms::optimum) {
|
|
|
|
return aResult.ParseDoubleValue(aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute,
|
2017-11-02 06:35:52 +03:00
|
|
|
aValue,
|
|
|
|
aMaybeScriptedPrincipal,
|
|
|
|
aResult);
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
/*
|
|
|
|
* Value getters :
|
|
|
|
* const getters used by XPCOM methods and by IntrinsicState
|
|
|
|
*/
|
|
|
|
|
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::Min() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the attribute min is defined, the minimum is this value.
|
|
|
|
* Otherwise, the minimum is the default value.
|
|
|
|
*/
|
|
|
|
const nsAttrValue* attrMin = mAttrsAndChildren.GetAttr(nsGkAtoms::min);
|
|
|
|
if (attrMin && attrMin->Type() == nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
return attrMin->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
2012-05-16 15:21:53 +04:00
|
|
|
return kDefaultMin;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::Max() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the attribute max is defined, the maximum is this value.
|
|
|
|
* Otherwise, the maximum is the default value.
|
|
|
|
* If the maximum value is less than the minimum value,
|
|
|
|
* the maximum value is the same as the minimum value.
|
|
|
|
*/
|
2012-05-16 15:21:53 +04:00
|
|
|
double max;
|
|
|
|
|
2012-05-16 15:18:33 +04:00
|
|
|
const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max);
|
|
|
|
if (attrMax && attrMax->Type() == nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
max = attrMax->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
} else {
|
2012-05-16 15:21:53 +04:00
|
|
|
max = kDefaultMax;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
return std::max(max, Min());
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::Value() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the attribute value is defined, the actual value is this value.
|
|
|
|
* Otherwise, the actual value is the default value.
|
|
|
|
* If the actual value is less than the minimum value,
|
|
|
|
* the actual value is the same as the minimum value.
|
|
|
|
* If the actual value is greater than the maximum value,
|
|
|
|
* the actual value is the same as the maximum value.
|
|
|
|
*/
|
2012-05-16 15:21:53 +04:00
|
|
|
double value;
|
|
|
|
|
2012-05-16 15:18:33 +04:00
|
|
|
const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
|
|
|
|
if (attrValue && attrValue->Type() == nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
value = attrValue->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
} else {
|
2012-05-16 15:21:53 +04:00
|
|
|
value = kDefaultValue;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double min = Min();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
if (value <= min) {
|
|
|
|
return min;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
return std::min(value, Max());
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::Low() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the low value is defined, the low value is this value.
|
|
|
|
* Otherwise, the low value is the minimum value.
|
|
|
|
* If the low value is less than the minimum value,
|
|
|
|
* the low value is the same as the minimum value.
|
|
|
|
* If the low value is greater than the maximum value,
|
|
|
|
* the low value is the same as the maximum value.
|
|
|
|
*/
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double min = Min();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
|
|
|
const nsAttrValue* attrLow = mAttrsAndChildren.GetAttr(nsGkAtoms::low);
|
|
|
|
if (!attrLow || attrLow->Type() != nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
return min;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double low = attrLow->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
if (low <= min) {
|
|
|
|
return min;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
return std::min(low, Max());
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::High() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the high value is defined, the high value is this value.
|
|
|
|
* Otherwise, the high value is the maximum value.
|
|
|
|
* If the high value is less than the low value,
|
|
|
|
* the high value is the same as the low value.
|
|
|
|
* If the high value is greater than the maximum value,
|
|
|
|
* the high value is the same as the maximum value.
|
|
|
|
*/
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double max = Max();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
|
|
|
const nsAttrValue* attrHigh = mAttrsAndChildren.GetAttr(nsGkAtoms::high);
|
|
|
|
if (!attrHigh || attrHigh->Type() != nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
return max;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double high = attrHigh->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
if (high >= max) {
|
|
|
|
return max;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
return std::max(high, Low());
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double
|
2013-02-07 19:00:39 +04:00
|
|
|
HTMLMeterElement::Optimum() const
|
2012-05-16 15:18:33 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If the optimum value is defined, the optimum value is this value.
|
|
|
|
* Otherwise, the optimum value is the midpoint between
|
|
|
|
* the minimum value and the maximum value :
|
|
|
|
* min + (max - min)/2 = (min + max)/2
|
|
|
|
* If the optimum value is less than the minimum value,
|
|
|
|
* the optimum value is the same as the minimum value.
|
|
|
|
* If the optimum value is greater than the maximum value,
|
|
|
|
* the optimum value is the same as the maximum value.
|
|
|
|
*/
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double max = Max();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double min = Min();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
|
|
|
const nsAttrValue* attrOptimum =
|
|
|
|
mAttrsAndChildren.GetAttr(nsGkAtoms::optimum);
|
|
|
|
if (!attrOptimum || attrOptimum->Type() != nsAttrValue::eDoubleValue) {
|
2012-05-16 15:21:53 +04:00
|
|
|
return (min + max) / 2.0;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
double optimum = attrOptimum->GetDoubleValue();
|
2012-05-16 15:18:33 +04:00
|
|
|
|
2012-05-16 15:21:53 +04:00
|
|
|
if (optimum <= min) {
|
|
|
|
return min;
|
2012-05-16 15:18:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
return std::min(optimum, max);
|
2012-05-16 15:21:53 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2013-02-07 18:59:25 +04:00
|
|
|
HTMLMeterElement::GetOptimumState() const
|
2012-05-16 15:23:31 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the optimum value is in [minimum, low[,
|
|
|
|
* return if the value is in optimal, suboptimal or sub-suboptimal region
|
|
|
|
*
|
|
|
|
* If the optimum value is in [low, high],
|
|
|
|
* return if the value is in optimal or suboptimal region
|
|
|
|
*
|
|
|
|
* If the optimum value is in ]high, maximum],
|
|
|
|
* return if the value is in optimal, suboptimal or sub-suboptimal region
|
|
|
|
*/
|
2013-02-07 19:00:39 +04:00
|
|
|
double value = Value();
|
|
|
|
double low = Low();
|
|
|
|
double high = High();
|
|
|
|
double optimum = Optimum();
|
2012-05-16 15:23:31 +04:00
|
|
|
|
|
|
|
if (optimum < low) {
|
|
|
|
if (value < low) {
|
|
|
|
return NS_EVENT_STATE_OPTIMUM;
|
|
|
|
}
|
|
|
|
if (value <= high) {
|
|
|
|
return NS_EVENT_STATE_SUB_OPTIMUM;
|
|
|
|
}
|
|
|
|
return NS_EVENT_STATE_SUB_SUB_OPTIMUM;
|
|
|
|
}
|
|
|
|
if (optimum > high) {
|
|
|
|
if (value > high) {
|
|
|
|
return NS_EVENT_STATE_OPTIMUM;
|
|
|
|
}
|
|
|
|
if (value >= low) {
|
|
|
|
return NS_EVENT_STATE_SUB_OPTIMUM;
|
|
|
|
}
|
|
|
|
return NS_EVENT_STATE_SUB_SUB_OPTIMUM;
|
|
|
|
}
|
|
|
|
// optimum in [low, high]
|
|
|
|
if (value >= low && value <= high) {
|
|
|
|
return NS_EVENT_STATE_OPTIMUM;
|
|
|
|
}
|
|
|
|
return NS_EVENT_STATE_SUB_OPTIMUM;
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +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
|
|
|
HTMLMeterElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-07 19:00:39 +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 HTMLMeterElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 19:00:39 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|