Commit 36418cc2 authored by yoav@yoav.ws's avatar yoav@yoav.ws

Auto generate MediaFeatureNames, its macros and MediaTypeNames

As part of the review of https://codereview.chromium.org/171383002/
it was requested that the required static strings for the media features and types will be generated as part of the build system.
This CL implements that request.

BUG=

Review URL: https://codereview.chromium.org/185533012

git-svn-id: svn://svn.chromium.org/blink/trunk@168465 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a03d9b21
#!/usr/bin/env python
# Copyright 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.
import sys
import in_generator
import make_names
import media_feature_symbol
class MakeMediaFeatureNamesWriter(make_names.MakeNamesWriter):
pass
MakeMediaFeatureNamesWriter.filters['symbol'] = media_feature_symbol.getMediaFeatureSymbolWithSuffix('MediaFeature')
if __name__ == "__main__":
in_generator.Maker(MakeMediaFeatureNamesWriter).main(sys.argv)
#!/usr/bin/env python
# Copyright 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.
import media_feature_symbol
import in_generator
import template_expander
import name_utilities
import sys
class MakeMediaFeaturesWriter(in_generator.Writer):
defaults = {
'Conditional': None, # FIXME: Add support for Conditional.
'RuntimeEnabled': None,
'ImplementedAs': None,
}
filters = {
'symbol': media_feature_symbol.getMediaFeatureSymbolWithSuffix(''),
'to_macro_style': name_utilities.to_macro_style,
}
default_parameters = {
'namespace': '',
'export': '',
}
def __init__(self, in_file_path):
super(MakeMediaFeaturesWriter, self).__init__(in_file_path)
self._outputs = {
('MediaFeatures.h'): self.generate_header,
}
self._template_context = {
'namespace': '',
'export': '',
'entries': self.in_file.name_dictionaries,
}
@template_expander.use_jinja("MediaFeatures.h.tmpl", filters=filters)
def generate_header(self):
return self._template_context
if __name__ == "__main__":
in_generator.Maker(MakeMediaFeaturesWriter).main(sys.argv)
# Copyright 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.
def mediaFeatureSymbol(entry, suffix):
name = entry['name']
if name.startswith('-webkit-'):
name = name[8:]
foundDash = False
newName = ""
for chr in name:
if chr == '-':
foundDash = True
continue
if foundDash:
chr = chr.upper()
foundDash = False
newName = newName + chr
newName = newName + suffix
return newName
def getMediaFeatureSymbolWithSuffix(suffix):
def returnedFunction(entry):
return mediaFeatureSymbol(entry, suffix)
return returnedFunction
{% from "macros.tmpl" import license -%}
{{ license() }}
#ifndef MediaFeatures_h
#define MediaFeatures_h
#define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
{%- for entry in entries %}
macro({{entry|symbol}}) {%- if not loop.last %}\{%-endif %}
{%- endfor %}
#endif
......@@ -39,11 +39,12 @@
#include "HTMLNames.h"
#include "InputTypeNames.h"
#include "MathMLNames.h"
#include "MediaFeatureNames.h"
#include "MediaTypeNames.h"
#include "SVGNames.h"
#include "XLinkNames.h"
#include "XMLNSNames.h"
#include "XMLNames.h"
#include "core/css/MediaFeatureNames.h"
#include "core/html/parser/HTMLParserThread.h"
#include "heap/Heap.h"
#include "platform/EventTracer.h"
......@@ -76,6 +77,7 @@ void init()
FontFamilyNames::init();
InputTypeNames::init();
MediaFeatureNames::init();
MediaTypeNames::init();
WTF::StringStatics::init();
QualifiedName::init();
Partitions::init();
......
......@@ -284,6 +284,12 @@
# Generated from HTMLEntityNames.in
'<(SHARED_INTERMEDIATE_DIR)/blink/HTMLEntityTable.cpp',
# Generated from MediaFeatureNames.in
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaFeatureNames.cpp',
# Generated from MediaTypeNames.in
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaTypeNames.cpp',
# Generated from CSSTokenizer-in.cpp
'<(SHARED_INTERMEDIATE_DIR)/blink/CSSTokenizer.cpp',
......
......@@ -775,8 +775,6 @@
'css/FontSize.cpp',
'css/FontSize.h',
'css/HashTools.h',
'css/MediaFeatureNames.cpp',
'css/MediaFeatureNames.h',
'css/MediaList.cpp',
'css/MediaList.h',
'css/MediaQuery.cpp',
......
......@@ -179,6 +179,80 @@
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'MediaFeatureNames',
'variables': {
'in_files': [
'css/MediaFeatureNames.in',
],
},
'inputs': [
'<@(scripts_for_in_files)',
'../build/scripts/make_media_feature_names.py',
'<@(in_files)'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaFeatureNames.cpp',
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaFeatureNames.h',
],
'action': [
'python',
'../build/scripts/make_media_feature_names.py',
'<@(in_files)',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/blink',
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'MediaFeatures',
'variables': {
'in_files': [
'css/MediaFeatureNames.in',
],
},
'inputs': [
'<@(scripts_for_in_files)',
'../build/scripts/make_media_features.py',
'<@(in_files)'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaFeatures.h',
],
'action': [
'python',
'../build/scripts/make_media_features.py',
'<@(in_files)',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/blink',
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'MediaTypeNames',
'variables': {
'in_files': [
'css/MediaTypeNames.in',
],
},
'inputs': [
'<@(scripts_for_in_files)',
'../build/scripts/make_names.py',
'<@(in_files)'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaTypeNames.cpp',
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaTypeNames.h',
],
'action': [
'python',
'../build/scripts/make_names.py',
'<@(in_files)',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/blink',
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'StylePropertyShorthand',
'inputs': [
......
/*
* Copyright (C) 2005 Apple Computer, Inc.
*
* 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.
*
*/
#include "config.h"
#ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC
#define CSS_MEDIAQUERY_NAMES_HIDE_GLOBALS 1
#endif
#include "core/css/MediaFeatureNames.h"
#include "wtf/StaticConstructors.h"
namespace WebCore {
namespace MediaFeatureNames {
#define DEFINE_MEDIAFEATURE_GLOBAL(name, str) \
DEFINE_GLOBAL(AtomicString, name##MediaFeature, str)
CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(DEFINE_MEDIAFEATURE_GLOBAL)
#undef DEFINE_MEDIAFEATURE_GLOBAL
void init()
{
#define INITIALIZE_GLOBAL(name, str) new (NotNull, (void*)&name##MediaFeature) AtomicString(str, AtomicString::ConstructFromLiteral);
CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(INITIALIZE_GLOBAL)
#undef INITIALIZE_GLOBAL
}
} // namespace MediaFeatureNames
} // namespace WebCore
/*
* Copyright (C) 2005, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2013 Intel Corporation. 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.
*
*/
#ifndef MediaFeatureNames_h
#define MediaFeatureNames_h
#include "wtf/text/AtomicString.h"
namespace WebCore {
namespace MediaFeatureNames {
#define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
macro(color, "color") \
macro(colorIndex, "color-index") \
macro(grid, "grid") \
macro(monochrome, "monochrome") \
macro(height, "height") \
macro(hover, "hover") \
macro(width, "width") \
macro(orientation, "orientation") \
macro(aspectRatio, "aspect-ratio") \
macro(deviceAspectRatio, "device-aspect-ratio") \
macro(devicePixelRatio, "-webkit-device-pixel-ratio") \
macro(deviceHeight, "device-height") \
macro(deviceWidth, "device-width") \
macro(maxColor, "max-color") \
macro(maxColorIndex, "max-color-index") \
macro(maxAspectRatio, "max-aspect-ratio") \
macro(maxDeviceAspectRatio, "max-device-aspect-ratio") \
macro(maxDevicePixelRatio, "-webkit-max-device-pixel-ratio") \
macro(maxDeviceHeight, "max-device-height") \
macro(maxDeviceWidth, "max-device-width") \
macro(maxHeight, "max-height") \
macro(maxMonochrome, "max-monochrome") \
macro(maxWidth, "max-width") \
macro(maxResolution, "max-resolution") \
macro(minColor, "min-color") \
macro(minColorIndex, "min-color-index") \
macro(minAspectRatio, "min-aspect-ratio") \
macro(minDeviceAspectRatio, "min-device-aspect-ratio") \
macro(minDevicePixelRatio, "-webkit-min-device-pixel-ratio") \
macro(minDeviceHeight, "min-device-height") \
macro(minDeviceWidth, "min-device-width") \
macro(minHeight, "min-height") \
macro(minMonochrome, "min-monochrome") \
macro(minWidth, "min-width") \
macro(minResolution, "min-resolution") \
macro(pointer, "pointer") \
macro(resolution, "resolution") \
macro(transform2d, "-webkit-transform-2d") \
macro(transform3d, "-webkit-transform-3d") \
macro(scan, "scan") \
macro(animation, "-webkit-animation") \
macro(viewMode, "-webkit-view-mode")
// end of macro
#ifndef CSS_MEDIAQUERY_NAMES_HIDE_GLOBALS
#define CSS_MEDIAQUERY_NAMES_DECLARE(name, str) extern const AtomicString name##MediaFeature;
CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(CSS_MEDIAQUERY_NAMES_DECLARE)
#undef CSS_MEDIAQUERY_NAMES_DECLARE
#endif
void init();
} // namespace MediaFeatureNames
} // namespace WebCore
#endif // MediaFeatureNames_h
namespace="MediaFeature"
export=""
color
color-index
grid
monochrome
height
hover
width
orientation
aspect-ratio
device-aspect-ratio
-webkit-device-pixel-ratio
device-height
device-width
max-color
max-color-index
max-aspect-ratio
max-device-aspect-ratio
-webkit-max-device-pixel-ratio
max-device-height
max-device-width
max-height
max-monochrome
max-width
max-resolution
min-color
min-color-index
min-aspect-ratio
min-device-aspect-ratio
-webkit-min-device-pixel-ratio
min-device-height
min-device-width
min-height
min-monochrome
min-width
min-resolution
pointer
resolution
-webkit-transform-2d
-webkit-transform-3d
scan
-webkit-animation
-webkit-view-mode
......@@ -20,10 +20,10 @@
#include "config.h"
#include "core/css/MediaList.h"
#include "MediaFeatureNames.h"
#include "bindings/v8/ExceptionState.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/MediaFeatureNames.h"
#include "core/css/MediaQuery.h"
#include "core/css/MediaQueryExp.h"
#include "core/dom/Document.h"
......
......@@ -31,11 +31,12 @@
#include "core/css/MediaQueryEvaluator.h"
#include "CSSValueKeywords.h"
#include "MediaFeatureNames.h"
#include "MediaFeatures.h"
#include "core/css/CSSAspectRatioValue.h"
#include "core/css/CSSHelper.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSToLengthConversionData.h"
#include "core/css/MediaFeatureNames.h"
#include "core/css/MediaList.h"
#include "core/css/MediaQuery.h"
#include "core/css/resolver/MediaQueryResult.h"
......@@ -673,7 +674,7 @@ static void createFunctionMap()
{
// Create the table.
gFunctionMap = new FunctionMap;
#define ADD_TO_FUNCTIONMAP(name, str) \
#define ADD_TO_FUNCTIONMAP(name) \
gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
#undef ADD_TO_FUNCTIONMAP
......
......@@ -29,8 +29,8 @@
#ifndef MediaQueryExp_h
#define MediaQueryExp_h
#include "MediaFeatureNames.h"
#include "core/css/CSSValue.h"
#include "core/css/MediaFeatureNames.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/text/AtomicString.h"
......
namespace="MediaType"
export=""
# http://www.w3.org/TR/CSS2/media.html#media-types
all
braille
embossed
handheld
print
projection
screen
speech
tty
tv
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