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 "FocusDirection.h"
25 #include "HTMLFrameOwnerElement.h"
26 #include "LayoutTypes.h"
35 class HTMLAreaElement;
41 inline long long maxDistance()
43 return numeric_limits<long long>::max();
46 inline int fudgeFactor()
51 bool isSpatialNavigationEnabled(const Frame*);
53 // Spatially speaking, two given elements in a web page can be:
54 // 1) Fully aligned: There is a full intersection between the rects, either
55 // vertically or horizontally.
57 // * Horizontally * Vertically
60 // |_|...... _ |_|_|_|_|_|_|
62 // |_|......|_| OR . .
64 // |_|......|_| _ _ _ _
68 // 2) Partially aligned: There is a partial intersection between the rects, either
69 // vertically or horizontally.
71 // * Horizontally * Vertically
80 // 3) Or, otherwise, not aligned at all.
82 // * Horizontally * Vertically
93 // "Totally Aligned" elements are preferable candidates to move
94 // focus to over "Partially Aligned" ones, that on its turns are
95 // more preferable than "Not Aligned".
102 struct FocusCandidate {
106 , enclosingScrollableBox(0)
107 , distance(maxDistance())
108 , parentDistance(maxDistance())
110 , parentAlignment(None)
112 , isOffscreenAfterScrolling(true)
116 FocusCandidate(Node* n, FocusDirection);
117 explicit FocusCandidate(HTMLAreaElement* area, FocusDirection);
118 bool isNull() const { return !visibleNode; }
119 bool inScrollableContainer() const { return visibleNode && enclosingScrollableBox; }
120 bool isFrameOwnerElement() const { return visibleNode && visibleNode->isFrameOwnerElement(); }
121 Document* document() const { return visibleNode ? visibleNode->document() : 0; }
123 // We handle differently visibleNode and FocusableNode to properly handle the areas of imagemaps,
124 // where visibleNode would represent the image element and focusableNode would represent the area element.
125 // In all other cases, visibleNode and focusableNode are one and the same.
128 Node* enclosingScrollableBox;
130 long long parentDistance;
131 RectsAlignment alignment;
132 RectsAlignment parentAlignment;
135 bool isOffscreenAfterScrolling;
138 bool hasOffscreenRect(Node*, FocusDirection direction = FocusDirectionNone);
139 bool scrollInDirection(Frame*, FocusDirection);
140 bool scrollInDirection(Node* container, FocusDirection);
141 bool canScrollInDirection(const Node* container, FocusDirection);
142 bool canScrollInDirection(const Frame*, FocusDirection);
143 bool canBeScrolledIntoView(FocusDirection, const FocusCandidate&);
144 bool areElementsOnSameLine(const FocusCandidate& firstCandidate, const FocusCandidate& secondCandidate);
145 void distanceDataForNode(FocusDirection, const FocusCandidate& current, FocusCandidate& candidate);
146 Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection, Node*);
147 LayoutRect nodeRectInAbsoluteCoordinates(Node*, bool ignoreBorder = false);
148 LayoutRect frameRectInAbsoluteCoordinates(Frame*);
149 LayoutRect virtualRectForDirection(FocusDirection, const LayoutRect& startingRect, LayoutUnit width = 0);
150 LayoutRect virtualRectForAreaElementAndDirection(HTMLAreaElement*, FocusDirection);
151 HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate&);
153 } // namspace WebCore
155 #endif // SpatialNavigation_h