Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: Source/core/html/HTMLMeterElement.cpp

Issue 131483008: Correctly report TypeError for HTML{Meter,Progress}Element setters. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 double HTMLMeterElement::min() const 73 double HTMLMeterElement::min() const
74 { 74 {
75 return getFloatingPointAttribute(minAttr, 0); 75 return getFloatingPointAttribute(minAttr, 0);
76 } 76 }
77 77
78 void HTMLMeterElement::setMin(double min, ExceptionState& exceptionState) 78 void HTMLMeterElement::setMin(double min, ExceptionState& exceptionState)
79 { 79 {
80 if (!std::isfinite(min)) { 80 if (!std::isfinite(min)) {
81 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(min)); 81 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(min));
82 return; 82 return;
83 } 83 }
84 setFloatingPointAttribute(minAttr, min); 84 setFloatingPointAttribute(minAttr, min);
85 } 85 }
86 86
87 double HTMLMeterElement::max() const 87 double HTMLMeterElement::max() const
88 { 88 {
89 return std::max(getFloatingPointAttribute(maxAttr, std::max(1.0, min())), mi n()); 89 return std::max(getFloatingPointAttribute(maxAttr, std::max(1.0, min())), mi n());
90 } 90 }
91 91
92 void HTMLMeterElement::setMax(double max, ExceptionState& exceptionState) 92 void HTMLMeterElement::setMax(double max, ExceptionState& exceptionState)
93 { 93 {
94 if (!std::isfinite(max)) { 94 if (!std::isfinite(max)) {
95 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(max)); 95 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(max));
96 return; 96 return;
97 } 97 }
98 setFloatingPointAttribute(maxAttr, max); 98 setFloatingPointAttribute(maxAttr, max);
99 } 99 }
100 100
101 double HTMLMeterElement::value() const 101 double HTMLMeterElement::value() const
102 { 102 {
103 double value = getFloatingPointAttribute(valueAttr, 0); 103 double value = getFloatingPointAttribute(valueAttr, 0);
104 return std::min(std::max(value, min()), max()); 104 return std::min(std::max(value, min()), max());
105 } 105 }
106 106
107 void HTMLMeterElement::setValue(double value, ExceptionState& exceptionState) 107 void HTMLMeterElement::setValue(double value, ExceptionState& exceptionState)
108 { 108 {
109 if (!std::isfinite(value)) { 109 if (!std::isfinite(value)) {
110 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(value)); 110 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(value) );
111 return; 111 return;
112 } 112 }
113 setFloatingPointAttribute(valueAttr, value); 113 setFloatingPointAttribute(valueAttr, value);
114 } 114 }
115 115
116 double HTMLMeterElement::low() const 116 double HTMLMeterElement::low() const
117 { 117 {
118 double low = getFloatingPointAttribute(lowAttr, min()); 118 double low = getFloatingPointAttribute(lowAttr, min());
119 return std::min(std::max(low, min()), max()); 119 return std::min(std::max(low, min()), max());
120 } 120 }
121 121
122 void HTMLMeterElement::setLow(double low, ExceptionState& exceptionState) 122 void HTMLMeterElement::setLow(double low, ExceptionState& exceptionState)
123 { 123 {
124 if (!std::isfinite(low)) { 124 if (!std::isfinite(low)) {
125 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(low)); 125 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(low));
126 return; 126 return;
127 } 127 }
128 setFloatingPointAttribute(lowAttr, low); 128 setFloatingPointAttribute(lowAttr, low);
129 } 129 }
130 130
131 double HTMLMeterElement::high() const 131 double HTMLMeterElement::high() const
132 { 132 {
133 double high = getFloatingPointAttribute(highAttr, max()); 133 double high = getFloatingPointAttribute(highAttr, max());
134 return std::min(std::max(high, low()), max()); 134 return std::min(std::max(high, low()), max());
135 } 135 }
136 136
137 void HTMLMeterElement::setHigh(double high, ExceptionState& exceptionState) 137 void HTMLMeterElement::setHigh(double high, ExceptionState& exceptionState)
138 { 138 {
139 if (!std::isfinite(high)) { 139 if (!std::isfinite(high)) {
140 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(high)); 140 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(high)) ;
141 return; 141 return;
142 } 142 }
143 setFloatingPointAttribute(highAttr, high); 143 setFloatingPointAttribute(highAttr, high);
144 } 144 }
145 145
146 double HTMLMeterElement::optimum() const 146 double HTMLMeterElement::optimum() const
147 { 147 {
148 double optimum = getFloatingPointAttribute(optimumAttr, (max() + min()) / 2) ; 148 double optimum = getFloatingPointAttribute(optimumAttr, (max() + min()) / 2) ;
149 return std::min(std::max(optimum, min()), max()); 149 return std::min(std::max(optimum, min()), max());
150 } 150 }
151 151
152 void HTMLMeterElement::setOptimum(double optimum, ExceptionState& exceptionState ) 152 void HTMLMeterElement::setOptimum(double optimum, ExceptionState& exceptionState )
153 { 153 {
154 if (!std::isfinite(optimum)) { 154 if (!std::isfinite(optimum)) {
155 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(optimum)); 155 exceptionState.throwTypeError(ExceptionMessages::notAFiniteNumber(optimu m));
156 return; 156 return;
157 } 157 }
158 setFloatingPointAttribute(optimumAttr, optimum); 158 setFloatingPointAttribute(optimumAttr, optimum);
159 } 159 }
160 160
161 HTMLMeterElement::GaugeRegion HTMLMeterElement::gaugeRegion() const 161 HTMLMeterElement::GaugeRegion HTMLMeterElement::gaugeRegion() const
162 { 162 {
163 double lowValue = low(); 163 double lowValue = low();
164 double highValue = high(); 164 double highValue = high();
165 double theValue = value(); 165 double theValue = value();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 RefPtr<MeterBarElement> bar = MeterBarElement::create(document()); 229 RefPtr<MeterBarElement> bar = MeterBarElement::create(document());
230 m_value = MeterValueElement::create(document()); 230 m_value = MeterValueElement::create(document());
231 m_value->setWidthPercentage(0); 231 m_value->setWidthPercentage(0);
232 m_value->updatePseudo(); 232 m_value->updatePseudo();
233 bar->appendChild(m_value); 233 bar->appendChild(m_value);
234 234
235 inner->appendChild(bar); 235 inner->appendChild(bar);
236 } 236 }
237 237
238 } // namespace 238 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698