Chromium Code Reviews| Index: Source/core/page/SpatialNavigation.cpp |
| diff --git a/Source/core/page/SpatialNavigation.cpp b/Source/core/page/SpatialNavigation.cpp |
| index e9ea56911a233c090ba660d29a03419265d2e80c..444747025047aa9148ef3b346158e105374b7ef8 100644 |
| --- a/Source/core/page/SpatialNavigation.cpp |
| +++ b/Source/core/page/SpatialNavigation.cpp |
| @@ -45,10 +45,6 @@ namespace blink { |
| using namespace HTMLNames; |
| -static RectsAlignment alignmentForRects(FocusType, const LayoutRect&, const LayoutRect&, const LayoutSize& viewSize); |
| -static bool areRectsFullyAligned(FocusType, const LayoutRect&, const LayoutRect&); |
| -static bool areRectsPartiallyAligned(FocusType, const LayoutRect&, const LayoutRect&); |
| -static bool areRectsMoreThanFullScreenApart(FocusType, const LayoutRect& curRect, const LayoutRect& targetRect, const LayoutSize& viewSize); |
| static bool isRectInDirection(FocusType, const LayoutRect&, const LayoutRect&); |
| static void deflateIfOverlapped(LayoutRect&, LayoutRect&); |
| static LayoutRect rectToAbsoluteCoordinates(LocalFrame* initialFrame, const LayoutRect&); |
| @@ -59,7 +55,6 @@ FocusCandidate::FocusCandidate(Node* node, FocusType type) |
| , focusableNode(nullptr) |
| , enclosingScrollableBox(nullptr) |
| , distance(maxDistance()) |
| - , alignment(None) |
| , isOffscreen(true) |
| , isOffscreenAfterScrolling(true) |
| { |
| @@ -92,21 +87,6 @@ bool isSpatialNavigationEnabled(const LocalFrame* frame) |
| return (frame && frame->settings() && frame->settings()->spatialNavigationEnabled()); |
| } |
| -static RectsAlignment alignmentForRects(FocusType type, const LayoutRect& curRect, const LayoutRect& targetRect, const LayoutSize& viewSize) |
| -{ |
| - // If we found a node in full alignment, but it is too far away, ignore it. |
| - if (areRectsMoreThanFullScreenApart(type, curRect, targetRect, viewSize)) |
| - return None; |
| - |
| - if (areRectsFullyAligned(type, curRect, targetRect)) |
| - return Full; |
| - |
| - if (areRectsPartiallyAligned(type, curRect, targetRect)) |
| - return Partial; |
| - |
| - return None; |
| -} |
| - |
| static inline bool isHorizontalMove(FocusType type) |
| { |
| return type == FocusTypeLeft || type == FocusTypeRight; |
| @@ -128,120 +108,6 @@ static inline LayoutUnit end(FocusType type, const LayoutRect& rect) |
| return isHorizontalMove(type) ? rect.maxY() : rect.maxX(); |
| } |
| -// This method checks if rects |a| and |b| are fully aligned either vertically or |
| -// horizontally. In general, rects whose central point falls between the top or |
| -// bottom of each other are considered fully aligned. |
| -// Rects that match this criteria are preferable target nodes in move focus changing |
| -// operations. |
| -// * a = Current focused node's rect. |
| -// * b = Focus candidate node's rect. |
| -static bool areRectsFullyAligned(FocusType type, const LayoutRect& a, const LayoutRect& b) |
| -{ |
| - LayoutUnit aStart, bStart, aEnd, bEnd; |
| - |
| - switch (type) { |
| - case FocusTypeLeft: |
| - aStart = a.x(); |
| - bEnd = b.x(); |
| - break; |
| - case FocusTypeRight: |
| - aStart = b.x(); |
| - bEnd = a.x(); |
| - break; |
| - case FocusTypeUp: |
| - aStart = a.y(); |
| - bEnd = b.y(); |
| - break; |
| - case FocusTypeDown: |
| - aStart = b.y(); |
| - bEnd = a.y(); |
| - break; |
| - default: |
| - ASSERT_NOT_REACHED(); |
| - return false; |
| - } |
| - |
| - if (aStart < bEnd) |
| - return false; |
| - |
| - aStart = start(type, a); |
| - bStart = start(type, b); |
| - |
| - LayoutUnit aMiddle = middle(type, a); |
| - LayoutUnit bMiddle = middle(type, b); |
| - |
| - aEnd = end(type, a); |
| - bEnd = end(type, b); |
| - |
| - // Picture of the totally aligned logic: |
| - // |
| - // Horizontal Vertical Horizontal Vertical |
| - // **************************** ***************************** |
| - // * _ * _ _ _ _ * * _ * _ _ * |
| - // * |_| _ * |_|_|_|_| * * _ |_| * |_|_| * |
| - // * |_|....|_| * . * * |_|....|_| * . * |
| - // * |_| |_| (1) . * * |_| |_| (2) . * |
| - // * |_| * _._ * * |_| * _ _._ _ * |
| - // * * |_|_| * * * |_|_|_|_| * |
| - // * * * * * * |
| - // **************************** ***************************** |
| - |
| - return (bMiddle >= aStart && bMiddle <= aEnd) // (1) |
| - || (aMiddle >= bStart && aMiddle <= bEnd); // (2) |
| -} |
| - |
| -// This method checks if rects |a| and |b| are partially aligned either vertically or |
| -// horizontally. In general, rects whose either of edges falls between the top or |
| -// bottom of each other are considered partially-aligned. |
| -// This is a separate set of conditions from "fully-aligned" and do not include cases |
| -// that satisfy the former. |
| -// * a = Current focused node's rect. |
| -// * b = Focus candidate node's rect. |
| -static bool areRectsPartiallyAligned(FocusType type, const LayoutRect& a, const LayoutRect& b) |
| -{ |
| - LayoutUnit aStart = start(type, a); |
| - LayoutUnit bStart = start(type, b); |
| - LayoutUnit aEnd = end(type, a); |
| - LayoutUnit bEnd = end(type, b); |
| - |
| - // Picture of the partially aligned logic: |
| - // |
| - // Horizontal Vertical |
| - // ******************************** |
| - // * _ * _ _ _ * |
| - // * |_| * |_|_|_| * |
| - // * |_|.... _ * . . * |
| - // * |_| |_| * . . * |
| - // * |_|....|_| * ._._ _ * |
| - // * |_| * |_|_|_| * |
| - // * |_| * * |
| - // * * * |
| - // ******************************** |
| - // |
| - // ... and variants of the above cases. |
| - return (bStart >= aStart && bStart <= aEnd) |
| - || (bEnd >= aStart && bEnd <= aEnd); |
| -} |
| - |
| -static bool areRectsMoreThanFullScreenApart(FocusType type, const LayoutRect& curRect, const LayoutRect& targetRect, const LayoutSize& viewSize) |
| -{ |
| - ASSERT(isRectInDirection(type, curRect, targetRect)); |
| - |
| - switch (type) { |
| - case FocusTypeLeft: |
| - return curRect.x() - targetRect.maxX() > viewSize.width(); |
| - case FocusTypeRight: |
| - return targetRect.x() - curRect.maxX() > viewSize.width(); |
| - case FocusTypeUp: |
| - return curRect.y() - targetRect.maxY() > viewSize.height(); |
| - case FocusTypeDown: |
| - return targetRect.y() - curRect.maxY() > viewSize.height(); |
| - default: |
| - ASSERT_NOT_REACHED(); |
| - return true; |
| - } |
| -} |
| - |
| // Return true if rect |a| is below |b|. False otherwise. |
| // For overlapping rects, |a| is considered to be below |b| |
| // if both edges of |a| are below the respective ones of |b| |
| @@ -644,7 +510,6 @@ void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCan |
| if (areElementsOnSameLine(current, candidate)) { |
| if ((type == FocusTypeUp && current.rect.y() > candidate.rect.y()) || (type == FocusTypeDown && candidate.rect.y() > current.rect.y())) { |
| candidate.distance = 0; |
| - candidate.alignment = Full; |
| return; |
| } |
| } |
| @@ -664,18 +529,18 @@ void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCan |
| LayoutUnit yAxis = exitPoint.y() - entryPoint.y(); |
| LayoutUnit navigationAxisDistance; |
| - LayoutUnit orthogonalAxisDistance; |
| + LayoutUnit weightedOrthogonalAxisDistance; |
| switch (type) { |
| case FocusTypeLeft: |
| case FocusTypeRight: |
| navigationAxisDistance = xAxis.abs(); |
| - orthogonalAxisDistance = yAxis.abs(); |
| + weightedOrthogonalAxisDistance = yAxis.abs() * 30; |
|
fs
2014/12/17 09:51:11
Could you try to add some form of documentation to
|
| break; |
| case FocusTypeUp: |
| case FocusTypeDown: |
| navigationAxisDistance = yAxis.abs(); |
| - orthogonalAxisDistance = xAxis.abs(); |
| + weightedOrthogonalAxisDistance = xAxis.abs() * 4; |
| break; |
| default: |
| ASSERT_NOT_REACHED(); |
| @@ -687,10 +552,7 @@ void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCan |
| double overlap = (intersectionRect.width() * intersectionRect.height()).toDouble(); |
| // Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handling |
| - candidate.distance = sqrt(euclidianDistancePow2) + navigationAxisDistance+ orthogonalAxisDistance * 2 - sqrt(overlap); |
| - |
| - LayoutSize viewSize = LayoutSize(candidate.visibleNode->document().page()->deprecatedLocalMainFrame()->view()->visibleContentRect().size()); |
| - candidate.alignment = alignmentForRects(type, currentRect, nodeRect, viewSize); |
| + candidate.distance = sqrt(euclidianDistancePow2) + navigationAxisDistance + weightedOrthogonalAxisDistance - sqrt(overlap); |
| } |
| bool canBeScrolledIntoView(FocusType type, const FocusCandidate& candidate) |