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

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

Issue 84713002: Add number() static methods to AtomicString class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Pass NaN as default argument Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLInputElement.cpp ('k') | Source/core/html/HTMLOListElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 void HTMLMeterElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 65 void HTMLMeterElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
66 { 66 {
67 if (name == valueAttr || name == minAttr || name == maxAttr || name == lowAt tr || name == highAttr || name == optimumAttr) 67 if (name == valueAttr || name == minAttr || name == maxAttr || name == lowAt tr || name == highAttr || name == optimumAttr)
68 didElementStateChange(); 68 didElementStateChange();
69 else 69 else
70 LabelableElement::parseAttribute(name, value); 70 LabelableElement::parseAttribute(name, value);
71 } 71 }
72 72
73 double HTMLMeterElement::min() const 73 double HTMLMeterElement::min() const
74 { 74 {
75 return parseToDoubleForNumberType(getAttribute(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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 81 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
82 return; 82 return;
83 } 83 }
84 setAttribute(minAttr, String::number(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(parseToDoubleForNumberType(getAttribute(maxAttr), std::max(1 .0, min())), min()); 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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 95 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
96 return; 96 return;
97 } 97 }
98 setAttribute(maxAttr, String::number(max)); 98 setFloatingPointAttribute(maxAttr, max);
99 } 99 }
100 100
101 double HTMLMeterElement::value() const 101 double HTMLMeterElement::value() const
102 { 102 {
103 double value = parseToDoubleForNumberType(getAttribute(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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 110 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
111 return; 111 return;
112 } 112 }
113 setAttribute(valueAttr, String::number(value)); 113 setFloatingPointAttribute(valueAttr, value);
114 } 114 }
115 115
116 double HTMLMeterElement::low() const 116 double HTMLMeterElement::low() const
117 { 117 {
118 double low = parseToDoubleForNumberType(getAttribute(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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 125 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
126 return; 126 return;
127 } 127 }
128 setAttribute(lowAttr, String::number(low)); 128 setFloatingPointAttribute(lowAttr, low);
129 } 129 }
130 130
131 double HTMLMeterElement::high() const 131 double HTMLMeterElement::high() const
132 { 132 {
133 double high = parseToDoubleForNumberType(getAttribute(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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 140 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
141 return; 141 return;
142 } 142 }
143 setAttribute(highAttr, String::number(high)); 143 setFloatingPointAttribute(highAttr, high);
144 } 144 }
145 145
146 double HTMLMeterElement::optimum() const 146 double HTMLMeterElement::optimum() const
147 { 147 {
148 double optimum = parseToDoubleForNumberType(getAttribute(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.throwUninformativeAndGenericDOMException(NotSupportedErro r); 155 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
156 return; 156 return;
157 } 157 }
158 setAttribute(optimumAttr, String::number(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();
166 double optimumValue = optimum(); 166 double optimumValue = optimum();
167 167
168 if (optimumValue < lowValue) { 168 if (optimumValue < lowValue) {
(...skipping 60 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
« no previous file with comments | « Source/core/html/HTMLInputElement.cpp ('k') | Source/core/html/HTMLOListElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698