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
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLMeterElement::HTMLMeterElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(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
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
EventStates HTMLMeterElement::IntrinsicState() const {
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2012-05-16 15:23:31 +04:00
|
|
|
|
|
|
|
state |= GetOptimumState();
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:35:52 +03:00
|
|
|
bool 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, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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.
|
|
|
|
*/
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrMin = mAttrs.GetAttr(nsGkAtoms::min);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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;
|
|
|
|
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrMax = mAttrs.GetAttr(nsGkAtoms::max);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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;
|
|
|
|
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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
|
|
|
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrLow = mAttrs.GetAttr(nsGkAtoms::low);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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
|
|
|
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrHigh = mAttrs.GetAttr(nsGkAtoms::high);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 19:00:39 +04:00
|
|
|
double 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
|
|
|
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* attrOptimum = mAttrs.GetAttr(nsGkAtoms::optimum);
|
2012-05-16 15:18:33 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
EventStates 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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
JSObject* HTMLMeterElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLMeterElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 19:00:39 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 18:59:25 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|