layout/base/nsDisplayItemTypes.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // IWYU pragma: private, include "nsDisplayList.h"
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     3  * vim: set ts=2 sw=2 et tw=78:
     4  * This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7  */
     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 purposes
    12  * of easy comparison and matching of items in different display lists.
    13  * 
    14  * This is #included inside nsDisplayItem.
    15  */
    18 enum Type {
    19   TYPE_ZERO = 0, /** Spacer so that the first item starts at 1 */
    21 #define DECLARE_DISPLAY_ITEM_TYPE(name) TYPE_##name,
    22 #define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) TYPE_##name,
    23 #include "nsDisplayItemTypesList.h"
    24 #undef DECLARE_DISPLAY_ITEM_TYPE
    25 #undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS
    27   TYPE_MAX
    28 };
    30 enum {
    31   // Number of bits needed to represent all types
    32   TYPE_BITS = 8
    33 };
    35 enum DisplayItemFlags {
    36   TYPE_RENDERS_NO_IMAGES = 1 << 0
    37 };
    39 static const char* DisplayItemTypeName(Type aType)
    40 {
    41   switch (aType) {
    42 #define DECLARE_DISPLAY_ITEM_TYPE(name) case TYPE_##name: return #name;
    43 #define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) case TYPE_##name: return #name;
    44 #include "nsDisplayItemTypesList.h"
    45 #undef DECLARE_DISPLAY_ITEM_TYPE
    46 #undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS
    48     default: return "TYPE_UNKNOWN";
    49   }
    50 }
    52 static uint8_t GetDisplayItemFlagsForType(Type aType)
    53 {
    54   static const uint8_t flags[TYPE_MAX] = {
    55     0
    56 #define DECLARE_DISPLAY_ITEM_TYPE(name) ,0
    57 #define DECLARE_DISPLAY_ITEM_TYPE_FLAGS(name,flags) ,flags
    58 #include "nsDisplayItemTypesList.h"
    59 #undef DECLARE_DISPLAY_ITEM_TYPE
    60 #undef DECLARE_DISPLAY_ITEM_TYPE_FLAGS
    61   };
    63   return flags[aType];
    64 }
    66 static Type GetDisplayItemTypeFromKey(uint32_t aDisplayItemKey)
    67 {
    68   static const uint32_t typeMask = (1 << TYPE_BITS) - 1;
    69   Type type = static_cast<Type>(aDisplayItemKey & typeMask);
    70   NS_ASSERTION(type > TYPE_ZERO && type < TYPE_MAX, "Invalid display item type!");
    71   return type;
    72 }

mercurial