1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CC_TREES_COMPOSITOR_COMMIT_DATA_H_
6 #define CC_TREES_COMPOSITOR_COMMIT_DATA_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "cc/cc_export.h"
12 #include "cc/input/browser_controls_state.h"
13 #include "cc/input/scroll_snap_data.h"
14 #include "cc/paint/element_id.h"
15 #include "cc/trees/layer_tree_host_client.h"
16 #include "ui/gfx/geometry/scroll_offset.h"
17 #include "ui/gfx/geometry/vector2d.h"
18 #include "ui/gfx/transform.h"
19 
20 namespace cc {
21 
22 class SwapPromise;
23 
24 struct CC_EXPORT CompositorCommitData {
25   CompositorCommitData();
26   CompositorCommitData(const CompositorCommitData&) = delete;
27   ~CompositorCommitData();
28 
29   CompositorCommitData& operator=(const CompositorCommitData&) = delete;
30 
31   struct CC_EXPORT ScrollUpdateInfo {
32     ScrollUpdateInfo();
33     ScrollUpdateInfo(ElementId id,
34                      gfx::ScrollOffset delta,
35                      base::Optional<TargetSnapAreaElementIds> snap_target_ids);
36     ScrollUpdateInfo(const ScrollUpdateInfo& other);
37     ScrollUpdateInfo& operator=(const ScrollUpdateInfo&);
38     ElementId element_id;
39     gfx::ScrollOffset scroll_delta;
40 
41     // The target snap area element ids of the scrolling element.
42     // This will have a value if the scrolled element's scroll node has snap
43     // container data and the scroll delta is non-zero.
44     base::Optional<TargetSnapAreaElementIds> snap_target_element_ids;
45 
46     bool operator==(const ScrollUpdateInfo& other) const {
47       return element_id == other.element_id &&
48              scroll_delta == other.scroll_delta &&
49              snap_target_element_ids == other.snap_target_element_ids;
50     }
51   };
52 
53   // The inner viewport scroll delta is kept separate since it's special.
54   // Because the inner (visual) viewport's maximum offset depends on the
55   // current page scale, the two must be committed at the same time to prevent
56   // clamping.
57   ScrollUpdateInfo inner_viewport_scroll;
58 
59   std::vector<ScrollUpdateInfo> scrolls;
60   float page_scale_delta;
61   bool is_pinch_gesture_active;
62 
63   // Elastic overscroll effect offset delta. This is used only on Mac and shows
64   // the pixels that the page is rubber-banned/stretched by.
65   gfx::Vector2dF elastic_overscroll_delta;
66 
67   // Unconsumed scroll delta used to send overscroll events to the latched
68   // element on the main thread;
69   gfx::Vector2dF overscroll_delta;
70 
71   // The element id of the node to which scrolling is latched. This is used to
72   // send overscroll/scrollend DOM events to proper targets whenever needed.
73   ElementId scroll_latched_element_id;
74 
75   float top_controls_delta;
76   float bottom_controls_delta;
77 
78   // Used to communicate scrollbar visibility from Impl thread to Blink.
79   // Scrollbar input is handled by Blink but the compositor thread animates
80   // opacity on scrollbars to fade them out when they're overlay. Blink needs
81   // to be told when they're faded out so it can stop handling input for
82   // invisible scrollbars.
83   struct CC_EXPORT ScrollbarsUpdateInfo {
84     ElementId element_id;
85     bool hidden = true;
86 
87     bool operator==(const ScrollbarsUpdateInfo& other) const {
88       return element_id == other.element_id && hidden == other.hidden;
89     }
90   };
91   std::vector<ScrollbarsUpdateInfo> scrollbars;
92 
93   std::vector<std::unique_ptr<SwapPromise>> swap_promises;
94   BrowserControlsState browser_controls_constraint;
95   bool browser_controls_constraint_changed;
96 
97   // Set to true when a scroll gesture being handled on the compositor has
98   // ended.
99   bool scroll_gesture_did_end;
100 
101   // Tracks whether there is an ongoing compositor-driven animation for a
102   // scroll.
103   bool ongoing_scroll_animation = false;
104 
105   // Tracks different methods of scrolling (e.g. wheel, touch, precision
106   // touchpad, etc.).
107   ManipulationInfo manipulation_info;
108 };
109 
110 }  // namespace cc
111 
112 #endif  // CC_TREES_COMPOSITOR_COMMIT_DATA_H_
113