1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
|
#! /usr/bin/perl
#
# This file is part of the WebKit project
#
# Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
# Copyright (C) 2007, 2008, 2012, 2014, 2015 Apple Inc. All rights reserved.
# Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
# Copyright (C) 2010 Andras Becsi (abecsi@inf.u-szeged.hu), University of Szeged
# Copyright (C) 2013 Google 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.
use Getopt::Long;
use preprocessor;
use strict;
use warnings;
my $defines;
my $preprocessor;
my $gperf;
GetOptions('defines=s' => \$defines,
'preprocessor=s' => \$preprocessor,
'gperf-executable=s' => \$gperf);
my @NAMES = applyPreprocessor("CSSPropertyNames.in", $defines, $preprocessor);
die "We've reached more than 1024 CSS properties, please make sure to update CSSProperty/StylePropertyMetadata accordingly" if (scalar(@NAMES) > 1024);
my %namesHash;
my @duplicates = ();
my $numPredefinedProperties = 2;
my @names = ();
my %nameIsInherited;
my %propertiesWithStyleBuilderOptions;
my %styleBuilderOptions = (
AnimationProperty => 1, # Defined in Source/WebCore/css/StyleBuilderConverter.h
AutoFunctions => 1,
ConditionalConverter => 1,
Converter => 1,
Custom => 1,
FillLayerProperty => 1,
FontProperty => 1,
Getter => 1,
Initial => 1,
Longhands => 1,
NameForMethods => 1,
NoDefaultColor => 1,
SVG => 1,
SkipBuilder => 1,
Setter => 1,
VisitedLinkColorSupport => 1,
);
my %nameToId;
my @aliases = ();
foreach (@NAMES) {
next if (m/(^\s*$)/);
next if (/^#/);
# Input may use a different EOL sequence than $/, so avoid chomp.
$_ =~ s/\s*\[(.+?)\]\r?$//;
my @options = ();
if ($1) {
@options = split(/\s*,\s*/, $1);
}
$_ =~ s/[\r\n]+$//g;
if (exists $namesHash{$_}) {
push @duplicates, $_;
} else {
$namesHash{$_} = 1;
}
if ($_ =~ /=/) {
if (@options) {
die "Options are specified on an alias $_: ", join(", ", @options) . "\n";
}
push @aliases, $_;
} else {
$nameIsInherited{$_} = 0;
$propertiesWithStyleBuilderOptions{$_} = {};
foreach my $option (@options) {
my ($optionName, $optionValue) = split(/=/, $option);
if ($optionName eq "Inherited") {
$nameIsInherited{$_} = 1;
} elsif ($styleBuilderOptions{$optionName}) {
$propertiesWithStyleBuilderOptions{$_}{$optionName} = $optionValue;
} else {
die "Unrecognized \"" . $optionName . "\" option for " . $_ . " property.";
}
}
my $id = $_;
$id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
$nameToId{$_} = $id;
push @names, $_;
}
}
if (@duplicates > 0) {
die 'Duplicate CSS property names: ', join(', ', @duplicates) . "\n";
}
open GPERF, ">CSSPropertyNames.gperf" || die "Could not open CSSPropertyNames.gperf for writing";
print GPERF << "EOF";
%{
/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
#include "config.h"
#include \"CSSProperty.h\"
#include \"CSSPropertyNames.h\"
#include \"HashTools.h\"
#include <string.h>
#include <wtf/ASCIICType.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/WTFString.h>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored \"-Wunknown-pragmas\"
#pragma clang diagnostic ignored \"-Wdeprecated-register\"
#pragma clang diagnostic ignored \"-Wimplicit-fallthrough\"
#endif
namespace WebCore {
// Using std::numeric_limits<uint16_t>::max() here would be cleaner,
// but is not possible due to missing constexpr support in MSVC 2013.
static_assert(numCSSProperties + 1 <= 65535, "CSSPropertyID should fit into uint16_t.");
EOF
print GPERF "const char* const propertyNameStrings[numCSSProperties] = {\n";
foreach my $name (@names) {
print GPERF " \"$name\",\n";
}
print GPERF "};\n\n";
print GPERF << "EOF";
%}
%struct-type
struct Property;
%omit-struct-type
%language=C++
%readonly-tables
%global-table
%compare-strncmp
%define class-name CSSPropertyNamesHash
%define lookup-function-name findPropertyImpl
%define hash-function-name propery_hash_function
%define word-array-name property_wordlist
%enum
%%
EOF
foreach my $name (@names) {
print GPERF $name . ", CSSProperty" . $nameToId{$name} . "\n";
}
foreach my $alias (@aliases) {
$alias =~ /^([^\s]*)[\s]*=[\s]*([^\s]*)/;
my $name = $1;
print GPERF $name . ", CSSProperty" . $nameToId{$2} . "\n";
}
print GPERF<< "EOF";
%%
const Property* findProperty(const char* str, unsigned int len)
{
return CSSPropertyNamesHash::findPropertyImpl(str, len);
}
const char* getPropertyName(CSSPropertyID id)
{
if (id < firstCSSProperty)
return 0;
int index = id - firstCSSProperty;
if (index >= numCSSProperties)
return 0;
return propertyNameStrings[index];
}
const AtomicString& getPropertyNameAtomicString(CSSPropertyID id)
{
if (id < firstCSSProperty)
return nullAtom;
int index = id - firstCSSProperty;
if (index >= numCSSProperties)
return nullAtom;
static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; // Intentionally never destroyed.
AtomicString& propertyString = propertyStrings[index];
if (propertyString.isNull()) {
const char* propertyName = propertyNameStrings[index];
propertyString = AtomicString(propertyName, strlen(propertyName), AtomicString::ConstructFromLiteral);
}
return propertyString;
}
String getPropertyNameString(CSSPropertyID id)
{
// We share the StringImpl with the AtomicStrings.
return getPropertyNameAtomicString(id).string();
}
String getJSPropertyName(CSSPropertyID id)
{
char result[maxCSSPropertyNameLength + 1];
const char* cssPropertyName = getPropertyName(id);
const char* propertyNamePointer = cssPropertyName;
if (!propertyNamePointer)
return emptyString();
char* resultPointer = result;
while (char character = *propertyNamePointer++) {
if (character == '-') {
char nextCharacter = *propertyNamePointer++;
if (!nextCharacter)
break;
character = (propertyNamePointer - 2 != cssPropertyName) ? toASCIIUpper(nextCharacter) : nextCharacter;
}
*resultPointer++ = character;
}
*resultPointer = '\\0';
return WTF::String(result);
}
static const bool isInheritedPropertyTable[numCSSProperties + $numPredefinedProperties] = {
false, // CSSPropertyInvalid
true, // CSSPropertyCustom
EOF
foreach my $name (@names) {
my $id = $nameToId{$name};
my $value = $nameIsInherited{$name} ? "true " : "false";
print GPERF " $value, // CSSProperty$id\n";
}
print GPERF<< "EOF";
};
bool CSSProperty::isInheritedProperty(CSSPropertyID id)
{
ASSERT(id <= lastCSSProperty);
ASSERT(id != CSSPropertyInvalid);
return isInheritedPropertyTable[id];
}
} // namespace WebCore
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
EOF
close GPERF;
open HEADER, ">CSSPropertyNames.h" || die "Could not open CSSPropertyNames.h for writing";
print HEADER << "EOF";
/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
#ifndef CSSPropertyNames_h
#define CSSPropertyNames_h
#include <string.h>
#include <wtf/HashFunctions.h>
#include <wtf/HashTraits.h>
namespace WTF {
class AtomicString;
class String;
}
namespace WebCore {
enum CSSPropertyID : uint16_t {
CSSPropertyInvalid = 0,
CSSPropertyCustom = 1,
EOF
my $first = $numPredefinedProperties;
my $i = $numPredefinedProperties;
my $maxLen = 0;
foreach my $name (@names) {
print HEADER " CSSProperty" . $nameToId{$name} . " = " . $i . ",\n";
$i = $i + 1;
if (length($name) > $maxLen) {
$maxLen = length($name);
}
}
my $num = $i - $first;
my $last = $i - 1;
print HEADER "};\n\n";
print HEADER "const int firstCSSProperty = $first;\n";
print HEADER "const int numCSSProperties = $num;\n";
print HEADER "const int lastCSSProperty = $last;\n";
print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
print HEADER << "EOF";
const char* getPropertyName(CSSPropertyID);
const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID id);
WTF::String getPropertyNameString(CSSPropertyID id);
WTF::String getJSPropertyName(CSSPropertyID);
inline CSSPropertyID convertToCSSPropertyID(int value)
{
ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == CSSPropertyInvalid || value == CSSPropertyCustom);
return static_cast<CSSPropertyID>(value);
}
} // namespace WebCore
namespace WTF {
template<> struct DefaultHash<WebCore::CSSPropertyID> { typedef IntHash<unsigned> Hash; };
template<> struct HashTraits<WebCore::CSSPropertyID> : GenericHashTraits<WebCore::CSSPropertyID> {
static const bool emptyValueIsZero = true;
static const bool needsDestruction = false;
static void constructDeletedValue(WebCore::CSSPropertyID& slot) { slot = static_cast<WebCore::CSSPropertyID>(WebCore::lastCSSProperty + 1); }
static bool isDeletedValue(WebCore::CSSPropertyID value) { return value == (WebCore::lastCSSProperty + 1); }
};
}
#endif // CSSPropertyNames_h
EOF
close HEADER;
#
# StyleBuilder.cpp generator.
#
sub getScopeForFunction {
my $name = shift;
my $builderFunction = shift;
return $propertiesWithStyleBuilderOptions{$name}{"Custom"}{$builderFunction} ? "StyleBuilderCustom" : "StyleBuilderFunctions";
}
sub getNameForMethods {
my $name = shift;
my $nameForMethods = $nameToId{$name};
$nameForMethods =~ s/Webkit//g;
if (exists($propertiesWithStyleBuilderOptions{$name}{"NameForMethods"})) {
$nameForMethods = $propertiesWithStyleBuilderOptions{$name}{"NameForMethods"};
}
return $nameForMethods;
}
sub getAutoGetter {
my $name = shift;
my $renderStyle = shift;
return $renderStyle . "->hasAuto" . getNameForMethods($name) . "()";
}
sub getAutoSetter {
my $name = shift;
my $renderStyle = shift;
return $renderStyle . "->setHasAuto" . getNameForMethods($name) . "()";
}
sub getVisitedLinkSetter {
my $name = shift;
my $renderStyle = shift;
return $renderStyle . "->setVisitedLink" . getNameForMethods($name);
}
sub getClearFunction {
my $name = shift;
return "clear" . getNameForMethods($name);
}
sub getEnsureAnimationsOrTransitionsMethod {
my $name = shift;
return "ensureAnimations" if $name =~ /animation-/;
return "ensureTransitions" if $name =~ /transition-/;
die "Unrecognized animation property name.";
}
sub getAnimationsOrTransitionsMethod {
my $name = shift;
return "animations" if $name =~ /animation-/;
return "transitions" if $name =~ /transition-/;
die "Unrecognized animation property name.";
}
sub getTestFunction {
my $name = shift;
return "is" . getNameForMethods($name) . "Set";
}
sub getAnimationMapfunction {
my $name = shift;
return "mapAnimation" . getNameForMethods($name);
}
sub getLayersFunction {
my $name = shift;
return "backgroundLayers" if $name =~ /background-/;
return "maskLayers" if $name =~ /mask-/;
die "Unrecognized FillLayer property name.";
}
sub getLayersAccessorFunction {
my $name = shift;
return "ensureBackgroundLayers" if $name =~ /background-/;
return "ensureMaskLayers" if $name =~ /mask-/;
die "Unrecognized FillLayer property name.";
}
sub getFillLayerType {
my $name = shift;
return "BackgroundFillLayer" if $name =~ /background-/;
return "MaskFillLayer" if $name =~ /mask-/;
}
sub getFillLayerMapfunction {
my $name = shift;
return "mapFill" . getNameForMethods($name);
}
foreach my $name (@names) {
my $nameForMethods = getNameForMethods($name);
$nameForMethods =~ s/Webkit//g;
if (exists($propertiesWithStyleBuilderOptions{$name}{"NameForMethods"})) {
$nameForMethods = $propertiesWithStyleBuilderOptions{$name}{"NameForMethods"};
}
if (!exists($propertiesWithStyleBuilderOptions{$name}{"Getter"})) {
$propertiesWithStyleBuilderOptions{$name}{"Getter"} = lcfirst($nameForMethods);
}
if (!exists($propertiesWithStyleBuilderOptions{$name}{"Setter"})) {
$propertiesWithStyleBuilderOptions{$name}{"Setter"} = "set" . $nameForMethods;
}
if (!exists($propertiesWithStyleBuilderOptions{$name}{"Initial"})) {
if (exists($propertiesWithStyleBuilderOptions{$name}{"FillLayerProperty"})) {
$propertiesWithStyleBuilderOptions{$name}{"Initial"} = "initialFill" . $nameForMethods;
} else {
$propertiesWithStyleBuilderOptions{$name}{"Initial"} = "initial" . $nameForMethods;
}
}
if (!exists($propertiesWithStyleBuilderOptions{$name}{"Custom"})) {
$propertiesWithStyleBuilderOptions{$name}{"Custom"} = "";
} elsif ($propertiesWithStyleBuilderOptions{$name}{"Custom"} eq "All") {
$propertiesWithStyleBuilderOptions{$name}{"Custom"} = "Initial|Inherit|Value";
}
my %customValues = map { $_ => 1 } split(/\|/, $propertiesWithStyleBuilderOptions{$name}{"Custom"});
$propertiesWithStyleBuilderOptions{$name}{"Custom"} = \%customValues;
}
use constant {
NOT_FOR_VISITED_LINK => 0,
FOR_VISITED_LINK => 1,
};
sub colorFromPrimitiveValue {
my $primitiveValue = shift;
my $forVisitedLink = @_ ? shift : NOT_FOR_VISITED_LINK;
return "styleResolver.colorFromPrimitiveValue(" . $primitiveValue . ", /* forVisitedLink */ " . ($forVisitedLink ? "true" : "false") . ")";
}
use constant {
VALUE_IS_COLOR => 0,
VALUE_IS_PRIMITIVE => 1,
};
sub generateColorValueSetter {
my $name = shift;
my $value = shift;
my $indent = shift;
my $valueIsPrimitive = @_ ? shift : VALUE_IS_COLOR;
my $style = "styleResolver.style()";
my $setterContent .= $indent . "if (styleResolver.applyPropertyToRegularStyle())\n";
my $setValue = $style . "->" . $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $color = $valueIsPrimitive ? colorFromPrimitiveValue($value) : $value;
$setterContent .= $indent . " " . $setValue . "(" . $color . ");\n";
$setterContent .= $indent . "if (styleResolver.applyPropertyToVisitedLinkStyle())\n";
$color = $valueIsPrimitive ? colorFromPrimitiveValue($value, FOR_VISITED_LINK) : $value;
$setterContent .= $indent . " " . getVisitedLinkSetter($name, $style) . "(" . $color . ");\n";
return $setterContent;
}
sub handleCurrentColorValue {
my $name = shift;
my $primitiveValue = shift;
my $indent = shift;
my $code = $indent . "if (" . $primitiveValue . ".getValueID() == CSSValueCurrentcolor) {\n";
$code .= $indent . " applyInherit" . $nameToId{$name} . "(styleResolver);\n";
$code .= $indent . " return;\n";
$code .= $indent . "}\n";
return $code;
}
sub generateAnimationPropertyInitialValueSetter {
my $name = shift;
my $indent = shift;
my $setterContent = "";
$setterContent .= $indent . "AnimationList& list = styleResolver.style()->" . getEnsureAnimationsOrTransitionsMethod($name) . "();\n";
$setterContent .= $indent . "if (list.isEmpty())\n";
$setterContent .= $indent . " list.append(Animation::create());\n";
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $initial = $propertiesWithStyleBuilderOptions{$name}{"Initial"};
$setterContent .= $indent . "list.animation(0)." . $setter . "(Animation::" . $initial . "());\n";
if ($name eq "-webkit-transition-property") {
$setterContent .= $indent . "list.animation(0).setAnimationMode(Animation::AnimateAll);\n";
}
$setterContent .= $indent . "for (size_t i = 1; i < list.size(); ++i)\n";
$setterContent .= $indent . " list.animation(i)." . getClearFunction($name) . "();\n";
return $setterContent;
}
sub generateAnimationPropertyInheritValueSetter {
my $name = shift;
my $indent = shift;
my $setterContent = "";
$setterContent .= $indent . "AnimationList& list = styleResolver.style()->" . getEnsureAnimationsOrTransitionsMethod($name) . "();\n";
$setterContent .= $indent . "const AnimationList* parentList = styleResolver.parentStyle()->" . getAnimationsOrTransitionsMethod($name) . "();\n";
$setterContent .= $indent . "size_t i = 0, parentSize = parentList ? parentList->size() : 0;\n";
$setterContent .= $indent . "for ( ; i < parentSize && parentList->animation(i)." . getTestFunction($name) . "(); ++i) {\n";
$setterContent .= $indent . " if (list.size() <= i)\n";
$setterContent .= $indent . " list.append(Animation::create());\n";
my $getter = $propertiesWithStyleBuilderOptions{$name}{"Getter"};
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
$setterContent .= $indent . " list.animation(i)." . $setter . "(parentList->animation(i)." . $getter . "());\n";
$setterContent .= $indent . " list.animation(i).setAnimationMode(parentList->animation(i).animationMode());\n";
$setterContent .= $indent . "}\n";
$setterContent .= "\n";
$setterContent .= $indent . "/* Reset any remaining animations to not have the property set. */\n";
$setterContent .= $indent . "for ( ; i < list.size(); ++i)\n";
$setterContent .= $indent . " list.animation(i)." . getClearFunction($name) . "();\n";
return $setterContent;
}
sub generateAnimationPropertyValueSetter {
my $name = shift;
my $indent = shift;
my $setterContent = "";
$setterContent .= $indent . "AnimationList& list = styleResolver.style()->" . getEnsureAnimationsOrTransitionsMethod($name) . "();\n";
$setterContent .= $indent . "size_t childIndex = 0;\n";
$setterContent .= $indent . "if (is<CSSValueList>(value)) {\n";
$setterContent .= $indent . " /* Walk each value and put it into an animation, creating new animations as needed. */\n";
$setterContent .= $indent . " for (auto& currentValue : downcast<CSSValueList>(value)) {\n";
$setterContent .= $indent . " if (childIndex <= list.size())\n";
$setterContent .= $indent . " list.append(Animation::create());\n";
$setterContent .= $indent . " styleResolver.styleMap()->" . getAnimationMapfunction($name) . "(list.animation(childIndex), currentValue);\n";
$setterContent .= $indent . " ++childIndex;\n";
$setterContent .= $indent . " }\n";
$setterContent .= $indent . "} else {\n";
$setterContent .= $indent . " if (list.isEmpty())\n";
$setterContent .= $indent . " list.append(Animation::create());\n";
$setterContent .= $indent . " styleResolver.styleMap()->" . getAnimationMapfunction($name) . "(list.animation(childIndex), value);\n";
$setterContent .= $indent . " childIndex = 1;\n";
$setterContent .= $indent . "}\n";
$setterContent .= $indent . "for ( ; childIndex < list.size(); ++childIndex) {\n";
$setterContent .= $indent . " /* Reset all remaining animations to not have the property set. */\n";
$setterContent .= $indent . " list.animation(childIndex)." . getClearFunction($name) . "();\n";
$setterContent .= $indent . "}\n";
return $setterContent;
}
sub generateFillLayerPropertyInitialValueSetter {
my $name = shift;
my $indent = shift;
my $getter = $propertiesWithStyleBuilderOptions{$name}{"Getter"};
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $clearFunction = getClearFunction($name);
my $testFunction = getTestFunction($name);
my $initial = "FillLayer::" . $propertiesWithStyleBuilderOptions{$name}{"Initial"} . "(" . getFillLayerType($name) . ")";
my $setterContent = "";
$setterContent .= $indent . "// Check for (single-layer) no-op before clearing anything.\n";
$setterContent .= $indent . "const FillLayer& layers = *styleResolver.style()->" . getLayersFunction($name) . "();\n";
$setterContent .= $indent . "if (!layers.next() && (!layers." . $testFunction . "() || layers." . $getter . "() == $initial))\n";
$setterContent .= $indent . " return;\n";
$setterContent .= "\n";
$setterContent .= $indent . "FillLayer* child = &styleResolver.style()->" . getLayersAccessorFunction($name) . "();\n";
$setterContent .= $indent . "child->" . $setter . "(" . $initial . ");\n";
$setterContent .= $indent . "for (child = child->next(); child; child = child->next())\n";
$setterContent .= $indent . " child->" . $clearFunction . "();\n";
return $setterContent;
}
sub generateFillLayerPropertyInheritValueSetter {
my $name = shift;
my $indent = shift;
my $getter = $propertiesWithStyleBuilderOptions{$name}{"Getter"};
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $clearFunction = getClearFunction($name);
my $testFunction = getTestFunction($name);
my $setterContent = "";
$setterContent .= $indent . "// Check for no-op before copying anything.\n";
$setterContent .= $indent . "if (*styleResolver.parentStyle()->" . getLayersFunction($name) ."() == *styleResolver.style()->" . getLayersFunction($name) . "())\n";
$setterContent .= $indent . " return;\n";
$setterContent .= "\n";
$setterContent .= $indent . "auto* child = &styleResolver.style()->" . getLayersAccessorFunction($name) . "();\n";
$setterContent .= $indent . "FillLayer* previousChild = nullptr;\n";
$setterContent .= $indent . "for (auto* parent = styleResolver.parentStyle()->" . getLayersFunction($name) . "(); parent && parent->" . $testFunction . "(); parent = parent->next()) {\n";
$setterContent .= $indent . " if (!child) {\n";
$setterContent .= $indent . " previousChild->setNext(std::make_unique<FillLayer>(" . getFillLayerType($name) . "));\n";
$setterContent .= $indent . " child = previousChild->next();\n";
$setterContent .= $indent . " }\n";
$setterContent .= $indent . " child->" . $setter . "(parent->" . $getter . "());\n";
$setterContent .= $indent . " previousChild = child;\n";
$setterContent .= $indent . " child = previousChild->next();\n";
$setterContent .= $indent . "}\n";
$setterContent .= $indent . "for (; child; child = child->next())\n";
$setterContent .= $indent . " child->" . $clearFunction . "();\n";
return $setterContent;
}
sub generateFillLayerPropertyValueSetter {
my $name = shift;
my $indent = shift;
my $CSSPropertyId = "CSSProperty" . $nameToId{$name};
my $setterContent = "";
$setterContent .= $indent . "FillLayer* child = &styleResolver.style()->" . getLayersAccessorFunction($name) . "();\n";
$setterContent .= $indent . "FillLayer* previousChild = nullptr;\n";
$setterContent .= $indent . "if (is<CSSValueList>(value)\n";
$setterContent .= "#if ENABLE(CSS_IMAGE_SET)\n";
$setterContent .= $indent . "&& !is<CSSImageSetValue>(value)\n";
$setterContent .= "#endif\n";
$setterContent .= $indent . ") {\n";
$setterContent .= $indent . " // Walk each value and put it into a layer, creating new layers as needed.\n";
$setterContent .= $indent . " for (auto& item : downcast<CSSValueList>(value)) {\n";
$setterContent .= $indent . " if (!child) {\n";
$setterContent .= $indent . " previousChild->setNext(std::make_unique<FillLayer>(" . getFillLayerType($name) . "));\n";
$setterContent .= $indent . " child = previousChild->next();\n";
$setterContent .= $indent . " }\n";
$setterContent .= $indent . " styleResolver.styleMap()->" . getFillLayerMapfunction($name) . "(" . $CSSPropertyId . ", *child, item);\n";
$setterContent .= $indent . " previousChild = child;\n";
$setterContent .= $indent . " child = child->next();\n";
$setterContent .= $indent . " }\n";
$setterContent .= $indent . "} else {\n";
$setterContent .= $indent . " styleResolver.styleMap()->" . getFillLayerMapfunction($name) . "(" . $CSSPropertyId . ", *child, value);\n";
$setterContent .= $indent . " child = child->next();\n";
$setterContent .= $indent . "}\n";
$setterContent .= $indent . "for (; child; child = child->next())\n";
$setterContent .= $indent . " child->" . getClearFunction($name) . "();\n";
return $setterContent;
}
sub generateSetValueStatement
{
my $name = shift;
my $value = shift;
my $isSVG = exists $propertiesWithStyleBuilderOptions{$name}{"SVG"};
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
return "styleResolver.style()->" . ($isSVG ? "accessSVGStyle()." : "") . $setter . "(" . $value . ")";
}
sub generateInitialValueSetter {
my $name = shift;
my $indent = shift;
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $initial = $propertiesWithStyleBuilderOptions{$name}{"Initial"};
my $isSVG = exists $propertiesWithStyleBuilderOptions{$name}{"SVG"};
my $setterContent = "";
$setterContent .= $indent . "static void applyInitial" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
$setterContent .= $indent . "{\n";
my $style = "styleResolver.style()";
if (exists $propertiesWithStyleBuilderOptions{$name}{"AutoFunctions"}) {
$setterContent .= $indent . " " . getAutoSetter($name, $style) . ";\n";
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"VisitedLinkColorSupport"}) {
my $initialColor = "RenderStyle::" . $initial . "()";
$setterContent .= generateColorValueSetter($name, $initialColor, $indent . " ");
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"AnimationProperty"}) {
$setterContent .= generateAnimationPropertyInitialValueSetter($name, $indent . " ");
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FontProperty"}) {
$setterContent .= $indent . " auto fontDescription = styleResolver.fontDescription();\n";
$setterContent .= $indent . " fontDescription." . $setter . "(FontCascadeDescription::" . $initial . "());\n";
$setterContent .= $indent . " styleResolver.setFontDescription(fontDescription);\n";
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FillLayerProperty"}) {
$setterContent .= generateFillLayerPropertyInitialValueSetter($name, $indent . " ");
} else {
my $initialValue = ($isSVG ? "SVGRenderStyle" : "RenderStyle") . "::" . $initial . "()";
$setterContent .= $indent . " " . generateSetValueStatement($name, $initialValue) . ";\n";
}
$setterContent .= $indent . "}\n";
return $setterContent;
}
sub generateInheritValueSetter {
my $name = shift;
my $indent = shift;
my $setterContent = "";
$setterContent .= $indent . "static void applyInherit" . $nameToId{$name} . "(StyleResolver& styleResolver)\n";
$setterContent .= $indent . "{\n";
my $isSVG = exists $propertiesWithStyleBuilderOptions{$name}{"SVG"};
my $parentStyle = "styleResolver.parentStyle()";
my $style = "styleResolver.style()";
my $getter = $propertiesWithStyleBuilderOptions{$name}{"Getter"};
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $didCallSetValue = 0;
if (exists $propertiesWithStyleBuilderOptions{$name}{"AutoFunctions"}) {
$setterContent .= $indent . " if (" . getAutoGetter($name, $parentStyle) . ") {\n";
$setterContent .= $indent . " " . getAutoSetter($name, $style) . ";\n";
$setterContent .= $indent . " return;\n";
$setterContent .= $indent . " }\n";
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"VisitedLinkColorSupport"}) {
$setterContent .= $indent . " Color color = " . $parentStyle . "->" . $getter . "();\n";
if (!exists($propertiesWithStyleBuilderOptions{$name}{"NoDefaultColor"})) {
$setterContent .= $indent . " if (!color.isValid())\n";
$setterContent .= $indent . " color = " . $parentStyle . "->color();\n";
}
$setterContent .= generateColorValueSetter($name, "color", $indent . " ");
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"AnimationProperty"}) {
$setterContent .= generateAnimationPropertyInheritValueSetter($name, $indent . " ");
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FontProperty"}) {
$setterContent .= $indent . " auto fontDescription = styleResolver.fontDescription();\n";
$setterContent .= $indent . " fontDescription." . $setter . "(styleResolver.parentFontDescription()." . $getter . "());\n";
$setterContent .= $indent . " styleResolver.setFontDescription(fontDescription);\n";
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FillLayerProperty"}) {
$setterContent .= generateFillLayerPropertyInheritValueSetter($name, $indent . " ");
$didCallSetValue = 1;
}
if (!$didCallSetValue) {
my $inheritedValue = $parentStyle . "->" . ($isSVG ? "svgStyle()." : "") . $getter . "()";
$setterContent .= $indent . " " . generateSetValueStatement($name, $inheritedValue) . ";\n";
}
$setterContent .= $indent . "}\n";
return $setterContent;
}
sub generateValueSetter {
my $name = shift;
my $indent = shift;
my $setterContent = "";
$setterContent .= $indent . "static void applyValue" . $nameToId{$name} . "(StyleResolver& styleResolver, CSSValue& value)\n";
$setterContent .= $indent . "{\n";
my $convertedValue;
if (exists($propertiesWithStyleBuilderOptions{$name}{"Converter"})) {
$convertedValue = "StyleBuilderConverter::convert" . $propertiesWithStyleBuilderOptions{$name}{"Converter"} . "(styleResolver, value)";
} elsif (exists($propertiesWithStyleBuilderOptions{$name}{"ConditionalConverter"})) {
$setterContent .= $indent . " auto convertedValue = StyleBuilderConverter::convert" . $propertiesWithStyleBuilderOptions{$name}{"ConditionalConverter"} . "(styleResolver, value);\n";
$convertedValue = "convertedValue.value()";
} else {
$convertedValue = "downcast<CSSPrimitiveValue>(value)";
}
my $setter = $propertiesWithStyleBuilderOptions{$name}{"Setter"};
my $style = "styleResolver.style()";
my $didCallSetValue = 0;
if (exists $propertiesWithStyleBuilderOptions{$name}{"AutoFunctions"}) {
$setterContent .= $indent . " if (downcast<CSSPrimitiveValue>(value).getValueID() == CSSValueAuto) {\n";
$setterContent .= $indent . " ". getAutoSetter($name, $style) . ";\n";
$setterContent .= $indent . " return;\n";
$setterContent .= $indent . " }\n";
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"VisitedLinkColorSupport"}) {
$setterContent .= $indent . " auto& primitiveValue = downcast<CSSPrimitiveValue>(value);\n";
if ($name eq "color") {
# The "color" property supports "currentColor" value. We should add a parameter.
$setterContent .= handleCurrentColorValue($name, "primitiveValue", $indent . " ");
}
$setterContent .= generateColorValueSetter($name, "primitiveValue", $indent . " ", VALUE_IS_PRIMITIVE);
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"AnimationProperty"}) {
$setterContent .= generateAnimationPropertyValueSetter($name, $indent . " ");
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FontProperty"}) {
$setterContent .= $indent . " auto fontDescription = styleResolver.fontDescription();\n";
$setterContent .= $indent . " fontDescription." . $setter . "(" . $convertedValue . ");\n";
$setterContent .= $indent . " styleResolver.setFontDescription(fontDescription);\n";
$didCallSetValue = 1;
} elsif (exists $propertiesWithStyleBuilderOptions{$name}{"FillLayerProperty"}) {
$setterContent .= generateFillLayerPropertyValueSetter($name, $indent . " ");
$didCallSetValue = 1;
}
if (!$didCallSetValue) {
if (exists($propertiesWithStyleBuilderOptions{$name}{"ConditionalConverter"})) {
$setterContent .= $indent . " if (convertedValue)\n";
$setterContent .= " ";
}
$setterContent .= $indent . " " . generateSetValueStatement($name, $convertedValue) . ";\n";
}
$setterContent .= $indent . "}\n";
return $setterContent;
}
open STYLEBUILDER, ">StyleBuilder.cpp" || die "Could not open StyleBuilder.cpp for writing";
print STYLEBUILDER << "EOF";
/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
#include "config.h"
#include "StyleBuilder.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSProperty.h"
#include "RenderStyle.h"
#include "StyleBuilderConverter.h"
#include "StyleBuilderCustom.h"
#include "StylePropertyShorthand.h"
#include "StyleResolver.h"
namespace WebCore {
class StyleBuilderFunctions {
public:
EOF
foreach my $name (@names) {
# Skip Shorthand properties and properties that do not use the StyleBuilder.
next if (exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
next if (exists $propertiesWithStyleBuilderOptions{$name}{"SkipBuilder"});
my $indent = " ";
if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Initial"}) {
print STYLEBUILDER generateInitialValueSetter($name, $indent);
}
if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Inherit"}) {
print STYLEBUILDER generateInheritValueSetter($name, $indent);
}
if (!$propertiesWithStyleBuilderOptions{$name}{"Custom"}{"Value"}) {
print STYLEBUILDER generateValueSetter($name, $indent);
}
}
print STYLEBUILDER << "EOF";
};
void StyleBuilder::applyProperty(CSSPropertyID property, StyleResolver& styleResolver, CSSValue& value, bool isInitial, bool isInherit)
{
switch (property) {
case CSSPropertyInvalid:
case CSSPropertyCustom:
break;
EOF
foreach my $name (@names) {
print STYLEBUILDER " case CSSProperty" . $nameToId{$name} . ":\n";
if (exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"}) {
print STYLEBUILDER " ASSERT(isShorthandCSSProperty(property));\n";
print STYLEBUILDER " ASSERT_NOT_REACHED();\n";
} elsif (!exists $propertiesWithStyleBuilderOptions{$name}{"SkipBuilder"}) {
print STYLEBUILDER " if (isInitial)\n";
print STYLEBUILDER " " . getScopeForFunction($name, "Initial") . "::applyInitial" . $nameToId{$name} . "(styleResolver);\n";
print STYLEBUILDER " else if (isInherit)\n";
print STYLEBUILDER " " . getScopeForFunction($name, "Inherit") . "::applyInherit" . $nameToId{$name} . "(styleResolver);\n";
print STYLEBUILDER " else\n";
print STYLEBUILDER " " . getScopeForFunction($name, "Value") . "::applyValue" . $nameToId{$name} . "(styleResolver, value);\n";
}
print STYLEBUILDER " break;\n";
}
print STYLEBUILDER << "EOF";
};
}
} // namespace WebCore
EOF
close STYLEBUILDER;
# Generate StylePropertyShorthandsFunctions.
open SHORTHANDS_H, ">StylePropertyShorthandFunctions.h" || die "Could not open StylePropertyShorthandFunctions.h for writing";
print SHORTHANDS_H << "EOF";
/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
#ifndef StylePropertyShorthandFunctions_h
#define StylePropertyShorthandFunctions_h
namespace WebCore {
class StylePropertyShorthand;
EOF
foreach my $name (@names) {
# Skip non-Shorthand properties.
next if (!exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
print SHORTHANDS_H "StylePropertyShorthand " . lcfirst($nameToId{$name}) . "Shorthand();\n";
}
print SHORTHANDS_H << "EOF";
} // namespace WebCore
#endif // StylePropertyShorthandFunctions_h
EOF
close SHORTHANDS_H;
open SHORTHANDS_CPP, ">StylePropertyShorthandFunctions.cpp" || die "Could not open StylePropertyShorthandFunctions.cpp for writing";
print SHORTHANDS_CPP << "EOF";
/* This file is automatically generated from CSSPropertyNames.in by makeprop, do not edit */
#include "config.h"
#include "StylePropertyShorthandFunctions.h"
#include "StylePropertyShorthand.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
EOF
my %longhandToShorthands = ();
foreach my $name (@names) {
# Skip non-Shorthand properties.
next if (!exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
my $lowercaseId = lcfirst($nameToId{$name});
my @longhands = split(/\|/, $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
print SHORTHANDS_CPP "StylePropertyShorthand " . $lowercaseId . "Shorthand()\n";
print SHORTHANDS_CPP "{\n";
print SHORTHANDS_CPP " static const CSSPropertyID " . $lowercaseId . "Properties[] = {\n";
foreach (@longhands) {
if ($_ eq "all") {
foreach my $propname (@names) {
next if (exists $propertiesWithStyleBuilderOptions{$propname}{"Longhands"});
next if ($propname eq "direction" || $propname eq "unicode-bidi");
die "Unknown CSS property used in all shorthand: " . $nameToId{$propname} if !exists($nameToId{$propname});
push(@{$longhandToShorthands{$propname}}, $name);
print SHORTHANDS_CPP " CSSProperty" . $nameToId{$propname} . ",\n";
}
} else {
die "Unknown CSS property used in Longhands: " . $nameToId{$_} if !exists($nameToId{$_});
push(@{$longhandToShorthands{$_}}, $name);
print SHORTHANDS_CPP " CSSProperty" . $nameToId{$_} . ",\n";
}
}
print SHORTHANDS_CPP " };\n";
print SHORTHANDS_CPP " return StylePropertyShorthand(CSSProperty" . $nameToId{$name} . ", " . $lowercaseId . "Properties);\n";
print SHORTHANDS_CPP "}\n\n";
}
print SHORTHANDS_CPP << "EOF";
StylePropertyShorthand shorthandForProperty(CSSPropertyID propertyID)
{
static NeverDestroyed<StylePropertyShorthand> emptyShorthand;
switch (propertyID) {
EOF
foreach my $name (@names) {
# Skip non-Shorthand properties.
next if (!exists $propertiesWithStyleBuilderOptions{$name}{"Longhands"});
print SHORTHANDS_CPP " case CSSProperty" . $nameToId{$name} . ":\n";
print SHORTHANDS_CPP " return " . lcfirst($nameToId{$name}) . "Shorthand();\n";
}
print SHORTHANDS_CPP << "EOF";
default:
return emptyShorthand;
}
}
EOF
print SHORTHANDS_CPP << "EOF";
Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
{
switch (propertyID) {
EOF
sub constructShorthandsVector {
my $shorthands = shift;
my $vector = "Vector<StylePropertyShorthand>{";
foreach my $i (0 .. $#$shorthands) {
$vector .= ", " unless $i == 0;
$vector .= lcfirst($nameToId{$shorthands->[$i]}) . "Shorthand()";
}
$vector .= "}";
return $vector;
}
my %vectorToLonghands = ();
for my $longhand (sort keys %longhandToShorthands) {
my @shorthands = sort(@{$longhandToShorthands{$longhand}});
push(@{$vectorToLonghands{constructShorthandsVector(\@shorthands)}}, $longhand);
}
for my $vector (sort keys %vectorToLonghands) {
foreach (@{$vectorToLonghands{$vector}}) {
print SHORTHANDS_CPP " case CSSProperty" . $nameToId{$_} . ":\n";
}
print SHORTHANDS_CPP " return " . $vector . ";\n";
}
print SHORTHANDS_CPP << "EOF";
default:
return { };
}
}
EOF
print SHORTHANDS_CPP << "EOF";
} // namespace WebCore
EOF
close SHORTHANDS_CPP;
if (not $gperf) {
$gperf = $ENV{GPERF} ? $ENV{GPERF} : "gperf";
}
system("\"$gperf\" --key-positions=\"*\" -D -n -s 2 CSSPropertyNames.gperf --output-file=CSSPropertyNames.cpp") == 0 || die "calling gperf failed: $?";
|