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

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

Issue 1747763002: Remove OSX-specific <meter> rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "core/html/HTMLMeterElement.h" 21 #include "core/html/HTMLMeterElement.h"
22 22
23 #include "bindings/core/v8/ExceptionMessages.h" 23 #include "bindings/core/v8/ExceptionMessages.h"
24 #include "bindings/core/v8/ExceptionState.h" 24 #include "bindings/core/v8/ExceptionState.h"
25 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 25 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
26 #include "core/HTMLNames.h" 26 #include "core/HTMLNames.h"
27 #include "core/dom/ExceptionCode.h" 27 #include "core/dom/ExceptionCode.h"
28 #include "core/dom/shadow/ShadowRoot.h" 28 #include "core/dom/shadow/ShadowRoot.h"
29 #include "core/frame/UseCounter.h" 29 #include "core/frame/UseCounter.h"
30 #include "core/html/HTMLDivElement.h"
30 #include "core/html/parser/HTMLParserIdioms.h" 31 #include "core/html/parser/HTMLParserIdioms.h"
31 #include "core/html/shadow/MeterShadowElement.h" 32 #include "core/layout/LayoutObject.h"
32 #include "core/layout/LayoutMeter.h" 33 #include "core/style/ComputedStyle.h"
33 #include "core/layout/LayoutTheme.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 using namespace HTMLNames; 37 using namespace HTMLNames;
38 38
39 HTMLMeterElement::HTMLMeterElement(Document& document) 39 HTMLMeterElement::HTMLMeterElement(Document& document)
40 : LabelableElement(meterTag, document) 40 : LabelableElement(meterTag, document)
41 { 41 {
42 UseCounter::count(document, UseCounter::MeterElement); 42 UseCounter::count(document, UseCounter::MeterElement);
43 } 43 }
44 44
45 HTMLMeterElement::~HTMLMeterElement() 45 HTMLMeterElement::~HTMLMeterElement()
46 { 46 {
47 } 47 }
48 48
49 PassRefPtrWillBeRawPtr<HTMLMeterElement> HTMLMeterElement::create(Document& docu ment) 49 PassRefPtrWillBeRawPtr<HTMLMeterElement> HTMLMeterElement::create(Document& docu ment)
50 { 50 {
51 RefPtrWillBeRawPtr<HTMLMeterElement> meter = adoptRefWillBeNoop(new HTMLMete rElement(document)); 51 RefPtrWillBeRawPtr<HTMLMeterElement> meter = adoptRefWillBeNoop(new HTMLMete rElement(document));
52 meter->ensureUserAgentShadowRoot(); 52 meter->ensureUserAgentShadowRoot();
53 return meter.release(); 53 return meter.release();
54 } 54 }
55 55
56 LayoutObject* HTMLMeterElement::createLayoutObject(const ComputedStyle& style) 56 LayoutObject* HTMLMeterElement::createLayoutObject(const ComputedStyle& style)
57 { 57 {
58 switch (style.appearance()) { 58 switch (style.appearance()) {
59 case ContinuousCapacityLevelIndicatorPart:
60 UseCounter::count(document(), UseCounter::MeterElementWithContinuousCapa cityAppearance);
61 break;
62 case DiscreteCapacityLevelIndicatorPart:
63 UseCounter::count(document(), UseCounter::MeterElementWithDiscreteCapaci tyAppearance);
64 break;
65 case MeterPart: 59 case MeterPart:
66 UseCounter::count(document(), UseCounter::MeterElementWithMeterAppearanc e); 60 UseCounter::count(document(), UseCounter::MeterElementWithMeterAppearanc e);
67 break; 61 break;
68 case NoControlPart: 62 case NoControlPart:
69 UseCounter::count(document(), UseCounter::MeterElementWithNoneAppearance ); 63 UseCounter::count(document(), UseCounter::MeterElementWithNoneAppearance );
70 break; 64 break;
71 case RatingLevelIndicatorPart:
72 UseCounter::count(document(), UseCounter::MeterElementWithRatingAppearan ce);
73 break;
74 case RelevancyLevelIndicatorPart:
75 UseCounter::count(document(), UseCounter::MeterElementWithRelevancyAppea rance);
76 break;
77 default: 65 default:
78 break; 66 break;
79 } 67 }
80 if (openShadowRoot() || !LayoutTheme::theme().supportsMeter(style.appearance ())) 68 return LayoutObject::createObject(this, style);
81 return LayoutObject::createObject(this, style);
82 return new LayoutMeter(this);
83 } 69 }
84 70
85 void HTMLMeterElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& oldValue, const AtomicString& value) 71 void HTMLMeterElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& oldValue, const AtomicString& value)
86 { 72 {
87 if (name == valueAttr || name == minAttr || name == maxAttr || name == lowAt tr || name == highAttr || name == optimumAttr) 73 if (name == valueAttr || name == minAttr || name == maxAttr || name == lowAt tr || name == highAttr || name == optimumAttr)
88 didElementStateChange(); 74 didElementStateChange();
89 else 75 else
90 LabelableElement::parseAttribute(name, oldValue, value); 76 LabelableElement::parseAttribute(name, oldValue, value);
91 } 77 }
92 78
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 double max = this->max(); 179 double max = this->max();
194 double value = this->value(); 180 double value = this->value();
195 181
196 if (max <= min) 182 if (max <= min)
197 return 0; 183 return 0;
198 return (value - min) / (max - min); 184 return (value - min) / (max - min);
199 } 185 }
200 186
201 void HTMLMeterElement::didElementStateChange() 187 void HTMLMeterElement::didElementStateChange()
202 { 188 {
203 m_value->setWidthPercentage(valueRatio()*100); 189 updateValueAppearance(valueRatio() * 100);
204 m_value->updatePseudo();
205 if (LayoutMeter* layoutMeter = this->layoutMeter())
206 layoutMeter->updateFromElement();
207 }
208
209 LayoutMeter* HTMLMeterElement::layoutMeter() const
210 {
211 if (layoutObject() && layoutObject()->isMeter())
212 return toLayoutMeter(layoutObject());
213
214 LayoutObject* layoutObject = userAgentShadowRoot()->firstChild()->layoutObje ct();
215 return toLayoutMeter(layoutObject);
216 } 190 }
217 191
218 void HTMLMeterElement::didAddUserAgentShadowRoot(ShadowRoot& root) 192 void HTMLMeterElement::didAddUserAgentShadowRoot(ShadowRoot& root)
219 { 193 {
220 ASSERT(!m_value); 194 ASSERT(!m_value);
221 195
222 RefPtrWillBeRawPtr<MeterInnerElement> inner = MeterInnerElement::create(docu ment()); 196 RefPtrWillBeRawPtr<HTMLDivElement> inner = HTMLDivElement::create(document() );
197 inner->setShadowPseudoId(AtomicString("-webkit-meter-inner-element", AtomicS tring::ConstructFromLiteral));
223 root.appendChild(inner); 198 root.appendChild(inner);
224 199
225 RefPtrWillBeRawPtr<MeterBarElement> bar = MeterBarElement::create(document() ); 200 RefPtrWillBeRawPtr<HTMLDivElement> bar = HTMLDivElement::create(document());
226 m_value = MeterValueElement::create(document()); 201 bar->setShadowPseudoId(AtomicString("-webkit-meter-bar", AtomicString::Const ructFromLiteral));
227 m_value->setWidthPercentage(0); 202
228 m_value->updatePseudo(); 203 m_value = HTMLDivElement::create(document());
204 updateValueAppearance(0);
229 bar->appendChild(m_value); 205 bar->appendChild(m_value);
230 206
231 inner->appendChild(bar); 207 inner->appendChild(bar);
232 } 208 }
233 209
234 void HTMLMeterElement::willAddFirstAuthorShadowRoot() 210 void HTMLMeterElement::willAddFirstAuthorShadowRoot()
235 { 211 {
236 ASSERT(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled()); 212 ASSERT(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled());
237 lazyReattachIfAttached(); 213 lazyReattachIfAttached();
238 } 214 }
239 215
216 void HTMLMeterElement::updateValueAppearance(double percentage)
217 {
218 DEFINE_STATIC_LOCAL(AtomicString, optimumPseudoId, ("-webkit-meter-optimum-v alue", AtomicString::ConstructFromLiteral));
219 DEFINE_STATIC_LOCAL(AtomicString, suboptimumPseudoId, ("-webkit-meter-subopt imum-value", AtomicString::ConstructFromLiteral));
220 DEFINE_STATIC_LOCAL(AtomicString, evenLessGoodPseudoId, ("-webkit-meter-even -less-good-value", AtomicString::ConstructFromLiteral));
221
222 m_value->setInlineStyleProperty(CSSPropertyWidth, percentage, CSSPrimitiveVa lue::UnitType::Percentage);
223 switch (gaugeRegion()) {
224 case GaugeRegionOptimum:
225 m_value->setShadowPseudoId(optimumPseudoId);
226 break;
227 case GaugeRegionSuboptimal:
228 m_value->setShadowPseudoId(suboptimumPseudoId);
229 break;
230 case GaugeRegionEvenLessGood:
231 m_value->setShadowPseudoId(evenLessGoodPseudoId);
232 break;
233 }
234 }
235
240 DEFINE_TRACE(HTMLMeterElement) 236 DEFINE_TRACE(HTMLMeterElement)
241 { 237 {
242 visitor->trace(m_value); 238 visitor->trace(m_value);
243 LabelableElement::trace(visitor); 239 LabelableElement::trace(visitor);
244 } 240 }
245 241
246 } // namespace blink 242 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698