LCOV - code coverage report
Current view: top level - layout/base - ServoRestyleManager.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 23 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_ServoRestyleManager_h
       8             : #define mozilla_ServoRestyleManager_h
       9             : 
      10             : #include "mozilla/EventStates.h"
      11             : #include "mozilla/RestyleManager.h"
      12             : #include "mozilla/Maybe.h"
      13             : #include "mozilla/ServoElementSnapshot.h"
      14             : #include "mozilla/ServoElementSnapshotTable.h"
      15             : #include "nsChangeHint.h"
      16             : #include "nsPresContext.h"
      17             : 
      18             : namespace mozilla {
      19             : namespace dom {
      20             : class Element;
      21             : } // namespace dom
      22             : } // namespace mozilla
      23             : class nsAttrValue;
      24             : class nsIAtom;
      25             : class nsIContent;
      26             : class nsIFrame;
      27             : class nsStyleChangeList;
      28             : 
      29             : namespace mozilla {
      30             : 
      31             : /**
      32             :  * A stack class used to pass some common restyle state in a slightly more
      33             :  * comfortable way than a bunch of individual arguments, and that also checks
      34             :  * that the change hint used for optimization is correctly used in debug mode.
      35             :  */
      36             : class ServoRestyleState
      37             : {
      38             : public:
      39           0 :   ServoRestyleState(ServoStyleSet& aStyleSet, nsStyleChangeList& aChangeList)
      40           0 :     : mStyleSet(aStyleSet)
      41             :     , mChangeList(aChangeList)
      42           0 :     , mChangesHandled(nsChangeHint(0))
      43           0 :   {}
      44             : 
      45             :   // We shouldn't assume that changes handled from our parent are handled for
      46             :   // our children too if we're out of flow since they aren't necessarily
      47             :   // parented in DOM order, and thus a change handled by a DOM ancestor doesn't
      48             :   // necessarily mean that it's handled for an ancestor frame.
      49             :   enum class Type
      50             :   {
      51             :     InFlow,
      52             :     OutOfFlow,
      53             :   };
      54             : 
      55           0 :   ServoRestyleState(const nsIFrame& aOwner,
      56             :                     ServoRestyleState& aParentState,
      57             :                     nsChangeHint aHintForThisFrame,
      58             :                     Type aType)
      59           0 :     : mStyleSet(aParentState.mStyleSet)
      60           0 :     , mChangeList(aParentState.mChangeList)
      61             :     , mChangesHandled(
      62             :         aType == Type::InFlow
      63           0 :           ? aParentState.mChangesHandled | aHintForThisFrame
      64             :           : aHintForThisFrame)
      65             : #ifdef DEBUG
      66           0 :     , mOwner(&aOwner)
      67             : #endif
      68             :   {
      69           0 :     if (aType == Type::InFlow) {
      70           0 :       AssertOwner(aParentState);
      71             :     }
      72           0 :   }
      73             : 
      74           0 :   nsStyleChangeList& ChangeList() { return mChangeList; }
      75           0 :   ServoStyleSet& StyleSet() { return mStyleSet; }
      76             : 
      77             : #ifdef DEBUG
      78             :   void AssertOwner(const ServoRestyleState& aParentState) const;
      79             :   nsChangeHint ChangesHandledFor(const nsIFrame&) const;
      80             : #else
      81             :   void AssertOwner(const ServoRestyleState&) const {}
      82             :   nsChangeHint ChangesHandledFor(const nsIFrame&) const
      83             :   {
      84             :     return mChangesHandled;
      85             :   }
      86             : #endif
      87             : 
      88             : private:
      89             :   ServoStyleSet& mStyleSet;
      90             :   nsStyleChangeList& mChangeList;
      91             :   const nsChangeHint mChangesHandled;
      92             : 
      93             :   // We track the "owner" frame of this restyle state, that is, the frame that
      94             :   // generated the last change that is stored in mChangesHandled, in order to
      95             :   // verify that we only use mChangesHandled for actual descendants of that
      96             :   // frame (given DOM order isn't always frame order, and that there are a few
      97             :   // special cases for stuff like wrapper frames, ::backdrop, and so on).
      98             : #ifdef DEBUG
      99             :   const nsIFrame* mOwner { nullptr };
     100             : #endif
     101             : };
     102             : 
     103             : /**
     104             :  * Restyle manager for a Servo-backed style system.
     105             :  */
     106             : class ServoRestyleManager : public RestyleManager
     107             : {
     108             :   friend class ServoStyleSet;
     109             : 
     110             : public:
     111             :   typedef ServoElementSnapshotTable SnapshotTable;
     112             :   typedef RestyleManager base_type;
     113             : 
     114             :   explicit ServoRestyleManager(nsPresContext* aPresContext);
     115             : 
     116             :   void PostRestyleEvent(dom::Element* aElement,
     117             :                         nsRestyleHint aRestyleHint,
     118             :                         nsChangeHint aMinChangeHint);
     119             :   void PostRestyleEventForCSSRuleChanges();
     120             :   void RebuildAllStyleData(nsChangeHint aExtraHint,
     121             :                            nsRestyleHint aRestyleHint);
     122             :   void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
     123             :                                     nsRestyleHint aRestyleHint);
     124             :   void ProcessPendingRestyles();
     125             : 
     126             :   void UpdateOnlyAnimationStyles();
     127             : 
     128             :   void ContentStateChanged(nsIContent* aContent, EventStates aStateMask);
     129             :   void AttributeWillChange(dom::Element* aElement,
     130             :                            int32_t aNameSpaceID,
     131             :                            nsIAtom* aAttribute,
     132             :                            int32_t aModType,
     133             :                            const nsAttrValue* aNewValue);
     134             :   void ClassAttributeWillBeChangedBySMIL(dom::Element* aElement);
     135             : 
     136             :   void AttributeChanged(dom::Element* aElement, int32_t aNameSpaceID,
     137             :                         nsIAtom* aAttribute, int32_t aModType,
     138             :                         const nsAttrValue* aOldValue);
     139             : 
     140             :   nsresult ReparentStyleContext(nsIFrame* aFrame);
     141             : 
     142             :   /**
     143             :    * Gets the appropriate frame given a content and a pseudo-element tag.
     144             :    *
     145             :    * Right now only supports a null tag, before or after. If the pseudo-element
     146             :    * is not null, the content needs to be an element.
     147             :    */
     148             :   static nsIFrame* FrameForPseudoElement(const Element* aElement,
     149             :                                          nsIAtom* aPseudoTagOrNull);
     150             : 
     151             :   /**
     152             :    * Clears the ServoElementData and HasDirtyDescendants from all elements
     153             :    * in the subtree rooted at aElement.
     154             :    */
     155             :   static void ClearServoDataFromSubtree(Element* aElement);
     156             : 
     157             :   /**
     158             :    * Clears HasDirtyDescendants and RestyleData from all elements in the
     159             :    * subtree rooted at aElement.
     160             :    */
     161             :   static void ClearRestyleStateFromSubtree(Element* aElement);
     162             : 
     163             :   /**
     164             :    * Posts restyle hints for animations.
     165             :    * This is only called for the second traversal for CSS animations during
     166             :    * updating CSS animations in a SequentialTask.
     167             :    * This function does neither register a refresh observer nor flag that a
     168             :    * style flush is needed since this function is supposed to be called during
     169             :    * restyling process and this restyle event will be processed in the second
     170             :    * traversal of the same restyling process.
     171             :    */
     172             :   static void PostRestyleEventForAnimations(dom::Element* aElement,
     173             :                                             CSSPseudoElementType aPseudoType,
     174             :                                             nsRestyleHint aRestyleHint);
     175             : protected:
     176           0 :   ~ServoRestyleManager() override
     177           0 :   {
     178           0 :     MOZ_ASSERT(!mReentrantChanges);
     179           0 :   }
     180             : 
     181             : private:
     182             :   /**
     183             :    * Performs post-Servo-traversal processing on this element and its
     184             :    * descendants.
     185             :    *
     186             :    * Returns whether any style did actually change. There may be cases where we
     187             :    * didn't need to change any style after all, for example, when a content
     188             :    * attribute changes that happens not to have any effect on the style of that
     189             :    * element or any descendant or sibling.
     190             :    */
     191             :   bool ProcessPostTraversal(Element* aElement,
     192             :                             nsStyleContext* aParentContext,
     193             :                             ServoRestyleState& aRestyleState);
     194             : 
     195             :   struct TextPostTraversalState;
     196             :   bool ProcessPostTraversalForText(nsIContent* aTextNode,
     197             :                                    TextPostTraversalState& aState);
     198             : 
     199           0 :   inline ServoStyleSet* StyleSet() const
     200             :   {
     201           0 :     MOZ_ASSERT(PresContext()->StyleSet()->IsServo(),
     202             :                "ServoRestyleManager should only be used with a Servo-flavored "
     203             :                "style backend");
     204           0 :     return PresContext()->StyleSet()->AsServo();
     205             :   }
     206             : 
     207           0 :   const SnapshotTable& Snapshots() const { return mSnapshots; }
     208             :   void ClearSnapshots();
     209             :   ServoElementSnapshot& SnapshotFor(mozilla::dom::Element* aElement);
     210             :   void TakeSnapshotForAttributeChange(mozilla::dom::Element* aElement,
     211             :                                       int32_t aNameSpaceID,
     212             :                                       nsIAtom* aAttribute);
     213             : 
     214             :   void DoProcessPendingRestyles(TraversalRestyleBehavior aRestyleBehavior);
     215             : 
     216             :   // We use a separate data structure from nsStyleChangeList because we need a
     217             :   // frame to create nsStyleChangeList entries, and the primary frame may not be
     218             :   // attached yet.
     219           0 :   struct ReentrantChange {
     220             :     nsCOMPtr<nsIContent> mContent;
     221             :     nsChangeHint mHint;
     222             :   };
     223             :   typedef AutoTArray<ReentrantChange, 10> ReentrantChangeList;
     224             : 
     225             :   // Only non-null while processing change hints. See the comment in
     226             :   // ProcessPendingRestyles.
     227             :   ReentrantChangeList* mReentrantChanges;
     228             : 
     229             :   // We use this flag to track if the current restyle contains any non-animation
     230             :   // update, which triggers a normal restyle, and so there might be any new
     231             :   // transition created later. Therefore, if this flag is true, we need to
     232             :   // increase mAnimationGeneration before creating new transitions, so their
     233             :   // creation sequence will be correct.
     234             :   bool mHaveNonAnimationRestyles = false;
     235             : 
     236             :   // Set to true when posting restyle events triggered by CSS rule changes.
     237             :   // This flag is cleared once ProcessPendingRestyles has completed.
     238             :   // When we process a traversal all descendants elements of the document
     239             :   // triggered by CSS rule changes, we will need to update all elements with
     240             :   // CSS animations.  We propagate TraversalRestyleBehavior::ForCSSRuleChanges
     241             :   // to traversal function if this flag is set.
     242             :   bool mRestyleForCSSRuleChanges = false;
     243             : 
     244             :   // A hashtable with the elements that have changed state or attributes, in
     245             :   // order to calculate restyle hints during the traversal.
     246             :   SnapshotTable mSnapshots;
     247             : };
     248             : 
     249             : } // namespace mozilla
     250             : 
     251             : #endif // mozilla_ServoRestyleManager_h

Generated by: LCOV version 1.13