Title: [165787] trunk/Source/WebCore
Revision
165787
Author
[email protected]
Date
2014-03-17 18:38:01 -0700 (Mon, 17 Mar 2014)

Log Message

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]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (165786 => 165787)


--- trunk/Source/WebCore/ChangeLog	2014-03-18 01:35:46 UTC (rev 165786)
+++ trunk/Source/WebCore/ChangeLog	2014-03-18 01:38:01 UTC (rev 165787)
@@ -1,5 +1,23 @@
 2014-03-17  Ryosuke Niwa  <[email protected]>
 
+        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  <[email protected]>
+
         Rewrite WebHTMLConverter::_getComputedFloat in C++
         https://bugs.webkit.org/show_bug.cgi?id=130284
 

Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.h (165786 => 165787)


--- trunk/Source/WebCore/platform/mac/HTMLConverter.h	2014-03-18 01:35:46 UTC (rev 165786)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.h	2014-03-18 01:38:01 UTC (rev 165787)
@@ -58,7 +58,6 @@
     NSMutableArray *_textTableRowBackgroundColors;
     NSMutableDictionary *_colorsForNodes;
     NSMutableDictionary *_attributesForElements;
-    NSMutableDictionary *_elementIsBlockLevel;
     NSMutableDictionary *_fontCache;
     NSMutableArray *_writingDirectionArray;
     NSUInteger _domRangeStartIndex;

Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.mm (165786 => 165787)


--- trunk/Source/WebCore/platform/mac/HTMLConverter.mm	2014-03-18 01:35:46 UTC (rev 165786)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.mm	2014-03-18 01:38:01 UTC (rev 165787)
@@ -403,6 +403,7 @@
 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 @@
     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 @@
         }
     } 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 @@
     [_textTableRowBackgroundColors release];
     [_colorsForNodes release];
     [_attributesForElements release];
-    [_elementIsBlockLevel release];
     [_fontCache release];
     [_writingDirectionArray release];
     [super dealloc];
@@ -2443,7 +2432,6 @@
     _textTableRowBackgroundColors = [[NSMutableArray alloc] init];
     _colorsForNodes = [[NSMutableDictionary alloc] init];
     _attributesForElements = [[NSMutableDictionary alloc] init];
-    _elementIsBlockLevel = [[NSMutableDictionary alloc] init];
     _fontCache = [[NSMutableDictionary alloc] init];
     _writingDirectionArray = [[NSMutableArray alloc] init];
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to