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

Side by Side Diff: sky/framework/sky-radio/sky-radio.sky

Issue 836923002: Automate reflected properties in SkyElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" /> 6 <import src="/sky/framework/sky-button/sky-button.sky" as="SkyButton" />
7 7
8 <sky-element name="sky-radio"> 8 <sky-element name="sky-radio" attributes="selected:boolean, group:string">
9 <template> 9 <template>
10 <style> 10 <style>
11 :host { 11 :host {
12 display: inline-block; 12 display: inline-block;
13 -webkit-user-select: none; 13 -webkit-user-select: none;
14 width: 14px; 14 width: 14px;
15 height: 14px; 15 height: 14px;
16 border-radius: 7px; 16 border-radius: 7px;
17 border: 1px solid blue; 17 border: 1px solid blue;
18 margin: 0 5px; 18 margin: 0 5px;
(...skipping 24 matching lines...) Expand all
43 if (!controller) 43 if (!controller)
44 kControllerMap.set(scope, new RadioGroupController()); 44 kControllerMap.set(scope, new RadioGroupController());
45 return kControllerMap.get(scope); 45 return kControllerMap.get(scope);
46 } 46 }
47 constructor() { 47 constructor() {
48 this.radios = new Set(); 48 this.radios = new Set();
49 } 49 }
50 addRadio(radio) { 50 addRadio(radio) {
51 this.radios.add(radio); 51 this.radios.add(radio);
52 // If this new radio is default-selected, take selection from the group. 52 // If this new radio is default-selected, take selection from the group.
53 if (radio.selected) 53 if (radio.selected) {
54 this.takeSelectionFromGroup(radio); 54 this.takeSelectionFromGroup(radio);
55 }
abarth-chromium 2015/01/06 04:02:38 Why add the braces?
esprehn 2015/01/06 04:10:24 Woops, that was from debugging.
55 } 56 }
56 removeRadio(radio) { 57 removeRadio(radio) {
57 this.radios.remove(radio); 58 this.radios.remove(radio);
58 } 59 }
59 takeSelectionFromGroup(selectedRadio) { 60 takeSelectionFromGroup(selectedRadio) {
60 // Emtpy/null/undefined group means and isolated radio. 61 // Emtpy/null/undefined group means an isolated radio.
61 if (!selectedRadio.group) 62 if (!selectedRadio.group)
62 return; 63 return;
63 this.radios.forEach(function(radio) { 64 this.radios.forEach(function(radio) {
64 if (selectedRadio === radio) 65 if (selectedRadio === radio)
65 return; 66 return;
66 if (radio.group != selectedRadio.group) 67 if (radio.group != selectedRadio.group)
67 return; 68 return;
68 radio.setSelected(false); 69 radio.selected = false;
69 }) 70 });
70 } 71 }
71 }; 72 };
72 73
73 module.exports = class extends SkyButton { 74 module.exports = class extends SkyButton {
74 created() { 75 created() {
75 super.created(); 76 super.created();
76 this.setSelected(this.getAttribute('selected')); 77
77 this.group = this.getAttribute('group'); 78 this.controller = null;
78 79
79 this.addEventListener("mouseup", function() { 80 this.addEventListener("mouseup", function() {
80 this.setSelected(true); 81 this.selected = true;
81 }); 82 });
82 this.cachedController = null;
83 } 83 }
84 attached() { 84 attached() {
85 super.attached(); 85 super.attached();
86 this.cachedController = RadioGroupController.forRadio(this); 86 this.controller = RadioGroupController.forRadio(this);
87 this.cachedController.addRadio(this); 87 this.controller.addRadio(this);
88 } 88 }
89 detached() { 89 detached() {
90 super.detached(); 90 super.detached();
91 this.cachedController.removeRadio(this); 91 this.controller.removeRadio(this);
92 this.controller = null;
92 } 93 }
93 setSelected(selected) { 94 selectedChanged(oldValue, newValue) {
94 if (selected == this.selected) 95 if (newValue && this.controller)
95 return; 96 this.controller.takeSelectionFromGroup(this);
96 this.setAttribute('selected', selected); 97 }
97 this.selected = selected; 98 groupChanged(oldValue, newValue) {
98 if (selected && this.cachedController) 99 if (this.selected && this.controller)
99 this.cachedController.takeSelectionFromGroup(this); 100 this.controller.takeSelectionFromGroup(this);
100 } 101 }
101 }.register(); 102 }.register();
102 </script> 103 </script>
103 </sky-element> 104 </sky-element>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698