hyatt@apple.com | 9e09f63 | 2016-10-27 22:05:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "CSSCustomPropertyValue.h" |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 28 | #include "CSSTokenizer.h" |
hyatt@apple.com | 9e09f63 | 2016-10-27 22:05:01 +0000 | [diff] [blame] | 29 | |
commit-queue@webkit.org | 8e2a732 | 2018-10-29 21:48:51 +0000 | [diff] [blame] | 30 | namespace WebCore { |
commit-queue@webkit.org | 43c1161 | 2018-10-23 06:10:59 +0000 | [diff] [blame] | 31 | |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 32 | bool CSSCustomPropertyValue::equals(const CSSCustomPropertyValue& other) const |
| 33 | { |
| 34 | if (m_name != other.m_name || m_value.index() != other.m_value.index()) |
| 35 | return false; |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 36 | return WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>& value) { |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 37 | return value.get() == WTF::get<Ref<CSSVariableReferenceValue>>(other.m_value).get(); |
| 38 | }, [&](const CSSValueID& value) { |
| 39 | return value == WTF::get<CSSValueID>(other.m_value); |
| 40 | }, [&](const Ref<CSSVariableData>& value) { |
| 41 | return value.get() == WTF::get<Ref<CSSVariableData>>(other.m_value).get(); |
| 42 | }, [&](const Length& value) { |
| 43 | return value == WTF::get<Length>(other.m_value); |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 44 | }, [&](const Ref<StyleImage>& value) { |
| 45 | return value.get() == WTF::get<Ref<StyleImage>>(other.m_value).get(); |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 46 | }); |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 47 | } |
| 48 | |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 49 | String CSSCustomPropertyValue::customCSSText() const |
| 50 | { |
| 51 | if (!m_serialized) { |
| 52 | m_serialized = true; |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 53 | |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 54 | WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>& value) { |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 55 | m_stringValue = value->cssText(); |
| 56 | }, [&](const CSSValueID& value) { |
| 57 | m_stringValue = getValueName(value); |
| 58 | }, [&](const Ref<CSSVariableData>& value) { |
| 59 | m_stringValue = value->tokenRange().serialize(); |
| 60 | }, [&](const Length& value) { |
| 61 | m_stringValue = CSSPrimitiveValue::create(value.value(), CSSPrimitiveValue::CSS_PX)->cssText(); |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 62 | }, [&](const Ref<StyleImage>& value) { |
| 63 | m_stringValue = value->cssValue()->cssText(); |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 64 | }); |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 65 | } |
| 66 | return m_stringValue; |
| 67 | } |
| 68 | |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 69 | Vector<CSSParserToken> CSSCustomPropertyValue::tokens() const |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 70 | { |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 71 | Vector<CSSParserToken> result; |
| 72 | |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 73 | WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>&) { |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 74 | ASSERT_NOT_REACHED(); |
| 75 | }, [&](const CSSValueID&) { |
| 76 | // Do nothing |
| 77 | }, [&](const Ref<CSSVariableData>& value) { |
| 78 | result.appendVector(value->tokens()); |
| 79 | }, [&](const Length&) { |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 80 | CSSTokenizer tokenizer(cssText()); |
| 81 | |
| 82 | auto tokenizerRange = tokenizer.tokenRange(); |
| 83 | while (!tokenizerRange.atEnd()) |
| 84 | result.append(tokenizerRange.consume()); |
justin_michaud@apple.com | 724b47a | 2018-12-04 20:25:02 +0000 | [diff] [blame] | 85 | }, [&](const Ref<StyleImage>&) { |
| 86 | CSSTokenizer tokenizer(cssText()); |
| 87 | |
| 88 | auto tokenizerRange = tokenizer.tokenRange(); |
| 89 | while (!tokenizerRange.atEnd()) |
| 90 | result.append(tokenizerRange.consume()); |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 91 | }); |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 92 | |
justin_michaud@apple.com | ea578c3 | 2018-11-01 20:35:27 +0000 | [diff] [blame] | 93 | return result; |
commit-queue@webkit.org | 4450fe2 | 2018-10-06 13:57:16 +0000 | [diff] [blame] | 94 | } |
| 95 | |
hyatt@apple.com | 9e09f63 | 2016-10-27 22:05:01 +0000 | [diff] [blame] | 96 | } |