<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[165635] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/165635">165635</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2014-03-14 12:31:25 -0700 (Fri, 14 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
https://bugs.webkit.org/show_bug.cgi?id=130226
Reviewed by Andreas Kling.
Extracted HTMLConverterCaches in C++ that directly calls getPropertyCSSValue on computed style
and inline style to avoid creating Objective-C wrappers for CSSComputedStyleDeclaration.
This improves the runtime of PerformanceTests/Interactive/CopyAll.html from 31-32s to 25-26s (20%).
* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(HTMLConverterCaches::computedStylePropertyForElement):
(HTMLConverterCaches::inlineStylePropertyForElement):
(stringFromCSSValue):
(-[WebHTMLConverter _computedStringForNode:property:]):
(floatValueFromPrimitiveValue):
(_getFloat):
(-[WebHTMLConverter _getComputedFloat:forNode:property:]):
(-[WebHTMLConverter _computedColorForNode:property:]):
(-[WebHTMLConverter dealloc]):
(-[WebHTMLConverter init]):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformmacHTMLConverterh">trunk/Source/WebCore/platform/mac/HTMLConverter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacHTMLConvertermm">trunk/Source/WebCore/platform/mac/HTMLConverter.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/ChangeLog        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-03-13 Ryosuke Niwa <rniwa@webkit.org>
+
+ [Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
+ https://bugs.webkit.org/show_bug.cgi?id=130226
+
+ Reviewed by Andreas Kling.
+
+ Extracted HTMLConverterCaches in C++ that directly calls getPropertyCSSValue on computed style
+ and inline style to avoid creating Objective-C wrappers for CSSComputedStyleDeclaration.
+
+ This improves the runtime of PerformanceTests/Interactive/CopyAll.html from 31-32s to 25-26s (20%).
+
+ * platform/mac/HTMLConverter.h:
+ * platform/mac/HTMLConverter.mm:
+ (HTMLConverterCaches::computedStylePropertyForElement):
+ (HTMLConverterCaches::inlineStylePropertyForElement):
+ (stringFromCSSValue):
+ (-[WebHTMLConverter _computedStringForNode:property:]):
+ (floatValueFromPrimitiveValue):
+ (_getFloat):
+ (-[WebHTMLConverter _getComputedFloat:forNode:property:]):
+ (-[WebHTMLConverter _computedColorForNode:property:]):
+ (-[WebHTMLConverter dealloc]):
+ (-[WebHTMLConverter init]):
+
</ins><span class="cx"> 2014-03-14 James Craig <jcraig@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: AXI: Include Role as an extra attribute in the page overlay.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacHTMLConverterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.h (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/HTMLConverter.h        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.h        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -31,6 +31,8 @@
</span><span class="cx"> class Range;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+class HTMLConverterCaches;
+
</ins><span class="cx"> @interface WebHTMLConverter : NSObject {
</span><span class="cx"> NSMutableAttributedString *_attrStr;
</span><span class="cx"> NSMutableDictionary *_documentAttrs;
</span><span class="lines">@@ -54,7 +56,6 @@
</span><span class="cx"> NSMutableArray *_textTableRows;
</span><span class="cx"> NSMutableArray *_textTableRowArrays;
</span><span class="cx"> NSMutableArray *_textTableRowBackgroundColors;
</span><del>- NSMutableDictionary *_computedStylesForElements;
</del><span class="cx"> NSMutableDictionary *_specifiedStylesForElements;
</span><span class="cx"> NSMutableDictionary *_stringsForNodes;
</span><span class="cx"> NSMutableDictionary *_floatsForNodes;
</span><span class="lines">@@ -69,6 +70,8 @@
</span><span class="cx"> NSInteger _errorCode;
</span><span class="cx"> NSInteger _quoteLevel;
</span><span class="cx">
</span><ins>+ std::unique_ptr<HTMLConverterCaches> _caches;
+
</ins><span class="cx"> struct {
</span><span class="cx"> unsigned int isSoft:1;
</span><span class="cx"> unsigned int reachedStart:1;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacHTMLConvertermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.mm (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/HTMLConverter.mm        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.mm        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -29,12 +29,18 @@
</span><span class="cx"> #import "ArchiveResource.h"
</span><span class="cx"> #import "CachedImage.h"
</span><span class="cx"> #import "ColorMac.h"
</span><ins>+#import "CSSComputedStyleDeclaration.h"
+#import "CSSParser.h"
+#import "CSSPrimitiveValue.h"
</ins><span class="cx"> #import "Document.h"
</span><span class="cx"> #import "DocumentLoader.h"
</span><ins>+#import "DOMCSSPrimitiveValueInternal.h"
</ins><span class="cx"> #import "DOMDocumentInternal.h"
</span><span class="cx"> #import "DOMElementInternal.h"
</span><span class="cx"> #import "DOMHTMLTableCellElement.h"
</span><ins>+#import "DOMNodeInternal.h"
</ins><span class="cx"> #import "DOMPrivate.h"
</span><ins>+#import "DOMRGBColorInternal.h"
</ins><span class="cx"> #import "DOMRangeInternal.h"
</span><span class="cx"> #import "Element.h"
</span><span class="cx"> #import "Font.h"
</span><span class="lines">@@ -43,8 +49,11 @@
</span><span class="cx"> #import "HTMLNames.h"
</span><span class="cx"> #import "HTMLParserIdioms.h"
</span><span class="cx"> #import "LoaderNSURLExtras.h"
</span><ins>+#import "RGBColor.h"
</ins><span class="cx"> #import "RenderImage.h"
</span><span class="cx"> #import "SoftLinking.h"
</span><ins>+#import "StyleProperties.h"
+#import "StyledElement.h"
</ins><span class="cx"> #import "TextIterator.h"
</span><span class="cx"> #import <objc/runtime.h>
</span><span class="cx"> #import <wtf/ASCIICType.h>
</span><span class="lines">@@ -389,6 +398,15 @@
</span><span class="cx"> // Additional control Unicode characters
</span><span class="cx"> const unichar WebNextLineCharacter = 0x0085;
</span><span class="cx">
</span><ins>+class HTMLConverterCaches {
+public:
+ PassRefPtr<CSSValue> computedStylePropertyForElement(Element&, String&);
+ PassRefPtr<CSSValue> inlineStylePropertyForElement(Element&, String&);
+
+private:
+ HashMap<Element*, std::unique_ptr<ComputedStyleExtractor>> m_computedStyles;
+};
+
</ins><span class="cx"> @interface NSTextList (WebCoreNSTextListDetails)
</span><span class="cx"> + (NSDictionary *)_standardMarkerAttributesForAttributes:(NSDictionary *)attrs;
</span><span class="cx"> @end
</span><span class="lines">@@ -543,82 +561,76 @@
</span><span class="cx"> return array;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (DOMCSSStyleDeclaration *)_computedStyleForElement:(DOMElement *)element
</del><ins>+PassRefPtr<CSSValue> HTMLConverterCaches::computedStylePropertyForElement(Element& element, String& propertyName)
</ins><span class="cx"> {
</span><del>- DOMDocument *document = [element ownerDocument];
- DOMCSSStyleDeclaration *result = nil;
- result = [_computedStylesForElements objectForKey:element];
- if (result) {
- if ([result isEqual:[NSNull null]])
- result = nil;
- } else {
- result = [document getComputedStyle:element pseudoElement:@""] ;
- [_computedStylesForElements setObject:(result ? (id)result : (id)[NSNull null]) forKey:element];
- }
- return result;
</del><ins>+ CSSPropertyID propetyId = cssPropertyID(propertyName);
+ if (propetyId == CSSPropertyInvalid)
+ return nullptr;
+
+ auto result = m_computedStyles.add(&element, nullptr);
+ if (result.isNewEntry)
+ result.iterator->value = std::make_unique<ComputedStyleExtractor>(&element, true);
+ ComputedStyleExtractor& computedStyle = *result.iterator->value;
+ return computedStyle.propertyValue(propetyId);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-- (DOMCSSStyleDeclaration *)_specifiedStyleForElement:(DOMElement *)element
</del><ins>+PassRefPtr<CSSValue> HTMLConverterCaches::inlineStylePropertyForElement(Element& element, String& propertyName)
</ins><span class="cx"> {
</span><del>- DOMCSSStyleDeclaration *result = [_specifiedStylesForElements objectForKey:element];
- if (result) {
- if ([result isEqual:[NSNull null]])
- result = nil;
- } else {
- result = [element style];
- [_specifiedStylesForElements setObject:(result ? (id)result : (id)[NSNull null]) forKey:element];
</del><ins>+ CSSPropertyID propetyId = cssPropertyID(propertyName);
+ if (propetyId == CSSPropertyInvalid || !element.isStyledElement())
+ return nullptr;
+ const StyleProperties* properties = toStyledElement(element).inlineStyle();
+ if (!properties)
+ return nullptr;
+ return properties->getPropertyCSSValue(propetyId);
+}
+
+static bool stringFromCSSValue(CSSValue& value, String& result)
+{
+ if (value.isPrimitiveValue()) {
+ unsigned short primitiveType = toCSSPrimitiveValue(value).primitiveType();
+ if (primitiveType == CSSPrimitiveValue::CSS_STRING || primitiveType == CSSPrimitiveValue::CSS_URI ||
+ primitiveType == CSSPrimitiveValue::CSS_IDENT || primitiveType == CSSPrimitiveValue::CSS_ATTR) {
+ String stringValue = value.cssText();
+ if (stringValue.length()) {
+ result = stringValue;
+ return true;
+ }
+ }
+ } else if (value.isValueList()) {
+ result = value.cssText();
+ return true;
</ins><span class="cx"> }
</span><del>- return result;
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSString *)_computedStringForNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><del>- NSString *result = nil;
- BOOL inherit = YES;
- DOMElement *element = (DOMElement *)node;
- if (element && [element nodeType] == DOM_ELEMENT_NODE) {
- DOMCSSStyleDeclaration *computedStyle;
- DOMCSSStyleDeclaration *specifiedStyle;
- inherit = NO;
- if (!result && (computedStyle = [self _computedStyleForElement:element])) {
- DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
- if (computedValue) {
- unsigned short valueType = [computedValue cssValueType];
- if (valueType == DOM_CSS_PRIMITIVE_VALUE) {
- unsigned short primitiveType = [computedValue primitiveType];
- if (primitiveType == DOM_CSS_STRING || primitiveType == DOM_CSS_URI || primitiveType == DOM_CSS_IDENT || primitiveType == DOM_CSS_ATTR) {
- result = [computedValue getStringValue];
- if (result && ![result length])
- result = nil;
- }
- } else if (valueType == DOM_CSS_VALUE_LIST)
- result = [computedStyle getPropertyValue:key];
- }
</del><ins>+ bool haveResult = false;
+ String result;
+ bool inherit = true;
+ Node* coreNode = core(node);
+ if (coreNode && coreNode->isElementNode()) {
+ Element& element = toElement(*coreNode);
+ String propertyName = key;
+ inherit = false;
+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->computedStylePropertyForElement(element, propertyName))
+ haveResult = stringFromCSSValue(*value, result);
</ins><span class="cx"> }
</span><del>- if (!result && (specifiedStyle = [self _specifiedStyleForElement:element])) {
- DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
- if (specifiedValue) {
- unsigned short valueType = [specifiedValue cssValueType];
- if (valueType == DOM_CSS_PRIMITIVE_VALUE) {
- unsigned short primitiveType = [specifiedValue primitiveType];
- if (primitiveType == DOM_CSS_STRING || primitiveType == DOM_CSS_URI || primitiveType == DOM_CSS_IDENT || primitiveType == DOM_CSS_ATTR) {
- result = [specifiedValue getStringValue];
- if (result && ![result length])
- result = nil;
- if (!result)
- result = [specifiedStyle getPropertyValue:key];
- }
- } else if (valueType == DOM_CSS_INHERIT)
- inherit = YES;
- else if (valueType == DOM_CSS_VALUE_LIST)
- result = [specifiedStyle getPropertyValue:key];
</del><ins>+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->computedStylePropertyForElement(element, propertyName)) {
+ if (value->isInheritedValue())
+ inherit = true;
+ else
+ haveResult = stringFromCSSValue(*value, result);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (!result) {
- Element* coreElement = core(element);
</del><ins>+ Element* coreElement = &element;
+ if (!haveResult) {
</ins><span class="cx"> if ([@"display" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(headTag) || coreElement->hasTagName(scriptTag) || coreElement->hasTagName(appletTag) || coreElement->hasTagName(noframesTag))
</span><del>- result = @"none";
</del><ins>+ result = "none";
</ins><span class="cx"> else if (coreElement->hasTagName(addressTag) || coreElement->hasTagName(blockquoteTag) || coreElement->hasTagName(bodyTag) || coreElement->hasTagName(centerTag)
</span><span class="cx"> || coreElement->hasTagName(ddTag) || coreElement->hasTagName(dirTag) || coreElement->hasTagName(divTag) || coreElement->hasTagName(dlTag)
</span><span class="cx"> || coreElement->hasTagName(dtTag) || coreElement->hasTagName(fieldsetTag) || coreElement->hasTagName(formTag) || coreElement->hasTagName(frameTag)
</span><span class="lines">@@ -626,61 +638,61 @@
</span><span class="cx"> || coreElement->hasTagName(h2Tag) || coreElement->hasTagName(h3Tag) || coreElement->hasTagName(h4Tag) || coreElement->hasTagName(h5Tag)
</span><span class="cx"> || coreElement->hasTagName(h6Tag) || coreElement->hasTagName(iframeTag) || coreElement->hasTagName(menuTag) || coreElement->hasTagName(noscriptTag)
</span><span class="cx"> || coreElement->hasTagName(olTag) || coreElement->hasTagName(pTag) || coreElement->hasTagName(preTag) || coreElement->hasTagName(ulTag))
</span><del>- result = @"block";
</del><ins>+ result = "block";
</ins><span class="cx"> else if (coreElement->hasTagName(liTag))
</span><del>- result = @"list-item";
</del><ins>+ result = "list-item";
</ins><span class="cx"> else if (coreElement->hasTagName(tableTag))
</span><del>- result = @"table";
</del><ins>+ result = "table";
</ins><span class="cx"> else if (coreElement->hasTagName(trTag))
</span><del>- result = @"table-row";
</del><ins>+ result = "table-row";
</ins><span class="cx"> else if (coreElement->hasTagName(thTag) || coreElement->hasTagName(tdTag))
</span><del>- result = @"table-cell";
</del><ins>+ result = "table-cell";
</ins><span class="cx"> else if (coreElement->hasTagName(theadTag))
</span><del>- result = @"table-header-group";
</del><ins>+ result = "table-header-group";
</ins><span class="cx"> else if (coreElement->hasTagName(tbodyTag))
</span><del>- result = @"table-row-group";
</del><ins>+ result = "table-row-group";
</ins><span class="cx"> else if (coreElement->hasTagName(tfootTag))
</span><del>- result = @"table-footer-group";
</del><ins>+ result = "table-footer-group";
</ins><span class="cx"> else if (coreElement->hasTagName(colTag))
</span><del>- result = @"table-column";
</del><ins>+ result = "table-column";
</ins><span class="cx"> else if (coreElement->hasTagName(colgroupTag))
</span><del>- result = @"table-column-group";
</del><ins>+ result = "table-column-group";
</ins><span class="cx"> else if (coreElement->hasTagName(captionTag))
</span><del>- result = @"table-caption";
</del><ins>+ result = "table-caption";
</ins><span class="cx"> } else if ([@"white-space" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(preTag))
</span><del>- result = @"pre";
</del><ins>+ result = "pre";
</ins><span class="cx"> else
</span><span class="cx"> inherit = YES;
</span><span class="cx"> } else if ([@"font-style" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(iTag) || coreElement->hasTagName(citeTag) || coreElement->hasTagName(emTag) || coreElement->hasTagName(varTag) || coreElement->hasTagName(addressTag))
</span><del>- result = @"italic";
</del><ins>+ result = "italic";
</ins><span class="cx"> else
</span><span class="cx"> inherit = YES;
</span><span class="cx"> } else if ([@"font-weight" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(bTag) || coreElement->hasTagName(strongTag) || coreElement->hasTagName(thTag))
</span><del>- result = @"bolder";
</del><ins>+ result = "bolder";
</ins><span class="cx"> else
</span><span class="cx"> inherit = YES;
</span><span class="cx"> } else if ([@"text-decoration" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(uTag) || coreElement->hasTagName(insTag))
</span><del>- result = @"underline";
</del><ins>+ result = "underline";
</ins><span class="cx"> else if (coreElement->hasTagName(sTag) || coreElement->hasTagName(strikeTag) || coreElement->hasTagName(delTag))
</span><del>- result = @"line-through";
</del><ins>+ result = "line-through";
</ins><span class="cx"> else
</span><span class="cx"> inherit = YES; // ??? this is not strictly correct
</span><span class="cx"> } else if ([@"text-align" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(centerTag) || coreElement->hasTagName(captionTag) || coreElement->hasTagName(thTag))
</span><del>- result = @"center";
</del><ins>+ result = "center";
</ins><span class="cx"> else
</span><span class="cx"> inherit = YES;
</span><span class="cx"> } else if ([@"vertical-align" isEqualToString:key]) {
</span><span class="cx"> if (coreElement->hasTagName(supTag))
</span><del>- result = @"super";
</del><ins>+ result = "super";
</ins><span class="cx"> else if (coreElement->hasTagName(subTag))
</span><del>- result = @"sub";
</del><ins>+ result = "sub";
</ins><span class="cx"> else if (coreElement->hasTagName(theadTag) || coreElement->hasTagName(tbodyTag) || coreElement->hasTagName(tfootTag))
</span><del>- result = @"middle";
</del><ins>+ result = "middle";
</ins><span class="cx"> else if (coreElement->hasTagName(trTag) || coreElement->hasTagName(thTag) || coreElement->hasTagName(tdTag))
</span><span class="cx"> inherit = YES;
</span><span class="cx"> } else if ([@"font-family" isEqualToString:key] || [@"font-variant" isEqualToString:key] || [@"font-effect" isEqualToString:key]
</span><span class="lines">@@ -691,12 +703,14 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (!result && inherit) {
</del><ins>+ if (!haveResult && inherit) {
</ins><span class="cx"> DOMNode *parentNode = [node parentNode];
</span><span class="cx"> if (parentNode)
</span><del>- result = [self _stringForNode:parentNode property:key];
</del><ins>+ return [self _stringForNode:parentNode property:key];
</ins><span class="cx"> }
</span><del>- return result ? [result lowercaseString] : nil;
</del><ins>+ if (haveResult)
+ return result.lower();
+ return nil;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (NSString *)_stringForNode:(DOMNode *)node property:(NSString *)key
</span><span class="lines">@@ -718,72 +732,82 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static inline bool floatValueFromPrimitiveValue(CSSPrimitiveValue& primitiveValue, float& result)
+{
+ // FIXME: Use CSSPrimitiveValue::computeValue.
+ switch (primitiveValue.primitiveType()) {
+ case CSSPrimitiveValue::CSS_PX:
+ result = primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PX);
+ return true;
+ case CSSPrimitiveValue::CSS_PT:
+ result = 4 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PT) / 3;
+ return true;
+ case CSSPrimitiveValue::CSS_PC:
+ result = 16 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC);
+ return true;
+ case CSSPrimitiveValue::CSS_CM:
+ result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC) / 2.54;
+ return true;
+ case CSSPrimitiveValue::CSS_MM:
+ result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC) / 25.4;
+ return true;
+ case CSSPrimitiveValue::CSS_IN:
+ result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_IN);
+ return true;
+ default:
+ return false;
+ }
+}
+
</ins><span class="cx"> static inline BOOL _getFloat(DOMCSSPrimitiveValue *primitiveValue, CGFloat *val)
</span><span class="cx"> {
</span><span class="cx"> if (!val)
</span><span class="cx"> return NO;
</span><del>- switch ([primitiveValue primitiveType]) {
- case DOM_CSS_PX:
- *val = [primitiveValue getFloatValue:DOM_CSS_PX];
- return YES;
- case DOM_CSS_PT:
- *val = 4 * [primitiveValue getFloatValue:DOM_CSS_PT] / 3;
- return YES;
- case DOM_CSS_PC:
- *val = 16 * [primitiveValue getFloatValue:DOM_CSS_PC];
- return YES;
- case DOM_CSS_CM:
- *val = 96 * [primitiveValue getFloatValue:DOM_CSS_CM] / (CGFloat)2.54;
- return YES;
- case DOM_CSS_MM:
- *val = 96 * [primitiveValue getFloatValue:DOM_CSS_MM] / (CGFloat)25.4;
- return YES;
- case DOM_CSS_IN:
- *val = 96 * [primitiveValue getFloatValue:DOM_CSS_IN];
- return YES;
- default:
- return NO;
- }
</del><ins>+ float result;
+ bool haveResult = floatValueFromPrimitiveValue(*core(primitiveValue), result);
+ if (haveResult && val)
+ *val = result;
+ return haveResult;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (BOOL)_getComputedFloat:(CGFloat *)val forNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><del>- BOOL result = NO;
- BOOL inherit = YES;
- CGFloat floatVal = 0;
- DOMElement *element = (DOMElement *)node;
- if (element && [element nodeType] == DOM_ELEMENT_NODE) {
- DOMCSSStyleDeclaration *computedStyle, *specifiedStyle;
- inherit = NO;
- if (!result && (computedStyle = [self _computedStyleForElement:element])) {
- DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
- if (computedValue && [computedValue cssValueType] == DOM_CSS_PRIMITIVE_VALUE)
- result = _getFloat(computedValue, &floatVal);
</del><ins>+ bool haveResult = false;
+ bool inherit = true;
+ float floatVal = 0;
+ Node* coreNode = core(node);
+ if (coreNode && coreNode->isElementNode()) {
+ Element& element = toElement(*coreNode);
+ String propertyName = key;
+ inherit = false;
+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->computedStylePropertyForElement(element, propertyName)) {
+ if (value->isPrimitiveValue())
+ haveResult = floatValueFromPrimitiveValue(toCSSPrimitiveValue(*value), floatVal);
+ }
</ins><span class="cx"> }
</span><del>- if (!result && (specifiedStyle = [self _specifiedStyleForElement:element])) {
- DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
- if (specifiedValue) {
- unsigned short valueType = [specifiedValue cssValueType];
- if (valueType == DOM_CSS_PRIMITIVE_VALUE)
- result = _getFloat(specifiedValue, &floatVal);
- else if (valueType == DOM_CSS_INHERIT)
- inherit = YES;
</del><ins>+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->inlineStylePropertyForElement(element, propertyName)) {
+ if (value->isInheritedValue())
+ inherit = true;
+ else if (value->isPrimitiveValue())
+ haveResult = floatValueFromPrimitiveValue(toCSSPrimitiveValue(*value), floatVal);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (!result) {
</del><ins>+ if (!haveResult) {
</ins><span class="cx"> if ([@"text-indent" isEqualToString:key] || [@"letter-spacing" isEqualToString:key] || [@"word-spacing" isEqualToString:key]
</span><span class="cx"> || [@"line-height" isEqualToString:key] || [@"widows" isEqualToString:key] || [@"orphans" isEqualToString:key])
</span><del>- inherit = YES;
</del><ins>+ inherit = true;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (!result && inherit) {
</del><ins>+ if (!haveResult && inherit) {
</ins><span class="cx"> DOMNode *parentNode = [node parentNode];
</span><span class="cx"> if (parentNode)
</span><del>- result = [self _getFloat:&floatVal forNode:parentNode property:key];
</del><ins>+ return [self _getFloat:val forNode:parentNode property:key];
</ins><span class="cx"> }
</span><del>- if (result && val)
</del><ins>+ if (haveResult && val)
</ins><span class="cx"> *val = floatVal;
</span><del>- return result;
</del><ins>+ return haveResult;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (BOOL)_getFloat:(CGFloat *)val forNode:(DOMNode *)node property:(NSString *)key
</span><span class="lines">@@ -967,41 +991,43 @@
</span><span class="cx"> - (PlatformColor *)_computedColorForNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><span class="cx"> PlatformColor *result = nil;
</span><del>- BOOL inherit = YES;
- BOOL haveResult = NO;
</del><ins>+ bool inherit = true;
+ bool haveResult = false;
</ins><span class="cx"> BOOL isColor = [@"color" isEqualToString:key];
</span><span class="cx"> BOOL isBackgroundColor = [@"background-color" isEqualToString:key];
</span><del>- DOMElement *element = (DOMElement *)node;
- if (element && [element nodeType] == DOM_ELEMENT_NODE) {
- DOMCSSStyleDeclaration *computedStyle, *specifiedStyle;
- inherit = NO;
- if (!haveResult && (computedStyle = [self _computedStyleForElement:element])) {
- DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
- if (computedValue && [computedValue cssValueType] == DOM_CSS_PRIMITIVE_VALUE && [computedValue primitiveType] == DOM_CSS_RGBCOLOR) {
- result = _colorForRGBColor([computedValue getRGBColorValue], isColor);
- haveResult = YES;
</del><ins>+ Node* coreNode = core(node);
+ if (coreNode && coreNode->isElementNode()) {
+ Element& element = toElement(*coreNode);
+ String propertyName = key;
+ inherit = false;
+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->computedStylePropertyForElement(element, propertyName)) {
+ if (value->isPrimitiveValue() && toCSSPrimitiveValue(*value).isRGBColor()) {
+ RefPtr<WebCore::RGBColor> color = toCSSPrimitiveValue(*value).getRGBColorValue(ASSERT_NO_EXCEPTION);
+ result = _colorForRGBColor(kit(color.get()), isColor);
+ haveResult = true;
+ }
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (!haveResult && (specifiedStyle = [self _specifiedStyleForElement:element])) {
- DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
- if (specifiedValue) {
- unsigned short valueType = [specifiedValue cssValueType];
- if (valueType == DOM_CSS_PRIMITIVE_VALUE && [specifiedValue primitiveType] == DOM_CSS_RGBCOLOR) {
- result = _colorForRGBColor([specifiedValue getRGBColorValue], isColor);
- haveResult = YES;
- } else if (valueType == DOM_CSS_INHERIT)
- inherit = YES;
</del><ins>+ if (!haveResult) {
+ if (RefPtr<CSSValue> value = _caches->inlineStylePropertyForElement(element, propertyName)) {
+ if (value->isPrimitiveValue() && toCSSPrimitiveValue(*value).isRGBColor()) {
+ RefPtr<WebCore::RGBColor> color = toCSSPrimitiveValue(*value).getRGBColorValue(ASSERT_NO_EXCEPTION);
+ result = _colorForRGBColor(kit(color.get()), isColor);
+ haveResult = true;
+ } else if (value->isInheritedValue())
+ inherit = true;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> if (!result) {
</span><del>- if ((isColor && !haveResult) || (isBackgroundColor && ![self _elementHasOwnBackgroundColor:element]))
- inherit = YES;
</del><ins>+ if ((isColor && !haveResult) || (isBackgroundColor && ![self _elementHasOwnBackgroundColor:static_cast<DOMElement*>(node)]))
+ inherit = true;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> if (!result && inherit) {
</span><span class="cx"> DOMNode *parentNode = [node parentNode];
</span><span class="cx"> if (parentNode && !(isBackgroundColor && [parentNode nodeType] == DOM_ELEMENT_NODE && [self _elementHasOwnBackgroundColor:(DOMElement *)parentNode]))
</span><del>- result = [self _colorForNode:parentNode property:key];
</del><ins>+ return [self _colorForNode:parentNode property:key];
</ins><span class="cx"> }
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="lines">@@ -2404,7 +2430,6 @@
</span><span class="cx"> [_textTableRows release];
</span><span class="cx"> [_textTableRowArrays release];
</span><span class="cx"> [_textTableRowBackgroundColors release];
</span><del>- [_computedStylesForElements release];
</del><span class="cx"> [_specifiedStylesForElements release];
</span><span class="cx"> [_stringsForNodes release];
</span><span class="cx"> [_floatsForNodes release];
</span><span class="lines">@@ -2434,7 +2459,6 @@
</span><span class="cx"> _textTableRows = [[NSMutableArray alloc] init];
</span><span class="cx"> _textTableRowArrays = [[NSMutableArray alloc] init];
</span><span class="cx"> _textTableRowBackgroundColors = [[NSMutableArray alloc] init];
</span><del>- _computedStylesForElements = [[NSMutableDictionary alloc] init];
</del><span class="cx"> _specifiedStylesForElements = [[NSMutableDictionary alloc] init];
</span><span class="cx"> _stringsForNodes = [[NSMutableDictionary alloc] init];
</span><span class="cx"> _floatsForNodes = [[NSMutableDictionary alloc] init];
</span><span class="lines">@@ -2452,6 +2476,8 @@
</span><span class="cx"> _errorCode = -1;
</span><span class="cx"> _indexingLimit = 0;
</span><span class="cx"> _thumbnailLimit = 0;
</span><ins>+
+ _caches = std::make_unique<HTMLConverterCaches>();
</ins><span class="cx">
</span><span class="cx"> _flags.isIndexing = (_indexingLimit > 0);
</span><span class="cx"> _flags.isTesting = 0;
</span></span></pre>
</div>
</div>
</body>
</html>