summaryrefslogtreecommitdiffstats
path: root/cc/input/main_thread_scrolling_reason.h
blob: 1f384ebfcee48d60cee17f942d8d3128b5c1e632 (plain)
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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_
#define CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_

namespace cc {

// Ensure this stays in sync with MainThreadScrollingReason in histograms.xml.
// When adding a new MainThreadScrollingReason, make sure the corresponding
// [MainThread/Compositor]CanSetScrollReasons function is also updated.
struct MainThreadScrollingReason {
  // Non-transient scrolling reasons.
  enum : uint32_t { kNotScrollingOnMain = 0 };
  enum : uint32_t { kHasBackgroundAttachmentFixedObjects = 1 << 0 };
  enum : uint32_t { kHasNonLayerViewportConstrainedObjects = 1 << 1 };
  enum : uint32_t { kThreadedScrollingDisabled = 1 << 2 };
  enum : uint32_t { kScrollbarScrolling = 1 << 3 };
  enum : uint32_t { kPageOverlay = 1 << 4 };
  enum : uint32_t { kAnimatingScrollOnMainThread = 1 << 13 };

  // Transient scrolling reasons. These are computed for each scroll begin.
  enum : uint32_t { kNonFastScrollableRegion = 1 << 5 };
  enum : uint32_t { kEventHandlers = 1 << 6 };
  enum : uint32_t { kFailedHitTest = 1 << 7 };
  enum : uint32_t { kNoScrollingLayer = 1 << 8 };
  enum : uint32_t { kNotScrollable = 1 << 9 };
  enum : uint32_t { kContinuingMainThreadScroll = 1 << 10 };
  enum : uint32_t { kNonInvertibleTransform = 1 << 11 };
  enum : uint32_t { kPageBasedScrolling = 1 << 12 };

  // The number of flags in this struct (excluding itself).
  enum : uint32_t { kMainThreadScrollingReasonCount = 15 };

  // Returns true if the given MainThreadScrollingReason can be set by the main
  // thread.
  static bool MainThreadCanSetScrollReasons(uint32_t reasons) {
    uint32_t reasons_set_by_main_thread =
        kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects |
        kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled |
        kScrollbarScrolling | kPageOverlay | kAnimatingScrollOnMainThread;
    return (reasons & reasons_set_by_main_thread) == reasons;
  }

  // Returns true if the given MainThreadScrollingReason can be set by the
  // compositor.
  static bool CompositorCanSetScrollReasons(uint32_t reasons) {
    uint32_t reasons_set_by_compositor =
        kNonFastScrollableRegion | kEventHandlers | kFailedHitTest |
        kNoScrollingLayer | kNotScrollable | kContinuingMainThreadScroll |
        kNonInvertibleTransform | kPageBasedScrolling;
    return (reasons & reasons_set_by_compositor) == reasons;
  }
};

}  // namespace cc

#endif  // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_