Skip to content

Commit 13950c5

Browse files
stevenjbCommit bot
authored and
Commit bot
committed
Add cr-settings-radio-group wrapper
We need a cr-settings wrapper for policy indicators regardless. I think it makes snese to do any pref / selected conversion here also. BUG=521791 Review URL: https://codereview.chromium.org/1347193003 Cr-Commit-Position: refs/heads/master@{#349476}
1 parent 0c6422a commit 13950c5

File tree

9 files changed

+155
-23
lines changed

9 files changed

+155
-23
lines changed

chrome/browser/resources/settings/appearance_page/appearance_page.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<link rel="import" href="chrome://resources/polymer/v1_0/polymer/polymer.html">
2-
<link rel="import" href="chrome://md-settings/checkbox/checkbox.html">
32
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
3+
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-button/paper-radio-button.html">
4+
<link rel="import" href="chrome://md-settings/checkbox/checkbox.html">
5+
<link rel="import" href="chrome://md-settings/radio_group/radio_group.html">
46

57
<dom-module id="cr-settings-appearance-page">
68
<link rel="import" type="css"
@@ -23,16 +25,14 @@
2325
<cr-settings-checkbox pref="{{prefs.browser.show_home_button}}"
2426
i18n-values="label:showHomeButton">
2527
</cr-settings-checkbox>
26-
<div id="change-home-page-section"
27-
hidden$="[[!prefs.browser.show_home_button.value]]">
28-
<div id="change-home-page-section-container">
29-
<span id="home-page-ntp" i18n-content="homePageNtp"></span>
30-
<span id="home-page-url"></span>
31-
<a is="action-link" id="change-home-page"
32-
i18n-content="changeHomePage">
33-
</a>
34-
</div>
35-
</div>
28+
<template is="dom-if" if="{{prefs.browser.show_home_button.value}}">
29+
<cr-settings-radio-group pref="{{prefs.homepage_is_newtabpage}}">
30+
<paper-radio-button name="true"
31+
>[[i18n_.homePageNtp]]</paper-radio-button>
32+
<paper-radio-button name="false"
33+
>[[i18n_.openThisPage]]</paper-radio-button>
34+
</cr-settings-radio-group>
35+
</template>
3636
<cr-settings-checkbox pref="{{prefs.bookmark_bar.show_on_all_tabs}}"
3737
i18n-values="label:showBookmarksBar">
3838
</cr-settings-checkbox>

chrome/browser/resources/settings/appearance_page/appearance_page.js

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ Polymer({
4141
type: Object,
4242
notify: true,
4343
},
44+
45+
/**
46+
* Translated strings used in data binding.
47+
*/
48+
i18n_: {
49+
type: Object,
50+
value: function() {
51+
return {
52+
homePageNtp: loadTimeData.getString('homePageNtp'),
53+
openThisPage: loadTimeData.getString('openThisPage'),
54+
};
55+
},
56+
},
4457
},
4558

4659
setResetThemeEnabled: function(enabled) {

chrome/browser/resources/settings/compiled_resources.gyp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
'internet_page/compiled_resources.gyp:*',
1212
'languages_page/compiled_resources.gyp:*',
1313
'on_startup_page/compiled_resources.gyp:*',
14-
'prefs/compiled_resources.gyp:*'
14+
'prefs/compiled_resources.gyp:*',
15+
'radio_group/compiled_resources.gyp:*',
1516
],
1617
},
1718
]

chrome/browser/resources/settings/on_startup_page/on_startup_page.html

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/classes/iron-flex-layout.html">
33
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/neon-animatable.html">
44
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-button/paper-radio-button.html">
5-
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-group/paper-radio-group.html">
65
<link rel="import" href="chrome://md-settings/on_startup_page/startup_urls_page.html">
6+
<link rel="import" href="chrome://md-settings/radio_group/radio_group.html">
77
<link rel="import" href="chrome://md-settings/settings_page/settings_animated_pages.html">
88
<link rel="import" href="chrome://md-settings/settings_page/settings_subheader.html">
99

