SVG: hit testing region for <text> elements is incorrect
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 10:40:17 +0000 (10:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 10:40:17 +0000 (10:40 +0000)
commite4b671c2f4acca7c79b371c6f812a0527e28c8b7
treef14d4d2702ab536886400b8c5ba87657c343c261
parente9cdc1dffe98662a74eec6a811c7288159f03822
SVG: hit testing region for <text> elements is incorrect
https://bugs.webkit.org/show_bug.cgi?id=150838

Patch by Antoine Quint <graouts@apple.com> on 2015-11-04
Reviewed by Dean Jackson.

Source/WebCore:

Hit testing for SVG <text> elements was using the same code as hit testing
for CSS-rendered elements. However, in SVG, text elements should only hit
test based on their character cells, not the rectangular bounds of the
element, see section 16.6 of the SVG 1.1 specification:

http://www.w3.org/TR/SVG11/interact.html#PointerEventsProperty

So we now hit test each SVGTextFragment of each SVGInlineTextBox
that is a child of an SVGRootInlineBox to correctly find whether the
provided HitTestLocation is contained within a character cell.

Tests: svg/hittest/text-dominant-baseline-hanging.svg
       svg/hittest/text-multiple-dx-values.svg
       svg/hittest/text-with-multiple-tspans.svg
       svg/hittest/text-with-text-node-and-content-elements.svg
       svg/hittest/text-with-text-node-only.svg
       svg/hittest/text-with-text-path.svg

* rendering/RootInlineBox.h:
Remove the final keyword since nodeAtPoint() may now be subclassed as
implemented in SVGRootInlineBox.

* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::nodeAtPoint):
Iterate over the SVGTextFragments to look for a fragment containing the
provided HitTestLocation.

* rendering/svg/SVGRootInlineBox.cpp:
(WebCore::SVGRootInlineBox::nodeAtPoint):
* rendering/svg/SVGRootInlineBox.h:
Override RootInlineBox::nodeAtPoint() to delegate hit testing to the
children inline boxes.

LayoutTests:

* svg/hittest/text-dominant-baseline-hanging-expected.svg: Added.
* svg/hittest/text-dominant-baseline-hanging.svg: Added.
* svg/hittest/text-multiple-dx-values-expected.svg: Added.
* svg/hittest/text-multiple-dx-values.svg: Added.
* svg/hittest/text-with-multiple-tspans-expected.svg: Added.
* svg/hittest/text-with-multiple-tspans.svg: Added.
* svg/hittest/text-with-text-node-and-content-elements-expected.svg: Added.
* svg/hittest/text-with-text-node-and-content-elements.svg: Added.
* svg/hittest/text-with-text-node-only-expected.svg: Added.
* svg/hittest/text-with-text-node-only.svg: Added.
* svg/hittest/text-with-text-path-expected.svg: Added.
* svg/hittest/text-with-text-path.svg: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/hittest/text-dominant-baseline-hanging-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-dominant-baseline-hanging.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-multiple-dx-values-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-multiple-dx-values.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-multiple-tspans-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-multiple-tspans.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-node-and-content-elements-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-node-and-content-elements.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-node-only-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-node-only.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-path-expected.svg [new file with mode: 0644]
LayoutTests/svg/hittest/text-with-text-path.svg [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RootInlineBox.h
Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
Source/WebCore/rendering/svg/SVGRootInlineBox.cpp
Source/WebCore/rendering/svg/SVGRootInlineBox.h