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

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 1964493002: MD Downloads: use custom iconset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CrIconsCrOS
Patch Set: rebase Created 4 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 | « no previous file | chrome/browser/resources/md_downloads/icons.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Assertion support. 6 * @fileoverview Assertion support.
7 */ 7 */
8 8
9 /** 9 /**
10 * Verify |condition| is truthy and return |condition| if so. 10 * Verify |condition| is truthy and return |condition| if so.
(...skipping 4662 matching lines...) Expand 10 before | Expand all | Expand 10 after
4673 this._img.style.height = '100%'; 4673 this._img.style.height = '100%';
4674 this._img.draggable = false; 4674 this._img.draggable = false;
4675 } 4675 }
4676 this._img.src = this.src; 4676 this._img.src = this.src;
4677 Polymer.dom(this.root).appendChild(this._img); 4677 Polymer.dom(this.root).appendChild(this._img);
4678 } 4678 }
4679 } 4679 }
4680 4680
4681 }); 4681 });
4682 /** 4682 /**
4683 * The `iron-iconset-svg` element allows users to define their own icon sets
4684 * that contain svg icons. The svg icon elements should be children of the
4685 * `iron-iconset-svg` element. Multiple icons should be given distinct id's.
4686 *
4687 * Using svg elements to create icons has a few advantages over traditional
4688 * bitmap graphics like jpg or png. Icons that use svg are vector based so
4689 * they are resolution independent and should look good on any device. They
4690 * are stylable via css. Icons can be themed, colorized, and even animated.
4691 *
4692 * Example:
4693 *
4694 * <iron-iconset-svg name="my-svg-icons" size="24">
4695 * <svg>
4696 * <defs>
4697 * <g id="shape">
4698 * <rect x="12" y="0" width="12" height="24" />
4699 * <circle cx="12" cy="12" r="12" />
4700 * </g>
4701 * </defs>
4702 * </svg>
4703 * </iron-iconset-svg>
4704 *
4705 * This will automatically register the icon set "my-svg-icons" to the iconset
4706 * database. To use these icons from within another element, make a
4707 * `iron-iconset` element and call the `byId` method
4708 * to retrieve a given iconset. To apply a particular icon inside an
4709 * element use the `applyIcon` method. For example:
4710 *
4711 * iconset.applyIcon(iconNode, 'car');
4712 *
4713 * @element iron-iconset-svg
4714 * @demo demo/index.html
4715 * @implements {Polymer.Iconset}
4716 */
4717 Polymer({
4718 is: 'iron-iconset-svg',
4719
4720 properties: {
4721
4722 /**
4723 * The name of the iconset.
4724 */
4725 name: {
4726 type: String,
4727 observer: '_nameChanged'
4728 },
4729
4730 /**
4731 * The size of an individual icon. Note that icons must be square.
4732 */
4733 size: {
4734 type: Number,
4735 value: 24
4736 }
4737
4738 },
4739
4740 attached: function() {
4741 this.style.display = 'none';
4742 },
4743
4744 /**
4745 * Construct an array of all icon names in this iconset.
4746 *
4747 * @return {!Array} Array of icon names.
4748 */
4749 getIconNames: function() {
4750 this._icons = this._createIconMap();
4751 return Object.keys(this._icons).map(function(n) {
4752 return this.name + ':' + n;
4753 }, this);
4754 },
4755
4756 /**
4757 * Applies an icon to the given element.
4758 *
4759 * An svg icon is prepended to the element's shadowRoot if it exists,
4760 * otherwise to the element itself.
4761 *
4762 * @method applyIcon
4763 * @param {Element} element Element to which the icon is applied.
4764 * @param {string} iconName Name of the icon to apply.
4765 * @return {?Element} The svg element which renders the icon.
4766 */
4767 applyIcon: function(element, iconName) {
4768 // insert svg element into shadow root, if it exists
4769 element = element.root || element;
4770 // Remove old svg element
4771 this.removeIcon(element);
4772 // install new svg element
4773 var svg = this._cloneIcon(iconName);
4774 if (svg) {
4775 var pde = Polymer.dom(element);
4776 pde.insertBefore(svg, pde.childNodes[0]);
4777 return element._svgIcon = svg;
4778 }
4779 return null;
4780 },
4781
4782 /**
4783 * Remove an icon from the given element by undoing the changes effected
4784 * by `applyIcon`.
4785 *
4786 * @param {Element} element The element from which the icon is removed.
4787 */
4788 removeIcon: function(element) {
4789 // Remove old svg element
4790 if (element._svgIcon) {
4791 Polymer.dom(element).removeChild(element._svgIcon);
4792 element._svgIcon = null;
4793 }
4794 },
4795
4796 /**
4797 *
4798 * When name is changed, register iconset metadata
4799 *
4800 */
4801 _nameChanged: function() {
4802 new Polymer.IronMeta({type: 'iconset', key: this.name, value: this});
4803 this.async(function() {
4804 this.fire('iron-iconset-added', this, {node: window});
4805 });
4806 },
4807
4808 /**
4809 * Create a map of child SVG elements by id.
4810 *
4811 * @return {!Object} Map of id's to SVG elements.
4812 */
4813 _createIconMap: function() {
4814 // Objects chained to Object.prototype (`{}`) have members. Specifically,
4815 // on FF there is a `watch` method that confuses the icon map, so we
4816 // need to use a null-based object here.
4817 var icons = Object.create(null);
4818 Polymer.dom(this).querySelectorAll('[id]')
4819 .forEach(function(icon) {
4820 icons[icon.id] = icon;
4821 });
4822 return icons;
4823 },
4824
4825 /**
4826 * Produce installable clone of the SVG element matching `id` in this
4827 * iconset, or `undefined` if there is no matching element.
4828 *
4829 * @return {Element} Returns an installable clone of the SVG element
4830 * matching `id`.
4831 */
4832 _cloneIcon: function(id) {
4833 // create the icon map on-demand, since the iconset itself has no discrete
4834 // signal to know when it's children are fully parsed
4835 this._icons = this._icons || this._createIconMap();
4836 return this._prepareSvgClone(this._icons[id], this.size);
4837 },
4838
4839 /**
4840 * @param {Element} sourceSvg
4841 * @param {number} size
4842 * @return {Element}
4843 */
4844 _prepareSvgClone: function(sourceSvg, size) {
4845 if (sourceSvg) {
4846 var content = sourceSvg.cloneNode(true),
4847 svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
4848 viewBox = content.getAttribute('viewBox') || '0 0 ' + size + ' ' + s ize;
4849 svg.setAttribute('viewBox', viewBox);
4850 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
4851 // TODO(dfreedm): `pointer-events: none` works around https://crbug.com/ 370136
4852 // TODO(sjmiles): inline style may not be ideal, but avoids requiring a shadow-root
4853 svg.style.cssText = 'pointer-events: none; display: block; width: 100%; height: 100%;';
4854 svg.appendChild(content).removeAttribute('id');
4855 return svg;
4856 }
4857 return null;
4858 }
4859
4860 });
4861 /**
4862 * @demo demo/index.html 4683 * @demo demo/index.html
4863 * @polymerBehavior 4684 * @polymerBehavior
4864 */ 4685 */
4865 Polymer.IronControlState = { 4686 Polymer.IronControlState = {
4866 4687
4867 properties: { 4688 properties: {
4868 4689
4869 /** 4690 /**
4870 * If true, the element currently has focus. 4691 * If true, the element currently has focus.
4871 */ 4692 */
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 }, 6066 },
6246 6067
6247 _disabledChanged: function(disabled) { 6068 _disabledChanged: function(disabled) {
6248 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); 6069 this.setAttribute('aria-disabled', disabled ? 'true' : 'false');
6249 }, 6070 },
6250 6071
6251 _hideSecondaryProgress: function(secondaryRatio) { 6072 _hideSecondaryProgress: function(secondaryRatio) {
6252 return secondaryRatio === 0; 6073 return secondaryRatio === 0;
6253 } 6074 }
6254 }); 6075 });
6076 /**
6077 * The `iron-iconset-svg` element allows users to define their own icon sets
6078 * that contain svg icons. The svg icon elements should be children of the
6079 * `iron-iconset-svg` element. Multiple icons should be given distinct id's.
6080 *
6081 * Using svg elements to create icons has a few advantages over traditional
6082 * bitmap graphics like jpg or png. Icons that use svg are vector based so
6083 * they are resolution independent and should look good on any device. They
6084 * are stylable via css. Icons can be themed, colorized, and even animated.
6085 *
6086 * Example:
6087 *
6088 * <iron-iconset-svg name="my-svg-icons" size="24">
6089 * <svg>
6090 * <defs>
6091 * <g id="shape">
6092 * <rect x="12" y="0" width="12" height="24" />
6093 * <circle cx="12" cy="12" r="12" />
6094 * </g>
6095 * </defs>
6096 * </svg>
6097 * </iron-iconset-svg>
6098 *
6099 * This will automatically register the icon set "my-svg-icons" to the iconset
6100 * database. To use these icons from within another element, make a
6101 * `iron-iconset` element and call the `byId` method
6102 * to retrieve a given iconset. To apply a particular icon inside an
6103 * element use the `applyIcon` method. For example:
6104 *
6105 * iconset.applyIcon(iconNode, 'car');
6106 *
6107 * @element iron-iconset-svg
6108 * @demo demo/index.html
6109 * @implements {Polymer.Iconset}
6110 */
6111 Polymer({
6112 is: 'iron-iconset-svg',
6113
6114 properties: {
6115
6116 /**
6117 * The name of the iconset.
6118 */
6119 name: {
6120 type: String,
6121 observer: '_nameChanged'
6122 },
6123
6124 /**
6125 * The size of an individual icon. Note that icons must be square.
6126 */
6127 size: {
6128 type: Number,
6129 value: 24
6130 }
6131
6132 },
6133
6134 attached: function() {
6135 this.style.display = 'none';
6136 },
6137
6138 /**
6139 * Construct an array of all icon names in this iconset.
6140 *
6141 * @return {!Array} Array of icon names.
6142 */
6143 getIconNames: function() {
6144 this._icons = this._createIconMap();
6145 return Object.keys(this._icons).map(function(n) {
6146 return this.name + ':' + n;
6147 }, this);
6148 },
6149
6150 /**
6151 * Applies an icon to the given element.
6152 *
6153 * An svg icon is prepended to the element's shadowRoot if it exists,
6154 * otherwise to the element itself.
6155 *
6156 * @method applyIcon
6157 * @param {Element} element Element to which the icon is applied.
6158 * @param {string} iconName Name of the icon to apply.
6159 * @return {?Element} The svg element which renders the icon.
6160 */
6161 applyIcon: function(element, iconName) {
6162 // insert svg element into shadow root, if it exists
6163 element = element.root || element;
6164 // Remove old svg element
6165 this.removeIcon(element);
6166 // install new svg element
6167 var svg = this._cloneIcon(iconName);
6168 if (svg) {
6169 var pde = Polymer.dom(element);
6170 pde.insertBefore(svg, pde.childNodes[0]);
6171 return element._svgIcon = svg;
6172 }
6173 return null;
6174 },
6175
6176 /**
6177 * Remove an icon from the given element by undoing the changes effected
6178 * by `applyIcon`.
6179 *
6180 * @param {Element} element The element from which the icon is removed.
6181 */
6182 removeIcon: function(element) {
6183 // Remove old svg element
6184 if (element._svgIcon) {
6185 Polymer.dom(element).removeChild(element._svgIcon);
6186 element._svgIcon = null;
6187 }
6188 },
6189
6190 /**
6191 *
6192 * When name is changed, register iconset metadata
6193 *
6194 */
6195 _nameChanged: function() {
6196 new Polymer.IronMeta({type: 'iconset', key: this.name, value: this});
6197 this.async(function() {
6198 this.fire('iron-iconset-added', this, {node: window});
6199 });
6200 },
6201
6202 /**
6203 * Create a map of child SVG elements by id.
6204 *
6205 * @return {!Object} Map of id's to SVG elements.
6206 */
6207 _createIconMap: function() {
6208 // Objects chained to Object.prototype (`{}`) have members. Specifically,
6209 // on FF there is a `watch` method that confuses the icon map, so we
6210 // need to use a null-based object here.
6211 var icons = Object.create(null);
6212 Polymer.dom(this).querySelectorAll('[id]')
6213 .forEach(function(icon) {
6214 icons[icon.id] = icon;
6215 });
6216 return icons;
6217 },
6218
6219 /**
6220 * Produce installable clone of the SVG element matching `id` in this
6221 * iconset, or `undefined` if there is no matching element.
6222 *
6223 * @return {Element} Returns an installable clone of the SVG element
6224 * matching `id`.
6225 */
6226 _cloneIcon: function(id) {
6227 // create the icon map on-demand, since the iconset itself has no discrete
6228 // signal to know when it's children are fully parsed
6229 this._icons = this._icons || this._createIconMap();
6230 return this._prepareSvgClone(this._icons[id], this.size);
6231 },
6232
6233 /**
6234 * @param {Element} sourceSvg
6235 * @param {number} size
6236 * @return {Element}
6237 */
6238 _prepareSvgClone: function(sourceSvg, size) {
6239 if (sourceSvg) {
6240 var content = sourceSvg.cloneNode(true),
6241 svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
6242 viewBox = content.getAttribute('viewBox') || '0 0 ' + size + ' ' + s ize;
6243 svg.setAttribute('viewBox', viewBox);
6244 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
6245 // TODO(dfreedm): `pointer-events: none` works around https://crbug.com/ 370136
6246 // TODO(sjmiles): inline style may not be ideal, but avoids requiring a shadow-root
6247 svg.style.cssText = 'pointer-events: none; display: block; width: 100%; height: 100%;';
6248 svg.appendChild(content).removeAttribute('id');
6249 return svg;
6250 }
6251 return null;
6252 }
6253
6254 });
6255 // Copyright 2015 The Chromium Authors. All rights reserved. 6255 // Copyright 2015 The Chromium Authors. All rights reserved.
6256 // Use of this source code is governed by a BSD-style license that can be 6256 // Use of this source code is governed by a BSD-style license that can be
6257 // found in the LICENSE file. 6257 // found in the LICENSE file.
6258 6258
6259 cr.define('downloads', function() { 6259 cr.define('downloads', function() {
6260 var InkyTextButton = Polymer({ 6260 var InkyTextButton = Polymer({
6261 is: 'inky-text-button', 6261 is: 'inky-text-button',
6262 6262
6263 behaviors: [ 6263 behaviors: [
6264 Polymer.PaperInkyFocusBehavior 6264 Polymer.PaperInkyFocusBehavior
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6376 computeDangerIcon_: function() { 6376 computeDangerIcon_: function() {
6377 if (!this.isDangerous_) 6377 if (!this.isDangerous_)
6378 return ''; 6378 return '';
6379 6379
6380 switch (this.data.danger_type) { 6380 switch (this.data.danger_type) {
6381 case downloads.DangerType.DANGEROUS_CONTENT: 6381 case downloads.DangerType.DANGEROUS_CONTENT:
6382 case downloads.DangerType.DANGEROUS_HOST: 6382 case downloads.DangerType.DANGEROUS_HOST:
6383 case downloads.DangerType.DANGEROUS_URL: 6383 case downloads.DangerType.DANGEROUS_URL:
6384 case downloads.DangerType.POTENTIALLY_UNWANTED: 6384 case downloads.DangerType.POTENTIALLY_UNWANTED:
6385 case downloads.DangerType.UNCOMMON_CONTENT: 6385 case downloads.DangerType.UNCOMMON_CONTENT:
6386 return 'remove-circle'; 6386 return 'downloads:remove-circle';
6387 default: 6387 default:
6388 return 'warning'; 6388 return 'downloads:warning';
6389 } 6389 }
6390 }, 6390 },
6391 6391
6392 /** @private */ 6392 /** @private */
6393 computeDate_: function() { 6393 computeDate_: function() {
6394 assert(typeof this.data.hideDate == 'boolean'); 6394 assert(typeof this.data.hideDate == 'boolean');
6395 if (this.data.hideDate) 6395 if (this.data.hideDate)
6396 return ''; 6396 return '';
6397 return assert(this.data.since_string || this.data.date_string); 6397 return assert(this.data.since_string || this.data.date_string);
6398 }, 6398 },
(...skipping 4972 matching lines...) Expand 10 before | Expand all | Expand 10 after
11371 Manager.get().updateItem_(index, data); 11371 Manager.get().updateItem_(index, data);
11372 }; 11372 };
11373 11373
11374 return {Manager: Manager}; 11374 return {Manager: Manager};
11375 }); 11375 });
11376 // Copyright 2015 The Chromium Authors. All rights reserved. 11376 // Copyright 2015 The Chromium Authors. All rights reserved.
11377 // Use of this source code is governed by a BSD-style license that can be 11377 // Use of this source code is governed by a BSD-style license that can be
11378 // found in the LICENSE file. 11378 // found in the LICENSE file.
11379 11379
11380 window.addEventListener('load', downloads.Manager.onLoad); 11380 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/icons.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698