layout/style/Rule.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/Rule.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* base class for all rule types in a CSS style sheet */
    1.10 +
    1.11 +#ifndef mozilla_css_Rule_h___
    1.12 +#define mozilla_css_Rule_h___
    1.13 +
    1.14 +#include "mozilla/MemoryReporting.h"
    1.15 +#include "nsIStyleRule.h"
    1.16 +#include "nsIDOMCSSRule.h"
    1.17 +#include "nsCSSStyleSheet.h"
    1.18 +
    1.19 +class nsIStyleSheet;
    1.20 +class nsIDocument;
    1.21 +struct nsRuleData;
    1.22 +template<class T> struct already_AddRefed;
    1.23 +class nsHTMLCSSStyleSheet;
    1.24 +
    1.25 +namespace mozilla {
    1.26 +namespace css {
    1.27 +class GroupRule;
    1.28 +
    1.29 +#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE  \
    1.30 +virtual void MapRuleInfoInto(nsRuleData* aRuleData);
    1.31 +
    1.32 +#define DECL_STYLE_RULE_INHERIT                   \
    1.33 +  DECL_STYLE_RULE_INHERIT_NO_DOMRULE              \
    1.34 +  virtual nsIDOMCSSRule* GetDOMRule();            \
    1.35 +  virtual nsIDOMCSSRule* GetExistingDOMRule();
    1.36 +
    1.37 +class Rule : public nsIStyleRule {
    1.38 +protected:
    1.39 +  Rule()
    1.40 +    : mSheet(0),
    1.41 +      mParentRule(nullptr)
    1.42 +  {
    1.43 +  }
    1.44 +
    1.45 +  Rule(const Rule& aCopy)
    1.46 +    : mSheet(aCopy.mSheet),
    1.47 +      mParentRule(aCopy.mParentRule)
    1.48 +  {
    1.49 +  }
    1.50 +
    1.51 +  virtual ~Rule() {}
    1.52 +
    1.53 +public:
    1.54 +
    1.55 +  // The constants in this list must maintain the following invariants:
    1.56 +  //   If a rule of type N must appear before a rule of type M in stylesheets
    1.57 +  //   then N < M
    1.58 +  // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
    1.59 +  // rules can come between two rules of type IMPORT_RULE.
    1.60 +  enum {
    1.61 +    UNKNOWN_RULE = 0,
    1.62 +    CHARSET_RULE,
    1.63 +    IMPORT_RULE,
    1.64 +    NAMESPACE_RULE,
    1.65 +    STYLE_RULE,
    1.66 +    MEDIA_RULE,
    1.67 +    FONT_FACE_RULE,
    1.68 +    PAGE_RULE,
    1.69 +    KEYFRAME_RULE,
    1.70 +    KEYFRAMES_RULE,
    1.71 +    DOCUMENT_RULE,
    1.72 +    SUPPORTS_RULE,
    1.73 +    FONT_FEATURE_VALUES_RULE
    1.74 +  };
    1.75 +
    1.76 +  virtual int32_t GetType() const = 0;
    1.77 +
    1.78 +  nsCSSStyleSheet* GetStyleSheet() const;
    1.79 +  nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const;
    1.80 +
    1.81 +  // Return the document the rule lives in, if any
    1.82 +  nsIDocument* GetDocument() const
    1.83 +  {
    1.84 +    nsCSSStyleSheet* sheet = GetStyleSheet();
    1.85 +    return sheet ? sheet->GetDocument() : nullptr;
    1.86 +  }
    1.87 +
    1.88 +  virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
    1.89 +  // This does not need to be virtual, because GroupRule and MediaRule are not
    1.90 +  // used for inline style.
    1.91 +  void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet);
    1.92 +
    1.93 +  void SetParentRule(GroupRule* aRule) {
    1.94 +    // We don't reference count this up reference. The group rule
    1.95 +    // will tell us when it's going away or when we're detached from
    1.96 +    // it.
    1.97 +    mParentRule = aRule;
    1.98 +  }
    1.99 +
   1.100 +  /**
   1.101 +   * Clones |this|. Never returns nullptr.
   1.102 +   */
   1.103 +  virtual already_AddRefed<Rule> Clone() const = 0;
   1.104 +
   1.105 +  // Note that this returns null for inline style rules since they aren't
   1.106 +  // supposed to have a DOM rule representation (and our code wouldn't work).
   1.107 +  virtual nsIDOMCSSRule* GetDOMRule() = 0;
   1.108 +
   1.109 +  // Like GetDOMRule(), but won't create one if we don't have one yet
   1.110 +  virtual nsIDOMCSSRule* GetExistingDOMRule() = 0;
   1.111 +
   1.112 +  // to implement methods on nsIDOMCSSRule
   1.113 +  nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
   1.114 +  nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
   1.115 +
   1.116 +  // This is pure virtual because all of Rule's data members are non-owning and
   1.117 +  // thus measured elsewhere.
   1.118 +  virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
   1.119 +    const MOZ_MUST_OVERRIDE = 0;
   1.120 +
   1.121 +  // This is used to measure nsCOMArray<Rule>s.
   1.122 +  static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
   1.123 +                                                   mozilla::MallocSizeOf aMallocSizeOf,
   1.124 +                                                   void* aData);
   1.125 +
   1.126 +protected:
   1.127 +  // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*.  The former
   1.128 +  // if the low bit is 0, the latter if the low bit is 1.
   1.129 +  uintptr_t         mSheet;
   1.130 +  GroupRule*        mParentRule;
   1.131 +};
   1.132 +
   1.133 +} // namespace css
   1.134 +} // namespace mozilla
   1.135 +
   1.136 +#endif /* mozilla_css_Rule_h___ */

mercurial