Home | History | Annotate | Download | only in css
      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 #ifndef CSSPropertySourceData_h
     32 #define CSSPropertySourceData_h
     33 
     34 #include "platform/heap/Handle.h"
     35 #include "wtf/Forward.h"
     36 #include "wtf/RefCounted.h"
     37 #include "wtf/Vector.h"
     38 #include "wtf/text/WTFString.h"
     39 
     40 namespace WebCore {
     41 
     42 class StyleRuleBase;
     43 
     44 struct SourceRange {
     45     ALLOW_ONLY_INLINE_ALLOCATION();
     46 public:
     47     SourceRange();
     48     SourceRange(unsigned start, unsigned end);
     49     unsigned length() const;
     50 
     51     void trace(Visitor*) { }
     52 
     53     unsigned start;
     54     unsigned end;
     55 };
     56 
     57 struct CSSPropertySourceData {
     58     ALLOW_ONLY_INLINE_ALLOCATION();
     59 public:
     60     CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange& range);
     61     CSSPropertySourceData(const CSSPropertySourceData& other);
     62     CSSPropertySourceData();
     63 
     64     String toString() const;
     65     unsigned hash() const;
     66 
     67     void trace(Visitor* visitor) { visitor->trace(range); }
     68 
     69     String name;
     70     String value;
     71     bool important;
     72     bool disabled;
     73     bool parsedOk;
     74     SourceRange range;
     75 };
     76 
     77 struct CSSStyleSourceData : public RefCountedWillBeGarbageCollected<CSSStyleSourceData> {
     78     static PassRefPtrWillBeRawPtr<CSSStyleSourceData> create()
     79     {
     80         return adoptRefWillBeNoop(new CSSStyleSourceData());
     81     }
     82 
     83     void trace(Visitor* visitor) { visitor->trace(propertyData); }
     84 
     85     WillBeHeapVector<CSSPropertySourceData> propertyData;
     86 };
     87 
     88 struct CSSRuleSourceData;
     89 typedef WillBeHeapVector<RefPtrWillBeMember<CSSRuleSourceData> > RuleSourceDataList;
     90 typedef WillBeHeapVector<SourceRange> SelectorRangeList;
     91 
     92 struct CSSRuleSourceData : public RefCountedWillBeGarbageCollected<CSSRuleSourceData> {
     93     enum Type {
     94         UNKNOWN_RULE,
     95         STYLE_RULE,
     96         CHARSET_RULE,
     97         IMPORT_RULE,
     98         MEDIA_RULE,
     99         FONT_FACE_RULE,
    100         PAGE_RULE,
    101         KEYFRAMES_RULE,
    102         VIEWPORT_RULE,
    103         SUPPORTS_RULE,
    104         FILTER_RULE
    105     };
    106 
    107     static PassRefPtrWillBeRawPtr<CSSRuleSourceData> create(Type type)
    108     {
    109         return adoptRefWillBeNoop(new CSSRuleSourceData(type));
    110     }
    111 
    112     static PassRefPtrWillBeRawPtr<CSSRuleSourceData> createUnknown()
    113     {
    114         return adoptRefWillBeNoop(new CSSRuleSourceData(UNKNOWN_RULE));
    115     }
    116 
    117     CSSRuleSourceData(Type type)
    118         : type(type)
    119     {
    120         if (type == STYLE_RULE || type == FONT_FACE_RULE || type == PAGE_RULE)
    121             styleSourceData = CSSStyleSourceData::create();
    122     }
    123 
    124     void trace(Visitor*);
    125 
    126     Type type;
    127 
    128     // Range of the selector list in the enclosing source.
    129     SourceRange ruleHeaderRange;
    130 
    131     // Range of the rule body (e.g. style text for style rules) in the enclosing source.
    132     SourceRange ruleBodyRange;
    133 
    134     // Only for CSSStyleRules.
    135     SelectorRangeList selectorRanges;
    136 
    137     // Only for CSSStyleRules, CSSFontFaceRules, and CSSPageRules.
    138     RefPtrWillBeMember<CSSStyleSourceData> styleSourceData;
    139 
    140     // Only for CSSMediaRules.
    141     RuleSourceDataList childRules;
    142 };
    143 
    144 } // namespace WebCore
    145 
    146 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(WebCore::SourceRange);
    147 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(WebCore::CSSPropertySourceData);
    148 
    149 #endif // CSSPropertySourceData_h
    150