Commit f9355806 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Add CSSPropertyIDList to simplify looping over CSS property IDs

This change allows to change the loop:
    for (int id = kIntFirstCSSProperty; id <= kIntLastCSSProperty; ++id)
      CSSPropertyID property_id = static_cast<CSSPropertyID>(id);
for the simpler:
    for (CSSPropertyID property_id : CSSPropertyIDList())

Additionally, remove unneeded static casts from kCSSPropertyAliasList.

Bug: 936369
Change-Id: I4ebcd57cce26d2021da04f9f02e0dbca7a3c4585
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538287Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#644741}
parent c5620d27
...@@ -22,8 +22,7 @@ class CSSPropertyNamesWriter(json5_generator.Writer): ...@@ -22,8 +22,7 @@ class CSSPropertyNamesWriter(json5_generator.Writer):
return " %(enum_key)s = %(enum_value)s," % property_ return " %(enum_key)s = %(enum_value)s," % property_
def _array_item(self, property_): def _array_item(self, property_):
return " static_cast<CSSPropertyID>(%(enum_value)s), " \ return " CSSPropertyID::%(enum_key)s," % property_
"// %(property_id)s" % property_
@template_expander.use_jinja('core/css/templates/css_property_names.h.tmpl') @template_expander.use_jinja('core/css/templates/css_property_names.h.tmpl')
def generate_header(self): def generate_header(self):
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stddef.h> #include <stddef.h>
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace WTF { namespace WTF {
...@@ -68,6 +69,23 @@ CSSPropertyID unresolvedCSSPropertyID(const WTF::String&); ...@@ -68,6 +69,23 @@ CSSPropertyID unresolvedCSSPropertyID(const WTF::String&);
CSSPropertyID CORE_EXPORT cssPropertyID(const WTF::String&); CSSPropertyID CORE_EXPORT cssPropertyID(const WTF::String&);
class CSSPropertyIDList {
STACK_ALLOCATED();
public:
class Iterator {
STACK_ALLOCATED();
public:
Iterator(int id) : id_(id) {}
CSSPropertyID operator*() const { return convertToCSSPropertyID(id_); }
Iterator& operator++() { id_++; return *this; }
bool operator!=(const Iterator& i) const { return id_ != i.id_; }
private:
int id_;
};
Iterator begin() const { return Iterator(kIntFirstCSSProperty); }
Iterator end() const { return Iterator(kIntLastCSSProperty + 1); }
};
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_PROPERTY_NAMES_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_PROPERTY_NAMES_H_
...@@ -1273,8 +1273,7 @@ const StylePropertyShorthand& CSSAnimations::PropertiesForTransitionAll() { ...@@ -1273,8 +1273,7 @@ const StylePropertyShorthand& CSSAnimations::PropertiesForTransitionAll() {
DEFINE_STATIC_LOCAL(Vector<const CSSProperty*>, properties, ()); DEFINE_STATIC_LOCAL(Vector<const CSSProperty*>, properties, ());
DEFINE_STATIC_LOCAL(StylePropertyShorthand, property_shorthand, ()); DEFINE_STATIC_LOCAL(StylePropertyShorthand, property_shorthand, ());
if (properties.IsEmpty()) { if (properties.IsEmpty()) {
for (int i = kIntFirstCSSProperty; i <= kIntLastCSSProperty; ++i) { for (CSSPropertyID id : CSSPropertyIDList()) {
CSSPropertyID id = convertToCSSPropertyID(i);
// Avoid creating overlapping transitions with perspective-origin and // Avoid creating overlapping transitions with perspective-origin and
// transition-origin. // transition-origin.
if (id == CSSPropertyID::kWebkitPerspectiveOriginX || if (id == CSSPropertyID::kWebkitPerspectiveOriginX ||
......
...@@ -192,8 +192,7 @@ void CSSStyleDeclaration::NamedPropertyEnumerator(Vector<String>& names, ...@@ -192,8 +192,7 @@ void CSSStyleDeclaration::NamedPropertyEnumerator(Vector<String>& names,
DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, property_names, ()); DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, property_names, ());
if (property_names.IsEmpty()) { if (property_names.IsEmpty()) {
for (int id = kIntFirstCSSProperty; id <= kIntLastCSSProperty; ++id) { for (CSSPropertyID property_id : CSSPropertyIDList()) {
CSSPropertyID property_id = static_cast<CSSPropertyID>(id);
const CSSProperty& property_class = const CSSProperty& property_class =
CSSProperty::Get(resolveCSSPropertyID(property_id)); CSSProperty::Get(resolveCSSPropertyID(property_id));
if (property_class.IsEnabled()) if (property_class.IsEnabled())
......
...@@ -1129,8 +1129,7 @@ Response InspectorCSSAgent::getComputedStyleForNode( ...@@ -1129,8 +1129,7 @@ Response InspectorCSSAgent::getComputedStyleForNode(
auto* computed_style_info = auto* computed_style_info =
MakeGarbageCollected<CSSComputedStyleDeclaration>(node, true); MakeGarbageCollected<CSSComputedStyleDeclaration>(node, true);
*style = protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); *style = protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create();
for (int id = kIntFirstCSSProperty; id <= kIntLastCSSProperty; ++id) { for (CSSPropertyID property_id : CSSPropertyIDList()) {
CSSPropertyID property_id = static_cast<CSSPropertyID>(id);
const CSSProperty& property_class = const CSSProperty& property_class =
CSSProperty::Get(resolveCSSPropertyID(property_id)); CSSProperty::Get(resolveCSSPropertyID(property_id));
if (!property_class.IsEnabled() || property_class.IsShorthand() || if (!property_class.IsEnabled() || property_class.IsShorthand() ||
......
...@@ -3304,8 +3304,7 @@ void Internals::clearUseCounter(Document* document, uint32_t feature) { ...@@ -3304,8 +3304,7 @@ void Internals::clearUseCounter(Document* document, uint32_t feature) {
Vector<String> Internals::getCSSPropertyLonghands() const { Vector<String> Internals::getCSSPropertyLonghands() const {
Vector<String> result; Vector<String> result;
for (int id = kIntFirstCSSProperty; id <= kIntLastCSSProperty; ++id) { for (CSSPropertyID property : CSSPropertyIDList()) {
CSSPropertyID property = static_cast<CSSPropertyID>(id);
const CSSProperty& property_class = CSSProperty::Get(property); const CSSProperty& property_class = CSSProperty::Get(property);
if (property_class.IsLonghand()) { if (property_class.IsLonghand()) {
result.push_back(property_class.GetPropertyNameString()); result.push_back(property_class.GetPropertyNameString());
...@@ -3316,8 +3315,7 @@ Vector<String> Internals::getCSSPropertyLonghands() const { ...@@ -3316,8 +3315,7 @@ Vector<String> Internals::getCSSPropertyLonghands() const {
Vector<String> Internals::getCSSPropertyShorthands() const { Vector<String> Internals::getCSSPropertyShorthands() const {
Vector<String> result; Vector<String> result;
for (int id = kIntFirstCSSProperty; id <= kIntLastCSSProperty; ++id) { for (CSSPropertyID property : CSSPropertyIDList()) {
CSSPropertyID property = static_cast<CSSPropertyID>(id);
const CSSProperty& property_class = CSSProperty::Get(property); const CSSProperty& property_class = CSSProperty::Get(property);
if (property_class.IsShorthand()) { if (property_class.IsShorthand()) {
result.push_back(property_class.GetPropertyNameString()); result.push_back(property_class.GetPropertyNameString());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment