@@ -48,7 +48,9 @@ - (NSString *)styleSelector
4848- (void )applyStylesWithScriptEngine : (GAScriptEngine *)engine
4949{
5050 NSString * selector = [self styleSelector ];
51+ #if 1
5152 NSLog (@" GAViewStyling selector: %@ " , selector);
53+ #endif
5254
5355 id element = [[engine documentObject ] querySelector: selector];
5456
@@ -73,13 +75,26 @@ - (void)applyComputedStyles:(id)cssDeclaration
7375
7476 NSString * backgroundImage = [cssDeclaration valueForKey: @" background-image" ];
7577
76- // TODO: If this view's layer is a CAGradientLayer, we can use a webkit linear gradient
78+ // If this view's layer is a CAGradientLayer, we can use a webkit linear gradient
7779 // -webkit-gradient(<type>, <point>, <point> [, <stop>]*)
7880 //
79- if ([backgroundImage hasPrefix: @" -webkit-gradient(linear," ]
80- && [self .layer isKindOfClass: [CAGradientLayer class ]])
81+ if ([backgroundImage hasPrefix: @" -webkit-gradient(linear," ])
8182 {
82- NSLog (@" TODO: Gradient: %@ " , backgroundImage);
83+ CAGradientLayer * gradLayer = [self .layer.sublayers objectAtIndex: 0 ];
84+
85+ if (![gradLayer valueForKey: @" GAViewStylingID" ])
86+ {
87+ gradLayer = [CAGradientLayer layer ];
88+ [gradLayer setValue: @" -webkit-gradient" forKey: @" GAViewStylingID" ];
89+
90+ CGRect bounds = [self bounds ];
91+ [gradLayer setBounds: bounds];
92+ [gradLayer setPosition: CGPointMake (CGRectGetMidX (bounds), CGRectGetMidY (bounds))];
93+
94+ [self .layer insertSublayer: gradLayer atIndex: 0 ];
95+ }
96+
97+ [gradLayer setValuesWithCSSGradient: backgroundImage];
8398 }
8499
85100 NSString * opacity = [cssDeclaration valueForKey: @" opacity" ];
@@ -180,7 +195,7 @@ - (void)applyComputedStyles:(id)cssDeclaration
180195@implementation UITableView (GAViewStyling)
181196
182197- (void )applyComputedStyles : (id )cssDeclaration
183- {
198+ {
184199 [super applyComputedStyles: cssDeclaration];
185200
186201 // Border (Separator) Color. We use "top" because it's the first color in TRBL.
@@ -202,3 +217,14 @@ - (void)applyComputedStyles:(id)cssDeclaration
202217
203218@end
204219
220+ @implementation UITableViewCell (GAViewStyling)
221+
222+ - (void )applyComputedStyles : (id )cssDeclaration
223+ {
224+ if (self.backgroundView ) // Don't apply background styles to this view
225+ return ;
226+
227+ [super applyComputedStyles: cssDeclaration];
228+ }
229+
230+ @end
0 commit comments