Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit c97416897da89f7d35d76c0cd7387b7d4a85ece2 @jverkoey committed Nov 19, 2010
@@ -0,0 +1,2 @@
+build/
+Grammars/CssTokenizer.cpp
@@ -0,0 +1,25 @@
+//
+// Copyright 2009-2010 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "../../src/common/Configurations/Library.xcconfig"
+#include "../../src/common/Configurations/Libraries.xcconfig"
+
+BASE_PRODUCT_NAME = extCSSStyle
+PRODUCT_NAME = $(BASE_PRODUCT_NAME)
+BUILD_LIBRARY_VERSION = 1.0
+
+PRIVATE_HEADERS_FOLDER_PATH = /../three20/$(BASE_PRODUCT_NAME)/private
+PUBLIC_HEADERS_FOLDER_PATH = /../three20/$(BASE_PRODUCT_NAME)
@@ -0,0 +1,17 @@
+//
+// Copyright 2009-2010 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "../../src/common/Configurations/Project.xcconfig"
@@ -0,0 +1,24 @@
+//
+// Copyright 2009-2010 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "../../src/common/Configurations/UnitTests.xcconfig"
+#include "../../src/common/Configurations/Libraries.xcconfig"
+
+BASE_PRODUCT_NAME = extCSSStyleUnitTests
+PRODUCT_NAME = $(BASE_PRODUCT_NAME)
+BUILD_BUNDLE_VERSION = 1.0
+
+OTHER_LDFLAGS = $(COMMON_LDFLAGS) $(UIKIT_FX)
@@ -0,0 +1,10 @@
+flex --prefix=css --nounput css.grammar
+
+cat CssTokenizerPrefix > CssTokenizer.cpp
+cat lex.css.c >> CssTokenizer.cpp
+
+rm lex.css.c
+
+mv CssTokenizer.cpp ../Sources/CssTokenizer.m
+cp CssTokens.cpp ../Sources/CssTokens.m
+cp CssToken*.h ../Headers/
@@ -0,0 +1 @@
+#include "extThree20CSSStyle/private/CssTokens.h"
@@ -0,0 +1,19 @@
+
+const char* cssnames[] = {
+ "STRING",
+ "IDENT",
+ "HASH",
+ "EMS",
+ "EXS",
+ "LENGTH",
+ "ANGLE",
+ "TIME",
+ "FREQ",
+ "DIMEN",
+ "PERCENTAGE",
+ "NUMBER",
+ "URI",
+ "FUNCTION",
+ "UNICODERANGE",
+ "UNKNOWN",
+};
@@ -0,0 +1,35 @@
+
+#include <stdio.h>
+
+typedef enum {
+ CSSFIRST_TOKEN = 0x100,
+ CSSSTRING = CSSFIRST_TOKEN,
+ CSSIDENT,
+ CSSHASH,
+ CSSEMS,
+ CSSEXS,
+ CSSLENGTH,
+ CSSANGLE,
+ CSSTIME,
+ CSSFREQ,
+ CSSDIMEN,
+ CSSPERCENTAGE,
+ CSSNUMBER,
+ CSSURI,
+ CSSFUNCTION,
+ CSSUNICODERANGE,
+ CSSUNKNOWN,
+
+} CssParserCodes;
+
+extern const char* cssnames[];
+
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+extern FILE *cssin;
+
+int csslex(void);
+int cssConsume(char* text, int token);
@@ -0,0 +1,78 @@
+%option case-insensitive
+
+h [0-9a-f]
+nonascii [\200-\377]
+unicode \\{h}{1,6}[ \t\r\n\f]?
+escape {unicode}|\\[ -~\200-\377]
+nmstart [a-z]|{nonascii}|{escape}
+nmchar [a-z0-9-]|{nonascii}|{escape}
+string1 \"([\t !#$%&(-~]|\\{nl}|\'|{nonascii}|{escape})*\"
+string2 \'([\t !#$%&(-~]|\\{nl}|\"|{nonascii}|{escape})*\'
+
+ident [-]?{nmstart}{nmchar}*
+name {nmchar}+
+num [-]?[0-9]+|[-]?[0-9]*"."[0-9]+
+string {string1}|{string2}
+url ([!#$%&*-~]|{nonascii}|{escape})*
+w [ \t\r\n\f]*
+nl \n|\r\n|\r|\f
+range \?{1,6}|{h}(\?{0,5}|{h}(\?{0,4}|{h}(\?{0,3}|{h}(\?{0,2}|{h}(\??|{h})))))
+
+%%
+
+[ \t\r\n\f]+
+
+\/\*[^*]*\*+([^/][^*]*\*+)*\/ /* ignore comments */
+
+"<!--"
+"-->"
+"~="
+"|="
+
+{string} {cssConsume(yytext, CSSSTRING);}
+
+{ident}(:{ident})? {cssConsume(yytext, CSSIDENT);}
+
+"#"{name} {cssConsume(yytext, CSSHASH);}
+
+"@import"
+"@page"
+"@media"
+"@font-face"
+"@charset"
+"@namespace"
+
+"!{w}important"
+
+{num}em {cssConsume(yytext, CSSEMS);}
+{num}ex {cssConsume(yytext, CSSEXS);}
+{num}px {cssConsume(yytext, CSSLENGTH);}
+{num}cm {cssConsume(yytext, CSSLENGTH);}
+{num}mm {cssConsume(yytext, CSSLENGTH);}
+{num}in {cssConsume(yytext, CSSLENGTH);}
+{num}pt {cssConsume(yytext, CSSLENGTH);}
+{num}pc {cssConsume(yytext, CSSLENGTH);}
+{num}deg {cssConsume(yytext, CSSANGLE);}
+{num}rad {cssConsume(yytext, CSSANGLE);}
+{num}grad {cssConsume(yytext, CSSANGLE);}
+{num}ms {cssConsume(yytext, CSSTIME);}
+{num}s {cssConsume(yytext, CSSTIME);}
+{num}Hz {cssConsume(yytext, CSSFREQ);}
+{num}kHz {cssConsume(yytext, CSSFREQ);}
+{num}{ident} {cssConsume(yytext, CSSDIMEN);}
+{num}% {cssConsume(yytext, CSSPERCENTAGE);}
+{num} {cssConsume(yytext, CSSNUMBER);}
+
+"url("{w}{string}{w}")" {cssConsume(yytext, CSSURI);}
+"url("{w}{url}{w}")" {cssConsume(yytext, CSSURI);}
+{ident}"(" {cssConsume(yytext, CSSFUNCTION);}
+
+U\+{range} {cssConsume(yytext, CSSUNICODERANGE);}
+U\+{h}{1,6}-{h}{1,6} {cssConsume(yytext, CSSUNICODERANGE);}
+
+. {cssConsume(yytext, CSSUNKNOWN);}
+
+%%
+
+int csswrap(void){return 1;}
+
@@ -0,0 +1,35 @@
+
+#include <stdio.h>
+
+typedef enum {
+ CSSFIRST_TOKEN = 0x100,
+ CSSSTRING = CSSFIRST_TOKEN,
+ CSSIDENT,
+ CSSHASH,
+ CSSEMS,
+ CSSEXS,
+ CSSLENGTH,
+ CSSANGLE,
+ CSSTIME,
+ CSSFREQ,
+ CSSDIMEN,
+ CSSPERCENTAGE,
+ CSSNUMBER,
+ CSSURI,
+ CSSFUNCTION,
+ CSSUNICODERANGE,
+ CSSUNKNOWN,
+
+} CssParserCodes;
+
+extern const char* cssnames[];
+
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+extern FILE *cssin;
+
+int csslex(void);
+int cssConsume(char* text, int token);
@@ -0,0 +1,54 @@
+//
+// Copyright 2009-2010 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+/**
+ * CSS Jargon:
+ *
+ * Rule Set: A selector and a set of property/value pairs.
+ * Selector: An identifier for a rule set. Example: "img"
+ * Property: A name for a set of values. Example: "color"
+ * Value: A value for a property.
+ *
+ * img { \
+ * border-color: red; | A single rule set.
+ * } /
+ */
+@interface TTCSSParser : NSObject {
+@private
+ NSMutableDictionary* _ruleSets;
+ NSMutableArray* _activeCssSelectors;
+ NSMutableDictionary* _activeRuleSet;
+ NSString* _activePropertyName;
+
+ NSString* _lastTokenText;
+ int _lastToken;
+
+ union {
+ struct {
+ int InsideDefinition : 1;
+ int InsideProperty : 1;
+ int InsideFunction : 1;
+ } Flags;
+ int _data;
+ } _state;
+}
+
+- (NSDictionary*)parseFilename:(NSString*)filename;
+
+@end
@@ -0,0 +1,85 @@
+//
+// Copyright 2009-2010 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+/**
+ * A general purpose CSS style sheet object for accessing a CSS style sheet's properties.
+ *
+ * This is useful if you want to use style sheets to manually customize certain aspects of
+ * your UI.
+ *
+ * Example apps: three20/samples/Style/TTCSSStyleSheets
+ */
+@interface TTCSSStyleSheet : NSObject {
+@private
+ NSDictionary* _cssStyles;
+
+ NSMutableDictionary* _cachedCssStyles;
+
+ NSDictionary* _colorLookupTable;
+}
+
+@property (nonatomic, readonly) NSDictionary* cssStyles;
+
+
+/**
+ * Load the style sheet into memory from disk.
+ *
+ * @return NO if the file does not exist.
+ */
+- (BOOL)loadFromFilename:(NSString*)filename;
+
+/**
+ * Add a stylesheet to this one, overriding any properties as expected.
+ */
+- (void)addStyleSheet:(TTCSSStyleSheet*)styleSheet;
+
+
+/**
+ * Get (text) color from a specific rule set.
+ */
+- (UIColor*)colorWithCssSelector:(NSString*)selector forState:(UIControlState)state;
+
+/**
+ * Get background-color from a specific rule set.
+ */
+- (UIColor*)backgroundColorWithCssSelector:(NSString*)selector forState:(UIControlState)state;
+
+/**
+ * Get font from a specific rule set.
+ */
+- (UIFont*)fontWithCssSelector:(NSString*)selector forState:(UIControlState)state;
+
+/**
+ * Get text shadow color from a specific rule set.
+ */
+- (UIColor*)textShadowColorWithCssSelector:(NSString*)selector forState:(UIControlState)state;
+
+/**
+ * Get text shadow offset from a specific rule set.
+ */
+- (CGSize)textShadowOffsetWithCssSelector:(NSString*)selector forState:(UIControlState)state;
+
+
+/**
+ * Release all cached data.
+ */
+- (void)freeMemory;
+
+
+@end
Oops, something went wrong.

0 comments on commit c974168

Please sign in to comment.