layout/style/nsIStyleRule.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * internal abstract interface for objects providing immutable style
michael@0 8 * information
michael@0 9 */
michael@0 10
michael@0 11 #ifndef nsIStyleRule_h___
michael@0 12 #define nsIStyleRule_h___
michael@0 13
michael@0 14 #include <stdio.h>
michael@0 15
michael@0 16 #include "nsISupports.h"
michael@0 17
michael@0 18 struct nsRuleData;
michael@0 19
michael@0 20 // IID for the nsIStyleRule interface {f75f3f70-435d-43a6-a01b-65970489ca26}
michael@0 21 #define NS_ISTYLE_RULE_IID \
michael@0 22 { 0xf75f3f70, 0x435d, 0x43a6, \
michael@0 23 { 0xa0, 0x1b, 0x65, 0x97, 0x04, 0x89, 0xca, 0x26 } }
michael@0 24
michael@0 25 /**
michael@0 26 * An object implementing |nsIStyleRule| (henceforth, a rule) represents
michael@0 27 * immutable stylistic information that either applies or does not apply
michael@0 28 * to a given element. It belongs to an object or group of objects that
michael@0 29 * implement |nsIStyleSheet| and |nsIStyleRuleProcessor| (henceforth, a
michael@0 30 * sheet).
michael@0 31 *
michael@0 32 * A rule becomes relevant to the computation of style data when
michael@0 33 * |nsIStyleRuleProcessor::RulesMatching| creates a rule node that
michael@0 34 * points to the rule. (A rule node, |nsRuleNode|, is a node in the
michael@0 35 * rule tree, which is a lexicographic tree indexed by rules. The path
michael@0 36 * from the root of the rule tree to the |nsRuleNode| for a given
michael@0 37 * |nsStyleContext| contains exactly the rules that match the element
michael@0 38 * that the style context is for, in priority (weight, origin,
michael@0 39 * specificity) order.)
michael@0 40 *
michael@0 41 * The computation of style data uses the rule tree, which calls
michael@0 42 * |nsIStyleRule::MapRuleInfoInto| below.
michael@0 43 *
michael@0 44 * It is worth emphasizing that the data represented by a rule
michael@0 45 * implementation are immutable. When the data need to be changed, a
michael@0 46 * new rule object must be created. Failing to do this will lead to
michael@0 47 * bugs in the handling of dynamic style changes, since the rule tree
michael@0 48 * caches the results of |MapRuleInfoInto|.
michael@0 49 *
michael@0 50 * |nsIStyleRule| objects are owned by |nsRuleNode| objects (in addition
michael@0 51 * to typically being owned by their sheet), which are in turn garbage
michael@0 52 * collected (with the garbage collection roots being style contexts).
michael@0 53 */
michael@0 54
michael@0 55
michael@0 56 class nsIStyleRule : public nsISupports {
michael@0 57 public:
michael@0 58 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_IID)
michael@0 59
michael@0 60 /**
michael@0 61 * |nsIStyleRule::MapRuleInfoInto| is a request to copy all stylistic
michael@0 62 * data represented by the rule that:
michael@0 63 * + are relevant for any structs in |aRuleData->mSIDs| (style
michael@0 64 * struct ID bits)
michael@0 65 * + are not already filled into the data struct
michael@0 66 * into the appropriate data struct in |aRuleData|. It is important
michael@0 67 * that only empty data are filled in, since the rule tree is walked
michael@0 68 * from highest priority rule to least, so that the walk can stop if
michael@0 69 * all needed data are found. Thus overwriting non-empty data will
michael@0 70 * break CSS cascading rules.
michael@0 71 */
michael@0 72 virtual void MapRuleInfoInto(nsRuleData* aRuleData)=0;
michael@0 73
michael@0 74 #ifdef DEBUG
michael@0 75 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
michael@0 76 #endif
michael@0 77 };
michael@0 78
michael@0 79 NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRule, NS_ISTYLE_RULE_IID)
michael@0 80
michael@0 81 #endif /* nsIStyleRule_h___ */

mercurial