Bug 156659 - CSSCursorImageValue shouldn't mutate element during style resolution
Summary: CSSCursorImageValue shouldn't mutate element during style resolution
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-16 04:40 PDT by Antti Koivisto
Modified: 2016-04-16 10:54 PDT (History)
1 user (show)

See Also:


Attachments
patch (20.65 KB, patch)
2016-04-16 06:54 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
patch (22.46 KB, patch)
2016-04-16 10:01 PDT, Antti Koivisto
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2016-04-16 04:40:32 PDT
CSSCursorImageValue::updateIfSVGCursorIsUsed may mutate the argument element.
Comment 1 Antti Koivisto 2016-04-16 06:54:15 PDT
Created attachment 276553 [details]
patch
Comment 2 Antti Koivisto 2016-04-16 10:01:14 PDT
Created attachment 276558 [details]
patch
Comment 3 Darin Adler 2016-04-16 10:15:53 PDT
Comment on attachment 276558 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=276558&action=review

I would probably refer to these as "cursor elements" rather than "SVG cursor elements" even more consistently in the code. Names like m_cursorElements and updateCursorElement would be nicer than m_svgCursorElements and updateSVGCursorElement. Type would still make it clear it’s specific to SVG.

> Source/WebCore/css/CSSCursorImageValue.cpp:91
> +    auto* svgCursorElement = downcast<SVGCursorElement>(element);

I would use a reference:

    auto& svgCursorElement = downcast<SVGCursorElement>(*element);

> Source/WebCore/css/CSSCursorImageValue.cpp:110
> +    SVGLengthContext lengthContext(0);

Should be nullptr rather than 0.

> Source/WebCore/css/CSSCursorImageValue.cpp:112
> +    float x = roundf(cursorElement.x().value(lengthContext));

I suggest using std::round instead of roundf. Also not sure if rounding is correct. Also wondering if we should clamp to the size of the image.

> Source/WebCore/css/CSSCursorImageValue.cpp:115
> +    float y = roundf(cursorElement.y().value(lengthContext));

Ditto.

> Source/WebCore/css/CSSCursorImageValue.h:-78
> +    HashSet<SVGCursorElement*> m_svgCursorElements;
>  
> -    HashSet<SVGElement*> m_referencedElements;

There’s a stray blank line here. I suggest removing it.
Comment 4 Antti Koivisto 2016-04-16 10:54:47 PDT
http://trac.webkit.org