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

Side by Side Diff: third_party/WebKit/Source/core/page/FocusController.cpp

Issue 2362223002: Stop clamping tabIndex to short range (Closed)
Patch Set: Fix tabindex-clamp.html Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd. 3 * Copyright (C) 2008 Nuanti Ltd.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 Element* current = scope.currentElement(); 419 Element* current = scope.currentElement();
420 if (shouldVisit(*current) && adjustedTabIndex(*current) == tabIndex) 420 if (shouldVisit(*current) && adjustedTabIndex(*current) == tabIndex)
421 return current; 421 return current;
422 } 422 }
423 return nullptr; 423 return nullptr;
424 } 424 }
425 425
426 Element* nextElementWithGreaterTabIndex(ScopedFocusNavigation& scope, 426 Element* nextElementWithGreaterTabIndex(ScopedFocusNavigation& scope,
427 int tabIndex) { 427 int tabIndex) {
428 // Search is inclusive of start 428 // Search is inclusive of start
429 int winningTabIndex = std::numeric_limits<short>::max() + 1; 429 int winningTabIndex = std::numeric_limits<int>::max();
430 Element* winner = nullptr; 430 Element* winner = nullptr;
431 for (; scope.currentElement(); scope.moveToNext()) { 431 for (; scope.currentElement(); scope.moveToNext()) {
432 Element* current = scope.currentElement(); 432 Element* current = scope.currentElement();
433 int currentTabIndex = adjustedTabIndex(*current); 433 int currentTabIndex = adjustedTabIndex(*current);
434 if (shouldVisit(*current) && currentTabIndex > tabIndex && 434 if (shouldVisit(*current) && currentTabIndex > tabIndex) {
435 currentTabIndex < winningTabIndex) { 435 if (!winner || currentTabIndex < winningTabIndex) {
436 winner = current; 436 winner = current;
437 winningTabIndex = currentTabIndex; 437 winningTabIndex = currentTabIndex;
438 }
438 } 439 }
439 } 440 }
440 return winner; 441 return winner;
441 } 442 }
442 443
443 Element* previousElementWithLowerTabIndex(ScopedFocusNavigation& scope, 444 Element* previousElementWithLowerTabIndex(ScopedFocusNavigation& scope,
444 int tabIndex) { 445 int tabIndex) {
445 // Search is inclusive of start 446 // Search is inclusive of start
446 int winningTabIndex = 0; 447 int winningTabIndex = 0;
447 Element* winner = nullptr; 448 Element* winner = nullptr;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 if (Element* winner = 527 if (Element* winner =
527 findElementWithExactTabIndex(scope, tabIndex, WebFocusTypeBackward)) 528 findElementWithExactTabIndex(scope, tabIndex, WebFocusTypeBackward))
528 return winner; 529 return winner;
529 } 530 }
530 531
531 // There are no elements before start with the same tabindex as start, so look 532 // There are no elements before start with the same tabindex as start, so look
532 // for an element that: 533 // for an element that:
533 // 1) has the highest non-zero tabindex (that is less than start's tabindex), 534 // 1) has the highest non-zero tabindex (that is less than start's tabindex),
534 // and 535 // and
535 // 2) comes last in the scope, if there's a tie. 536 // 2) comes last in the scope, if there's a tie.
536 tabIndex = 537 tabIndex = (current && tabIndex) ? tabIndex : std::numeric_limits<int>::max();
537 (current && tabIndex) ? tabIndex : std::numeric_limits<short>::max();
538 scope.moveToLast(); 538 scope.moveToLast();
539 return previousElementWithLowerTabIndex(scope, tabIndex); 539 return previousElementWithLowerTabIndex(scope, tabIndex);
540 } 540 }
541 541
542 // Searches through the given tree scope, starting from start element, for the 542 // Searches through the given tree scope, starting from start element, for the
543 // next/previous selectable element that comes after/before start element. 543 // next/previous selectable element that comes after/before start element.
544 // The order followed is as specified in the HTML spec[1], which is elements 544 // The order followed is as specified in the HTML spec[1], which is elements
545 // with tab indexes first (from lowest to highest), and then elements without 545 // with tab indexes first (from lowest to highest), and then elements without
546 // tab indexes (in document order). The search algorithm also conforms the 546 // tab indexes (in document order). The search algorithm also conforms the
547 // Shadow DOM spec[2], which inserts sequence in a shadow tree into its host. 547 // Shadow DOM spec[2], which inserts sequence in a shadow tree into its host.
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 1411
1412 return consumed; 1412 return consumed;
1413 } 1413 }
1414 1414
1415 DEFINE_TRACE(FocusController) { 1415 DEFINE_TRACE(FocusController) {
1416 visitor->trace(m_page); 1416 visitor->trace(m_page);
1417 visitor->trace(m_focusedFrame); 1417 visitor->trace(m_focusedFrame);
1418 } 1418 }
1419 1419
1420 } // namespace blink 1420 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.cpp ('k') | third_party/WebKit/Source/core/svg/SVGAElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698