2 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2009 Antonio Gomes <tonikitoo@webkit.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef SpatialNavigation_h
22 #define SpatialNavigation_h
24 #include "core/dom/Node.h"
25 #include "core/page/FocusType.h"
26 #include "platform/geometry/LayoutRect.h"
34 class HTMLAreaElement;
35 class HTMLFrameOwnerElement;
39 inline long long maxDistance()
41 return std::numeric_limits<long long>::max();
44 inline int fudgeFactor()
49 bool isSpatialNavigationEnabled(const LocalFrame*);
51 // Spatially speaking, two given elements in a web page can be:
52 // 1) Fully aligned: There is a full intersection between the rects, either
53 // vertically or horizontally.
55 // * Horizontally * Vertically
58 // |_|...... _ |_|_|_|_|_|_|
60 // |_|......|_| OR . .
62 // |_|......|_| _ _ _ _
66 // 2) Partially aligned: There is a partial intersection between the rects, either
67 // vertically or horizontally.
69 // * Horizontally * Vertically
78 // 3) Or, otherwise, not aligned at all.
80 // * Horizontally * Vertically
91 // "Totally Aligned" elements are preferable candidates to move
92 // focus to over "Partially Aligned" ones, that on its turns are
93 // more preferable than "Not Aligned".
100 struct FocusCandidate {
104 : visibleNode(nullptr)
105 , focusableNode(nullptr)
106 , enclosingScrollableBox(nullptr)
107 , distance(maxDistance())
110 , isOffscreenAfterScrolling(true)
114 FocusCandidate(Node*, FocusType);
115 explicit FocusCandidate(HTMLAreaElement*, FocusType);
116 bool isNull() const { return !visibleNode; }
117 bool inScrollableContainer() const { return visibleNode && enclosingScrollableBox; }
118 bool isFrameOwnerElement() const { return visibleNode && visibleNode->isFrameOwnerElement(); }
119 Document* document() const { return visibleNode ? &visibleNode->document() : 0; }
121 // We handle differently visibleNode and FocusableNode to properly handle the areas of imagemaps,
122 // where visibleNode would represent the image element and focusableNode would represent the area element.
123 // In all other cases, visibleNode and focusableNode are one and the same.
124 RawPtrWillBeMember<Node> visibleNode;
125 RawPtrWillBeMember<Node> focusableNode;
126 RawPtrWillBeMember<Node> enclosingScrollableBox;
128 RectsAlignment alignment;
131 bool isOffscreenAfterScrolling;
134 bool hasOffscreenRect(Node*, FocusType = FocusTypeNone);
135 bool scrollInDirection(LocalFrame*, FocusType);
136 bool scrollInDirection(Node* container, FocusType);
137 bool canScrollInDirection(const Node* container, FocusType);
138 bool canScrollInDirection(const LocalFrame*, FocusType);
139 bool canBeScrolledIntoView(FocusType, const FocusCandidate&);
140 bool areElementsOnSameLine(const FocusCandidate& firstCandidate, const FocusCandidate& secondCandidate);
141 void distanceDataForNode(FocusType, const FocusCandidate& current, FocusCandidate&);
142 Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusType, Node*);
143 LayoutRect nodeRectInAbsoluteCoordinates(Node*, bool ignoreBorder = false);
144 LayoutRect frameRectInAbsoluteCoordinates(LocalFrame*);
145 LayoutRect virtualRectForDirection(FocusType, const LayoutRect& startingRect, LayoutUnit width = 0);
146 LayoutRect virtualRectForAreaElementAndDirection(HTMLAreaElement&, FocusType);
147 HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate&);
151 #endif // SpatialNavigation_h