Changeset 29348 in webkit
- Timestamp:
- Jan 9, 2008 7:03:11 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r29343 r29348 1 2008-01-09 Ada Chan <adachan@apple.com> 2 3 Tests tabbing with different combinations of modifiers keys, where some 4 should advance focus and some should not. 5 6 Reviewed by Darin. 7 8 * fast/forms/tabs-with-modifiers-expected.txt: Added. 9 * fast/forms/tabs-with-modifiers.html: Copied from fast/forms/focus2.html. 10 1 11 2008-01-09 Dan Bernstein <mitz@apple.com> 2 12 -
trunk/LayoutTests/fast/forms/tabs-with-modifiers.html
r29342 r29348 1 <p>This test tabs between lots of elements, printing out the events you see along the way.</p> 2 <hr> 1 <p>This test tabs with different combinations of modifiers pressed, where some should advance focus and some should not.</p> 3 2 <div id="testDiv"></div> 4 <iframe id="testIframe" style="width: 800; height: 125; margin-top: 10px; border: 2px solid black"></iframe>5 3 <pre id="console"></pre> 6 4 … … 17 15 function description(element) 18 16 { 19 var inputType = element.getAttribute('type'); 20 if (inputType) 21 return inputType; 22 23 if (element.toString().match(/iframe/i)) 24 return "IFRAME"; 25 26 if (element.toString().match(/javascript:/i)) 27 return "ANCHOR"; 28 29 if (element.toString().match(/textarea/i)) 30 return "TEXTAREA"; 31 32 if (element.toString().match(/div/i)) 33 return "DIV"; 34 35 return element.toString(); 17 return element.getAttribute("id"); 36 18 } 37 19 38 20 function keydownListener(event) 39 21 { 40 log(" keydown event: [to]" + description(event.target) + "\n");22 log("- keydown event: " + description(event.target) + "\n"); 41 23 } 42 24 43 25 function blurListener(event) 44 26 { 45 log(" blur event: [to]" + description(event.target) + "\n");27 log("- blur event: " + description(event.target) + "\n"); 46 28 } 47 29 … … 49 31 function focusListener(event) 50 32 { 51 log(' focus event: [to]' + description(event.target) + '\n');33 log('- focus event: ' + description(event.target) + '\n'); 52 34 lastFocusedElement = event.target; 53 35 } … … 62 44 function addElements(parentElement) 63 45 { 64 var inputTypes = [ 65 "BUTTON", 66 "CHECKBOX", 67 "FILE", 68 "HIDDEN", 69 "IMAGE", 70 "ISINDEX", 71 "PASSWORD", 72 "RADIO", 73 "RANGE", 74 "RESET", 75 "SEARCH", 76 "SUBMIT", 77 "TEXT" 78 ]; 79 80 // Form elements 81 for (var i = 0; i < inputTypes.length; ++i) { //> 82 var input = parentElement.ownerDocument.createElement('input'); 83 input.type = inputTypes[i]; 84 addEventListeners(input); 85 parentElement.appendChild(input); 86 } 87 88 // Textarea 89 var textarea = parentElement.ownerDocument.createElement('textarea'); 90 addEventListeners(textarea); 91 parentElement.appendChild(textarea); 92 93 // Contenteditable 94 var div = parentElement.ownerDocument.createElement('div'); 95 div.contentEditable = true; 96 div.style.border = "1px solid black"; 97 addEventListeners(div); 98 parentElement.appendChild(div); 99 100 // Anchor 101 var anchor = parentElement.ownerDocument.createElement('a'); 102 anchor.innerHTML = "anchor"; 103 anchor.href = "javascript:"; 104 addEventListeners(anchor); 105 parentElement.appendChild(anchor); 46 // Add 3 input elements 47 var input = parentElement.ownerDocument.createElement('input'); 48 addEventListeners(input); 49 input.setAttribute("id", "a"); 50 parentElement.appendChild(input); 51 input = parentElement.ownerDocument.createElement('input'); 52 addEventListeners(input); 53 input.setAttribute("id", "b"); 54 parentElement.appendChild(input); 55 input = parentElement.ownerDocument.createElement('input'); 56 addEventListeners(input); 57 input.setAttribute("id", "c"); 58 parentElement.appendChild(input); 106 59 } 107 60 108 function dispatch OptionTab(element, shiftKey)61 function dispatchTab(element, shiftKey, metaKey, ctrlKey, altGraphKey) 109 62 { 110 63 var event = document.createEvent("KeyboardEvents"); 111 64 var tabKeyIdentifier = "U+0009"; 112 event.initKeyboardEvent("keydown", true, true, document.defaultView, tabKeyIdentifier, 0, false, true, shiftKey, false, false);65 event.initKeyboardEvent("keydown", true, true, document.defaultView, tabKeyIdentifier, 0, ctrlKey, false, shiftKey, metaKey, altGraphKey); 113 66 element.dispatchEvent(event); 114 67 } … … 118 71 var testDiv = document.getElementById('testDiv'); 119 72 addElements(testDiv); 120 121 var testIframe = document.getElementById('testIframe');122 addElements(testIframe.contentDocument.body);123 addEventListeners(testIframe);124 73 } 125 74 126 75 setup(); 127 76 128 log('PARENT DOCUMENT:\n'); 129 document.getElementsByTagName('input')[0].focus(); 130 for (var i = 0; i < 13; ++i) //> 131 dispatchOptionTab(lastFocusedElement, false); 77 var middleInput = document.getElementsByTagName('input')[1]; 132 78 133 lastFocusedElement.blur(); 79 for (i = 0; i < 2; ++i) { 80 log("resetting focus to middle input\n"); 81 middleInput.focus(); 82 log("test tab case that should advance focus\n"); 83 dispatchTab(middleInput, (i & 1) != 0, false, false, false); 84 } 85 for (i = 2; i < 16; ++i) { 86 log("resetting focus to middle input\n"); 87 middleInput.focus(); 88 log("test tab case that should not advance focus\n"); 89 dispatchTab(middleInput, (i & 1) != 0, (i & 2) != 0, (i & 4) != 0, (i & 8) != 0); 90 } 134 91 135 log('\nIFRAME DOCUMENT:\n');136 document.getElementById('testIframe').contentDocument.getElementsByTagName('input')[0].focus();137 for (var i = 0; i < 13; ++i) //>138 dispatchOptionTab(lastFocusedElement, false);139 92 </script> -
trunk/WebCore/ChangeLog
r29345 r29348 1 2008-01-09 Ada Chan <adachan@apple.com> 2 3 Tabs with ctrl, meta, or altgraph modifier key down should not advance focus. 4 5 Reviewed by Darin. 6 7 Test: fast/forms/tabs-with-modifiers.html 8 9 * page/EventHandler.cpp: 10 (WebCore::EventHandler::defaultKeyboardEventHandler): 11 (WebCore::EventHandler::defaultTabEventHandler): bail if ctrl, meta, or altgraph key is down. 12 Clean up the code a bit. 13 * page/EventHandler.h: 14 * page/FocusController.cpp: Remove the advanceFocus() that takes in a KeyboardEvent. It was 15 only called in EventHandler::defaultTabEventHandler() but we have cleaned up the code there and 16 no longer needs it. 17 * page/FocusController.h: 18 1 19 2008-01-09 Antti Koivisto <antti@apple.com> 2 20 -
trunk/WebCore/page/EventHandler.cpp
r29257 r29348 1592 1592 return; 1593 1593 if (event->keyIdentifier() == "U+0009") 1594 defaultTabEventHandler(event , false);1594 defaultTabEventHandler(event); 1595 1595 } 1596 1596 if (event->type() == keypressEvent) { … … 1848 1848 } 1849 1849 1850 void EventHandler::defaultTabEventHandler(Event* event, bool isBackTab) 1851 { 1850 void EventHandler::defaultTabEventHandler(KeyboardEvent* event) 1851 { 1852 // We should only advance focus on tabs if no special modifier keys are held down. 1853 if (event->ctrlKey() || event->metaKey() || event->altGraphKey()) 1854 return; 1855 1852 1856 Page* page = m_frame->page(); 1857 if (!page) 1858 return; 1859 if (!page->tabKeyCyclesThroughElements()) 1860 return; 1861 1862 FocusDirection focusDirection = event->shiftKey() ? FocusDirectionBackward : FocusDirectionForward; 1863 1853 1864 // Tabs can be used in design mode editing. You can still move out with back tab. 1854 if ( !page || !page->tabKeyCyclesThroughElements() || (m_frame->document()->inDesignMode() && !isBackTab))1865 if (m_frame->document()->inDesignMode() && focusDirection == FocusDirectionForward) 1855 1866 return; 1856 FocusController* focus = page->focusController(); 1857 KeyboardEvent* keyboardEvent = findKeyboardEvent(event); 1858 bool handled; 1859 if (isBackTab) 1860 handled = focus->advanceFocus(FocusDirectionBackward, keyboardEvent); 1861 else 1862 handled = focus->advanceFocus(keyboardEvent); // get direction from keyboard event 1863 if (handled) 1867 1868 if (page->focusController()->advanceFocus(focusDirection, event)) 1864 1869 event->setDefaultHandled(); 1865 1870 } -
trunk/WebCore/page/EventHandler.h
r29010 r29348 249 249 bool passWheelEventToWidget(PlatformWheelEvent&, Widget*); 250 250 251 void defaultTabEventHandler( Event*, bool isBackTab);251 void defaultTabEventHandler(KeyboardEvent*); 252 252 253 253 void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const; -
trunk/WebCore/page/FocusController.cpp
r26047 r29348 116 116 } 117 117 118 bool FocusController::advanceFocus(KeyboardEvent* event)119 {120 return advanceFocus((event && event->shiftKey()) ? FocusDirectionBackward : FocusDirectionForward, event);121 }122 123 118 bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event, bool initialFocus) 124 119 { -
trunk/WebCore/page/FocusController.h
r26047 r29348 47 47 48 48 bool setInitialFocus(FocusDirection, KeyboardEvent*); 49 bool advanceFocus(KeyboardEvent*);50 49 bool advanceFocus(FocusDirection, KeyboardEvent*, bool initialFocus = false); 51 50
Note: See TracChangeset
for help on using the changeset viewer.