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

Side by Side Diff: LayoutTests/fast/forms/resources/picker-common.js

Issue 736883002: Implement <select> Popup Menu using PagePopup (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed tests for mac Created 5 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 window.jsTestIsAsync = true; 1 window.jsTestIsAsync = true;
2 2
3 var popupWindow = null; 3 var popupWindow = null;
4 4
5 var popupOpenCallback = null; 5 var popupOpenCallback = null;
6 6
7 function popupOpenCallbackWrapper() { 7 function popupOpenCallbackWrapper() {
8 popupWindow.removeEventListener("didOpenPicker", popupOpenCallbackWrapper); 8 popupWindow.removeEventListener("didOpenPicker", popupOpenCallbackWrapper);
9 setTimeout(popupOpenCallback, 0); 9 setTimeout(popupOpenCallback, 0);
10 } 10 }
11 11
12 function waitUntilClosing(callback) { 12 function waitUntilClosing(callback) {
13 setTimeout(callback, 1); 13 setTimeout(callback, 1);
14 } 14 }
15 15
16 function sendKey(input, keyName, ctrlKey, altKey) { 16 function sendKey(input, keyName, ctrlKey, altKey) {
17 var event = document.createEvent('KeyboardEvent'); 17 var event = document.createEvent('KeyboardEvent');
18 event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName , 0, ctrlKey, altKey); 18 event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName , 0, ctrlKey, altKey);
19 input.dispatchEvent(event); 19 input.dispatchEvent(event);
20 } 20 }
21 21
22 function openPicker(input, callback) { 22 function rootWindow() {
23 window.moveTo(); 23 var currentWindow = window;
24 input.offsetTop; // Force to lay out 24 while (currentWindow !== currentWindow.parent) {
25 if (input.type === "color") { 25 currentWindow = currentWindow.parent;
26 input.focus(); 26 }
27 eventSender.keyDown(" "); 27 return currentWindow;
28 } else { 28 }
29 sendKey(input, "Down", false, true); 29
30 function openPicker(element, callback, errorCallback) {
31 rootWindow().moveTo();
32 element.offsetTop; // Force to lay out
33 if (element.tagName === "SELECT") {
34 sendKey(element, "Down", false, true);
35 } else if (element.tagName === "INPUT") {
36 if (element.type === "color") {
37 element.focus();
38 eventSender.keyDown(" ");
39 } else {
40 sendKey(element, "Down", false, true);
41 }
30 } 42 }
31 popupWindow = window.internals.pagePopupWindow; 43 popupWindow = window.internals.pagePopupWindow;
32 if (typeof callback === "function") { 44 if (typeof callback === "function" && popupWindow)
33 popupOpenCallback = (function(callback) { 45 setPopupOpenCallback(callback);
34 // We need to move the window to the top left of available space 46 else if (typeof errorCallback === "function" && !popupWindow)
35 // because the window will move back to (0, 0) when the 47 errorCallback();
36 // ShellViewMsg_SetTestConfiguration IPC arrives.
37 window.moveTo();
38 callback();
39 }).bind(this, callback);
40 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper, false);
41 }
42 } 48 }
49
50 function clickToOpenPicker(x, y, callback, errorCallback) {
51 rootWindow().moveTo();
52 eventSender.mouseMoveTo(x, y);
53 eventSender.mouseDown();
54 eventSender.mouseUp();
55 popupWindow = window.internals.pagePopupWindow;
56 if (typeof callback === "function" && popupWindow)
57 setPopupOpenCallback(callback);
58 else if (typeof errorCallback === "function" && !popupWindow)
59 errorCallback();
60 }
61
62 function setPopupOpenCallback(callback) {
63 console.assert(popupWindow);
64 popupOpenCallback = (function(callback) {
65 // We need to move the window to the top left of available space
66 // because the window will move back to (0, 0) when the
67 // ShellViewMsg_SetTestConfiguration IPC arrives.
68 rootWindow().moveTo();
69 callback();
70 }).bind(this, callback);
71 popupWindow.addEventListener("didOpenPicker", popupOpenCallbackWrapper, fals e);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698