layout/base/DisplayListClipState.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/DisplayListClipState.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "DisplayListClipState.h"
    1.10 +
    1.11 +#include "nsDisplayList.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +
    1.15 +const DisplayItemClip*
    1.16 +DisplayListClipState::GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder)
    1.17 +{
    1.18 +  if (mCurrentCombinedClip) {
    1.19 +    return mCurrentCombinedClip;
    1.20 +  }
    1.21 +  if (!mClipContentDescendants && !mClipContainingBlockDescendants) {
    1.22 +    return nullptr;
    1.23 +  }
    1.24 +  if (mClipContentDescendants) {
    1.25 +    if (mClipContainingBlockDescendants) {
    1.26 +      DisplayItemClip intersection = *mClipContentDescendants;
    1.27 +      intersection.IntersectWith(*mClipContainingBlockDescendants);
    1.28 +      mCurrentCombinedClip = aBuilder->AllocateDisplayItemClip(intersection);
    1.29 +    } else {
    1.30 +      mCurrentCombinedClip =
    1.31 +        aBuilder->AllocateDisplayItemClip(*mClipContentDescendants);
    1.32 +    }
    1.33 +  } else {
    1.34 +    mCurrentCombinedClip =
    1.35 +      aBuilder->AllocateDisplayItemClip(*mClipContainingBlockDescendants);
    1.36 +  }
    1.37 +  return mCurrentCombinedClip;
    1.38 +}
    1.39 +
    1.40 +void
    1.41 +DisplayListClipState::ClipContainingBlockDescendants(const nsRect& aRect,
    1.42 +                                                     const nscoord* aRadii,
    1.43 +                                                     DisplayItemClip& aClipOnStack)
    1.44 +{
    1.45 +  if (aRadii) {
    1.46 +    aClipOnStack.SetTo(aRect, aRadii);
    1.47 +  } else {
    1.48 +    aClipOnStack.SetTo(aRect);
    1.49 +  }
    1.50 +  if (mClipContainingBlockDescendants) {
    1.51 +    aClipOnStack.IntersectWith(*mClipContainingBlockDescendants);
    1.52 +  }
    1.53 +  mClipContainingBlockDescendants = &aClipOnStack;
    1.54 +  mCurrentCombinedClip = nullptr;
    1.55 +}
    1.56 +
    1.57 +void
    1.58 +DisplayListClipState::ClipContentDescendants(const nsRect& aRect,
    1.59 +                                             const nscoord* aRadii,
    1.60 +                                             DisplayItemClip& aClipOnStack)
    1.61 +{
    1.62 +  if (aRadii) {
    1.63 +    aClipOnStack.SetTo(aRect, aRadii);
    1.64 +  } else {
    1.65 +    aClipOnStack.SetTo(aRect);
    1.66 +  }
    1.67 +  if (mClipContentDescendants) {
    1.68 +    aClipOnStack.IntersectWith(*mClipContentDescendants);
    1.69 +  }
    1.70 +  mClipContentDescendants = &aClipOnStack;
    1.71 +  mCurrentCombinedClip = nullptr;
    1.72 +}
    1.73 +
    1.74 +void
    1.75 +DisplayListClipState::ClipContainingBlockDescendantsToContentBox(nsDisplayListBuilder* aBuilder,
    1.76 +                                                                 nsIFrame* aFrame,
    1.77 +                                                                 DisplayItemClip& aClipOnStack,
    1.78 +                                                                 uint32_t aFlags)
    1.79 +{
    1.80 +  nscoord radii[8];
    1.81 +  bool hasBorderRadius = aFrame->GetContentBoxBorderRadii(radii);
    1.82 +  if (!hasBorderRadius && (aFlags & ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT)) {
    1.83 +    return;
    1.84 +  }
    1.85 +
    1.86 +  nsRect clipRect = aFrame->GetContentRectRelativeToSelf() +
    1.87 +    aBuilder->ToReferenceFrame(aFrame);
    1.88 +  // If we have a border-radius, we have to clip our content to that
    1.89 +  // radius.
    1.90 +  ClipContainingBlockDescendants(clipRect, hasBorderRadius ? radii : nullptr,
    1.91 +                                 aClipOnStack);
    1.92 +}
    1.93 +
    1.94 +DisplayListClipState::AutoSaveRestore::AutoSaveRestore(nsDisplayListBuilder* aBuilder)
    1.95 +  : mState(aBuilder->ClipState())
    1.96 +  , mSavedState(aBuilder->ClipState())
    1.97 +  , mClipUsed(false)
    1.98 +  , mRestored(false)
    1.99 +{}
   1.100 +
   1.101 +}

mercurial