1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/BrowserTouchHandler.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +/* 1.5 + * BrowserTouchHandler 1.6 + * 1.7 + * Receives touch events from our input event capturing in input.js 1.8 + * and relays appropriate events to content. Also handles requests 1.9 + * from content for UI. 1.10 + */ 1.11 + 1.12 +const BrowserTouchHandler = { 1.13 + _debugEvents: false, 1.14 + 1.15 + init: function init() { 1.16 + // Misc. events we catch during the bubbling phase 1.17 + document.addEventListener("PopupChanged", this, false); 1.18 + document.addEventListener("CancelTouchSequence", this, false); 1.19 + 1.20 + // Messages sent from content.js 1.21 + messageManager.addMessageListener("Content:ContextMenu", this); 1.22 + messageManager.addMessageListener("Content:SelectionCaret", this); 1.23 + }, 1.24 + 1.25 + // Content forwarding the contextmenu command 1.26 + _onContentContextMenu: function _onContentContextMenu(aMessage) { 1.27 + // Note, target here is the target of the message manager message, 1.28 + // usually the browser. 1.29 + // Touch input selection handling 1.30 + if (!InputSourceHelper.isPrecise && 1.31 + !SelectionHelperUI.isActive && 1.32 + SelectionHelperUI.canHandleContextMenuMsg(aMessage)) { 1.33 + SelectionHelperUI.openEditSession(aMessage.target, 1.34 + aMessage.json.xPos, 1.35 + aMessage.json.yPos); 1.36 + return; 1.37 + } 1.38 + 1.39 + // Check to see if we have context menu item(s) that apply to what 1.40 + // was clicked on. 1.41 + let contextInfo = { name: aMessage.name, 1.42 + json: aMessage.json, 1.43 + target: aMessage.target }; 1.44 + if (ContextMenuUI.showContextMenu(contextInfo)) { 1.45 + let event = document.createEvent("Events"); 1.46 + event.initEvent("CancelTouchSequence", true, false); 1.47 + document.dispatchEvent(event); 1.48 + } else { 1.49 + // Send the MozEdgeUIGesture to input.js to 1.50 + // toggle the context ui. 1.51 + let event = document.createEvent("Events"); 1.52 + event.initEvent("MozEdgeUICompleted", true, false); 1.53 + window.dispatchEvent(event); 1.54 + } 1.55 + }, 1.56 + 1.57 + /* 1.58 + * Called when Content wants to initiate selection management 1.59 + * due to a tap in a form input. 1.60 + */ 1.61 + _onCaretSelectionStarted: function _onCaretSelectionStarted(aMessage) { 1.62 + SelectionHelperUI.attachToCaret(aMessage.target, 1.63 + aMessage.json.xPos, 1.64 + aMessage.json.yPos); 1.65 + }, 1.66 + 1.67 + /* 1.68 + * Events 1.69 + */ 1.70 + 1.71 + handleEvent: function handleEvent(aEvent) { 1.72 + // ignore content events we generate 1.73 + if (aEvent.target == document) 1.74 + return; 1.75 + 1.76 + if (this._debugEvents) 1.77 + Util.dumpLn("BrowserTouchHandler:", aEvent.type); 1.78 + 1.79 + switch (aEvent.type) { 1.80 + case "PopupChanged": 1.81 + case "CancelTouchSequence": 1.82 + if (!aEvent.detail) 1.83 + ContextMenuUI.reset(); 1.84 + break; 1.85 + } 1.86 + }, 1.87 + 1.88 + receiveMessage: function receiveMessage(aMessage) { 1.89 + if (this._debugEvents) Util.dumpLn("BrowserTouchHandler:", aMessage.name); 1.90 + switch (aMessage.name) { 1.91 + // Content forwarding the contextmenu command 1.92 + case "Content:ContextMenu": 1.93 + this._onContentContextMenu(aMessage); 1.94 + break; 1.95 + case "Content:SelectionCaret": 1.96 + this._onCaretSelectionStarted(aMessage); 1.97 + break; 1.98 + } 1.99 + }, 1.100 +};