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
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.
35 uint32_t mPresShellId
;
38 ScrollableLayerGuid();
40 ScrollableLayerGuid(LayersId aLayersId
, uint32_t aPresShellId
,
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,
63 // ScrollableLayerGuid::HashFn> myMap;
64 // std::unordered_map<ScrollableLayerGuid,
66 // ScrollableLayerGuid::HashIgnoringPresShellFn,
67 // ScrollableLayerGuid::EqualIgnoringPresShellFn> myMap;
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;
84 } // namespace mozilla
86 #endif /* GFX_SCROLLABLELAYERGUID_H */