Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: Source/core/page/SpatialNavigation.cpp

Issue 797463003: spatnav: Allow focus move to a close-by not-fully-aligned node over a distant but fully-aligned nod… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/page/SpatialNavigation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) 2 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2009 Antonio Gomes <tonikitoo@webkit.org> 3 * Copyright (C) 2009 Antonio Gomes <tonikitoo@webkit.org>
4 * 4 *
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 static bool isRectInDirection(FocusType, const LayoutRect&, const LayoutRect&); 52 static bool isRectInDirection(FocusType, const LayoutRect&, const LayoutRect&);
53 static void deflateIfOverlapped(LayoutRect&, LayoutRect&); 53 static void deflateIfOverlapped(LayoutRect&, LayoutRect&);
54 static LayoutRect rectToAbsoluteCoordinates(LocalFrame* initialFrame, const Layo utRect&); 54 static LayoutRect rectToAbsoluteCoordinates(LocalFrame* initialFrame, const Layo utRect&);
55 static bool isScrollableNode(const Node*); 55 static bool isScrollableNode(const Node*);
56 56
57 FocusCandidate::FocusCandidate(Node* node, FocusType type) 57 FocusCandidate::FocusCandidate(Node* node, FocusType type)
58 : visibleNode(nullptr) 58 : visibleNode(nullptr)
59 , focusableNode(nullptr) 59 , focusableNode(nullptr)
60 , enclosingScrollableBox(nullptr) 60 , enclosingScrollableBox(nullptr)
61 , distance(maxDistance()) 61 , distance(maxDistance())
62 , alignment(None)
63 , isOffscreen(true) 62 , isOffscreen(true)
64 , isOffscreenAfterScrolling(true) 63 , isOffscreenAfterScrolling(true)
65 { 64 {
66 ASSERT(node); 65 ASSERT(node);
67 ASSERT(node->isElementNode()); 66 ASSERT(node->isElementNode());
68 67
69 if (isHTMLAreaElement(*node)) { 68 if (isHTMLAreaElement(*node)) {
70 HTMLAreaElement& area = toHTMLAreaElement(*node); 69 HTMLAreaElement& area = toHTMLAreaElement(*node);
71 HTMLImageElement* image = area.imageElement(); 70 HTMLImageElement* image = area.imageElement();
72 if (!image || !image->renderer()) 71 if (!image || !image->renderer())
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 return false; 636 return false;
638 637
639 return true; 638 return true;
640 } 639 }
641 640
642 void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCan didate& candidate) 641 void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCan didate& candidate)
643 { 642 {
644 if (areElementsOnSameLine(current, candidate)) { 643 if (areElementsOnSameLine(current, candidate)) {
645 if ((type == FocusTypeUp && current.rect.y() > candidate.rect.y()) || (t ype == FocusTypeDown && candidate.rect.y() > current.rect.y())) { 644 if ((type == FocusTypeUp && current.rect.y() > candidate.rect.y()) || (t ype == FocusTypeDown && candidate.rect.y() > current.rect.y())) {
646 candidate.distance = 0; 645 candidate.distance = 0;
647 candidate.alignment = Full;
648 return; 646 return;
649 } 647 }
650 } 648 }
651 649
652 LayoutRect nodeRect = candidate.rect; 650 LayoutRect nodeRect = candidate.rect;
653 LayoutRect currentRect = current.rect; 651 LayoutRect currentRect = current.rect;
654 deflateIfOverlapped(currentRect, nodeRect); 652 deflateIfOverlapped(currentRect, nodeRect);
655 653
656 if (!isRectInDirection(type, currentRect, nodeRect)) 654 if (!isRectInDirection(type, currentRect, nodeRect))
657 return; 655 return;
(...skipping 25 matching lines...) Expand all
683 } 681 }
684 682
685 double euclidianDistancePow2 = (xAxis * xAxis + yAxis * yAxis).toDouble(); 683 double euclidianDistancePow2 = (xAxis * xAxis + yAxis * yAxis).toDouble();
686 LayoutRect intersectionRect = intersection(currentRect, nodeRect); 684 LayoutRect intersectionRect = intersection(currentRect, nodeRect);
687 double overlap = (intersectionRect.width() * intersectionRect.height()).toDo uble(); 685 double overlap = (intersectionRect.width() * intersectionRect.height()).toDo uble();
688 686
689 // Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handlin g 687 // Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handlin g
690 candidate.distance = sqrt(euclidianDistancePow2) + navigationAxisDistance+ o rthogonalAxisDistance * 2 - sqrt(overlap); 688 candidate.distance = sqrt(euclidianDistancePow2) + navigationAxisDistance+ o rthogonalAxisDistance * 2 - sqrt(overlap);
691 689
692 LayoutSize viewSize = LayoutSize(candidate.visibleNode->document().page()->d eprecatedLocalMainFrame()->view()->visibleContentRect().size()); 690 LayoutSize viewSize = LayoutSize(candidate.visibleNode->document().page()->d eprecatedLocalMainFrame()->view()->visibleContentRect().size());
693 candidate.alignment = alignmentForRects(type, currentRect, nodeRect, viewSiz e); 691 RectsAlignment alignment = alignmentForRects(type, currentRect, nodeRect, vi ewSize);
fs 2014/12/15 11:36:09 Should the weights be applied to (one of) the comp
c.shu 2014/12/15 18:17:37 The distance calculation at L688 is based on the s
fs 2014/12/16 13:15:42 The link at L687 does not lead to a spec - it lead
692 if (alignment == None) {
693 if (type == FocusTypeLeft || type == FocusTypeRight)
694 candidate.distance *= 4;
695 else
696 candidate.distance *= 1.5;
697 } else if (alignment == Partial) {
698 if (type == FocusTypeLeft || type == FocusTypeRight)
699 candidate.distance *= 2;
700 else
701 candidate.distance *= 1.2;
702 }
694 } 703 }
695 704
696 bool canBeScrolledIntoView(FocusType type, const FocusCandidate& candidate) 705 bool canBeScrolledIntoView(FocusType type, const FocusCandidate& candidate)
697 { 706 {
698 ASSERT(candidate.visibleNode && candidate.isOffscreen); 707 ASSERT(candidate.visibleNode && candidate.isOffscreen);
699 LayoutRect candidateRect = candidate.rect; 708 LayoutRect candidateRect = candidate.rect;
700 for (Node* parentNode = candidate.visibleNode->parentNode(); parentNode; par entNode = parentNode->parentNode()) { 709 for (Node* parentNode = candidate.visibleNode->parentNode(); parentNode; par entNode = parentNode->parentNode()) {
701 LayoutRect parentRect = nodeRectInAbsoluteCoordinates(parentNode); 710 LayoutRect parentRect = nodeRectInAbsoluteCoordinates(parentNode);
702 if (!candidateRect.intersects(parentRect)) { 711 if (!candidateRect.intersects(parentRect)) {
703 if (((type == FocusTypeLeft || type == FocusTypeRight) && parentNode ->renderer()->style()->overflowX() == OHIDDEN) 712 if (((type == FocusTypeLeft || type == FocusTypeRight) && parentNode ->renderer()->style()->overflowX() == OHIDDEN)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 LayoutRect rect = virtualRectForDirection(type, rectToAbsoluteCoordinates(ar ea.document().frame(), area.computeRect(area.imageElement()->renderer())), 1); 756 LayoutRect rect = virtualRectForDirection(type, rectToAbsoluteCoordinates(ar ea.document().frame(), area.computeRect(area.imageElement()->renderer())), 1);
748 return rect; 757 return rect;
749 } 758 }
750 759
751 HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate& candidate) 760 HTMLFrameOwnerElement* frameOwnerElement(FocusCandidate& candidate)
752 { 761 {
753 return candidate.isFrameOwnerElement() ? toHTMLFrameOwnerElement(candidate.v isibleNode) : nullptr; 762 return candidate.isFrameOwnerElement() ? toHTMLFrameOwnerElement(candidate.v isibleNode) : nullptr;
754 }; 763 };
755 764
756 } // namespace blink 765 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/SpatialNavigation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698