Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/HTMLProgressElement.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "mozilla/EventStates.h"
8
#include "mozilla/dom/HTMLProgressElement.h"
9
#include "mozilla/dom/HTMLProgressElementBinding.h"
10
11
NS_IMPL_NS_NEW_HTML_ELEMENT(Progress)
12
13
namespace mozilla {
14
namespace dom {
15
16
const double HTMLProgressElement::kIndeterminatePosition = -1.0;
17
const double HTMLProgressElement::kDefaultValue          =  0.0;
18
const double HTMLProgressElement::kDefaultMax            =  1.0;
19
20
21
HTMLProgressElement::HTMLProgressElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
22
  : nsGenericHTMLElement(std::move(aNodeInfo))
23
0
{
24
0
  // We start out indeterminate
25
0
  AddStatesSilently(NS_EVENT_STATE_INDETERMINATE);
26
0
}
27
28
HTMLProgressElement::~HTMLProgressElement()
29
0
{
30
0
}
31
32
NS_IMPL_ELEMENT_CLONE(HTMLProgressElement)
33
34
35
EventStates
36
HTMLProgressElement::IntrinsicState() const
37
0
{
38
0
  EventStates state = nsGenericHTMLElement::IntrinsicState();
39
0
40
0
  if (IsIndeterminate()) {
41
0
    state |= NS_EVENT_STATE_INDETERMINATE;
42
0
  }
43
0
44
0
  return state;
45
0
}
46
47
bool
48
HTMLProgressElement::ParseAttribute(int32_t aNamespaceID,
49
                                    nsAtom* aAttribute,
50
                                    const nsAString& aValue,
51
                                    nsIPrincipal* aMaybeScriptedPrincipal,
52
                                    nsAttrValue& aResult)
53
0
{
54
0
  if (aNamespaceID == kNameSpaceID_None) {
55
0
    if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) {
56
0
      return aResult.ParseDoubleValue(aValue);
57
0
    }
58
0
  }
59
0
60
0
  return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute,
61
0
                                              aValue,
62
0
                                              aMaybeScriptedPrincipal,
63
0
                                              aResult);
64
0
}
65
66
double
67
HTMLProgressElement::Value() const
68
0
{
69
0
  const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
70
0
  if (!attrValue || attrValue->Type() != nsAttrValue::eDoubleValue ||
71
0
      attrValue->GetDoubleValue() < 0.0) {
72
0
    return kDefaultValue;
73
0
  }
74
0
75
0
  return std::min(attrValue->GetDoubleValue(), Max());
76
0
}
77
78
double
79
HTMLProgressElement::Max() const
80
0
{
81
0
  const nsAttrValue* attrMax = mAttrs.GetAttr(nsGkAtoms::max);
82
0
  if (!attrMax || attrMax->Type() != nsAttrValue::eDoubleValue ||
83
0
      attrMax->GetDoubleValue() <= 0.0) {
84
0
    return kDefaultMax;
85
0
  }
86
0
87
0
  return attrMax->GetDoubleValue();
88
0
}
89
90
double
91
HTMLProgressElement::Position() const
92
0
{
93
0
  if (IsIndeterminate()) {
94
0
    return kIndeterminatePosition;
95
0
  }
96
0
97
0
  return Value() / Max();
98
0
}
99
100
bool
101
HTMLProgressElement::IsIndeterminate() const
102
0
{
103
0
  const nsAttrValue* attrValue = mAttrs.GetAttr(nsGkAtoms::value);
104
0
  return !attrValue || attrValue->Type() != nsAttrValue::eDoubleValue;
105
0
}
106
107
JSObject*
108
HTMLProgressElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
109
0
{
110
0
  return HTMLProgressElement_Binding::Wrap(aCx, this, aGivenProto);
111
0
}
112
113
} // namespace dom
114
} // namespace mozilla