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

Unified Diff: sky/framework/elements/sky-radio.sky

Issue 1132063007: Rationalize Dart mojo and sky package structure (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/elements/sky-menu-item.sky ('k') | sky/framework/elements/sky-scrollable.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/elements/sky-radio.sky
diff --git a/sky/framework/elements/sky-radio.sky b/sky/framework/elements/sky-radio.sky
deleted file mode 100644
index 781c4556f58664d78eebd6b087464b7f5edf84d1..0000000000000000000000000000000000000000
--- a/sky/framework/elements/sky-radio.sky
+++ /dev/null
@@ -1,112 +0,0 @@
-<!--
-// Copyright 2015 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.
--->
-<import src="sky-element.sky" />
-<import src="sky-icon.sky" />
-
-<sky-element attributes="selected:boolean, group:string">
-<template>
- <style>
- :host {
- display: inline-flex;
- -webkit-user-select: none;
- margin: 8px 16px;
- }
- </style>
- <sky-icon size="18" />
-</template>
-<script>
-import "dart:sky";
-
-final Map<Node, _RadioGroupController> _controllerMap = new Map();
-
-class _RadioGroupController {
- static _RadioGroupController forRadio(radio) {
- Node owner = radio.owner;
- return _controllerMap.putIfAbsent(owner, () =>
- new _RadioGroupController(owner));
- }
-
- final Node _scope;
- final Set<SkyRadio> _radios = new Set<SkyRadio>();
-
- _RadioGroupController(this._scope);
-
- void addRadio(SkyRadio radio) {
- _radios.add(radio);
- // If this new radio is default-selected, take selection from the group.
- if (radio.selected)
- takeSelectionFromGroup(radio);
- }
-
- void removeRadio(SkyRadio radio) {
- _radios.remove(radio);
- if (_radios.isEmpty)
- _controllerMap.remove(_scope);
- }
-
- void takeSelectionFromGroup(SkyRadio selectedRadio) {
- String group = selectedRadio.group;
- if (group == null)
- return;
- _radios.forEach((SkyRadio radio) {
- if (selectedRadio == radio)
- return;
- if (radio.group != group)
- return;
- radio.selected = false;
- });
- }
-}
-
-const String _kOnIcon = 'toggle/radio_button_on_black';
-const String _kOffIcon = 'toggle/radio_button_off_black';
-
-@Tagname('sky-radio')
-class SkyRadio extends SkyElement {
- _RadioGroupController _controller;
- SkyIcon _icon;
-
- SkyRadio() {
- addEventListener('click', _handleClick);
- }
-
- void shadowRootReady() {
- _icon = shadowRoot.querySelector('sky-icon');
- _icon.type = selected ? _kOnIcon : _kOffIcon;
- }
-
- void attached() {
- super.attached();
- _controller = _RadioGroupController.forRadio(this);
- _controller.addRadio(this);
- }
-
- void detached() {
- super.detached();
- _controller.removeRadio(this);
- _controller = null;
- }
-
- void selectedChanged(bool oldValue, bool newValue) {
- if (_icon != null)
- _icon.type = newValue ? _kOnIcon : _kOffIcon;
- if (newValue && _controller != null)
- _controller.takeSelectionFromGroup(this);
- }
-
- void groupChanged(String oldValue, String newValue) {
- if (selected && _controller != null)
- _controller.takeSelectionFromGroup(this);
- }
-
- _handleClick(_) {
- this.selected = true;
- }
-}
-
-_init(script) => register(script, SkyRadio);
-</script>
-</sky-element>
« no previous file with comments | « sky/framework/elements/sky-menu-item.sky ('k') | sky/framework/elements/sky-scrollable.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698