layout/style/Rule.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* base class for all rule types in a CSS style sheet */
     8 #ifndef mozilla_css_Rule_h___
     9 #define mozilla_css_Rule_h___
    11 #include "mozilla/MemoryReporting.h"
    12 #include "nsIStyleRule.h"
    13 #include "nsIDOMCSSRule.h"
    14 #include "nsCSSStyleSheet.h"
    16 class nsIStyleSheet;
    17 class nsIDocument;
    18 struct nsRuleData;
    19 template<class T> struct already_AddRefed;
    20 class nsHTMLCSSStyleSheet;
    22 namespace mozilla {
    23 namespace css {
    24 class GroupRule;
    26 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
    27 virtual void MapRuleInfoInto(nsRuleData* aRuleData);
    29 #define DECL_STYLE_RULE_INHERIT                   \
    30   DECL_STYLE_RULE_INHERIT_NO_DOMRULE              \
    31   virtual nsIDOMCSSRule* GetDOMRule();            \
    32   virtual nsIDOMCSSRule* GetExistingDOMRule();
    34 class Rule : public nsIStyleRule {
    35 protected:
    36   Rule()
    37     : mSheet(0),
    38       mParentRule(nullptr)
    39   {
    40   }
    42   Rule(const Rule& aCopy)
    43     : mSheet(aCopy.mSheet),
    44       mParentRule(aCopy.mParentRule)
    45   {
    46   }
    48   virtual ~Rule() {}
    50 public:
    52   // The constants in this list must maintain the following invariants:
    53   //   If a rule of type N must appear before a rule of type M in stylesheets
    54   //   then N < M
    55   // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
    56   // rules can come between two rules of type IMPORT_RULE.
    57   enum {
    58     UNKNOWN_RULE = 0,
    59     CHARSET_RULE,
    60     IMPORT_RULE,
    61     NAMESPACE_RULE,
    62     STYLE_RULE,
    63     MEDIA_RULE,
    64     FONT_FACE_RULE,
    65     PAGE_RULE,
    66     KEYFRAME_RULE,
    67     KEYFRAMES_RULE,
    68     DOCUMENT_RULE,
    69     SUPPORTS_RULE,
    70     FONT_FEATURE_VALUES_RULE
    71   };
    73   virtual int32_t GetType() const = 0;
    75   nsCSSStyleSheet* GetStyleSheet() const;
    76   nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const;
    78   // Return the document the rule lives in, if any
    79   nsIDocument* GetDocument() const
    80   {
    81     nsCSSStyleSheet* sheet = GetStyleSheet();
    82     return sheet ? sheet->GetDocument() : nullptr;
    83   }
    85   virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
    86   // This does not need to be virtual, because GroupRule and MediaRule are not
    87   // used for inline style.
    88   void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet);
    90   void SetParentRule(GroupRule* aRule) {
    91     // We don't reference count this up reference. The group rule
    92     // will tell us when it's going away or when we're detached from
    93     // it.
    94     mParentRule = aRule;
    95   }
    97   /**
    98    * Clones |this|. Never returns nullptr.
    99    */
   100   virtual already_AddRefed<Rule> Clone() const = 0;
   102   // Note that this returns null for inline style rules since they aren't
   103   // supposed to have a DOM rule representation (and our code wouldn't work).
   104   virtual nsIDOMCSSRule* GetDOMRule() = 0;
   106   // Like GetDOMRule(), but won't create one if we don't have one yet
   107   virtual nsIDOMCSSRule* GetExistingDOMRule() = 0;
   109   // to implement methods on nsIDOMCSSRule
   110   nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
   111   nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
   113   // This is pure virtual because all of Rule's data members are non-owning and
   114   // thus measured elsewhere.
   115   virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
   116     const MOZ_MUST_OVERRIDE = 0;
   118   // This is used to measure nsCOMArray<Rule>s.
   119   static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
   120                                                    mozilla::MallocSizeOf aMallocSizeOf,
   121                                                    void* aData);
   123 protected:
   124   // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*.  The former
   125   // if the low bit is 0, the latter if the low bit is 1.
   126   uintptr_t         mSheet;
   127   GroupRule*        mParentRule;
   128 };
   130 } // namespace css
   131 } // namespace mozilla
   133 #endif /* mozilla_css_Rule_h___ */

mercurial