Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/generic/nsAbsoluteContainingBlock.h
Line
Count
Source (jump to first uncovered line)
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
 * code for managing absolutely positioned children of a rendering
9
 * object that is a containing block for them
10
 */
11
12
#ifndef nsAbsoluteContainingBlock_h___
13
#define nsAbsoluteContainingBlock_h___
14
15
#include "nsFrameList.h"
16
#include "nsIFrame.h"
17
#include "mozilla/TypedEnumBits.h"
18
19
class nsContainerFrame;
20
class nsPresContext;
21
22
/**
23
 * This class contains the logic for being an absolute containing block.  This
24
 * class is used within viewport frames (for frames representing content with
25
 * fixed position) and blocks (for frames representing absolutely positioned
26
 * content), since each set of frames is absolutely positioned with respect to
27
 * its parent.
28
 *
29
 * There is no principal child list, just a named child list which contains
30
 * the absolutely positioned frames (kAbsoluteList or kFixedList).
31
 *
32
 * All functions include as the first argument the frame that is delegating
33
 * the request.
34
 */
35
class nsAbsoluteContainingBlock
36
{
37
  using ReflowInput = mozilla::ReflowInput;
38
39
public:
40
  typedef nsIFrame::ChildListID ChildListID;
41
42
  explicit nsAbsoluteContainingBlock(ChildListID aChildListID)
43
#ifdef DEBUG
44
    : mChildListID(aChildListID)
45
#endif
46
0
  {
47
0
    MOZ_ASSERT(mChildListID == nsIFrame::kAbsoluteList ||
48
0
               mChildListID == nsIFrame::kFixedList,
49
0
               "should either represent position:fixed or absolute content");
50
0
  }
51
52
0
  const nsFrameList& GetChildList() const { return mAbsoluteFrames; }
53
  void AppendChildList(nsTArray<nsIFrame::ChildList>* aLists,
54
                       ChildListID aListID) const
55
0
  {
56
0
    NS_ASSERTION(aListID == mChildListID, "wrong list ID");
57
0
    GetChildList().AppendIfNonempty(aLists, aListID);
58
0
  }
59
60
  void SetInitialChildList(nsIFrame*       aDelegatingFrame,
61
                           ChildListID     aListID,
62
                           nsFrameList&    aChildList);
63
  void AppendFrames(nsIFrame*      aDelegatingFrame,
64
                    ChildListID    aListID,
65
                    nsFrameList&   aFrameList);
66
  void InsertFrames(nsIFrame*      aDelegatingFrame,
67
                    ChildListID    aListID,
68
                    nsIFrame*      aPrevFrame,
69
                    nsFrameList&   aFrameList);
70
  void RemoveFrame(nsIFrame*      aDelegatingFrame,
71
                   ChildListID    aListID,
72
                   nsIFrame*      aOldFrame);
73
74
  enum class AbsPosReflowFlags {
75
    eConstrainHeight   = 0x1,
76
    eCBWidthChanged    = 0x2,
77
    eCBHeightChanged   = 0x4,
78
    eCBWidthAndHeightChanged = eCBWidthChanged | eCBHeightChanged,
79
    eIsGridContainerCB = 0x8,
80
  };
81
82
  /**
83
   * Called by the delegating frame after it has done its reflow first. This
84
   * function will reflow any absolutely positioned child frames that need to
85
   * be reflowed, e.g., because the absolutely positioned child frame has
86
   * 'auto' for an offset, or a percentage based width or height.
87
   *
88
   * @param aOverflowAreas, if non-null, is unioned with (in the local
89
   * coordinate space) the overflow areas of the absolutely positioned
90
   * children.
91
   *
92
   * @param aReflowStatus is assumed to be already-initialized, e.g. with the
93
   * status of the delegating frame's main reflow. This function merges in the
94
   * statuses of the absolutely positioned children's reflows.
95
   *
96
   * @param aFlags zero or more AbsPosReflowFlags
97
   */
98
  void Reflow(nsContainerFrame*        aDelegatingFrame,
99
              nsPresContext*           aPresContext,
100
              const ReflowInput& aReflowInput,
101
              nsReflowStatus&          aReflowStatus,
102
              const nsRect&            aContainingBlock,
103
              AbsPosReflowFlags        aFlags,
104
              nsOverflowAreas*         aOverflowAreas);
105
106
  using PostDestroyData = nsIFrame::PostDestroyData;
107
  void DestroyFrames(nsIFrame* aDelegatingFrame,
108
                     nsIFrame* aDestructRoot,
109
                     PostDestroyData& aPostDestroyData);
110
111
0
  bool HasAbsoluteFrames() const { return mAbsoluteFrames.NotEmpty(); }
112
113
  /**
114
   * Mark our size-dependent absolute frames with NS_FRAME_HAS_DIRTY_CHILDREN
115
   * so that we'll make sure to reflow them.
116
   */
117
  void MarkSizeDependentFramesDirty();
118
119
  /**
120
   * Mark all our absolute frames with NS_FRAME_IS_DIRTY.
121
   */
122
  void MarkAllFramesDirty();
123
124
protected:
125
  /**
126
   * Returns true if the position of aFrame depends on the position of
127
   * its placeholder or if the position or size of aFrame depends on a
128
   * containing block dimension that changed.
129
   */
130
  bool FrameDependsOnContainer(nsIFrame* aFrame, bool aCBWidthChanged,
131
                               bool aCBHeightChanged);
132
133
  /**
134
   * After an abspos child's size is known, this method can be used to
135
   * resolve size-dependent values in the ComputedLogicalOffsets on its
136
   * reflow state. (This may involve resolving the inline dimension of
137
   * aLogicalCBSize, too; hence, that variable is an in/outparam.)
138
   *
139
   * aKidSize, aMargin, aOffsets, and aLogicalCBSize are all expected to be
140
   * represented in terms of the absolute containing block's writing-mode.
141
   */
142
  void ResolveSizeDependentOffsets(nsPresContext* aPresContext,
143
                                   ReflowInput& aKidReflowInput,
144
                                   const mozilla::LogicalSize& aKidSize,
145
                                   const mozilla::LogicalMargin& aMargin,
146
                                   mozilla::LogicalMargin* aOffsets,
147
                                   mozilla::LogicalSize* aLogicalCBSize);
148
149
  void ReflowAbsoluteFrame(nsIFrame*                aDelegatingFrame,
150
                           nsPresContext*           aPresContext,
151
                           const ReflowInput& aReflowInput,
152
                           const nsRect&            aContainingBlockRect,
153
                           AbsPosReflowFlags        aFlags,
154
                           nsIFrame*                aKidFrame,
155
                           nsReflowStatus&          aStatus,
156
                           nsOverflowAreas*         aOverflowAreas);
157
158
  /**
159
   * Mark our absolute frames dirty.
160
   * @param aMarkAllDirty if true, all will be marked with NS_FRAME_IS_DIRTY.
161
   * Otherwise, the size-dependant ones will be marked with
162
   * NS_FRAME_HAS_DIRTY_CHILDREN.
163
   */
164
  void DoMarkFramesDirty(bool aMarkAllDirty);
165
166
protected:
167
  nsFrameList mAbsoluteFrames;  // additional named child list
168
169
#ifdef DEBUG
170
  ChildListID const mChildListID; // kFixedList or kAbsoluteList
171
#endif
172
};
173
174
namespace mozilla {
175
  MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(nsAbsoluteContainingBlock::AbsPosReflowFlags)
176
}
177
#endif /* nsnsAbsoluteContainingBlock_h___ */