chromium/third_party/blink/renderer/core/css/style_rule.h

/*
 * (C) 1999-2003 Lars Knoll ([email protected])
 * (C) 2002-2003 Dirk Mueller ([email protected])
 * Copyright (C) 2002, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_STYLE_RULE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_STYLE_RULE_H_

#include <limits>

#include "base/bits.h"
#include "base/memory/scoped_refptr.h"
#include "base/types/pass_key.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/container_query.h"
#include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/css/css_selector_list.h"
#include "third_party/blink/renderer/core/css/css_syntax_definition.h"
#include "third_party/blink/renderer/core/css/css_variable_data.h"
#include "third_party/blink/renderer/core/css/media_list.h"
#include "third_party/blink/renderer/core/css/parser/css_at_rule_id.h"
#include "third_party/blink/renderer/core/css/parser/css_nesting_type.h"
#include "third_party/blink/renderer/core/css/style_scope.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"

namespace blink {

class CascadeLayer;
class CSSRule;
class CSSStyleSheet;
class ExecutionContext;
class StyleSheetContents;

class CORE_EXPORT StyleRuleBase : public GarbageCollected<StyleRuleBase> {};

// A single rule from a stylesheet. Contains a selector list (one or more
// complex selectors) and a collection of style properties to be applied where
// those selectors match. These are output by CSSParserImpl.
//
// Note that since this we generate so many StyleRule objects, and all of them
// have at least one selector, the selector list is not allocated separately as
// on a CSSSelectorList. Instead, we put the CSSSelectors immediately after the
// StyleRule object. This both saves memory (since we don't need the pointer,
// or any of the extra allocation overhead), and makes it likely that the
// CSSSelectors are on the same cache line as the StyleRule. (On the flip side,
// it makes it unlikely that the CSSSelector's RareData is on the same cache
// line as the CSSSelector itself, but it is still overall a good tradeoff
// for us.) StyleRule provides an API that is a subset of CSSSelectorList,
// partially implemented using its static member functions.
class CORE_EXPORT StyleRule : public StyleRuleBase {};

class CORE_EXPORT StyleRuleFontFace : public StyleRuleBase {};

class CORE_EXPORT StyleRuleProperty : public StyleRuleBase {};

class CORE_EXPORT StyleRuleGroup : public StyleRuleBase {};

class CORE_EXPORT StyleRuleScope : public StyleRuleGroup {};

// https://www.w3.org/TR/css-cascade-5/#layer-block
class CORE_EXPORT StyleRuleLayerBlock : public StyleRuleGroup {};

// https://www.w3.org/TR/css-cascade-5/#layer-empty
class CORE_EXPORT StyleRuleLayerStatement : public StyleRuleBase {};

class StyleRulePage : public StyleRuleGroup {};

class StyleRulePageMargin : public StyleRuleBase {};

// If you add new children of this class, remember to update IsConditionRule()
// above.
class CORE_EXPORT StyleRuleCondition : public StyleRuleGroup {};

class CORE_EXPORT StyleRuleMedia : public StyleRuleCondition {};

class StyleRuleSupports : public StyleRuleCondition {};

class CORE_EXPORT StyleRuleContainer : public StyleRuleCondition {};

class StyleRuleStartingStyle : public StyleRuleGroup {};

// This should only be used within the CSS Parser
class StyleRuleCharset : public StyleRuleBase {};

// An @function rule, representing a CSS function.
class CORE_EXPORT StyleRuleFunction : public StyleRuleBase {};

// An @mixin rule, representing a CSS mixin. We store all of the rules
// and declarations under a dummy rule that serves as the parent;
// when @apply comes, we clone all the children below that rule and
// reparent them into the point of @apply.
class CORE_EXPORT StyleRuleMixin : public StyleRuleBase {};

// An @apply rule, representing applying a mixin.
class CORE_EXPORT StyleRuleApplyMixin : public StyleRuleBase {};

template <>
struct DowncastTraits<StyleRule> {};

template <>
struct DowncastTraits<StyleRuleFontFace> {};

template <>
struct DowncastTraits<StyleRulePage> {};

template <>
struct DowncastTraits<StyleRulePageMargin> {};

template <>
struct DowncastTraits<StyleRuleProperty> {};

template <>
struct DowncastTraits<StyleRuleScope> {};

template <>
struct DowncastTraits<StyleRuleGroup> {};

template <>
struct DowncastTraits<StyleRuleLayerBlock> {};

template <>
struct DowncastTraits<StyleRuleLayerStatement> {};

template <>
struct DowncastTraits<StyleRuleMedia> {};

template <>
struct DowncastTraits<StyleRuleSupports> {};

template <>
struct DowncastTraits<StyleRuleContainer> {};

template <>
struct DowncastTraits<StyleRuleCharset> {};

template <>
struct DowncastTraits<StyleRuleStartingStyle> {};

template <>
struct DowncastTraits<StyleRuleFunction> {};

template <>
struct DowncastTraits<StyleRuleMixin> {};

template <>
struct DowncastTraits<StyleRuleApplyMixin> {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_STYLE_RULE_H_