Skip to content

Commit

Permalink
Merge 1b043de into e779026
Browse files Browse the repository at this point in the history
  • Loading branch information
amro committed Oct 1, 2013
2 parents e779026 + 1b043de commit 8d0094b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
32 changes: 2 additions & 30 deletions Core/Source/DTCSSStylesheet.m
Expand Up @@ -661,6 +661,8 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element match
// (Note that when styles are applied, the later styles take precedence,
// so the order in which we grab them matters!)

NSLog(@"%@", element);

NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary];

// Get based on element
Expand Down Expand Up @@ -701,10 +703,6 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element match
return (NSComparisonResult)NSOrderedSame;
}];

// Single part selectors are also weighted by specificity, but since they all have the same weight,
//we apply them in order of least specific to most specific.
[matchingCascadingSelectors addObjectsFromArray:[self matchingSimpleCascadedSelectors:element]];

NSMutableSet *tmpMatchedSelectors;

if (matchedSelectors)
Expand Down Expand Up @@ -883,32 +881,6 @@ - (NSMutableArray *)matchingComplexCascadingSelectorsForElement:(DTHTMLElement *
return matchedSelectors;
}

// This looks for cascaded single classes
- (NSArray *)matchingSimpleCascadedSelectors:(DTHTMLElement *)element
{
NSMutableArray *simpleSelectors = [NSMutableArray array];

DTHTMLElement *currentElement = element.parentElement;
while (currentElement != nil)
{
NSString *currentElementClassString = [currentElement.attributes objectForKey:@"class"];
NSArray *selectorParts = [currentElementClassString componentsSeparatedByString:@" "];
if (selectorParts.count == 1 && ([selectorParts[0] length] > 0))
{
NSString *ancessorClassRule = [NSString stringWithFormat:@".%@", selectorParts[0]];

if (_styles[ancessorClassRule])
{
[simpleSelectors insertObject:ancessorClassRule atIndex:0];
}
}

currentElement = currentElement.parentElement;
}

return simpleSelectors;
}

// This computes the specificity for a given selector
- (NSUInteger)weightForSelector:(NSString *)selector {
if ((selector == nil) || (selector.length == 0))
Expand Down
3 changes: 1 addition & 2 deletions Demo/Resources/CurrentTest.html
@@ -1,2 +1 @@
<h1 style="font-variant: small-caps;">one<br>
two</h1>
<html><head><style> .container { display: block; } span.test { font-style:italic; }</style></head><body><div class='container'>before<span class='test'>test</span>after</div></body></html>
2 changes: 1 addition & 1 deletion Test/MacUnitTest-Prefix.pch
Expand Up @@ -6,7 +6,7 @@
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "DTCoreText.h"
#import "DTCoreText.h"
#endif

#define CGSizeValue sizeValue
Expand Down
9 changes: 9 additions & 0 deletions Test/Source/DTHTMLAttributedStringBuilderTest.m
Expand Up @@ -1022,4 +1022,13 @@ - (void)testLetterSpacing
STAssertTrue(kerning == 10, @"Kerning should be 10px");
}

// issue 636
- (void)testDisplayStyleInheritance
{
NSAttributedString *attributedString = [self attributedStringFromHTMLString:@"<html><head><style> .container { display: block; } span.test { font-style:italic; }</style></head><body><div class='container'>\n before <span class='test'>test</span> after\n</div></body></html>" options:NULL];


NSArray *lines = [[[attributedString string] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsSeparatedByString:@"\n"];
STAssertTrue([lines count]==1, @"There should only be one line, display style block should not be inherited");
}
@end

0 comments on commit 8d0094b

Please sign in to comment.