|
1 /* |
|
2 * BrowserTouchHandler |
|
3 * |
|
4 * Receives touch events from our input event capturing in input.js |
|
5 * and relays appropriate events to content. Also handles requests |
|
6 * from content for UI. |
|
7 */ |
|
8 |
|
9 const BrowserTouchHandler = { |
|
10 _debugEvents: false, |
|
11 |
|
12 init: function init() { |
|
13 // Misc. events we catch during the bubbling phase |
|
14 document.addEventListener("PopupChanged", this, false); |
|
15 document.addEventListener("CancelTouchSequence", this, false); |
|
16 |
|
17 // Messages sent from content.js |
|
18 messageManager.addMessageListener("Content:ContextMenu", this); |
|
19 messageManager.addMessageListener("Content:SelectionCaret", this); |
|
20 }, |
|
21 |
|
22 // Content forwarding the contextmenu command |
|
23 _onContentContextMenu: function _onContentContextMenu(aMessage) { |
|
24 // Note, target here is the target of the message manager message, |
|
25 // usually the browser. |
|
26 // Touch input selection handling |
|
27 if (!InputSourceHelper.isPrecise && |
|
28 !SelectionHelperUI.isActive && |
|
29 SelectionHelperUI.canHandleContextMenuMsg(aMessage)) { |
|
30 SelectionHelperUI.openEditSession(aMessage.target, |
|
31 aMessage.json.xPos, |
|
32 aMessage.json.yPos); |
|
33 return; |
|
34 } |
|
35 |
|
36 // Check to see if we have context menu item(s) that apply to what |
|
37 // was clicked on. |
|
38 let contextInfo = { name: aMessage.name, |
|
39 json: aMessage.json, |
|
40 target: aMessage.target }; |
|
41 if (ContextMenuUI.showContextMenu(contextInfo)) { |
|
42 let event = document.createEvent("Events"); |
|
43 event.initEvent("CancelTouchSequence", true, false); |
|
44 document.dispatchEvent(event); |
|
45 } else { |
|
46 // Send the MozEdgeUIGesture to input.js to |
|
47 // toggle the context ui. |
|
48 let event = document.createEvent("Events"); |
|
49 event.initEvent("MozEdgeUICompleted", true, false); |
|
50 window.dispatchEvent(event); |
|
51 } |
|
52 }, |
|
53 |
|
54 /* |
|
55 * Called when Content wants to initiate selection management |
|
56 * due to a tap in a form input. |
|
57 */ |
|
58 _onCaretSelectionStarted: function _onCaretSelectionStarted(aMessage) { |
|
59 SelectionHelperUI.attachToCaret(aMessage.target, |
|
60 aMessage.json.xPos, |
|
61 aMessage.json.yPos); |
|
62 }, |
|
63 |
|
64 /* |
|
65 * Events |
|
66 */ |
|
67 |
|
68 handleEvent: function handleEvent(aEvent) { |
|
69 // ignore content events we generate |
|
70 if (aEvent.target == document) |
|
71 return; |
|
72 |
|
73 if (this._debugEvents) |
|
74 Util.dumpLn("BrowserTouchHandler:", aEvent.type); |
|
75 |
|
76 switch (aEvent.type) { |
|
77 case "PopupChanged": |
|
78 case "CancelTouchSequence": |
|
79 if (!aEvent.detail) |
|
80 ContextMenuUI.reset(); |
|
81 break; |
|
82 } |
|
83 }, |
|
84 |
|
85 receiveMessage: function receiveMessage(aMessage) { |
|
86 if (this._debugEvents) Util.dumpLn("BrowserTouchHandler:", aMessage.name); |
|
87 switch (aMessage.name) { |
|
88 // Content forwarding the contextmenu command |
|
89 case "Content:ContextMenu": |
|
90 this._onContentContextMenu(aMessage); |
|
91 break; |
|
92 case "Content:SelectionCaret": |
|
93 this._onCaretSelectionStarted(aMessage); |
|
94 break; |
|
95 } |
|
96 }, |
|
97 }; |