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