tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsStyleChangeList.cpp (3037B)


      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 /*
      8 * a list of the recomputation that needs to be done in response to a
      9 * style change
     10 */
     11 
     12 #include "nsStyleChangeList.h"
     13 
     14 #include "mozilla/dom/ElementInlines.h"
     15 #include "nsCSSFrameConstructor.h"
     16 #include "nsIContent.h"
     17 #include "nsIFrame.h"
     18 
     19 void nsStyleChangeList::AppendChange(nsIFrame* aFrame, nsIContent* aContent,
     20                                     nsChangeHint aHint) {
     21  MOZ_ASSERT(aFrame || (aHint & nsChangeHint_ReconstructFrame),
     22             "must have frame");
     23  MOZ_ASSERT(aHint, "No hint to process?");
     24  MOZ_ASSERT(!(aHint & nsChangeHint_NeutralChange),
     25             "Neutral changes do not need extra processing, "
     26             "and should be stripped out");
     27  MOZ_ASSERT(aContent || !(aHint & nsChangeHint_ReconstructFrame),
     28             "must have content");
     29  // XXXbz we should make this take Element instead of nsIContent
     30  MOZ_ASSERT(
     31      !aContent || aContent->IsElement() ||
     32          // display:contents elements posts the changes for their children:
     33          (aFrame && aContent->GetFlattenedTreeParentElementForStyle() &&
     34           Servo_Element_IsDisplayContents(
     35               aContent->GetFlattenedTreeParentElementForStyle())) ||
     36          (aContent->IsText() && aContent->HasFlag(NODE_NEEDS_FRAME) &&
     37           aHint & nsChangeHint_ReconstructFrame),
     38      "Shouldn't be trying to restyle non-elements directly, "
     39      "except if it's a display:contents child or a text node "
     40      "doing lazy frame construction");
     41  MOZ_ASSERT(!(aHint & nsChangeHint_AllReflowHints) ||
     42                 (aHint & nsChangeHint_NeedReflow),
     43             "Reflow hint bits set without actually asking for a reflow");
     44 
     45  if (aHint & nsChangeHint_ReconstructFrame) {
     46    // If Servo fires reconstruct at a node, it is the only change hint fired at
     47    // that node.
     48 
     49    // Note: Because we check whether |aHint| is a reconstruct above (which is
     50    // necessary to avoid debug test timeouts on certain crashtests), this check
     51    // will not find bugs where we add a non-reconstruct hint for an element
     52    // after adding a reconstruct. This is ok though, since
     53    // ProcessRestyledFrames will handle that case via mDestroyedFrames.
     54 #ifdef DEBUG
     55    for (size_t i = 0; i < Length(); ++i) {
     56      MOZ_ASSERT(aContent != (*this)[i].mContent ||
     57                     !((*this)[i].mHint & nsChangeHint_ReconstructFrame),
     58                 "Should not append a non-ReconstructFrame hint after \
     59                 appending a ReconstructFrame hint for the same \
     60                 content.");
     61    }
     62 #endif
     63  }
     64 
     65  if (!IsEmpty() && aFrame && aFrame == LastElement().mFrame) {
     66    LastElement().mHint |= aHint;
     67    return;
     68  }
     69 
     70  AppendElement(nsStyleChangeData{aFrame, aContent, aHint});
     71 }