RESOLVED FIXED 68473
Parse '-webkit-filter' property syntax
https://bugs.webkit.org/show_bug.cgi?id=68473
Summary Parse '-webkit-filter' property syntax
Dean Jackson
Reported 2011-09-20 14:14:52 PDT
https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/publish/Filters.html has a new filter property syntax. We need to support an arbitrary list of filters.
Attachments
Patch (315.21 KB, patch)
2011-09-30 19:18 PDT, Dean Jackson
no flags
Patch (315.21 KB, patch)
2011-09-30 19:40 PDT, Dean Jackson
no flags
Patch (315.62 KB, patch)
2011-10-04 14:22 PDT, Dean Jackson
no flags
Patch (315.80 KB, patch)
2011-10-04 21:08 PDT, Dean Jackson
zimmermann: review+
Radar WebKit Bug Importer
Comment 1 2011-09-20 14:15:10 PDT
Dean Jackson
Comment 2 2011-09-30 19:18:59 PDT
Dean Jackson
Comment 3 2011-09-30 19:21:04 PDT
Patch uploaded. This intentionally leaves drop-shadow to a followup. Unfortunately adding the new type for WebKitCSSFilterValue meant I had to copy some test results into the platform-specific area, while ENABLE(CSS_FILTERS) is only turned on for those ports.
Early Warning System Bot
Comment 4 2011-09-30 19:31:43 PDT
Gyuyoung Kim
Comment 5 2011-09-30 19:34:09 PDT
Dean Jackson
Comment 6 2011-09-30 19:40:10 PDT
Nikolas Zimmermann
Comment 7 2011-10-02 03:43:49 PDT
Comment on attachment 109393 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=109393&action=review First round of review, nice patch Dean! I didn't check the tests extenisvely, though they all look thoughtful and sane > Source/WebCore/css/CSSParser.cpp:6383 > + You can omit this newline. > Source/WebCore/css/CSSParser.cpp:6387 > + Ditto. > Source/WebCore/css/CSSParser.cpp:6396 > + if (equalIgnoringCase(name, "grayscale(")) { > + filterType = WebKitCSSFilterValue::GrayscaleFilterOperation; > + } else if (equalIgnoringCase(name, "sepia(")) { > + filterType = WebKitCSSFilterValue::SepiaFilterOperation; This should go into a static inline helper function, to make the code more readable! Also the { .. } braces can be omitted everywhere. > Source/WebCore/css/CSSParser.cpp:6421 > + // Create the new WebKitCSSFilterValue for this operation and add it to our list. > + RefPtr<WebKitCSSFilterValue> filterValue = WebKitCSSFilterValue::create(filterType); > + list->append(filterValue); This should be moved below the next return 0 early return, to avoid creating and destructing this immediately again. > Source/WebCore/css/CSSParser.cpp:6431 > + Unneeded newline. > Source/WebCore/css/CSSParser.cpp:6432 > + // Check parameter types. I think this whole method should be moved into a helper function. The current parseFilter() method is not really readable. > Source/WebCore/css/CSSParser.cpp:6448 > + } else { > + if (!validUnit(argument, FNumber, true)) > + return 0; > + } Can be a joined into else if (!validUnit). > Source/WebCore/css/CSSParser.cpp:6451 > + > + // Check parameter values. > + if (filterType == WebKitCSSFilterValue::GrayscaleFilterOperation Same here, that cries for another helper function :-) > Source/WebCore/css/CSSParser.cpp:6484 > + argumentCount++; I'd prefer pre-increment, but it's taste. > Source/WebCore/css/CSSStyleSelector.cpp:5297 > + case WebKitCSSFilterValue::ReferenceFilterOperation: return FilterOperation::REFERENCE; That's not our preferred style, each statement should go into a new line. > Source/WebCore/css/CSSStyleSelector.cpp:5353 > + double amount = 1.0; You should omit the .0 per our style guide, constants like 1 should be 1 not 1.0. > Source/WebCore/css/CSSStyleSelector.cpp:5372 > + double amount = 1.0; Ditto. > Source/WebCore/css/CSSStyleSelector.cpp:5382 > + double amplitude = 1.0; > + double exponent = 1.0; > + double offset = 0.0; Ditto. > Source/WebCore/css/CSSStyleSelector.cpp:5413 > + double amount = 0.0; Ditto. > Source/WebCore/css/WebKitCSSFilterValue.cpp:32 > +#include "PlatformString.h" This is deprecated, please use <wtf/text/WTFString.h> > Source/WebCore/css/WebKitCSSFilterValue.cpp:37 > +WebKitCSSFilterValue::WebKitCSSFilterValue(FilterOperationType op) s/op/type/ to avoid abbrevations. > Source/WebCore/css/WebKitCSSFilterValue.cpp:52 > + result += "url("; The usage of += here is inefficient, just use assignment, as the String is empty initially. > Source/WebCore/css/WebKitCSSFilterValue.cpp:90 > + result += CSSValueList::cssText(); > + > + result += ")"; result += CSSValueList::cssText() + ")" is potentially faster, as += always reallocs, and our string concat operator + is optimized.
Dean Jackson
Comment 8 2011-10-04 14:22:59 PDT
Dean Jackson
Comment 9 2011-10-04 14:25:33 PDT
(In reply to comment #7) > (From update of attachment 109393 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=109393&action=review > > First round of review, nice patch Dean! I didn't check the tests extenisvely, though they all look thoughtful and sane > Thanks Nikolas. I fixed everything you mentioned. The biggest changes are the two helper functions (one static, one unfortunately on CSSParser in order to access validUnit) in the parseFilter.
Dean Jackson
Comment 10 2011-10-04 21:08:06 PDT
Nikolas Zimmermann
Comment 11 2011-10-05 02:14:08 PDT
Comment on attachment 109741 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=109741&action=review Looks great, r=me with some minor comments. Unfortunately the patch doesn't apply at the moment, so we have no EWS results. If you think it's safe and if you want to watch the bots to fixup any breakage, feel free to land as-is - if you're not upload a new updated patch, and I'll r+ that as well once we got positive EWS results. > Source/WebCore/css/CSSParser.cpp:6371 > + if (equalIgnoringCase(name, "grayscale(")) If this ever shows up hot in a profile, we could check char by char here, but for now it's fine as-is. > Source/WebCore/css/CSSParser.cpp:6395 > +bool CSSParser::validFilterArgument(CSSParserValue* argument, WebKitCSSFilterValue::FilterOperationType& filterType, unsigned argumentCount) isValidFilterArgument? Seems to be preferred here. > Source/WebCore/css/CSSStyleSelector.cpp:5294 > +static FilterOperation::OperationType getFilterOperationType(WebKitCSSFilterValue::FilterOperationType type) The prefix get here violates the style guide - you should sth. like "filterOperationForType" > Source/WebCore/css/CSSStyleSelector.cpp:5359 > + AtomicString url = firstValue->getStringValue(); > + operations.operations().append(ReferenceFilterOperation::create(url, operationType)); I'd avoid the local here, seems there's no gain. > Source/WebCore/css/WebKitCSSFilterValue.cpp:89 > + result += CSSValueList::cssText() + ")"; > + return result; Thinking about this again, I should have suggested to use "return result + CSSValueList::cssText() + ")";" directly, it's even more efficient.
Dean Jackson
Comment 12 2011-10-05 16:28:37 PDT
Thanks Nikolas. I'm watching the bots. http://trac.webkit.org/changeset/96764
Dirk Schulze
Comment 13 2011-11-16 23:09:55 PST
Will '-webkit-filter' replace the 'filter' property that we already have?
Dean Jackson
Comment 14 2011-11-16 23:36:09 PST
(In reply to comment #13) > Will '-webkit-filter' replace the 'filter' property that we already have? Eventually. That's what the spec says. We'll wait until CR I guess. (Not sure what to do when we want -webkit-filter to apply to SVG)
Dirk Schulze
Comment 15 2011-11-17 03:10:41 PST
(In reply to comment #14) > (In reply to comment #13) > > Will '-webkit-filter' replace the 'filter' property that we already have? > > Eventually. That's what the spec says. We'll wait until CR I guess. > > (Not sure what to do when we want -webkit-filter to apply to SVG) It depends how how you move forward with implementing filters for HTML, I don't see any problems with CSS Filters for SVG elements, as long as the code is not HTML dependent. The next step for SVG might be to use RenderLayers for filtered elements (for instance for CSS Shaders).
Note You need to log in before you can comment on or make changes to this bug.