OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "core/frame/FrameView.h" | 46 #include "core/frame/FrameView.h" |
47 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
48 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
49 #include "core/frame/VisualViewport.h" | 49 #include "core/frame/VisualViewport.h" |
50 #include "core/html/HTMLIFrameElement.h" | 50 #include "core/html/HTMLIFrameElement.h" |
51 #include "core/html/HTMLInputElement.h" | 51 #include "core/html/HTMLInputElement.h" |
52 #include "core/html/HTMLTextAreaElement.h" | 52 #include "core/html/HTMLTextAreaElement.h" |
53 #include "core/layout/api/LayoutViewItem.h" | 53 #include "core/layout/api/LayoutViewItem.h" |
54 #include "core/loader/DocumentLoader.h" | 54 #include "core/loader/DocumentLoader.h" |
55 #include "core/loader/FrameLoadRequest.h" | 55 #include "core/loader/FrameLoadRequest.h" |
| 56 #include "core/page/FocusController.h" |
56 #include "core/page/Page.h" | 57 #include "core/page/Page.h" |
57 #include "core/page/PrintContext.h" | 58 #include "core/page/PrintContext.h" |
58 #include "core/page/ScopedPageSuspender.h" | 59 #include "core/page/ScopedPageSuspender.h" |
59 #include "core/paint/PaintLayer.h" | 60 #include "core/paint/PaintLayer.h" |
60 #include "core/paint/PaintLayerPainter.h" | 61 #include "core/paint/PaintLayerPainter.h" |
61 #include "core/timing/DOMWindowPerformance.h" | 62 #include "core/timing/DOMWindowPerformance.h" |
62 #include "core/timing/Performance.h" | 63 #include "core/timing/Performance.h" |
63 #include "platform/KeyboardCodes.h" | 64 #include "platform/KeyboardCodes.h" |
64 #include "platform/UserGestureIndicator.h" | 65 #include "platform/UserGestureIndicator.h" |
65 #include "platform/geometry/IntRect.h" | 66 #include "platform/geometry/IntRect.h" |
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 web_view->SetInitialFocus(false); | 1623 web_view->SetInitialFocus(false); |
1623 frame->SetEditableSelectionOffsets(4, 10); | 1624 frame->SetEditableSelectionOffsets(4, 10); |
1624 EXPECT_TRUE(web_view->IsSelectionAnchorFirst()); | 1625 EXPECT_TRUE(web_view->IsSelectionAnchorFirst()); |
1625 WebRect anchor; | 1626 WebRect anchor; |
1626 WebRect focus; | 1627 WebRect focus; |
1627 web_view->SelectionBounds(anchor, focus); | 1628 web_view->SelectionBounds(anchor, focus); |
1628 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); | 1629 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); |
1629 EXPECT_FALSE(web_view->IsSelectionAnchorFirst()); | 1630 EXPECT_FALSE(web_view->IsSelectionAnchorFirst()); |
1630 } | 1631 } |
1631 | 1632 |
| 1633 TEST_P( |
| 1634 WebViewTest, |
| 1635 MoveFocusToNextFocusableElementInFormWithKeyEventListenersAndNonEditableElem
ents) { |
| 1636 const std::string test_file = |
| 1637 "advance_focus_in_form_with_key_event_listeners.html"; |
| 1638 RegisterMockedHttpURLLoad(test_file); |
| 1639 WebViewBase* web_view = |
| 1640 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 1641 web_view->SetInitialFocus(false); |
| 1642 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 1643 WebInputMethodController* active_input_method_controller = |
| 1644 web_view->MainFrameImpl() |
| 1645 ->FrameWidget() |
| 1646 ->GetActiveWebInputMethodController(); |
| 1647 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences; |
| 1648 |
| 1649 struct FocusedElement { |
| 1650 AtomicString element_id; |
| 1651 int text_input_flags; |
| 1652 } focused_elements[] = { |
| 1653 {"input1", |
| 1654 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1655 {"contenteditable1", kWebTextInputFlagHaveNextFocusableElement | |
| 1656 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1657 {"input2", default_text_input_flags | |
| 1658 kWebTextInputFlagHaveNextFocusableElement | |
| 1659 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1660 {"textarea1", default_text_input_flags | |
| 1661 kWebTextInputFlagHaveNextFocusableElement | |
| 1662 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1663 {"input3", default_text_input_flags | |
| 1664 kWebTextInputFlagHaveNextFocusableElement | |
| 1665 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1666 {"textarea2", default_text_input_flags | |
| 1667 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1668 }; |
| 1669 |
| 1670 // Forward Navigation in form1 with NEXT |
| 1671 Element* input1 = document->getElementById("input1"); |
| 1672 input1->focus(); |
| 1673 Element* current_focus = nullptr; |
| 1674 Element* next_focus = nullptr; |
| 1675 WebTextInputInfo text_input_info; |
| 1676 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1677 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1678 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1679 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1680 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1681 next_focus = |
| 1682 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1683 current_focus, kWebFocusTypeForward); |
| 1684 if (next_focus) { |
| 1685 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1686 focused_elements[i + 1].element_id); |
| 1687 } |
| 1688 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1689 } |
| 1690 // Now focus will stay on previous focus itself, because it has no next |
| 1691 // element. |
| 1692 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1693 |
| 1694 // Backward Navigation in form1 with PREVIOUS |
| 1695 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 1696 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1697 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1698 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1699 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1700 next_focus = |
| 1701 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1702 current_focus, kWebFocusTypeBackward); |
| 1703 if (next_focus) { |
| 1704 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1705 focused_elements[i - 1].element_id); |
| 1706 } |
| 1707 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1708 } |
| 1709 // Now focus will stay on previous focus itself, because it has no previous |
| 1710 // element. |
| 1711 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1712 |
| 1713 // Setting a non editable element as focus in form1, and ensuring editable |
| 1714 // navigation is fine in forward and backward. |
| 1715 Element* button1 = document->getElementById("button1"); |
| 1716 button1->focus(); |
| 1717 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1718 EXPECT_EQ(kWebTextInputFlagHaveNextFocusableElement | |
| 1719 kWebTextInputFlagHavePreviousFocusableElement, |
| 1720 text_input_info.flags); |
| 1721 next_focus = |
| 1722 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1723 button1, kWebFocusTypeForward); |
| 1724 EXPECT_EQ(next_focus->GetIdAttribute(), "contenteditable1"); |
| 1725 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1726 Element* content_editable1 = document->getElementById("contenteditable1"); |
| 1727 EXPECT_EQ(content_editable1, document->FocusedElement()); |
| 1728 button1->focus(); |
| 1729 next_focus = |
| 1730 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1731 button1, kWebFocusTypeBackward); |
| 1732 EXPECT_EQ(next_focus->GetIdAttribute(), "input1"); |
| 1733 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1734 EXPECT_EQ(input1, document->FocusedElement()); |
| 1735 |
| 1736 Element* anchor1 = document->getElementById("anchor1"); |
| 1737 anchor1->focus(); |
| 1738 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1739 // No Next/Previous element for elements outside form. |
| 1740 EXPECT_EQ(0, text_input_info.flags); |
| 1741 next_focus = |
| 1742 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1743 anchor1, kWebFocusTypeForward); |
| 1744 EXPECT_EQ(next_focus, nullptr); |
| 1745 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1746 // Since anchor is not a form control element, next/previous element will |
| 1747 // be null, hence focus will stay same as it is. |
| 1748 EXPECT_EQ(anchor1, document->FocusedElement()); |
| 1749 |
| 1750 next_focus = |
| 1751 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1752 anchor1, kWebFocusTypeBackward); |
| 1753 EXPECT_EQ(next_focus, nullptr); |
| 1754 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1755 EXPECT_EQ(anchor1, document->FocusedElement()); |
| 1756 |
| 1757 // Navigation of elements which is not part of any forms. |
| 1758 Element* text_area3 = document->getElementById("textarea3"); |
| 1759 text_area3->focus(); |
| 1760 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1761 // No Next/Previous element for elements outside form. |
| 1762 EXPECT_EQ(default_text_input_flags, text_input_info.flags); |
| 1763 next_focus = |
| 1764 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1765 text_area3, kWebFocusTypeForward); |
| 1766 EXPECT_EQ(next_focus, nullptr); |
| 1767 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1768 // No Next/Previous element to this element because it's not part of any |
| 1769 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1770 EXPECT_EQ(text_area3, document->FocusedElement()); |
| 1771 next_focus = |
| 1772 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1773 text_area3, kWebFocusTypeBackward); |
| 1774 EXPECT_EQ(next_focus, nullptr); |
| 1775 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1776 EXPECT_EQ(text_area3, document->FocusedElement()); |
| 1777 |
| 1778 // Navigation from an element which is part of a form but not an editable |
| 1779 // element. |
| 1780 Element* button2 = document->getElementById("button2"); |
| 1781 button2->focus(); |
| 1782 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1783 // No Next element for this element, due to last element outside the form. |
| 1784 EXPECT_EQ(kWebTextInputFlagHavePreviousFocusableElement, |
| 1785 text_input_info.flags); |
| 1786 next_focus = |
| 1787 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1788 button2, kWebFocusTypeForward); |
| 1789 EXPECT_EQ(next_focus, nullptr); |
| 1790 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1791 // No Next element to this element because it's not part of any form. |
| 1792 // Hence focus won't change wrt NEXT. |
| 1793 EXPECT_EQ(button2, document->FocusedElement()); |
| 1794 Element* text_area2 = document->getElementById("textarea2"); |
| 1795 next_focus = |
| 1796 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1797 button2, kWebFocusTypeBackward); |
| 1798 EXPECT_EQ(next_focus, text_area2); |
| 1799 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1800 // Since button is a form control element from form1, ensuring focus is set |
| 1801 // at correct position. |
| 1802 EXPECT_EQ(text_area2, document->FocusedElement()); |
| 1803 |
| 1804 Element* content_editable2 = document->getElementById("contenteditable2"); |
| 1805 document->SetFocusedElement( |
| 1806 content_editable2, |
| 1807 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr)); |
| 1808 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1809 // No Next/Previous element for elements outside form. |
| 1810 EXPECT_EQ(0, text_input_info.flags); |
| 1811 next_focus = |
| 1812 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1813 content_editable2, kWebFocusTypeForward); |
| 1814 EXPECT_EQ(next_focus, nullptr); |
| 1815 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1816 // No Next/Previous element to this element because it's not part of any |
| 1817 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1818 EXPECT_EQ(content_editable2, document->FocusedElement()); |
| 1819 next_focus = |
| 1820 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1821 content_editable2, kWebFocusTypeBackward); |
| 1822 EXPECT_EQ(next_focus, nullptr); |
| 1823 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1824 EXPECT_EQ(content_editable2, document->FocusedElement()); |
| 1825 |
| 1826 // Navigation of elements which is having invalid form attribute and hence |
| 1827 // not part of any forms. |
| 1828 Element* text_area4 = document->getElementById("textarea4"); |
| 1829 text_area4->focus(); |
| 1830 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1831 // No Next/Previous element for elements which is having invalid form |
| 1832 // attribute. |
| 1833 EXPECT_EQ(default_text_input_flags, text_input_info.flags); |
| 1834 next_focus = |
| 1835 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1836 text_area4, kWebFocusTypeForward); |
| 1837 EXPECT_EQ(next_focus, nullptr); |
| 1838 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1839 // No Next/Previous element to this element because it's not part of any |
| 1840 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1841 EXPECT_EQ(text_area4, document->FocusedElement()); |
| 1842 next_focus = |
| 1843 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1844 text_area4, kWebFocusTypeBackward); |
| 1845 EXPECT_EQ(next_focus, nullptr); |
| 1846 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1847 EXPECT_EQ(text_area4, document->FocusedElement()); |
| 1848 |
| 1849 web_view_helper_.Reset(); |
| 1850 } |
| 1851 |
| 1852 TEST_P( |
| 1853 WebViewTest, |
| 1854 MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements)
{ |
| 1855 const std::string test_file = |
| 1856 "advance_focus_in_form_with_key_event_listeners.html"; |
| 1857 RegisterMockedHttpURLLoad(test_file); |
| 1858 WebViewBase* web_view = |
| 1859 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 1860 web_view->SetInitialFocus(false); |
| 1861 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 1862 WebInputMethodController* active_input_method_controller = |
| 1863 web_view->MainFrameImpl() |
| 1864 ->FrameWidget() |
| 1865 ->GetActiveWebInputMethodController(); |
| 1866 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences; |
| 1867 |
| 1868 struct FocusedElement { |
| 1869 const char* element_id; |
| 1870 int text_input_flags; |
| 1871 } focused_elements[] = { |
| 1872 {"textarea5", |
| 1873 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1874 {"input4", default_text_input_flags | |
| 1875 kWebTextInputFlagHaveNextFocusableElement | |
| 1876 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1877 {"contenteditable3", kWebTextInputFlagHaveNextFocusableElement | |
| 1878 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1879 {"input5", kWebTextInputFlagHavePreviousFocusableElement}, |
| 1880 }; |
| 1881 |
| 1882 // Forward Navigation in form2 with NEXT |
| 1883 Element* text_area5 = document->getElementById("textarea5"); |
| 1884 text_area5->focus(); |
| 1885 Element* current_focus = nullptr; |
| 1886 Element* next_focus = nullptr; |
| 1887 WebTextInputInfo text_input_info; |
| 1888 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1889 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1890 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1891 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1892 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1893 next_focus = |
| 1894 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1895 current_focus, kWebFocusTypeForward); |
| 1896 if (next_focus) { |
| 1897 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1898 focused_elements[i + 1].element_id); |
| 1899 } |
| 1900 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1901 } |
| 1902 // Now focus will stay on previous focus itself, because it has no next |
| 1903 // element. |
| 1904 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1905 |
| 1906 // Backward Navigation in form1 with PREVIOUS |
| 1907 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 1908 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1909 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1910 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1911 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1912 next_focus = |
| 1913 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1914 current_focus, kWebFocusTypeBackward); |
| 1915 if (next_focus) { |
| 1916 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1917 focused_elements[i - 1].element_id); |
| 1918 } |
| 1919 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1920 } |
| 1921 // Now focus will stay on previous focus itself, because it has no previous |
| 1922 // element. |
| 1923 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1924 |
| 1925 // Setting a non editable element as focus in form1, and ensuring editable |
| 1926 // navigation is fine in forward and backward. |
| 1927 Element* anchor2 = document->getElementById("anchor2"); |
| 1928 anchor2->focus(); |
| 1929 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1930 // No Next/Previous element for non-form control elements inside form. |
| 1931 EXPECT_EQ(0, text_input_info.flags); |
| 1932 next_focus = |
| 1933 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1934 anchor2, kWebFocusTypeForward); |
| 1935 EXPECT_EQ(next_focus, nullptr); |
| 1936 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1937 // Since anchor is not a form control element, next/previous element will |
| 1938 // be null, hence focus will stay same as it is. |
| 1939 EXPECT_EQ(anchor2, document->FocusedElement()); |
| 1940 next_focus = |
| 1941 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1942 anchor2, kWebFocusTypeBackward); |
| 1943 EXPECT_EQ(next_focus, nullptr); |
| 1944 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1945 EXPECT_EQ(anchor2, document->FocusedElement()); |
| 1946 |
| 1947 web_view_helper_.Reset(); |
| 1948 } |
| 1949 |
| 1950 TEST_P(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements) { |
| 1951 const std::string test_file = |
| 1952 "advance_focus_in_form_with_tabindex_elements.html"; |
| 1953 RegisterMockedHttpURLLoad(test_file); |
| 1954 WebViewBase* web_view = |
| 1955 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 1956 web_view->SetInitialFocus(false); |
| 1957 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 1958 WebInputMethodController* active_input_method_controller = |
| 1959 web_view->MainFrameImpl() |
| 1960 ->FrameWidget() |
| 1961 ->GetActiveWebInputMethodController(); |
| 1962 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences; |
| 1963 |
| 1964 struct FocusedElement { |
| 1965 const char* element_id; |
| 1966 int text_input_flags; |
| 1967 } focused_elements[] = { |
| 1968 {"textarea6", |
| 1969 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1970 {"input5", default_text_input_flags | |
| 1971 kWebTextInputFlagHaveNextFocusableElement | |
| 1972 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1973 {"contenteditable4", kWebTextInputFlagHaveNextFocusableElement | |
| 1974 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1975 {"input6", default_text_input_flags | |
| 1976 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1977 }; |
| 1978 |
| 1979 // Forward Navigation in form with NEXT which has tabindex attribute |
| 1980 // which differs visual order. |
| 1981 Element* text_area6 = document->getElementById("textarea6"); |
| 1982 text_area6->focus(); |
| 1983 Element* current_focus = nullptr; |
| 1984 Element* next_focus = nullptr; |
| 1985 WebTextInputInfo text_input_info; |
| 1986 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1987 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1988 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1989 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1990 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1991 next_focus = |
| 1992 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1993 current_focus, kWebFocusTypeForward); |
| 1994 if (next_focus) { |
| 1995 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1996 focused_elements[i + 1].element_id); |
| 1997 } |
| 1998 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1999 } |
| 2000 // No next editable element which is focusable with proper tab index, hence |
| 2001 // staying on previous focus. |
| 2002 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2003 |
| 2004 // Backward Navigation in form with PREVIOUS which has tabindex attribute |
| 2005 // which differs visual order. |
| 2006 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 2007 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2008 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2009 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2010 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2011 next_focus = |
| 2012 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2013 current_focus, kWebFocusTypeBackward); |
| 2014 if (next_focus) { |
| 2015 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2016 focused_elements[i - 1].element_id); |
| 2017 } |
| 2018 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2019 } |
| 2020 // Now focus will stay on previous focus itself, because it has no previous |
| 2021 // element. |
| 2022 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2023 |
| 2024 // Setting an element which has invalid tabindex and ensuring it is not |
| 2025 // modifying further navigation. |
| 2026 Element* content_editable5 = document->getElementById("contenteditable5"); |
| 2027 content_editable5->focus(); |
| 2028 Element* input6 = document->getElementById("input6"); |
| 2029 next_focus = |
| 2030 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2031 content_editable5, kWebFocusTypeForward); |
| 2032 EXPECT_EQ(next_focus, input6); |
| 2033 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 2034 EXPECT_EQ(input6, document->FocusedElement()); |
| 2035 content_editable5->focus(); |
| 2036 next_focus = |
| 2037 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2038 content_editable5, kWebFocusTypeBackward); |
| 2039 EXPECT_EQ(next_focus, text_area6); |
| 2040 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2041 EXPECT_EQ(text_area6, document->FocusedElement()); |
| 2042 |
| 2043 web_view_helper_.Reset(); |
| 2044 } |
| 2045 |
| 2046 TEST_P(WebViewTest, |
| 2047 MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements) { |
| 2048 const std::string test_file = |
| 2049 "advance_focus_in_form_with_disabled_and_readonly_elements.html"; |
| 2050 RegisterMockedHttpURLLoad(test_file); |
| 2051 WebViewBase* web_view = |
| 2052 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 2053 web_view->SetInitialFocus(false); |
| 2054 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 2055 WebInputMethodController* active_input_method_controller = |
| 2056 web_view->MainFrameImpl() |
| 2057 ->FrameWidget() |
| 2058 ->GetActiveWebInputMethodController(); |
| 2059 |
| 2060 struct FocusedElement { |
| 2061 const char* element_id; |
| 2062 int text_input_flags; |
| 2063 } focused_elements[] = { |
| 2064 {"contenteditable6", kWebTextInputFlagHaveNextFocusableElement}, |
| 2065 {"contenteditable7", kWebTextInputFlagHavePreviousFocusableElement}, |
| 2066 }; |
| 2067 // Forward Navigation in form with NEXT which has has disabled/enabled |
| 2068 // elements which will gets skipped during navigation. |
| 2069 Element* content_editable6 = document->getElementById("contenteditable6"); |
| 2070 content_editable6->focus(); |
| 2071 Element* current_focus = nullptr; |
| 2072 Element* next_focus = nullptr; |
| 2073 WebTextInputInfo text_input_info; |
| 2074 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 2075 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2076 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2077 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2078 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2079 next_focus = |
| 2080 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2081 current_focus, kWebFocusTypeForward); |
| 2082 if (next_focus) { |
| 2083 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2084 focused_elements[i + 1].element_id); |
| 2085 } |
| 2086 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 2087 } |
| 2088 // No next editable element which is focusable, hence staying on previous |
| 2089 // focus. |
| 2090 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2091 |
| 2092 // Backward Navigation in form with PREVIOUS which has has |
| 2093 // disabled/enabled elements which will gets skipped during navigation. |
| 2094 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 2095 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2096 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2097 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2098 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2099 next_focus = |
| 2100 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2101 current_focus, kWebFocusTypeBackward); |
| 2102 if (next_focus) { |
| 2103 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2104 focused_elements[i - 1].element_id); |
| 2105 } |
| 2106 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2107 } |
| 2108 // Now focus will stay on previous focus itself, because it has no previous |
| 2109 // element. |
| 2110 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2111 |
| 2112 web_view_helper_.Reset(); |
| 2113 } |
| 2114 |
1632 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { | 2115 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { |
1633 RegisterMockedHttpURLLoad("200-by-300.html"); | 2116 RegisterMockedHttpURLLoad("200-by-300.html"); |
1634 WebViewBase* web_view_impl = | 2117 WebViewBase* web_view_impl = |
1635 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); | 2118 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); |
1636 web_view_impl->Resize(WebSize(200, 300)); | 2119 web_view_impl->Resize(WebSize(200, 300)); |
1637 | 2120 |
1638 float page_scale_expected = web_view_impl->PageScaleFactor(); | 2121 float page_scale_expected = web_view_impl->PageScaleFactor(); |
1639 | 2122 |
1640 WebDeviceEmulationParams params; | 2123 WebDeviceEmulationParams params; |
1641 params.screen_position = WebDeviceEmulationParams::kDesktop; | 2124 params.screen_position = WebDeviceEmulationParams::kDesktop; |
(...skipping 2706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4348 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); | 4831 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); |
4349 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 4832 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
4350 EXPECT_NE(nullptr, | 4833 EXPECT_NE(nullptr, |
4351 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); | 4834 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); |
4352 } else { | 4835 } else { |
4353 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); | 4836 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); |
4354 } | 4837 } |
4355 } | 4838 } |
4356 | 4839 |
4357 } // namespace blink | 4840 } // namespace blink |
OLD | NEW |