layout/style/nsIStyleRule.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsIStyleRule.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     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 +/*
    1.10 + * internal abstract interface for objects providing immutable style
    1.11 + * information
    1.12 + */
    1.13 +
    1.14 +#ifndef nsIStyleRule_h___
    1.15 +#define nsIStyleRule_h___
    1.16 +
    1.17 +#include <stdio.h>
    1.18 +
    1.19 +#include "nsISupports.h"
    1.20 +
    1.21 +struct nsRuleData;
    1.22 +
    1.23 +// IID for the nsIStyleRule interface {f75f3f70-435d-43a6-a01b-65970489ca26}
    1.24 +#define NS_ISTYLE_RULE_IID     \
    1.25 +{ 0xf75f3f70, 0x435d, 0x43a6, \
    1.26 + { 0xa0, 0x1b, 0x65, 0x97, 0x04, 0x89, 0xca, 0x26 } }
    1.27 +
    1.28 +/**
    1.29 + * An object implementing |nsIStyleRule| (henceforth, a rule) represents
    1.30 + * immutable stylistic information that either applies or does not apply
    1.31 + * to a given element.  It belongs to an object or group of objects that
    1.32 + * implement |nsIStyleSheet| and |nsIStyleRuleProcessor| (henceforth, a
    1.33 + * sheet).
    1.34 + *
    1.35 + * A rule becomes relevant to the computation of style data when
    1.36 + * |nsIStyleRuleProcessor::RulesMatching| creates a rule node that
    1.37 + * points to the rule.  (A rule node, |nsRuleNode|, is a node in the
    1.38 + * rule tree, which is a lexicographic tree indexed by rules.  The path
    1.39 + * from the root of the rule tree to the |nsRuleNode| for a given
    1.40 + * |nsStyleContext| contains exactly the rules that match the element
    1.41 + * that the style context is for, in priority (weight, origin,
    1.42 + * specificity) order.)
    1.43 + *
    1.44 + * The computation of style data uses the rule tree, which calls
    1.45 + * |nsIStyleRule::MapRuleInfoInto| below.
    1.46 + *
    1.47 + * It is worth emphasizing that the data represented by a rule
    1.48 + * implementation are immutable.  When the data need to be changed, a
    1.49 + * new rule object must be created.  Failing to do this will lead to
    1.50 + * bugs in the handling of dynamic style changes, since the rule tree
    1.51 + * caches the results of |MapRuleInfoInto|.
    1.52 + *
    1.53 + * |nsIStyleRule| objects are owned by |nsRuleNode| objects (in addition
    1.54 + * to typically being owned by their sheet), which are in turn garbage
    1.55 + * collected (with the garbage collection roots being style contexts).
    1.56 + */
    1.57 +
    1.58 +
    1.59 +class nsIStyleRule : public nsISupports {
    1.60 +public:
    1.61 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_IID)
    1.62 +
    1.63 +  /**
    1.64 +   * |nsIStyleRule::MapRuleInfoInto| is a request to copy all stylistic
    1.65 +   * data represented by the rule that:
    1.66 +   *   + are relevant for any structs in |aRuleData->mSIDs| (style
    1.67 +   *     struct ID bits)
    1.68 +   *   + are not already filled into the data struct
    1.69 +   * into the appropriate data struct in |aRuleData|.  It is important
    1.70 +   * that only empty data are filled in, since the rule tree is walked
    1.71 +   * from highest priority rule to least, so that the walk can stop if
    1.72 +   * all needed data are found.  Thus overwriting non-empty data will
    1.73 +   * break CSS cascading rules.
    1.74 +   */
    1.75 +  virtual void MapRuleInfoInto(nsRuleData* aRuleData)=0;
    1.76 +
    1.77 +#ifdef DEBUG
    1.78 +  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
    1.79 +#endif
    1.80 +};
    1.81 +
    1.82 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRule, NS_ISTYLE_RULE_IID)
    1.83 +
    1.84 +#endif /* nsIStyleRule_h___ */

mercurial