diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_resources.grd | 5 | ||||
-rw-r--r-- | chrome/browser/resources/gesture_config.css | 62 | ||||
-rw-r--r-- | chrome/browser/resources/gesture_config.html | 26 | ||||
-rw-r--r-- | chrome/browser/resources/gesture_config.js | 232 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/webui/gesture_config_ui.cc | 78 | ||||
-rw-r--r-- | chrome/browser/ui/webui/gesture_config_ui.h | 40 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 14 | ||||
-rw-r--r-- | chrome/common/url_constants.cc | 5 | ||||
-rw-r--r-- | chrome/common/url_constants.h | 5 |
10 files changed, 473 insertions, 3 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 45fb7d1..e2d8b8c 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -205,6 +205,11 @@ <if expr="pp_ifdef('chromeos') and pp_ifdef('_google_chrome')"> <include name="IDR_HELP_MANIFEST" file="resources\help_app\manifest.json" type="BINDATA" /> </if> + <if expr="pp_ifdef('use_aura')"> + <include name="IDR_GESTURE_CONFIG_CSS" file="resources\gesture_config.css" type="BINDATA" /> + <include name="IDR_GESTURE_CONFIG_HTML" file="resources\gesture_config.html" type="BINDATA" /> + <include name="IDR_GESTURE_CONFIG_JS" file="resources\gesture_config.js" type="BINDATA" /> + </if> </includes> </release> </grit> diff --git a/chrome/browser/resources/gesture_config.css b/chrome/browser/resources/gesture_config.css new file mode 100644 index 0000000..38df85c --- /dev/null +++ b/chrome/browser/resources/gesture_config.css @@ -0,0 +1,62 @@ +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + +body { + font-family: 'Chrome Droid Sans', 'Droid Sans Fallback', sans-serif; + font-size: 12px; +} + +button { + background-image: -webkit-linear-gradient(#e7e7e7, #e7e7e7 38%, #d7d7d7); + border: 1px solid rgba(0, 0, 0, 0.25); + border-radius: 2px; + color: #444; + float: right; + margin-top: 15px; + min-height: 2em; + min-width: 7em; + padding-left: 10px; + padding-right: 10px; +} + +.buttons-pane { + width: 90%; +} + +form { + width: 610px; +} + +h2 { + color: rgb(48, 57, 66); + font-size: 1.3em; + font-weight: normal; +} + +input { + border: solid 1px rgb(170, 207, 228); + float: left; + margin: 2px 0 8px 10px; + padding: 4px 2px; + text-align: right; + width: 110px; +} + +label { + color: black; + float: left; + font-size: 16px; + font-weight: normal; + padding-top: 4px; + text-align: right; + width: 370px; +} + +.row-units { + float: left; + margin-left: 7px; + padding-top: 7px; + text-align: left; + width: 100px; +} diff --git a/chrome/browser/resources/gesture_config.html b/chrome/browser/resources/gesture_config.html new file mode 100644 index 0000000..86ba463 --- /dev/null +++ b/chrome/browser/resources/gesture_config.html @@ -0,0 +1,26 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Gesture Preferences</title> + <link rel="stylesheet" href="gesture_config.css"> + <script src="gesture_config.js"></script> +</head> +<body> +<h2>Gesture Preferences</h2> +<hr> +<form> + <div id="gesture-form"></div> + <div class="buttons-pane"> + <button id="reset-button">Reset</button> + </div> +</form> +<div hidden> + <div id="gesture-form-row" class="row"> + <label class="row-label"></label> + <input class="row-input" type="number" size="20"> + <div class="row-units"></div> + </div> +</div> +</body> +</html> diff --git a/chrome/browser/resources/gesture_config.js b/chrome/browser/resources/gesture_config.js new file mode 100644 index 0000000..69bb9f8 --- /dev/null +++ b/chrome/browser/resources/gesture_config.js @@ -0,0 +1,232 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Redefine '$' here rather than including 'cr.js', since this is +// the only function needed. This allows this file to be loaded +// in a browser directly for layout and some testing purposes. +var $ = function(id) { return document.getElementById(id); }; + +/** + * WebUI for configuring gesture.* preference values used by + * Chrome's gesture recognition system. + */ +var gesture_config = (function() { + 'use strict'; + + /** Common prefix of gesture preferences. **/ + /** @const */ var GESTURE_PREFIX = 'gesture.'; + + /** List of fields used to dynamically build form. **/ + var FIELDS = [ + { + key: 'long_press_time_in_seconds', + label: 'Long Press Time', + units: 'seconds', + default: 1.0 + }, + { + key: 'max_seconds_between_double_click', + label: 'Maximum Double Click Interval', + units: 'seconds', + step: 0.1, + default: 0.7 + }, + { + key: 'max_separation_for_gesture_touches_in_pixels', + label: 'Maximum Separation for Gesture Touches', + units: 'pixels', + default: 150 + }, + { + key: 'max_swipe_deviation_ratio', + label: 'Maximum Swipe Deviation', + units: '', + default: 3 + }, + { + key: 'max_touch_down_duration_in_seconds_for_click', + label: 'Maximum Touch-Down Duration for Click', + units: 'seconds', + step: 0.1, + default: 0.8 + }, + { + key: 'max_touch_move_in_pixels_for_click', + label: 'Maximum Touch-Move for Click', + units: 'pixels', + default: 20 + }, + { + key: 'min_distance_for_pinch_scroll_in_pixels', + label: 'Minimum Distance for Pinch Scroll', + units: 'pixels', + default: 20 + }, + { + key: 'min_flick_speed_squared', + label: 'Minimum Flick Speed Squared', + units: '(pixels/sec.)<sup>2</sup>', + default: 550 * 550 + }, + { + key: 'min_pinch_update_distance_in_pixels', + label: 'Minimum Pinch Update Distance', + units: 'pixels', + default: 5 + }, + { + key: 'min_rail_break_velocity', + label: 'Minimum Rail-Break Velocity', + units: 'pixels/sec.', + default: 200 + }, + { + key: 'min_scroll_delta_squared', + label: 'Minimum Scroll Delta Squared', + units: '', + default: 5 * 5 + }, + { + key: 'min_swipe_speed', + label: 'Minimum Swipe Speed', + units: 'pixels/sec.', + default: 20 + }, + { + key: 'min_touch_down_duration_in_seconds_for_click', + label: 'Minimum Touch-Down Duration for Click', + units: 'seconds', + step: 0.01, + default: 0.01 + }, + { + key: 'points_buffered_for_velocity', + label: 'Points Buffered for Velocity', + units: '', + step: 1, + default: 3 + }, + { + key: 'rail_break_proportion', + label: 'Rail-Break Proportion', + units: '%', + default: 15 + }, + { + key: 'rail_start_proportion', + label: 'Rail-Start Proportion', + units: '%', + default: 2 + } + ]; + + /** + * Dynamically builds web-form based on FIELDS list. + * @return {string} The form's HTML. + */ + function buildForm() { + var buf = []; + + for (var i = 0; i < FIELDS.length; i++) { + var field = FIELDS[i]; + + var row = $('gesture-form-row').cloneNode(true); + var label = row.querySelector('.row-label'); + var input = row.querySelector('.row-input'); + var units = row.querySelector('.row-units'); + + row.id = ''; + label.setAttribute('for', field.key); + label.textContent = field.label; + input.id = field.key; + input.min = field.min || 0; + input.title = "Default Value: " + field.default; + if (field.max) input.max = field.max; + if (field.step) input.step = field.step; + + $('gesture-form').appendChild(row); + if (field.units) + units.innerHTML = field.units; + } + } + + /** + * Initialize the form by adding 'onChange' listeners to all fields. + */ + function initForm() { + for (var i = 0; i < FIELDS.length; i++) { + var field = FIELDS[i]; + $(field.key).onchange = (function(key) { + setPreferenceValue(key, $(key).value); + }).bind(null, field.key); + } + } + + /** + * Request a preference setting's value. + * This method is asynchronous; the result is provided by a call to + * getPreferenceValueResult. + * @param {string} prefName The name of the preference value being requested. + */ + function getPreferenceValue(prefName) { + chrome.send('getPreferenceValue', [GESTURE_PREFIX + prefName]); + } + + /** + * Handle callback from call to getPreferenceValue. + * @param {string} prefName The name of the requested preference value. + * @param {value} value The current value associated with prefName. + */ + function getPreferenceValueResult(prefName, value) { + prefName = prefName.substring(prefName.indexOf('.') + 1); + $(prefName).value = value; + } + + /** + * Set a preference setting's value. + * @param {string} prefName The name of the preference value being set. + * @param {value} value The value to be associated with prefName. + */ + function setPreferenceValue(prefName, value) { + chrome.send( + 'setPreferenceValue', + [GESTURE_PREFIX + prefName, parseFloat(value)]); + } + + /** + * Handle processing of "Reset" button. + * Causes off form values to be updated based on current preference values. + */ + function onReset() { + for (var i = 0; i < FIELDS.length; i++) { + var field = FIELDS[i]; + $(field.key).value = field.default; + setPreferenceValue(field.key, field.default); + } + return false; + } + + function loadForm() { + for (var i = 0; i < FIELDS.length; i++) + getPreferenceValue(FIELDS[i].key); + } + + /** + * Build and initialize the gesture configuration form. + */ + function initialize() { + buildForm(); + loadForm(); + initForm(); + + $('reset-button').onclick = onReset.bind(this); + } + + return { + initialize: initialize, + getPreferenceValueResult: getPreferenceValueResult + }; +})(); + +document.addEventListener('DOMContentLoaded', gesture_config.initialize); diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index f004803..e1764bd 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -70,6 +70,10 @@ #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" #endif +#if defined(USE_AURA) +#include "chrome/browser/ui/webui/gesture_config_ui.h" +#endif + #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" #endif @@ -290,6 +294,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, } #endif +#if defined(USE_AURA) + if (url.host() == chrome::kChromeUIGestureConfigHost) + return &NewWebUI<GestureConfigUI>; +#endif + #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) if (url.host() == chrome::kChromeUISyncPromoHost) { // If the sync promo page is enabled then use the sync promo WebUI otherwise diff --git a/chrome/browser/ui/webui/gesture_config_ui.cc b/chrome/browser/ui/webui/gesture_config_ui.cc new file mode 100644 index 0000000..806f7a0 --- /dev/null +++ b/chrome/browser/ui/webui/gesture_config_ui.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/gesture_config_ui.h" + +#include "base/values.h" +#include "base/bind.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" +#include "chrome/common/url_constants.h" +#include "content/public/browser/web_ui.h" +#include "grit/browser_resources.h" +#include "grit/generated_resources.h" + +/** + * WebUI for configuring 'gesture.*' preference values used by + * Chrome's gesture recognition system. + */ +GestureConfigUI::GestureConfigUI(content::WebUI* web_ui) + : content::WebUIController(web_ui) { + // Set up the chrome://gesture-config source. + ChromeWebUIDataSource* html_source = + new ChromeWebUIDataSource(chrome::kChromeUIGestureConfigHost); + + // Register callback handlers. + web_ui->RegisterMessageCallback( + "getPreferenceValue", + base::Bind(&GestureConfigUI::GetPreferenceValue, + base::Unretained(this))); + web_ui->RegisterMessageCallback( + "setPreferenceValue", + base::Bind(&GestureConfigUI::SetPreferenceValue, + base::Unretained(this))); + + // Add required resources. + html_source->add_resource_path("gesture_config.css", IDR_GESTURE_CONFIG_CSS); + html_source->add_resource_path("gesture_config.js", IDR_GESTURE_CONFIG_JS); + html_source->set_default_resource(IDR_GESTURE_CONFIG_HTML); + + Profile* profile = Profile::FromWebUI(web_ui); + ChromeURLDataManager::AddDataSource(profile, html_source); +} + +GestureConfigUI::~GestureConfigUI() { +} + +void GestureConfigUI::GetPreferenceValue(const base::ListValue* args) { + std::string pref_name; + + if (!args->GetString(0, &pref_name)) return; + + Profile* profile = Profile::FromWebUI(web_ui()); + PrefService* prefs = profile->GetPrefs(); + + base::StringValue arg1(pref_name); + base::FundamentalValue arg2(prefs->GetDouble(pref_name.c_str())); + + web_ui()->CallJavascriptFunction( + "gesture_config.getPreferenceValueResult", + arg1, + arg2); +} + +void GestureConfigUI::SetPreferenceValue(const base::ListValue* args) { + std::string pref_name; + double value; + + if (!args->GetString(0, &pref_name) || !args->GetDouble(1, &value)) return; + + Profile* profile = Profile::FromWebUI(web_ui()); + PrefService* prefs = profile->GetPrefs(); + + prefs->SetDouble(pref_name.c_str(), value); +} + diff --git a/chrome/browser/ui/webui/gesture_config_ui.h b/chrome/browser/ui/webui/gesture_config_ui.h new file mode 100644 index 0000000..df70949 --- /dev/null +++ b/chrome/browser/ui/webui/gesture_config_ui.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_GESTURE_CONFIG_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_GESTURE_CONFIG_UI_H_ +#pragma once + +#include "content/public/browser/web_ui_controller.h" + +namespace base { + class ListValue; +} // namespace base + +// The WebUI for 'chrome://gesture'. +class GestureConfigUI : public content::WebUIController { + public: + // Constructs a new GestureConfig for the specified |web_ui|. + explicit GestureConfigUI(content::WebUI* web_ui); + virtual ~GestureConfigUI(); + + private: + /** + * Request a preference setting's value. + * This method is asynchronous; the result is provided by a call to + * the JS method 'gesture_config.getPreferenceValueResult'. + */ + void GetPreferenceValue(const base::ListValue* args); + + /** + * Set a preference setting's value. + * Two parameters are provided in a JS list: prefName and value, the + * key of the preference value to be set, and the value it's to be set to. + */ + void SetPreferenceValue(const base::ListValue* args); + + DISALLOW_COPY_AND_ASSIGN(GestureConfigUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_GESTURE_CONFIG_UI_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8ba0424..fa3d4fd 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3734,8 +3734,6 @@ 'browser/ui/webui/about_ui.h', 'browser/ui/webui/bookmarks_ui.cc', 'browser/ui/webui/bookmarks_ui.h', - 'browser/ui/webui/feedback_ui.cc', - 'browser/ui/webui/feedback_ui.h', 'browser/ui/webui/certificate_viewer_webui.cc', 'browser/ui/webui/certificate_viewer_webui.h', 'browser/ui/webui/certificate_viewer_ui.cc', @@ -3820,6 +3818,8 @@ 'browser/ui/webui/extensions/pack_extension_handler.h', 'browser/ui/webui/favicon_source.cc', 'browser/ui/webui/favicon_source.h', + 'browser/ui/webui/feedback_ui.cc', + 'browser/ui/webui/feedback_ui.h', 'browser/ui/webui/fileicon_source.cc', 'browser/ui/webui/fileicon_source.h', 'browser/ui/webui/flags_ui.cc', @@ -3828,6 +3828,8 @@ 'browser/ui/webui/flash_ui.h', 'browser/ui/webui/generic_handler.cc', 'browser/ui/webui/generic_handler.h', + 'browser/ui/webui/gesture_config_ui.cc', + 'browser/ui/webui/gesture_config_ui.h', 'browser/ui/webui/gpu_internals_ui.cc', 'browser/ui/webui/gpu_internals_ui.h', 'browser/ui/webui/help/help_handler.cc', @@ -4585,6 +4587,12 @@ }], ], }], + ['use_aura==0', { + 'sources/': [ + ['exclude', '^browser/ui/webui/gesture_config_ui.cc'], + ['exclude', '^browser/ui/webui/gesture_config_ui.h'] + ], + }], ['use_nss==1', { 'sources': [ 'third_party/mozilla_security_manager/nsNSSCertHelper.cpp', @@ -5022,7 +5030,7 @@ # Exclude all of views. ['exclude', '^browser/ui/views/'], ['exclude', '^browser/ui/webui/tab_modal_confirm_dialog_webui.cc'], - ['exclude', '^browser/ui/webui/tab_modal_confirm_dialog_webui.h'], + ['exclude', '^browser/ui/webui/tab_modal_confirm_dialog_webui.h'] ] }], # Build Aura on desktop linux diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index c78c4fd..0812fc6 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -105,6 +105,11 @@ const char kChromeUITransparencyURL[] = "chrome://transparency/"; const char kChromeUIFileManagerURL[] = "chrome://files/"; #endif +#if defined(USE_AURA) +const char kChromeUIGestureConfigURL[] = "chrome://gesture/"; +const char kChromeUIGestureConfigHost[] = "gesture"; +#endif + #if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA) const char kChromeUICollectedCookiesURL[] = "chrome://collected-cookies/"; const char kChromeUIHttpAuthURL[] = "chrome://http-auth/"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index be07411..c49291e 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -99,6 +99,11 @@ extern const char kChromeUITransparencyURL[]; extern const char kChromeUIFileManagerURL[]; #endif +#if defined(USE_AURA) +extern const char kChromeUIGestureConfigURL[]; +extern const char kChromeUIGestureConfigHost[]; +#endif + #if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA) extern const char kChromeUICollectedCookiesURL[]; extern const char kChromeUIHttpAuthURL[]; |