Bug 1882703 [wpt PR 44848] - Update wpt metadata, a=testonly
[gecko.git] / gfx / layers / ScrollableLayerGuid.h
blobef3733eba0c23a49dbd0db55d788f80ec9c4150f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_SCROLLABLELAYERGUID_H
8 #define GFX_SCROLLABLELAYERGUID_H
10 #include <iosfwd> // for ostream
11 #include <stdint.h> // for uint8_t, uint32_t, uint64_t
12 #include "mozilla/layers/LayersTypes.h" // for LayersId
13 #include "nsHashKeys.h" // for nsUint64HashKey
15 namespace mozilla {
16 namespace layers {
18 /**
19 * This class allows us to uniquely identify a scrollable layer. The
20 * mLayersId identifies the layer tree (corresponding to a child process
21 * and/or tab) that the scrollable layer belongs to. The mPresShellId
22 * is a temporal identifier (corresponding to the document loaded that
23 * contains the scrollable layer, which may change over time). The
24 * mScrollId corresponds to the actual frame that is scrollable.
26 struct ScrollableLayerGuid {
27 // We use IDs to identify frames across processes.
28 typedef uint64_t ViewID;
29 typedef nsUint64HashKey ViewIDHashKey;
30 static const ViewID NULL_SCROLL_ID; // This container layer does not scroll.
31 static const ViewID START_SCROLL_ID = 2; // This is the ID that scrolling
32 // subframes will begin at.
34 LayersId mLayersId;
35 uint32_t mPresShellId;
36 ViewID mScrollId;
38 ScrollableLayerGuid();
40 ScrollableLayerGuid(LayersId aLayersId, uint32_t aPresShellId,
41 ViewID aScrollId);
43 ScrollableLayerGuid(const ScrollableLayerGuid& other) = default;
45 ~ScrollableLayerGuid() = default;
47 bool operator==(const ScrollableLayerGuid& other) const;
48 bool operator!=(const ScrollableLayerGuid& other) const;
49 bool operator<(const ScrollableLayerGuid& other) const;
51 friend std::ostream& operator<<(std::ostream& aOut,
52 const ScrollableLayerGuid& aGuid);
54 using Comparator = bool (*)(const ScrollableLayerGuid&,
55 const ScrollableLayerGuid&);
57 static bool EqualsIgnoringPresShell(const ScrollableLayerGuid& aA,
58 const ScrollableLayerGuid& aB);
60 // Helper structs to use as hash/equality functions in std::unordered_map.
61 // e.g. std::unordered_map<ScrollableLayerGuid,
62 // ValueType,
63 // ScrollableLayerGuid::HashFn> myMap;
64 // std::unordered_map<ScrollableLayerGuid,
65 // ValueType,
66 // ScrollableLayerGuid::HashIgnoringPresShellFn,
67 // ScrollableLayerGuid::EqualIgnoringPresShellFn> myMap;
69 struct HashFn {
70 std::size_t operator()(const ScrollableLayerGuid& aGuid) const;
73 struct HashIgnoringPresShellFn {
74 std::size_t operator()(const ScrollableLayerGuid& aGuid) const;
77 struct EqualIgnoringPresShellFn {
78 bool operator()(const ScrollableLayerGuid& lhs,
79 const ScrollableLayerGuid& rhs) const;
83 } // namespace layers
84 } // namespace mozilla
86 #endif /* GFX_SCROLLABLELAYERGUID_H */