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"
33 class HTMLAreaElement;
34 class HTMLFrameOwnerElement;
36 inline long long maxDistance()
38 return std::numeric_limits<long long>::max();
41 inline int fudgeFactor()
46 bool isSpatialNavigationEnabled(const LocalFrame*);
48 // Spatially speaking, two given elements in a web page can be:
49 // 1) Fully aligned: There is a full intersection between the rects, either
50 // vertically or horizontally.
52 // * Horizontally * Vertically
55 // |_|...... _ |_|_|_|_|_|_|
57 // |_|......|_| OR . .
59 // |_|......|_| _ _ _ _
63 // 2) Partially aligned: There is a partial intersection between the rects, either
64 // vertically or horizontally.
66 // * Horizontally * Vertically
75 // 3) Or, otherwise, not aligned at all.
77 // * Horizontally * Vertically
88 // "Totally Aligned" elements are preferable candidates to move
89 // focus to over "Partially Aligned" ones, that on its turns are
90 // more preferable than "Not Aligned".
97 struct FocusCandidate {
101 : visibleNode(nullptr)
102 , focusableNode(nullptr)
103 , enclosingScrollableBox(nullptr)
104 , distance(maxDistance())
107 , isOffscreenAfterScrolling(true)
111 FocusCandidate(Node*, FocusType);
112 explicit FocusCandidate(HTMLAreaElement*, FocusType);
113 bool isNull() const { return !visibleNode; }
114 bool inScrollableContainer() const { return visibleNode && enclosingScrollableBox; }
115 bool isFrameOwnerElement() const { return visibleNode && visibleNode->isFrameOwnerElement(); }
116 Document* document() const { return visibleNode ? &visibleNode->document() : nullptr; }
118 // We handle differently visibleNode and FocusableNode to properly handle the areas of imagemaps,
119 // where visibleNode would represent the image element and focusableNode would represent the area element.
120 // In all other cases, visibleNode and focusableNode are one and the same.
121 RawPtrWillBeMember<Node> visibleNode;
122 RawPtrWillBeMember<Node> focusableNode;
123 RawPtrWillBeMember<Node> enclosingScrollableBox;
125 RectsAlignment alignment;
128 bool isOffscreenAfterScrolling;
131 bool hasOffscreenRect(Node*, FocusType = FocusTypeNone);
132 bool scrollInDirection(LocalFrame*, FocusType);
133 bool scrollInDirection(Node* container, FocusType);
134 bool canScrollInDirection(const Node* container, FocusType);
135 bool canScrollInDirection(const LocalFrame*, FocusType);
136 bool canBeScrolledIntoView(FocusType, const FocusCandidate&);
137 bool areElementsOnSameLine(const FocusCandidate& firstCandidate, const FocusCandidate& secondCandidate);
138 void distanceDataForNode(FocusType, const FocusCandidate& current, FocusCandidate&);
139 Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusType, Node*);
140 LayoutRect nodeRectInAbsoluteCoordinates(Node*, bool ignoreBorder = false);
141 LayoutRect frameRectInAbsoluteCoordinates(LocalFrame*);
142 LayoutRect virtualRectForDirection(FocusType, const LayoutRect& startingRect, LayoutUnit width = 0);
143 LayoutRect virtualRectForAreaElementAndDirection(HTMLAreaElement&, FocusType);
144 HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate&);
148 #endif // SpatialNavigation_h