@@ -17,21 +17,17 @@
1717
<neon-animatable id="">
1818
<div id="locationLabel" i18n-content="onStartup"></div>
1919
<div>
20-
<paper-radio-group
21-
selected="{{prefs.session.restore_on_startup.value}}">
22-
<paper-radio-button
23-
name="[[prefValues_.OPEN_NEW_TAB]]"
20+
<cr-settings-radio-group pref="{{prefs.session.restore_on_startup}}">
21+
<paper-radio-button name="[[prefValues_.OPEN_NEW_TAB]]"
2422
i18n-content="onStartupOpenNewTab">
2523
</paper-radio-button>
26-
<paper-radio-button
27-
name="[[prefValues_.CONTINUE]]"
24+
<paper-radio-button name="[[prefValues_.CONTINUE]]"
2825
i18n-content="onStartupContinue">
2926
</paper-radio-button>
30-
<paper-radio-button
31-
name="[[prefValues_.OPEN_SPECIFIC]]"
32-
i18n-content="onStartupOpenSpecific">
27+
<paper-radio-button name="[[prefValues_.OPEN_SPECIFIC]]">
28+
<span i18n-content="onStartupOpenSpecific"></span>
3329
</paper-radio-button>
34-
</paper-radio-group>
30+
</cr-settings-radio-group>
3531
<paper-button
3632
on-tap="onSetPagesTap_" raised i18n-content="onStartupSetPages">
3733
</paper-button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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
3+
# found in the LICENSE file.
4+
{
5+
'targets': [
6+
{
7+
'target_name': 'radio_group',
8+
'variables': {
9+
'depends': [
10+
'../../../../../ui/webui/resources/js/compiled_resources.gyp:assert',
11+
],
12+
'externs': [
13+
'../../../../../third_party/closure_compiler/externs/settings_private.js'
14+
],
15+
},
16+
'includes': ['../../../../../third_party/closure_compiler/compile_js.gypi'],
17+
},
18+
],
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Copyright 2015 The Chromium Authors. All rights reserved.
2+
* Use of this source code is governed by a BSD-style license that can be
3+
* found in the LICENSE file. */
4+
5+
:host {
6+
display: block;
7+
margin-bottom: 10px;
8+
margin-top: 10px;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<link rel="import" href="chrome://resources/polymer/v1_0/polymer/polymer.html">
2+
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-group/paper-radio-group.html">
3+
<link rel="import" href="chrome://resources/polymer/v1_0/paper-radio-button/paper-radio-button.html">
4+
5+
<dom-module id="cr-settings-radio-group">
6+
<link rel="import" type="css" href="radio_group.css">
7+
<template>
8+
<div>[[label]]</div>
9+
<paper-radio-group selected="{{selected}}">
10+
<content></content>
11+
</paper-radio-group>
12+
</template>
13+
<script src="radio_group.js"></script>
14+
</dom-module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2015 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/**
6+
* @fileoverview
7+
* `cr-radio-group` wraps a radio-group and set of radio-buttons that control
8+
* a supplied preference.
9+
*
10+
* Example:
11+
* <cr-settings-radio-group pref="{{prefs.settings.foo}}"
12+
* label="Foo Options." buttons="{{fooOptionsList}}">
13+
* </cr-settings-radio-group>
14+
*
15+
* @element cr-settings-radio-group
16+
*/
17+
Polymer({
18+
is: 'cr-settings-radio-group',
19+
20+
properties: {
21+
/**
22+
* The preference object to control.
23+
* @type {chrome.settingsPrivate.PrefObject|undefined}
24+
*/
25+
pref: {
26+
type: Object,
27+
notify: true,
28+
observer: 'prefChanged_'
29+
},
30+
31+
/**
32+
* IronSelectableBehavior selected attribute
33+
*/
34+
selected: {
35+
type: String,
36+
observer: 'selectedChanged_'
37+
},
38+
},
39+
40+
/** @private */
41+
prefChanged_: function() {
42+
if (!this.pref)
43+
return;
44+
if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER ||
45+
this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
46+
this.selected = this.pref.value.toString();
47+
} else {
48+
assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST);
49+
this.selected = /** @type {string} */(this.pref.value);
50+
}
51+
},
52+
53+
/** @private */
54+
selectedChanged_: function() {
55+
if (!this.pref)
56+
return;
57+
if (this.pref.type == chrome.settingsPrivate.PrefType.NUMBER) {
58+
var n = parseInt(this.selected, 10);
59+
if (isNaN(n)) {
60+
console.error('Bad selected name for numerical pref: ' + this.selected);
61+
return;
62+
}
63+
this.set('pref.value', n);
64+
} else if (this.pref.type == chrome.settingsPrivate.PrefType.BOOLEAN) {
65+
this.set('pref.value', this.selected == 'true');
66+
} else {
67+
assert(this.pref.type != chrome.settingsPrivate.PrefType.LIST);
68+
this.set('pref.value', this.selected);
69+
}
70+
},
71+
});

chrome/browser/resources/settings/settings_resources.grd

+9
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@
213213
<structure name="IDR_SETTINGS_PRIVACY_PAGE_JS"
214214
file="privacy_page/privacy_page.js"
215215
type="chrome_html" />
216+
<structure name="IDR_SETTINGS_RADIO_GROUP_HTML"
217+
file="radio_group/radio_group.html"
218+
type="chrome_html" />
219+
<structure name="IDR_SETTINGS_RADIO_GROUP_JS"
220+
file="radio_group/radio_group.js"
221+
type="chrome_html" />
222+
<structure name="IDR_SETTINGS_RADIO_GROUP_CSS"
223+
file="radio_group/radio_group.css"
224+
type="chrome_html" />
216225
<structure name="IDR_SETTINGS_CR_SETTINGS_ROUTER_HTML"
217226
file="settings_page/settings_router.html"
218227
type="chrome_html" />

0 commit comments

Comments
 (0)