LCOV - code coverage report
Current view: top level - layout/style - nsRuleWalker.h (source / functions) Hit Total Coverage
Test: output.info Lines: 36 37 97.3 %
Date: 2017-07-14 16:53:18 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : /*
       7             :  * a class that walks the lexicographic tree of rule nodes as style
       8             :  * rules are matched
       9             :  */
      10             : 
      11             : #ifndef nsRuleWalker_h_
      12             : #define nsRuleWalker_h_
      13             : 
      14             : #include "nsRuleNode.h"
      15             : #include "nsIStyleRule.h"
      16             : #include "Declaration.h"
      17             : #include "nsQueryObject.h"
      18             : 
      19             : class nsRuleWalker {
      20             : public:
      21       45358 :   nsRuleNode* CurrentNode() { return mCurrent; }
      22          69 :   void SetCurrentNode(nsRuleNode* aNode) {
      23          69 :     NS_ASSERTION(aNode, "Must have node here!");
      24          69 :     mCurrent = aNode;
      25          69 :   }
      26             : 
      27             :   nsPresContext* PresContext() const { return mRoot->PresContext(); }
      28             : 
      29             : protected:
      30       11651 :   void DoForward(nsIStyleRule* aRule) {
      31       11651 :     mCurrent = mCurrent->Transition(aRule, mLevel, mImportance);
      32       11651 :     NS_POSTCONDITION(mCurrent, "Transition messed up");
      33       11651 :   }
      34             : 
      35             : public:
      36         663 :   void Forward(nsIStyleRule* aRule) {
      37         663 :     NS_PRECONDITION(!RefPtr<mozilla::css::Declaration>(do_QueryObject(aRule)),
      38             :                     "Calling the wrong Forward() overload");
      39         663 :     DoForward(aRule);
      40         663 :   }
      41       10844 :   void Forward(mozilla::css::Declaration* aRule) {
      42       10844 :     DoForward(aRule);
      43       10844 :     mCheckForImportantRules =
      44       10844 :       mCheckForImportantRules && !aRule->HasImportantData();
      45       10844 :   }
      46             :   // ForwardOnPossiblyCSSRule should only be used by callers that have
      47             :   // an explicit list of rules they need to walk, with the list
      48             :   // already containing any important rules they care about.
      49         144 :   void ForwardOnPossiblyCSSRule(nsIStyleRule* aRule) {
      50         144 :     DoForward(aRule);
      51         144 :   }
      52             : 
      53           0 :   void Reset() { mCurrent = mRoot; }
      54             : 
      55             :   bool AtRoot() { return mCurrent == mRoot; }
      56             : 
      57       36720 :   void SetLevel(mozilla::SheetType aLevel, bool aImportance,
      58             :                 bool aCheckForImportantRules) {
      59       36720 :     NS_ASSERTION(!aCheckForImportantRules || !aImportance,
      60             :                  "Shouldn't be checking for important rules while walking "
      61             :                  "important rules");
      62       36720 :     mLevel = aLevel;
      63       36720 :     mImportance = aImportance;
      64       36720 :     mCheckForImportantRules = aCheckForImportantRules;
      65       36720 :   }
      66             :   mozilla::SheetType GetLevel() const { return mLevel; }
      67             :   bool GetImportance() const { return mImportance; }
      68       19998 :   bool GetCheckForImportantRules() const { return mCheckForImportantRules; }
      69             : 
      70        5002 :   bool AuthorStyleDisabled() const { return mAuthorStyleDisabled; }
      71             : 
      72             :   // We define the visited-relevant link to be the link that is the
      73             :   // nearest self-or-ancestor to the node being matched.
      74             :   enum VisitedHandlingType {
      75             :     // Do rule matching as though all links are unvisited.
      76             :     eRelevantLinkUnvisited,
      77             :     // Do rule matching as though the relevant link is visited and all
      78             :     // other links are unvisited.
      79             :     eRelevantLinkVisited,
      80             :     // Do rule matching as though a rule should match if it would match
      81             :     // given any set of visitedness states.  (used by users other than
      82             :     // nsRuleWalker)
      83             :     eLinksVisitedOrUnvisited
      84             :   };
      85             : 
      86             : private:
      87             :   nsRuleNode* mCurrent; // Our current position.  Never null.
      88             :   nsRuleNode* mRoot; // The root of the tree we're walking.
      89             :   mozilla::SheetType mLevel;
      90             :   bool mImportance;
      91             :   bool mCheckForImportantRules; // If true, check for important rules as
      92             :                                 // we walk and set to false if we find
      93             :                                 // one.
      94             :   bool mAuthorStyleDisabled;
      95             : 
      96             : public:
      97        4068 :   nsRuleWalker(nsRuleNode* aRoot, bool aAuthorStyleDisabled)
      98        4068 :     : mCurrent(aRoot)
      99             :     , mRoot(aRoot)
     100        4068 :     , mAuthorStyleDisabled(aAuthorStyleDisabled)
     101             :   {
     102        4068 :     NS_ASSERTION(mCurrent, "Caller screwed up and gave us null node");
     103        4068 :     MOZ_COUNT_CTOR(nsRuleWalker);
     104        4068 :   }
     105        4068 :   ~nsRuleWalker() { MOZ_COUNT_DTOR(nsRuleWalker); }
     106             : };
     107             : 
     108             : #endif /* !defined(nsRuleWalker_h_) */

Generated by: LCOV version 1.13