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