1 /* 2 * Copyright (c) 2010 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "config.h" 32 33 #ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC 34 #define CSSPROPERTYSOURCEDATA_HIDE_GLOBALS 1 35 #endif 36 37 #include "CSSPropertySourceData.h" 38 39 #include "PlatformString.h" 40 #include <wtf/StaticConstructors.h> 41 #include <wtf/text/StringHash.h> 42 43 namespace WebCore { 44 45 SourceRange::SourceRange() 46 : start(0) 47 , end(0) 48 { 49 } 50 51 SourceRange::SourceRange(unsigned start, unsigned end) 52 : start(start) 53 , end(end) 54 { 55 } 56 57 CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool parsedOk, const SourceRange& range) 58 : name(name) 59 , value(value) 60 , important(important) 61 , parsedOk(parsedOk) 62 , range(range) 63 { 64 } 65 66 CSSPropertySourceData::CSSPropertySourceData(const CSSPropertySourceData& other) 67 : name(other.name) 68 , value(other.value) 69 , important(other.important) 70 , parsedOk(other.parsedOk) 71 , range(other.range) 72 { 73 } 74 75 CSSPropertySourceData::CSSPropertySourceData() 76 : name("") 77 , value("") 78 , important(false) 79 , parsedOk(false) 80 , range(SourceRange(0, 0)) 81 { 82 } 83 84 String CSSPropertySourceData::toString() const 85 { 86 DEFINE_STATIC_LOCAL(String, emptyValue, ("e")); 87 DEFINE_STATIC_LOCAL(String, importantSuffix, (" !important")); 88 if (!name && value == emptyValue) 89 return String(); 90 91 String result = name; 92 result += ": "; 93 result += value; 94 if (important) 95 result += importantSuffix; 96 result += ";"; 97 return result; 98 } 99 100 unsigned CSSPropertySourceData::hash() const 101 { 102 return StringHash::hash(name) + 3 * StringHash::hash(value) + 7 * important + 13 * parsedOk + 31; 103 } 104 105 // Global init routines 106 DEFINE_GLOBAL(CSSPropertySourceData, emptyCSSPropertySourceData, "", "e", false, false) 107 108 // static 109 void CSSPropertySourceData::init() 110 { 111 static bool initialized; 112 if (!initialized) { 113 new ((void *) &emptyCSSPropertySourceData) CSSPropertySourceData("", "e", false, false, SourceRange(0, 0)); 114 initialized = true; 115 } 116 } 117 118 } // namespace WebCore 119