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 /* struct containing the output from nsIFrame::Reflow */
9 #include "mozilla/ReflowOutput.h"
10 #include "mozilla/ReflowInput.h"
14 static bool IsValidOverflowRect(const nsRect
& aRect
) {
15 // `IsEmpty` in the context of `nsRect` means "width OR height is zero."
16 // However, in the context of overflow, the rect having one axis as zero is
17 // NOT considered empty.
18 if (MOZ_LIKELY(!aRect
.IsEmpty())) {
22 // Be defensive and consider rects with any negative size as invalid.
23 return !aRect
.IsEqualEdges(nsRect()) && aRect
.Width() >= 0 &&
28 nsRect
OverflowAreas::GetOverflowClipRect(const nsRect
& aRectToClip
,
29 const nsRect
& aBounds
,
30 PhysicalAxes aClipAxes
,
31 const nsSize
& aOverflowMargin
) {
32 auto inflatedBounds
= aBounds
;
33 inflatedBounds
.Inflate(aOverflowMargin
);
34 auto clip
= aRectToClip
;
35 if (aClipAxes
& PhysicalAxes::Vertical
) {
36 clip
.y
= inflatedBounds
.y
;
37 clip
.height
= inflatedBounds
.height
;
39 if (aClipAxes
& PhysicalAxes::Horizontal
) {
40 clip
.x
= inflatedBounds
.x
;
41 clip
.width
= inflatedBounds
.width
;
47 void OverflowAreas::ApplyOverflowClippingOnRect(nsRect
& aOverflowRect
,
48 const nsRect
& aBounds
,
49 PhysicalAxes aClipAxes
,
50 const nsSize
& aOverflowMargin
) {
51 aOverflowRect
= aOverflowRect
.Intersect(
52 GetOverflowClipRect(aOverflowRect
, aBounds
, aClipAxes
, aOverflowMargin
));
55 void OverflowAreas::UnionWith(const OverflowAreas
& aOther
) {
56 if (IsValidOverflowRect(aOther
.InkOverflow())) {
57 InkOverflow().UnionRect(InkOverflow(), aOther
.InkOverflow());
59 if (IsValidOverflowRect(aOther
.ScrollableOverflow())) {
60 ScrollableOverflow().UnionRect(ScrollableOverflow(),
61 aOther
.ScrollableOverflow());
65 void OverflowAreas::UnionAllWith(const nsRect
& aRect
) {
66 if (!IsValidOverflowRect(aRect
)) {
67 // Same as `UnionWith()` - avoid losing information.
70 InkOverflow().UnionRect(InkOverflow(), aRect
);
71 ScrollableOverflow().UnionRect(ScrollableOverflow(), aRect
);
74 void OverflowAreas::SetAllTo(const nsRect
& aRect
) {
75 InkOverflow() = aRect
;
76 ScrollableOverflow() = aRect
;
79 ReflowOutput::ReflowOutput(const ReflowInput
& aReflowInput
)
80 : ReflowOutput(aReflowInput
.GetWritingMode()) {}
82 void ReflowOutput::SetOverflowAreasToDesiredBounds() {
83 mOverflowAreas
.SetAllTo(nsRect(0, 0, Width(), Height()));
86 void ReflowOutput::UnionOverflowAreasWithDesiredBounds() {
87 mOverflowAreas
.UnionAllWith(nsRect(0, 0, Width(), Height()));
90 } // namespace mozilla