Rewrite WebHTMLConverter::_elementIsBlockLevel in C++
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Mar 2014 01:38:01 +0000 (01:38 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Mar 2014 01:38:01 +0000 (01:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130287

Reviewed by Andreas Kling.

Rewrote _elementIsBlockLevel as HTMLConverterCaches::isBlockElement. Also removed the code to update
_elementIsBlockLevel in _traverseNode as computing the value of _elementIsBlockLevel is now fast.

* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(HTMLConverterCaches::isBlockElement):
(-[WebHTMLConverter _elementIsBlockLevel:]):
(-[WebHTMLConverter _traverseNode:depth:embedded:]):
(-[WebHTMLConverter dealloc]):
(-[WebHTMLConverter init]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165787 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/HTMLConverter.h
Source/WebCore/platform/mac/HTMLConverter.mm

index e69ccd5c090e411df681bbcadb671d8fcf4fc35b..314996b7a079e8035cfd163e68f152d351583c50 100644 (file)
@@ -1,3 +1,21 @@
+2014-03-17  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Rewrite WebHTMLConverter::_elementIsBlockLevel in C++
+        https://bugs.webkit.org/show_bug.cgi?id=130287
+
+        Reviewed by Andreas Kling.
+
+        Rewrote _elementIsBlockLevel as HTMLConverterCaches::isBlockElement. Also removed the code to update
+        _elementIsBlockLevel in _traverseNode as computing the value of _elementIsBlockLevel is now fast.
+
+        * platform/mac/HTMLConverter.h:
+        * platform/mac/HTMLConverter.mm:
+        (HTMLConverterCaches::isBlockElement):
+        (-[WebHTMLConverter _elementIsBlockLevel:]):
+        (-[WebHTMLConverter _traverseNode:depth:embedded:]):
+        (-[WebHTMLConverter dealloc]):
+        (-[WebHTMLConverter init]):
+
 2014-03-17  Ryosuke Niwa  <rniwa@webkit.org>
 
         Rewrite WebHTMLConverter::_getComputedFloat in C++
index c2f606873a06eef5a014932b42aaaaec5262794a..52913e3cd411c999de35fb37942c99d173be8d4a 100644 (file)
@@ -58,7 +58,6 @@ class HTMLConverterCaches;
     NSMutableArray *_textTableRowBackgroundColors;
     NSMutableDictionary *_colorsForNodes;
     NSMutableDictionary *_attributesForElements;
-    NSMutableDictionary *_elementIsBlockLevel;
     NSMutableDictionary *_fontCache;
     NSMutableArray *_writingDirectionArray;
     NSUInteger _domRangeStartIndex;
index 05d95a509ad9615847fecbc1ffff7c27447edadd..545a1604f5030f23e434b2e62ee53fff992f88da 100644 (file)
@@ -403,6 +403,7 @@ class HTMLConverterCaches {
 public:
     String propertyValueForNode(Node&, const String& propertyName);
     bool floatPropertyValueForNode(Node&, const String& propertyName, float&);
+    bool isBlockElement(Element&);
 
     PassRefPtr<CSSValue> computedStylePropertyForElement(Element&, const String&);
     PassRefPtr<CSSValue> inlineStylePropertyForElement(Element&, const String&);
@@ -930,24 +931,20 @@ static inline NSShadow *_shadowForShadowStyle(NSString *shadowStyle)
     return shadow;
 }
 
-- (BOOL)_elementIsBlockLevel:(DOMElement *)element
+bool HTMLConverterCaches::isBlockElement(Element& element)
 {
-    BOOL isBlockLevel = NO;
-    NSNumber *val = nil;
-    val = [_elementIsBlockLevel objectForKey:element];
-    if (val)
-        isBlockLevel = [val boolValue];
-    else {
-        NSString *displayVal = [self _stringForNode:element property:@"display"];
-        NSString *floatVal = [self _stringForNode:element property:@"float"];
-        if (floatVal && ([@"left" isEqualToString:floatVal] || [@"right" isEqualToString:floatVal]))
-            isBlockLevel = YES;
-        else if (displayVal)
-            isBlockLevel = ([@"block" isEqualToString:displayVal] || [@"list-item" isEqualToString:displayVal] || [displayVal hasPrefix:@"table"]);
+    String displayValue = propertyValueForNode(element, "display");
+    if (displayValue == "block" || displayValue == "list-item" || displayValue.startsWith("table"))
+        return true;
+    String floatValue = propertyValueForNode(element, "float");
+    if (floatValue == "left" || floatValue == "right")
+        return true;
+    return false;
+}
 
-        [_elementIsBlockLevel setObject:[NSNumber numberWithBool:isBlockLevel] forKey:element];
-    }
-    return isBlockLevel;
+- (BOOL)_elementIsBlockLevel:(DOMElement *)element
+{
+    return element && _caches->isBlockElement(*core(element));
 }
 
 - (BOOL)_elementHasOwnBackgroundColor:(DOMElement *)element
@@ -2282,14 +2279,7 @@ static NSInteger _colCompare(id block1, id block2, void *)
         }
     } else if (nodeType == DOM_ELEMENT_NODE) {
         DOMElement *element = (DOMElement *)node;
-        NSString *tag = [element tagName], *displayVal = [self _stringForNode:element property:@"display"], *floatVal = [self _stringForNode:element property:@"float"];
-        BOOL isBlockLevel = NO;
-        if (floatVal && ([@"left" isEqualToString:floatVal] || [@"right" isEqualToString:floatVal])) {
-            isBlockLevel = YES;
-        } else if (displayVal) {
-            isBlockLevel = ([@"block" isEqualToString:displayVal] || [@"list-item" isEqualToString:displayVal] || [displayVal hasPrefix:@"table"]);
-        }
-        [_elementIsBlockLevel setObject:[NSNumber numberWithBool:isBlockLevel] forKey:element];
+        NSString *tag = [element tagName], *displayVal = [self _stringForNode:element property:@"display"];
         if ([self _enterElement:element tag:tag display:displayVal embedded:embedded]) {
             NSUInteger startIndex = [_attrStr length];
             if ([self _processElement:element tag:tag display:displayVal depth:depth]) {
@@ -2417,7 +2407,6 @@ static NSInteger _colCompare(id block1, id block2, void *)
     [_textTableRowBackgroundColors release];
     [_colorsForNodes release];
     [_attributesForElements release];
-    [_elementIsBlockLevel release];
     [_fontCache release];
     [_writingDirectionArray release];
     [super dealloc];
@@ -2443,7 +2432,6 @@ static NSInteger _colCompare(id block1, id block2, void *)
     _textTableRowBackgroundColors = [[NSMutableArray alloc] init];
     _colorsForNodes = [[NSMutableDictionary alloc] init];
     _attributesForElements = [[NSMutableDictionary alloc] init];
-    _elementIsBlockLevel = [[NSMutableDictionary alloc] init];
     _fontCache = [[NSMutableDictionary alloc] init];
     _writingDirectionArray = [[NSMutableArray alloc] init];