DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_gfx_layers_LayerAttributes_h
#define mozilla_gfx_layers_LayerAttributes_h

#include "mozilla/Maybe.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/layers/LayersTypes.h"

namespace IPC {
template <typename T>
struct ParamTraits;
}  // namespace IPC

namespace mozilla {
namespace layers {

// Data stored for scroll thumb container layers.
struct ScrollThumbData {
  ScrollThumbData() : mThumbRatio(0.0f), mIsAsyncDraggable(false) {}
  ScrollThumbData(ScrollDirection aDirection, float aThumbRatio,
                  CSSCoord aThumbStart, CSSCoord aThumbLength,
                  bool aIsAsyncDraggable, CSSCoord aScrollTrackStart,
                  CSSCoord aScrollTrackLength)
      : mDirection(Some(aDirection)),
        mThumbRatio(aThumbRatio),
        mThumbStart(aThumbStart),
        mThumbLength(aThumbLength),
        mIsAsyncDraggable(aIsAsyncDraggable),
        mScrollTrackStart(aScrollTrackStart),
        mScrollTrackLength(aScrollTrackLength) {}

  Maybe<ScrollDirection> mDirection;
  // The scrollbar thumb ratio is the ratio of the thumb position (in the CSS
  // pixels of the scrollframe's parent's space) to the scroll position (in the
  // CSS pixels of the scrollframe's space).
  float mThumbRatio;
  CSSCoord mThumbStart;
  CSSCoord mThumbLength;
  // Whether the scrollbar thumb can be dragged asynchronously.
  bool mIsAsyncDraggable;
  CSSCoord mScrollTrackStart;
  CSSCoord mScrollTrackLength;

  bool operator==(const ScrollThumbData& aOther) const {
    return mDirection == aOther.mDirection &&
           mThumbRatio == aOther.mThumbRatio &&
           mThumbStart == aOther.mThumbStart &&
           mThumbLength == aOther.mThumbLength &&
           mIsAsyncDraggable == aOther.mIsAsyncDraggable &&
           mScrollTrackStart == aOther.mScrollTrackStart &&
           mScrollTrackLength == aOther.mScrollTrackLength;
  }
  bool operator!=(const ScrollThumbData& aOther) const {
    return !(*this == aOther);
  }
};

// Infrequently changing layer attributes that require no special
// serialization work.
class SimpleLayerAttributes final {
  friend struct IPC::ParamTraits<mozilla::layers::SimpleLayerAttributes>;

 public:
  SimpleLayerAttributes()
      : mTransformIsPerspective(false),
        mPostXScale(1.0f),
        mPostYScale(1.0f),
        mContentFlags(0),
        mOpacity(1.0f),
        mIsFixedPosition(false),
        mScrollbarTargetContainerId(FrameMetrics::NULL_SCROLL_ID),
        mMixBlendMode(gfx::CompositionOp::OP_OVER),
        mForceIsolatedGroup(false) {}

  //
  // Setters.
  // All set methods return true if values changed, false otherwise.
  //

