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

Side by Side Diff: sky/framework/elements/sky-icon.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 unified diff | Download patch
« no previous file with comments | « sky/framework/elements/sky-element.sky ('k') | sky/framework/elements/sky-ink-splash.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <import src="sky-element.sky" />
7
8 <sky-element attributes="type:string, size:number">
9 <template>
10 <img />
11 </template>
12 <script>
13 import "dart:sky";
14
15 const String kAssetBase = '/sky/assets/material-design-icons';
16
17 @Tagname('sky-icon')
18 class SkyIcon extends SkyElement {
19 Element _img;
20
21 void _setSize(int size) {
22 _img.style['height'] = '${size}px';
23 _img.style['width'] = '${size}px';
24 }
25
26 void _setSrc(String type, int size) {
27 List<String> parts = type.split('/');
28 if (parts.length < 2)
29 return;
30 String category = parts[0];
31 String subtype = parts[1];
32 _img.src = '${kAssetBase}/${category}/2x_web/ic_${subtype}_${size}dp.png';
33 }
34
35 void shadowRootReady() {
36 _img = shadowRoot.firstElementChild;
37 int size = this.size.floor();
38 _setSize(size);
39 _setSrc(type, size);
40 }
41
42 void typeChanged(String oldValue, String newValue) {
43 if (_img != null)
44 _setSrc(newValue, size.floor());
45 }
46
47 void sizeChanged(double oldValue, double newValue) {
48 if (_img != null) {
49 _setSize(newValue.floor());
50 _setSrc(type, newValue.floor());
51 }
52 }
53 }
54
55 _init(script) => register(script, SkyIcon);
56 </script>
57 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/elements/sky-element.sky ('k') | sky/framework/elements/sky-ink-splash.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698