nsDisplayItemTypes.h (2193B)
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 // IWYU pragma: private, include "nsDisplayList.h" 8 9 /** 10 * It's useful to be able to dynamically check the type of certain items. 11 * Every subclass of nsDisplayItem must have a new type added here for the 12 * purposes of easy comparison and matching of items in different display lists. 13 */ 14 15 #ifndef NSDISPLAYITEMTYPES_H_ 16 #define NSDISPLAYITEMTYPES_H_ 17 18 enum class DisplayItemType : uint8_t { 19 TYPE_ZERO = 0, /** Spacer so that the first item starts at 1 */ 20 21 #define DECLARE_DISPLAY_ITEM_TYPE(name, flags) TYPE_##name, 22 #include "nsDisplayItemTypesList.h" 23 #undef DECLARE_DISPLAY_ITEM_TYPE 24 25 TYPE_MAX 26 }; 27 28 enum { 29 // Number of bits needed to represent all types 30 TYPE_BITS = 8 31 }; 32 33 enum DisplayItemFlags { 34 TYPE_RENDERS_NO_IMAGES = 1 << 0, 35 TYPE_IS_CONTENTFUL = 1 << 1, 36 TYPE_IS_CONTAINER = 1 << 2 37 }; 38 39 inline const char* DisplayItemTypeName(DisplayItemType aType) { 40 switch (aType) { 41 #define DECLARE_DISPLAY_ITEM_TYPE(name, flags) \ 42 case DisplayItemType::TYPE_##name: \ 43 return #name; 44 #include "nsDisplayItemTypesList.h" 45 #undef DECLARE_DISPLAY_ITEM_TYPE 46 47 default: 48 return "TYPE_UNKNOWN"; 49 } 50 } 51 52 inline uint8_t GetDisplayItemFlagsForType(DisplayItemType aType) { 53 static const uint8_t flags[static_cast<uint32_t>(DisplayItemType::TYPE_MAX)] = 54 {0 55 #define DECLARE_DISPLAY_ITEM_TYPE(name, flags) , flags 56 #include "nsDisplayItemTypesList.h" 57 #undef DECLARE_DISPLAY_ITEM_TYPE 58 }; 59 60 return flags[static_cast<uint32_t>(aType)]; 61 } 62 63 inline DisplayItemType GetDisplayItemTypeFromKey(uint32_t aDisplayItemKey) { 64 static const uint32_t typeMask = (1 << TYPE_BITS) - 1; 65 DisplayItemType type = 66 static_cast<DisplayItemType>(aDisplayItemKey & typeMask); 67 NS_ASSERTION( 68 type >= DisplayItemType::TYPE_ZERO && type < DisplayItemType::TYPE_MAX, 69 "Invalid display item type!"); 70 return type; 71 } 72 73 #endif /*NSDISPLAYITEMTYPES_H_*/