|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "DisplayListClipState.h" |
|
7 |
|
8 #include "nsDisplayList.h" |
|
9 |
|
10 namespace mozilla { |
|
11 |
|
12 const DisplayItemClip* |
|
13 DisplayListClipState::GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder) |
|
14 { |
|
15 if (mCurrentCombinedClip) { |
|
16 return mCurrentCombinedClip; |
|
17 } |
|
18 if (!mClipContentDescendants && !mClipContainingBlockDescendants) { |
|
19 return nullptr; |
|
20 } |
|
21 if (mClipContentDescendants) { |
|
22 if (mClipContainingBlockDescendants) { |
|
23 DisplayItemClip intersection = *mClipContentDescendants; |
|
24 intersection.IntersectWith(*mClipContainingBlockDescendants); |
|
25 mCurrentCombinedClip = aBuilder->AllocateDisplayItemClip(intersection); |
|
26 } else { |
|
27 mCurrentCombinedClip = |
|
28 aBuilder->AllocateDisplayItemClip(*mClipContentDescendants); |
|
29 } |
|
30 } else { |
|
31 mCurrentCombinedClip = |
|
32 aBuilder->AllocateDisplayItemClip(*mClipContainingBlockDescendants); |
|
33 } |
|
34 return mCurrentCombinedClip; |
|
35 } |
|
36 |
|
37 void |
|
38 DisplayListClipState::ClipContainingBlockDescendants(const nsRect& aRect, |
|
39 const nscoord* aRadii, |
|
40 DisplayItemClip& aClipOnStack) |
|
41 { |
|
42 if (aRadii) { |
|
43 aClipOnStack.SetTo(aRect, aRadii); |
|
44 } else { |
|
45 aClipOnStack.SetTo(aRect); |
|
46 } |
|
47 if (mClipContainingBlockDescendants) { |
|
48 aClipOnStack.IntersectWith(*mClipContainingBlockDescendants); |
|
49 } |
|
50 mClipContainingBlockDescendants = &aClipOnStack; |
|
51 mCurrentCombinedClip = nullptr; |
|
52 } |
|
53 |
|
54 void |
|
55 DisplayListClipState::ClipContentDescendants(const nsRect& aRect, |
|
56 const nscoord* aRadii, |
|
57 DisplayItemClip& aClipOnStack) |
|
58 { |
|
59 if (aRadii) { |
|
60 aClipOnStack.SetTo(aRect, aRadii); |
|
61 } else { |
|
62 aClipOnStack.SetTo(aRect); |
|
63 } |
|
64 if (mClipContentDescendants) { |
|
65 aClipOnStack.IntersectWith(*mClipContentDescendants); |
|
66 } |
|
67 mClipContentDescendants = &aClipOnStack; |
|
68 mCurrentCombinedClip = nullptr; |
|
69 } |
|
70 |
|
71 void |
|
72 DisplayListClipState::ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder, |
|
73 nsIFrame* aFrame, |
|
74 DisplayItemClip& aClipOnStack, |
|
75 uint32_t aFlags) |
|
76 { |
|
77 nscoord radii[8]; |
|
78 bool hasBorderRadius = aFrame->GetContentBoxBorderRadii(radii); |
|
79 if (!hasBorderRadius && (aFlags & ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT)) { |
|
80 return; |
|
81 } |
|
82 |
|
83 nsRect clipRect = aFrame->GetContentRectRelativeToSelf() + |
|
84 aBuilder->ToReferenceFrame(aFrame); |
|
85 // If we have a border-radius, we have to clip our content to that |
|
86 // radius. |
|
87 ClipContainingBlockDescendants(clipRect, hasBorderRadius ? radii : nullptr, |
|
88 aClipOnStack); |
|
89 } |
|
90 |
|
91 DisplayListClipState::AutoSaveRestore::AutoSaveRestore(nsDisplayListBuilder* aBuilder) |
|
92 : mState(aBuilder->ClipState()) |
|
93 , mSavedState(aBuilder->ClipState()) |
|
94 , mClipUsed(false) |
|
95 , mRestored(false) |
|
96 {} |
|
97 |
|
98 } |