blob: 83c5bb086e8cadef5b1727d2fb5faa97eb16bab7 [file] [log] [blame]
%{
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include <string.h>
#include "third_party/blink/renderer/core/css/hash_tools.h"
#ifdef _MSC_VER
// Disable the warnings from casting a 64-bit pointer to 32-bit long
// warning C4302: 'type cast': truncation from 'char (*)[28]' to 'long'
// warning C4311: 'type cast': pointer truncation from 'char (*)[18]' to 'long'
#pragma warning(disable : 4302 4311)
#endif
namespace blink {
static const char valueListStringPool[] = {
{% for keyword in value_keywords %}
"{{keyword.name}}\0"
{% endfor %}
};
static const uint16_t valueListStringOffsets[] = {
{% for offset in value_keyword_offsets %}
{{offset}},
{% endfor %}
};
%}
%struct-type
struct Value;
%omit-struct-type
%language=C++
%readonly-tables
%compare-strncmp
%define class-name CSSValueKeywordsHash
%define lookup-function-name findValueImpl
%define hash-function-name value_hash_function
%define slot-name name_offset
%define word-array-name value_word_list
%pic
%enum
%%
{% for keyword in value_keywords %}
{{keyword.lower_name}}, static_cast<int>(CSSValueID::{{keyword.enum_name}})
{% endfor %}
%%
const Value* FindValue(const char* str, unsigned int len) {
return CSSValueKeywordsHash::findValueImpl(str, len);
}
const char* getValueName(CSSValueID id) {
DCHECK_GT(id, CSSValueID::kInvalid);
DCHECK_LT(static_cast<int>(id), numCSSValueKeywords);
return valueListStringPool + valueListStringOffsets[static_cast<int>(id) - 1];
}
bool isValueAllowedInMode(CSSValueID id, CSSParserMode mode) {
switch (id) {
{% for ua_keyword in ua_sheet_mode_values_keywords %}
case CSSValueID::{{ua_keyword.enum_name}}:
{% endfor %}
return IsUASheetBehavior(mode);
{% for quirks_or_ua_keyword in quirks_mode_or_ua_sheet_mode_values_keywords %}
case CSSValueID::{{quirks_or_ua_keyword.enum_name}}:
{% endfor %}
return IsUASheetBehavior(mode) || IsQuirksModeBehavior(mode);
default:
return true;
}
}
} // namespace blink