diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 12 | ||||
-rw-r--r-- | chrome/browser/browser_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/menu_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/menu_ui.h | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/network_menu_ui.cc | 18 | ||||
-rw-r--r-- | chrome/browser/chromeos/dom_ui/network_menu_ui.h | 1 | ||||
-rw-r--r-- | chrome/browser/resources/menu.css | 5 | ||||
-rw-r--r-- | chrome/browser/resources/menu.html | 1 | ||||
-rw-r--r-- | chrome/browser/resources/menu.js | 2 | ||||
-rw-r--r-- | chrome/browser/resources/network_menu.css | 25 | ||||
-rw-r--r-- | chrome/browser/resources/network_menu.js | 294 |
11 files changed, 322 insertions, 44 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 5d4495b..0964f60 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -9195,6 +9195,18 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE" desc="In settings internet options, Title of the overlay when the user is not connected and can."> Connect to network </message> + <message name="IDS_NETWORK_RECONNECT_TITLE" desc="In network menu, title of the reconnect button that allows user to retry connection on error."> + Reconnect + </message> + <message name="IDS_NETWORK_REMEMBER_THIS_NETWORK_TITLE" desc="In network menu, title of checkbox that remembers the network when checked."> + Remember this network + </message> + <message name="IDS_NETWORK_SSID_HINT" desc="In network menu, hint text for network name field."> + network name + </message> + <message name="IDS_NETWORK_PASSWORD_HINT" desc="In network menu, hint text for network password field."> + network password + </message> <message name="IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_SERVICE_NAME" desc="Cellular service name under network details in chrome:settings/internet."> Service name: diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 75bd699..ea1cc6f 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -78,6 +78,7 @@ without changes to the corresponding grd file. eter --> <include name="IDR_SLIDESHOW_HTML" file="resources\slideshow.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_TALK_APP_MANIFEST" file="resources\chat_manager\manifest.json" type="BINDATA" /> <include name="IDR_MENU_HTML" file="resources\menu.html" flattenhtml="true" type="BINDATA" /> + <include name="IDR_NETWORK_MENU_CSS" file="resources\network_menu.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_NETWORK_MENU_JS" file="resources\network_menu.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_WRENCH_MENU_JS" file="resources\wrench_menu.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_WRENCH_MENU_CSS" file="resources\wrench_menu.css" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/chromeos/dom_ui/menu_ui.cc b/chrome/browser/chromeos/dom_ui/menu_ui.cc index 19989b0..3bac97f 100644 --- a/chrome/browser/chromeos/dom_ui/menu_ui.cc +++ b/chrome/browser/chromeos/dom_ui/menu_ui.cc @@ -197,6 +197,8 @@ std::string GetMenuUIHTMLSourceFromString( strings.SetString("menu_css", menu_css.as_string()); } + menu_ui.AddLocalizedStrings(&strings); + return jstemplate_builder::GetI18nTemplateHtml(menu_template, &strings); } diff --git a/chrome/browser/chromeos/dom_ui/menu_ui.h b/chrome/browser/chromeos/dom_ui/menu_ui.h index 6127d64..58619cc 100644 --- a/chrome/browser/chromeos/dom_ui/menu_ui.h +++ b/chrome/browser/chromeos/dom_ui/menu_ui.h @@ -39,6 +39,11 @@ class MenuUI : public DOMUI { // Subclass can add extra parameters or replaces default configuration. virtual void AddCustomConfigValues(DictionaryValue* config) const {}; + // Subclass can add their values to |localized_strings| and those values + // are used by JS template builder and could be accessed via JS class + // LocalStrings. + virtual void AddLocalizedStrings(DictionaryValue* localized_strings) const {}; + // A utility function which creates a concrete html file from // template file |menu_resource_id| and |menu_css_id| for given |menu_class|. // The resource_name is the host part of DOMUI's url. diff --git a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc index cb267a1..2658e9f 100644 --- a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc +++ b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/dom_ui/network_menu_ui.h" +#include "app/l10n_util.h" #include "base/values.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -13,6 +14,7 @@ #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "grit/browser_resources.h" +#include "grit/generated_resources.h" #include "views/controls/menu/menu_2.h" namespace { @@ -76,7 +78,7 @@ NetworkMenuUI::NetworkMenuUI(TabContents* contents) chrome::kChromeUINetworkMenu, "NetworkMenu", IDR_NETWORK_MENU_JS, - -1))) { + IDR_NETWORK_MENU_CSS))) { NetworkMenuHandler* handler = new NetworkMenuHandler(); AddMessageHandler((handler)->Attach(this)); } @@ -84,6 +86,20 @@ NetworkMenuUI::NetworkMenuUI(TabContents* contents) void NetworkMenuUI::AddCustomConfigValues(DictionaryValue* config) const { } +void NetworkMenuUI::AddLocalizedStrings( + DictionaryValue* localized_strings) const { + DCHECK(localized_strings); + + localized_strings->SetString("reconnect", l10n_util::GetStringUTF16( + IDS_NETWORK_RECONNECT_TITLE)); + localized_strings->SetString("remeber_this_network", + l10n_util::GetStringUTF16(IDS_NETWORK_REMEMBER_THIS_NETWORK_TITLE)); + localized_strings->SetString("ssid_prompt", + l10n_util::GetStringUTF16(IDS_NETWORK_SSID_HINT)); + localized_strings->SetString("pass_prompt", + l10n_util::GetStringUTF16(IDS_NETWORK_PASSWORD_HINT)); +} + void NetworkMenuUI::ModelAction(const menus::MenuModel* model, const ListValue* values) { const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model); diff --git a/chrome/browser/chromeos/dom_ui/network_menu_ui.h b/chrome/browser/chromeos/dom_ui/network_menu_ui.h index 79bac9c..4560c9c 100644 --- a/chrome/browser/chromeos/dom_ui/network_menu_ui.h +++ b/chrome/browser/chromeos/dom_ui/network_menu_ui.h @@ -35,6 +35,7 @@ class NetworkMenuUI : public MenuUI { int* max_icon_width, bool* has_accel) const; virtual void AddCustomConfigValues(DictionaryValue* config) const; + virtual void AddLocalizedStrings(DictionaryValue* localized_strings) const; // A convenient factory method to create Menu2 for the network menu. static views::Menu2* CreateMenu2(menus::MenuModel* model); diff --git a/chrome/browser/resources/menu.css b/chrome/browser/resources/menu.css index 2c9b055..43ea18a 100644 --- a/chrome/browser/resources/menu.css +++ b/chrome/browser/resources/menu.css @@ -2,6 +2,7 @@ body { background: -webkit-gradient(linear, left top, left bottom, from(white), to(#EEE)); + cursor: default; margin: 0; -webkit-user-select: none; overflow: hidden; @@ -32,7 +33,7 @@ body { vertical-align: middle; } -.accelerator { +.accelerator { opacity: 0.3; -webkit-margin-start: 15px; } @@ -41,7 +42,7 @@ body { background-position: 4px center; } -.right-icon { +.right-icon { background-position: right center; } diff --git a/chrome/browser/resources/menu.html b/chrome/browser/resources/menu.html index f6acc6a..ea88119 100644 --- a/chrome/browser/resources/menu.html +++ b/chrome/browser/resources/menu.html @@ -5,6 +5,7 @@ <link rel="stylesheet" href="menu.css"> <script src="shared/js/cr.js"></script> <script src="shared/js/cr/ui.js"></script> + <script src="shared/js/local_strings.js"></script> <script src="menu.js"></script> <style i18n-content="menu_css"></style> <script i18n-content="menu_source"></script> diff --git a/chrome/browser/resources/menu.js b/chrome/browser/resources/menu.js index b5d1afe..8328db5 100644 --- a/chrome/browser/resources/menu.js +++ b/chrome/browser/resources/menu.js @@ -13,6 +13,8 @@ var SCROLL_TICK_PX = 4; // Regular expression to match/find mnemonic key. var MNEMONIC_REGEXP = /([^&]*)&(.)(.*)/; +var localStrings = new LocalStrings(); + /** * Sends 'activate' DOMUI message. * @param {number} index The index of menu item to activate in menu model. diff --git a/chrome/browser/resources/network_menu.css b/chrome/browser/resources/network_menu.css new file mode 100644 index 0000000..8ca40b0 --- /dev/null +++ b/chrome/browser/resources/network_menu.css @@ -0,0 +1,25 @@ +input:invalid { + background-color: #ff6666; +} + +.network-menu-item { + width: 100%; +} + +.network-label-icon { + -webkit-box-align: center; + display: -webkit-box; + min-height: 24px; +} + +.network-label { + -webkit-box-flex: 1; +} + +.network-icon { + border: 0; +} + +.network-status { + color: grey; +} diff --git a/chrome/browser/resources/network_menu.js b/chrome/browser/resources/network_menu.js index 2f0e767..a021b95 100644 --- a/chrome/browser/resources/network_menu.js +++ b/chrome/browser/resources/network_menu.js @@ -2,6 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + +// Network status constants. +const StatusConnected = 'connected'; +const StatusDisconnected = 'disconnected'; +const StatusConnecting = 'connecting'; +const StatusError = 'error'; + +const NetworkOther = 'other'; + /** * Sends "connect" using the 'action' DOMUI message. */ @@ -9,11 +18,204 @@ function sendConnect(index, passphrase, identity) { chrome.send('action', [ 'connect', String(index), passphrase, identity ]); } -var NetworkMenuItem = cr.ui.define('div'); +var networkMenuItemProto = (function() { + var networkMenuItem = cr.doc.createElement('div'); + networkMenuItem.innerHTML = '<div class="network-menu-item">' + + '<div class="network-label-icon">' + + '<div class="network-label"></div>' + + '<img class="network-icon hidden">' + + '</div>' + + '<div class="network-status hidden"></div>' + + '<div class="hidden"></div>' + + '</div>'; + return networkMenuItem; + })(); + +var NetworkMenuItem = cr.ui.define(function() { + return networkMenuItemProto.cloneNode(true); + }); NetworkMenuItem.prototype = { __proto__: MenuItem.prototype, + ssidEdit: null, + passwordEdit: null, + rememberCheckbox: null, + + /** + * The label element. + * @private + */ + get label_() { + return this.firstElementChild.firstElementChild.firstElementChild; + }, + + /** + * The icon element. + * @private + */ + get icon_() { + return this.label_.nextElementSibling; + }, + + /** + * The status area element. + * @private + */ + get status_() { + return this.firstElementChild.firstElementChild.nextElementSibling; + }, + + /** + * The action area container element. + * @private + */ + get action_() { + return this.status_.nextElementSibling; + }, + + /** + * Set status message. + * @param {string} message The message to display in status area. + * @private + */ + setStatus_: function(message) { + if (message) { + this.status_.textContent = message; + this.status_.classList.remove('hidden'); + } else { + this.status_.classList.add('hidden'); + } + }, + + /** + * Set status icon. + * @param {string} icon Source url for the icon image. + * @private + */ + setIcon_: function(icon) { + if (icon) { + this.icon_.src = icon; + this.icon_.classList.remove('hidden'); + } else { + this.icon_.classList.add('hidden'); + } + }, + + /** + * Handle reconnect. + * @private + */ + handleConnect_ : function(e) { + // TODO: Handle "Remember" checkbox + + if (this.ssidEdit && this.passwordEdit) { + sendConnect(this.menu_.getMenuItemIndexOf(this), + this.passwordEdit.value, this.ssidEdit.value); + } else if (this.passwordEdit) { + sendConnect(this.menu_.getMenuItemIndexOf(this), + this.passwordEdit.value, ''); + } else { + sendConnect(this.menu_.getMenuItemIndexOf(this), '', ''); + } + }, + + /** + * Handle keydown event in ssid edit. + * @private + */ + handleSsidEditKeydown_: function(e) { + if (e.target == this.ssidEdit && + e.keyIdentifier == 'Enter') { + this.passwordEdit.focus(); + } + }, + + /** + * Handle keydown event in password edit. + * @private + */ + handlePassEditKeydown_: function(e) { + if (e.target == this.passwordEdit && + e.keyIdentifier == 'Enter') { + this.handleConnect_(); + } + }, + + /** + * Returns whether action area is visible. + * @private + */ + isActionVisible_: function() { + return !this.action_.classList.contains('hidden'); + }, + + /** + * Show/hide action area. + * @private + */ + showAction_: function(show) { + var visible = this.isActionVisible_(); + if (show && !visible) { + this.action_.classList.remove('hidden'); + } else if (!show && visible) { + this.action_.classList.add('hidden'); + } + }, + + /** + * Add network name edit to action area. + * @private + */ + addSsidEdit_: function() { + this.ssidEdit = this.ownerDocument.createElement('input'); + this.ssidEdit.type = 'text'; + this.ssidEdit.placeholder = localStrings.getString('ssid_prompt'); + this.ssidEdit.pattern = '^\\S+$'; + this.ssidEdit.addEventListener('keydown', + this.handleSsidEditKeydown_.bind(this)); + + var box = this.ownerDocument.createElement('div'); + box.appendChild(this.ssidEdit); + this.action_.appendChild(box); + }, + + /** + * Add password edit to action area. + * @private + */ + addPasswordEdit_: function() { + this.passwordEdit = this.ownerDocument.createElement('input'); + this.passwordEdit.type = 'password'; + this.passwordEdit.placeholder = localStrings.getString('pass_prompt'); + this.passwordEdit.pattern = '^\\S+$'; + this.passwordEdit.addEventListener('keydown', + this.handlePassEditKeydown_.bind(this)); + + var box = this.ownerDocument.createElement('div'); + box.appendChild(this.passwordEdit); + this.action_.appendChild(box); + }, + + /** + * Add remember this network check box to action area. + * @private + */ + addRememberCheckbox_: function() { + this.rememberCheckbox = this.ownerDocument.createElement('input'); + this.rememberCheckbox.type = 'checkbox'; + this.rememberCheckbox.checked = this.attrs.remembered; + + var rememberSpan = this.ownerDocument.createElement('span'); + rememberSpan.textContent = localStrings.getString('remeber_this_network'); + + var rememberLabel = this.ownerDocument.createElement('label'); + rememberLabel.appendChild(this.rememberCheckbox); + rememberLabel.appendChild(rememberSpan); + + this.action_.appendChild(rememberLabel); + }, + /** * Internal method to initiailze the MenuItem. * @private @@ -22,43 +224,66 @@ NetworkMenuItem.prototype = { // *TODO: eliminate code duplication with menu.js // MenuItem.prototype.initMenuItem_(); var attrs = this.attrs; - this.className = 'menu-item ' + attrs.type; + this.classList.add(attrs.type); this.menu_.addHandlers(this, this); - var label = document.createElement('div'); - - label.className = 'menu-label'; //////// NetworkMenuItem specific code: // TODO: Handle specific types of network, connecting icon. - if (attrs.status && attrs.status != 'unknown') { - label.appendChild(document.createTextNode(attrs.label)); - if (attrs.status == 'connected') { - // label.appendChild(document.createElement('p')). - // appendChild(document.createTextNode(attrs.message)); - label.appendChild(document.createElement('p')). - appendChild(document.createTextNode(attrs.ip_address)); - } else if (attrs.status == 'connecting') { - label.appendChild(document.createElement('p')). - appendChild(document.createTextNode(attrs.message)); - } else { - // error - label.appendChild(document.createElement('p')). - appendChild(document.createTextNode(attrs.message)); - // TODO: error icon, reconnect button + this.label_.textContent = attrs.label; + + if (attrs.network_type == NetworkOther) { + this.addSsidEdit_(); + this.addPasswordEdit_(); + this.addRememberCheckbox_(); + } else if (attrs.status && attrs.status != 'unknown') { + if (attrs.status == StatusConnected) { + this.setStatus_(attrs.ip_address); + } else if (attrs.status == StatusConnecting) { + this.setStatus_(attrs.message); + } else if (attrs.status == StatusError) { + this.setStatus_(attrs.message); + this.setIcon_('chrome://theme/IDR_WARNING'); + + var button = this.ownerDocument.createElement('button'); + button.textContent = localStrings.getString('reconnect'); + button.addEventListener('click', this.handleConnect_.bind(this)); + this.action_.appendChild(button); + this.showAction_(true); } - // TODO: need_passphrase - // TODO: remembered - } else { - label.textContent = attrs.label; + + if (attrs.need_passphrase) { + this.addPasswordEdit_(); + } + + this.addRememberCheckbox_(); } //////// End NetworkMenuItem specifi code if (attrs.font) { - label.style.font = attrs.font; - } - this.appendChild(label); + this.label_.style.font = attrs.font; + var base_font = attrs.font.replace(/bold/, '').replace(/italic/, ''); + this.status_.style.font = base_font; + this.action_.style.font = base_font; + } }, + + /** @inheritDoc */ + activate: function() { + // Show action area for encrypted network and 'other' network. + if ((this.attrs.network_type == NetworkOther || + this.attrs.status == StatusDisconnected) && + this.attrs.need_passphrase && + !this.isActionVisible_()) { + this.showAction_(true); + } + + // No default activate if action area is visible. + if (this.isActionVisible_()) + return; + + MenuItem.prototype.activate.call(this); + } }; @@ -67,25 +292,12 @@ var NetworkMenu = cr.ui.define('div'); NetworkMenu.prototype = { __proto__: Menu.prototype, + /** @inheritDoc */ createMenuItem: function(attrs) { if (attrs.type == 'command') { return new NetworkMenuItem(); } else { return new MenuItem(); } - }, - - onKeydown_: function(event) { - switch (event.keyIdentifier) { - case 'Enter': - case 'U+0020': // space - // Temporary, for testing sendConnect() - sendConnect(this.getMenuItemIndexOf(this.current_), - "passphrase", "identity"); - break; - default: - Menu.prototype.onKeydown_.call(this, event); - break; - } } }; |