| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * 1999 Waldo Bastian (bastian@kde.org) | 3 * 1999 Waldo Bastian (bastian@kde.org) |
| 4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch) | 4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch) |
| 5 * 2001-2003 Dirk Mueller (mueller@kde.org) | 5 * 2001-2003 Dirk Mueller (mueller@kde.org) |
| 6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | 6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. |
| 7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com) | 7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com) |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * along with this library; see the file COPYING.LIB. If not, write to | 21 * along with this library; see the file COPYING.LIB. If not, write to |
| 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/css/CSSSelector.h" | 26 #include "core/css/CSSSelector.h" |
| 27 | 27 |
| 28 #include "core/HTMLNames.h" | 28 #include "core/HTMLNames.h" |
| 29 #include "core/css/CSSMarkup.h" | 29 #include "core/css/CSSMarkup.h" |
| 30 #include "core/css/CSSSelectorList.h" | 30 #include "core/css/CSSSelectorList.h" |
| 31 #include "core/css/serializer/CSSDeserializeStream.h" |
| 32 #include "core/css/serializer/CSSSerializeStream.h" |
| 31 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
| 32 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
| 33 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 34 #include "wtf/StdLibExtras.h" | 36 #include "wtf/StdLibExtras.h" |
| 35 #include "wtf/text/StringBuilder.h" | 37 #include "wtf/text/StringBuilder.h" |
| 36 #include <algorithm> | 38 #include <algorithm> |
| 37 | 39 |
| 38 #ifndef NDEBUG | 40 #ifndef NDEBUG |
| 39 #include <stdio.h> | 41 #include <stdio.h> |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 namespace blink { | 44 namespace blink { |
| 43 | 45 |
| 44 using namespace HTMLNames; | 46 using namespace HTMLNames; |
| 45 | 47 |
| 46 struct SameSizeAsCSSSelector { | 48 struct SameSizeAsCSSSelector { |
| 47 unsigned bitfields; | 49 unsigned bitfields; |
| 48 void* pointers[1]; | 50 void* pointers[1]; |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 static_assert(sizeof(CSSSelector) == sizeof(SameSizeAsCSSSelector), "CSSSelector
should stay small"); | 53 static_assert(sizeof(CSSSelector) == sizeof(SameSizeAsCSSSelector), "CSSSelector
should stay small"); |
| 52 | 54 |
| 55 CSSSelector::CSSSelector(CSSDeserializeStream* stream) |
| 56 { |
| 57 CSDEBUG("CSSSelector::ctor deserialize\n"); |
| 58 m_bitfields = stream->readUnsigned(); |
| 59 if (m_hasRareData) { |
| 60 m_data.m_rareData = RareData::deserialize(stream).leakRef(); |
| 61 } else if (m_match == Tag) { |
| 62 QualifiedName tagQName = stream->readQualifiedName(); |
| 63 m_data.m_tagQName = tagQName.impl(); |
| 64 m_data.m_tagQName->ref(); |
| 65 } else { |
| 66 AtomicString value = stream->readAtomicString(); |
| 67 m_data.m_value = value.impl(); |
| 68 m_data.m_value->ref(); |
| 69 } |
| 70 } |
| 71 |
| 53 void CSSSelector::createRareData() | 72 void CSSSelector::createRareData() |
| 54 { | 73 { |
| 55 ASSERT(m_match != Tag); | 74 ASSERT(m_match != Tag); |
| 56 if (m_hasRareData) | 75 if (m_hasRareData) |
| 57 return; | 76 return; |
| 58 AtomicString value(m_data.m_value); | 77 AtomicString value(m_data.m_value); |
| 59 if (m_data.m_value) | 78 if (m_data.m_value) |
| 60 m_data.m_value->deref(); | 79 m_data.m_value->deref(); |
| 61 m_data.m_rareData = RareData::create(value).leakRef(); | 80 m_data.m_rareData = RareData::create(value).leakRef(); |
| 62 m_hasRareData = true; | 81 m_hasRareData = true; |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 m_data.m_rareData->m_bits.m_nth.m_a = a; | 893 m_data.m_rareData->m_bits.m_nth.m_a = a; |
| 875 m_data.m_rareData->m_bits.m_nth.m_b = b; | 894 m_data.m_rareData->m_bits.m_nth.m_b = b; |
| 876 } | 895 } |
| 877 | 896 |
| 878 bool CSSSelector::matchNth(int count) const | 897 bool CSSSelector::matchNth(int count) const |
| 879 { | 898 { |
| 880 ASSERT(m_hasRareData); | 899 ASSERT(m_hasRareData); |
| 881 return m_data.m_rareData->matchNth(count); | 900 return m_data.m_rareData->matchNth(count); |
| 882 } | 901 } |
| 883 | 902 |
| 903 void CSSSelector::serialize(CSSSerializeStream* stream) const |
| 904 { |
| 905 CSDEBUG("CSSSelector::serialize "); CSSHOW(selectorText()); |
| 906 stream->writeUnsigned(m_bitfields); |
| 907 if (m_hasRareData) { |
| 908 m_data.m_rareData->serialize(stream); |
| 909 } else if (m_match == Tag) { |
| 910 stream->writeQualifiedName(tagQName()); |
| 911 } else { |
| 912 stream->writeAtomicString(value()); |
| 913 } |
| 914 } |
| 915 |
| 884 CSSSelector::RareData::RareData(const AtomicString& value) | 916 CSSSelector::RareData::RareData(const AtomicString& value) |
| 885 : m_matchingValue(value) | 917 : m_matchingValue(value) |
| 886 , m_serializingValue(value) | 918 , m_serializingValue(value) |
| 887 , m_bits() | 919 , m_bits() |
| 888 , m_attribute(anyQName()) | 920 , m_attribute(anyQName()) |
| 889 , m_argument(nullAtom) | 921 , m_argument(nullAtom) |
| 890 { | 922 { |
| 891 } | 923 } |
| 892 | 924 |
| 893 CSSSelector::RareData::~RareData() | 925 CSSSelector::RareData::~RareData() |
| 894 { | 926 { |
| 895 } | 927 } |
| 896 | 928 |
| 929 PassRefPtr<CSSSelector::RareData> CSSSelector::RareData::deserialize(CSSDeserial
izeStream* stream) |
| 930 { |
| 931 AtomicString matchingValue = stream->readAtomicString(); |
| 932 RefPtr<RareData> rareData = create(matchingValue); |
| 933 rareData->m_serializingValue = stream->readAtomicString();; |
| 934 |
| 935 rareData->m_bits.m_nth.m_a = stream->readInt(); |
| 936 rareData->m_bits.m_nth.m_b = stream->readInt(); |
| 937 rareData->m_attribute = stream->readQualifiedName(); |
| 938 rareData->m_argument = stream->readAtomicString(); |
| 939 bool hasSelectorList = stream->readBool(); |
| 940 if (hasSelectorList) { |
| 941 rareData->m_selectorList = adoptPtr(new CSSSelectorList()); |
| 942 *rareData->m_selectorList = CSSSelectorList::deserialize(stream); |
| 943 } |
| 944 |
| 945 return rareData.release(); |
| 946 } |
| 947 |
| 897 // a helper function for checking nth-arguments | 948 // a helper function for checking nth-arguments |
| 898 bool CSSSelector::RareData::matchNth(int count) | 949 bool CSSSelector::RareData::matchNth(int count) |
| 899 { | 950 { |
| 900 if (!nthAValue()) | 951 if (!nthAValue()) |
| 901 return count == nthBValue(); | 952 return count == nthBValue(); |
| 902 if (nthAValue() > 0) { | 953 if (nthAValue() > 0) { |
| 903 if (count < nthBValue()) | 954 if (count < nthBValue()) |
| 904 return false; | 955 return false; |
| 905 return (count - nthBValue()) % nthAValue() == 0; | 956 return (count - nthBValue()) % nthAValue() == 0; |
| 906 } | 957 } |
| 907 if (count > nthBValue()) | 958 if (count > nthBValue()) |
| 908 return false; | 959 return false; |
| 909 return (nthBValue() - count) % (-nthAValue()) == 0; | 960 return (nthBValue() - count) % (-nthAValue()) == 0; |
| 910 } | 961 } |
| 911 | 962 |
| 963 void CSSSelector::RareData::serialize(CSSSerializeStream* stream) |
| 964 { |
| 965 stream->writeAtomicString(m_matchingValue); |
| 966 stream->writeAtomicString(m_serializingValue); |
| 967 stream->writeInt(m_bits.m_nth.m_a); |
| 968 stream->writeInt(m_bits.m_nth.m_b); |
| 969 stream->writeQualifiedName(m_attribute); |
| 970 stream->writeAtomicString(m_argument); |
| 971 if (m_selectorList) { |
| 972 stream->writeBool(true); |
| 973 m_selectorList->serialize(stream); |
| 974 } else { |
| 975 stream->writeBool(false); |
| 976 } |
| 977 } |
| 978 |
| 912 } // namespace blink | 979 } // namespace blink |
| OLD | NEW |