18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2006 Apple Computer, Inc. 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version. 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful, 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details. 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB. If not, write to 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA. 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef HitTestResult_h 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define HitTestResult_h 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2381bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch#include "FloatRect.h" 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "IntPoint.h" 25db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block#include "IntRect.h" 26db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block#include "IntSize.h" 270bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#include "TextDirection.h" 28dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include <wtf/Forward.h> 29db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block#include <wtf/ListHashSet.h> 302bde8e466a4451c7319e3a072d118917957d6554Steve Block#include <wtf/OwnPtr.h> 318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/RefPtr.h> 328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Element; 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Frame; 37bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#if ENABLE(VIDEO) 38bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenclass HTMLMediaElement; 39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#endif 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Image; 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass IntRect; 420bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochclass KURL; 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Node; 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Scrollbar; 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass HitTestResult { 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic: 482bde8e466a4451c7319e3a072d118917957d6554Steve Block typedef ListHashSet<RefPtr<Node> > NodeSet; 492bde8e466a4451c7319e3a072d118917957d6554Steve Block 50f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch HitTestResult(); 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project HitTestResult(const IntPoint&); 52bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // Pass non-negative padding values to perform a rect-based hit test. 53bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen HitTestResult(const IntPoint& centerPoint, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding); 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project HitTestResult(const HitTestResult&); 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ~HitTestResult(); 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project HitTestResult& operator=(const HitTestResult&); 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Node* innerNode() const { return m_innerNode.get(); } 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Node* innerNonSharedNode() const { return m_innerNonSharedNode.get(); } 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project IntPoint point() const { return m_point; } 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project IntPoint localPoint() const { return m_localPoint; } 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Element* URLElement() const { return m_innerURLElement.get(); } 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Scrollbar* scrollbar() const { return m_scrollbar.get(); } 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool isOverWidget() const { return m_isOverWidget; } 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setToNonShadowAncestor(); 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setInnerNode(Node*); 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setInnerNonSharedNode(Node*); 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setPoint(const IntPoint& p) { m_point = p; } 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setLocalPoint(const IntPoint& p) { m_localPoint = p; } 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setURLElement(Element*); 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setScrollbar(Scrollbar*); 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void setIsOverWidget(bool b) { m_isOverWidget = b; } 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Frame* targetFrame() const; 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool isSelected() const; 780bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch String spellingToolTip(TextDirection&) const; 795f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian String replacedString() const; 800bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch String title(TextDirection&) const; 818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String altDisplayString() const; 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String titleDisplayString() const; 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Image* image() const; 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project IntRect imageRect() const; 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project KURL absoluteImageURL() const; 860bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch KURL absoluteMediaURL() const; 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project KURL absoluteLinkURL() const; 888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String textContent() const; 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool isLiveLink() const; 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool isContentEditable() const; 91bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void toggleMediaControlsDisplay() const; 92bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void toggleMediaLoopPlayback() const; 93bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void enterFullscreenForVideo() const; 94bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaControlsEnabled() const; 95bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaLoopEnabled() const; 96bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaPlaying() const; 97bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaSupportsFullscreen() const; 98bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void toggleMediaPlayState() const; 99bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaHasAudio() const; 100bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaIsVideo() const; 101bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen bool mediaMuted() const; 102bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen void toggleMediaMuteState() const; 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 104db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block // Rect-based hit test related methods. 105db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block bool isRectBasedTest() const { return m_isRectBased; } 106a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch IntRect rectForPoint(int x, int y) const; 107a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch IntRect rectForPoint(const IntPoint&) const; 108a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch static IntRect rectForPoint(const IntPoint&, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding); 109bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int topPadding() const { return m_topPadding; } 110bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int rightPadding() const { return m_rightPadding; } 111bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int bottomPadding() const { return m_bottomPadding; } 112bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int leftPadding() const { return m_leftPadding; } 113bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 114db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block // Returns true if it is rect-based hit test and needs to continue until the rect is fully 115db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block // enclosed by the boundaries of a node. 11681bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch bool addNodeToRectBasedTestResult(Node*, int x, int y, const IntRect& = IntRect()); 11781bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch bool addNodeToRectBasedTestResult(Node*, int x, int y, const FloatRect&); 118db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block void append(const HitTestResult&); 11917dcead8ee9edfa8f75e7e2d2284ed3c6f4bd403Grace Kloba 1202bde8e466a4451c7319e3a072d118917957d6554Steve Block // If m_rectBasedTestResult is 0 then set it to a new NodeSet. Return *m_rectBasedTestResult. Lazy allocation makes 1212bde8e466a4451c7319e3a072d118917957d6554Steve Block // sense because the NodeSet is seldom necessary, and it's somewhat expensive to allocate and initialize. This method does 1222bde8e466a4451c7319e3a072d118917957d6554Steve Block // the same thing as mutableRectBasedTestResult(), but here the return value is const. 1232bde8e466a4451c7319e3a072d118917957d6554Steve Block const NodeSet& rectBasedTestResult() const; 1242bde8e466a4451c7319e3a072d118917957d6554Steve Block 1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate: 1262bde8e466a4451c7319e3a072d118917957d6554Steve Block NodeSet& mutableRectBasedTestResult(); // See above. 127db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block 128bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#if ENABLE(VIDEO) 129bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen HTMLMediaElement* mediaElement() const; 130bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#endif 131bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 1328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<Node> m_innerNode; 1338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<Node> m_innerNonSharedNode; 1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project IntPoint m_point; 1358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project IntPoint m_localPoint; // A point in the local coordinate space of m_innerNonSharedNode's renderer. Allows us to efficiently 1368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // determine where inside the renderer we hit on subsequent operations. 1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<Element> m_innerURLElement; 1388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<Scrollbar> m_scrollbar; 1398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool m_isOverWidget; // Returns true if we are over a widget (and not in the border/padding area of a RenderWidget for example). 140db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block bool m_isRectBased; 141bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_topPadding; 142bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_rightPadding; 143bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_bottomPadding; 144bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen int m_leftPadding; 1452bde8e466a4451c7319e3a072d118917957d6554Steve Block mutable OwnPtr<NodeSet> m_rectBasedTestResult; 1468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}; 1478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 148a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline IntRect HitTestResult::rectForPoint(int x, int y) const 149db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block{ 150a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return rectForPoint(IntPoint(x, y), m_topPadding, m_rightPadding, m_bottomPadding, m_leftPadding); 151db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block} 152db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block 153db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block// Formula: 154bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// x = p.x() - rightPadding 155bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// y = p.y() - topPadding 156bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// width = leftPadding + rightPadding + 1 157bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen// height = topPadding + bottomPadding + 1 158a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochinline IntRect HitTestResult::rectForPoint(const IntPoint& point) const 159db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block{ 160a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return rectForPoint(point, m_topPadding, m_rightPadding, m_bottomPadding, m_leftPadding); 161db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block} 162db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block 1638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectString displayString(const String&, const Node*); 1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore 1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // HitTestResult_h 168