  bool SetPostScale(float aXScale, float aYScale) {
    if (mPostXScale == aXScale && mPostYScale == aYScale) {
      return false;
    }
    mPostXScale = aXScale;
    mPostYScale = aYScale;
    return true;
  }
  bool SetContentFlags(uint32_t aFlags) {
    if (aFlags == mContentFlags) {
      return false;
    }
    mContentFlags = aFlags;
    return true;
  }
  bool SetOpacity(float aOpacity) {
    if (aOpacity == mOpacity) {
      return false;
    }
    mOpacity = aOpacity;
    return true;
  }
  bool SetIsFixedPosition(bool aFixedPosition) {
    if (mIsFixedPosition == aFixedPosition) {
      return false;
    }
    mIsFixedPosition = aFixedPosition;
    return true;
  }
  bool SetScrollThumbData(FrameMetrics::ViewID aScrollId,
                          const ScrollThumbData& aThumbData) {
    if (mScrollbarTargetContainerId == aScrollId && mThumbData == aThumbData) {
      return false;
    }
    mScrollbarTargetContainerId = aScrollId;
    mThumbData = aThumbData;
    return true;
  }
  bool SetScrollbarContainer(FrameMetrics::ViewID aScrollId,
                             ScrollDirection aDirection) {
    if (mScrollbarContainerDirection &&
        *mScrollbarContainerDirection == aDirection &&
        mScrollbarTargetContainerId == aScrollId) {
      return false;
    }
    mScrollbarContainerDirection = Some(aDirection);
    mScrollbarTargetContainerId = aScrollId;
    return true;
  }
  bool SetMixBlendMode(gfx::CompositionOp aMixBlendMode) {
    if (mMixBlendMode == aMixBlendMode) {
      return false;
    }
    mMixBlendMode = aMixBlendMode;
    return true;
  }
  bool SetForceIsolatedGroup(bool aForceIsolatedGroup) {
    if (mForceIsolatedGroup == aForceIsolatedGroup) {
      return false;
    }
    mForceIsolatedGroup = aForceIsolatedGroup;
    return true;
  }
  bool SetTransform(const gfx::Matrix4x4& aMatrix) {
    if (mTransform == aMatrix) {
      return false;
    }
    mTransform = aMatrix;
    return true;
  }
  bool SetTransformIsPerspective(bool aIsPerspective) {
    if (mTransformIsPerspective == aIsPerspective) {
      return false;
    }
    mTransformIsPerspective = aIsPerspective;
    return true;
  }
  bool SetScrolledClip(const Maybe<LayerClip>& aScrolledClip) {
    if (mScrolledClip == aScrolledClip) {
      return false;
    }
    mScrolledClip = aScrolledClip;
    return true;
  }
  bool SetFixedPositionData(FrameMetrics::ViewID aScrollId,
                            const LayerPoint& aAnchor, int32_t aSides) {
    if (mFixedPositionData && mFixedPositionData->mScrollId == aScrollId &&
        mFixedPositionData->mAnchor == aAnchor &&
        mFixedPositionData->mSides == aSides) {
      return false;
    }
    if (!mFixedPositionData) {
      mFixedPositionData.emplace();
    }
    mFixedPositionData->mScrollId = aScrollId;
    mFixedPositionData->mAnchor = aAnchor;
    mFixedPositionData->mSides = aSides;
    return true;
  }
  bool SetStickyPositionData(FrameMetrics::ViewID aScrollId,
                             LayerRectAbsolute aOuter,
                             LayerRectAbsolute aInner) {
    if (mStickyPositionData &&
        mStickyPositionData->mOuter.IsEqualEdges(aOuter) &&
        mStickyPositionData->mInner.IsEqualEdges(aInner)) {
      return false;
    }
    if (!mStickyPositionData) {
      mStickyPositionData.emplace();
    }
    mStickyPositionData->mScrollId = aScrollId;
    mStickyPositionData->mOuter = aOuter;
    mStickyPositionData->mInner = aInner;
    return true;
  }

  // This returns true if scrolling info is equivalent for the purposes of
  // APZ hit testing.
  bool HitTestingInfoIsEqual(const SimpleLayerAttributes& aOther) const {
    if (mScrollbarContainerDirection != aOther.mScrollbarContainerDirection) {
      return false;
    }
    if (mScrollbarTargetContainerId != aOther.mScrollbarTargetContainerId) {
      return false;
    }
    if (mThumbData != aOther.mThumbData) {
      return false;
    }
    if (FixedPositionScrollContainerId() !=
        aOther.FixedPositionScrollContainerId()) {
      return false;
    }
    if (mTransform != aOther.mTransform) {
      return false;
    }
    return true;
  }

  //
  // Getters.
  //

