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

Side by Side Diff: ui/webui/resources/js/cr/link_controller.js

Issue 2597013002: Run clang-format on ui/webui/resources (Closed)
Patch Set: remove cr_shared_menu.js Created 3 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * @fileoverview This file provides a class that can be used to open URLs based 6 * @fileoverview This file provides a class that can be used to open URLs based
7 * on user interactions. It ensures a consistent behavior when it comes to 7 * on user interactions. It ensures a consistent behavior when it comes to
8 * holding down Ctrl and Shift while clicking or activating the a link. 8 * holding down Ctrl and Shift while clicking or activating the a link.
9 * 9 *
10 * This depends on the {@code chrome.windows} and {@code chrome.tabs} 10 * This depends on the {@code chrome.windows} and {@code chrome.tabs}
(...skipping 28 matching lines...) Expand all
39 * Opens the link in a new window. 39 * Opens the link in a new window.
40 * 40 *
41 * On Mac, uses Command instead of Ctrl. 41 * On Mac, uses Command instead of Ctrl.
42 * For keyboard support you need to use keydown. 42 * For keyboard support you need to use keydown.
43 * 43 *
44 * @param {!LoadTimeData} localStrings The local strings object which is used 44 * @param {!LoadTimeData} localStrings The local strings object which is used
45 * to localize the warning prompt in case the user tries to open a lot of 45 * to localize the warning prompt in case the user tries to open a lot of
46 * links. 46 * links.
47 * @constructor 47 * @constructor
48 */ 48 */
49 function LinkController(localStrings) { 49 function LinkController(localStrings) { this.localStrings_ = localStrings; }
50 this.localStrings_ = localStrings;
51 }
52 50
53 LinkController.prototype = { 51 LinkController.prototype = {
54 /** 52 /**
55 * The number of links that can be opened before showing a warning confirm 53 * The number of links that can be opened before showing a warning confirm
56 * message. 54 * message.
57 */ 55 */
58 warningLimit: 15, 56 warningLimit: 15,
59 57
60 /** 58 /**
61 * The DOM window that we want to open links into in case we are opening 59 * The DOM window that we want to open links into in case we are opening
(...skipping 16 matching lines...) Expand all
78 * Open an URL from a mouse or keyboard event. 76 * Open an URL from a mouse or keyboard event.
79 * @param {string} url The URL to open. 77 * @param {string} url The URL to open.
80 * @param {!Event} e The event triggering the opening of the URL. 78 * @param {!Event} e The event triggering the opening of the URL.
81 */ 79 */
82 openUrlFromEvent: function(url, e) { 80 openUrlFromEvent: function(url, e) {
83 // We only support keydown Enter and non right click events. 81 // We only support keydown Enter and non right click events.
84 if (e.type == 'keydown' && e.key == 'Enter' || e.button != 2) { 82 if (e.type == 'keydown' && e.key == 'Enter' || e.button != 2) {
85 var kind; 83 var kind;
86 var ctrl = cr.isMac && e.metaKey || !cr.isMac && e.ctrlKey; 84 var ctrl = cr.isMac && e.metaKey || !cr.isMac && e.ctrlKey;
87 85
88 if (e.button == 1 || ctrl) // middle, ctrl or keyboard 86 if (e.button == 1 || ctrl) // middle, ctrl or keyboard
89 kind = e.shiftKey ? cr.LinkKind.FOREGROUND_TAB : 87 kind = e.shiftKey ? cr.LinkKind.FOREGROUND_TAB :
90 cr.LinkKind.BACKGROUND_TAB; 88 cr.LinkKind.BACKGROUND_TAB;
91 else // left or keyboard 89 else // left or keyboard
92 kind = e.shiftKey ? cr.LinkKind.WINDOW : cr.LinkKind.SELF; 90 kind = e.shiftKey ? cr.LinkKind.WINDOW : cr.LinkKind.SELF;
93 91
94 this.openUrls([url], kind); 92 this.openUrls([url], kind);
95 } 93 }
96 }, 94 },
97 95
98 96
99 /** 97 /**
100 * Opens a URL in a new tab, window or incognito window. 98 * Opens a URL in a new tab, window or incognito window.
101 * @param {string} url The URL to open. 99 * @param {string} url The URL to open.
102 * @param {cr.LinkKind} kind The kind of open we want to do. 100 * @param {cr.LinkKind} kind The kind of open we want to do.
103 */ 101 */
104 openUrl: function(url, kind) { 102 openUrl: function(url, kind) { this.openUrls([url], kind); },
105 this.openUrls([url], kind);
106 },
107 103
108 /** 104 /**
109 * Opens URLs in new tab, window or incognito mode. 105 * Opens URLs in new tab, window or incognito mode.
110 * @param {!Array<string>} urls The URLs to open. 106 * @param {!Array<string>} urls The URLs to open.
111 * @param {cr.LinkKind} kind The kind of open we want to do. 107 * @param {cr.LinkKind} kind The kind of open we want to do.
112 */ 108 */
113 openUrls: function(urls, kind) { 109 openUrls: function(urls, kind) {
114 if (urls.length < 1) 110 if (urls.length < 1)
115 return; 111 return;
116 112
117 if (urls.length > this.warningLimit) { 113 if (urls.length > this.warningLimit) {
118 if (!this.window.confirm(this.getWarningMessage(urls.length))) 114 if (!this.window.confirm(this.getWarningMessage(urls.length)))
119 return; 115 return;
120 } 116 }
121 117
122 // Fix '#124' URLs since opening those in a new window does not work. We 118 // Fix '#124' URLs since opening those in a new window does not work. We
123 // prepend the base URL when we encounter those. 119 // prepend the base URL when we encounter those.
124 var base = this.window.location.href.split('#')[0]; 120 var base = this.window.location.href.split('#')[0];
125 urls = urls.map(function(url) { 121 urls =
126 return url[0] == '#' ? base + url : url; 122 urls.map(function(url) { return url[0] == '#' ? base + url : url; });
127 });
128 123
129 var incognito = kind == cr.LinkKind.INCOGNITO; 124 var incognito = kind == cr.LinkKind.INCOGNITO;
130 if (kind == cr.LinkKind.WINDOW || incognito) { 125 if (kind == cr.LinkKind.WINDOW || incognito) {
131 chrome.windows.create({ 126 chrome.windows.create({url: urls, incognito: incognito});
132 url: urls, 127 } else if (
133 incognito: incognito 128 kind == cr.LinkKind.FOREGROUND_TAB ||
134 }); 129 kind == cr.LinkKind.BACKGROUND_TAB) {
135 } else if (kind == cr.LinkKind.FOREGROUND_TAB ||
136 kind == cr.LinkKind.BACKGROUND_TAB) {
137 urls.forEach(function(url, i) { 130 urls.forEach(function(url, i) {
138 chrome.tabs.create({ 131 chrome.tabs.create(
139 url: url, 132 {url: url, selected: kind == cr.LinkKind.FOREGROUND_TAB && !i});
140 selected: kind == cr.LinkKind.FOREGROUND_TAB && !i
141 });
142 }); 133 });
143 } else { 134 } else {
144 this.window.location.href = urls[0]; 135 this.window.location.href = urls[0];
145 } 136 }
146 } 137 }
147 }; 138 };
148 139
149 // Export 140 // Export
150 return { 141 return {
151 LinkController: LinkController, 142 LinkController: LinkController,
152 }; 143 };
153 }); 144 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698