diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/SpatialNavigation.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/page/SpatialNavigation.cpp')
-rw-r--r-- | Source/WebCore/page/SpatialNavigation.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/Source/WebCore/page/SpatialNavigation.cpp b/Source/WebCore/page/SpatialNavigation.cpp index 50cb3f367..b73f46f4a 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 COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE 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 COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE 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 @@ -34,7 +34,7 @@ #include "HTMLAreaElement.h" #include "HTMLImageElement.h" #include "HTMLMapElement.h" -#include "HTMLNames.h" +#include "HTMLSelectElement.h" #include "IntRect.h" #include "MainFrame.h" #include "Node.h" @@ -55,25 +55,24 @@ static void entryAndExitPointsForDirection(FocusDirection, const LayoutRect& sta static bool isScrollableNode(const Node*); FocusCandidate::FocusCandidate(Node* node, FocusDirection direction) - : visibleNode(0) - , focusableNode(0) - , enclosingScrollableBox(0) + : visibleNode(nullptr) + , focusableNode(nullptr) + , enclosingScrollableBox(nullptr) , distance(maxDistance()) , alignment(None) , isOffscreen(true) , isOffscreenAfterScrolling(true) { - ASSERT(node); - ASSERT(node->isElementNode()); + ASSERT(is<Element>(node)); - if (isHTMLAreaElement(node)) { - HTMLAreaElement* area = toHTMLAreaElement(node); - HTMLImageElement* image = area->imageElement(); + if (is<HTMLAreaElement>(*node)) { + HTMLAreaElement& area = downcast<HTMLAreaElement>(*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; @@ -366,8 +365,8 @@ bool scrollInDirection(Frame* frame, FocusDirection direction) bool scrollInDirection(Node* container, FocusDirection direction) { ASSERT(container); - if (container->isDocumentNode()) - return scrollInDirection(toDocument(container)->frame(), direction); + if (is<Document>(*container)) + return scrollInDirection(downcast<Document>(*container).frame(), direction); if (!container->renderBox()) return false; @@ -419,15 +418,11 @@ static void deflateIfOverlapped(LayoutRect& a, LayoutRect& b) bool isScrollableNode(const Node* node) { - ASSERT(!node->isDocumentNode()); - if (!node) return false; - - if (RenderObject* renderer = node->renderer()) - return renderer->isBox() && toRenderBox(renderer)->canBeScrolledAndHasScrollableArea() && node->hasChildNodes(); - - return false; + ASSERT(!node->isDocumentNode()); + auto* renderer = node->renderer(); + return is<RenderBox>(renderer) && downcast<RenderBox>(*renderer).canBeScrolledAndHasScrollableArea() && node->hasChildNodes(); } Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direction, Node* node) @@ -435,11 +430,11 @@ Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direc ASSERT(node); Node* parent = node; do { - if (parent->isDocumentNode()) - parent = toDocument(parent)->document().frame()->ownerElement(); + if (is<Document>(*parent)) + parent = downcast<Document>(*parent).document().frame()->ownerElement(); else parent = parent->parentNode(); - } while (parent && !canScrollInDirection(parent, direction) && !parent->isDocumentNode()); + } while (parent && !canScrollInDirection(parent, direction) && !is<Document>(*parent)); return parent; } @@ -448,11 +443,11 @@ bool canScrollInDirection(const Node* container, FocusDirection direction) { ASSERT(container); - if (isHTMLSelectElement(container)) + if (is<HTMLSelectElement>(*container)) return false; - if (container->isDocumentNode()) - return canScrollInDirection(toDocument(container)->frame(), direction); + if (is<Document>(*container)) + return canScrollInDirection(downcast<Document>(*container).frame(), direction); if (!isScrollableNode(container)) return false; @@ -484,24 +479,26 @@ bool canScrollInDirection(const Frame* frame, FocusDirection direction) if ((direction == FocusDirectionUp || direction == FocusDirectionDown) && ScrollbarAlwaysOff == verticalMode) return false; LayoutSize size = frame->view()->totalContentsSize(); - LayoutSize offset = frame->view()->scrollOffset(); - LayoutRect rect = frame->view()->visibleContentRectIncludingScrollbars(); + LayoutPoint scrollPosition = frame->view()->scrollPosition(); + LayoutRect rect = frame->view()->unobscuredContentRectIncludingScrollbars(); + // FIXME: wrong in RTL documents. switch (direction) { case FocusDirectionLeft: - return offset.width() > 0; + return scrollPosition.x() > 0; case FocusDirectionUp: - return offset.height() > 0; + return scrollPosition.y() > 0; case FocusDirectionRight: - return rect.width() + offset.width() < size.width(); + return rect.width() + scrollPosition.x() < size.width(); case FocusDirectionDown: - return rect.height() + offset.height() < size.height(); + return rect.height() + scrollPosition.y() < 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; @@ -510,7 +507,7 @@ static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRec do { rect.move(element->offsetLeft(), element->offsetTop()); } while ((element = element->offsetParent())); - rect.move((-frame->view()->scrollOffset())); + rect.moveBy((-frame->view()->scrollPosition())); } } return rect; @@ -520,9 +517,12 @@ LayoutRect nodeRectInAbsoluteCoordinates(Node* node, bool ignoreBorder) { ASSERT(node && node->renderer() && !node->document().view()->needsLayout()); - if (node->isDocumentNode()) - return frameRectInAbsoluteCoordinates(toDocument(node)->frame()); - LayoutRect rect = rectToAbsoluteCoordinates(node->document().frame(), node->boundingBox()); + if (is<Document>(*node)) + return frameRectInAbsoluteCoordinates(downcast<Document>(*node).frame()); + + LayoutRect rect; + if (RenderObject* renderer = node->renderer()) + rect = rectToAbsoluteCoordinates(node->document().frame(), renderer->absoluteBoundingBoxRect()); // 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. @@ -607,7 +607,7 @@ bool areElementsOnSameLine(const FocusCandidate& firstCandidate, const FocusCand if (!firstCandidate.rect.intersects(secondCandidate.rect)) return false; - if (isHTMLAreaElement(firstCandidate.focusableNode) || isHTMLAreaElement(secondCandidate.focusableNode)) + if (is<HTMLAreaElement>(*firstCandidate.focusableNode) || is<HTMLAreaElement>(*secondCandidate.focusableNode)) return false; if (!firstCandidate.visibleNode->renderer()->isRenderInline() || !secondCandidate.visibleNode->renderer()->isRenderInline()) @@ -758,7 +758,7 @@ LayoutRect virtualRectForAreaElementAndDirection(HTMLAreaElement* area, FocusDir HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate& candidate) { - return candidate.isFrameOwnerElement() ? toHTMLFrameOwnerElement(candidate.visibleNode) : nullptr; -}; + return candidate.isFrameOwnerElement() ? downcast<HTMLFrameOwnerElement>(candidate.visibleNode) : nullptr; +} } // namespace WebCore |