ScrollableLayerGuid.h (3253B)
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/. */ 6 7 #ifndef GFX_SCROLLABLELAYERGUID_H 8 #define GFX_SCROLLABLELAYERGUID_H 9 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 14 15 namespace mozilla { 16 namespace layers { 17 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. 25 */ 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. 33 34 LayersId mLayersId; 35 uint32_t mPresShellId; 36 ViewID mScrollId; 37 38 ScrollableLayerGuid(); 39 40 ScrollableLayerGuid(LayersId aLayersId, uint32_t aPresShellId, 41 ViewID aScrollId); 42 43 ScrollableLayerGuid(const ScrollableLayerGuid& other) = default; 44 45 ~ScrollableLayerGuid() = default; 46 47 bool operator==(const ScrollableLayerGuid& other) const; 48 bool operator!=(const ScrollableLayerGuid& other) const; 49 bool operator<(const ScrollableLayerGuid& other) const; 50 51 friend std::ostream& operator<<(std::ostream& aOut, 52 const ScrollableLayerGuid& aGuid); 53 54 using Comparator = bool (*)(const ScrollableLayerGuid&, 55 const ScrollableLayerGuid&); 56 57 static bool EqualsIgnoringPresShell(const ScrollableLayerGuid& aA, 58 const ScrollableLayerGuid& aB); 59 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; 68 69 struct HashFn { 70 std::size_t operator()(const ScrollableLayerGuid& aGuid) const; 71 }; 72 73 struct HashIgnoringPresShellFn { 74 std::size_t operator()(const ScrollableLayerGuid& aGuid) const; 75 }; 76 77 struct EqualIgnoringPresShellFn { 78 bool operator()(const ScrollableLayerGuid& lhs, 79 const ScrollableLayerGuid& rhs) const; 80 }; 81 }; 82 83 } // namespace layers 84 } // namespace mozilla 85 86 #endif /* GFX_SCROLLABLELAYERGUID_H */