1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/nsDisplayItemTypes.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +// IWYU pragma: private, include "nsDisplayList.h" 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.6 + * vim: set ts=2 sw=2 et tw=78: 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + */ 1.11 + 1.12 +/** 1.13 + * It's useful to be able to dynamically check the type of certain items. 1.14 + * Every subclass of nsDisplayItem must have a new type added here for the purposes 1.15 + * of easy comparison and matching of items in different display lists. 1.16 + * 1.17 + * This is #included inside nsDisplayItem. 1.18 + */ 1.19 + 1.20 + 1.21 +enum Type { 1.22 + TYPE_ZERO = 0, /** Spacer so that the first item starts at 1 */ 1.23 + 1.24 +#define DECLARE_DISPLAY_ITEM_TYPE(name) TYPE_##name, 1.25 +#define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) TYPE_##name, 1.26 +#include "nsDisplayItemTypesList.h" 1.27 +#undef DECLARE_DISPLAY_ITEM_TYPE 1.28 +#undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS 1.29 + 1.30 + TYPE_MAX 1.31 +}; 1.32 + 1.33 +enum { 1.34 + // Number of bits needed to represent all types 1.35 + TYPE_BITS = 8 1.36 +}; 1.37 + 1.38 +enum DisplayItemFlags { 1.39 + TYPE_RENDERS_NO_IMAGES = 1 << 0 1.40 +}; 1.41 + 1.42 +static const char* DisplayItemTypeName(Type aType) 1.43 +{ 1.44 + switch (aType) { 1.45 +#define DECLARE_DISPLAY_ITEM_TYPE(name) case TYPE_##name: return #name; 1.46 +#define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) case TYPE_##name: return #name; 1.47 +#include "nsDisplayItemTypesList.h" 1.48 +#undef DECLARE_DISPLAY_ITEM_TYPE 1.49 +#undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS 1.50 + 1.51 + default: return "TYPE_UNKNOWN"; 1.52 + } 1.53 +} 1.54 + 1.55 +static uint8_t GetDisplayItemFlagsForType(Type aType) 1.56 +{ 1.57 + static const uint8_t flags[TYPE_MAX] = { 1.58 + 0 1.59 +#define DECLARE_DISPLAY_ITEM_TYPE(name) ,0 1.60 +#define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) ,flags 1.61 +#include "nsDisplayItemTypesList.h" 1.62 +#undef DECLARE_DISPLAY_ITEM_TYPE 1.63 +#undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS 1.64 + }; 1.65 + 1.66 + return flags[aType]; 1.67 +} 1.68 + 1.69 +static Type GetDisplayItemTypeFromKey(uint32_t aDisplayItemKey) 1.70 +{ 1.71 + static const uint32_t typeMask = (1 << TYPE_BITS) - 1; 1.72 + Type type = static_cast<Type>(aDisplayItemKey & typeMask); 1.73 + NS_ASSERTION(type > TYPE_ZERO && type < TYPE_MAX, "Invalid display item type!"); 1.74 + return type; 1.75 +}