• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/css/CSSPropertySourceData.h"
38 
39 #include "wtf/StaticConstructors.h"
40 #include "wtf/text/StringBuilder.h"
41 #include "wtf/text/StringHash.h"
42 
43 namespace WebCore {
44 
SourceRange()45 SourceRange::SourceRange()
46     : start(0)
47     , end(0)
48 {
49 }
50 
SourceRange(unsigned start,unsigned end)51 SourceRange::SourceRange(unsigned start, unsigned end)
52     : start(start)
53     , end(end)
54 {
55 }
56 
length() const57 unsigned SourceRange::length() const
58 {
59     return end - start;
60 }
61 
CSSPropertySourceData(const String & name,const String & value,bool important,bool disabled,bool parsedOk,const SourceRange & range)62 CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange& range)
63     : name(name)
64     , value(value)
65     , important(important)
66     , disabled(disabled)
67     , parsedOk(parsedOk)
68     , range(range)
69 {
70 }
71 
CSSPropertySourceData(const CSSPropertySourceData & other)72 CSSPropertySourceData::CSSPropertySourceData(const CSSPropertySourceData& other)
73     : name(other.name)
74     , value(other.value)
75     , important(other.important)
76     , disabled(other.disabled)
77     , parsedOk(other.parsedOk)
78     , range(other.range)
79 {
80 }
81 
CSSPropertySourceData()82 CSSPropertySourceData::CSSPropertySourceData()
83     : name("")
84     , value("")
85     , important(false)
86     , disabled(false)
87     , parsedOk(false)
88     , range(SourceRange(0, 0))
89 {
90 }
91 
toString() const92 String CSSPropertySourceData::toString() const
93 {
94     DEFINE_STATIC_LOCAL(String, emptyValue, ("e"));
95     if (!name && value == emptyValue)
96         return String();
97 
98     StringBuilder result;
99     if (disabled)
100         result.append("/* ");
101     result.append(name);
102     result.appendLiteral(": ");
103     result.append(value);
104     if (important)
105         result.appendLiteral(" !important");
106     result.append(';');
107     if (disabled)
108         result.append(" */");
109     return result.toString();
110 }
111 
hash() const112 unsigned CSSPropertySourceData::hash() const
113 {
114     return StringHash::hash(name) + 3 * StringHash::hash(value) + 7 * important + 13 * parsedOk + 31;
115 }
116 
117 // Global init routines
118 DEFINE_GLOBAL(CSSPropertySourceData, emptyCSSPropertySourceData, "", "e", false, false)
119 
120 // static
init()121 void CSSPropertySourceData::init()
122 {
123     static bool initialized;
124     if (!initialized) {
125         new ((void *) &emptyCSSPropertySourceData) CSSPropertySourceData("", "e", false, false, false, SourceRange(0, 0));
126         initialized = true;
127     }
128 }
129 
130 } // namespace WebCore
131