OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview Context Menu for Search. | 7 * @fileoverview Context Menu for Search. |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('cvox.SearchContextMenu'); | 10 goog.provide('cvox.SearchContextMenu'); |
11 | 11 |
12 goog.require('cvox.ChromeVoxKbHandler'); | 12 goog.require('cvox.ChromeVoxKbHandler'); |
13 goog.require('cvox.KeySequence'); | 13 goog.require('cvox.KeySequence'); |
14 goog.require('cvox.Search'); | 14 goog.require('cvox.Search'); |
15 goog.require('cvox.SearchTool'); | 15 goog.require('cvox.SearchTool'); |
16 | 16 |
17 /** | 17 /** |
18 * @constructor | 18 * @constructor |
19 */ | 19 */ |
20 cvox.SearchContextMenu = function() { | 20 cvox.SearchContextMenu = function() {}; |
21 }; | |
22 | 21 |
23 /* Globals */ | 22 /* Globals */ |
24 var Command = { | 23 var Command = {TOOLS: 'tools', ADS: 'ads', MAIN: 'main'}; |
25 TOOLS: 'tools', | |
26 ADS: 'ads', | |
27 MAIN: 'main' | |
28 }; | |
29 | 24 |
30 /** | 25 /** |
31 * Current focus Search is in. | 26 * Current focus Search is in. |
32 */ | 27 */ |
33 cvox.SearchContextMenu.currState = Command.MAIN; | 28 cvox.SearchContextMenu.currState = Command.MAIN; |
34 | 29 |
35 /** | 30 /** |
36 * Handles context menu events. | 31 * Handles context menu events. |
37 * @param {Event} evt Event received. | 32 * @param {Event} evt Event received. |
38 */ | 33 */ |
39 cvox.SearchContextMenu.contextMenuHandler = function(evt) { | 34 cvox.SearchContextMenu.contextMenuHandler = function(evt) { |
40 var cmd = evt.detail['customCommand']; | 35 var cmd = evt.detail['customCommand']; |
41 switch (cmd) { | 36 switch (cmd) { |
42 case Command.TOOLS: | 37 case Command.TOOLS: |
43 cvox.SearchContextMenu.focusTools(); | 38 cvox.SearchContextMenu.focusTools(); |
44 break; | 39 break; |
45 | 40 |
46 case Command.ADS: | 41 case Command.ADS: |
47 cvox.SearchContextMenu.focusAds(); | 42 cvox.SearchContextMenu.focusAds(); |
48 break; | 43 break; |
49 | 44 |
50 case Command.MAIN: | 45 case Command.MAIN: |
51 cvox.SearchContextMenu.focusMain(); | 46 cvox.SearchContextMenu.focusMain(); |
52 break; | 47 break; |
53 } | 48 } |
54 }; | 49 }; |
55 | 50 |
56 /** | 51 /** |
57 * Handles key events. | 52 * Handles key events. |
58 * @param {Event} evt Event received. | 53 * @param {Event} evt Event received. |
59 * @return {boolean} True if key was handled, false otherwise. | 54 * @return {boolean} True if key was handled, false otherwise. |
60 */ | 55 */ |
61 cvox.SearchContextMenu.keyhandler = function(evt) { | 56 cvox.SearchContextMenu.keyhandler = function(evt) { |
62 var ret = false; | 57 var ret = false; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 cvox.SearchTool.activateTools(); | 112 cvox.SearchTool.activateTools(); |
118 cvox.SearchContextMenu.currState = Command.TOOLS; | 113 cvox.SearchContextMenu.currState = Command.TOOLS; |
119 } | 114 } |
120 }; | 115 }; |
121 | 116 |
122 /** | 117 /** |
123 * Initializes the context menu. | 118 * Initializes the context menu. |
124 */ | 119 */ |
125 cvox.SearchContextMenu.init = function() { | 120 cvox.SearchContextMenu.init = function() { |
126 var ACTIONS = [ | 121 var ACTIONS = [ |
127 { desc: 'Main Results', cmd: Command.MAIN }, | 122 {desc: 'Main Results', cmd: Command.MAIN}, |
128 { desc: 'Search Tools', cmd: Command.TOOLS }, | 123 {desc: 'Search Tools', cmd: Command.TOOLS}, |
129 { desc: 'Ads', cmd: Command.ADS } | 124 {desc: 'Ads', cmd: Command.ADS} |
130 ]; | 125 ]; |
131 /* Attach ContextMenuActions. */ | 126 /* Attach ContextMenuActions. */ |
132 var body = document.querySelector('body'); | 127 var body = document.querySelector('body'); |
133 body.setAttribute('contextMenuActions', JSON.stringify(ACTIONS)); | 128 body.setAttribute('contextMenuActions', JSON.stringify(ACTIONS)); |
134 | 129 |
135 /* Listen for ContextMenu events. */ | 130 /* Listen for ContextMenu events. */ |
136 body.addEventListener('ATCustomEvent', | 131 body.addEventListener( |
137 cvox.SearchContextMenu.contextMenuHandler, true); | 132 'ATCustomEvent', cvox.SearchContextMenu.contextMenuHandler, true); |
138 | 133 |
139 window.addEventListener('keydown', cvox.SearchContextMenu.keyhandler, true); | 134 window.addEventListener('keydown', cvox.SearchContextMenu.keyhandler, true); |
140 cvox.Search.init(); | 135 cvox.Search.init(); |
141 }; | 136 }; |
OLD | NEW |