summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/SpatialNavigation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/page/SpatialNavigation.cpp')
-rw-r--r--Source/WebCore/page/SpatialNavigation.cpp70
1 files changed, 33 insertions, 37 deletions
diff --git a/Source/WebCore/page/SpatialNavigation.cpp b/Source/WebCore/page/SpatialNavigation.cpp
index 1e5754f57..50cb3f367 100644
--- a/Source/WebCore/page/SpatialNavigation.cpp
+++ b/Source/WebCore/page/SpatialNavigation.cpp
@@ -13,10 +13,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -55,24 +55,25 @@ static void entryAndExitPointsForDirection(FocusDirection, const LayoutRect& sta
static bool isScrollableNode(const Node*);
FocusCandidate::FocusCandidate(Node* node, FocusDirection direction)
- : visibleNode(nullptr)
- , focusableNode(nullptr)
- , enclosingScrollableBox(nullptr)
+ : visibleNode(0)
+ , focusableNode(0)
+ , enclosingScrollableBox(0)
, distance(maxDistance())
, alignment(None)
, isOffscreen(true)
, isOffscreenAfterScrolling(true)
{
- ASSERT(is<Element>(node));
+ ASSERT(node);
+ ASSERT(node->isElementNode());
- if (is<HTMLAreaElement>(*node)) {
- HTMLAreaElement& area = downcast<HTMLAreaElement>(*node);
- HTMLImageElement* image = area.imageElement();
+ if (isHTMLAreaElement(node)) {
+ HTMLAreaElement* area = toHTMLAreaElement(node);
+ HTMLImageElement* image = area->imageElement();
if (!image || !image->renderer())
return;
visibleNode = image;
- rect = virtualRectForAreaElementAndDirection(&area, direction);
+ rect = virtualRectForAreaElementAndDirection(area, direction);
} else {
if (!node->renderer())
return;
@@ -365,8 +366,8 @@ bool scrollInDirection(Frame* frame, FocusDirection direction)
bool scrollInDirection(Node* container, FocusDirection direction)
{
ASSERT(container);
- if (is<Document>(*container))
- return scrollInDirection(downcast<Document>(*container).frame(), direction);
+ if (container->isDocumentNode())
+ return scrollInDirection(toDocument(container)->frame(), direction);
if (!container->renderBox())
return false;
@@ -424,7 +425,7 @@ bool isScrollableNode(const Node* node)
return false;
if (RenderObject* renderer = node->renderer())
- return is<RenderBox>(*renderer) && downcast<RenderBox>(*renderer).canBeScrolledAndHasScrollableArea() && node->hasChildNodes();
+ return renderer->isBox() && toRenderBox(renderer)->canBeScrolledAndHasScrollableArea() && node->hasChildNodes();
return false;
}
@@ -434,11 +435,11 @@ Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direc
ASSERT(node);
Node* parent = node;
do {
- if (is<Document>(*parent))
- parent = downcast<Document>(*parent).document().frame()->ownerElement();
+ if (parent->isDocumentNode())
+ parent = toDocument(parent)->document().frame()->ownerElement();
else
parent = parent->parentNode();
- } while (parent && !canScrollInDirection(parent, direction) && !is<Document>(*parent));
+ } while (parent && !canScrollInDirection(parent, direction) && !parent->isDocumentNode());
return parent;
}
@@ -447,11 +448,11 @@ bool canScrollInDirection(const Node* container, FocusDirection direction)
{
ASSERT(container);
- if (is<HTMLSelectElement>(*container))
+ if (isHTMLSelectElement(container))
return false;
- if (is<Document>(*container))
- return canScrollInDirection(downcast<Document>(*container).frame(), direction);
+ if (container->isDocumentNode())
+ return canScrollInDirection(toDocument(container)->frame(), direction);
if (!isScrollableNode(container))
return false;
@@ -483,26 +484,24 @@ bool canScrollInDirection(const Frame* frame, FocusDirection direction)
if ((direction == FocusDirectionUp || direction == FocusDirectionDown) && ScrollbarAlwaysOff == verticalMode)
return false;
LayoutSize size = frame->view()->totalContentsSize();
- LayoutPoint scrollPosition = frame->view()->scrollPosition();
- LayoutRect rect = frame->view()->unobscuredContentRectIncludingScrollbars();
+ LayoutSize offset = frame->view()->scrollOffset();
+ LayoutRect rect = frame->view()->visibleContentRectIncludingScrollbars();
- // FIXME: wrong in RTL documents.
switch (direction) {
case FocusDirectionLeft:
- return scrollPosition.x() > 0;
+ return offset.width() > 0;
case FocusDirectionUp:
- return scrollPosition.y() > 0;
+ return offset.height() > 0;
case FocusDirectionRight:
- return rect.width() + scrollPosition.x() < size.width();
+ return rect.width() + offset.width() < size.width();
case FocusDirectionDown:
- return rect.height() + scrollPosition.y() < size.height();
+ return rect.height() + offset.height() < size.height();
default:
ASSERT_NOT_REACHED();
return false;
}
}
-// FIXME: This is completely broken. This should be deleted and callers should be calling ScrollView::contentsToWindow() instead.
static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRect& initialRect)
{
LayoutRect rect = initialRect;
@@ -511,7 +510,7 @@ static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRec
do {
rect.move(element->offsetLeft(), element->offsetTop());
} while ((element = element->offsetParent()));
- rect.moveBy((-frame->view()->scrollPosition()));
+ rect.move((-frame->view()->scrollOffset()));
}
}
return rect;
@@ -521,12 +520,9 @@ LayoutRect nodeRectInAbsoluteCoordinates(Node* node, bool ignoreBorder)
{
ASSERT(node && node->renderer() && !node->document().view()->needsLayout());
- if (is<Document>(*node))
- return frameRectInAbsoluteCoordinates(downcast<Document>(*node).frame());
-
- LayoutRect rect;
- if (RenderObject* renderer = node->renderer())
- rect = rectToAbsoluteCoordinates(node->document().frame(), renderer->absoluteBoundingBoxRect());
+ if (node->isDocumentNode())
+ return frameRectInAbsoluteCoordinates(toDocument(node)->frame());
+ LayoutRect rect = rectToAbsoluteCoordinates(node->document().frame(), node->boundingBox());
// For authors that use border instead of outline in their CSS, we compensate by ignoring the border when calculating
// the rect of the focused element.
@@ -611,7 +607,7 @@ bool areElementsOnSameLine(const FocusCandidate& firstCandidate, const FocusCand
if (!firstCandidate.rect.intersects(secondCandidate.rect))
return false;
- if (is<HTMLAreaElement>(*firstCandidate.focusableNode) || is<HTMLAreaElement>(*secondCandidate.focusableNode))
+ if (isHTMLAreaElement(firstCandidate.focusableNode) || isHTMLAreaElement(secondCandidate.focusableNode))
return false;
if (!firstCandidate.visibleNode->renderer()->isRenderInline() || !secondCandidate.visibleNode->renderer()->isRenderInline())
@@ -762,7 +758,7 @@ LayoutRect virtualRectForAreaElementAndDirection(HTMLAreaElement* area, FocusDir
HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate& candidate)
{
- return candidate.isFrameOwnerElement() ? downcast<HTMLFrameOwnerElement>(candidate.visibleNode) : nullptr;
-}
+ return candidate.isFrameOwnerElement() ? toHTMLFrameOwnerElement(candidate.visibleNode) : nullptr;
+};
} // namespace WebCore