Bug 1709347 - Add CanvasRenderingContext2D.reset(). r=lsalzman,webidl,smaug
[gecko.git] / layout / base / DepthOrderedFrameList.cpp
blob3c9826d954cf9c19469ccf2a6cdca6b240574cbd
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/. */
7 #include "DepthOrderedFrameList.h"
8 #include "nsIFrame.h"
9 #include "nsContainerFrame.h"
11 namespace mozilla {
13 void DepthOrderedFrameList::Add(nsIFrame* aFrame) {
14 // Is this root already scheduled for reflow?
15 // FIXME: This could possibly be changed to a uniqueness assertion, with some
16 // work in ResizeReflowIgnoreOverride (and maybe others?)
17 // FIXME(emilio): Should probably reuse the traversal for insertion.
18 if (Contains(aFrame)) {
19 // We don't expect frame to change depths.
20 MOZ_ASSERT(aFrame->GetDepthInFrameTree() ==
21 mList[mList.IndexOf(aFrame)].mDepth);
22 return;
25 mList.InsertElementSorted(
26 FrameAndDepth{aFrame, aFrame->GetDepthInFrameTree()},
27 FrameAndDepth::CompareByReverseDepth{});
30 void DepthOrderedFrameList::Remove(nsIFrame* aFrame) {
31 mList.RemoveElement(aFrame);
34 nsIFrame* DepthOrderedFrameList::PopShallowestRoot() {
35 // List is sorted in order of decreasing depth, so there are no shallower
36 // frames than the last one.
37 const FrameAndDepth& lastFAD = mList.PopLastElement();
38 nsIFrame* frame = lastFAD.mFrame;
39 // We don't expect frame to change depths.
40 MOZ_ASSERT(frame->GetDepthInFrameTree() == lastFAD.mDepth);
41 return frame;
44 bool DepthOrderedFrameList::FrameIsAncestorOfAnyElement(
45 nsIFrame* aFrame) const {
46 MOZ_ASSERT(aFrame);
48 // Look for a path from any element to aFrame, following GetParent(). This
49 // check mirrors what FrameNeedsReflow() would have done if the reflow root
50 // didn't get in the way.
51 for (nsIFrame* f : mList) {
52 do {
53 if (f == aFrame) {
54 return true;
56 f = f->GetParent();
57 } while (f);
60 return false;
63 } // namespace mozilla