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/. */ 6 7 #ifndef mozilla_dom_HTMLMeterElement_h 8 #define mozilla_dom_HTMLMeterElement_h 9 10 #include "mozilla/Attributes.h" 11 #include "nsGenericHTMLElement.h" 12 #include "nsAttrValue.h" 13 #include "nsAttrValueInlines.h" 14 #include "nsAlgorithm.h" 15 #include <algorithm> 16 17 namespace mozilla { 18 namespace dom { 19 20 class HTMLMeterElement final : public nsGenericHTMLElement { 21 public: 22 explicit HTMLMeterElement( 23 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 24 25 virtual EventStates IntrinsicState() const override; 26 27 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 28 29 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 30 const nsAString& aValue, 31 nsIPrincipal* aMaybeScriptedPrincipal, 32 nsAttrValue& aResult) override; 33 34 // WebIDL 35 36 /* @return the value */ 37 double Value() const; SetValue(double aValue,ErrorResult & aRv)38 void SetValue(double aValue, ErrorResult& aRv) { 39 SetDoubleAttr(nsGkAtoms::value, aValue, aRv); 40 } 41 42 /* @return the minimum value */ 43 double Min() const; SetMin(double aValue,ErrorResult & aRv)44 void SetMin(double aValue, ErrorResult& aRv) { 45 SetDoubleAttr(nsGkAtoms::min, aValue, aRv); 46 } 47 48 /* @return the maximum value */ 49 double Max() const; SetMax(double aValue,ErrorResult & aRv)50 void SetMax(double aValue, ErrorResult& aRv) { 51 SetDoubleAttr(nsGkAtoms::max, aValue, aRv); 52 } 53 54 /* @return the low value */ 55 double Low() const; SetLow(double aValue,ErrorResult & aRv)56 void SetLow(double aValue, ErrorResult& aRv) { 57 SetDoubleAttr(nsGkAtoms::low, aValue, aRv); 58 } 59 60 /* @return the high value */ 61 double High() const; SetHigh(double aValue,ErrorResult & aRv)62 void SetHigh(double aValue, ErrorResult& aRv) { 63 SetDoubleAttr(nsGkAtoms::high, aValue, aRv); 64 } 65 66 /* @return the optimum value */ 67 double Optimum() const; SetOptimum(double aValue,ErrorResult & aRv)68 void SetOptimum(double aValue, ErrorResult& aRv) { 69 SetDoubleAttr(nsGkAtoms::optimum, aValue, aRv); 70 } 71 72 protected: 73 virtual ~HTMLMeterElement(); 74 75 virtual JSObject* WrapNode(JSContext* aCx, 76 JS::Handle<JSObject*> aGivenProto) override; 77 78 private: 79 static const double kDefaultValue; 80 static const double kDefaultMin; 81 static const double kDefaultMax; 82 83 /** 84 * Returns the optimum state of the element. 85 * NS_EVENT_STATE_OPTIMUM if the actual value is in the optimum region. 86 * NS_EVENT_STATE_SUB_OPTIMUM if the actual value is in the sub-optimal 87 * region. 88 * NS_EVENT_STATE_SUB_SUB_OPTIMUM if the actual value is in the 89 * sub-sub-optimal region. 90 * 91 * @return the optimum state of the element. 92 */ 93 EventStates GetOptimumState() const; 94 }; 95 96 } // namespace dom 97 } // namespace mozilla 98 99 #endif // mozilla_dom_HTMLMeterElement_h 100