layout/painting/nsDisplayItemTypes.h
author alwu <alwu@mozilla.com>
Mon, 07 Jan 2019 19:57:48 +0000
changeset 512757 0e229bbdaae5c8fa9f83796c628a4fdf88f057ba
parent 508163 6f3709b3878117466168c40affa7bca0b60cf75b
child 522911 159c31166c7a5ddcd61191729d1247484123de9d
permissions -rw-r--r--
Bug 1513039 - part5 : log warning when autoplay is blocked. r=cpearce,karlt Wrap 'nsContentUtils::ReportToConsole()' to reduce necessary input parameters and call it when we need to log error or warning message. Show the warning when autoplay is blocked. For web audio, this restores the console messages removed in part4 and also reports the same message when the AudioContext is blocked in the constructor. Differential Revision: https://phabricator.services.mozilla.com/D14330

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
// IWYU pragma: private, include "nsDisplayList.h"

/**
 * It's useful to be able to dynamically check the type of certain items.
 * Every subclass of nsDisplayItem must have a new type added here for the
 * purposes of easy comparison and matching of items in different display lists.
 */

#ifndef NSDISPLAYITEMTYPES_H_
#define NSDISPLAYITEMTYPES_H_

enum class DisplayItemType {
  TYPE_ZERO = 0, /** Spacer so that the first item starts at 1 */

#define DECLARE_DISPLAY_ITEM_TYPE(name, flags) TYPE_##name,
#include "nsDisplayItemTypesList.h"
#undef DECLARE_DISPLAY_ITEM_TYPE

  TYPE_MAX
};

enum {
  // Number of bits needed to represent all types
  TYPE_BITS = 8
};

enum DisplayItemFlags {
  TYPE_RENDERS_NO_IMAGES = 1 << 0,
  TYPE_IS_CONTENTFUL = 1 << 1
};

inline const char* DisplayItemTypeName(DisplayItemType aType) {
  switch (aType) {
#define DECLARE_DISPLAY_ITEM_TYPE(name, flags) \
  case DisplayItemType::TYPE_##name:           \
    return #name;
#include "nsDisplayItemTypesList.h"
#undef DECLARE_DISPLAY_ITEM_TYPE

    default:
      return "TYPE_UNKNOWN";
  }
}

inline uint8_t GetDisplayItemFlagsForType(DisplayItemType aType) {
  static const uint8_t flags[static_cast<uint32_t>(DisplayItemType::TYPE_MAX)] =
      {0
#define DECLARE_DISPLAY_ITEM_TYPE(name, flags) , flags
#include "nsDisplayItemTypesList.h"
#undef DECLARE_DISPLAY_ITEM_TYPE
      };

  return flags[static_cast<uint32_t>(aType)];
}

inline DisplayItemType GetDisplayItemTypeFromKey(uint32_t aDisplayItemKey) {
  static const uint32_t typeMask = (1 << TYPE_BITS) - 1;
  DisplayItemType type =
      static_cast<DisplayItemType>(aDisplayItemKey & typeMask);
  NS_ASSERTION(
      type >= DisplayItemType::TYPE_ZERO && type < DisplayItemType::TYPE_MAX,
      "Invalid display item type!");
  return type;
}

#endif /*NSDISPLAYITEMTYPES_H_*/