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