| OLD | NEW |
| 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 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 element.style.left = '-9999px'; | 1182 element.style.left = '-9999px'; |
| 1183 element.style.height = '0px'; | 1183 element.style.height = '0px'; |
| 1184 element.innerText = msg; | 1184 element.innerText = msg; |
| 1185 document.body.appendChild(element); | 1185 document.body.appendChild(element); |
| 1186 window.setTimeout(function() { | 1186 window.setTimeout(function() { |
| 1187 document.body.removeChild(element); | 1187 document.body.removeChild(element); |
| 1188 }, 0); | 1188 }, 0); |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 /** | 1191 /** |
| 1192 * Returns the scale factors supported by this platform for webui | |
| 1193 * resources. | |
| 1194 * @return {Array} The supported scale factors. | |
| 1195 */ | |
| 1196 function getSupportedScaleFactors() { | |
| 1197 var supportedScaleFactors = []; | |
| 1198 if (cr.isMac || cr.isChromeOS || cr.isWindows || cr.isLinux) { | |
| 1199 // All desktop platforms support zooming which also updates the | |
| 1200 // renderer's device scale factors (a.k.a devicePixelRatio), and | |
| 1201 // these platforms has high DPI assets for 2.0x. Use 1x and 2x in | |
| 1202 // image-set on these platforms so that the renderer can pick the | |
| 1203 // closest image for the current device scale factor. | |
| 1204 supportedScaleFactors.push(1); | |
| 1205 supportedScaleFactors.push(2); | |
| 1206 } else { | |
| 1207 // For other platforms that use fixed device scale factor, use | |
| 1208 // the window's device pixel ratio. | |
| 1209 // TODO(oshima): Investigate if Android/iOS need to use image-set. | |
| 1210 supportedScaleFactors.push(window.devicePixelRatio); | |
| 1211 } | |
| 1212 return supportedScaleFactors; | |
| 1213 } | |
| 1214 | |
| 1215 /** | |
| 1216 * Generates a CSS url string. | 1192 * Generates a CSS url string. |
| 1217 * @param {string} s The URL to generate the CSS url for. | 1193 * @param {string} s The URL to generate the CSS url for. |
| 1218 * @return {string} The CSS url string. | 1194 * @return {string} The CSS url string. |
| 1219 */ | 1195 */ |
| 1220 function url(s) { | 1196 function url(s) { |
| 1221 // http://www.w3.org/TR/css3-values/#uris | 1197 // http://www.w3.org/TR/css3-values/#uris |
| 1222 // Parentheses, commas, whitespace characters, single quotes (') and double | 1198 // Parentheses, commas, whitespace characters, single quotes (') and double |
| 1223 // quotes (") appearing in a URI must be escaped with a backslash | 1199 // quotes (") appearing in a URI must be escaped with a backslash |
| 1224 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1'); | 1200 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1'); |
| 1225 // WebKit has a bug when it comes to URLs that end with \ | 1201 // WebKit has a bug when it comes to URLs that end with \ |
| 1226 // https://bugs.webkit.org/show_bug.cgi?id=28885 | 1202 // https://bugs.webkit.org/show_bug.cgi?id=28885 |
| 1227 if (/\\\\$/.test(s2)) { | 1203 if (/\\\\$/.test(s2)) { |
| 1228 // Add a space to work around the WebKit bug. | 1204 // Add a space to work around the WebKit bug. |
| 1229 s2 += ' '; | 1205 s2 += ' '; |
| 1230 } | 1206 } |
| 1231 return 'url("' + s2 + '")'; | 1207 return 'url("' + s2 + '")'; |
| 1232 } | 1208 } |
| 1233 | 1209 |
| 1234 /** | 1210 /** |
| 1235 * Returns the URL of the image, or an image set of URLs for the profile avatar. | |
| 1236 * Default avatars have resources available for multiple scalefactors, whereas | |
| 1237 * the GAIA profile image only comes in one size. | |
| 1238 * | |
| 1239 * @param {string} path The path of the image. | |
| 1240 * @return {string} The url, or an image set of URLs of the avatar image. | |
| 1241 */ | |
| 1242 function getProfileAvatarIcon(path) { | |
| 1243 var chromeThemePath = 'chrome://theme'; | |
| 1244 var isDefaultAvatar = | |
| 1245 (path.slice(0, chromeThemePath.length) == chromeThemePath); | |
| 1246 return isDefaultAvatar ? imageset(path + '@scalefactorx'): url(path); | |
| 1247 } | |
| 1248 | |
| 1249 /** | |
| 1250 * Generates a CSS -webkit-image-set for a chrome:// url. | |
| 1251 * An entry in the image set is added for each of getSupportedScaleFactors(). | |
| 1252 * The scale-factor-specific url is generated by replacing the first instance of | |
| 1253 * 'scalefactor' in |path| with the numeric scale factor. | |
| 1254 * @param {string} path The URL to generate an image set for. | |
| 1255 * 'scalefactor' should be a substring of |path|. | |
| 1256 * @return {string} The CSS -webkit-image-set. | |
| 1257 */ | |
| 1258 function imageset(path) { | |
| 1259 var supportedScaleFactors = getSupportedScaleFactors(); | |
| 1260 | |
| 1261 var replaceStartIndex = path.indexOf('scalefactor'); | |
| 1262 if (replaceStartIndex < 0) | |
| 1263 return url(path); | |
| 1264 | |
| 1265 var s = ''; | |
| 1266 for (var i = 0; i < supportedScaleFactors.length; ++i) { | |
| 1267 var scaleFactor = supportedScaleFactors[i]; | |
| 1268 var pathWithScaleFactor = path.substr(0, replaceStartIndex) + scaleFactor + | |
| 1269 path.substr(replaceStartIndex + 'scalefactor'.length); | |
| 1270 | |
| 1271 s += url(pathWithScaleFactor) + ' ' + scaleFactor + 'x'; | |
| 1272 | |
| 1273 if (i != supportedScaleFactors.length - 1) | |
| 1274 s += ', '; | |
| 1275 } | |
| 1276 return '-webkit-image-set(' + s + ')'; | |
| 1277 } | |
| 1278 | |
| 1279 /** | |
| 1280 * Parses query parameters from Location. | 1211 * Parses query parameters from Location. |
| 1281 * @param {Location} location The URL to generate the CSS url for. | 1212 * @param {Location} location The URL to generate the CSS url for. |
| 1282 * @return {Object} Dictionary containing name value pairs for URL | 1213 * @return {Object} Dictionary containing name value pairs for URL |
| 1283 */ | 1214 */ |
| 1284 function parseQueryParams(location) { | 1215 function parseQueryParams(location) { |
| 1285 var params = {}; | 1216 var params = {}; |
| 1286 var query = unescape(location.search.substring(1)); | 1217 var query = unescape(location.search.substring(1)); |
| 1287 var vars = query.split('&'); | 1218 var vars = query.split('&'); |
| 1288 for (var i = 0; i < vars.length; i++) { | 1219 for (var i = 0; i < vars.length; i++) { |
| 1289 var pair = vars[i].split('='); | 1220 var pair = vars[i].split('='); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 */ | 1392 */ |
| 1462 function appendParam(url, key, value) { | 1393 function appendParam(url, key, value) { |
| 1463 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); | 1394 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); |
| 1464 | 1395 |
| 1465 if (url.indexOf('?') == -1) | 1396 if (url.indexOf('?') == -1) |
| 1466 return url + '?' + param; | 1397 return url + '?' + param; |
| 1467 return url + '&' + param; | 1398 return url + '&' + param; |
| 1468 } | 1399 } |
| 1469 | 1400 |
| 1470 /** | 1401 /** |
| 1471 * A regular expression for identifying favicon URLs. | |
| 1472 * @const {!RegExp} | |
| 1473 * TODO(dpapad): Move all favicon related methods to a new favicon_util.js file | |
| 1474 * and make this RegExp private. | |
| 1475 */ | |
| 1476 var FAVICON_URL_REGEX = /\.ico$/i; | |
| 1477 | |
| 1478 /** | |
| 1479 * Creates a CSS -webkit-image-set for a favicon request. | |
| 1480 * @param {string} url Either the URL of the original page or of the favicon | |
| 1481 * itself. | |
| 1482 * @param {number=} opt_size Optional preferred size of the favicon. | |
| 1483 * @param {string=} opt_type Optional type of favicon to request. Valid values | |
| 1484 * are 'favicon' and 'touch-icon'. Default is 'favicon'. | |
| 1485 * @return {string} -webkit-image-set for the favicon. | |
| 1486 */ | |
| 1487 function getFaviconImageSet(url, opt_size, opt_type) { | |
| 1488 var size = opt_size || 16; | |
| 1489 var type = opt_type || 'favicon'; | |
| 1490 | |
| 1491 return imageset( | |
| 1492 'chrome://' + type + '/size/' + size + '@scalefactorx/' + | |
| 1493 // Note: Literal 'iconurl' must match |kIconURLParameter| in | |
| 1494 // components/favicon_base/favicon_url_parser.cc. | |
| 1495 (FAVICON_URL_REGEX.test(url) ? 'iconurl/' : '') + url); | |
| 1496 } | |
| 1497 | |
| 1498 /** | |
| 1499 * Creates an element of a specified type with a specified class name. | 1402 * Creates an element of a specified type with a specified class name. |
| 1500 * @param {string} type The node type. | 1403 * @param {string} type The node type. |
| 1501 * @param {string} className The class name to use. | 1404 * @param {string} className The class name to use. |
| 1502 * @return {Element} The created element. | 1405 * @return {Element} The created element. |
| 1503 */ | 1406 */ |
| 1504 function createElementWithClassName(type, className) { | 1407 function createElementWithClassName(type, className) { |
| 1505 var elm = document.createElement(type); | 1408 var elm = document.createElement(type); |
| 1506 elm.className = className; | 1409 elm.className = className; |
| 1507 return elm; | 1410 return elm; |
| 1508 } | 1411 } |
| (...skipping 8768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10277 | 10180 |
| 10278 Polymer.IronA11yAnnouncer.requestAvailability = function() { | 10181 Polymer.IronA11yAnnouncer.requestAvailability = function() { |
| 10279 if (!Polymer.IronA11yAnnouncer.instance) { | 10182 if (!Polymer.IronA11yAnnouncer.instance) { |
| 10280 Polymer.IronA11yAnnouncer.instance = document.createElement('iron-a11y
-announcer'); | 10183 Polymer.IronA11yAnnouncer.instance = document.createElement('iron-a11y
-announcer'); |
| 10281 } | 10184 } |
| 10282 | 10185 |
| 10283 document.body.appendChild(Polymer.IronA11yAnnouncer.instance); | 10186 document.body.appendChild(Polymer.IronA11yAnnouncer.instance); |
| 10284 }; | 10187 }; |
| 10285 })(); | 10188 })(); |
| 10286 /** | 10189 /** |
| 10190 * Singleton IronMeta instance. |
| 10191 */ |
| 10192 Polymer.IronValidatableBehaviorMeta = null; |
| 10193 |
| 10194 /** |
| 10287 * `Use Polymer.IronValidatableBehavior` to implement an element that validate
s user input. | 10195 * `Use Polymer.IronValidatableBehavior` to implement an element that validate
s user input. |
| 10288 * Use the related `Polymer.IronValidatorBehavior` to add custom validation lo
gic to an iron-input. | 10196 * Use the related `Polymer.IronValidatorBehavior` to add custom validation lo
gic to an iron-input. |
| 10289 * | 10197 * |
| 10290 * By default, an `<iron-form>` element validates its fields when the user pre
sses the submit button. | 10198 * By default, an `<iron-form>` element validates its fields when the user pre
sses the submit button. |
| 10291 * To validate a form imperatively, call the form's `validate()` method, which
in turn will | 10199 * To validate a form imperatively, call the form's `validate()` method, which
in turn will |
| 10292 * call `validate()` on all its children. By using `Polymer.IronValidatableBeh
avior`, your | 10200 * call `validate()` on all its children. By using `Polymer.IronValidatableBeh
avior`, your |
| 10293 * custom element will get a public `validate()`, which | 10201 * custom element will get a public `validate()`, which |
| 10294 * will return the validity of the element, and a corresponding `invalid` attr
ibute, | 10202 * will return the validity of the element, and a corresponding `invalid` attr
ibute, |
| 10295 * which can be used for styling. | 10203 * which can be used for styling. |
| 10296 * | 10204 * |
| 10297 * To implement the custom validation logic of your element, you must override | 10205 * To implement the custom validation logic of your element, you must override |
| 10298 * the protected `_getValidity()` method of this behaviour, rather than `valid
ate()`. | 10206 * the protected `_getValidity()` method of this behaviour, rather than `valid
ate()`. |
| 10299 * See [this](https://github.com/PolymerElements/iron-form/blob/master/demo/si
mple-element.html) | 10207 * See [this](https://github.com/PolymerElements/iron-form/blob/master/demo/si
mple-element.html) |
| 10300 * for an example. | 10208 * for an example. |
| 10301 * | 10209 * |
| 10302 * ### Accessibility | 10210 * ### Accessibility |
| 10303 * | 10211 * |
| 10304 * Changing the `invalid` property, either manually or by calling `validate()`
will update the | 10212 * Changing the `invalid` property, either manually or by calling `validate()`
will update the |
| 10305 * `aria-invalid` attribute. | 10213 * `aria-invalid` attribute. |
| 10306 * | 10214 * |
| 10307 * @demo demo/index.html | 10215 * @demo demo/index.html |
| 10308 * @polymerBehavior | 10216 * @polymerBehavior |
| 10309 */ | 10217 */ |
| 10310 Polymer.IronValidatableBehavior = { | 10218 Polymer.IronValidatableBehavior = { |
| 10311 | 10219 |
| 10312 properties: { | 10220 properties: { |
| 10313 | 10221 |
| 10314 /** | 10222 /** |
| 10315 * Namespace for this validator. | |
| 10316 */ | |
| 10317 validatorType: { | |
| 10318 type: String, | |
| 10319 value: 'validator' | |
| 10320 }, | |
| 10321 | |
| 10322 /** | |
| 10323 * Name of the validator to use. | 10223 * Name of the validator to use. |
| 10324 */ | 10224 */ |
| 10325 validator: { | 10225 validator: { |
| 10326 type: String | 10226 type: String |
| 10327 }, | 10227 }, |
| 10328 | 10228 |
| 10329 /** | 10229 /** |
| 10330 * True if the last call to `validate` is invalid. | 10230 * True if the last call to `validate` is invalid. |
| 10331 */ | 10231 */ |
| 10332 invalid: { | 10232 invalid: { |
| 10333 notify: true, | 10233 notify: true, |
| 10334 reflectToAttribute: true, | 10234 reflectToAttribute: true, |
| 10335 type: Boolean, | 10235 type: Boolean, |
| 10336 value: false | 10236 value: false |
| 10337 }, | 10237 }, |
| 10338 | 10238 |
| 10239 /** |
| 10240 * This property is deprecated and should not be used. Use the global |
| 10241 * validator meta singleton, `Polymer.IronValidatableBehaviorMeta` instead
. |
| 10242 */ |
| 10339 _validatorMeta: { | 10243 _validatorMeta: { |
| 10340 type: Object | 10244 type: Object |
| 10245 }, |
| 10246 |
| 10247 /** |
| 10248 * Namespace for this validator. This property is deprecated and should |
| 10249 * not be used. For all intents and purposes, please consider it a |
| 10250 * read-only, config-time property. |
| 10251 */ |
| 10252 validatorType: { |
| 10253 type: String, |
| 10254 value: 'validator' |
| 10255 }, |
| 10256 |
| 10257 _validator: { |
| 10258 type: Object, |
| 10259 computed: '__computeValidator(validator)' |
| 10341 } | 10260 } |
| 10342 | |
| 10343 }, | 10261 }, |
| 10344 | 10262 |
| 10345 observers: [ | 10263 observers: [ |
| 10346 '_invalidChanged(invalid)' | 10264 '_invalidChanged(invalid)' |
| 10347 ], | 10265 ], |
| 10348 | 10266 |
| 10349 get _validator() { | 10267 registered: function() { |
| 10350 return this._validatorMeta && this._validatorMeta.byKey(this.validator); | 10268 Polymer.IronValidatableBehaviorMeta = new Polymer.IronMeta({type: 'validat
or'}); |
| 10351 }, | |
| 10352 | |
| 10353 ready: function() { | |
| 10354 this._validatorMeta = new Polymer.IronMeta({type: this.validatorType}); | |
| 10355 }, | 10269 }, |
| 10356 | 10270 |
| 10357 _invalidChanged: function() { | 10271 _invalidChanged: function() { |
| 10358 if (this.invalid) { | 10272 if (this.invalid) { |
| 10359 this.setAttribute('aria-invalid', 'true'); | 10273 this.setAttribute('aria-invalid', 'true'); |
| 10360 } else { | 10274 } else { |
| 10361 this.removeAttribute('aria-invalid'); | 10275 this.removeAttribute('aria-invalid'); |
| 10362 } | 10276 } |
| 10363 }, | 10277 }, |
| 10364 | 10278 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 10391 * | 10305 * |
| 10392 * @param {Object} value The value to be validated. | 10306 * @param {Object} value The value to be validated. |
| 10393 * @return {boolean} True if `value` is valid. | 10307 * @return {boolean} True if `value` is valid. |
| 10394 */ | 10308 */ |
| 10395 | 10309 |
| 10396 _getValidity: function(value) { | 10310 _getValidity: function(value) { |
| 10397 if (this.hasValidator()) { | 10311 if (this.hasValidator()) { |
| 10398 return this._validator.validate(value); | 10312 return this._validator.validate(value); |
| 10399 } | 10313 } |
| 10400 return true; | 10314 return true; |
| 10315 }, |
| 10316 |
| 10317 __computeValidator: function() { |
| 10318 return Polymer.IronValidatableBehaviorMeta && |
| 10319 Polymer.IronValidatableBehaviorMeta.byKey(this.validator); |
| 10401 } | 10320 } |
| 10402 }; | 10321 }; |
| 10403 /* | 10322 /* |
| 10404 `<iron-input>` adds two-way binding and custom validators using `Polymer.IronVal
idatorBehavior` | 10323 `<iron-input>` adds two-way binding and custom validators using `Polymer.IronVal
idatorBehavior` |
| 10405 to `<input>`. | 10324 to `<input>`. |
| 10406 | 10325 |
| 10407 ### Two-way binding | 10326 ### Two-way binding |
| 10408 | 10327 |
| 10409 By default you can only get notified of changes to an `input`'s `value` due to u
ser input: | 10328 By default you can only get notified of changes to an `input`'s `value` due to u
ser input: |
| 10410 | 10329 |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11371 Manager.get().updateItem_(index, data); | 11290 Manager.get().updateItem_(index, data); |
| 11372 }; | 11291 }; |
| 11373 | 11292 |
| 11374 return {Manager: Manager}; | 11293 return {Manager: Manager}; |
| 11375 }); | 11294 }); |
| 11376 // Copyright 2015 The Chromium Authors. All rights reserved. | 11295 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 11377 // Use of this source code is governed by a BSD-style license that can be | 11296 // Use of this source code is governed by a BSD-style license that can be |
| 11378 // found in the LICENSE file. | 11297 // found in the LICENSE file. |
| 11379 | 11298 |
| 11380 window.addEventListener('load', downloads.Manager.onLoad); | 11299 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |