Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBlock.cpp

Issue 1506053003: Include clip-path and border radius when hit testing boxes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup tests to use js-test.js Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "core/layout/LayoutTextControl.h" 53 #include "core/layout/LayoutTextControl.h"
54 #include "core/layout/LayoutTextFragment.h" 54 #include "core/layout/LayoutTextFragment.h"
55 #include "core/layout/LayoutTheme.h" 55 #include "core/layout/LayoutTheme.h"
56 #include "core/layout/LayoutView.h" 56 #include "core/layout/LayoutView.h"
57 #include "core/layout/TextAutosizer.h" 57 #include "core/layout/TextAutosizer.h"
58 #include "core/layout/api/LineLayoutItem.h" 58 #include "core/layout/api/LineLayoutItem.h"
59 #include "core/layout/line/GlyphOverflow.h" 59 #include "core/layout/line/GlyphOverflow.h"
60 #include "core/layout/line/InlineIterator.h" 60 #include "core/layout/line/InlineIterator.h"
61 #include "core/layout/line/InlineTextBox.h" 61 #include "core/layout/line/InlineTextBox.h"
62 #include "core/layout/shapes/ShapeOutsideInfo.h" 62 #include "core/layout/shapes/ShapeOutsideInfo.h"
63 #include "core/layout/svg/LayoutSVGResourceClipper.h"
64 #include "core/page/Page.h" 63 #include "core/page/Page.h"
65 #include "core/paint/BlockPainter.h" 64 #include "core/paint/BlockPainter.h"
66 #include "core/paint/BoxPainter.h" 65 #include "core/paint/BoxPainter.h"
67 #include "core/paint/LayoutObjectDrawingRecorder.h" 66 #include "core/paint/LayoutObjectDrawingRecorder.h"
68 #include "core/paint/PaintLayer.h" 67 #include "core/paint/PaintLayer.h"
69 #include "core/style/ComputedStyle.h" 68 #include "core/style/ComputedStyle.h"
70 #include "core/style/ContentData.h" 69 #include "core/style/ContentData.h"
71 #include "platform/RuntimeEnabledFeatures.h" 70 #include "platform/RuntimeEnabledFeatures.h"
72 #include "platform/geometry/FloatQuad.h" 71 #include "platform/geometry/FloatQuad.h"
73 #include "platform/geometry/TransformState.h" 72 #include "platform/geometry/TransformState.h"
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 } 1624 }
1626 1625
1627 Node* LayoutBlock::nodeForHitTest() const 1626 Node* LayoutBlock::nodeForHitTest() const
1628 { 1627 {
1629 // If we are in the margins of block elements that are part of a 1628 // If we are in the margins of block elements that are part of a
1630 // continuation we're actually still inside the enclosing element 1629 // continuation we're actually still inside the enclosing element
1631 // that was split. Use the appropriate inner node. 1630 // that was split. Use the appropriate inner node.
1632 return isAnonymousBlockContinuation() ? continuation()->node() : node(); 1631 return isAnonymousBlockContinuation() ? continuation()->node() : node();
1633 } 1632 }
1634 1633
1634 // TODO(pdr): This is very similar to LayoutBox::nodeAtPoint and we should share more code.
1635 bool LayoutBlock::nodeAtPoint(HitTestResult& result, const HitTestLocation& loca tionInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestActi on) 1635 bool LayoutBlock::nodeAtPoint(HitTestResult& result, const HitTestLocation& loca tionInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestActi on)
1636 { 1636 {
1637 LayoutPoint adjustedLocation(accumulatedOffset + location()); 1637 LayoutPoint adjustedLocation(accumulatedOffset + location());
1638 LayoutSize localOffset = toLayoutSize(adjustedLocation); 1638 LayoutSize localOffset = toLayoutSize(adjustedLocation);
1639 1639
1640 if (!isLayoutView()) { 1640 if (!isLayoutView()) {
1641 // Check if we need to do anything at all. 1641 // Check if we need to do anything at all.
1642 // If we have clipping, then we can't have any spillout. 1642 // If we have clipping, then we can't have any spillout.
1643 LayoutRect overflowBox = hasOverflowClip() ? borderBoxRect() : visualOve rflowRect(); 1643 LayoutRect overflowBox = hasOverflowClip() ? borderBoxRect() : visualOve rflowRect();
1644 flipForWritingMode(overflowBox); 1644 flipForWritingMode(overflowBox);
1645 overflowBox.moveBy(adjustedLocation); 1645 overflowBox.moveBy(adjustedLocation);
1646 if (!locationInContainer.intersects(overflowBox)) 1646 if (!locationInContainer.intersects(overflowBox))
1647 return false; 1647 return false;
1648 } 1648 }
1649 1649
1650 if ((hitTestAction == HitTestBlockBackground || hitTestAction == HitTestChil dBlockBackground) 1650 if ((hitTestAction == HitTestBlockBackground || hitTestAction == HitTestChil dBlockBackground)
1651 && visibleToHitTestRequest(result.hitTestRequest()) 1651 && visibleToHitTestRequest(result.hitTestRequest())
1652 && isPointInOverflowControl(result, locationInContainer.point(), adjuste dLocation)) { 1652 && isPointInOverflowControl(result, locationInContainer.point(), adjuste dLocation)) {
1653 updateHitTestResult(result, locationInContainer.point() - localOffset); 1653 updateHitTestResult(result, locationInContainer.point() - localOffset);
1654 // FIXME: isPointInOverflowControl() doesn't handle rect-based tests yet . 1654 // FIXME: isPointInOverflowControl() doesn't handle rect-based tests yet .
1655 if (!result.addNodeToListBasedTestResult(nodeForHitTest(), locationInCon tainer)) 1655 if (!result.addNodeToListBasedTestResult(nodeForHitTest(), locationInCon tainer))
1656 return true; 1656 return true;
1657 } 1657 }
1658 1658
1659 if (style()->clipPath()) { 1659 if (hitTestClippedOutByClipPath(locationInContainer, adjustedLocation))
1660 switch (style()->clipPath()->type()) { 1660 return false;
1661 case ClipPathOperation::SHAPE: {
1662 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(style()- >clipPath());
1663 // FIXME: handle marginBox etc.
1664 if (!clipPath->path(FloatRect(borderBoxRect())).contains(FloatPoint( locationInContainer.point() - localOffset), clipPath->windRule()))
1665 return false;
1666 break;
1667 }
1668 case ClipPathOperation::REFERENCE:
1669 ReferenceClipPathOperation* referenceClipPathOperation = toReference ClipPathOperation(style()->clipPath());
1670 Element* element = document().getElementById(referenceClipPathOperat ion->fragment());
1671 if (isSVGClipPathElement(element) && element->layoutObject()) {
1672 LayoutSVGResourceClipper* clipper = toLayoutSVGResourceClipper(t oLayoutSVGResourceContainer(element->layoutObject()));
1673 if (!clipper->hitTestClipContent(FloatRect(borderBoxRect()), Flo atPoint(locationInContainer.point() - localOffset)))
1674 return false;
1675 }
1676 break;
1677 }
1678 }
1679 1661
1680 bool checkChildren = true; 1662 bool checkChildren = true;
1681 1663
1682 // Self painting layers will handle overflow clip in most cases, but without one we need to 1664 // TODO(pdr): We should also include checks for hit testing clip path and bo rder radius at the
1683 // check if overflip clip will affect child hit testing. 1665 // layer level (see: crbug.com/568904).
1684 if (hasOverflowClip() && !hasSelfPaintingLayer()) { 1666 if (hasOverflowClip() && !hasSelfPaintingLayer()) {
1685 if (style()->hasBorderRadius()) { 1667 if (style()->hasBorderRadius()) {
1686 LayoutRect borderRect = borderBoxRect(); 1668 LayoutRect borderRect = borderBoxRect();
1687 borderRect.moveBy(adjustedLocation); 1669 borderRect.moveBy(adjustedLocation);
1688 checkChildren = locationInContainer.intersects(style()->getRoundedIn nerBorderFor(borderRect)); 1670 checkChildren = locationInContainer.intersects(style()->getRoundedIn nerBorderFor(borderRect));
1689 } else { 1671 } else {
1690 checkChildren = locationInContainer.intersects(overflowClipRect(adju stedLocation, IncludeOverlayScrollbarSize)); 1672 checkChildren = locationInContainer.intersects(overflowClipRect(adju stedLocation, IncludeOverlayScrollbarSize));
1691 } 1673 }
1692 } 1674 }
1693 1675
1694 // A control clip can also clip out child hit testing. 1676 // A control clip can also clip out child hit testing.
1695 if (checkChildren && hasControlClip()) 1677 if (checkChildren && hasControlClip())
1696 checkChildren = locationInContainer.intersects(controlClipRect(adjustedL ocation)); 1678 checkChildren = locationInContainer.intersects(controlClipRect(adjustedL ocation));
1697 1679
1698 if (checkChildren) { 1680 if (checkChildren) {
1699 // Hit test descendants first. 1681 // Hit test descendants first.
1700 LayoutSize scrolledOffset(localOffset); 1682 LayoutSize scrolledOffset(localOffset);
1701 if (hasOverflowClip()) 1683 if (hasOverflowClip())
1702 scrolledOffset -= scrolledContentOffset(); 1684 scrolledOffset -= scrolledContentOffset();
1703 1685
1704 // Hit test contents 1686 // Hit test contents
1705 if (hitTestContents(result, locationInContainer, toLayoutPoint(scrolledO ffset), hitTestAction)) { 1687 if (hitTestContents(result, locationInContainer, toLayoutPoint(scrolledO ffset), hitTestAction)) {
1706 updateHitTestResult(result, flipForWritingMode(locationInContainer.p oint() - localOffset)); 1688 updateHitTestResult(result, flipForWritingMode(locationInContainer.p oint() - localOffset));
1707 return true; 1689 return true;
1708 } 1690 }
1709 if (hitTestAction == HitTestFloat && hitTestFloats(result, locationInCon tainer, toLayoutPoint(scrolledOffset))) 1691 if (hitTestAction == HitTestFloat && hitTestFloats(result, locationInCon tainer, toLayoutPoint(scrolledOffset)))
1710 return true; 1692 return true;
1711 } 1693 }
1712 1694
1713 // Check if the point is outside radii. 1695 if (hitTestClippedOutByRoundedBorder(locationInContainer, adjustedLocation))
1714 if (style()->hasBorderRadius()) { 1696 return false;
1715 LayoutRect borderRect = borderBoxRect();
1716 borderRect.moveBy(adjustedLocation);
1717 if (!locationInContainer.intersects(style()->getRoundedBorderFor(borderR ect)))
1718 return false;
1719 }
1720 1697
1721 // Now hit test our background 1698 // Now hit test our background
1722 if (hitTestAction == HitTestBlockBackground || hitTestAction == HitTestChild BlockBackground) { 1699 if (hitTestAction == HitTestBlockBackground || hitTestAction == HitTestChild BlockBackground) {
1723 LayoutRect boundsRect(adjustedLocation, size()); 1700 LayoutRect boundsRect(adjustedLocation, size());
1724 if (visibleToHitTestRequest(result.hitTestRequest()) && locationInContai ner.intersects(boundsRect)) { 1701 if (visibleToHitTestRequest(result.hitTestRequest()) && locationInContai ner.intersects(boundsRect)) {
1725 updateHitTestResult(result, flipForWritingMode(locationInContainer.p oint() - localOffset)); 1702 updateHitTestResult(result, flipForWritingMode(locationInContainer.p oint() - localOffset));
1726 if (!result.addNodeToListBasedTestResult(nodeForHitTest(), locationI nContainer, boundsRect)) 1703 if (!result.addNodeToListBasedTestResult(nodeForHitTest(), locationI nContainer, boundsRect))
1727 return true; 1704 return true;
1728 } 1705 }
1729 } 1706 }
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const 2888 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const
2912 { 2889 {
2913 showLayoutObject(); 2890 showLayoutObject();
2914 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 2891 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
2915 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 2892 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
2916 } 2893 }
2917 2894
2918 #endif 2895 #endif
2919 2896
2920 } // namespace blink 2897 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698