  float PostXScale() const { return mPostXScale; }
  float PostYScale() const { return mPostYScale; }
  uint32_t ContentFlags() const { return mContentFlags; }
  float Opacity() const { return mOpacity; }
  bool IsFixedPosition() const { return mIsFixedPosition; }
  FrameMetrics::ViewID ScrollbarTargetContainerId() const {
    return mScrollbarTargetContainerId;
  }
  const ScrollThumbData& ThumbData() const { return mThumbData; }
  Maybe<ScrollDirection> GetScrollbarContainerDirection() const {
    return mScrollbarContainerDirection;
  }
  gfx::CompositionOp MixBlendMode() const { return mMixBlendMode; }
  bool ForceIsolatedGroup() const { return mForceIsolatedGroup; }
  const gfx::Matrix4x4& Transform() const { return mTransform; }
  bool TransformIsPerspective() const { return mTransformIsPerspective; }
  const Maybe<LayerClip>& ScrolledClip() const { return mScrolledClip; }
  FrameMetrics::ViewID FixedPositionScrollContainerId() const {
    return mFixedPositionData ? mFixedPositionData->mScrollId
                              : FrameMetrics::NULL_SCROLL_ID;
  }
  LayerPoint FixedPositionAnchor() const {
    return mFixedPositionData ? mFixedPositionData->mAnchor : LayerPoint();
  }
  int32_t FixedPositionSides() const {
    return mFixedPositionData ? mFixedPositionData->mSides : eSideBitsNone;
  }
  bool IsStickyPosition() const { return !!mStickyPositionData; }
  FrameMetrics::ViewID StickyScrollContainerId() const {
    return mStickyPositionData->mScrollId;
  }
  const LayerRectAbsolute& StickyScrollRangeOuter() const {
    return mStickyPositionData->mOuter;
  }
  const LayerRectAbsolute& StickyScrollRangeInner() const {
    return mStickyPositionData->mInner;
  }

  bool operator==(const SimpleLayerAttributes& aOther) const {
    return mTransform == aOther.mTransform &&
           mTransformIsPerspective == aOther.mTransformIsPerspective &&
           mScrolledClip == aOther.mScrolledClip &&
           mPostXScale == aOther.mPostXScale &&
           mPostYScale == aOther.mPostYScale &&
           mContentFlags == aOther.mContentFlags &&
           mOpacity == aOther.mOpacity &&
           mIsFixedPosition == aOther.mIsFixedPosition &&
           mScrollbarTargetContainerId == aOther.mScrollbarTargetContainerId &&
           mThumbData == aOther.mThumbData &&
           mScrollbarContainerDirection ==
               aOther.mScrollbarContainerDirection &&
           mMixBlendMode == aOther.mMixBlendMode &&
           mForceIsolatedGroup == aOther.mForceIsolatedGroup;
  }

 private:
  gfx::Matrix4x4 mTransform;
  bool mTransformIsPerspective;
  Maybe<LayerClip> mScrolledClip;
  float mPostXScale;
  float mPostYScale;
  uint32_t mContentFlags;
  float mOpacity;
  bool mIsFixedPosition;
  uint64_t mScrollbarTargetContainerId;
  ScrollThumbData mThumbData;
  Maybe<ScrollDirection> mScrollbarContainerDirection;
  gfx::CompositionOp mMixBlendMode;
  bool mForceIsolatedGroup;

  struct FixedPositionData {
    FrameMetrics::ViewID mScrollId;
    LayerPoint mAnchor;
    int32_t mSides;
  };
  Maybe<FixedPositionData> mFixedPositionData;

  struct StickyPositionData {
    FrameMetrics::ViewID mScrollId;
    LayerRectAbsolute mOuter;
    LayerRectAbsolute mInner;
  };
  Maybe<StickyPositionData> mStickyPositionData;

  // This class may only contain plain-old-data members that can be safely
  // copied over IPC. Make sure to add new members to operator ==.
};

}  // namespace layers
}  // namespace mozilla

#endif  // mozilla_gfx_layers_LayerAttributes_h