ScrollableLayerGuid.cpp (2744B)
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 #include "ScrollableLayerGuid.h" 8 9 #include <ostream> 10 #include "mozilla/HashFunctions.h" // for HashGeneric 11 #include "mozilla/IntegerPrintfMacros.h" 12 #include "nsPrintfCString.h" // for nsPrintfCString 13 14 namespace mozilla { 15 namespace layers { 16 17 ScrollableLayerGuid::ScrollableLayerGuid() 18 : mLayersId{0}, mPresShellId(0), mScrollId(0) {} 19 20 ScrollableLayerGuid::ScrollableLayerGuid(LayersId aLayersId, 21 uint32_t aPresShellId, 22 ViewID aScrollId) 23 : mLayersId(aLayersId), mPresShellId(aPresShellId), mScrollId(aScrollId) {} 24 25 bool ScrollableLayerGuid::operator==(const ScrollableLayerGuid& other) const { 26 return mLayersId == other.mLayersId && mPresShellId == other.mPresShellId && 27 mScrollId == other.mScrollId; 28 } 29 30 bool ScrollableLayerGuid::operator!=(const ScrollableLayerGuid& other) const { 31 return !(*this == other); 32 } 33 34 bool ScrollableLayerGuid::operator<(const ScrollableLayerGuid& other) const { 35 if (mLayersId < other.mLayersId) { 36 return true; 37 } 38 if (mLayersId == other.mLayersId) { 39 if (mPresShellId < other.mPresShellId) { 40 return true; 41 } 42 if (mPresShellId == other.mPresShellId) { 43 return mScrollId < other.mScrollId; 44 } 45 } 46 return false; 47 } 48 49 std::ostream& operator<<(std::ostream& aOut, const ScrollableLayerGuid& aGuid) { 50 return aOut << nsPrintfCString("{ l=0x%" PRIx64 ", p=%u, v=%" PRIu64 " }", 51 uint64_t(aGuid.mLayersId), aGuid.mPresShellId, 52 aGuid.mScrollId) 53 .get(); 54 } 55 56 bool ScrollableLayerGuid::EqualsIgnoringPresShell( 57 const ScrollableLayerGuid& aA, const ScrollableLayerGuid& aB) { 58 return aA.mLayersId == aB.mLayersId && aA.mScrollId == aB.mScrollId; 59 } 60 61 std::size_t ScrollableLayerGuid::HashFn::operator()( 62 const ScrollableLayerGuid& aGuid) const { 63 return HashGeneric(uint64_t(aGuid.mLayersId), aGuid.mPresShellId, 64 aGuid.mScrollId); 65 } 66 67 std::size_t ScrollableLayerGuid::HashIgnoringPresShellFn::operator()( 68 const ScrollableLayerGuid& aGuid) const { 69 return HashGeneric(uint64_t(aGuid.mLayersId), aGuid.mScrollId); 70 } 71 72 bool ScrollableLayerGuid::EqualIgnoringPresShellFn::operator()( 73 const ScrollableLayerGuid& lhs, const ScrollableLayerGuid& rhs) const { 74 return EqualsIgnoringPresShell(lhs, rhs); 75 } 76 77 } // namespace layers 78 } // namespace mozilla