| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 function PromiseResolver(){this.resolve_;this.reject_;this.promise_=new Promise(
function(resolve,reject){this.resolve_=resolve;this.reject_=reject}.bind(this))}
PromiseResolver.prototype={get promise(){return this.promise_},set promise(p){as
sertNotReached()},get resolve(){return this.resolve_},set resolve(r){assertNotRe
ached()},get reject(){return this.reject_},set reject(s){assertNotReached()}}; | 4 function PromiseResolver() { |
| 5 this.resolve_; |
| 6 this.reject_; |
| 7 this.promise_ = new Promise(function(resolve, reject) { |
| 8 this.resolve_ = resolve; |
| 9 this.reject_ = reject |
| 10 }.bind(this)) |
| 11 } |
| 12 PromiseResolver.prototype = { |
| 13 get promise() { |
| 14 return this.promise_ |
| 15 }, |
| 16 set promise(p) { |
| 17 assertNotReached() |
| 18 }, |
| 19 get resolve() { |
| 20 return this.resolve_ |
| 21 }, |
| 22 set resolve(r) { |
| 23 assertNotReached() |
| 24 }, |
| 25 get reject() { |
| 26 return this.reject_ |
| 27 }, |
| 28 set reject(s) { |
| 29 assertNotReached() |
| 30 } |
| 31 }; |
| 5 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 32 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 6 // Use of this source code is governed by a BSD-style license that can be | 33 // Use of this source code is governed by a BSD-style license that can be |
| 7 // found in the LICENSE file. | 34 // found in the LICENSE file. |
| 8 var global=this;var WebUIListener;var cr=cr||function(){"use strict";function ex
portPath(name,opt_object,opt_objectToExportTo){var parts=name.split(".");var cur
=opt_objectToExportTo||global;for(var part;parts.length&&(part=parts.shift());){
if(!parts.length&&opt_object!==undefined){cur[part]=opt_object}else if(part in c
ur){cur=cur[part]}else{cur=cur[part]={}}}return cur}function dispatchPropertyCha
nge(target,propertyName,newValue,oldValue){var e=new Event(propertyName+"Change"
);e.propertyName=propertyName;e.newValue=newValue;e.oldValue=oldValue;target.dis
patchEvent(e)}function getAttributeName(jsName){return jsName.replace(/([A-Z])/g
,"-$1").toLowerCase()}var PropertyKind={JS:"js",ATTR:"attr",BOOL_ATTR:"boolAttr"
};function getGetter(name,kind){switch(kind){case PropertyKind.JS:var privateNam
e=name+"_";return function(){return this[privateName]};case PropertyKind.ATTR:va
r attributeName=getAttributeName(name);return function(){return this.getAttribut
e(attributeName)};case PropertyKind.BOOL_ATTR:var attributeName=getAttributeName
(name);return function(){return this.hasAttribute(attributeName)}}throw"not reac
hed"}function getSetter(name,kind,opt_setHook){switch(kind){case PropertyKind.JS
:var privateName=name+"_";return function(value){var oldValue=this[name];if(valu
e!==oldValue){this[privateName]=value;if(opt_setHook)opt_setHook.call(this,value
,oldValue);dispatchPropertyChange(this,name,value,oldValue)}};case PropertyKind.
ATTR:var attributeName=getAttributeName(name);return function(value){var oldValu
e=this[name];if(value!==oldValue){if(value==undefined)this.removeAttribute(attri
buteName);else this.setAttribute(attributeName,value);if(opt_setHook)opt_setHook
.call(this,value,oldValue);dispatchPropertyChange(this,name,value,oldValue)}};ca
se PropertyKind.BOOL_ATTR:var attributeName=getAttributeName(name);return functi
on(value){var oldValue=this[name];if(value!==oldValue){if(value)this.setAttribut
e(attributeName,name);else this.removeAttribute(attributeName);if(opt_setHook)op
t_setHook.call(this,value,oldValue);dispatchPropertyChange(this,name,value,oldVa
lue)}}}throw"not reached"}function defineProperty(obj,name,opt_kind,opt_setHook)
{if(typeof obj=="function")obj=obj.prototype;var kind=opt_kind||PropertyKind.JS;
if(!obj.__lookupGetter__(name))obj.__defineGetter__(name,getGetter(name,kind));i
f(!obj.__lookupSetter__(name))obj.__defineSetter__(name,getSetter(name,kind,opt_
setHook))}var uidCounter=1;function createUid(){return uidCounter++}function get
Uid(item){if(item.hasOwnProperty("uid"))return item.uid;return item.uid=createUi
d()}function dispatchSimpleEvent(target,type,opt_bubbles,opt_cancelable){var e=n
ew Event(type,{bubbles:opt_bubbles,cancelable:opt_cancelable===undefined||opt_ca
ncelable});return target.dispatchEvent(e)}function define(name,fun){var obj=expo
rtPath(name);var exports=fun();for(var propertyName in exports){var propertyDesc
riptor=Object.getOwnPropertyDescriptor(exports,propertyName);if(propertyDescript
or)Object.defineProperty(obj,propertyName,propertyDescriptor)}}function addSingl
etonGetter(ctor){ctor.getInstance=function(){return ctor.instance_||(ctor.instan
ce_=new ctor)}}function makePublic(ctor,methods,opt_target){methods.forEach(func
tion(method){ctor[method]=function(){var target=opt_target?document.getElementBy
Id(opt_target):ctor.getInstance();return target[method+"_"].apply(target,argumen
ts)}})}var chromeSendResolverMap={};function webUIResponse(id,isSuccess,response
){var resolver=chromeSendResolverMap[id];delete chromeSendResolverMap[id];if(isS
uccess)resolver.resolve(response);else resolver.reject(response)}function sendWi
thPromise(methodName,var_args){var args=Array.prototype.slice.call(arguments,1);
var promiseResolver=new PromiseResolver;var id=methodName+"_"+createUid();chrome
SendResolverMap[id]=promiseResolver;chrome.send(methodName,[id].concat(args));re
turn promiseResolver.promise}var webUIListenerMap={};function webUIListenerCallb
ack(event,var_args){var eventListenersMap=webUIListenerMap[event];if(!eventListe
nersMap){return}var args=Array.prototype.slice.call(arguments,1);for(var listene
rId in eventListenersMap){eventListenersMap[listenerId].apply(null,args)}}functi
on addWebUIListener(eventName,callback){webUIListenerMap[eventName]=webUIListene
rMap[eventName]||{};var uid=createUid();webUIListenerMap[eventName][uid]=callbac
k;return{eventName:eventName,uid:uid}}function removeWebUIListener(listener){var
listenerExists=webUIListenerMap[listener.eventName]&&webUIListenerMap[listener.
eventName][listener.uid];if(listenerExists){delete webUIListenerMap[listener.eve
ntName][listener.uid];return true}return false}return{addSingletonGetter:addSing
letonGetter,createUid:createUid,define:define,defineProperty:defineProperty,disp
atchPropertyChange:dispatchPropertyChange,dispatchSimpleEvent:dispatchSimpleEven
t,exportPath:exportPath,getUid:getUid,makePublic:makePublic,PropertyKind:Propert
yKind,addWebUIListener:addWebUIListener,removeWebUIListener:removeWebUIListener,
sendWithPromise:sendWithPromise,webUIListenerCallback:webUIListenerCallback,webU
IResponse:webUIResponse,get doc(){return document},get isMac(){return/Mac/.test(
navigator.platform)},get isWindows(){return/Win/.test(navigator.platform)},get i
sChromeOS(){return/CrOS/.test(navigator.userAgent)},get isLinux(){return/Linux/.
test(navigator.userAgent)},get isAndroid(){return/Android/.test(navigator.userAg
ent)},get isIOS(){return/iPad|iPhone|iPod/.test(navigator.platform)}}}(); | 35 var global = this; |
| 36 var WebUIListener; |
| 37 var cr = cr || function() { |
| 38 "use strict"; |
| 39 function exportPath(name, opt_object, opt_objectToExportTo) { |
| 40 var parts = name.split("."); |
| 41 var cur = opt_objectToExportTo || global; |
| 42 for (var part; parts.length && (part = parts.shift());) { |
| 43 if (!parts.length && opt_object !== undefined) { |
| 44 cur[part] = opt_object |
| 45 } else if (part in cur) { |
| 46 cur = cur[part] |
| 47 } else { |
| 48 cur = cur[part] = {} |
| 49 } |
| 50 } |
| 51 return cur |
| 52 } |
| 53 function dispatchPropertyChange(target, propertyName, newValue, oldValue) { |
| 54 var e = new Event(propertyName + "Change"); |
| 55 e.propertyName = propertyName; |
| 56 e.newValue = newValue; |
| 57 e.oldValue = oldValue; |
| 58 target.dispatchEvent(e) |
| 59 } |
| 60 function getAttributeName(jsName) { |
| 61 return jsName.replace(/([A-Z])/g, "-$1").toLowerCase() |
| 62 } |
| 63 var PropertyKind = {JS: "js", ATTR: "attr", BOOL_ATTR: "boolAttr"}; |
| 64 function getGetter(name, kind) { |
| 65 switch (kind) { |
| 66 case PropertyKind.JS: |
| 67 var privateName = name + "_"; |
| 68 return function() { |
| 69 return this[privateName] |
| 70 }; |
| 71 case PropertyKind.ATTR: |
| 72 var attributeName = getAttributeName(name); |
| 73 return function() { |
| 74 return this.getAttribute(attributeName) |
| 75 }; |
| 76 case PropertyKind.BOOL_ATTR: |
| 77 var attributeName = getAttributeName(name); |
| 78 return function() { |
| 79 return this.hasAttribute(attributeName) |
| 80 } |
| 81 } |
| 82 throw "not reached" |
| 83 } |
| 84 function getSetter(name, kind, opt_setHook) { |
| 85 switch (kind) { |
| 86 case PropertyKind.JS: |
| 87 var privateName = name + "_"; |
| 88 return function(value) { |
| 89 var oldValue = this[name]; |
| 90 if (value !== oldValue) { |
| 91 this[privateName] = value; |
| 92 if (opt_setHook) |
| 93 opt_setHook.call(this, value, oldValue); |
| 94 dispatchPropertyChange(this, name, value, oldValue) |
| 95 } |
| 96 }; |
| 97 case PropertyKind.ATTR: |
| 98 var attributeName = getAttributeName(name); |
| 99 return function(value) { |
| 100 var oldValue = this[name]; |
| 101 if (value !== oldValue) { |
| 102 if (value == undefined) |
| 103 this.removeAttribute(attributeName); |
| 104 else |
| 105 this.setAttribute(attributeName, value); |
| 106 if (opt_setHook) |
| 107 opt_setHook.call(this, value, oldValue); |
| 108 dispatchPropertyChange(this, name, value, oldValue) |
| 109 } |
| 110 }; |
| 111 case PropertyKind.BOOL_ATTR: |
| 112 var attributeName = getAttributeName(name); |
| 113 return function(value) { |
| 114 var oldValue = this[name]; |
| 115 if (value !== oldValue) { |
| 116 if (value) |
| 117 this.setAttribute(attributeName, name); |
| 118 else |
| 119 this.removeAttribute(attributeName); |
| 120 if (opt_setHook) |
| 121 opt_setHook.call(this, value, oldValue); |
| 122 dispatchPropertyChange(this, name, value, oldValue) |
| 123 } |
| 124 } |
| 125 } |
| 126 throw "not reached" |
| 127 } |
| 128 function defineProperty(obj, name, opt_kind, opt_setHook) { |
| 129 if (typeof obj == "function") |
| 130 obj = obj.prototype; |
| 131 var kind = opt_kind || PropertyKind.JS; |
| 132 if (!obj.__lookupGetter__(name)) |
| 133 obj.__defineGetter__(name, getGetter(name, kind)); |
| 134 if (!obj.__lookupSetter__(name)) |
| 135 obj.__defineSetter__(name, getSetter(name, kind, opt_setHook)) |
| 136 } |
| 137 var uidCounter = 1; |
| 138 function createUid() { |
| 139 return uidCounter++ |
| 140 } |
| 141 function getUid(item) { |
| 142 if (item.hasOwnProperty("uid")) |
| 143 return item.uid; |
| 144 return item.uid = createUid() |
| 145 } |
| 146 function dispatchSimpleEvent(target, type, opt_bubbles, opt_cancelable) { |
| 147 var e = new Event(type, { |
| 148 bubbles: opt_bubbles, |
| 149 cancelable: opt_cancelable === undefined || opt_cancelable |
| 150 }); |
| 151 return target.dispatchEvent(e) |
| 152 } |
| 153 function define(name, fun) { |
| 154 var obj = exportPath(name); |
| 155 var exports = fun(); |
| 156 for (var propertyName in exports) { |
| 157 var propertyDescriptor = |
| 158 Object.getOwnPropertyDescriptor(exports, propertyName); |
| 159 if (propertyDescriptor) |
| 160 Object.defineProperty(obj, propertyName, propertyDescriptor) |
| 161 } |
| 162 } |
| 163 function addSingletonGetter(ctor) { |
| 164 ctor.getInstance = function() { |
| 165 return ctor.instance_ || (ctor.instance_ = new ctor) |
| 166 } |
| 167 } |
| 168 function makePublic(ctor, methods, opt_target) { |
| 169 methods.forEach(function(method) { |
| 170 ctor[method] = function() { |
| 171 var target = opt_target ? document.getElementById(opt_target) : |
| 172 ctor.getInstance(); |
| 173 return target[method + "_"].apply(target, arguments) |
| 174 } |
| 175 }) |
| 176 } |
| 177 var chromeSendResolverMap = {}; |
| 178 function webUIResponse(id, isSuccess, response) { |
| 179 var resolver = chromeSendResolverMap[id]; |
| 180 delete chromeSendResolverMap[id]; |
| 181 if (isSuccess) |
| 182 resolver.resolve(response); |
| 183 else |
| 184 resolver.reject(response) |
| 185 } |
| 186 function sendWithPromise(methodName, var_args) { |
| 187 var args = Array.prototype.slice.call(arguments, 1); |
| 188 var promiseResolver = new PromiseResolver; |
| 189 var id = methodName + "_" + createUid(); |
| 190 chromeSendResolverMap[id] = promiseResolver; |
| 191 chrome.send(methodName, [id].concat(args)); |
| 192 return promiseResolver.promise |
| 193 } |
| 194 var webUIListenerMap = {}; |
| 195 function webUIListenerCallback(event, var_args) { |
| 196 var eventListenersMap = webUIListenerMap[event]; |
| 197 if (!eventListenersMap) { |
| 198 return |
| 199 } |
| 200 var args = Array.prototype.slice.call(arguments, 1); |
| 201 for (var listenerId in eventListenersMap) { |
| 202 eventListenersMap[listenerId].apply(null, args) |
| 203 } |
| 204 } |
| 205 function addWebUIListener(eventName, callback) { |
| 206 webUIListenerMap[eventName] = webUIListenerMap[eventName] || {}; |
| 207 var uid = createUid(); |
| 208 webUIListenerMap[eventName][uid] = callback; |
| 209 return { |
| 210 eventName: eventName, uid: uid |
| 211 } |
| 212 } |
| 213 function removeWebUIListener(listener) { |
| 214 var listenerExists = webUIListenerMap[listener.eventName] && |
| 215 webUIListenerMap[listener.eventName][listener.uid]; |
| 216 if (listenerExists) { |
| 217 delete webUIListenerMap[listener.eventName][listener.uid]; |
| 218 return true |
| 219 } |
| 220 return false |
| 221 } |
| 222 return { |
| 223 addSingletonGetter: addSingletonGetter, createUid: createUid, |
| 224 define: define, defineProperty: defineProperty, |
| 225 dispatchPropertyChange: dispatchPropertyChange, |
| 226 dispatchSimpleEvent: dispatchSimpleEvent, exportPath: exportPath, |
| 227 getUid: getUid, makePublic: makePublic, PropertyKind: PropertyKind, |
| 228 addWebUIListener: addWebUIListener, |
| 229 removeWebUIListener: removeWebUIListener, |
| 230 sendWithPromise: sendWithPromise, |
| 231 webUIListenerCallback: webUIListenerCallback, |
| 232 webUIResponse: webUIResponse, get doc(){return document}, |
| 233 get isMac(){return /Mac/.test(navigator.platform)}, |
| 234 get isWindows(){return /Win/.test(navigator.platform)}, |
| 235 get isChromeOS(){return /CrOS/.test(navigator.userAgent)}, |
| 236 get isLinux(){return /Linux/.test(navigator.userAgent)}, |
| 237 get isAndroid(){return /Android/.test(navigator.userAgent)}, |
| 238 get isIOS() { |
| 239 return /iPad|iPhone|iPod/.test(navigator.platform) |
| 240 } |
| 241 } |
| 242 }(); |
| 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 243 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 10 // Use of this source code is governed by a BSD-style license that can be | 244 // Use of this source code is governed by a BSD-style license that can be |
| 11 // found in the LICENSE file. | 245 // found in the LICENSE file. |
| 12 cr.define("cr.ui",function(){function decorate(source,constr){var elements;if(ty
peof source=="string")elements=cr.doc.querySelectorAll(source);else elements=[so
urce];for(var i=0,el;el=elements[i];i++){if(!(el instanceof constr))constr.decor
ate(el)}}function createElementHelper(tagName,opt_bag){var doc;if(opt_bag&&opt_b
ag.ownerDocument)doc=opt_bag.ownerDocument;else doc=cr.doc;return doc.createElem
ent(tagName)}function define(tagNameOrFunction){var createFunction,tagName;if(ty
peof tagNameOrFunction=="function"){createFunction=tagNameOrFunction;tagName=""}
else{createFunction=createElementHelper;tagName=tagNameOrFunction}function f(opt
_propertyBag){var el=createFunction(tagName,opt_propertyBag);f.decorate(el);for(
var propertyName in opt_propertyBag){el[propertyName]=opt_propertyBag[propertyNa
me]}return el}f.decorate=function(el){el.__proto__=f.prototype;el.decorate()};re
turn f}function limitInputWidth(el,parentEl,min,opt_scale){el.style.width="10px"
;var doc=el.ownerDocument;var win=doc.defaultView;var computedStyle=win.getCompu
tedStyle(el);var parentComputedStyle=win.getComputedStyle(parentEl);var rtl=comp
utedStyle.direction=="rtl";var inputRect=el.getBoundingClientRect();var parentRe
ct=parentEl.getBoundingClientRect();var startPos=rtl?parentRect.right-inputRect.
right:inputRect.left-parentRect.left;var inner=parseInt(computedStyle.borderLeft
Width,10)+parseInt(computedStyle.paddingLeft,10)+parseInt(computedStyle.paddingR
ight,10)+parseInt(computedStyle.borderRightWidth,10);var parentPadding=rtl?parse
Int(parentComputedStyle.paddingLeft,10):parseInt(parentComputedStyle.paddingRigh
t,10);var max=parentEl.clientWidth-startPos-inner-parentPadding;if(opt_scale)max
*=opt_scale;function limit(){if(el.scrollWidth>max){el.style.width=max+"px"}else
{el.style.width=0;var sw=el.scrollWidth;if(sw<min){el.style.width=min+"px"}else{
el.style.width=sw+"px"}}}el.addEventListener("input",limit);limit()}function toC
ssPx(pixels){if(!window.isFinite(pixels))console.error("Pixel value is not a num
ber: "+pixels);return Math.round(pixels)+"px"}function swallowDoubleClick(e){var
doc=e.target.ownerDocument;var counter=Math.min(1,e.detail);function swallow(e)
{e.stopPropagation();e.preventDefault()}function onclick(e){if(e.detail>counter)
{counter=e.detail;swallow(e)}else{doc.removeEventListener("dblclick",swallow,tru
e);doc.removeEventListener("click",onclick,true)}}setTimeout(function(){doc.addE
ventListener("click",onclick,true);doc.addEventListener("dblclick",swallow,true)
},0)}return{decorate:decorate,define:define,limitInputWidth:limitInputWidth,toCs
sPx:toCssPx,swallowDoubleClick:swallowDoubleClick}}); | 246 cr.define("cr.ui", function() { |
| 247 function decorate(source, constr) { |
| 248 var elements; |
| 249 if (typeof source == "string") |
| 250 elements = cr.doc.querySelectorAll(source); |
| 251 else |
| 252 elements = [source]; |
| 253 for (var i = 0, el; el = elements[i]; i++) { |
| 254 if (!(el instanceof constr)) |
| 255 constr.decorate(el) |
| 256 } |
| 257 } |
| 258 function createElementHelper(tagName, opt_bag) { |
| 259 var doc; |
| 260 if (opt_bag && opt_bag.ownerDocument) |
| 261 doc = opt_bag.ownerDocument; |
| 262 else |
| 263 doc = cr.doc; |
| 264 return doc.createElement(tagName) |
| 265 } |
| 266 function define(tagNameOrFunction) { |
| 267 var createFunction, tagName; |
| 268 if (typeof tagNameOrFunction == "function") { |
| 269 createFunction = tagNameOrFunction; |
| 270 tagName = "" |
| 271 } else { |
| 272 createFunction = createElementHelper; |
| 273 tagName = tagNameOrFunction |
| 274 } |
| 275 function f(opt_propertyBag) { |
| 276 var el = createFunction(tagName, opt_propertyBag); |
| 277 f.decorate(el); |
| 278 for (var propertyName in opt_propertyBag) { |
| 279 el[propertyName] = opt_propertyBag[propertyName] |
| 280 } |
| 281 return el |
| 282 } |
| 283 f.decorate = function(el) { |
| 284 el.__proto__ = f.prototype; |
| 285 el.decorate() |
| 286 }; |
| 287 return f |
| 288 } |
| 289 function limitInputWidth(el, parentEl, min, opt_scale) { |
| 290 el.style.width = "10px"; |
| 291 var doc = el.ownerDocument; |
| 292 var win = doc.defaultView; |
| 293 var computedStyle = win.getComputedStyle(el); |
| 294 var parentComputedStyle = win.getComputedStyle(parentEl); |
| 295 var rtl = computedStyle.direction == "rtl"; |
| 296 var inputRect = el.getBoundingClientRect(); |
| 297 var parentRect = parentEl.getBoundingClientRect(); |
| 298 var startPos = rtl ? parentRect.right - inputRect.right : |
| 299 inputRect.left - parentRect.left; |
| 300 var inner = parseInt(computedStyle.borderLeftWidth, 10) + |
| 301 parseInt(computedStyle.paddingLeft, 10) + |
| 302 parseInt(computedStyle.paddingRight, 10) + |
| 303 parseInt(computedStyle.borderRightWidth, 10); |
| 304 var parentPadding = rtl ? parseInt(parentComputedStyle.paddingLeft, 10) : |
| 305 parseInt(parentComputedStyle.paddingRight, 10); |
| 306 var max = parentEl.clientWidth - startPos - inner - parentPadding; |
| 307 if (opt_scale) |
| 308 max *= opt_scale; |
| 309 function limit() { |
| 310 if (el.scrollWidth > max) { |
| 311 el.style.width = max + "px" |
| 312 } else { |
| 313 el.style.width = 0; |
| 314 var sw = el.scrollWidth; |
| 315 if (sw < min) { |
| 316 el.style.width = min + "px" |
| 317 } else { |
| 318 el.style.width = sw + "px" |
| 319 } |
| 320 } |
| 321 } |
| 322 el.addEventListener("input", limit); |
| 323 limit() |
| 324 } |
| 325 function toCssPx(pixels) { |
| 326 if (!window.isFinite(pixels)) |
| 327 console.error("Pixel value is not a number: " + pixels); |
| 328 return Math.round(pixels) + "px" |
| 329 } |
| 330 function swallowDoubleClick(e) { |
| 331 var doc = e.target.ownerDocument; |
| 332 var counter = Math.min(1, e.detail); |
| 333 function swallow(e) { |
| 334 e.stopPropagation(); |
| 335 e.preventDefault() |
| 336 } |
| 337 function onclick(e) { |
| 338 if (e.detail > counter) { |
| 339 counter = e.detail; |
| 340 swallow(e) |
| 341 } else { |
| 342 doc.removeEventListener("dblclick", swallow, true); |
| 343 doc.removeEventListener("click", onclick, true) |
| 344 } |
| 345 } |
| 346 setTimeout(function() { |
| 347 doc.addEventListener("click", onclick, true); |
| 348 doc.addEventListener("dblclick", swallow, true) |
| 349 }, 0) |
| 350 } |
| 351 return { |
| 352 decorate: decorate, define: define, limitInputWidth: limitInputWidth, |
| 353 toCssPx: toCssPx, swallowDoubleClick: swallowDoubleClick |
| 354 } |
| 355 }); |
| 13 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 356 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 14 // Use of this source code is governed by a BSD-style license that can be | 357 // Use of this source code is governed by a BSD-style license that can be |
| 15 // found in the LICENSE file. | 358 // found in the LICENSE file. |
| 16 cr.define("cr.ui",function(){function KeyboardShortcut(shortcut){var mods={};var
ident="";shortcut.split("|").forEach(function(part){var partLc=part.toLowerCase
();switch(partLc){case"alt":case"ctrl":case"meta":case"shift":mods[partLc+"Key"]
=true;break;default:if(ident)throw Error("Invalid shortcut");ident=part}});this.
ident_=ident;this.mods_=mods}KeyboardShortcut.prototype={matchesEvent:function(e
){if(e.key==this.ident_){var mods=this.mods_;return["altKey","ctrlKey","metaKey"
,"shiftKey"].every(function(k){return e[k]==!!mods[k]})}return false}};var Comma
nd=cr.ui.define("command");Command.prototype={__proto__:HTMLElement.prototype,de
corate:function(){CommandManager.init(assert(this.ownerDocument));if(this.hasAtt
ribute("shortcut"))this.shortcut=this.getAttribute("shortcut")},execute:function
(opt_element){if(this.disabled)return;var doc=this.ownerDocument;if(doc.activeEl
ement){var e=new Event("command",{bubbles:true});e.command=this;(opt_element||do
c.activeElement).dispatchEvent(e)}},canExecuteChange:function(opt_node){dispatch
CanExecuteEvent(this,opt_node||this.ownerDocument.activeElement)},shortcut_:"",g
et shortcut(){return this.shortcut_},set shortcut(shortcut){var oldShortcut=this
.shortcut_;if(shortcut!==oldShortcut){this.keyboardShortcuts_=shortcut.split(/\s
+/).map(function(shortcut){return new KeyboardShortcut(shortcut)});this.shortcut
_=shortcut;cr.dispatchPropertyChange(this,"shortcut",this.shortcut_,oldShortcut)
}},matchesEvent:function(e){if(!this.keyboardShortcuts_)return false;return this
.keyboardShortcuts_.some(function(keyboardShortcut){return keyboardShortcut.matc
hesEvent(e)})}};cr.defineProperty(Command,"label",cr.PropertyKind.ATTR);cr.defin
eProperty(Command,"disabled",cr.PropertyKind.BOOL_ATTR);cr.defineProperty(Comman
d,"hidden",cr.PropertyKind.BOOL_ATTR);cr.defineProperty(Command,"checked",cr.Pro
pertyKind.BOOL_ATTR);cr.defineProperty(Command,"hideShortcutText",cr.PropertyKin
d.BOOL_ATTR);function dispatchCanExecuteEvent(command,target){var e=new CanExecu
teEvent(command);target.dispatchEvent(e);command.disabled=!e.canExecute}var comm
andManagers={};function CommandManager(doc){doc.addEventListener("focus",this.ha
ndleFocus_.bind(this),true);doc.addEventListener("keydown",this.handleKeyDown_.b
ind(this),false)}CommandManager.init=function(doc){var uid=cr.getUid(doc);if(!(u
id in commandManagers)){commandManagers[uid]=new CommandManager(doc)}};CommandMa
nager.prototype={handleFocus_:function(e){var target=e.target;if(target.menu||ta
rget.command)return;var commands=Array.prototype.slice.call(target.ownerDocument
.querySelectorAll("command"));commands.forEach(function(command){dispatchCanExec
uteEvent(command,target)})},handleKeyDown_:function(e){var target=e.target;var c
ommands=Array.prototype.slice.call(target.ownerDocument.querySelectorAll("comman
d"));for(var i=0,command;command=commands[i];i++){if(command.matchesEvent(e)){co
mmand.canExecuteChange();if(!command.disabled){e.preventDefault();e.stopPropagat
ion();command.execute();return}}}}};function CanExecuteEvent(command){var e=new
Event("canExecute",{bubbles:true,cancelable:true});e.__proto__=CanExecuteEvent.p
rototype;e.command=command;return e}CanExecuteEvent.prototype={__proto__:Event.p
rototype,command:null,canExecute_:false,get canExecute(){return this.canExecute_
},set canExecute(canExecute){this.canExecute_=!!canExecute;this.stopPropagation(
);this.preventDefault()}};return{Command:Command,CanExecuteEvent:CanExecuteEvent
}});Polymer({is:"iron-media-query",properties:{queryMatches:{type:Boolean,value:
false,readOnly:true,notify:true},query:{type:String,observer:"queryChanged"},ful
l:{type:Boolean,value:false},_boundMQHandler:{value:function(){return this.query
Handler.bind(this)}},_mq:{value:null}},attached:function(){this.style.display="n
one";this.queryChanged()},detached:function(){this._remove()},_add:function(){if
(this._mq){this._mq.addListener(this._boundMQHandler)}},_remove:function(){if(th
is._mq){this._mq.removeListener(this._boundMQHandler)}this._mq=null},queryChange
d:function(){this._remove();var query=this.query;if(!query){return}if(!this.full
&&query[0]!=="("){query="("+query+")"}this._mq=window.matchMedia(query);this._ad
d();this.queryHandler(this._mq)},queryHandler:function(mq){this._setQueryMatches
(mq.matches)}});Polymer.IronResizableBehavior={properties:{_parentResizable:{typ
e:Object,observer:"_parentResizableChanged"},_notifyingDescendant:{type:Boolean,
value:false}},listeners:{"iron-request-resize-notifications":"_onIronRequestResi
zeNotifications"},created:function(){this._interestedResizables=[];this._boundNo
tifyResize=this.notifyResize.bind(this)},attached:function(){this.fire("iron-req
uest-resize-notifications",null,{node:this,bubbles:true,cancelable:true});if(!th
is._parentResizable){window.addEventListener("resize",this._boundNotifyResize);t
his.notifyResize()}},detached:function(){if(this._parentResizable){this._parentR
esizable.stopResizeNotificationsFor(this)}else{window.removeEventListener("resiz
e",this._boundNotifyResize)}this._parentResizable=null},notifyResize:function(){
if(!this.isAttached){return}this._interestedResizables.forEach(function(resizabl
e){if(this.resizerShouldNotify(resizable)){this._notifyDescendant(resizable)}},t
his);this._fireResize()},assignParentResizable:function(parentResizable){this._p
arentResizable=parentResizable},stopResizeNotificationsFor:function(target){var
index=this._interestedResizables.indexOf(target);if(index>-1){this._interestedRe
sizables.splice(index,1);this.unlisten(target,"iron-resize","_onDescendantIronRe
size")}},resizerShouldNotify:function(element){return true},_onDescendantIronRes
ize:function(event){if(this._notifyingDescendant){event.stopPropagation();return
}if(!Polymer.Settings.useShadow){this._fireResize()}},_fireResize:function(){thi
s.fire("iron-resize",null,{node:this,bubbles:false})},_onIronRequestResizeNotifi
cations:function(event){var target=event.path?event.path[0]:event.target;if(targ
et===this){return}if(this._interestedResizables.indexOf(target)===-1){this._inte
restedResizables.push(target);this.listen(target,"iron-resize","_onDescendantIro
nResize")}target.assignParentResizable(this);this._notifyDescendant(target);even
t.stopPropagation()},_parentResizableChanged:function(parentResizable){if(parent
Resizable){window.removeEventListener("resize",this._boundNotifyResize)}},_notif
yDescendant:function(descendant){if(!this.isAttached){return}this._notifyingDesc
endant=true;descendant.notifyResize();this._notifyingDescendant=false}};Polymer.
IronSelection=function(selectCallback){this.selection=[];this.selectCallback=sel
ectCallback};Polymer.IronSelection.prototype={get:function(){return this.multi?t
his.selection.slice():this.selection[0]},clear:function(excludes){this.selection
.slice().forEach(function(item){if(!excludes||excludes.indexOf(item)<0){this.set
ItemSelected(item,false)}},this)},isSelected:function(item){return this.selectio
n.indexOf(item)>=0},setItemSelected:function(item,isSelected){if(item!=null){if(
isSelected!==this.isSelected(item)){if(isSelected){this.selection.push(item)}els
e{var i=this.selection.indexOf(item);if(i>=0){this.selection.splice(i,1)}}if(thi
s.selectCallback){this.selectCallback(item,isSelected)}}}},select:function(item)
{if(this.multi){this.toggle(item)}else if(this.get()!==item){this.setItemSelecte
d(this.get(),false);this.setItemSelected(item,true)}},toggle:function(item){this
.setItemSelected(item,!this.isSelected(item))}};Polymer.IronSelectableBehavior={
properties:{attrForSelected:{type:String,value:null},selected:{type:String,notif
y:true},selectedItem:{type:Object,readOnly:true,notify:true},activateEvent:{type
:String,value:"tap",observer:"_activateEventChanged"},selectable:String,selected
Class:{type:String,value:"iron-selected"},selectedAttribute:{type:String,value:n
ull},fallbackSelection:{type:String,value:null},items:{type:Array,readOnly:true,
notify:true,value:function(){return[]}},_excludedLocalNames:{type:Object,value:f
unction(){return{template:1}}}},observers:["_updateAttrForSelected(attrForSelect
ed)","_updateSelected(selected)","_checkFallback(fallbackSelection)"],created:fu
nction(){this._bindFilterItem=this._filterItem.bind(this);this._selection=new Po
lymer.IronSelection(this._applySelection.bind(this))},attached:function(){this._
observer=this._observeItems(this);this._updateItems();if(!this._shouldUpdateSele
ction){this._updateSelected()}this._addListener(this.activateEvent)},detached:fu
nction(){if(this._observer){Polymer.dom(this).unobserveNodes(this._observer)}thi
s._removeListener(this.activateEvent)},indexOf:function(item){return this.items.
indexOf(item)},select:function(value){this.selected=value},selectPrevious:functi
on(){var length=this.items.length;var index=(Number(this._valueToIndex(this.sele
cted))-1+length)%length;this.selected=this._indexToValue(index)},selectNext:func
tion(){var index=(Number(this._valueToIndex(this.selected))+1)%this.items.length
;this.selected=this._indexToValue(index)},selectIndex:function(index){this.selec
t(this._indexToValue(index))},forceSynchronousItemUpdate:function(){this._update
Items()},get _shouldUpdateSelection(){return this.selected!=null},_checkFallback
:function(){if(this._shouldUpdateSelection){this._updateSelected()}},_addListene
r:function(eventName){this.listen(this,eventName,"_activateHandler")},_removeLis
tener:function(eventName){this.unlisten(this,eventName,"_activateHandler")},_act
ivateEventChanged:function(eventName,old){this._removeListener(old);this._addLis
tener(eventName)},_updateItems:function(){var nodes=Polymer.dom(this).queryDistr
ibutedElements(this.selectable||"*");nodes=Array.prototype.filter.call(nodes,thi
s._bindFilterItem);this._setItems(nodes)},_updateAttrForSelected:function(){if(t
his._shouldUpdateSelection){this.selected=this._indexToValue(this.indexOf(this.s
electedItem))}},_updateSelected:function(){this._selectSelected(this.selected)},
_selectSelected:function(selected){this._selection.select(this._valueToItem(this
.selected));if(this.fallbackSelection&&this.items.length&&this._selection.get()=
==undefined){this.selected=this.fallbackSelection}},_filterItem:function(node){r
eturn!this._excludedLocalNames[node.localName]},_valueToItem:function(value){ret
urn value==null?null:this.items[this._valueToIndex(value)]},_valueToIndex:functi
on(value){if(this.attrForSelected){for(var i=0,item;item=this.items[i];i++){if(t
his._valueForItem(item)==value){return i}}}else{return Number(value)}},_indexToV
alue:function(index){if(this.attrForSelected){var item=this.items[index];if(item
){return this._valueForItem(item)}}else{return index}},_valueForItem:function(it
em){var propValue=item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)];re
turn propValue!=undefined?propValue:item.getAttribute(this.attrForSelected)},_ap
plySelection:function(item,isSelected){if(this.selectedClass){this.toggleClass(t
his.selectedClass,isSelected,item)}if(this.selectedAttribute){this.toggleAttribu
te(this.selectedAttribute,isSelected,item)}this._selectionChange();this.fire("ir
on-"+(isSelected?"select":"deselect"),{item:item})},_selectionChange:function(){
this._setSelectedItem(this._selection.get())},_observeItems:function(node){retur
n Polymer.dom(node).observeNodes(function(mutation){this._updateItems();if(this.
_shouldUpdateSelection){this._updateSelected()}this.fire("iron-items-changed",mu
tation,{bubbles:false,cancelable:false})})},_activateHandler:function(e){var t=e
.target;var items=this.items;while(t&&t!=this){var i=items.indexOf(t);if(i>=0){v
ar value=this._indexToValue(i);this._itemActivate(value,t);return}t=t.parentNode
}},_itemActivate:function(value,item){if(!this.fire("iron-activate",{selected:va
lue,item:item},{cancelable:true}).defaultPrevented){this.select(value)}}};Polyme
r({is:"iron-pages",behaviors:[Polymer.IronResizableBehavior,Polymer.IronSelectab
leBehavior],properties:{activateEvent:{type:String,value:null}},observers:["_sel
ectedPageChanged(selected)"],_selectedPageChanged:function(selected,old){this.as
ync(this.notifyResize)}});Polymer.IronScrollTargetBehavior={properties:{scrollTa
rget:{type:HTMLElement,value:function(){return this._defaultScrollTarget}}},obse
rvers:["_scrollTargetChanged(scrollTarget, isAttached)"],_shouldHaveListener:tru
e,_scrollTargetChanged:function(scrollTarget,isAttached){var eventTarget;if(this
._oldScrollTarget){this._toggleScrollListener(false,this._oldScrollTarget);this.
_oldScrollTarget=null}if(!isAttached){return}if(scrollTarget==="document"){this.
scrollTarget=this._doc}else if(typeof scrollTarget==="string"){this.scrollTarget
=this.domHost?this.domHost.$[scrollTarget]:Polymer.dom(this.ownerDocument).query
Selector("#"+scrollTarget)}else if(this._isValidScrollTarget()){this._boundScrol
lHandler=this._boundScrollHandler||this._scrollHandler.bind(this);this._oldScrol
lTarget=scrollTarget;this._toggleScrollListener(this._shouldHaveListener,scrollT
arget)}},_scrollHandler:function scrollHandler(){},get _defaultScrollTarget(){re
turn this._doc},get _doc(){return this.ownerDocument.documentElement},get _scrol
lTop(){if(this._isValidScrollTarget()){return this.scrollTarget===this._doc?wind
ow.pageYOffset:this.scrollTarget.scrollTop}return 0},get _scrollLeft(){if(this._
isValidScrollTarget()){return this.scrollTarget===this._doc?window.pageXOffset:t
his.scrollTarget.scrollLeft}return 0},set _scrollTop(top){if(this.scrollTarget==
=this._doc){window.scrollTo(window.pageXOffset,top)}else if(this._isValidScrollT
arget()){this.scrollTarget.scrollTop=top}},set _scrollLeft(left){if(this.scrollT
arget===this._doc){window.scrollTo(left,window.pageYOffset)}else if(this._isVali
dScrollTarget()){this.scrollTarget.scrollLeft=left}},scroll:function(left,top){i
f(this.scrollTarget===this._doc){window.scrollTo(left,top)}else if(this._isValid
ScrollTarget()){this.scrollTarget.scrollLeft=left;this.scrollTarget.scrollTop=to
p}},get _scrollTargetWidth(){if(this._isValidScrollTarget()){return this.scrollT
arget===this._doc?window.innerWidth:this.scrollTarget.offsetWidth}return 0},get
_scrollTargetHeight(){if(this._isValidScrollTarget()){return this.scrollTarget==
=this._doc?window.innerHeight:this.scrollTarget.offsetHeight}return 0},_isValidS
crollTarget:function(){return this.scrollTarget instanceof HTMLElement},_toggleS
crollListener:function(yes,scrollTarget){if(!this._boundScrollHandler){return}va
r eventTarget=scrollTarget===this._doc?window:scrollTarget;if(yes){eventTarget.a
ddEventListener("scroll",this._boundScrollHandler)}else{eventTarget.removeEventL
istener("scroll",this._boundScrollHandler)}},toggleScrollListener:function(yes){
this._shouldHaveListener=yes;this._toggleScrollListener(yes,this.scrollTarget)}}
;(function(){var metaDatas={};var metaArrays={};var singleton=null;Polymer.IronM
eta=Polymer({is:"iron-meta",properties:{type:{type:String,value:"default",observ
er:"_typeChanged"},key:{type:String,observer:"_keyChanged"},value:{type:Object,n
otify:true,observer:"_valueChanged"},self:{type:Boolean,observer:"_selfChanged"}
,list:{type:Array,notify:true}},hostAttributes:{hidden:true},factoryImpl:functio
n(config){if(config){for(var n in config){switch(n){case"type":case"key":case"va
lue":this[n]=config[n];break}}}},created:function(){this._metaDatas=metaDatas;th
is._metaArrays=metaArrays},_keyChanged:function(key,old){this._resetRegistration
(old)},_valueChanged:function(value){this._resetRegistration(this.key)},_selfCha
nged:function(self){if(self){this.value=this}},_typeChanged:function(type){this.
_unregisterKey(this.key);if(!metaDatas[type]){metaDatas[type]={}}this._metaData=
metaDatas[type];if(!metaArrays[type]){metaArrays[type]=[]}this.list=metaArrays[t
ype];this._registerKeyValue(this.key,this.value)},byKey:function(key){return thi
s._metaData&&this._metaData[key]},_resetRegistration:function(oldKey){this._unre
gisterKey(oldKey);this._registerKeyValue(this.key,this.value)},_unregisterKey:fu
nction(key){this._unregister(key,this._metaData,this.list)},_registerKeyValue:fu
nction(key,value){this._register(key,value,this._metaData,this.list)},_register:
function(key,value,data,list){if(key&&data&&value!==undefined){data[key]=value;l
ist.push(value)}},_unregister:function(key,data,list){if(key&&data){if(key in da
ta){var value=data[key];delete data[key];this.arrayDelete(list,value)}}}});Polym
er.IronMeta.getIronMeta=function getIronMeta(){if(singleton===null){singleton=ne
w Polymer.IronMeta}return singleton};Polymer.IronMetaQuery=Polymer({is:"iron-met
a-query",properties:{type:{type:String,value:"default",observer:"_typeChanged"},
key:{type:String,observer:"_keyChanged"},value:{type:Object,notify:true,readOnly
:true},list:{type:Array,notify:true}},factoryImpl:function(config){if(config){fo
r(var n in config){switch(n){case"type":case"key":this[n]=config[n];break}}}},cr
eated:function(){this._metaDatas=metaDatas;this._metaArrays=metaArrays},_keyChan
ged:function(key){this._setValue(this._metaData&&this._metaData[key])},_typeChan
ged:function(type){this._metaData=metaDatas[type];this.list=metaArrays[type];if(
this.key){this._keyChanged(this.key)}},byKey:function(key){return this._metaData
&&this._metaData[key]}})})();Polymer({is:"iron-icon",properties:{icon:{type:Stri
ng,observer:"_iconChanged"},theme:{type:String,observer:"_updateIcon"},src:{type
:String,observer:"_srcChanged"},_meta:{value:Polymer.Base.create("iron-meta",{ty
pe:"iconset"}),observer:"_updateIcon"}},_DEFAULT_ICONSET:"icons",_iconChanged:fu
nction(icon){var parts=(icon||"").split(":");this._iconName=parts.pop();this._ic
onsetName=parts.pop()||this._DEFAULT_ICONSET;this._updateIcon()},_srcChanged:fun
ction(src){this._updateIcon()},_usesIconset:function(){return this.icon||!this.s
rc},_updateIcon:function(){if(this._usesIconset()){if(this._img&&this._img.paren
tNode){Polymer.dom(this.root).removeChild(this._img)}if(this._iconName===""){if(
this._iconset){this._iconset.removeIcon(this)}}else if(this._iconsetName&&this._
meta){this._iconset=this._meta.byKey(this._iconsetName);if(this._iconset){this._
iconset.applyIcon(this,this._iconName,this.theme);this.unlisten(window,"iron-ico
nset-added","_updateIcon")}else{this.listen(window,"iron-iconset-added","_update
Icon")}}}else{if(this._iconset){this._iconset.removeIcon(this)}if(!this._img){th
is._img=document.createElement("img");this._img.style.width="100%";this._img.sty
le.height="100%";this._img.draggable=false}this._img.src=this.src;Polymer.dom(th
is.root).appendChild(this._img)}}});Polymer({is:"iron-iconset-svg",properties:{n
ame:{type:String,observer:"_nameChanged"},size:{type:Number,value:24},rtlMirrori
ng:{type:Boolean,value:false}},_targetIsRTL:function(target){if(target&&target.n
odeType!==Node.ELEMENT_NODE){target=target.host}return target&&window.getCompute
dStyle(target)["direction"]==="rtl"},attached:function(){this.style.display="non
e"},getIconNames:function(){this._icons=this._createIconMap();return Object.keys
(this._icons).map(function(n){return this.name+":"+n},this)},applyIcon:function(
element,iconName){element=element.root||element;this.removeIcon(element);var svg
=this._cloneIcon(iconName,this.rtlMirroring&&this._targetIsRTL(element));if(svg)
{var pde=Polymer.dom(element);pde.insertBefore(svg,pde.childNodes[0]);return ele
ment._svgIcon=svg}return null},removeIcon:function(element){element=element.root
||element;if(element._svgIcon){Polymer.dom(element).removeChild(element._svgIcon
);element._svgIcon=null}},_nameChanged:function(){new Polymer.IronMeta({type:"ic
onset",key:this.name,value:this});this.async(function(){this.fire("iron-iconset-
added",this,{node:window})})},_createIconMap:function(){var icons=Object.create(
null);Polymer.dom(this).querySelectorAll("[id]").forEach(function(icon){icons[ic
on.id]=icon});return icons},_cloneIcon:function(id,mirrorAllowed){this._icons=th
is._icons||this._createIconMap();return this._prepareSvgClone(this._icons[id],th
is.size,mirrorAllowed)},_prepareSvgClone:function(sourceSvg,size,mirrorAllowed){
if(sourceSvg){var content=sourceSvg.cloneNode(true),svg=document.createElementNS
("http://www.w3.org/2000/svg","svg"),viewBox=content.getAttribute("viewBox")||"0
0 "+size+" "+size,cssText="pointer-events: none; display: block; width: 100%; h
eight: 100%;";if(mirrorAllowed&&content.hasAttribute("mirror-in-rtl")){cssText+=
"-webkit-transform:scale(-1,1);transform:scale(-1,1);"}svg.setAttribute("viewBox
",viewBox);svg.setAttribute("preserveAspectRatio","xMidYMid meet");svg.style.css
Text=cssText;svg.appendChild(content).removeAttribute("id");return svg}return nu
ll}}); | 359 cr.define("cr.ui", function() { |
| 360 function KeyboardShortcut(shortcut) { |
| 361 var mods = {}; |
| 362 var ident = ""; |
| 363 shortcut.split("|").forEach(function(part) { |
| 364 var partLc = part.toLowerCase(); |
| 365 switch (partLc) { |
| 366 case "alt": |
| 367 case "ctrl": |
| 368 case "meta": |
| 369 case "shift": |
| 370 mods[partLc + "Key"] = true; |
| 371 break; |
| 372 default: |
| 373 if (ident) |
| 374 throw Error("Invalid shortcut"); |
| 375 ident = part |
| 376 } |
| 377 }); |
| 378 this.ident_ = ident; |
| 379 this.mods_ = mods |
| 380 } |
| 381 KeyboardShortcut.prototype = { |
| 382 matchesEvent: function(e) { |
| 383 if (e.key == this.ident_) { |
| 384 var mods = this.mods_; |
| 385 return ["altKey", "ctrlKey", "metaKey", "shiftKey"].every(function(k) { |
| 386 return e[k] == !!mods[k] |
| 387 }) |
| 388 } |
| 389 return false |
| 390 } |
| 391 }; |
| 392 var Command = cr.ui.define("command"); |
| 393 Command.prototype = { |
| 394 __proto__: HTMLElement.prototype, |
| 395 decorate: function() { |
| 396 CommandManager.init(assert(this.ownerDocument)); |
| 397 if (this.hasAttribute("shortcut")) |
| 398 this.shortcut = this.getAttribute("shortcut") |
| 399 }, |
| 400 execute: function(opt_element) { |
| 401 if (this.disabled) |
| 402 return; |
| 403 var doc = this.ownerDocument; |
| 404 if (doc.activeElement) { |
| 405 var e = new Event("command", {bubbles: true}); |
| 406 e.command = this; |
| 407 (opt_element || doc.activeElement).dispatchEvent(e) |
| 408 } |
| 409 }, |
| 410 canExecuteChange: function(opt_node) { |
| 411 dispatchCanExecuteEvent( |
| 412 this, opt_node || this.ownerDocument.activeElement) |
| 413 }, |
| 414 shortcut_: "", |
| 415 get shortcut() { |
| 416 return this.shortcut_ |
| 417 }, |
| 418 set shortcut(shortcut) { |
| 419 var oldShortcut = this.shortcut_; |
| 420 if (shortcut !== oldShortcut) { |
| 421 this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) { |
| 422 return new KeyboardShortcut(shortcut) |
| 423 }); |
| 424 this.shortcut_ = shortcut; |
| 425 cr.dispatchPropertyChange(this, "shortcut", this.shortcut_, oldShortcut) |
| 426 } |
| 427 }, |
| 428 matchesEvent: function(e) { |
| 429 if (!this.keyboardShortcuts_) |
| 430 return false; |
| 431 return this.keyboardShortcuts_.some(function(keyboardShortcut) { |
| 432 return keyboardShortcut.matchesEvent(e) |
| 433 }) |
| 434 } |
| 435 }; |
| 436 cr.defineProperty(Command, "label", cr.PropertyKind.ATTR); |
| 437 cr.defineProperty(Command, "disabled", cr.PropertyKind.BOOL_ATTR); |
| 438 cr.defineProperty(Command, "hidden", cr.PropertyKind.BOOL_ATTR); |
| 439 cr.defineProperty(Command, "checked", cr.PropertyKind.BOOL_ATTR); |
| 440 cr.defineProperty(Command, "hideShortcutText", cr.PropertyKind.BOOL_ATTR); |
| 441 function dispatchCanExecuteEvent(command, target) { |
| 442 var e = new CanExecuteEvent(command); |
| 443 target.dispatchEvent(e); |
| 444 command.disabled = !e.canExecute |
| 445 } |
| 446 var commandManagers = {}; |
| 447 function CommandManager(doc) { |
| 448 doc.addEventListener("focus", this.handleFocus_.bind(this), true); |
| 449 doc.addEventListener("keydown", this.handleKeyDown_.bind(this), false) |
| 450 } |
| 451 CommandManager.init = function(doc) { |
| 452 var uid = cr.getUid(doc); |
| 453 if (!(uid in commandManagers)) { |
| 454 commandManagers[uid] = new CommandManager(doc) |
| 455 } |
| 456 }; |
| 457 CommandManager.prototype = { |
| 458 handleFocus_: function(e) { |
| 459 var target = e.target; |
| 460 if (target.menu || target.command) |
| 461 return; |
| 462 var commands = Array.prototype.slice.call( |
| 463 target.ownerDocument.querySelectorAll("command")); |
| 464 commands.forEach(function(command) { |
| 465 dispatchCanExecuteEvent(command, target) |
| 466 }) |
| 467 }, |
| 468 handleKeyDown_: function(e) { |
| 469 var target = e.target; |
| 470 var commands = Array.prototype.slice.call( |
| 471 target.ownerDocument.querySelectorAll("command")); |
| 472 for (var i = 0, command; command = commands[i]; i++) { |
| 473 if (command.matchesEvent(e)) { |
| 474 command.canExecuteChange(); |
| 475 if (!command.disabled) { |
| 476 e.preventDefault(); |
| 477 e.stopPropagation(); |
| 478 command.execute(); |
| 479 return |
| 480 } |
| 481 } |
| 482 } |
| 483 } |
| 484 }; |
| 485 function CanExecuteEvent(command) { |
| 486 var e = new Event("canExecute", {bubbles: true, cancelable: true}); |
| 487 e.__proto__ = CanExecuteEvent.prototype; |
| 488 e.command = command; |
| 489 return e |
| 490 } |
| 491 CanExecuteEvent.prototype = { |
| 492 __proto__: Event.prototype, |
| 493 command: null, |
| 494 canExecute_: false, |
| 495 get canExecute() { |
| 496 return this.canExecute_ |
| 497 }, |
| 498 set canExecute(canExecute) { |
| 499 this.canExecute_ = !!canExecute; |
| 500 this.stopPropagation(); |
| 501 this.preventDefault() |
| 502 } |
| 503 }; |
| 504 return { |
| 505 Command: Command, CanExecuteEvent: CanExecuteEvent |
| 506 } |
| 507 }); |
| 508 Polymer({ |
| 509 is: "iron-media-query", |
| 510 properties: { |
| 511 queryMatches: {type: Boolean, value: false, readOnly: true, notify: true}, |
| 512 query: {type: String, observer: "queryChanged"}, |
| 513 full: {type: Boolean, value: false}, |
| 514 _boundMQHandler: { |
| 515 value: function() { |
| 516 return this.queryHandler.bind(this) |
| 517 } |
| 518 }, |
| 519 _mq: {value: null} |
| 520 }, |
| 521 attached: function() { |
| 522 this.style.display = "none"; |
| 523 this.queryChanged() |
| 524 }, |
| 525 detached: function() { |
| 526 this._remove() |
| 527 }, |
| 528 _add: function() { |
| 529 if (this._mq) { |
| 530 this._mq.addListener(this._boundMQHandler) |
| 531 } |
| 532 }, |
| 533 _remove: function() { |
| 534 if (this._mq) { |
| 535 this._mq.removeListener(this._boundMQHandler) |
| 536 } |
| 537 this._mq = null |
| 538 }, |
| 539 queryChanged: function() { |
| 540 this._remove(); |
| 541 var query = this.query; |
| 542 if (!query) { |
| 543 return |
| 544 } |
| 545 if (!this.full && query[0] !== "(") { |
| 546 query = "(" + query + ")" |
| 547 } |
| 548 this._mq = window.matchMedia(query); |
| 549 this._add(); |
| 550 this.queryHandler(this._mq) |
| 551 }, |
| 552 queryHandler: function(mq) { |
| 553 this._setQueryMatches(mq.matches) |
| 554 } |
| 555 }); |
| 556 Polymer.IronResizableBehavior = { |
| 557 properties: { |
| 558 _parentResizable: {type: Object, observer: "_parentResizableChanged"}, |
| 559 _notifyingDescendant: {type: Boolean, value: false} |
| 560 }, |
| 561 listeners: { |
| 562 "iron-request-resize-notifications": "_onIronRequestResizeNotifications" |
| 563 }, |
| 564 created: function() { |
| 565 this._interestedResizables = []; |
| 566 this._boundNotifyResize = this.notifyResize.bind(this) |
| 567 }, |
| 568 attached: function() { |
| 569 this.fire( |
| 570 "iron-request-resize-notifications", null, |
| 571 {node: this, bubbles: true, cancelable: true}); |
| 572 if (!this._parentResizable) { |
| 573 window.addEventListener("resize", this._boundNotifyResize); |
| 574 this.notifyResize() |
| 575 } |
| 576 }, |
| 577 detached: function() { |
| 578 if (this._parentResizable) { |
| 579 this._parentResizable.stopResizeNotificationsFor(this) |
| 580 } else { |
| 581 window.removeEventListener("resize", this._boundNotifyResize) |
| 582 } |
| 583 this._parentResizable = null |
| 584 }, |
| 585 notifyResize: function() { |
| 586 if (!this.isAttached) { |
| 587 return |
| 588 } |
| 589 this._interestedResizables.forEach(function(resizable) { |
| 590 if (this.resizerShouldNotify(resizable)) { |
| 591 this._notifyDescendant(resizable) |
| 592 } |
| 593 }, this); |
| 594 this._fireResize() |
| 595 }, |
| 596 assignParentResizable: function(parentResizable) { |
| 597 this._parentResizable = parentResizable |
| 598 }, |
| 599 stopResizeNotificationsFor: function(target) { |
| 600 var index = this._interestedResizables.indexOf(target); |
| 601 if (index > -1) { |
| 602 this._interestedResizables.splice(index, 1); |
| 603 this.unlisten(target, "iron-resize", "_onDescendantIronResize") |
| 604 } |
| 605 }, |
| 606 resizerShouldNotify: function(element) { |
| 607 return true |
| 608 }, |
| 609 _onDescendantIronResize: function(event) { |
| 610 if (this._notifyingDescendant) { |
| 611 event.stopPropagation(); |
| 612 return |
| 613 } |
| 614 if (!Polymer.Settings.useShadow) { |
| 615 this._fireResize() |
| 616 } |
| 617 }, |
| 618 _fireResize: function() { |
| 619 this.fire("iron-resize", null, {node: this, bubbles: false}) |
| 620 }, |
| 621 _onIronRequestResizeNotifications: function(event) { |
| 622 var target = event.path ? event.path[0] : event.target; |
| 623 if (target === this) { |
| 624 return |
| 625 } |
| 626 if (this._interestedResizables.indexOf(target) === -1) { |
| 627 this._interestedResizables.push(target); |
| 628 this.listen(target, "iron-resize", "_onDescendantIronResize") |
| 629 } |
| 630 target.assignParentResizable(this); |
| 631 this._notifyDescendant(target); |
| 632 event.stopPropagation() |
| 633 }, |
| 634 _parentResizableChanged: function(parentResizable) { |
| 635 if (parentResizable) { |
| 636 window.removeEventListener("resize", this._boundNotifyResize) |
| 637 } |
| 638 }, |
| 639 _notifyDescendant: function(descendant) { |
| 640 if (!this.isAttached) { |
| 641 return |
| 642 } |
| 643 this._notifyingDescendant = true; |
| 644 descendant.notifyResize(); |
| 645 this._notifyingDescendant = false |
| 646 } |
| 647 }; |
| 648 Polymer.IronSelection = function(selectCallback) { |
| 649 this.selection = []; |
| 650 this.selectCallback = selectCallback |
| 651 }; |
| 652 Polymer.IronSelection.prototype = { |
| 653 get: function() { |
| 654 return this.multi ? this.selection.slice() : this.selection[0] |
| 655 }, |
| 656 clear: function(excludes) { |
| 657 this.selection.slice().forEach(function(item) { |
| 658 if (!excludes || excludes.indexOf(item) < 0) { |
| 659 this.setItemSelected(item, false) |
| 660 } |
| 661 }, this) |
| 662 }, |
| 663 isSelected: function(item) { |
| 664 return this.selection.indexOf(item) >= 0 |
| 665 }, |
| 666 setItemSelected: function(item, isSelected) { |
| 667 if (item != null) { |
| 668 if (isSelected !== this.isSelected(item)) { |
| 669 if (isSelected) { |
| 670 this.selection.push(item) |
| 671 } else { |
| 672 var i = this.selection.indexOf(item); |
| 673 if (i >= 0) { |
| 674 this.selection.splice(i, 1) |
| 675 } |
| 676 } |
| 677 if (this.selectCallback) { |
| 678 this.selectCallback(item, isSelected) |
| 679 } |
| 680 } |
| 681 } |
| 682 }, |
| 683 select: function(item) { |
| 684 if (this.multi) { |
| 685 this.toggle(item) |
| 686 } else if (this.get() !== item) { |
| 687 this.setItemSelected(this.get(), false); |
| 688 this.setItemSelected(item, true) |
| 689 } |
| 690 }, |
| 691 toggle: function(item) { |
| 692 this.setItemSelected(item, !this.isSelected(item)) |
| 693 } |
| 694 }; |
| 695 Polymer.IronSelectableBehavior = { |
| 696 properties: { |
| 697 attrForSelected: {type: String, value: null}, |
| 698 selected: {type: String, notify: true}, |
| 699 selectedItem: {type: Object, readOnly: true, notify: true}, |
| 700 activateEvent: |
| 701 {type: String, value: "tap", observer: "_activateEventChanged"}, |
| 702 selectable: String, |
| 703 selectedClass: {type: String, value: "iron-selected"}, |
| 704 selectedAttribute: {type: String, value: null}, |
| 705 fallbackSelection: {type: String, value: null}, |
| 706 items: { |
| 707 type: Array, |
| 708 readOnly: true, |
| 709 notify: true, |
| 710 value: function() { |
| 711 return [] |
| 712 } |
| 713 }, |
| 714 _excludedLocalNames: { |
| 715 type: Object, |
| 716 value: function() { |
| 717 return { |
| 718 template: 1 |
| 719 } |
| 720 } |
| 721 } |
| 722 }, |
| 723 observers: [ |
| 724 "_updateAttrForSelected(attrForSelected)", "_updateSelected(selected)", |
| 725 "_checkFallback(fallbackSelection)" |
| 726 ], |
| 727 created: function() { |
| 728 this._bindFilterItem = this._filterItem.bind(this); |
| 729 this._selection = new Polymer.IronSelection(this._applySelection.bind(this)) |
| 730 }, |
| 731 attached: function() { |
| 732 this._observer = this._observeItems(this); |
| 733 this._updateItems(); |
| 734 if (!this._shouldUpdateSelection) { |
| 735 this._updateSelected() |
| 736 } |
| 737 this._addListener(this.activateEvent) |
| 738 }, |
| 739 detached: function() { |
| 740 if (this._observer) { |
| 741 Polymer.dom(this).unobserveNodes(this._observer) |
| 742 } |
| 743 this._removeListener(this.activateEvent) |
| 744 }, |
| 745 indexOf: function(item) { |
| 746 return this.items.indexOf(item) |
| 747 }, |
| 748 select: function(value) { |
| 749 this.selected = value |
| 750 }, |
| 751 selectPrevious: function() { |
| 752 var length = this.items.length; |
| 753 var index = |
| 754 (Number(this._valueToIndex(this.selected)) - 1 + length) % length; |
| 755 this.selected = this._indexToValue(index) |
| 756 }, |
| 757 selectNext: function() { |
| 758 var index = |
| 759 (Number(this._valueToIndex(this.selected)) + 1) % this.items.length; |
| 760 this.selected = this._indexToValue(index) |
| 761 }, |
| 762 selectIndex: function(index) { |
| 763 this.select(this._indexToValue(index)) |
| 764 }, |
| 765 forceSynchronousItemUpdate: function() { |
| 766 this._updateItems() |
| 767 }, |
| 768 get _shouldUpdateSelection() { |
| 769 return this.selected != null |
| 770 }, |
| 771 _checkFallback: function() { |
| 772 if (this._shouldUpdateSelection) { |
| 773 this._updateSelected() |
| 774 } |
| 775 }, |
| 776 _addListener: function(eventName) { |
| 777 this.listen(this, eventName, "_activateHandler") |
| 778 }, |
| 779 _removeListener: function(eventName) { |
| 780 this.unlisten(this, eventName, "_activateHandler") |
| 781 }, |
| 782 _activateEventChanged: function(eventName, old) { |
| 783 this._removeListener(old); |
| 784 this._addListener(eventName) |
| 785 }, |
| 786 _updateItems: function() { |
| 787 var nodes = |
| 788 Polymer.dom(this).queryDistributedElements(this.selectable || "*"); |
| 789 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); |
| 790 this._setItems(nodes) |
| 791 }, |
| 792 _updateAttrForSelected: function() { |
| 793 if (this._shouldUpdateSelection) { |
| 794 this.selected = this._indexToValue(this.indexOf(this.selectedItem)) |
| 795 } |
| 796 }, |
| 797 _updateSelected: function() { |
| 798 this._selectSelected(this.selected) |
| 799 }, |
| 800 _selectSelected: function(selected) { |
| 801 this._selection.select(this._valueToItem(this.selected)); |
| 802 if (this.fallbackSelection && this.items.length && |
| 803 this._selection.get() === undefined) { |
| 804 this.selected = this.fallbackSelection |
| 805 } |
| 806 }, |
| 807 _filterItem: function(node) { |
| 808 return !this._excludedLocalNames[node.localName] |
| 809 }, |
| 810 _valueToItem: function(value) { |
| 811 return value == null ? null : this.items[this._valueToIndex(value)] |
| 812 }, |
| 813 _valueToIndex: function(value) { |
| 814 if (this.attrForSelected) { |
| 815 for (var i = 0, item; item = this.items[i]; i++) { |
| 816 if (this._valueForItem(item) == value) { |
| 817 return i |
| 818 } |
| 819 } |
| 820 } else { |
| 821 return Number(value) |
| 822 } |
| 823 }, |
| 824 _indexToValue: function(index) { |
| 825 if (this.attrForSelected) { |
| 826 var item = this.items[index]; |
| 827 if (item) { |
| 828 return this._valueForItem(item) |
| 829 } |
| 830 } else { |
| 831 return index |
| 832 } |
| 833 }, |
| 834 _valueForItem: function(item) { |
| 835 var propValue = item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)]; |
| 836 return propValue != undefined ? propValue : |
| 837 item.getAttribute(this.attrForSelected) |
| 838 }, |
| 839 _applySelection: function(item, isSelected) { |
| 840 if (this.selectedClass) { |
| 841 this.toggleClass(this.selectedClass, isSelected, item) |
| 842 } |
| 843 if (this.selectedAttribute) { |
| 844 this.toggleAttribute(this.selectedAttribute, isSelected, item) |
| 845 } |
| 846 this._selectionChange(); |
| 847 this.fire("iron-" + (isSelected ? "select" : "deselect"), {item: item}) |
| 848 }, |
| 849 _selectionChange: function() { |
| 850 this._setSelectedItem(this._selection.get()) |
| 851 }, |
| 852 _observeItems: function(node) { |
| 853 return Polymer.dom(node).observeNodes(function(mutation) { |
| 854 this._updateItems(); |
| 855 if (this._shouldUpdateSelection) { |
| 856 this._updateSelected() |
| 857 } |
| 858 this.fire( |
| 859 "iron-items-changed", mutation, {bubbles: false, cancelable: false}) |
| 860 }) |
| 861 }, |
| 862 _activateHandler: function(e) { |
| 863 var t = e.target; |
| 864 var items = this.items; |
| 865 while (t && t != this) { |
| 866 var i = items.indexOf(t); |
| 867 if (i >= 0) { |
| 868 var value = this._indexToValue(i); |
| 869 this._itemActivate(value, t); |
| 870 return |
| 871 } |
| 872 t = t.parentNode |
| 873 } |
| 874 }, |
| 875 _itemActivate: function(value, item) { |
| 876 if (!this.fire( |
| 877 "iron-activate", {selected: value, item: item}, |
| 878 {cancelable: true}) |
| 879 .defaultPrevented) { |
| 880 this.select(value) |
| 881 } |
| 882 } |
| 883 }; |
| 884 Polymer({ |
| 885 is: "iron-pages", |
| 886 behaviors: [Polymer.IronResizableBehavior, Polymer.IronSelectableBehavior], |
| 887 properties: {activateEvent: {type: String, value: null}}, |
| 888 observers: ["_selectedPageChanged(selected)"], |
| 889 _selectedPageChanged: function(selected, old) { |
| 890 this.async(this.notifyResize) |
| 891 } |
| 892 }); |
| 893 Polymer.IronScrollTargetBehavior = { |
| 894 properties: { |
| 895 scrollTarget: { |
| 896 type: HTMLElement, |
| 897 value: function() { |
| 898 return this._defaultScrollTarget |
| 899 } |
| 900 } |
| 901 }, |
| 902 observers: ["_scrollTargetChanged(scrollTarget, isAttached)"], |
| 903 _shouldHaveListener: true, |
| 904 _scrollTargetChanged: function(scrollTarget, isAttached) { |
| 905 var eventTarget; |
| 906 if (this._oldScrollTarget) { |
| 907 this._toggleScrollListener(false, this._oldScrollTarget); |
| 908 this._oldScrollTarget = null |
| 909 } |
| 910 if (!isAttached) { |
| 911 return |
| 912 } |
| 913 if (scrollTarget === "document") { |
| 914 this.scrollTarget = this._doc |
| 915 } else if (typeof scrollTarget === "string") { |
| 916 this.scrollTarget = this.domHost ? |
| 917 this.domHost.$[scrollTarget] : |
| 918 Polymer.dom(this.ownerDocument).querySelector("#" + scrollTarget) |
| 919 } else if (this._isValidScrollTarget()) { |
| 920 this._boundScrollHandler = |
| 921 this._boundScrollHandler || this._scrollHandler.bind(this); |
| 922 this._oldScrollTarget = scrollTarget; |
| 923 this._toggleScrollListener(this._shouldHaveListener, scrollTarget) |
| 924 } |
| 925 }, |
| 926 _scrollHandler: function scrollHandler() {}, |
| 927 get _defaultScrollTarget() { |
| 928 return this._doc |
| 929 }, |
| 930 get _doc() { |
| 931 return this.ownerDocument.documentElement |
| 932 }, |
| 933 get _scrollTop() { |
| 934 if (this._isValidScrollTarget()) { |
| 935 return this.scrollTarget === this._doc ? window.pageYOffset : |
| 936 this.scrollTarget.scrollTop |
| 937 } |
| 938 return 0 |
| 939 }, |
| 940 get _scrollLeft() { |
| 941 if (this._isValidScrollTarget()) { |
| 942 return this.scrollTarget === this._doc ? window.pageXOffset : |
| 943 this.scrollTarget.scrollLeft |
| 944 } |
| 945 return 0 |
| 946 }, |
| 947 set _scrollTop(top) { |
| 948 if (this.scrollTarget === this._doc) { |
| 949 window.scrollTo(window.pageXOffset, top) |
| 950 } else if (this._isValidScrollTarget()) { |
| 951 this.scrollTarget.scrollTop = top |
| 952 } |
| 953 }, |
| 954 set _scrollLeft(left) { |
| 955 if (this.scrollTarget === this._doc) { |
| 956 window.scrollTo(left, window.pageYOffset) |
| 957 } else if (this._isValidScrollTarget()) { |
| 958 this.scrollTarget.scrollLeft = left |
| 959 } |
| 960 }, |
| 961 scroll: function(left, top) { |
| 962 if (this.scrollTarget === this._doc) { |
| 963 window.scrollTo(left, top) |
| 964 } else if (this._isValidScrollTarget()) { |
| 965 this.scrollTarget.scrollLeft = left; |
| 966 this.scrollTarget.scrollTop = top |
| 967 } |
| 968 }, |
| 969 get _scrollTargetWidth() { |
| 970 if (this._isValidScrollTarget()) { |
| 971 return this.scrollTarget === this._doc ? window.innerWidth : |
| 972 this.scrollTarget.offsetWidth |
| 973 } |
| 974 return 0 |
| 975 }, |
| 976 get _scrollTargetHeight() { |
| 977 if (this._isValidScrollTarget()) { |
| 978 return this.scrollTarget === this._doc ? window.innerHeight : |
| 979 this.scrollTarget.offsetHeight |
| 980 } |
| 981 return 0 |
| 982 }, |
| 983 _isValidScrollTarget: function() { |
| 984 return this.scrollTarget instanceof HTMLElement |
| 985 }, |
| 986 _toggleScrollListener: function(yes, scrollTarget) { |
| 987 if (!this._boundScrollHandler) { |
| 988 return |
| 989 } |
| 990 var eventTarget = scrollTarget === this._doc ? window : scrollTarget; |
| 991 if (yes) { |
| 992 eventTarget.addEventListener("scroll", this._boundScrollHandler) |
| 993 } else { |
| 994 eventTarget.removeEventListener("scroll", this._boundScrollHandler) |
| 995 } |
| 996 }, |
| 997 toggleScrollListener: function(yes) { |
| 998 this._shouldHaveListener = yes; |
| 999 this._toggleScrollListener(yes, this.scrollTarget) |
| 1000 } |
| 1001 }; |
| 1002 (function() { |
| 1003 var metaDatas = {}; |
| 1004 var metaArrays = {}; |
| 1005 var singleton = null; |
| 1006 Polymer.IronMeta = Polymer({ |
| 1007 is: "iron-meta", |
| 1008 properties: { |
| 1009 type: {type: String, value: "default", observer: "_typeChanged"}, |
| 1010 key: {type: String, observer: "_keyChanged"}, |
| 1011 value: {type: Object, notify: true, observer: "_valueChanged"}, |
| 1012 self: {type: Boolean, observer: "_selfChanged"}, |
| 1013 list: {type: Array, notify: true} |
| 1014 }, |
| 1015 hostAttributes: {hidden: true}, |
| 1016 factoryImpl: function(config) { |
| 1017 if (config) { |
| 1018 for (var n in config) { |
| 1019 switch (n) { |
| 1020 case "type": |
| 1021 case "key": |
| 1022 case "value": |
| 1023 this[n] = config[n]; |
| 1024 break |
| 1025 } |
| 1026 } |
| 1027 } |
| 1028 }, |
| 1029 created: function() { |
| 1030 this._metaDatas = metaDatas; |
| 1031 this._metaArrays = metaArrays |
| 1032 }, |
| 1033 _keyChanged: function(key, old) { |
| 1034 this._resetRegistration(old) |
| 1035 }, |
| 1036 _valueChanged: function(value) { |
| 1037 this._resetRegistration(this.key) |
| 1038 }, |
| 1039 _selfChanged: function(self) { |
| 1040 if (self) { |
| 1041 this.value = this |
| 1042 } |
| 1043 }, |
| 1044 _typeChanged: function(type) { |
| 1045 this._unregisterKey(this.key); |
| 1046 if (!metaDatas[type]) { |
| 1047 metaDatas[type] = {} |
| 1048 } |
| 1049 this._metaData = metaDatas[type]; |
| 1050 if (!metaArrays[type]) { |
| 1051 metaArrays[type] = [] |
| 1052 } |
| 1053 this.list = metaArrays[type]; |
| 1054 this._registerKeyValue(this.key, this.value) |
| 1055 }, |
| 1056 byKey: function(key) { |
| 1057 return this._metaData && this._metaData[key] |
| 1058 }, |
| 1059 _resetRegistration: function(oldKey) { |
| 1060 this._unregisterKey(oldKey); |
| 1061 this._registerKeyValue(this.key, this.value) |
| 1062 }, |
| 1063 _unregisterKey: function(key) { |
| 1064 this._unregister(key, this._metaData, this.list) |
| 1065 }, |
| 1066 _registerKeyValue: function(key, value) { |
| 1067 this._register(key, value, this._metaData, this.list) |
| 1068 }, |
| 1069 _register: function(key, value, data, list) { |
| 1070 if (key && data && value !== undefined) { |
| 1071 data[key] = value; |
| 1072 list.push(value) |
| 1073 } |
| 1074 }, |
| 1075 _unregister: function(key, data, list) { |
| 1076 if (key && data) { |
| 1077 if (key in data) { |
| 1078 var value = data[key]; |
| 1079 delete data[key]; |
| 1080 this.arrayDelete(list, value) |
| 1081 } |
| 1082 } |
| 1083 } |
| 1084 }); |
| 1085 Polymer.IronMeta.getIronMeta = function getIronMeta() { |
| 1086 if (singleton === null) { |
| 1087 singleton = new Polymer.IronMeta |
| 1088 } |
| 1089 return singleton |
| 1090 }; |
| 1091 Polymer.IronMetaQuery = Polymer({ |
| 1092 is: "iron-meta-query", |
| 1093 properties: { |
| 1094 type: {type: String, value: "default", observer: "_typeChanged"}, |
| 1095 key: {type: String, observer: "_keyChanged"}, |
| 1096 value: {type: Object, notify: true, readOnly: true}, |
| 1097 list: {type: Array, notify: true} |
| 1098 }, |
| 1099 factoryImpl: function(config) { |
| 1100 if (config) { |
| 1101 for (var n in config) { |
| 1102 switch (n) { |
| 1103 case "type": |
| 1104 case "key": |
| 1105 this[n] = config[n]; |
| 1106 break |
| 1107 } |
| 1108 } |
| 1109 } |
| 1110 }, |
| 1111 created: function() { |
| 1112 this._metaDatas = metaDatas; |
| 1113 this._metaArrays = metaArrays |
| 1114 }, |
| 1115 _keyChanged: function(key) { |
| 1116 this._setValue(this._metaData && this._metaData[key]) |
| 1117 }, |
| 1118 _typeChanged: function(type) { |
| 1119 this._metaData = metaDatas[type]; |
| 1120 this.list = metaArrays[type]; |
| 1121 if (this.key) { |
| 1122 this._keyChanged(this.key) |
| 1123 } |
| 1124 }, |
| 1125 byKey: function(key) { |
| 1126 return this._metaData && this._metaData[key] |
| 1127 } |
| 1128 }) |
| 1129 })(); |
| 1130 Polymer({ |
| 1131 is: "iron-icon", |
| 1132 properties: { |
| 1133 icon: {type: String, observer: "_iconChanged"}, |
| 1134 theme: {type: String, observer: "_updateIcon"}, |
| 1135 src: {type: String, observer: "_srcChanged"}, |
| 1136 _meta: { |
| 1137 value: Polymer.Base.create("iron-meta", {type: "iconset"}), |
| 1138 observer: "_updateIcon" |
| 1139 } |
| 1140 }, |
| 1141 _DEFAULT_ICONSET: "icons", |
| 1142 _iconChanged: function(icon) { |
| 1143 var parts = (icon || "").split(":"); |
| 1144 this._iconName = parts.pop(); |
| 1145 this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; |
| 1146 this._updateIcon() |
| 1147 }, |
| 1148 _srcChanged: function(src) { |
| 1149 this._updateIcon() |
| 1150 }, |
| 1151 _usesIconset: function() { |
| 1152 return this.icon || !this.src |
| 1153 }, |
| 1154 _updateIcon: function() { |
| 1155 if (this._usesIconset()) { |
| 1156 if (this._img && this._img.parentNode) { |
| 1157 Polymer.dom(this.root).removeChild(this._img) |
| 1158 } |
| 1159 if (this._iconName === "") { |
| 1160 if (this._iconset) { |
| 1161 this._iconset.removeIcon(this) |
| 1162 } |
| 1163 } else if (this._iconsetName && this._meta) { |
| 1164 this._iconset = this._meta.byKey(this._iconsetName); |
| 1165 if (this._iconset) { |
| 1166 this._iconset.applyIcon(this, this._iconName, this.theme); |
| 1167 this.unlisten(window, "iron-iconset-added", "_updateIcon") |
| 1168 } else { |
| 1169 this.listen(window, "iron-iconset-added", "_updateIcon") |
| 1170 } |
| 1171 } |
| 1172 } else { |
| 1173 if (this._iconset) { |
| 1174 this._iconset.removeIcon(this) |
| 1175 } |
| 1176 if (!this._img) { |
| 1177 this._img = document.createElement("img"); |
| 1178 this._img.style.width = "100%"; |
| 1179 this._img.style.height = "100%"; |
| 1180 this._img.draggable = false |
| 1181 } |
| 1182 this._img.src = this.src; |
| 1183 Polymer.dom(this.root).appendChild(this._img) |
| 1184 } |
| 1185 } |
| 1186 }); |
| 1187 Polymer({ |
| 1188 is: "iron-iconset-svg", |
| 1189 properties: { |
| 1190 name: {type: String, observer: "_nameChanged"}, |
| 1191 size: {type: Number, value: 24}, |
| 1192 rtlMirroring: {type: Boolean, value: false} |
| 1193 }, |
| 1194 _targetIsRTL: function(target) { |
| 1195 if (target && target.nodeType !== Node.ELEMENT_NODE) { |
| 1196 target = target.host |
| 1197 } |
| 1198 return target && window.getComputedStyle(target)["direction"] === "rtl" |
| 1199 }, |
| 1200 attached: function() { |
| 1201 this.style.display = "none" |
| 1202 }, |
| 1203 getIconNames: function() { |
| 1204 this._icons = this._createIconMap(); |
| 1205 return Object.keys(this._icons).map(function(n) { |
| 1206 return this.name + ":" + n |
| 1207 }, this) |
| 1208 }, |
| 1209 applyIcon: function(element, iconName) { |
| 1210 element = element.root || element; |
| 1211 this.removeIcon(element); |
| 1212 var svg = this._cloneIcon( |
| 1213 iconName, this.rtlMirroring && this._targetIsRTL(element)); |
| 1214 if (svg) { |
| 1215 var pde = Polymer.dom(element); |
| 1216 pde.insertBefore(svg, pde.childNodes[0]); |
| 1217 return element._svgIcon = svg |
| 1218 } |
| 1219 return null |
| 1220 }, |
| 1221 removeIcon: function(element) { |
| 1222 element = element.root || element; |
| 1223 if (element._svgIcon) { |
| 1224 Polymer.dom(element).removeChild(element._svgIcon); |
| 1225 element._svgIcon = null |
| 1226 } |
| 1227 }, |
| 1228 _nameChanged: function() { |
| 1229 new Polymer.IronMeta({type: "iconset", key: this.name, value: this}); |
| 1230 this.async(function() { |
| 1231 this.fire("iron-iconset-added", this, {node: window}) |
| 1232 }) |
| 1233 }, |
| 1234 _createIconMap: function() { |
| 1235 var icons = Object.create(null); |
| 1236 Polymer.dom(this).querySelectorAll("[id]").forEach(function(icon) { |
| 1237 icons[icon.id] = icon |
| 1238 }); |
| 1239 return icons |
| 1240 }, |
| 1241 _cloneIcon: function(id, mirrorAllowed) { |
| 1242 this._icons = this._icons || this._createIconMap(); |
| 1243 return this._prepareSvgClone(this._icons[id], this.size, mirrorAllowed) |
| 1244 }, |
| 1245 _prepareSvgClone: function(sourceSvg, size, mirrorAllowed) { |
| 1246 if (sourceSvg) { |
| 1247 var content = sourceSvg.cloneNode(true), |
| 1248 svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), |
| 1249 viewBox = |
| 1250 content.getAttribute("viewBox") || "0 0 " + size + " " + size, |
| 1251 cssText = |
| 1252 "pointer-events: none; display: block; width: 100%; height: 100%;"
; |
| 1253 if (mirrorAllowed && content.hasAttribute("mirror-in-rtl")) { |
| 1254 cssText += "-webkit-transform:scale(-1,1);transform:scale(-1,1);" |
| 1255 } |
| 1256 svg.setAttribute("viewBox", viewBox); |
| 1257 svg.setAttribute("preserveAspectRatio", "xMidYMid meet"); |
| 1258 svg.style.cssText = cssText; |
| 1259 svg.appendChild(content).removeAttribute("id"); |
| 1260 return svg |
| 1261 } |
| 1262 return null |
| 1263 } |
| 1264 }); |
| 17 // Copyright 2016 The Chromium Authors. All rights reserved. | 1265 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 18 // Use of this source code is governed by a BSD-style license that can be | 1266 // Use of this source code is governed by a BSD-style license that can be |
| 19 // found in the LICENSE file. | 1267 // found in the LICENSE file. |
| 20 Polymer({is:"cr-lazy-render","extends":"template",behaviors:[Polymer.Templatizer
],child_:null,get:function(){if(!this.child_)this.render_();return this.child_},
getIfExists:function(){return this.child_},render_:function(){if(!this.ctor)this
.templatize(this);var parentNode=this.parentNode;if(parentNode&&!this.child_){va
r instance=this.stamp({});this.child_=instance.root.firstElementChild;parentNode
.insertBefore(instance.root,this)}},_forwardParentProp:function(prop,value){if(t
his.child_)this.child_._templateInstance[prop]=value},_forwardParentPath:functio
n(path,value){if(this.child_)this.child_._templateInstance.notifyPath(path,value
,true)}});(function(){"use strict";var KEY_IDENTIFIER={"U+0008":"backspace","U+0
009":"tab","U+001B":"esc","U+0020":"space","U+007F":"del"};var KEY_CODE={8:"back
space",9:"tab",13:"enter",27:"esc",33:"pageup",34:"pagedown",35:"end",36:"home",
32:"space",37:"left",38:"up",39:"right",40:"down",46:"del",106:"*"};var MODIFIER
_KEYS={shift:"shiftKey",ctrl:"ctrlKey",alt:"altKey",meta:"metaKey"};var KEY_CHAR
=/[a-z0-9*]/;var IDENT_CHAR=/U\+/;var ARROW_KEY=/^arrow/;var SPACE_KEY=/^space(b
ar)?/;var ESC_KEY=/^escape$/;function transformKey(key,noSpecialChars){var valid
Key="";if(key){var lKey=key.toLowerCase();if(lKey===" "||SPACE_KEY.test(lKey)){v
alidKey="space"}else if(ESC_KEY.test(lKey)){validKey="esc"}else if(lKey.length==
1){if(!noSpecialChars||KEY_CHAR.test(lKey)){validKey=lKey}}else if(ARROW_KEY.tes
t(lKey)){validKey=lKey.replace("arrow","")}else if(lKey=="multiply"){validKey="*
"}else{validKey=lKey}}return validKey}function transformKeyIdentifier(keyIdent){
var validKey="";if(keyIdent){if(keyIdent in KEY_IDENTIFIER){validKey=KEY_IDENTIF
IER[keyIdent]}else if(IDENT_CHAR.test(keyIdent)){keyIdent=parseInt(keyIdent.repl
ace("U+","0x"),16);validKey=String.fromCharCode(keyIdent).toLowerCase()}else{val
idKey=keyIdent.toLowerCase()}}return validKey}function transformKeyCode(keyCode)
{var validKey="";if(Number(keyCode)){if(keyCode>=65&&keyCode<=90){validKey=Strin
g.fromCharCode(32+keyCode)}else if(keyCode>=112&&keyCode<=123){validKey="f"+(key
Code-112)}else if(keyCode>=48&&keyCode<=57){validKey=String(keyCode-48)}else if(
keyCode>=96&&keyCode<=105){validKey=String(keyCode-96)}else{validKey=KEY_CODE[ke
yCode]}}return validKey}function normalizedKeyForEvent(keyEvent,noSpecialChars){
if(keyEvent.key){return transformKey(keyEvent.key,noSpecialChars)}if(keyEvent.de
tail&&keyEvent.detail.key){return transformKey(keyEvent.detail.key,noSpecialChar
s)}return transformKeyIdentifier(keyEvent.keyIdentifier)||transformKeyCode(keyEv
ent.keyCode)||""}function keyComboMatchesEvent(keyCombo,event){var keyEvent=norm
alizedKeyForEvent(event,keyCombo.hasModifiers);return keyEvent===keyCombo.key&&(
!keyCombo.hasModifiers||!!event.shiftKey===!!keyCombo.shiftKey&&!!event.ctrlKey=
==!!keyCombo.ctrlKey&&!!event.altKey===!!keyCombo.altKey&&!!event.metaKey===!!ke
yCombo.metaKey)}function parseKeyComboString(keyComboString){if(keyComboString.l
ength===1){return{combo:keyComboString,key:keyComboString,event:"keydown"}}retur
n keyComboString.split("+").reduce(function(parsedKeyCombo,keyComboPart){var eve
ntParts=keyComboPart.split(":");var keyName=eventParts[0];var event=eventParts[1
];if(keyName in MODIFIER_KEYS){parsedKeyCombo[MODIFIER_KEYS[keyName]]=true;parse
dKeyCombo.hasModifiers=true}else{parsedKeyCombo.key=keyName;parsedKeyCombo.event
=event||"keydown"}return parsedKeyCombo},{combo:keyComboString.split(":").shift(
)})}function parseEventString(eventString){return eventString.trim().split(" ").
map(function(keyComboString){return parseKeyComboString(keyComboString)})}Polyme
r.IronA11yKeysBehavior={properties:{keyEventTarget:{type:Object,value:function()
{return this}},stopKeyboardEventPropagation:{type:Boolean,value:false},_boundKey
Handlers:{type:Array,value:function(){return[]}},_imperativeKeyBindings:{type:Ob
ject,value:function(){return{}}}},observers:["_resetKeyEventListeners(keyEventTa
rget, _boundKeyHandlers)"],keyBindings:{},registered:function(){this._prepKeyBin
dings()},attached:function(){this._listenKeyEventListeners()},detached:function(
){this._unlistenKeyEventListeners()},addOwnKeyBinding:function(eventString,handl
erName){this._imperativeKeyBindings[eventString]=handlerName;this._prepKeyBindin
gs();this._resetKeyEventListeners()},removeOwnKeyBindings:function(){this._imper
ativeKeyBindings={};this._prepKeyBindings();this._resetKeyEventListeners()},keyb
oardEventMatchesKeys:function(event,eventString){var keyCombos=parseEventString(
eventString);for(var i=0;i<keyCombos.length;++i){if(keyComboMatchesEvent(keyComb
os[i],event)){return true}}return false},_collectKeyBindings:function(){var keyB
indings=this.behaviors.map(function(behavior){return behavior.keyBindings});if(k
eyBindings.indexOf(this.keyBindings)===-1){keyBindings.push(this.keyBindings)}re
turn keyBindings},_prepKeyBindings:function(){this._keyBindings={};this._collect
KeyBindings().forEach(function(keyBindings){for(var eventString in keyBindings){
this._addKeyBinding(eventString,keyBindings[eventString])}},this);for(var eventS
tring in this._imperativeKeyBindings){this._addKeyBinding(eventString,this._impe
rativeKeyBindings[eventString])}for(var eventName in this._keyBindings){this._ke
yBindings[eventName].sort(function(kb1,kb2){var b1=kb1[0].hasModifiers;var b2=kb
2[0].hasModifiers;return b1===b2?0:b1?-1:1})}},_addKeyBinding:function(eventStri
ng,handlerName){parseEventString(eventString).forEach(function(keyCombo){this._k
eyBindings[keyCombo.event]=this._keyBindings[keyCombo.event]||[];this._keyBindin
gs[keyCombo.event].push([keyCombo,handlerName])},this)},_resetKeyEventListeners:
function(){this._unlistenKeyEventListeners();if(this.isAttached){this._listenKey
EventListeners()}},_listenKeyEventListeners:function(){if(!this.keyEventTarget){
return}Object.keys(this._keyBindings).forEach(function(eventName){var keyBinding
s=this._keyBindings[eventName];var boundKeyHandler=this._onKeyBindingEvent.bind(
this,keyBindings);this._boundKeyHandlers.push([this.keyEventTarget,eventName,bou
ndKeyHandler]);this.keyEventTarget.addEventListener(eventName,boundKeyHandler)},
this)},_unlistenKeyEventListeners:function(){var keyHandlerTuple;var keyEventTar
get;var eventName;var boundKeyHandler;while(this._boundKeyHandlers.length){keyHa
ndlerTuple=this._boundKeyHandlers.pop();keyEventTarget=keyHandlerTuple[0];eventN
ame=keyHandlerTuple[1];boundKeyHandler=keyHandlerTuple[2];keyEventTarget.removeE
ventListener(eventName,boundKeyHandler)}},_onKeyBindingEvent:function(keyBinding
s,event){if(this.stopKeyboardEventPropagation){event.stopPropagation()}if(event.
defaultPrevented){return}for(var i=0;i<keyBindings.length;i++){var keyCombo=keyB
indings[i][0];var handlerName=keyBindings[i][1];if(keyComboMatchesEvent(keyCombo
,event)){this._triggerKeyHandler(keyCombo,handlerName,event);if(event.defaultPre
vented){return}}}},_triggerKeyHandler:function(keyCombo,handlerName,keyboardEven
t){var detail=Object.create(keyCombo);detail.keyboardEvent=keyboardEvent;var eve
nt=new CustomEvent(keyCombo.event,{detail:detail,cancelable:true});this[handlerN
ame].call(this,event);if(event.defaultPrevented){keyboardEvent.preventDefault()}
}}})();Polymer.IronControlState={properties:{focused:{type:Boolean,value:false,n
otify:true,readOnly:true,reflectToAttribute:true},disabled:{type:Boolean,value:f
alse,notify:true,observer:"_disabledChanged",reflectToAttribute:true},_oldTabInd
ex:{type:Number},_boundFocusBlurHandler:{type:Function,value:function(){return t
his._focusBlurHandler.bind(this)}}},observers:["_changedControlState(focused, di
sabled)"],ready:function(){this.addEventListener("focus",this._boundFocusBlurHan
dler,true);this.addEventListener("blur",this._boundFocusBlurHandler,true)},_focu
sBlurHandler:function(event){if(event.target===this){this._setFocused(event.type
==="focus")}else if(!this.shadowRoot){var target=Polymer.dom(event).localTarget;
if(!this.isLightDescendant(target)){this.fire(event.type,{sourceEvent:event},{no
de:this,bubbles:event.bubbles,cancelable:event.cancelable})}}},_disabledChanged:
function(disabled,old){this.setAttribute("aria-disabled",disabled?"true":"false"
);this.style.pointerEvents=disabled?"none":"";if(disabled){this._oldTabIndex=thi
s.tabIndex;this._setFocused(false);this.tabIndex=-1;this.blur()}else if(this._ol
dTabIndex!==undefined){this.tabIndex=this._oldTabIndex}},_changedControlState:fu
nction(){if(this._controlStateChanged){this._controlStateChanged()}}};Polymer.Ir
onButtonStateImpl={properties:{pressed:{type:Boolean,readOnly:true,value:false,r
eflectToAttribute:true,observer:"_pressedChanged"},toggles:{type:Boolean,value:f
alse,reflectToAttribute:true},active:{type:Boolean,value:false,notify:true,refle
ctToAttribute:true},pointerDown:{type:Boolean,readOnly:true,value:false},receive
dFocusFromKeyboard:{type:Boolean,readOnly:true},ariaActiveAttribute:{type:String
,value:"aria-pressed",observer:"_ariaActiveAttributeChanged"}},listeners:{down:"
_downHandler",up:"_upHandler",tap:"_tapHandler"},observers:["_detectKeyboardFocu
s(focused)","_activeChanged(active, ariaActiveAttribute)"],keyBindings:{"enter:k
eydown":"_asyncClick","space:keydown":"_spaceKeyDownHandler","space:keyup":"_spa
ceKeyUpHandler"},_mouseEventRe:/^mouse/,_tapHandler:function(){if(this.toggles){
this._userActivate(!this.active)}else{this.active=false}},_detectKeyboardFocus:f
unction(focused){this._setReceivedFocusFromKeyboard(!this.pointerDown&&focused)}
,_userActivate:function(active){if(this.active!==active){this.active=active;this
.fire("change")}},_downHandler:function(event){this._setPointerDown(true);this._
setPressed(true);this._setReceivedFocusFromKeyboard(false)},_upHandler:function(
){this._setPointerDown(false);this._setPressed(false)},_spaceKeyDownHandler:func
tion(event){var keyboardEvent=event.detail.keyboardEvent;var target=Polymer.dom(
keyboardEvent).localTarget;if(this.isLightDescendant(target))return;keyboardEven
t.preventDefault();keyboardEvent.stopImmediatePropagation();this._setPressed(tru
e)},_spaceKeyUpHandler:function(event){var keyboardEvent=event.detail.keyboardEv
ent;var target=Polymer.dom(keyboardEvent).localTarget;if(this.isLightDescendant(
target))return;if(this.pressed){this._asyncClick()}this._setPressed(false)},_asy
ncClick:function(){this.async(function(){this.click()},1)},_pressedChanged:funct
ion(pressed){this._changedButtonState()},_ariaActiveAttributeChanged:function(va
lue,oldValue){if(oldValue&&oldValue!=value&&this.hasAttribute(oldValue)){this.re
moveAttribute(oldValue)}},_activeChanged:function(active,ariaActiveAttribute){if
(this.toggles){this.setAttribute(this.ariaActiveAttribute,active?"true":"false")
}else{this.removeAttribute(this.ariaActiveAttribute)}this._changedButtonState()}
,_controlStateChanged:function(){if(this.disabled){this._setPressed(false)}else{
this._changedButtonState()}},_changedButtonState:function(){if(this._buttonState
Changed){this._buttonStateChanged()}}};Polymer.IronButtonState=[Polymer.IronA11y
KeysBehavior,Polymer.IronButtonStateImpl];(function(){var Utility={distance:func
tion(x1,y1,x2,y2){var xDelta=x1-x2;var yDelta=y1-y2;return Math.sqrt(xDelta*xDel
ta+yDelta*yDelta)},now:window.performance&&window.performance.now?window.perform
ance.now.bind(window.performance):Date.now};function ElementMetrics(element){thi
s.element=element;this.width=this.boundingRect.width;this.height=this.boundingRe
ct.height;this.size=Math.max(this.width,this.height)}ElementMetrics.prototype={g
et boundingRect(){return this.element.getBoundingClientRect()},furthestCornerDis
tanceFrom:function(x,y){var topLeft=Utility.distance(x,y,0,0);var topRight=Utili
ty.distance(x,y,this.width,0);var bottomLeft=Utility.distance(x,y,0,this.height)
;var bottomRight=Utility.distance(x,y,this.width,this.height);return Math.max(to
pLeft,topRight,bottomLeft,bottomRight)}};function Ripple(element){this.element=e
lement;this.color=window.getComputedStyle(element).color;this.wave=document.crea
teElement("div");this.waveContainer=document.createElement("div");this.wave.styl
e.backgroundColor=this.color;this.wave.classList.add("wave");this.waveContainer.
classList.add("wave-container");Polymer.dom(this.waveContainer).appendChild(this
.wave);this.resetInteractionState()}Ripple.MAX_RADIUS=300;Ripple.prototype={get
recenters(){return this.element.recenters},get center(){return this.element.cent
er},get mouseDownElapsed(){var elapsed;if(!this.mouseDownStart){return 0}elapsed
=Utility.now()-this.mouseDownStart;if(this.mouseUpStart){elapsed-=this.mouseUpEl
apsed}return elapsed},get mouseUpElapsed(){return this.mouseUpStart?Utility.now(
)-this.mouseUpStart:0},get mouseDownElapsedSeconds(){return this.mouseDownElapse
d/1e3},get mouseUpElapsedSeconds(){return this.mouseUpElapsed/1e3},get mouseInte
ractionSeconds(){return this.mouseDownElapsedSeconds+this.mouseUpElapsedSeconds}
,get initialOpacity(){return this.element.initialOpacity},get opacityDecayVeloci
ty(){return this.element.opacityDecayVelocity},get radius(){var width2=this.cont
ainerMetrics.width*this.containerMetrics.width;var height2=this.containerMetrics
.height*this.containerMetrics.height;var waveRadius=Math.min(Math.sqrt(width2+he
ight2),Ripple.MAX_RADIUS)*1.1+5;var duration=1.1-.2*(waveRadius/Ripple.MAX_RADIU
S);var timeNow=this.mouseInteractionSeconds/duration;var size=waveRadius*(1-Math
.pow(80,-timeNow));return Math.abs(size)},get opacity(){if(!this.mouseUpStart){r
eturn this.initialOpacity}return Math.max(0,this.initialOpacity-this.mouseUpElap
sedSeconds*this.opacityDecayVelocity)},get outerOpacity(){var outerOpacity=this.
mouseUpElapsedSeconds*.3;var waveOpacity=this.opacity;return Math.max(0,Math.min
(outerOpacity,waveOpacity))},get isOpacityFullyDecayed(){return this.opacity<.01
&&this.radius>=Math.min(this.maxRadius,Ripple.MAX_RADIUS)},get isRestingAtMaxRad
ius(){return this.opacity>=this.initialOpacity&&this.radius>=Math.min(this.maxRa
dius,Ripple.MAX_RADIUS)},get isAnimationComplete(){return this.mouseUpStart?this
.isOpacityFullyDecayed:this.isRestingAtMaxRadius},get translationFraction(){retu
rn Math.min(1,this.radius/this.containerMetrics.size*2/Math.sqrt(2))},get xNow()
{if(this.xEnd){return this.xStart+this.translationFraction*(this.xEnd-this.xStar
t)}return this.xStart},get yNow(){if(this.yEnd){return this.yStart+this.translat
ionFraction*(this.yEnd-this.yStart)}return this.yStart},get isMouseDown(){return
this.mouseDownStart&&!this.mouseUpStart},resetInteractionState:function(){this.
maxRadius=0;this.mouseDownStart=0;this.mouseUpStart=0;this.xStart=0;this.yStart=
0;this.xEnd=0;this.yEnd=0;this.slideDistance=0;this.containerMetrics=new Element
Metrics(this.element)},draw:function(){var scale;var translateString;var dx;var
dy;this.wave.style.opacity=this.opacity;scale=this.radius/(this.containerMetrics
.size/2);dx=this.xNow-this.containerMetrics.width/2;dy=this.yNow-this.containerM
etrics.height/2;this.waveContainer.style.webkitTransform="translate("+dx+"px, "+
dy+"px)";this.waveContainer.style.transform="translate3d("+dx+"px, "+dy+"px, 0)"
;this.wave.style.webkitTransform="scale("+scale+","+scale+")";this.wave.style.tr
ansform="scale3d("+scale+","+scale+",1)"},downAction:function(event){var xCenter
=this.containerMetrics.width/2;var yCenter=this.containerMetrics.height/2;this.r
esetInteractionState();this.mouseDownStart=Utility.now();if(this.center){this.xS
tart=xCenter;this.yStart=yCenter;this.slideDistance=Utility.distance(this.xStart
,this.yStart,this.xEnd,this.yEnd)}else{this.xStart=event?event.detail.x-this.con
tainerMetrics.boundingRect.left:this.containerMetrics.width/2;this.yStart=event?
event.detail.y-this.containerMetrics.boundingRect.top:this.containerMetrics.heig
ht/2}if(this.recenters){this.xEnd=xCenter;this.yEnd=yCenter;this.slideDistance=U
tility.distance(this.xStart,this.yStart,this.xEnd,this.yEnd)}this.maxRadius=this
.containerMetrics.furthestCornerDistanceFrom(this.xStart,this.yStart);this.waveC
ontainer.style.top=(this.containerMetrics.height-this.containerMetrics.size)/2+"
px";this.waveContainer.style.left=(this.containerMetrics.width-this.containerMet
rics.size)/2+"px";this.waveContainer.style.width=this.containerMetrics.size+"px"
;this.waveContainer.style.height=this.containerMetrics.size+"px"},upAction:funct
ion(event){if(!this.isMouseDown){return}this.mouseUpStart=Utility.now()},remove:
function(){Polymer.dom(this.waveContainer.parentNode).removeChild(this.waveConta
iner)}};Polymer({is:"paper-ripple",behaviors:[Polymer.IronA11yKeysBehavior],prop
erties:{initialOpacity:{type:Number,value:.25},opacityDecayVelocity:{type:Number
,value:.8},recenters:{type:Boolean,value:false},center:{type:Boolean,value:false
},ripples:{type:Array,value:function(){return[]}},animating:{type:Boolean,readOn
ly:true,reflectToAttribute:true,value:false},holdDown:{type:Boolean,value:false,
observer:"_holdDownChanged"},noink:{type:Boolean,value:false},_animating:{type:B
oolean},_boundAnimate:{type:Function,value:function(){return this.animate.bind(t
his)}}},get target(){return this.keyEventTarget},keyBindings:{"enter:keydown":"_
onEnterKeydown","space:keydown":"_onSpaceKeydown","space:keyup":"_onSpaceKeyup"}
,attached:function(){if(this.parentNode.nodeType==11){this.keyEventTarget=Polyme
r.dom(this).getOwnerRoot().host}else{this.keyEventTarget=this.parentNode}var key
EventTarget=this.keyEventTarget;this.listen(keyEventTarget,"up","uiUpAction");th
is.listen(keyEventTarget,"down","uiDownAction")},detached:function(){this.unlist
en(this.keyEventTarget,"up","uiUpAction");this.unlisten(this.keyEventTarget,"dow
n","uiDownAction");this.keyEventTarget=null},get shouldKeepAnimating(){for(var i
ndex=0;index<this.ripples.length;++index){if(!this.ripples[index].isAnimationCom
plete){return true}}return false},simulatedRipple:function(){this.downAction(nul
l);this.async(function(){this.upAction()},1)},uiDownAction:function(event){if(!t
his.noink){this.downAction(event)}},downAction:function(event){if(this.holdDown&
&this.ripples.length>0){return}var ripple=this.addRipple();ripple.downAction(eve
nt);if(!this._animating){this._animating=true;this.animate()}},uiUpAction:functi
on(event){if(!this.noink){this.upAction(event)}},upAction:function(event){if(thi
s.holdDown){return}this.ripples.forEach(function(ripple){ripple.upAction(event)}
);this._animating=true;this.animate()},onAnimationComplete:function(){this._anim
ating=false;this.$.background.style.backgroundColor=null;this.fire("transitionen
d")},addRipple:function(){var ripple=new Ripple(this);Polymer.dom(this.$.waves).
appendChild(ripple.waveContainer);this.$.background.style.backgroundColor=ripple
.color;this.ripples.push(ripple);this._setAnimating(true);return ripple},removeR
ipple:function(ripple){var rippleIndex=this.ripples.indexOf(ripple);if(rippleInd
ex<0){return}this.ripples.splice(rippleIndex,1);ripple.remove();if(!this.ripples
.length){this._setAnimating(false)}},animate:function(){if(!this._animating){ret
urn}var index;var ripple;for(index=0;index<this.ripples.length;++index){ripple=t
his.ripples[index];ripple.draw();this.$.background.style.opacity=ripple.outerOpa
city;if(ripple.isOpacityFullyDecayed&&!ripple.isRestingAtMaxRadius){this.removeR
ipple(ripple)}}if(!this.shouldKeepAnimating&&this.ripples.length===0){this.onAni
mationComplete()}else{window.requestAnimationFrame(this._boundAnimate)}},_onEnte
rKeydown:function(){this.uiDownAction();this.async(this.uiUpAction,1)},_onSpaceK
eydown:function(){this.uiDownAction()},_onSpaceKeyup:function(){this.uiUpAction(
)},_holdDownChanged:function(newVal,oldVal){if(oldVal===undefined){return}if(new
Val){this.downAction()}else{this.upAction()}}})})();Polymer.PaperRippleBehavior=
{properties:{noink:{type:Boolean,observer:"_noinkChanged"},_rippleContainer:{typ
e:Object}},_buttonStateChanged:function(){if(this.focused){this.ensureRipple()}}
,_downHandler:function(event){Polymer.IronButtonStateImpl._downHandler.call(this
,event);if(this.pressed){this.ensureRipple(event)}},ensureRipple:function(optTri
ggeringEvent){if(!this.hasRipple()){this._ripple=this._createRipple();this._ripp
le.noink=this.noink;var rippleContainer=this._rippleContainer||this.root;if(ripp
leContainer){Polymer.dom(rippleContainer).appendChild(this._ripple)}if(optTrigge
ringEvent){var domContainer=Polymer.dom(this._rippleContainer||this);var target=
Polymer.dom(optTriggeringEvent).rootTarget;if(domContainer.deepContains(target))
{this._ripple.uiDownAction(optTriggeringEvent)}}}},getRipple:function(){this.ens
ureRipple();return this._ripple},hasRipple:function(){return Boolean(this._rippl
e)},_createRipple:function(){return document.createElement("paper-ripple")},_noi
nkChanged:function(noink){if(this.hasRipple()){this._ripple.noink=noink}}};Polym
er.PaperInkyFocusBehaviorImpl={observers:["_focusedChanged(receivedFocusFromKeyb
oard)"],_focusedChanged:function(receivedFocusFromKeyboard){if(receivedFocusFrom
Keyboard){this.ensureRipple()}if(this.hasRipple()){this._ripple.holdDown=receive
dFocusFromKeyboard}},_createRipple:function(){var ripple=Polymer.PaperRippleBeha
vior._createRipple();ripple.id="ink";ripple.setAttribute("center","");ripple.cla
ssList.add("circle");return ripple}};Polymer.PaperInkyFocusBehavior=[Polymer.Iro
nButtonState,Polymer.IronControlState,Polymer.PaperRippleBehavior,Polymer.PaperI
nkyFocusBehaviorImpl];Polymer({is:"paper-icon-button",hostAttributes:{role:"butt
on",tabindex:"0"},behaviors:[Polymer.PaperInkyFocusBehavior],properties:{src:{ty
pe:String},icon:{type:String},alt:{type:String,observer:"_altChanged"}},_altChan
ged:function(newValue,oldValue){var label=this.getAttribute("aria-label");if(!la
bel||oldValue==label){this.setAttribute("aria-label",newValue)}}});Polymer.Paper
SpinnerBehavior={listeners:{animationend:"__reset",webkitAnimationEnd:"__reset"}
,properties:{active:{type:Boolean,value:false,reflectToAttribute:true,observer:"
__activeChanged"},alt:{type:String,value:"loading",observer:"__altChanged"},__co
olingDown:{type:Boolean,value:false}},__computeContainerClasses:function(active,
coolingDown){return[active||coolingDown?"active":"",coolingDown?"cooldown":""].j
oin(" ")},__activeChanged:function(active,old){this.__setAriaHidden(!active);thi
s.__coolingDown=!active&&old},__altChanged:function(alt){if(alt===this.getProper
tyInfo("alt").value){this.alt=this.getAttribute("aria-label")||alt}else{this.__s
etAriaHidden(alt==="");this.setAttribute("aria-label",alt)}},__setAriaHidden:fun
ction(hidden){var attr="aria-hidden";if(hidden){this.setAttribute(attr,"true")}e
lse{this.removeAttribute(attr)}},__reset:function(){this.active=false;this.__coo
lingDown=false}};Polymer({is:"paper-spinner-lite",behaviors:[Polymer.PaperSpinne
rBehavior]}); | 1268 Polymer({ |
| 1269 is: "cr-lazy-render", |
| 1270 "extends": "template", |
| 1271 behaviors: [Polymer.Templatizer], |
| 1272 child_: null, |
| 1273 get: function() { |
| 1274 if (!this.child_) |
| 1275 this.render_(); |
| 1276 return this.child_ |
| 1277 }, |
| 1278 getIfExists: function() { |
| 1279 return this.child_ |
| 1280 }, |
| 1281 render_: function() { |
| 1282 if (!this.ctor) |
| 1283 this.templatize(this); |
| 1284 var parentNode = this.parentNode; |
| 1285 if (parentNode && !this.child_) { |
| 1286 var instance = this.stamp({}); |
| 1287 this.child_ = instance.root.firstElementChild; |
| 1288 parentNode.insertBefore(instance.root, this) |
| 1289 } |
| 1290 }, |
| 1291 _forwardParentProp: function(prop, value) { |
| 1292 if (this.child_) |
| 1293 this.child_._templateInstance[prop] = value |
| 1294 }, |
| 1295 _forwardParentPath: function(path, value) { |
| 1296 if (this.child_) |
| 1297 this.child_._templateInstance.notifyPath(path, value, true) |
| 1298 } |
| 1299 }); |
| 1300 (function() { |
| 1301 "use strict"; |
| 1302 var KEY_IDENTIFIER = { |
| 1303 "U+0008": "backspace", |
| 1304 "U+0009": "tab", |
| 1305 "U+001B": "esc", |
| 1306 "U+0020": "space", |
| 1307 "U+007F": "del" |
| 1308 }; |
| 1309 var KEY_CODE = { |
| 1310 8: "backspace", |
| 1311 9: "tab", |
| 1312 13: "enter", |
| 1313 27: "esc", |
| 1314 33: "pageup", |
| 1315 34: "pagedown", |
| 1316 35: "end", |
| 1317 36: "home", |
| 1318 32: "space", |
| 1319 37: "left", |
| 1320 38: "up", |
| 1321 39: "right", |
| 1322 40: "down", |
| 1323 46: "del", |
| 1324 106: "*" |
| 1325 }; |
| 1326 var MODIFIER_KEYS = |
| 1327 {shift: "shiftKey", ctrl: "ctrlKey", alt: "altKey", meta: "metaKey"}; |
| 1328 var KEY_CHAR = /[a-z0-9*]/; |
| 1329 var IDENT_CHAR = /U\+/; |
| 1330 var ARROW_KEY = /^arrow/; |
| 1331 var SPACE_KEY = /^space(bar)?/; |
| 1332 var ESC_KEY = /^escape$/; |
| 1333 function transformKey(key, noSpecialChars) { |
| 1334 var validKey = ""; |
| 1335 if (key) { |
| 1336 var lKey = key.toLowerCase(); |
| 1337 if (lKey === " " || SPACE_KEY.test(lKey)) { |
| 1338 validKey = "space" |
| 1339 } else if (ESC_KEY.test(lKey)) { |
| 1340 validKey = "esc" |
| 1341 } else if (lKey.length == 1) { |
| 1342 if (!noSpecialChars || KEY_CHAR.test(lKey)) { |
| 1343 validKey = lKey |
| 1344 } |
| 1345 } else if (ARROW_KEY.test(lKey)) { |
| 1346 validKey = lKey.replace("arrow", "") |
| 1347 } else if (lKey == "multiply") { |
| 1348 validKey = "*" |
| 1349 } else { |
| 1350 validKey = lKey |
| 1351 } |
| 1352 } |
| 1353 return validKey |
| 1354 } |
| 1355 function transformKeyIdentifier(keyIdent) { |
| 1356 var validKey = ""; |
| 1357 if (keyIdent) { |
| 1358 if (keyIdent in KEY_IDENTIFIER) { |
| 1359 validKey = KEY_IDENTIFIER[keyIdent] |
| 1360 } else if (IDENT_CHAR.test(keyIdent)) { |
| 1361 keyIdent = parseInt(keyIdent.replace("U+", "0x"), 16); |
| 1362 validKey = String.fromCharCode(keyIdent).toLowerCase() |
| 1363 } else { |
| 1364 validKey = keyIdent.toLowerCase() |
| 1365 } |
| 1366 } |
| 1367 return validKey |
| 1368 } |
| 1369 function transformKeyCode(keyCode) { |
| 1370 var validKey = ""; |
| 1371 if (Number(keyCode)) { |
| 1372 if (keyCode >= 65 && keyCode <= 90) { |
| 1373 validKey = String.fromCharCode(32 + keyCode) |
| 1374 } else if (keyCode >= 112 && keyCode <= 123) { |
| 1375 validKey = "f" + (keyCode - 112) |
| 1376 } else if (keyCode >= 48 && keyCode <= 57) { |
| 1377 validKey = String(keyCode - 48) |
| 1378 } else if (keyCode >= 96 && keyCode <= 105) { |
| 1379 validKey = String(keyCode - 96) |
| 1380 } else { |
| 1381 validKey = KEY_CODE[keyCode] |
| 1382 } |
| 1383 } |
| 1384 return validKey |
| 1385 } |
| 1386 function normalizedKeyForEvent(keyEvent, noSpecialChars) { |
| 1387 if (keyEvent.key) { |
| 1388 return transformKey(keyEvent.key, noSpecialChars) |
| 1389 } |
| 1390 if (keyEvent.detail && keyEvent.detail.key) { |
| 1391 return transformKey(keyEvent.detail.key, noSpecialChars) |
| 1392 } |
| 1393 return transformKeyIdentifier(keyEvent.keyIdentifier) || |
| 1394 transformKeyCode(keyEvent.keyCode) || "" |
| 1395 } |
| 1396 function keyComboMatchesEvent(keyCombo, event) { |
| 1397 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); |
| 1398 return keyEvent === keyCombo.key && |
| 1399 (!keyCombo.hasModifiers || |
| 1400 !!event.shiftKey === !!keyCombo.shiftKey && |
| 1401 !!event.ctrlKey === !!keyCombo.ctrlKey && |
| 1402 !!event.altKey === !!keyCombo.altKey && |
| 1403 !!event.metaKey === !!keyCombo.metaKey) |
| 1404 } |
| 1405 function parseKeyComboString(keyComboString) { |
| 1406 if (keyComboString.length === 1) { |
| 1407 return { |
| 1408 combo: keyComboString, key: keyComboString, event: "keydown" |
| 1409 } |
| 1410 } |
| 1411 return keyComboString.split("+") |
| 1412 .reduce(function(parsedKeyCombo, keyComboPart) { |
| 1413 var eventParts = keyComboPart.split(":"); |
| 1414 var keyName = eventParts[0]; |
| 1415 var event = eventParts[1]; |
| 1416 if (keyName in MODIFIER_KEYS) { |
| 1417 parsedKeyCombo[MODIFIER_KEYS[keyName]] = true; |
| 1418 parsedKeyCombo.hasModifiers = true |
| 1419 } else { |
| 1420 parsedKeyCombo.key = keyName; |
| 1421 parsedKeyCombo.event = event || "keydown" |
| 1422 } |
| 1423 return parsedKeyCombo |
| 1424 }, {combo: keyComboString.split(":").shift()}) |
| 1425 } |
| 1426 function parseEventString(eventString) { |
| 1427 return eventString.trim().split(" ").map(function(keyComboString) { |
| 1428 return parseKeyComboString(keyComboString) |
| 1429 }) |
| 1430 } |
| 1431 Polymer.IronA11yKeysBehavior = { |
| 1432 properties: { |
| 1433 keyEventTarget: { |
| 1434 type: Object, |
| 1435 value: function() { |
| 1436 return this |
| 1437 } |
| 1438 }, |
| 1439 stopKeyboardEventPropagation: {type: Boolean, value: false}, |
| 1440 _boundKeyHandlers: { |
| 1441 type: Array, |
| 1442 value: function() { |
| 1443 return [] |
| 1444 } |
| 1445 }, |
| 1446 _imperativeKeyBindings: { |
| 1447 type: Object, |
| 1448 value: function() { |
| 1449 return {} |
| 1450 } |
| 1451 } |
| 1452 }, |
| 1453 observers: ["_resetKeyEventListeners(keyEventTarget, _boundKeyHandlers)"], |
| 1454 keyBindings: {}, |
| 1455 registered: function() { |
| 1456 this._prepKeyBindings() |
| 1457 }, |
| 1458 attached: function() { |
| 1459 this._listenKeyEventListeners() |
| 1460 }, |
| 1461 detached: function() { |
| 1462 this._unlistenKeyEventListeners() |
| 1463 }, |
| 1464 addOwnKeyBinding: function(eventString, handlerName) { |
| 1465 this._imperativeKeyBindings[eventString] = handlerName; |
| 1466 this._prepKeyBindings(); |
| 1467 this._resetKeyEventListeners() |
| 1468 }, |
| 1469 removeOwnKeyBindings: function() { |
| 1470 this._imperativeKeyBindings = {}; |
| 1471 this._prepKeyBindings(); |
| 1472 this._resetKeyEventListeners() |
| 1473 }, |
| 1474 keyboardEventMatchesKeys: function(event, eventString) { |
| 1475 var keyCombos = parseEventString(eventString); |
| 1476 for (var i = 0; i < keyCombos.length; ++i) { |
| 1477 if (keyComboMatchesEvent(keyCombos[i], event)) { |
| 1478 return true |
| 1479 } |
| 1480 } |
| 1481 return false |
| 1482 }, |
| 1483 _collectKeyBindings: function() { |
| 1484 var keyBindings = this.behaviors.map(function(behavior) { |
| 1485 return behavior.keyBindings |
| 1486 }); |
| 1487 if (keyBindings.indexOf(this.keyBindings) === -1) { |
| 1488 keyBindings.push(this.keyBindings) |
| 1489 } |
| 1490 return keyBindings |
| 1491 }, |
| 1492 _prepKeyBindings: function() { |
| 1493 this._keyBindings = {}; |
| 1494 this._collectKeyBindings().forEach(function(keyBindings) { |
| 1495 for (var eventString in keyBindings) { |
| 1496 this._addKeyBinding(eventString, keyBindings[eventString]) |
| 1497 } |
| 1498 }, this); |
| 1499 for (var eventString in this._imperativeKeyBindings) { |
| 1500 this._addKeyBinding( |
| 1501 eventString, this._imperativeKeyBindings[eventString]) |
| 1502 } |
| 1503 for (var eventName in this._keyBindings) { |
| 1504 this._keyBindings[eventName].sort(function(kb1, kb2) { |
| 1505 var b1 = kb1[0].hasModifiers; |
| 1506 var b2 = kb2[0].hasModifiers; |
| 1507 return b1 === b2 ? 0 : b1 ? -1 : 1 |
| 1508 }) |
| 1509 } |
| 1510 }, |
| 1511 _addKeyBinding: function(eventString, handlerName) { |
| 1512 parseEventString(eventString).forEach(function(keyCombo) { |
| 1513 this._keyBindings[keyCombo.event] = |
| 1514 this._keyBindings[keyCombo.event] || []; |
| 1515 this._keyBindings[keyCombo.event].push([keyCombo, handlerName]) |
| 1516 }, this) |
| 1517 }, |
| 1518 _resetKeyEventListeners: function() { |
| 1519 this._unlistenKeyEventListeners(); |
| 1520 if (this.isAttached) { |
| 1521 this._listenKeyEventListeners() |
| 1522 } |
| 1523 }, |
| 1524 _listenKeyEventListeners: function() { |
| 1525 if (!this.keyEventTarget) { |
| 1526 return |
| 1527 } |
| 1528 Object.keys(this._keyBindings).forEach(function(eventName) { |
| 1529 var keyBindings = this._keyBindings[eventName]; |
| 1530 var boundKeyHandler = this._onKeyBindingEvent.bind(this, keyBindings); |
| 1531 this._boundKeyHandlers.push( |
| 1532 [this.keyEventTarget, eventName, boundKeyHandler]); |
| 1533 this.keyEventTarget.addEventListener(eventName, boundKeyHandler) |
| 1534 }, this) |
| 1535 }, |
| 1536 _unlistenKeyEventListeners: function() { |
| 1537 var keyHandlerTuple; |
| 1538 var keyEventTarget; |
| 1539 var eventName; |
| 1540 var boundKeyHandler; |
| 1541 while (this._boundKeyHandlers.length) { |
| 1542 keyHandlerTuple = this._boundKeyHandlers.pop(); |
| 1543 keyEventTarget = keyHandlerTuple[0]; |
| 1544 eventName = keyHandlerTuple[1]; |
| 1545 boundKeyHandler = keyHandlerTuple[2]; |
| 1546 keyEventTarget.removeEventListener(eventName, boundKeyHandler) |
| 1547 } |
| 1548 }, |
| 1549 _onKeyBindingEvent: function(keyBindings, event) { |
| 1550 if (this.stopKeyboardEventPropagation) { |
| 1551 event.stopPropagation() |
| 1552 } |
| 1553 if (event.defaultPrevented) { |
| 1554 return |
| 1555 } |
| 1556 for (var i = 0; i < keyBindings.length; i++) { |
| 1557 var keyCombo = keyBindings[i][0]; |
| 1558 var handlerName = keyBindings[i][1]; |
| 1559 if (keyComboMatchesEvent(keyCombo, event)) { |
| 1560 this._triggerKeyHandler(keyCombo, handlerName, event); |
| 1561 if (event.defaultPrevented) { |
| 1562 return |
| 1563 } |
| 1564 } |
| 1565 } |
| 1566 }, |
| 1567 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { |
| 1568 var detail = Object.create(keyCombo); |
| 1569 detail.keyboardEvent = keyboardEvent; |
| 1570 var event = |
| 1571 new CustomEvent(keyCombo.event, {detail: detail, cancelable: true}); |
| 1572 this[handlerName].call(this, event); |
| 1573 if (event.defaultPrevented) { |
| 1574 keyboardEvent.preventDefault() |
| 1575 } |
| 1576 } |
| 1577 } |
| 1578 })(); |
| 1579 Polymer.IronControlState = { |
| 1580 properties: { |
| 1581 focused: { |
| 1582 type: Boolean, |
| 1583 value: false, |
| 1584 notify: true, |
| 1585 readOnly: true, |
| 1586 reflectToAttribute: true |
| 1587 }, |
| 1588 disabled: { |
| 1589 type: Boolean, |
| 1590 value: false, |
| 1591 notify: true, |
| 1592 observer: "_disabledChanged", |
| 1593 reflectToAttribute: true |
| 1594 }, |
| 1595 _oldTabIndex: {type: Number}, |
| 1596 _boundFocusBlurHandler: { |
| 1597 type: Function, |
| 1598 value: function() { |
| 1599 return this._focusBlurHandler.bind(this) |
| 1600 } |
| 1601 } |
| 1602 }, |
| 1603 observers: ["_changedControlState(focused, disabled)"], |
| 1604 ready: function() { |
| 1605 this.addEventListener("focus", this._boundFocusBlurHandler, true); |
| 1606 this.addEventListener("blur", this._boundFocusBlurHandler, true) |
| 1607 }, |
| 1608 _focusBlurHandler: function(event) { |
| 1609 if (event.target === this) { |
| 1610 this._setFocused(event.type === "focus") |
| 1611 } else if (!this.shadowRoot) { |
| 1612 var target = Polymer.dom(event).localTarget; |
| 1613 if (!this.isLightDescendant(target)) { |
| 1614 this.fire( |
| 1615 event.type, {sourceEvent: event}, |
| 1616 {node: this, bubbles: event.bubbles, cancelable: event.cancelable}) |
| 1617 } |
| 1618 } |
| 1619 }, |
| 1620 _disabledChanged: function(disabled, old) { |
| 1621 this.setAttribute("aria-disabled", disabled ? "true" : "false"); |
| 1622 this.style.pointerEvents = disabled ? "none" : ""; |
| 1623 if (disabled) { |
| 1624 this._oldTabIndex = this.tabIndex; |
| 1625 this._setFocused(false); |
| 1626 this.tabIndex = -1; |
| 1627 this.blur() |
| 1628 } else if (this._oldTabIndex !== undefined) { |
| 1629 this.tabIndex = this._oldTabIndex |
| 1630 } |
| 1631 }, |
| 1632 _changedControlState: function() { |
| 1633 if (this._controlStateChanged) { |
| 1634 this._controlStateChanged() |
| 1635 } |
| 1636 } |
| 1637 }; |
| 1638 Polymer.IronButtonStateImpl = { |
| 1639 properties: { |
| 1640 pressed: { |
| 1641 type: Boolean, |
| 1642 readOnly: true, |
| 1643 value: false, |
| 1644 reflectToAttribute: true, |
| 1645 observer: "_pressedChanged" |
| 1646 }, |
| 1647 toggles: {type: Boolean, value: false, reflectToAttribute: true}, |
| 1648 active: |
| 1649 {type: Boolean, value: false, notify: true, reflectToAttribute: true}, |
| 1650 pointerDown: {type: Boolean, readOnly: true, value: false}, |
| 1651 receivedFocusFromKeyboard: {type: Boolean, readOnly: true}, |
| 1652 ariaActiveAttribute: { |
| 1653 type: String, |
| 1654 value: "aria-pressed", |
| 1655 observer: "_ariaActiveAttributeChanged" |
| 1656 } |
| 1657 }, |
| 1658 listeners: {down: "_downHandler", up: "_upHandler", tap: "_tapHandler"}, |
| 1659 observers: [ |
| 1660 "_detectKeyboardFocus(focused)", |
| 1661 "_activeChanged(active, ariaActiveAttribute)" |
| 1662 ], |
| 1663 keyBindings: { |
| 1664 "enter:keydown": "_asyncClick", |
| 1665 "space:keydown": "_spaceKeyDownHandler", |
| 1666 "space:keyup": "_spaceKeyUpHandler" |
| 1667 }, |
| 1668 _mouseEventRe: /^mouse/, |
| 1669 _tapHandler: function() { |
| 1670 if (this.toggles) { |
| 1671 this._userActivate(!this.active) |
| 1672 } else { |
| 1673 this.active = false |
| 1674 } |
| 1675 }, |
| 1676 _detectKeyboardFocus: function(focused) { |
| 1677 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused) |
| 1678 }, |
| 1679 _userActivate: function(active) { |
| 1680 if (this.active !== active) { |
| 1681 this.active = active; |
| 1682 this.fire("change") |
| 1683 } |
| 1684 }, |
| 1685 _downHandler: function(event) { |
| 1686 this._setPointerDown(true); |
| 1687 this._setPressed(true); |
| 1688 this._setReceivedFocusFromKeyboard(false) |
| 1689 }, |
| 1690 _upHandler: function() { |
| 1691 this._setPointerDown(false); |
| 1692 this._setPressed(false) |
| 1693 }, |
| 1694 _spaceKeyDownHandler: function(event) { |
| 1695 var keyboardEvent = event.detail.keyboardEvent; |
| 1696 var target = Polymer.dom(keyboardEvent).localTarget; |
| 1697 if (this.isLightDescendant(target)) |
| 1698 return; |
| 1699 keyboardEvent.preventDefault(); |
| 1700 keyboardEvent.stopImmediatePropagation(); |
| 1701 this._setPressed(true) |
| 1702 }, |
| 1703 _spaceKeyUpHandler: function(event) { |
| 1704 var keyboardEvent = event.detail.keyboardEvent; |
| 1705 var target = Polymer.dom(keyboardEvent).localTarget; |
| 1706 if (this.isLightDescendant(target)) |
| 1707 return; |
| 1708 if (this.pressed) { |
| 1709 this._asyncClick() |
| 1710 } |
| 1711 this._setPressed(false) |
| 1712 }, |
| 1713 _asyncClick: function() { |
| 1714 this.async(function() { |
| 1715 this.click() |
| 1716 }, 1) |
| 1717 }, |
| 1718 _pressedChanged: function(pressed) { |
| 1719 this._changedButtonState() |
| 1720 }, |
| 1721 _ariaActiveAttributeChanged: function(value, oldValue) { |
| 1722 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { |
| 1723 this.removeAttribute(oldValue) |
| 1724 } |
| 1725 }, |
| 1726 _activeChanged: function(active, ariaActiveAttribute) { |
| 1727 if (this.toggles) { |
| 1728 this.setAttribute(this.ariaActiveAttribute, active ? "true" : "false") |
| 1729 } else { |
| 1730 this.removeAttribute(this.ariaActiveAttribute) |
| 1731 } |
| 1732 this._changedButtonState() |
| 1733 }, |
| 1734 _controlStateChanged: function() { |
| 1735 if (this.disabled) { |
| 1736 this._setPressed(false) |
| 1737 } else { |
| 1738 this._changedButtonState() |
| 1739 } |
| 1740 }, |
| 1741 _changedButtonState: function() { |
| 1742 if (this._buttonStateChanged) { |
| 1743 this._buttonStateChanged() |
| 1744 } |
| 1745 } |
| 1746 }; |
| 1747 Polymer.IronButtonState = |
| 1748 [Polymer.IronA11yKeysBehavior, Polymer.IronButtonStateImpl]; |
| 1749 (function() { |
| 1750 var Utility = { |
| 1751 distance: function(x1, y1, x2, y2) { |
| 1752 var xDelta = x1 - x2; |
| 1753 var yDelta = y1 - y2; |
| 1754 return Math.sqrt(xDelta * xDelta + yDelta * yDelta) |
| 1755 }, |
| 1756 now: window.performance && window.performance.now ? |
| 1757 window.performance.now.bind(window.performance) : |
| 1758 Date.now |
| 1759 }; |
| 1760 function ElementMetrics(element) { |
| 1761 this.element = element; |
| 1762 this.width = this.boundingRect.width; |
| 1763 this.height = this.boundingRect.height; |
| 1764 this.size = Math.max(this.width, this.height) |
| 1765 } |
| 1766 ElementMetrics.prototype = { |
| 1767 get boundingRect() { |
| 1768 return this.element.getBoundingClientRect() |
| 1769 }, |
| 1770 furthestCornerDistanceFrom: function(x, y) { |
| 1771 var topLeft = Utility.distance(x, y, 0, 0); |
| 1772 var topRight = Utility.distance(x, y, this.width, 0); |
| 1773 var bottomLeft = Utility.distance(x, y, 0, this.height); |
| 1774 var bottomRight = Utility.distance(x, y, this.width, this.height); |
| 1775 return Math.max(topLeft, topRight, bottomLeft, bottomRight) |
| 1776 } |
| 1777 }; |
| 1778 function Ripple(element) { |
| 1779 this.element = element; |
| 1780 this.color = window.getComputedStyle(element).color; |
| 1781 this.wave = document.createElement("div"); |
| 1782 this.waveContainer = document.createElement("div"); |
| 1783 this.wave.style.backgroundColor = this.color; |
| 1784 this.wave.classList.add("wave"); |
| 1785 this.waveContainer.classList.add("wave-container"); |
| 1786 Polymer.dom(this.waveContainer).appendChild(this.wave); |
| 1787 this.resetInteractionState() |
| 1788 } |
| 1789 Ripple.MAX_RADIUS = 300; |
| 1790 Ripple.prototype = { |
| 1791 get recenters() { |
| 1792 return this.element.recenters |
| 1793 }, |
| 1794 get center() { |
| 1795 return this.element.center |
| 1796 }, |
| 1797 get mouseDownElapsed() { |
| 1798 var elapsed; |
| 1799 if (!this.mouseDownStart) { |
| 1800 return 0 |
| 1801 } |
| 1802 elapsed = Utility.now() - this.mouseDownStart; |
| 1803 if (this.mouseUpStart) { |
| 1804 elapsed -= this.mouseUpElapsed |
| 1805 } |
| 1806 return elapsed |
| 1807 }, |
| 1808 get mouseUpElapsed() { |
| 1809 return this.mouseUpStart ? Utility.now() - this.mouseUpStart : 0 |
| 1810 }, |
| 1811 get mouseDownElapsedSeconds() { |
| 1812 return this.mouseDownElapsed / 1e3 |
| 1813 }, |
| 1814 get mouseUpElapsedSeconds() { |
| 1815 return this.mouseUpElapsed / 1e3 |
| 1816 }, |
| 1817 get mouseInteractionSeconds() { |
| 1818 return this.mouseDownElapsedSeconds + this.mouseUpElapsedSeconds |
| 1819 }, |
| 1820 get initialOpacity() { |
| 1821 return this.element.initialOpacity |
| 1822 }, |
| 1823 get opacityDecayVelocity() { |
| 1824 return this.element.opacityDecayVelocity |
| 1825 }, |
| 1826 get radius() { |
| 1827 var width2 = this.containerMetrics.width * this.containerMetrics.width; |
| 1828 var height2 = this.containerMetrics.height * this.containerMetrics.height; |
| 1829 var waveRadius = |
| 1830 Math.min(Math.sqrt(width2 + height2), Ripple.MAX_RADIUS) * 1.1 + 5; |
| 1831 var duration = 1.1 - .2 * (waveRadius / Ripple.MAX_RADIUS); |
| 1832 var timeNow = this.mouseInteractionSeconds / duration; |
| 1833 var size = waveRadius * (1 - Math.pow(80, -timeNow)); |
| 1834 return Math.abs(size) |
| 1835 }, |
| 1836 get opacity() { |
| 1837 if (!this.mouseUpStart) { |
| 1838 return this.initialOpacity |
| 1839 } |
| 1840 return Math.max( |
| 1841 0, this.initialOpacity - |
| 1842 this.mouseUpElapsedSeconds * this.opacityDecayVelocity) |
| 1843 }, |
| 1844 get outerOpacity() { |
| 1845 var outerOpacity = this.mouseUpElapsedSeconds * .3; |
| 1846 var waveOpacity = this.opacity; |
| 1847 return Math.max(0, Math.min(outerOpacity, waveOpacity)) |
| 1848 }, |
| 1849 get isOpacityFullyDecayed() { |
| 1850 return this.opacity < .01 && |
| 1851 this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS) |
| 1852 }, |
| 1853 get isRestingAtMaxRadius() { |
| 1854 return this.opacity >= this.initialOpacity && |
| 1855 this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS) |
| 1856 }, |
| 1857 get isAnimationComplete() { |
| 1858 return this.mouseUpStart ? this.isOpacityFullyDecayed : |
| 1859 this.isRestingAtMaxRadius |
| 1860 }, |
| 1861 get translationFraction() { |
| 1862 return Math.min( |
| 1863 1, this.radius / this.containerMetrics.size * 2 / Math.sqrt(2)) |
| 1864 }, |
| 1865 get xNow() { |
| 1866 if (this.xEnd) { |
| 1867 return this.xStart + |
| 1868 this.translationFraction * (this.xEnd - this.xStart) |
| 1869 } |
| 1870 return this.xStart |
| 1871 }, |
| 1872 get yNow() { |
| 1873 if (this.yEnd) { |
| 1874 return this.yStart + |
| 1875 this.translationFraction * (this.yEnd - this.yStart) |
| 1876 } |
| 1877 return this.yStart |
| 1878 }, |
| 1879 get isMouseDown() { |
| 1880 return this.mouseDownStart && !this.mouseUpStart |
| 1881 }, |
| 1882 resetInteractionState: function() { |
| 1883 this.maxRadius = 0; |
| 1884 this.mouseDownStart = 0; |
| 1885 this.mouseUpStart = 0; |
| 1886 this.xStart = 0; |
| 1887 this.yStart = 0; |
| 1888 this.xEnd = 0; |
| 1889 this.yEnd = 0; |
| 1890 this.slideDistance = 0; |
| 1891 this.containerMetrics = new ElementMetrics(this.element) |
| 1892 }, |
| 1893 draw: function() { |
| 1894 var scale; |
| 1895 var translateString; |
| 1896 var dx; |
| 1897 var dy; |
| 1898 this.wave.style.opacity = this.opacity; |
| 1899 scale = this.radius / (this.containerMetrics.size / 2); |
| 1900 dx = this.xNow - this.containerMetrics.width / 2; |
| 1901 dy = this.yNow - this.containerMetrics.height / 2; |
| 1902 this.waveContainer.style.webkitTransform = |
| 1903 "translate(" + dx + "px, " + dy + "px)"; |
| 1904 this.waveContainer.style.transform = |
| 1905 "translate3d(" + dx + "px, " + dy + "px, 0)"; |
| 1906 this.wave.style.webkitTransform = "scale(" + scale + "," + scale + ")"; |
| 1907 this.wave.style.transform = "scale3d(" + scale + "," + scale + ",1)" |
| 1908 }, |
| 1909 downAction: function(event) { |
| 1910 var xCenter = this.containerMetrics.width / 2; |
| 1911 var yCenter = this.containerMetrics.height / 2; |
| 1912 this.resetInteractionState(); |
| 1913 this.mouseDownStart = Utility.now(); |
| 1914 if (this.center) { |
| 1915 this.xStart = xCenter; |
| 1916 this.yStart = yCenter; |
| 1917 this.slideDistance = |
| 1918 Utility.distance(this.xStart, this.yStart, this.xEnd, this.yEnd) |
| 1919 } else { |
| 1920 this.xStart = event ? |
| 1921 event.detail.x - this.containerMetrics.boundingRect.left : |
| 1922 this.containerMetrics.width / 2; |
| 1923 this.yStart = event ? |
| 1924 event.detail.y - this.containerMetrics.boundingRect.top : |
| 1925 this.containerMetrics.height / 2 |
| 1926 } |
| 1927 if (this.recenters) { |
| 1928 this.xEnd = xCenter; |
| 1929 this.yEnd = yCenter; |
| 1930 this.slideDistance = |
| 1931 Utility.distance(this.xStart, this.yStart, this.xEnd, this.yEnd) |
| 1932 } |
| 1933 this.maxRadius = this.containerMetrics.furthestCornerDistanceFrom( |
| 1934 this.xStart, this.yStart); |
| 1935 this.waveContainer.style.top = |
| 1936 (this.containerMetrics.height - this.containerMetrics.size) / 2 + |
| 1937 "px"; |
| 1938 this.waveContainer.style.left = |
| 1939 (this.containerMetrics.width - this.containerMetrics.size) / 2 + "px"; |
| 1940 this.waveContainer.style.width = this.containerMetrics.size + "px"; |
| 1941 this.waveContainer.style.height = this.containerMetrics.size + "px" |
| 1942 }, |
| 1943 upAction: function(event) { |
| 1944 if (!this.isMouseDown) { |
| 1945 return |
| 1946 } |
| 1947 this.mouseUpStart = Utility.now() |
| 1948 }, |
| 1949 remove: function() { |
| 1950 Polymer.dom(this.waveContainer.parentNode).removeChild(this.waveContainer) |
| 1951 } |
| 1952 }; |
| 1953 Polymer({ |
| 1954 is: "paper-ripple", |
| 1955 behaviors: [Polymer.IronA11yKeysBehavior], |
| 1956 properties: { |
| 1957 initialOpacity: {type: Number, value: .25}, |
| 1958 opacityDecayVelocity: {type: Number, value: .8}, |
| 1959 recenters: {type: Boolean, value: false}, |
| 1960 center: {type: Boolean, value: false}, |
| 1961 ripples: { |
| 1962 type: Array, |
| 1963 value: function() { |
| 1964 return [] |
| 1965 } |
| 1966 }, |
| 1967 animating: { |
| 1968 type: Boolean, |
| 1969 readOnly: true, |
| 1970 reflectToAttribute: true, |
| 1971 value: false |
| 1972 }, |
| 1973 holdDown: {type: Boolean, value: false, observer: "_holdDownChanged"}, |
| 1974 noink: {type: Boolean, value: false}, |
| 1975 _animating: {type: Boolean}, |
| 1976 _boundAnimate: { |
| 1977 type: Function, |
| 1978 value: function() { |
| 1979 return this.animate.bind(this) |
| 1980 } |
| 1981 } |
| 1982 }, |
| 1983 get target() { |
| 1984 return this.keyEventTarget |
| 1985 }, |
| 1986 keyBindings: { |
| 1987 "enter:keydown": "_onEnterKeydown", |
| 1988 "space:keydown": "_onSpaceKeydown", |
| 1989 "space:keyup": "_onSpaceKeyup" |
| 1990 }, |
| 1991 attached: function() { |
| 1992 if (this.parentNode.nodeType == 11) { |
| 1993 this.keyEventTarget = Polymer.dom(this).getOwnerRoot().host |
| 1994 } else { |
| 1995 this.keyEventTarget = this.parentNode |
| 1996 } |
| 1997 var keyEventTarget = this.keyEventTarget; |
| 1998 this.listen(keyEventTarget, "up", "uiUpAction"); |
| 1999 this.listen(keyEventTarget, "down", "uiDownAction") |
| 2000 }, |
| 2001 detached: function() { |
| 2002 this.unlisten(this.keyEventTarget, "up", "uiUpAction"); |
| 2003 this.unlisten(this.keyEventTarget, "down", "uiDownAction"); |
| 2004 this.keyEventTarget = null |
| 2005 }, |
| 2006 get shouldKeepAnimating() { |
| 2007 for (var index = 0; index < this.ripples.length; ++index) { |
| 2008 if (!this.ripples[index].isAnimationComplete) { |
| 2009 return true |
| 2010 } |
| 2011 } |
| 2012 return false |
| 2013 }, |
| 2014 simulatedRipple: function() { |
| 2015 this.downAction(null); |
| 2016 this.async(function() { |
| 2017 this.upAction() |
| 2018 }, 1) |
| 2019 }, |
| 2020 uiDownAction: function(event) { |
| 2021 if (!this.noink) { |
| 2022 this.downAction(event) |
| 2023 } |
| 2024 }, |
| 2025 downAction: function(event) { |
| 2026 if (this.holdDown && this.ripples.length > 0) { |
| 2027 return |
| 2028 } |
| 2029 var ripple = this.addRipple(); |
| 2030 ripple.downAction(event); |
| 2031 if (!this._animating) { |
| 2032 this._animating = true; |
| 2033 this.animate() |
| 2034 } |
| 2035 }, |
| 2036 uiUpAction: function(event) { |
| 2037 if (!this.noink) { |
| 2038 this.upAction(event) |
| 2039 } |
| 2040 }, |
| 2041 upAction: function(event) { |
| 2042 if (this.holdDown) { |
| 2043 return |
| 2044 } |
| 2045 this.ripples.forEach(function(ripple) { |
| 2046 ripple.upAction(event) |
| 2047 }); |
| 2048 this._animating = true; |
| 2049 this.animate() |
| 2050 }, |
| 2051 onAnimationComplete: function() { |
| 2052 this._animating = false; |
| 2053 this.$.background.style.backgroundColor = null; |
| 2054 this.fire("transitionend") |
| 2055 }, |
| 2056 addRipple: function() { |
| 2057 var ripple = new Ripple(this); |
| 2058 Polymer.dom(this.$.waves).appendChild(ripple.waveContainer); |
| 2059 this.$.background.style.backgroundColor = ripple.color; |
| 2060 this.ripples.push(ripple); |
| 2061 this._setAnimating(true); |
| 2062 return ripple |
| 2063 }, |
| 2064 removeRipple: function(ripple) { |
| 2065 var rippleIndex = this.ripples.indexOf(ripple); |
| 2066 if (rippleIndex < 0) { |
| 2067 return |
| 2068 } |
| 2069 this.ripples.splice(rippleIndex, 1); |
| 2070 ripple.remove(); |
| 2071 if (!this.ripples.length) { |
| 2072 this._setAnimating(false) |
| 2073 } |
| 2074 }, |
| 2075 animate: function() { |
| 2076 if (!this._animating) { |
| 2077 return |
| 2078 } |
| 2079 var index; |
| 2080 var ripple; |
| 2081 for (index = 0; index < this.ripples.length; ++index) { |
| 2082 ripple = this.ripples[index]; |
| 2083 ripple.draw(); |
| 2084 this.$.background.style.opacity = ripple.outerOpacity; |
| 2085 if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) { |
| 2086 this.removeRipple(ripple) |
| 2087 } |
| 2088 } |
| 2089 if (!this.shouldKeepAnimating && this.ripples.length === 0) { |
| 2090 this.onAnimationComplete() |
| 2091 } else { |
| 2092 window.requestAnimationFrame(this._boundAnimate) |
| 2093 } |
| 2094 }, |
| 2095 _onEnterKeydown: function() { |
| 2096 this.uiDownAction(); |
| 2097 this.async(this.uiUpAction, 1) |
| 2098 }, |
| 2099 _onSpaceKeydown: function() { |
| 2100 this.uiDownAction() |
| 2101 }, |
| 2102 _onSpaceKeyup: function() { |
| 2103 this.uiUpAction() |
| 2104 }, |
| 2105 _holdDownChanged: function(newVal, oldVal) { |
| 2106 if (oldVal === undefined) { |
| 2107 return |
| 2108 } |
| 2109 if (newVal) { |
| 2110 this.downAction() |
| 2111 } else { |
| 2112 this.upAction() |
| 2113 } |
| 2114 } |
| 2115 }) |
| 2116 })(); |
| 2117 Polymer.PaperRippleBehavior = { |
| 2118 properties: { |
| 2119 noink: {type: Boolean, observer: "_noinkChanged"}, |
| 2120 _rippleContainer: {type: Object} |
| 2121 }, |
| 2122 _buttonStateChanged: function() { |
| 2123 if (this.focused) { |
| 2124 this.ensureRipple() |
| 2125 } |
| 2126 }, |
| 2127 _downHandler: function(event) { |
| 2128 Polymer.IronButtonStateImpl._downHandler.call(this, event); |
| 2129 if (this.pressed) { |
| 2130 this.ensureRipple(event) |
| 2131 } |
| 2132 }, |
| 2133 ensureRipple: function(optTriggeringEvent) { |
| 2134 if (!this.hasRipple()) { |
| 2135 this._ripple = this._createRipple(); |
| 2136 this._ripple.noink = this.noink; |
| 2137 var rippleContainer = this._rippleContainer || this.root; |
| 2138 if (rippleContainer) { |
| 2139 Polymer.dom(rippleContainer).appendChild(this._ripple) |
| 2140 } |
| 2141 if (optTriggeringEvent) { |
| 2142 var domContainer = Polymer.dom(this._rippleContainer || this); |
| 2143 var target = Polymer.dom(optTriggeringEvent).rootTarget; |
| 2144 if (domContainer.deepContains(target)) { |
| 2145 this._ripple.uiDownAction(optTriggeringEvent) |
| 2146 } |
| 2147 } |
| 2148 } |
| 2149 }, |
| 2150 getRipple: function() { |
| 2151 this.ensureRipple(); |
| 2152 return this._ripple |
| 2153 }, |
| 2154 hasRipple: function() { |
| 2155 return Boolean(this._ripple) |
| 2156 }, |
| 2157 _createRipple: function() { |
| 2158 return document.createElement("paper-ripple") |
| 2159 }, |
| 2160 _noinkChanged: function(noink) { |
| 2161 if (this.hasRipple()) { |
| 2162 this._ripple.noink = noink |
| 2163 } |
| 2164 } |
| 2165 }; |
| 2166 Polymer.PaperInkyFocusBehaviorImpl = { |
| 2167 observers: ["_focusedChanged(receivedFocusFromKeyboard)"], |
| 2168 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 2169 if (receivedFocusFromKeyboard) { |
| 2170 this.ensureRipple() |
| 2171 } |
| 2172 if (this.hasRipple()) { |
| 2173 this._ripple.holdDown = receivedFocusFromKeyboard |
| 2174 } |
| 2175 }, |
| 2176 _createRipple: function() { |
| 2177 var ripple = Polymer.PaperRippleBehavior._createRipple(); |
| 2178 ripple.id = "ink"; |
| 2179 ripple.setAttribute("center", ""); |
| 2180 ripple.classList.add("circle"); |
| 2181 return ripple |
| 2182 } |
| 2183 }; |
| 2184 Polymer.PaperInkyFocusBehavior = [ |
| 2185 Polymer.IronButtonState, Polymer.IronControlState, |
| 2186 Polymer.PaperRippleBehavior, Polymer.PaperInkyFocusBehaviorImpl |
| 2187 ]; |
| 2188 Polymer({ |
| 2189 is: "paper-icon-button", |
| 2190 hostAttributes: {role: "button", tabindex: "0"}, |
| 2191 behaviors: [Polymer.PaperInkyFocusBehavior], |
| 2192 properties: { |
| 2193 src: {type: String}, |
| 2194 icon: {type: String}, |
| 2195 alt: {type: String, observer: "_altChanged"} |
| 2196 }, |
| 2197 _altChanged: function(newValue, oldValue) { |
| 2198 var label = this.getAttribute("aria-label"); |
| 2199 if (!label || oldValue == label) { |
| 2200 this.setAttribute("aria-label", newValue) |
| 2201 } |
| 2202 } |
| 2203 }); |
| 2204 Polymer.PaperSpinnerBehavior = { |
| 2205 listeners: {animationend: "__reset", webkitAnimationEnd: "__reset"}, |
| 2206 properties: { |
| 2207 active: { |
| 2208 type: Boolean, |
| 2209 value: false, |
| 2210 reflectToAttribute: true, |
| 2211 observer: "__activeChanged" |
| 2212 }, |
| 2213 alt: {type: String, value: "loading", observer: "__altChanged"}, |
| 2214 __coolingDown: {type: Boolean, value: false} |
| 2215 }, |
| 2216 __computeContainerClasses: function(active, coolingDown) { |
| 2217 return [ |
| 2218 active || coolingDown ? "active" : "", coolingDown ? "cooldown" : "" |
| 2219 ].join(" ") |
| 2220 }, |
| 2221 __activeChanged: function(active, old) { |
| 2222 this.__setAriaHidden(!active); |
| 2223 this.__coolingDown = !active && old |
| 2224 }, |
| 2225 __altChanged: function(alt) { |
| 2226 if (alt === this.getPropertyInfo("alt").value) { |
| 2227 this.alt = this.getAttribute("aria-label") || alt |
| 2228 } else { |
| 2229 this.__setAriaHidden(alt === ""); |
| 2230 this.setAttribute("aria-label", alt) |
| 2231 } |
| 2232 }, |
| 2233 __setAriaHidden: function(hidden) { |
| 2234 var attr = "aria-hidden"; |
| 2235 if (hidden) { |
| 2236 this.setAttribute(attr, "true") |
| 2237 } else { |
| 2238 this.removeAttribute(attr) |
| 2239 } |
| 2240 }, |
| 2241 __reset: function() { |
| 2242 this.active = false; |
| 2243 this.__coolingDown = false |
| 2244 } |
| 2245 }; |
| 2246 Polymer({is: "paper-spinner-lite", behaviors: [Polymer.PaperSpinnerBehavior]}); |
| 21 // Copyright 2016 The Chromium Authors. All rights reserved. | 2247 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 22 // Use of this source code is governed by a BSD-style license that can be | 2248 // Use of this source code is governed by a BSD-style license that can be |
| 23 // found in the LICENSE file. | 2249 // found in the LICENSE file. |
| 24 var CrSearchFieldBehavior={properties:{label:{type:String,value:""},clearLabel:{
type:String,value:""},lastValue_:{type:String,value:""}},getSearchInput:function
(){},getValue:function(){return this.getSearchInput().value},setValue:function(v
alue,opt_noEvent){var searchInput=this.getSearchInput();searchInput.value=value;
this.onValueChanged_(value,!!opt_noEvent)},onSearchTermSearch:function(){this.on
ValueChanged_(this.getValue(),false)},onValueChanged_:function(newValue,noEvent)
{if(newValue==this.lastValue_)return;this.lastValue_=newValue;if(!noEvent)this.f
ire("search-changed",newValue)}}; | 2250 var CrSearchFieldBehavior = { |
| 2251 properties: { |
| 2252 label: {type: String, value: ""}, |
| 2253 clearLabel: {type: String, value: ""}, |
| 2254 lastValue_: {type: String, value: ""} |
| 2255 }, |
| 2256 getSearchInput: function() {}, |
| 2257 getValue: function() { |
| 2258 return this.getSearchInput().value |
| 2259 }, |
| 2260 setValue: function(value, opt_noEvent) { |
| 2261 var searchInput = this.getSearchInput(); |
| 2262 searchInput.value = value; |
| 2263 this.onValueChanged_(value, !!opt_noEvent) |
| 2264 }, |
| 2265 onSearchTermSearch: function() { |
| 2266 this.onValueChanged_(this.getValue(), false) |
| 2267 }, |
| 2268 onValueChanged_: function(newValue, noEvent) { |
| 2269 if (newValue == this.lastValue_) |
| 2270 return; |
| 2271 this.lastValue_ = newValue; |
| 2272 if (!noEvent) |
| 2273 this.fire("search-changed", newValue) |
| 2274 } |
| 2275 }; |
| 25 // Copyright 2016 The Chromium Authors. All rights reserved. | 2276 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 26 // Use of this source code is governed by a BSD-style license that can be | 2277 // Use of this source code is governed by a BSD-style license that can be |
| 27 // found in the LICENSE file. | 2278 // found in the LICENSE file. |
| 28 Polymer({is:"cr-toolbar-search-field",behaviors:[CrSearchFieldBehavior],properti
es:{narrow:{type:Boolean,reflectToAttribute:true},showingSearch:{type:Boolean,va
lue:false,notify:true,observer:"showingSearchChanged_",reflectToAttribute:true},
label:String,clearLabel:String,spinnerActive:{type:Boolean,reflectToAttribute:tr
ue},hasSearchText_:{type:Boolean,reflectToAttribute:true},isSpinnerShown_:{type:
Boolean,computed:"computeIsSpinnerShown_(spinnerActive, showingSearch)"},searchF
ocused_:{type:Boolean,value:false}},listeners:{click:"showSearch_"},getSearchInp
ut:function(){return this.$.searchInput},setValue:function(value,opt_noEvent){Cr
SearchFieldBehavior.setValue.call(this,value,opt_noEvent);this.onSearchInput_()}
,isSearchFocused:function(){return this.searchFocused_},showAndFocus:function(){
this.showingSearch=true;this.focus_()},focus_:function(){this.getSearchInput().f
ocus()},computeIconTabIndex_:function(narrow){return narrow?0:-1},computeIsSpinn
erShown_:function(){return this.spinnerActive&&this.showingSearch},onInputFocus_
:function(){this.searchFocused_=true},onInputBlur_:function(){this.searchFocused
_=false;if(!this.hasSearchText_)this.showingSearch=false},onSearchInput_:functio
n(){var newValue=this.$.searchInput.value;this.hasSearchText_=newValue!="";if(ne
wValue!="")this.showingSearch=true},onSearchTermKeydown_:function(e){if(e.key=="
Escape")this.showingSearch=false},showSearch_:function(e){if(e.target!=this.$.cl
earSearch)this.showingSearch=true},clearSearch_:function(e){this.setValue("");th
is.focus_()},showingSearchChanged_:function(current,previous){if(previous==undef
ined)return;if(this.showingSearch){this.focus_();return}this.setValue("");this.g
etSearchInput().blur()}}); | 2279 Polymer({ |
| 2280 is: "cr-toolbar-search-field", |
| 2281 behaviors: [CrSearchFieldBehavior], |
| 2282 properties: { |
| 2283 narrow: {type: Boolean, reflectToAttribute: true}, |
| 2284 showingSearch: { |
| 2285 type: Boolean, |
| 2286 value: false, |
| 2287 notify: true, |
| 2288 observer: "showingSearchChanged_", |
| 2289 reflectToAttribute: true |
| 2290 }, |
| 2291 label: String, |
| 2292 clearLabel: String, |
| 2293 spinnerActive: {type: Boolean, reflectToAttribute: true}, |
| 2294 hasSearchText_: {type: Boolean, reflectToAttribute: true}, |
| 2295 isSpinnerShown_: { |
| 2296 type: Boolean, |
| 2297 computed: "computeIsSpinnerShown_(spinnerActive, showingSearch)" |
| 2298 }, |
| 2299 searchFocused_: {type: Boolean, value: false} |
| 2300 }, |
| 2301 listeners: {click: "showSearch_"}, |
| 2302 getSearchInput: function() { |
| 2303 return this.$.searchInput |
| 2304 }, |
| 2305 setValue: function(value, opt_noEvent) { |
| 2306 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); |
| 2307 this.onSearchInput_() |
| 2308 }, |
| 2309 isSearchFocused: function() { |
| 2310 return this.searchFocused_ |
| 2311 }, |
| 2312 showAndFocus: function() { |
| 2313 this.showingSearch = true; |
| 2314 this.focus_() |
| 2315 }, |
| 2316 focus_: function() { |
| 2317 this.getSearchInput().focus() |
| 2318 }, |
| 2319 computeIconTabIndex_: function(narrow) { |
| 2320 return narrow ? 0 : -1 |
| 2321 }, |
| 2322 computeIsSpinnerShown_: function() { |
| 2323 return this.spinnerActive && this.showingSearch |
| 2324 }, |
| 2325 onInputFocus_: function() { |
| 2326 this.searchFocused_ = true |
| 2327 }, |
| 2328 onInputBlur_: function() { |
| 2329 this.searchFocused_ = false; |
| 2330 if (!this.hasSearchText_) |
| 2331 this.showingSearch = false |
| 2332 }, |
| 2333 onSearchInput_: function() { |
| 2334 var newValue = this.$.searchInput.value; |
| 2335 this.hasSearchText_ = newValue != ""; |
| 2336 if (newValue != "") |
| 2337 this.showingSearch = true |
| 2338 }, |
| 2339 onSearchTermKeydown_: function(e) { |
| 2340 if (e.key == "Escape") |
| 2341 this.showingSearch = false |
| 2342 }, |
| 2343 showSearch_: function(e) { |
| 2344 if (e.target != this.$.clearSearch) |
| 2345 this.showingSearch = true |
| 2346 }, |
| 2347 clearSearch_: function(e) { |
| 2348 this.setValue(""); |
| 2349 this.focus_() |
| 2350 }, |
| 2351 showingSearchChanged_: function(current, previous) { |
| 2352 if (previous == undefined) |
| 2353 return; |
| 2354 if (this.showingSearch) { |
| 2355 this.focus_(); |
| 2356 return |
| 2357 } |
| 2358 this.setValue(""); |
| 2359 this.getSearchInput().blur() |
| 2360 } |
| 2361 }); |
| 29 // Copyright 2016 The Chromium Authors. All rights reserved. | 2362 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 30 // Use of this source code is governed by a BSD-style license that can be | 2363 // Use of this source code is governed by a BSD-style license that can be |
| 31 // found in the LICENSE file. | 2364 // found in the LICENSE file. |
| 32 Polymer({is:"cr-toolbar",properties:{pageName:String,searchPrompt:String,clearLa
bel:String,menuLabel:String,menuPromo:String,spinnerActive:Boolean,showMenu:{typ
e:Boolean,value:false},showMenuPromo:{type:Boolean,value:false},closeMenuPromo:S
tring,narrow_:{type:Boolean,reflectToAttribute:true},showingSearch_:{type:Boolea
n,reflectToAttribute:true}},observers:["possiblyShowMenuPromo_(showMenu, showMen
uPromo, showingSearch_)"],getSearchField:function(){return this.$.search},onClos
ePromoTap_:function(){this.fire("cr-toolbar-menu-promo-close")},onMenuTap_:funct
ion(){this.fire("cr-toolbar-menu-tap")},possiblyShowMenuPromo_:function(){Polyme
r.RenderStatus.afterNextRender(this,function(){if(this.showMenu&&this.showMenuPr
omo&&!this.showingSearch_){this.$$("#menuPromo").animate({opacity:[0,.9]},{durat
ion:500,fill:"forwards"});this.fire("cr-toolbar-menu-promo-shown")}}.bind(this))
},titleIfNotShowMenuPromo_:function(title,showMenuPromo){return showMenuPromo?""
:title}}); | 2365 Polymer({ |
| 2366 is: "cr-toolbar", |
| 2367 properties: { |
| 2368 pageName: String, |
| 2369 searchPrompt: String, |
| 2370 clearLabel: String, |
| 2371 menuLabel: String, |
| 2372 menuPromo: String, |
| 2373 spinnerActive: Boolean, |
| 2374 showMenu: {type: Boolean, value: false}, |
| 2375 showMenuPromo: {type: Boolean, value: false}, |
| 2376 closeMenuPromo: String, |
| 2377 narrow_: {type: Boolean, reflectToAttribute: true}, |
| 2378 showingSearch_: {type: Boolean, reflectToAttribute: true} |
| 2379 }, |
| 2380 observers: |
| 2381 ["possiblyShowMenuPromo_(showMenu, showMenuPromo, showingSearch_)"], |
| 2382 getSearchField: function() { |
| 2383 return this.$.search |
| 2384 }, |
| 2385 onClosePromoTap_: function() { |
| 2386 this.fire("cr-toolbar-menu-promo-close") |
| 2387 }, |
| 2388 onMenuTap_: function() { |
| 2389 this.fire("cr-toolbar-menu-tap") |
| 2390 }, |
| 2391 possiblyShowMenuPromo_: function() { |
| 2392 Polymer.RenderStatus.afterNextRender(this, function() { |
| 2393 if (this.showMenu && this.showMenuPromo && !this.showingSearch_) { |
| 2394 this.$$("#menuPromo") |
| 2395 .animate({opacity: [0, .9]}, {duration: 500, fill: "forwards"}); |
| 2396 this.fire("cr-toolbar-menu-promo-shown") |
| 2397 } |
| 2398 }.bind(this)) |
| 2399 }, |
| 2400 titleIfNotShowMenuPromo_: function(title, showMenuPromo) { |
| 2401 return showMenuPromo ? "" : title |
| 2402 } |
| 2403 }); |
| 33 // Copyright 2016 The Chromium Authors. All rights reserved. | 2404 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 34 // Use of this source code is governed by a BSD-style license that can be | 2405 // Use of this source code is governed by a BSD-style license that can be |
| 35 // found in the LICENSE file. | 2406 // found in the LICENSE file. |
| 36 cr.define("md_history",function(){function BrowserService(){this.pendingDeleteIt
ems_=null;this.pendingDeletePromise_=null}BrowserService.prototype={deleteItems:
function(items){if(this.pendingDeleteItems_!=null){return new Promise(function(r
esolve,reject){reject(items)})}var removalList=items.map(function(item){return{u
rl:item.url,timestamps:item.allTimestamps}});this.pendingDeleteItems_=items;this
.pendingDeletePromise_=new PromiseResolver;chrome.send("removeVisits",removalLis
t);return this.pendingDeletePromise_.promise},removeBookmark:function(url){chrom
e.send("removeBookmark",[url])},openForeignSessionAllTabs:function(sessionTag){c
hrome.send("openForeignSession",[sessionTag])},openForeignSessionTab:function(se
ssionTag,windowId,tabId,e){chrome.send("openForeignSession",[sessionTag,String(w
indowId),String(tabId),e.button||0,e.altKey,e.ctrlKey,e.metaKey,e.shiftKey])},de
leteForeignSession:function(sessionTag){chrome.send("deleteForeignSession",[sess
ionTag])},openClearBrowsingData:function(){chrome.send("clearBrowsingData")},rec
ordHistogram:function(histogram,value,max){chrome.send("metricsHandler:recordInH
istogram",[histogram,value,max])},recordAction:function(action){if(action.indexO
f("_")==-1)action="HistoryPage_"+action;chrome.send("metricsHandler:recordAction
",[action])},resolveDelete_:function(successful){if(this.pendingDeleteItems_==nu
ll||this.pendingDeletePromise_==null){return}if(successful)this.pendingDeletePro
mise_.resolve(this.pendingDeleteItems_);else this.pendingDeletePromise_.reject(t
his.pendingDeleteItems_);this.pendingDeleteItems_=null;this.pendingDeletePromise
_=null},menuPromoShown:function(){chrome.send("menuPromoShown")}};cr.addSingleto
nGetter(BrowserService);return{BrowserService:BrowserService}});function deleteC
omplete(){md_history.BrowserService.getInstance().resolveDelete_(true)}function
deleteFailed(){md_history.BrowserService.getInstance().resolveDelete_(false)} | 2407 cr.define("md_history", function() { |
| 2408 function BrowserService() { |
| 2409 this.pendingDeleteItems_ = null; |
| 2410 this.pendingDeletePromise_ = null |
| 2411 } |
| 2412 BrowserService.prototype = { |
| 2413 deleteItems: function(items) { |
| 2414 if (this.pendingDeleteItems_ != null) { |
| 2415 return new Promise(function(resolve, reject) { |
| 2416 reject(items) |
| 2417 }) |
| 2418 } |
| 2419 var removalList = items.map(function(item) { |
| 2420 return { |
| 2421 url: item.url, timestamps: item.allTimestamps |
| 2422 } |
| 2423 }); |
| 2424 this.pendingDeleteItems_ = items; |
| 2425 this.pendingDeletePromise_ = new PromiseResolver; |
| 2426 chrome.send("removeVisits", removalList); |
| 2427 return this.pendingDeletePromise_.promise |
| 2428 }, |
| 2429 removeBookmark: function(url) { |
| 2430 chrome.send("removeBookmark", [url]) |
| 2431 }, |
| 2432 openForeignSessionAllTabs: function(sessionTag) { |
| 2433 chrome.send("openForeignSession", [sessionTag]) |
| 2434 }, |
| 2435 openForeignSessionTab: function(sessionTag, windowId, tabId, e) { |
| 2436 chrome.send("openForeignSession", [ |
| 2437 sessionTag, String(windowId), String(tabId), e.button || 0, e.altKey, |
| 2438 e.ctrlKey, e.metaKey, e.shiftKey |
| 2439 ]) |
| 2440 }, |
| 2441 deleteForeignSession: function(sessionTag) { |
| 2442 chrome.send("deleteForeignSession", [sessionTag]) |
| 2443 }, |
| 2444 openClearBrowsingData: function() { |
| 2445 chrome.send("clearBrowsingData") |
| 2446 }, |
| 2447 recordHistogram: function(histogram, value, max) { |
| 2448 chrome.send("metricsHandler:recordInHistogram", [histogram, value, max]) |
| 2449 }, |
| 2450 recordAction: function(action) { |
| 2451 if (action.indexOf("_") == -1) |
| 2452 action = "HistoryPage_" + action; |
| 2453 chrome.send("metricsHandler:recordAction", [action]) |
| 2454 }, |
| 2455 resolveDelete_: function(successful) { |
| 2456 if (this.pendingDeleteItems_ == null || |
| 2457 this.pendingDeletePromise_ == null) { |
| 2458 return |
| 2459 } |
| 2460 if (successful) |
| 2461 this.pendingDeletePromise_.resolve(this.pendingDeleteItems_); |
| 2462 else |
| 2463 this.pendingDeletePromise_.reject(this.pendingDeleteItems_); |
| 2464 this.pendingDeleteItems_ = null; |
| 2465 this.pendingDeletePromise_ = null |
| 2466 }, |
| 2467 menuPromoShown: function() { |
| 2468 chrome.send("menuPromoShown") |
| 2469 } |
| 2470 }; |
| 2471 cr.addSingletonGetter(BrowserService); |
| 2472 return { |
| 2473 BrowserService: BrowserService |
| 2474 } |
| 2475 }); |
| 2476 function deleteComplete() { |
| 2477 md_history.BrowserService.getInstance().resolveDelete_(true) |
| 2478 } |
| 2479 function deleteFailed() { |
| 2480 md_history.BrowserService.getInstance().resolveDelete_(false) |
| 2481 } |
| 37 // Copyright 2015 The Chromium Authors. All rights reserved. | 2482 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 38 // Use of this source code is governed by a BSD-style license that can be | 2483 // Use of this source code is governed by a BSD-style license that can be |
| 39 // found in the LICENSE file. | 2484 // found in the LICENSE file. |
| 40 Polymer({is:"history-toolbar",properties:{count:{type:Number,value:0,observer:"c
hangeToolbarView_"},itemsSelected_:{type:Boolean,value:false,reflectToAttribute:
true},searchTerm:{type:String,observer:"searchTermChanged_",notify:true},spinner
Active:{type:Boolean,value:false},hasDrawer:{type:Boolean,reflectToAttribute:tru
e},isGroupedMode:{type:Boolean,reflectToAttribute:true},groupedRange:{type:Numbe
r,reflectToAttribute:true,notify:true},groupedOffset:{type:Number,notify:true},q
uerying:Boolean,hasMoreResults:Boolean,queryStartTime:String,queryEndTime:String
,showMenuPromo:Boolean,showSyncNotice:Boolean},get searchField(){return this.$["
main-toolbar"].getSearchField()},showSearchField:function(){this.searchField.sho
wAndFocus()},changeToolbarView_:function(){this.itemsSelected_=this.count>0},sea
rchTermChanged_:function(){if(this.searchField.getValue()!=this.searchTerm){this
.searchField.showAndFocus();this.searchField.setValue(this.searchTerm)}},onSearc
hChanged_:function(event){this.searchTerm=event.detail},onInfoButtonTap_:functio
n(){var dropdown=this.$.syncNotice.get();dropdown.positionTarget=this.$$("#info-
button-icon");if(dropdown.style.display=="none")dropdown.open()},onClearSelectio
nTap_:function(){this.fire("unselect-all")},onDeleteTap_:function(){this.fire("d
elete-selected")},deletingAllowed_:function(){return loadTimeData.getBoolean("al
lowDeletingHistory")},numberOfItemsSelected_:function(count){return count>0?load
TimeData.getStringF("itemsSelected",count):""},getHistoryInterval_:function(quer
yStartTime,queryEndTime){return loadTimeData.getStringF("historyInterval",queryS
tartTime,queryEndTime)},onTodayTap_:function(){if(!this.querying)this.groupedOff
set=0},onPrevTap_:function(){if(!this.querying)this.groupedOffset=this.groupedOf
fset+1},onNextTap_:function(){if(!this.querying)this.groupedOffset=this.groupedO
ffset-1},isToday_:function(){return this.groupedOffset==0}});(function(){"use st
rict";Polymer.IronA11yAnnouncer=Polymer({is:"iron-a11y-announcer",properties:{mo
de:{type:String,value:"polite"},_text:{type:String,value:""}},created:function()
{if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.instance=this
}document.body.addEventListener("iron-announce",this._onIronAnnounce.bind(this))
},announce:function(text){this._text="";this.async(function(){this._text=text},1
00)},_onIronAnnounce:function(event){if(event.detail&&event.detail.text){this.an
nounce(event.detail.text)}}});Polymer.IronA11yAnnouncer.instance=null;Polymer.Ir
onA11yAnnouncer.requestAvailability=function(){if(!Polymer.IronA11yAnnouncer.ins
tance){Polymer.IronA11yAnnouncer.instance=document.createElement("iron-a11y-anno
uncer")}document.body.appendChild(Polymer.IronA11yAnnouncer.instance)}})();(func
tion(){var IOS=navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/);
var IOS_TOUCH_SCROLLING=IOS&&IOS[1]>=8;var DEFAULT_PHYSICAL_COUNT=3;var HIDDEN_Y
="-10000px";var ITEM_WIDTH=0;var ITEM_HEIGHT=1;var SECRET_TABINDEX=-100;Polymer(
{is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{type:Number,val
ue:500},as:{type:String,value:"item"},indexAs:{type:String,value:"index"},select
edAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,reflectToAttr
ibute:true},selectionEnabled:{type:Boolean,value:false},selectedItem:{type:Objec
t,notify:true},selectedItems:{type:Object,notify:true},multiSelection:{type:Bool
ean,value:false}},observers:["_itemsChanged(items.*)","_selectionEnabledChanged(
selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOverflow(scroll
Target)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavior,Polymer.I
ronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{up:"_didMoveU
p",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPaddingTop:0,_scrol
lPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount:0,_physical
Top:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_scrollHeight
:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalSizes:null,_f
irstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,_maxPages:2,
_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focusBackfillItem
:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _physicalBott
om(){return this._physicalTop+this._physicalSize},get _scrollBottom(){return thi
s._scrollPosition+this._viewportHeight},get _virtualEnd(){return this._virtualSt
art+this._physicalCount-1},get _hiddenContentSize(){var size=this.grid?this._phy
sicalRows*this._rowHeight:this._physicalSize;return size-this._viewportHeight},g
et _maxScrollTop(){return this._estScrollHeight-this._viewportHeight+this._scrol
lerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math.max(0,this.
_virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualStart(val){th
is._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._minVirtualStar
t,val))},get _virtualStart(){return this._virtualStartVal||0},_physicalStartVal:
0,set _physicalStart(val){this._physicalStartVal=val%this._physicalCount;if(this
._physicalStartVal<0){this._physicalStartVal=this._physicalCount+this._physicalS
tartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1)%this._phys
icalCount},get _physicalStart(){return this._physicalStartVal||0},_physicalCount
Val:0,set _physicalCount(val){this._physicalCountVal=val;this._physicalEnd=(this
._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalCount()
{return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(){if(this.gr
id){return this._estRowsInView*this._rowHeight*this._maxPages}return this._viewp
ortHeight*this._maxPages},get _isVisible(){return Boolean(this.offsetWidth||this
.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVal===null){va
r physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingTop);this._fi
rstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOffset+=this._
getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPosition){return th
is.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtualCount-1===vi
dx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisibleIndexVal},
get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.grid){var la
stIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow-1;this._las
tVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var physicalOffset=
this._physicalTop;this._iterateItems(function(pidx,vidx){if(physicalOffset<this.
_scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physicalOffset+=t
his._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndexVal},get _de
faultScrollTarget(){return this},get _virtualRowCount(){return Math.ceil(this._v
irtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.ceil(this._view
portHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(this._physical
Count/this._itemsPerRow)},ready:function(){this.addEventListener("focus",this._d
idFocus.bind(this),true)},attached:function(){if(this._physicalCount===0){this._
debounceTemplate(this._render)}this.listen(this,"iron-resize","_resizeHandler")}
,detached:function(){this.unlisten(this,"iron-resize","_resizeHandler")},_setOve
rflow:function(scrollTarget){this.style.webkitOverflowScrolling=scrollTarget===t
his?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},updateViewport
Boundaries:function(){this._scrollerPaddingTop=this.scrollTarget===this?0:parseI
nt(window.getComputedStyle(this)["padding-top"],10);this._viewportWidth=this.$.i
tems.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.grid&&this._
updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.max(0,Math.min
(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scrollPosition;v
ar isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._firstVisibleInd
exVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._physicalSize)
{var idxAdjustment=Math.round(delta/this._physicalAverage)*this._itemsPerRow;thi
s._physicalTop=this._physicalTop+delta;this._virtualStart=this._virtualStart+idx
Adjustment;this._physicalStart=this._physicalStart+idxAdjustment;this._update()}
else{var reusables=this._getReusables(isScrollingDown);if(isScrollingDown){this.
_physicalTop=reusables.physicalTop;this._virtualStart=this._virtualStart+reusabl
es.indexes.length;this._physicalStart=this._physicalStart+reusables.indexes.leng
th}else{this._virtualStart=this._virtualStart-reusables.indexes.length;this._phy
sicalStart=this._physicalStart-reusables.indexes.length}if(reusables.indexes.len
gth===0){this._increasePoolIfNeeded()}else{this._update(reusables.indexes,isScro
llingDown?null:reusables.indexes)}}},_getReusables:function(fromTop){var ith,las
tIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffsetContent=thi
s._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart;var virtual
End=this._virtualEnd;var physicalCount=this._physicalCount;var physicalTop=this.
_physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;var scrollBo
ttom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=this._physic
alEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd;lastIth=thi
s._physicalStart;offsetContent=this._physicalBottom-scrollBottom}while(true){phy
sicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=offsetContent-
physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=protectedOffset
Content){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtualCount){brea
k}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith);physicalTop
=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(virtualStart-i
dxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemHeight<=scrol
lBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHeight;ith=ith
===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physicalTop-this._sc
rollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&itemSet.length
===0){return}this._manageFocus();this._assignModels(itemSet);this._updateMetrics
(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop();this._physi
calTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();this._updateS
crollerSize();this._increasePoolIfNeeded()},_createPool:function(size){var physi
calItems=new Array(size);this._ensureTemplatized();for(var i=0;i<size;i++){var i
nst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");Polymer.dom(t
his).appendChild(inst.root)}return physicalItems},_increasePoolIfNeeded:function
(){if(this._viewportHeight===0){return false}var self=this;var isClientFull=this
._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrollPosition;if
(this._physicalSize>=this._optPhysicalSize&&isClientFull){return false}var maxPo
olSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._debounceTempla
te(this._increasePool.bind(this,maxPoolSize));return true}this._yield(function()
{self._increasePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/self._template
Cost))))});return true},_yield:function(cb){var g=window;var handle=g.requestIdl
eCallback?g.requestIdleCallback(cb):g.setTimeout(cb,16);Polymer.dom.addDebouncer
({complete:function(){g.cancelIdleCallback?g.cancelIdleCallback(handle):g.clearT
imeout(handle);cb()}})},_increasePool:function(missingItems){var nextPhysicalCou
nt=Math.min(this._physicalCount+missingItems,this._virtualCount-this._virtualSta
rt,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhysicalCount
=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;var ts=window
.performance.now();if(delta<=0){return}[].push.apply(this._physicalItems,this._c
reatePool(delta));[].push.apply(this._physicalSizes,new Array(delta));this._phys
icalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physicalEnd&&this
._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._focusedIndex
)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}this._update(
);this._templateCost=(window.performance.now()-ts)/delta},_render:function(){if(
this.isAttached&&this._isVisible){if(this._physicalCount===0){this.updateViewpor
tBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var reusables=this
._getReusables(true);this._physicalTop=reusables.physicalTop;this._virtualStart=
this._virtualStart+reusables.indexes.length;this._physicalStart=this._physicalSt
art+reusables.indexes.length;this._update(reusables.indexes);this._update()}}},_
ensureTemplatized:function(){if(!this.ctor){var props={};props.__key__=true;prop
s[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true;props.tabIn
dex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(this).querySel
ector("template");if(this._userTemplate){this.templatize(this._userTemplate)}els
e{console.warn("iron-list requires a template to be provided in light-dom")}}},_
getStampedChildren:function(){return this._physicalItems},_forwardInstancePath:f
unction(inst,path,value){if(path.indexOf(this.as+".")===0){this.notifyPath("item
s."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardParentProp:fu
nction(prop,value){if(this._physicalItems){this._physicalItems.forEach(function(
item){item._templateInstance[prop]=value},this)}},_forwardParentPath:function(pa
th,value){if(this._physicalItems){this._physicalItems.forEach(function(item){ite
m._templateInstance.notifyPath(path,value,true)},this)}},_forwardItemPath:functi
on(path,value){if(!this._physicalIndexForKey){return}var dot=path.indexOf(".");v
ar key=path.substring(0,dot<0?path.length:dot);var idx=this._physicalIndexForKey
[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenItem&&offscre
enItem._templateInstance.__key__===key?offscreenItem:this._physicalItems[idx];if
(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=this.as+"."+pat
h.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}else{var cur
rentItem=el._templateInstance[this.as];if(Array.isArray(this.selectedItems)){for
(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]===currentItem
){this.set("selectedItems."+i,value);break}}}else if(this.selectedItem===current
Item){this.set("selectedItem",value)}el._templateInstance[this.as]=value}},_item
sChanged:function(change){if(change.path==="items"){this._virtualStart=0;this._p
hysicalTop=0;this._virtualCount=this.items?this.items.length:0;this._collection=
this.items?Polymer.Collection.get(this.items):null;this._physicalIndexForKey={};
this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this._physicalCou
nt=this._physicalCount||0;this._physicalItems=this._physicalItems||[];this._phys
icalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetScrollPositio
n(0);this._removeFocusedItem();this._debounceTemplate(this._render)}else if(chan
ge.path==="items.splices"){this._adjustVirtualIndex(change.value.indexSplices);t
his._virtualCount=this.items?this.items.length:0;this._debounceTemplate(this._re
nder)}else{this._forwardItemPath(change.path.split(".").slice(1).join("."),chang
e.value)}},_adjustVirtualIndex:function(splices){splices.forEach(function(splice
){splice.removed.forEach(this._removeItem,this);if(splice.index<this._virtualSta
rt){var delta=Math.max(splice.addedCount-splice.removed.length,splice.index-this
._virtualStart);this._virtualStart=this._virtualStart+delta;if(this._focusedInde
x>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeItem:function
(item){this.$.selector.deselect(item);if(this._focusedItem&&this._focusedItem._t
emplateInstance[this.as]===item){this._removeFocusedItem()}},_iterateItems:funct
ion(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet){for(i=0;i<
itemSet.length;i++){pidx=itemSet[i];vidx=this._computeVidx(pidx);if((rtn=fn.call
(this,pidx,vidx))!=null){return rtn}}}else{pidx=this._physicalStart;vidx=this._v
irtualStart;for(;pidx<this._physicalCount;pidx++,vidx++){if((rtn=fn.call(this,pi
dx,vidx))!=null){return rtn}}for(pidx=0;pidx<this._physicalStart;pidx++,vidx++){
if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:function(pid
x){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-this._physicalS
tart)}return this._virtualStart+(this._physicalCount-this._physicalStart)+pidx},
_assignModels:function(itemSet){this._iterateItems(function(pidx,vidx){var el=th
is._physicalItems[pidx];var inst=el._templateInstance;var item=this.items&&this.
items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._collection.getK
ey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst[this.indexA
s]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalIndexForKey[i
nst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=null;el.setAttr
ibute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Polymer.dom.flus
h();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=this._physicalA
verageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateItems(functio
n(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._physicalSizes[p
idx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._physicalSizes
[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},itemSet);if(th
is.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._physicalCo
unt/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._physicalSiz
e+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prevAvgCount){
this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhysicalSize)/
this._physicalAverageCount)}},_updateGridMetrics:function(){this._itemWidth=this
._physicalCount>0?this._physicalItems[0].getBoundingClientRect().width:200;this.
_rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight:200;this._i
temsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWidth):this.
_itemsPerRow},_positionItems:function(){this._adjustScrollPosition();var y=this.
_physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._itemWidth;
var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItems(function
(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulus*this._it
emWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItems[pidx]);i
f(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._iterateItems
(function(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[pidx]);y+=t
his._physicalSizes[pidx]})}},_getPhysicalSizeIncrement:function(pidx){if(!this.g
rid){return this._physicalSizes[pidx]}if(this._computeVidx(pidx)%this._itemsPerR
ow!==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRenderNextRow:
function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_adjustScrol
lPosition:function(){var deltaHeight=this._virtualStart===0?this._physicalTop:Ma
th.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this._physicalT
op=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physicalTop!==0)
{this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrollPosition:
function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPosition=thi
s._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid){this._est
ScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrollHeight=th
is._physicalBottom+Math.max(this._virtualCount-this._physicalCount-this._virtual
Start,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHeight===0;f
orceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-this._physic
alSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<this._estSc
rollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scrollHeight)>=t
his._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+"px";this.
_scrollHeight=this._estScrollHeight}},scrollToItem:function(item){return this.sc
rollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(typeof idx
!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush();if(this.
_physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualCount-1);if
(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtualStart=thi
s.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignModels();th
is._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/this._itemsP
erRow)*this._physicalAverage;var currentTopItem=this._physicalStart;var currentV
irtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentSize=this._
hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hiddenContentSi
ze){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(currentTopIte
m);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtualItem++}th
is._updateScrollerSize(true);this._positionItems();this._resetScrollPosition(thi
s._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increasePoolIfNee
ded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},_resetAver
age:function(){this._physicalAverage=0;this._physicalAverageCount=0},_resizeHand
ler:function(){var delta=Math.abs(this._viewportHeight-this._scrollTargetHeight)
;if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.debounce("_deb
ounceTemplate",function(){this.updateViewportBoundaries();this._render();if(this
._isVisible){this.toggleScrollListener(true);if(this._physicalCount>0){this._res
etAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.toggleScrollLi
stener(false)}}.bind(this),1))},_getModelFromItem:function(item){var key=this._c
ollection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){re
turn this._physicalItems[pidx]._templateInstance}return null},_getNormalizedItem
:function(item){if(this._collection.getKey(item)===undefined){if(typeof item==="
number"){item=this.items[item];if(!item){throw new RangeError("<item> not found"
)}return item}throw new TypeError("<item> should be a valid item")}return item},
selectItem:function(item){item=this._getNormalizedItem(item);var model=this._get
ModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this.deselectIte
m(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.selector.selec
t(item);this.updateSizeForItem(item)},deselectItem:function(item){item=this._get
NormalizedItem(item);var model=this._getModelFromItem(item);if(model){model[this
.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeForItem(item)},
toggleSelectionForItem:function(item){item=this._getNormalizedItem(item);if(this
.$.selector.isSelected(item)){this.deselectItem(item)}else{this.selectItem(item)
}},clearSelection:function(){function unselect(item){var model=this._getModelFro
mItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray(this.select
edItems)){this.selectedItems.forEach(unselect,this)}else if(this.selectedItem){u
nselect.call(this,this.selectedItem)}this.$.selector.clearSelection()},_selectio
nEnabledChanged:function(selectionEnabled){var handler=selectionEnabled?this.lis
ten:this.unlisten;handler.call(this,this,"tap","_selectionHandler")},_selectionH
andler:function(e){var model=this.modelForElement(e.target);if(!model){return}va
r modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];var activeEl=
Polymer.dom(this.domHost?this.domHost.root:document).activeElement;var physicalI
tem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])];if(target.l
ocalName==="input"||target.localName==="button"||target.localName==="select"){re
turn}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;activeElTabInde
x=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(activeEl&&physic
alItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabIndex!==SECRET_TA
BINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiSelectionChang
ed:function(multiSelection){this.clearSelection();this.$.selector.multi=multiSel
ection},updateSizeForItem:function(item){item=this._getNormalizedItem(item);var
key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pid
x!=null){this._updateMetrics([pidx]);this._positionItems()}},_manageFocus:functi
on(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCount){if(this._i
sIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createFocusBackfillI
tem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._focusedIndex=t
his._virtualStart;this._focusedItem=this._physicalItems[this._physicalStart]}},_
isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=this._virtual
End},_isIndexVisible:function(idx){return idx>=this.firstVisibleIndex&&idx<=this
.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._physicalIndexFor
Key[this._collection.getKey(this._getNormalizedItem(idx))]},_focusPhysicalItem:f
unction(idx){if(idx<0||idx>=this._virtualCount){return}this._restoreFocusedItem(
);if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physicalItem=this.
_physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem._templateInst
ance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.tabIndex===SEC
RET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polymer.dom(physic
alItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tabIndex=0;this.
_focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:function(){if
(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._offscreenFocuse
dItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null;this._focuse
dItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function(){var fidx=t
his._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._offscreenFocuse
dItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var stampedTempla
te=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.querySelector("
*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offscreenFocusedIt
em=this._physicalItems[pidx];this._offscreenFocusedItem._templateInstance.tabInd
ex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.translate3d(0,HIDDEN
_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){var pidx,fidx=t
his._focusedIndex;if(!this._offscreenFocusedItem||this._focusedIndex<0){return}t
his._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null){this._focus
BackfillItem=this._physicalItems[pidx];this._focusBackfillItem._templateInstance
.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;this._offscree
nFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfillItem)}},_didF
ocus:function(e){var targetModel=this.modelForElement(e.target);var focusedModel
=this._focusedItem?this._focusedItem._templateInstance:null;var hasOffscreenFocu
sedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedIndex;if(!target
Model||!focusedModel){return}if(focusedModel===targetModel){if(!this._isIndexVis
ible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem();focusedMod
el.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs];this._focus
edIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysicalIndex(fidx)]
;if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._update()}}},_did
MoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_didMoveDown:fu
nction(e){e.detail.keyboardEvent.preventDefault();this._focusPhysicalItem(this._
focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this._focusedInde
x);this._selectionHandler(e.detail.keyboardEvent)}})})();Polymer({is:"iron-scrol
l-threshold",properties:{upperThreshold:{type:Number,value:100},lowerThreshold:{
type:Number,value:100},upperTriggered:{type:Boolean,value:false,notify:true,read
Only:true},lowerTriggered:{type:Boolean,value:false,notify:true,readOnly:true},h
orizontal:{type:Boolean,value:false}},behaviors:[Polymer.IronScrollTargetBehavio
r],observers:["_setOverflow(scrollTarget)","_initCheck(horizontal, isAttached)"]
,get _defaultScrollTarget(){return this},_setOverflow:function(scrollTarget){thi
s.style.overflow=scrollTarget===this?"auto":""},_scrollHandler:function(){var TH
ROTTLE_THRESHOLD=200;if(!this.isDebouncerActive("_checkTheshold")){this.debounce
("_checkTheshold",function(){this.checkScrollThesholds()},THROTTLE_THRESHOLD)}},
_initCheck:function(horizontal,isAttached){if(isAttached){this.debounce("_init",
function(){this.clearTriggers();this.checkScrollThesholds()})}},checkScrollThesh
olds:function(){if(!this.scrollTarget||this.lowerTriggered&&this.upperTriggered)
{return}var upperScrollValue=this.horizontal?this._scrollLeft:this._scrollTop;va
r lowerScrollValue=this.horizontal?this.scrollTarget.scrollWidth-this._scrollTar
getWidth-this._scrollLeft:this.scrollTarget.scrollHeight-this._scrollTargetHeigh
t-this._scrollTop;if(upperScrollValue<=this.upperThreshold&&!this.upperTriggered
){this._setUpperTriggered(true);this.fire("upper-threshold")}if(lowerScrollValue
<=this.lowerThreshold&&!this.lowerTriggered){this._setLowerTriggered(true);this.
fire("lower-threshold")}},clearTriggers:function(){this._setUpperTriggered(false
);this._setLowerTriggered(false)}}); | 2485 Polymer({ |
| 2486 is: "history-toolbar", |
| 2487 properties: { |
| 2488 count: {type: Number, value: 0, observer: "changeToolbarView_"}, |
| 2489 itemsSelected_: {type: Boolean, value: false, reflectToAttribute: true}, |
| 2490 searchTerm: {type: String, observer: "searchTermChanged_", notify: true}, |
| 2491 spinnerActive: {type: Boolean, value: false}, |
| 2492 hasDrawer: {type: Boolean, reflectToAttribute: true}, |
| 2493 isGroupedMode: {type: Boolean, reflectToAttribute: true}, |
| 2494 groupedRange: {type: Number, reflectToAttribute: true, notify: true}, |
| 2495 groupedOffset: {type: Number, notify: true}, |
| 2496 querying: Boolean, |
| 2497 hasMoreResults: Boolean, |
| 2498 queryStartTime: String, |
| 2499 queryEndTime: String, |
| 2500 showMenuPromo: Boolean, |
| 2501 showSyncNotice: Boolean |
| 2502 }, |
| 2503 get searchField() { |
| 2504 return this.$["main-toolbar"].getSearchField() |
| 2505 }, |
| 2506 showSearchField: function() { |
| 2507 this.searchField.showAndFocus() |
| 2508 }, |
| 2509 changeToolbarView_: function() { |
| 2510 this.itemsSelected_ = this.count > 0 |
| 2511 }, |
| 2512 searchTermChanged_: function() { |
| 2513 if (this.searchField.getValue() != this.searchTerm) { |
| 2514 this.searchField.showAndFocus(); |
| 2515 this.searchField.setValue(this.searchTerm) |
| 2516 } |
| 2517 }, |
| 2518 onSearchChanged_: function(event) { |
| 2519 this.searchTerm = event.detail |
| 2520 }, |
| 2521 onInfoButtonTap_: function() { |
| 2522 var dropdown = this.$.syncNotice.get(); |
| 2523 dropdown.positionTarget = this.$$("#info-button-icon"); |
| 2524 if (dropdown.style.display == "none") |
| 2525 dropdown.open() |
| 2526 }, |
| 2527 onClearSelectionTap_: function() { |
| 2528 this.fire("unselect-all") |
| 2529 }, |
| 2530 onDeleteTap_: function() { |
| 2531 this.fire("delete-selected") |
| 2532 }, |
| 2533 deletingAllowed_: function() { |
| 2534 return loadTimeData.getBoolean("allowDeletingHistory") |
| 2535 }, |
| 2536 numberOfItemsSelected_: function(count) { |
| 2537 return count > 0 ? loadTimeData.getStringF("itemsSelected", count) : "" |
| 2538 }, |
| 2539 getHistoryInterval_: function(queryStartTime, queryEndTime) { |
| 2540 return loadTimeData.getStringF( |
| 2541 "historyInterval", queryStartTime, queryEndTime) |
| 2542 }, |
| 2543 onTodayTap_: function() { |
| 2544 if (!this.querying) |
| 2545 this.groupedOffset = 0 |
| 2546 }, |
| 2547 onPrevTap_: function() { |
| 2548 if (!this.querying) |
| 2549 this.groupedOffset = this.groupedOffset + 1 |
| 2550 }, |
| 2551 onNextTap_: function() { |
| 2552 if (!this.querying) |
| 2553 this.groupedOffset = this.groupedOffset - 1 |
| 2554 }, |
| 2555 isToday_: function() { |
| 2556 return this.groupedOffset == 0 |
| 2557 } |
| 2558 }); |
| 2559 (function() { |
| 2560 "use strict"; |
| 2561 Polymer.IronA11yAnnouncer = Polymer({ |
| 2562 is: "iron-a11y-announcer", |
| 2563 properties: { |
| 2564 mode: {type: String, value: "polite"}, |
| 2565 _text: {type: String, value: ""} |
| 2566 }, |
| 2567 created: function() { |
| 2568 if (!Polymer.IronA11yAnnouncer.instance) { |
| 2569 Polymer.IronA11yAnnouncer.instance = this |
| 2570 } |
| 2571 document.body.addEventListener( |
| 2572 "iron-announce", this._onIronAnnounce.bind(this)) |
| 2573 }, |
| 2574 announce: function(text) { |
| 2575 this._text = ""; |
| 2576 this.async(function() { |
| 2577 this._text = text |
| 2578 }, 100) |
| 2579 }, |
| 2580 _onIronAnnounce: function(event) { |
| 2581 if (event.detail && event.detail.text) { |
| 2582 this.announce(event.detail.text) |
| 2583 } |
| 2584 } |
| 2585 }); |
| 2586 Polymer.IronA11yAnnouncer.instance = null; |
| 2587 Polymer.IronA11yAnnouncer.requestAvailability = function() { |
| 2588 if (!Polymer.IronA11yAnnouncer.instance) { |
| 2589 Polymer.IronA11yAnnouncer.instance = |
| 2590 document.createElement("iron-a11y-announcer") |
| 2591 } |
| 2592 document.body.appendChild(Polymer.IronA11yAnnouncer.instance) |
| 2593 } |
| 2594 })(); |
| 2595 (function() { |
| 2596 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); |
| 2597 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; |
| 2598 var DEFAULT_PHYSICAL_COUNT = 3; |
| 2599 var HIDDEN_Y = "-10000px"; |
| 2600 var ITEM_WIDTH = 0; |
| 2601 var ITEM_HEIGHT = 1; |
| 2602 var SECRET_TABINDEX = -100; |
| 2603 Polymer({is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{type:
Number,value:500},as:{type:String,value:"item"},indexAs:{type:String,value:"inde
x"},selectedAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,ref
lectToAttribute:true},selectionEnabled:{type:Boolean,value:false},selectedItem:{
type:Object,notify:true},selectedItems:{type:Object,notify:true},multiSelection:
{type:Boolean,value:false}},observers:["_itemsChanged(items.*)","_selectionEnabl
edChanged(selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOverf
low(scrollTarget)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavior
,Polymer.IronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{up:
"_didMoveUp",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPaddingTo
p:0,_scrollPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount:0
,_physicalTop:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_sc
rollHeight:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalSiz
es:null,_firstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,_m
axPages:2,_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focusBa
ckfillItem:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _ph
ysicalBottom(){return this._physicalTop+this._physicalSize},get _scrollBottom(){
return this._scrollPosition+this._viewportHeight},get _virtualEnd(){return this.
_virtualStart+this._physicalCount-1},get _hiddenContentSize(){var size=this.grid
?this._physicalRows*this._rowHeight:this._physicalSize;return size-this._viewpor
tHeight},get _maxScrollTop(){return this._estScrollHeight-this._viewportHeight+t
his._scrollerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math.m
ax(0,this._virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualSta
rt(val){this._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._minV
irtualStart,val))},get _virtualStart(){return this._virtualStartVal||0},_physica
lStartVal:0,set _physicalStart(val){this._physicalStartVal=val%this._physicalCou
nt;if(this._physicalStartVal<0){this._physicalStartVal=this._physicalCount+this.
_physicalStartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1)%
this._physicalCount},get _physicalStart(){return this._physicalStartVal||0},_phy
sicalCountVal:0,set _physicalCount(val){this._physicalCountVal=val;this._physica
lEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physi
calCount(){return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(){
if(this.grid){return this._estRowsInView*this._rowHeight*this._maxPages}return t
his._viewportHeight*this._maxPages},get _isVisible(){return Boolean(this.offsetW
idth||this.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVal=
==null){var physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingTop
);this._firstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOffs
et+=this._getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPosition)
{return this.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtualCo
unt-1===vidx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisible
IndexVal},get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.gr
id){var lastIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow-1
;this._lastVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var physi
calOffset=this._physicalTop;this._iterateItems(function(pidx,vidx){if(physicalOf
fset<this._scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physica
lOffset+=this._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndexVa
l},get _defaultScrollTarget(){return this},get _virtualRowCount(){return Math.ce
il(this._virtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.ceil(
this._viewportHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(this
._physicalCount/this._itemsPerRow)},ready:function(){this.addEventListener("focu
s",this._didFocus.bind(this),true)},attached:function(){if(this._physicalCount==
=0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resize
Handler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandler"
)},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scroll
Target===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},upda
teViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===thi
s?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportWidt
h=this.$.items.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.gr
id&&this._updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.max(
0,Math.min(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scroll
Position;var isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._first
VisibleIndexVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._phy
sicalSize){var idxAdjustment=Math.round(delta/this._physicalAverage)*this._items
PerRow;this._physicalTop=this._physicalTop+delta;this._virtualStart=this._virtua
lStart+idxAdjustment;this._physicalStart=this._physicalStart+idxAdjustment;this.
_update()}else{var reusables=this._getReusables(isScrollingDown);if(isScrollingD
own){this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualSta
rt+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.in
dexes.length}else{this._virtualStart=this._virtualStart-reusables.indexes.length
;this._physicalStart=this._physicalStart-reusables.indexes.length}if(reusables.i
ndexes.length===0){this._increasePoolIfNeeded()}else{this._update(reusables.inde
xes,isScrollingDown?null:reusables.indexes)}}},_getReusables:function(fromTop){v
ar ith,lastIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffsetC
ontent=this._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart;v
ar virtualEnd=this._virtualEnd;var physicalCount=this._physicalCount;var physica
lTop=this._physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;va
r scrollBottom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=th
is._physicalEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd;l
astIth=this._physicalStart;offsetContent=this._physicalBottom-scrollBottom}while
(true){physicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=offs
etContent-physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=prote
ctedOffsetContent){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtualC
ount){break}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith);p
hysicalTop=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(virt
ualStart-idxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemHei
ght<=scrollBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHeig
ht;ith=ith===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physicalTo
p-this._scrollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&item
Set.length===0){return}this._manageFocus();this._assignModels(itemSet);this._upd
ateMetrics(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop();t
his._physicalTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();thi
s._updateScrollerSize();this._increasePoolIfNeeded()},_createPool:function(size)
{var physicalItems=new Array(size);this._ensureTemplatized();for(var i=0;i<size;
i++){var inst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");Pol
ymer.dom(this).appendChild(inst.root)}return physicalItems},_increasePoolIfNeede
d:function(){if(this._viewportHeight===0){return false}var self=this;var isClien
tFull=this._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrollP
osition;if(this._physicalSize>=this._optPhysicalSize&&isClientFull){return false
}var maxPoolSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._debo
unceTemplate(this._increasePool.bind(this,maxPoolSize));return true}this._yield(
function(){self._increasePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/self
._templateCost))))});return true},_yield:function(cb){var g=window;var handle=g.
requestIdleCallback?g.requestIdleCallback(cb):g.setTimeout(cb,16);Polymer.dom.ad
dDebouncer({complete:function(){g.cancelIdleCallback?g.cancelIdleCallback(handle
):g.clearTimeout(handle);cb()}})},_increasePool:function(missingItems){var nextP
hysicalCount=Math.min(this._physicalCount+missingItems,this._virtualCount-this._
virtualStart,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhy
sicalCount=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;var
ts=window.performance.now();if(delta<=0){return}[].push.apply(this._physicalIte
ms,this._createPool(delta));[].push.apply(this._physicalSizes,new Array(delta));
this._physicalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physica
lEnd&&this._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._fo
cusedIndex)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}thi
s._update();this._templateCost=(window.performance.now()-ts)/delta},_render:func
tion(){if(this.isAttached&&this._isVisible){if(this._physicalCount===0){this.upd
ateViewportBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var reus
ables=this._getReusables(true);this._physicalTop=reusables.physicalTop;this._vir
tualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._
physicalStart+reusables.indexes.length;this._update(reusables.indexes);this._upd
ate()}}},_ensureTemplatized:function(){if(!this.ctor){var props={};props.__key__
=true;props[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true;p
rops.tabIndex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(this
).querySelector("template");if(this._userTemplate){this.templatize(this._userTem
plate)}else{console.warn("iron-list requires a template to be provided in light-
dom")}}},_getStampedChildren:function(){return this._physicalItems},_forwardInst
ancePath:function(inst,path,value){if(path.indexOf(this.as+".")===0){this.notify
Path("items."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardPar
entProp:function(prop,value){if(this._physicalItems){this._physicalItems.forEach
(function(item){item._templateInstance[prop]=value},this)}},_forwardParentPath:f
unction(path,value){if(this._physicalItems){this._physicalItems.forEach(function
(item){item._templateInstance.notifyPath(path,value,true)},this)}},_forwardItemP
ath:function(path,value){if(!this._physicalIndexForKey){return}var dot=path.inde
xOf(".");var key=path.substring(0,dot<0?path.length:dot);var idx=this._physicalI
ndexForKey[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenIte
m&&offscreenItem._templateInstance.__key__===key?offscreenItem:this._physicalIte
ms[idx];if(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=this.
as+"."+path.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}el
se{var currentItem=el._templateInstance[this.as];if(Array.isArray(this.selectedI
tems)){for(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]===c
urrentItem){this.set("selectedItems."+i,value);break}}}else if(this.selectedItem
===currentItem){this.set("selectedItem",value)}el._templateInstance[this.as]=val
ue}},_itemsChanged:function(change){if(change.path==="items"){this._virtualStart
=0;this._physicalTop=0;this._virtualCount=this.items?this.items.length:0;this._c
ollection=this.items?Polymer.Collection.get(this.items):null;this._physicalIndex
ForKey={};this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this._p
hysicalCount=this._physicalCount||0;this._physicalItems=this._physicalItems||[];
this._physicalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetScr
ollPosition(0);this._removeFocusedItem();this._debounceTemplate(this._render)}el
se if(change.path==="items.splices"){this._adjustVirtualIndex(change.value.index
Splices);this._virtualCount=this.items?this.items.length:0;this._debounceTemplat
e(this._render)}else{this._forwardItemPath(change.path.split(".").slice(1).join(
"."),change.value)}},_adjustVirtualIndex:function(splices){splices.forEach(funct
ion(splice){splice.removed.forEach(this._removeItem,this);if(splice.index<this._
virtualStart){var delta=Math.max(splice.addedCount-splice.removed.length,splice.
index-this._virtualStart);this._virtualStart=this._virtualStart+delta;if(this._f
ocusedIndex>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeIte
m:function(item){this.$.selector.deselect(item);if(this._focusedItem&&this._focu
sedItem._templateInstance[this.as]===item){this._removeFocusedItem()}},_iterateI
tems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet){
for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=this._computeVidx(pidx);if((r
tn=fn.call(this,pidx,vidx))!=null){return rtn}}}else{pidx=this._physicalStart;vi
dx=this._virtualStart;for(;pidx<this._physicalCount;pidx++,vidx++){if((rtn=fn.ca
ll(this,pidx,vidx))!=null){return rtn}}for(pidx=0;pidx<this._physicalStart;pidx+
+,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:fu
nction(pidx){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-this.
_physicalStart)}return this._virtualStart+(this._physicalCount-this._physicalSta
rt)+pidx},_assignModels:function(itemSet){this._iterateItems(function(pidx,vidx)
{var el=this._physicalItems[pidx];var inst=el._templateInstance;var item=this.it
ems&&this.items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._colle
ction.getKey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst[t
his.indexAs]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalInd
exForKey[inst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=null;
el.setAttribute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Polyme
r.dom.flush();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=this.
_physicalAverageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateIte
ms(function(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._physi
calSizes[pidx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._phy
sicalSizes[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},item
Set);if(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._
physicalCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._p
hysicalSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prev
AvgCount){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhys
icalSize)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._item
Width=this._physicalCount>0?this._physicalItems[0].getBoundingClientRect().width
:200;this._rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight:2
00;this._itemsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWi
dth):this._itemsPerRow},_positionItems:function(){this._adjustScrollPosition();v
ar y=this._physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._
itemWidth;var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItem
s(function(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulu
s*this._itemWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItem
s[pidx]);if(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._it
erateItems(function(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[p
idx]);y+=this._physicalSizes[pidx]})}},_getPhysicalSizeIncrement:function(pidx){
if(!this.grid){return this._physicalSizes[pidx]}if(this._computeVidx(pidx)%this.
_itemsPerRow!==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRend
erNextRow:function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_a
djustScrollPosition:function(){var deltaHeight=this._virtualStart===0?this._phys
icalTop:Math.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this.
_physicalTop=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physic
alTop!==0){this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrol
lPosition:function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPo
sition=this._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid)
{this._estScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrol
lHeight=this._physicalBottom+Math.max(this._virtualCount-this._physicalCount-thi
s._virtualStart,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHe
ight===0;forceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-th
is._physicalSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<t
his._estScrollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scroll
Height)>=this._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+
"px";this._scrollHeight=this._estScrollHeight}},scrollToItem:function(item){retu
rn this.scrollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(
typeof idx!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush(
);if(this._physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualC
ount-1);if(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtua
lStart=this.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignM
odels();this._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/th
is._itemsPerRow)*this._physicalAverage;var currentTopItem=this._physicalStart;va
r currentVirtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentS
ize=this._hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hidde
nContentSize){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(cur
rentTopItem);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtua
lItem++}this._updateScrollerSize(true);this._positionItems();this._resetScrollPo
sition(this._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increas
ePoolIfNeeded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},
_resetAverage:function(){this._physicalAverage=0;this._physicalAverageCount=0},_
resizeHandler:function(){var delta=Math.abs(this._viewportHeight-this._scrollTar
getHeight);if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.debo
unce("_debounceTemplate",function(){this.updateViewportBoundaries();this._render
();if(this._isVisible){this.toggleScrollListener(true);if(this._physicalCount>0)
{this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.togg
leScrollListener(false)}}.bind(this),1))},_getModelFromItem:function(item){var k
ey=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx
!=null){return this._physicalItems[pidx]._templateInstance}return null},_getNorm
alizedItem:function(item){if(this._collection.getKey(item)===undefined){if(typeo
f item==="number"){item=this.items[item];if(!item){throw new RangeError("<item>
not found")}return item}throw new TypeError("<item> should be a valid item")}ret
urn item},selectItem:function(item){item=this._getNormalizedItem(item);var model
=this._getModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this.d
eselectItem(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.sele
ctor.select(item);this.updateSizeForItem(item)},deselectItem:function(item){item
=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(model){
model[this.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeForIt
em(item)},toggleSelectionForItem:function(item){item=this._getNormalizedItem(ite
m);if(this.$.selector.isSelected(item)){this.deselectItem(item)}else{this.select
Item(item)}},clearSelection:function(){function unselect(item){var model=this._g
etModelFromItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray(t
his.selectedItems)){this.selectedItems.forEach(unselect,this)}else if(this.selec
tedItem){unselect.call(this,this.selectedItem)}this.$.selector.clearSelection()}
,_selectionEnabledChanged:function(selectionEnabled){var handler=selectionEnable
d?this.listen:this.unlisten;handler.call(this,this,"tap","_selectionHandler")},_
selectionHandler:function(e){var model=this.modelForElement(e.target);if(!model)
{return}var modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];var
activeEl=Polymer.dom(this.domHost?this.domHost.root:document).activeElement;var
physicalItem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])];i
f(target.localName==="input"||target.localName==="button"||target.localName==="s
elect"){return}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;activ
eElTabIndex=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(active
El&&physicalItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabIndex!=
=SECRET_TABINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiSele
ctionChanged:function(multiSelection){this.clearSelection();this.$.selector.mult
i=multiSelection},updateSizeForItem:function(item){item=this._getNormalizedItem(
item);var key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[k
ey];if(pidx!=null){this._updateMetrics([pidx]);this._positionItems()}},_manageFo
cus:function(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCount){
if(this._isIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createFocu
sBackfillItem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._focu
sedIndex=this._virtualStart;this._focusedItem=this._physicalItems[this._physical
Start]}},_isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=thi
s._virtualEnd},_isIndexVisible:function(idx){return idx>=this.firstVisibleIndex&
&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._physic
alIndexForKey[this._collection.getKey(this._getNormalizedItem(idx))]},_focusPhys
icalItem:function(idx){if(idx<0||idx>=this._virtualCount){return}this._restoreFo
cusedItem();if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physical
Item=this._physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem._te
mplateInstance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.tabI
ndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polymer.
dom(physicalItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tabInd
ex=0;this._focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:fun
ction(){if(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._offsc
reenFocusedItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null;th
is._focusedItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function(){
var fidx=this._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._offsc
reenFocusedItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var sta
mpedTemplate=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.query
Selector("*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offscree
nFocusedItem=this._physicalItems[pidx];this._offscreenFocusedItem._templateInsta
nce.tabIndex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.translate3
d(0,HIDDEN_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){var p
idx,fidx=this._focusedIndex;if(!this._offscreenFocusedItem||this._focusedIndex<0
){return}this._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null){t
his._focusBackfillItem=this._physicalItems[pidx];this._focusBackfillItem._templa
teInstance.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;this
._offscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfillIte
m)}},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var fo
cusedModel=this._focusedItem?this._focusedItem._templateInstance:null;var hasOff
screenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedIndex;
if(!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!this._
isIndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem();
focusedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs];t
his._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysicalIn
dex(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._update
()}}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_didM
oveDown:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysicalI
tem(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this._f
ocusedIndex);this._selectionHandler(e.detail.keyboardEvent)}}) |
| 2604 })(); |
| 2605 Polymer({ |
| 2606 is: "iron-scroll-threshold", |
| 2607 properties: { |
| 2608 upperThreshold: {type: Number, value: 100}, |
| 2609 lowerThreshold: {type: Number, value: 100}, |
| 2610 upperTriggered: {type: Boolean, value: false, notify: true, readOnly: true}, |
| 2611 lowerTriggered: {type: Boolean, value: false, notify: true, readOnly: true}, |
| 2612 horizontal: {type: Boolean, value: false} |
| 2613 }, |
| 2614 behaviors: [Polymer.IronScrollTargetBehavior], |
| 2615 observers: |
| 2616 ["_setOverflow(scrollTarget)", "_initCheck(horizontal, isAttached)"], |
| 2617 get _defaultScrollTarget() { |
| 2618 return this |
| 2619 }, |
| 2620 _setOverflow: function(scrollTarget) { |
| 2621 this.style.overflow = scrollTarget === this ? "auto" : "" |
| 2622 }, |
| 2623 _scrollHandler: function() { |
| 2624 var THROTTLE_THRESHOLD = 200; |
| 2625 if (!this.isDebouncerActive("_checkTheshold")) { |
| 2626 this.debounce("_checkTheshold", function() { |
| 2627 this.checkScrollThesholds() |
| 2628 }, THROTTLE_THRESHOLD) |
| 2629 } |
| 2630 }, |
| 2631 _initCheck: function(horizontal, isAttached) { |
| 2632 if (isAttached) { |
| 2633 this.debounce("_init", function() { |
| 2634 this.clearTriggers(); |
| 2635 this.checkScrollThesholds() |
| 2636 }) |
| 2637 } |
| 2638 }, |
| 2639 checkScrollThesholds: function() { |
| 2640 if (!this.scrollTarget || this.lowerTriggered && this.upperTriggered) { |
| 2641 return |
| 2642 } |
| 2643 var upperScrollValue = this.horizontal ? this._scrollLeft : this._scrollTop; |
| 2644 var lowerScrollValue = this.horizontal ? |
| 2645 this.scrollTarget.scrollWidth - this._scrollTargetWidth - |
| 2646 this._scrollLeft : |
| 2647 this.scrollTarget.scrollHeight - this._scrollTargetHeight - |
| 2648 this._scrollTop; |
| 2649 if (upperScrollValue <= this.upperThreshold && !this.upperTriggered) { |
| 2650 this._setUpperTriggered(true); |
| 2651 this.fire("upper-threshold") |
| 2652 } |
| 2653 if (lowerScrollValue <= this.lowerThreshold && !this.lowerTriggered) { |
| 2654 this._setLowerTriggered(true); |
| 2655 this.fire("lower-threshold") |
| 2656 } |
| 2657 }, |
| 2658 clearTriggers: function() { |
| 2659 this._setUpperTriggered(false); |
| 2660 this._setLowerTriggered(false) |
| 2661 } |
| 2662 }); |
| 41 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2663 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 42 // Use of this source code is governed by a BSD-style license that can be | 2664 // Use of this source code is governed by a BSD-style license that can be |
| 43 // found in the LICENSE file. | 2665 // found in the LICENSE file. |
| 44 var EventTrackerEntry;function EventTracker(){this.listeners_=[]}EventTracker.pr
ototype={add:function(target,eventType,listener,opt_capture){var capture=!!opt_c
apture;var h={target:target,eventType:eventType,listener:listener,capture:captur
e};this.listeners_.push(h);target.addEventListener(eventType,listener,capture)},
remove:function(target,eventType){this.listeners_=this.listeners_.filter(functio
n(h){if(h.target==target&&(!eventType||h.eventType==eventType)){EventTracker.rem
oveEventListener_(h);return false}return true})},removeAll:function(){this.liste
ners_.forEach(EventTracker.removeEventListener_);this.listeners_=[]}};EventTrack
er.removeEventListener_=function(h){h.target.removeEventListener(h.eventType,h.l
istener,h.capture)}; | 2666 var EventTrackerEntry; |
| 2667 function EventTracker() { |
| 2668 this.listeners_ = [] |
| 2669 } |
| 2670 EventTracker.prototype = { |
| 2671 add: function(target, eventType, listener, opt_capture) { |
| 2672 var capture = !!opt_capture; |
| 2673 var h = { |
| 2674 target: target, |
| 2675 eventType: eventType, |
| 2676 listener: listener, |
| 2677 capture: capture |
| 2678 }; |
| 2679 this.listeners_.push(h); |
| 2680 target.addEventListener(eventType, listener, capture) |
| 2681 }, |
| 2682 remove: function(target, eventType) { |
| 2683 this.listeners_ = this.listeners_.filter(function(h) { |
| 2684 if (h.target == target && (!eventType || h.eventType == eventType)) { |
| 2685 EventTracker.removeEventListener_(h); |
| 2686 return false |
| 2687 } |
| 2688 return true |
| 2689 }) |
| 2690 }, |
| 2691 removeAll: function() { |
| 2692 this.listeners_.forEach(EventTracker.removeEventListener_); |
| 2693 this.listeners_ = [] |
| 2694 } |
| 2695 }; |
| 2696 EventTracker.removeEventListener_ = function(h) { |
| 2697 h.target.removeEventListener(h.eventType, h.listener, h.capture) |
| 2698 }; |
| 45 // Copyright 2014 The Chromium Authors. All rights reserved. | 2699 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 46 // Use of this source code is governed by a BSD-style license that can be | 2700 // Use of this source code is governed by a BSD-style license that can be |
| 47 // found in the LICENSE file. | 2701 // found in the LICENSE file. |
| 48 cr.define("cr.ui",function(){function FocusRow(root,boundary,opt_delegate){this.
root=root;this.boundary_=boundary||document.documentElement;this.delegate=opt_de
legate;this.eventTracker=new EventTracker}FocusRow.Delegate=function(){};FocusRo
w.Delegate.prototype={onKeydown:assertNotReached,onFocus:assertNotReached};Focus
Row.ACTIVE_CLASS="focus-row-active";FocusRow.isFocusable=function(element){if(!e
lement||element.disabled)return false;function isVisible(element){assertInstance
of(element,Element);var style=window.getComputedStyle(element);if(style.visibili
ty=="hidden"||style.display=="none")return false;var parent=element.parentNode;i
f(!parent)return false;if(parent==element.ownerDocument||parent instanceof Docum
entFragment)return true;return isVisible(parent)}return isVisible(element)};Focu
sRow.prototype={addItem:function(type,query){assert(type);var element=this.root.
querySelector(query);if(!element)return false;element.setAttribute("focus-type",
type);element.tabIndex=this.isActive()?0:-1;this.eventTracker.add(element,"blur"
,this.onBlur_.bind(this));this.eventTracker.add(element,"focus",this.onFocus_.bi
nd(this));this.eventTracker.add(element,"keydown",this.onKeydown_.bind(this));th
is.eventTracker.add(element,"mousedown",this.onMousedown_.bind(this));return tru
e},destroy:function(){this.eventTracker.removeAll()},getCustomEquivalent:functio
n(sampleElement){return assert(this.getFirstFocusable())},getElements:function()
{var elements=this.root.querySelectorAll("[focus-type]");return Array.prototype.
slice.call(elements)},getEquivalentElement:function(sampleElement){if(this.getFo
cusableElements().indexOf(sampleElement)>=0)return sampleElement;var sampleFocus
Type=this.getTypeForElement(sampleElement);if(sampleFocusType){var sameType=this
.getFirstFocusable(sampleFocusType);if(sameType)return sameType}return this.getC
ustomEquivalent(sampleElement)},getFirstFocusable:function(opt_type){var filter=
opt_type?'="'+opt_type+'"':"";var elements=this.root.querySelectorAll("[focus-ty
pe"+filter+"]");for(var i=0;i<elements.length;++i){if(cr.ui.FocusRow.isFocusable
(elements[i]))return elements[i]}return null},getFocusableElements:function(){re
turn this.getElements().filter(cr.ui.FocusRow.isFocusable)},getTypeForElement:fu
nction(element){return element.getAttribute("focus-type")||""},isActive:function
(){return this.root.classList.contains(FocusRow.ACTIVE_CLASS)},makeActive:functi
on(active){if(active==this.isActive())return;this.getElements().forEach(function
(element){element.tabIndex=active?0:-1});this.root.classList.toggle(FocusRow.ACT
IVE_CLASS,active)},onBlur_:function(e){if(!this.boundary_.contains(e.relatedTarg
et))return;var currentTarget=e.currentTarget;if(this.getFocusableElements().inde
xOf(currentTarget)>=0)this.makeActive(false)},onFocus_:function(e){if(this.deleg
ate)this.delegate.onFocus(this,e)},onMousedown_:function(e){if(e.button)return;i
f(!e.currentTarget.disabled)e.currentTarget.tabIndex=0},onKeydown_:function(e){v
ar elements=this.getFocusableElements();var currentElement=e.currentTarget;var e
lementIndex=elements.indexOf(currentElement);assert(elementIndex>=0);if(this.del
egate&&this.delegate.onKeydown(this,e))return;if(hasKeyModifiers(e))return;var i
ndex=-1;if(e.key=="ArrowLeft")index=elementIndex+(isRTL()?1:-1);else if(e.key=="
ArrowRight")index=elementIndex+(isRTL()?-1:1);else if(e.key=="Home")index=0;else
if(e.key=="End")index=elements.length-1;var elementToFocus=elements[index];if(e
lementToFocus){this.getEquivalentElement(elementToFocus).focus();e.preventDefaul
t()}}};return{FocusRow:FocusRow}}); | 2702 cr.define("cr.ui", function() { |
| 2703 function FocusRow(root, boundary, opt_delegate) { |
| 2704 this.root = root; |
| 2705 this.boundary_ = boundary || document.documentElement; |
| 2706 this.delegate = opt_delegate; |
| 2707 this.eventTracker = new EventTracker |
| 2708 } |
| 2709 FocusRow.Delegate = function() {}; |
| 2710 FocusRow.Delegate.prototype = { |
| 2711 onKeydown: assertNotReached, |
| 2712 onFocus: assertNotReached |
| 2713 }; |
| 2714 FocusRow.ACTIVE_CLASS = "focus-row-active"; |
| 2715 FocusRow.isFocusable = function(element) { |
| 2716 if (!element || element.disabled) |
| 2717 return false; |
| 2718 function isVisible(element) { |
| 2719 assertInstanceof(element, Element); |
| 2720 var style = window.getComputedStyle(element); |
| 2721 if (style.visibility == "hidden" || style.display == "none") |
| 2722 return false; |
| 2723 var parent = element.parentNode; |
| 2724 if (!parent) |
| 2725 return false; |
| 2726 if (parent == element.ownerDocument || parent instanceof DocumentFragment) |
| 2727 return true; |
| 2728 return isVisible(parent) |
| 2729 } |
| 2730 return isVisible(element) |
| 2731 }; |
| 2732 FocusRow.prototype = { |
| 2733 addItem: function(type, query) { |
| 2734 assert(type); |
| 2735 var element = this.root.querySelector(query); |
| 2736 if (!element) |
| 2737 return false; |
| 2738 element.setAttribute("focus-type", type); |
| 2739 element.tabIndex = this.isActive() ? 0 : -1; |
| 2740 this.eventTracker.add(element, "blur", this.onBlur_.bind(this)); |
| 2741 this.eventTracker.add(element, "focus", this.onFocus_.bind(this)); |
| 2742 this.eventTracker.add(element, "keydown", this.onKeydown_.bind(this)); |
| 2743 this.eventTracker.add(element, "mousedown", this.onMousedown_.bind(this)); |
| 2744 return true |
| 2745 }, |
| 2746 destroy: function() { |
| 2747 this.eventTracker.removeAll() |
| 2748 }, |
| 2749 getCustomEquivalent: function(sampleElement) { |
| 2750 return assert(this.getFirstFocusable()) |
| 2751 }, |
| 2752 getElements: function() { |
| 2753 var elements = this.root.querySelectorAll("[focus-type]"); |
| 2754 return Array.prototype.slice.call(elements) |
| 2755 }, |
| 2756 getEquivalentElement: function(sampleElement) { |
| 2757 if (this.getFocusableElements().indexOf(sampleElement) >= 0) |
| 2758 return sampleElement; |
| 2759 var sampleFocusType = this.getTypeForElement(sampleElement); |
| 2760 if (sampleFocusType) { |
| 2761 var sameType = this.getFirstFocusable(sampleFocusType); |
| 2762 if (sameType) |
| 2763 return sameType |
| 2764 } |
| 2765 return this.getCustomEquivalent(sampleElement) |
| 2766 }, |
| 2767 getFirstFocusable: function(opt_type) { |
| 2768 var filter = opt_type ? '="' + opt_type + '"' : ""; |
| 2769 var elements = this.root.querySelectorAll("[focus-type" + filter + "]"); |
| 2770 for (var i = 0; i < elements.length; ++i) { |
| 2771 if (cr.ui.FocusRow.isFocusable(elements[i])) |
| 2772 return elements[i] |
| 2773 } |
| 2774 return null |
| 2775 }, |
| 2776 getFocusableElements: function() { |
| 2777 return this.getElements().filter(cr.ui.FocusRow.isFocusable) |
| 2778 }, |
| 2779 getTypeForElement: function(element) { |
| 2780 return element.getAttribute("focus-type") || "" |
| 2781 }, |
| 2782 isActive: function() { |
| 2783 return this.root.classList.contains(FocusRow.ACTIVE_CLASS) |
| 2784 }, |
| 2785 makeActive: function(active) { |
| 2786 if (active == this.isActive()) |
| 2787 return; |
| 2788 this.getElements().forEach(function(element) { |
| 2789 element.tabIndex = active ? 0 : -1 |
| 2790 }); |
| 2791 this.root.classList.toggle(FocusRow.ACTIVE_CLASS, active) |
| 2792 }, |
| 2793 onBlur_: function(e) { |
| 2794 if (!this.boundary_.contains(e.relatedTarget)) |
| 2795 return; |
| 2796 var currentTarget = e.currentTarget; |
| 2797 if (this.getFocusableElements().indexOf(currentTarget) >= 0) |
| 2798 this.makeActive(false) |
| 2799 }, |
| 2800 onFocus_: function(e) { |
| 2801 if (this.delegate) |
| 2802 this.delegate.onFocus(this, e) |
| 2803 }, |
| 2804 onMousedown_: function(e) { |
| 2805 if (e.button) |
| 2806 return; |
| 2807 if (!e.currentTarget.disabled) |
| 2808 e.currentTarget.tabIndex = 0 |
| 2809 }, |
| 2810 onKeydown_: function(e) { |
| 2811 var elements = this.getFocusableElements(); |
| 2812 var currentElement = e.currentTarget; |
| 2813 var elementIndex = elements.indexOf(currentElement); |
| 2814 assert(elementIndex >= 0); |
| 2815 if (this.delegate && this.delegate.onKeydown(this, e)) |
| 2816 return; |
| 2817 if (hasKeyModifiers(e)) |
| 2818 return; |
| 2819 var index = -1; |
| 2820 if (e.key == "ArrowLeft") |
| 2821 index = elementIndex + (isRTL() ? 1 : -1); |
| 2822 else if (e.key == "ArrowRight") |
| 2823 index = elementIndex + (isRTL() ? -1 : 1); |
| 2824 else if (e.key == "Home") |
| 2825 index = 0; |
| 2826 else if (e.key == "End") |
| 2827 index = elements.length - 1; |
| 2828 var elementToFocus = elements[index]; |
| 2829 if (elementToFocus) { |
| 2830 this.getEquivalentElement(elementToFocus).focus(); |
| 2831 e.preventDefault() |
| 2832 } |
| 2833 } |
| 2834 }; |
| 2835 return { |
| 2836 FocusRow: FocusRow |
| 2837 } |
| 2838 }); |
| 49 // Copyright 2016 The Chromium Authors. All rights reserved. | 2839 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 50 // Use of this source code is governed by a BSD-style license that can be | 2840 // Use of this source code is governed by a BSD-style license that can be |
| 51 // found in the LICENSE file. | 2841 // found in the LICENSE file. |
| 52 cr.define("cr.icon",function(){function getSupportedScaleFactors(){var supported
ScaleFactors=[];if(!cr.isIOS){supportedScaleFactors.push(1)}if(cr.isMac||cr.isCh
romeOS||cr.isWindows||cr.isLinux){supportedScaleFactors.push(2)}else{supportedSc
aleFactors.push(window.devicePixelRatio)}return supportedScaleFactors}function g
etImageSet(path){var supportedScaleFactors=getSupportedScaleFactors();var replac
eStartIndex=path.indexOf("scalefactor");if(replaceStartIndex<0)return url(path);
var s="";for(var i=0;i<supportedScaleFactors.length;++i){var scaleFactor=support
edScaleFactors[i];var pathWithScaleFactor=path.substr(0,replaceStartIndex)+scale
Factor+path.substr(replaceStartIndex+"scalefactor".length);s+=url(pathWithScaleF
actor)+" "+scaleFactor+"x";if(i!=supportedScaleFactors.length-1)s+=", "}return"-
webkit-image-set("+s+")"}function getImage(path){var chromeThemePath="chrome://t
heme";var isChromeThemeUrl=path.slice(0,chromeThemePath.length)==chromeThemePath
;return isChromeThemeUrl?getImageSet(path+"@scalefactorx"):url(path)}var FAVICON
_URL_REGEX=/\.ico$/i;function getFavicon(url,opt_size,opt_type){var size=opt_siz
e||16;var type=opt_type||"favicon";return getImageSet("chrome://"+type+"/size/"+
size+"@scalefactorx/"+(FAVICON_URL_REGEX.test(url)?"iconurl/":"")+url)}return{ge
tImage:getImage,getFavicon:getFavicon}}); | 2842 cr.define("cr.icon", function() { |
| 2843 function getSupportedScaleFactors() { |
| 2844 var supportedScaleFactors = []; |
| 2845 if (!cr.isIOS) { |
| 2846 supportedScaleFactors.push(1) |
| 2847 } |
| 2848 if (cr.isMac || cr.isChromeOS || cr.isWindows || cr.isLinux) { |
| 2849 supportedScaleFactors.push(2) |
| 2850 } else { |
| 2851 supportedScaleFactors.push(window.devicePixelRatio) |
| 2852 } |
| 2853 return supportedScaleFactors |
| 2854 } |
| 2855 function getImageSet(path) { |
| 2856 var supportedScaleFactors = getSupportedScaleFactors(); |
| 2857 var replaceStartIndex = path.indexOf("scalefactor"); |
| 2858 if (replaceStartIndex < 0) |
| 2859 return url(path); |
| 2860 var s = ""; |
| 2861 for (var i = 0; i < supportedScaleFactors.length; ++i) { |
| 2862 var scaleFactor = supportedScaleFactors[i]; |
| 2863 var pathWithScaleFactor = path.substr(0, replaceStartIndex) + |
| 2864 scaleFactor + path.substr(replaceStartIndex + "scalefactor".length); |
| 2865 s += url(pathWithScaleFactor) + " " + scaleFactor + "x"; |
| 2866 if (i != supportedScaleFactors.length - 1) |
| 2867 s += ", " |
| 2868 } |
| 2869 return "-webkit-image-set(" + s + ")" |
| 2870 } |
| 2871 function getImage(path) { |
| 2872 var chromeThemePath = "chrome://theme"; |
| 2873 var isChromeThemeUrl = |
| 2874 path.slice(0, chromeThemePath.length) == chromeThemePath; |
| 2875 return isChromeThemeUrl ? getImageSet(path + "@scalefactorx") : url(path) |
| 2876 } |
| 2877 var FAVICON_URL_REGEX = /\.ico$/i; |
| 2878 function getFavicon(url, opt_size, opt_type) { |
| 2879 var size = opt_size || 16; |
| 2880 var type = opt_type || "favicon"; |
| 2881 return getImageSet( |
| 2882 "chrome://" + type + "/size/" + size + "@scalefactorx/" + |
| 2883 (FAVICON_URL_REGEX.test(url) ? "iconurl/" : "") + url) |
| 2884 } |
| 2885 return { |
| 2886 getImage: getImage, getFavicon: getFavicon |
| 2887 } |
| 2888 }); |
| 53 // Copyright 2016 The Chromium Authors. All rights reserved. | 2889 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 54 // Use of this source code is governed by a BSD-style license that can be | 2890 // Use of this source code is governed by a BSD-style license that can be |
| 55 // found in the LICENSE file. | 2891 // found in the LICENSE file. |
| 56 Polymer({is:"history-searched-label",properties:{title:String,searchTerm:String}
,observers:["setSearchedTextToBold_(title, searchTerm)"],setSearchedTextToBold_:
function(){var i=0;var titleText=this.title;if(this.searchTerm==""||this.searchT
erm==null){this.textContent=titleText;return}var re=new RegExp(quoteString(this.
searchTerm),"gim");var match;this.textContent="";while(match=re.exec(titleText))
{if(match.index>i)this.appendChild(document.createTextNode(titleText.slice(i,mat
ch.index)));i=re.lastIndex;var b=document.createElement("b");b.textContent=title
Text.substring(match.index,i);this.appendChild(b)}if(i<titleText.length)this.app
endChild(document.createTextNode(titleText.slice(i)))}}); | 2892 Polymer({ |
| 2893 is: "history-searched-label", |
| 2894 properties: {title: String, searchTerm: String}, |
| 2895 observers: ["setSearchedTextToBold_(title, searchTerm)"], |
| 2896 setSearchedTextToBold_: function() { |
| 2897 var i = 0; |
| 2898 var titleText = this.title; |
| 2899 if (this.searchTerm == "" || this.searchTerm == null) { |
| 2900 this.textContent = titleText; |
| 2901 return |
| 2902 } |
| 2903 var re = new RegExp(quoteString(this.searchTerm), "gim"); |
| 2904 var match; |
| 2905 this.textContent = ""; |
| 2906 while (match = re.exec(titleText)) { |
| 2907 if (match.index > i) |
| 2908 this.appendChild( |
| 2909 document.createTextNode(titleText.slice(i, match.index))); |
| 2910 i = re.lastIndex; |
| 2911 var b = document.createElement("b"); |
| 2912 b.textContent = titleText.substring(match.index, i); |
| 2913 this.appendChild(b) |
| 2914 } |
| 2915 if (i < titleText.length) |
| 2916 this.appendChild(document.createTextNode(titleText.slice(i))) |
| 2917 } |
| 2918 }); |
| 57 // Copyright 2015 The Chromium Authors. All rights reserved. | 2919 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 58 // Use of this source code is governed by a BSD-style license that can be | 2920 // Use of this source code is governed by a BSD-style license that can be |
| 59 // found in the LICENSE file. | 2921 // found in the LICENSE file. |
| 60 function HistoryFocusRow(root,boundary,delegate){cr.ui.FocusRow.call(this,root,b
oundary,delegate);this.addItems()}HistoryFocusRow.prototype={__proto__:cr.ui.Foc
usRow.prototype,getCustomEquivalent:function(sampleElement){var equivalent;if(th
is.getTypeForElement(sampleElement)=="star")equivalent=this.getFirstFocusable("t
itle");return equivalent||cr.ui.FocusRow.prototype.getCustomEquivalent.call(this
,sampleElement)},addItems:function(){this.destroy();assert(this.addItem("checkbo
x","#checkbox"));assert(this.addItem("title","#title"));assert(this.addItem("men
u-button","#menu-button"));this.addItem("star","#bookmark-star")}};cr.define("md
_history",function(){function FocusRowDelegate(historyItemElement){this.historyI
temElement=historyItemElement}FocusRowDelegate.prototype={onFocus:function(row,e
){this.historyItemElement.lastFocused=e.path[0]},onKeydown:function(row,e){if(e.
key=="Enter")e.stopPropagation();return false}};var HistoryItem=Polymer({is:"his
tory-item",properties:{item:{type:Object,observer:"showIcon_"},selected:{type:Bo
olean,reflectToAttribute:true},isCardStart:{type:Boolean,reflectToAttribute:true
},isCardEnd:{type:Boolean,reflectToAttribute:true},embedded:{type:Boolean,reflec
tToAttribute:true},lastFocused:{type:Object,notify:true},ironListTabIndex:{type:
Number,observer:"ironListTabIndexChanged_"},hasTimeGap:Boolean,index:Number,numb
erOfItems:Number,path:String,searchTerm:String},row_:null,attached:function(){Po
lymer.RenderStatus.afterNextRender(this,function(){this.row_=new HistoryFocusRow
(this.$["main-container"],null,new FocusRowDelegate(this));this.row_.makeActive(
this.ironListTabIndex==0);this.listen(this,"focus","onFocus_");this.listen(this,
"dom-change","onDomChange_")})},detached:function(){this.unlisten(this,"focus","
onFocus_");this.unlisten(this,"dom-change","onDomChange_");if(this.row_)this.row
_.destroy()},onFocus_:function(){if(this.lastFocused)this.row_.getEquivalentElem
ent(this.lastFocused).focus();else this.row_.getFirstFocusable().focus();this.ta
bIndex=-1},ironListTabIndexChanged_:function(){if(this.row_)this.row_.makeActive
(this.ironListTabIndex==0)},onDomChange_:function(){if(this.row_)this.row_.addIt
ems()},onItemClick_:function(e){for(var i=0;i<e.path.length;i++){var elem=e.path
[i];if(elem.id!="checkbox"&&(elem.nodeName=="A"||elem.nodeName=="BUTTON")){retur
n}}if(this.selectionNotAllowed_())return;this.$.checkbox.focus();this.fire("hist
ory-checkbox-select",{element:this,shiftKey:e.shiftKey})},onItemMousedown_:funct
ion(e){if(e.shiftKey)e.preventDefault()},getEntrySummary_:function(){var item=th
is.item;return loadTimeData.getStringF("entrySummary",item.dateTimeOfDay,item.st
arred?loadTimeData.getString("bookmarked"):"",item.title,item.domain)},getAriaCh
ecked_:function(selected){return selected?"true":"false"},onRemoveBookmarkTap_:f
unction(){if(!this.item.starred)return;if(this.$$("#bookmark-star")==this.root.a
ctiveElement)this.$["menu-button"].focus();var browserService=md_history.Browser
Service.getInstance();browserService.removeBookmark(this.item.url);browserServic
e.recordAction("BookmarkStarClicked");this.fire("remove-bookmark-stars",this.ite
m.url)},onMenuButtonTap_:function(e){this.fire("open-menu",{target:Polymer.dom(e
).localTarget,index:this.index,item:this.item,path:this.path});e.stopPropagation
()},onLinkClick_:function(){var browserService=md_history.BrowserService.getInst
ance();browserService.recordAction("EntryLinkClick");if(this.searchTerm)browserS
ervice.recordAction("SearchResultClick");if(this.index==undefined)return;browser
Service.recordHistogram("HistoryPage.ClickPosition",Math.min(this.index,UMA_MAX_
BUCKET_VALUE),UMA_MAX_BUCKET_VALUE);if(this.index<=UMA_MAX_SUBSET_BUCKET_VALUE){
browserService.recordHistogram("HistoryPage.ClickPositionSubset",this.index,UMA_
MAX_SUBSET_BUCKET_VALUE)}},onLinkRightClick_:function(){md_history.BrowserServic
e.getInstance().recordAction("EntryLinkRightClick")},showIcon_:function(){this.$
.icon.style.backgroundImage=cr.icon.getFavicon(this.item.url)},selectionNotAllow
ed_:function(){return!loadTimeData.getBoolean("allowDeletingHistory")},cardTitle
_:function(numberOfItems,historyDate,search){if(!search)return this.item.dateRel
ativeDay;return HistoryItem.searchResultsTitle(numberOfItems,search)},addTimeTit
le_:function(){var el=this.$["time-accessed"];el.setAttribute("title",new Date(t
his.item.time).toString());this.unlisten(el,"mouseover","addTimeTitle_")}});Hist
oryItem.needsTimeGap=function(visits,currentIndex,searchedTerm){if(currentIndex>
=visits.length-1||visits.length==0)return false;var currentItem=visits[currentIn
dex];var nextItem=visits[currentIndex+1];if(searchedTerm)return currentItem.date
Short!=nextItem.dateShort;return currentItem.time-nextItem.time>BROWSING_GAP_TIM
E&¤tItem.dateRelativeDay==nextItem.dateRelativeDay};HistoryItem.searchResu
ltsTitle=function(numberOfResults,searchTerm){var resultId=numberOfResults==1?"s
earchResult":"searchResults";return loadTimeData.getStringF("foundSearchResults"
,numberOfResults,loadTimeData.getString(resultId),searchTerm)};return{HistoryIte
m:HistoryItem}}); | 2922 function HistoryFocusRow(root, boundary, delegate) { |
| 2923 cr.ui.FocusRow.call(this, root, boundary, delegate); |
| 2924 this.addItems() |
| 2925 } |
| 2926 HistoryFocusRow.prototype = { |
| 2927 __proto__: cr.ui.FocusRow.prototype, |
| 2928 getCustomEquivalent: function(sampleElement) { |
| 2929 var equivalent; |
| 2930 if (this.getTypeForElement(sampleElement) == "star") |
| 2931 equivalent = this.getFirstFocusable("title"); |
| 2932 return equivalent || |
| 2933 cr.ui.FocusRow.prototype.getCustomEquivalent.call(this, sampleElement) |
| 2934 }, |
| 2935 addItems: function() { |
| 2936 this.destroy(); |
| 2937 assert(this.addItem("checkbox", "#checkbox")); |
| 2938 assert(this.addItem("title", "#title")); |
| 2939 assert(this.addItem("menu-button", "#menu-button")); |
| 2940 this.addItem("star", "#bookmark-star") |
| 2941 } |
| 2942 }; |
| 2943 cr.define("md_history", function() { |
| 2944 function FocusRowDelegate(historyItemElement) { |
| 2945 this.historyItemElement = historyItemElement |
| 2946 } |
| 2947 FocusRowDelegate.prototype = { |
| 2948 onFocus: function(row, e) { |
| 2949 this.historyItemElement.lastFocused = e.path[0] |
| 2950 }, |
| 2951 onKeydown: function(row, e) { |
| 2952 if (e.key == "Enter") |
| 2953 e.stopPropagation(); |
| 2954 return false |
| 2955 } |
| 2956 }; |
| 2957 var HistoryItem = Polymer({ |
| 2958 is: "history-item", |
| 2959 properties: { |
| 2960 item: {type: Object, observer: "showIcon_"}, |
| 2961 selected: {type: Boolean, reflectToAttribute: true}, |
| 2962 isCardStart: {type: Boolean, reflectToAttribute: true}, |
| 2963 isCardEnd: {type: Boolean, reflectToAttribute: true}, |
| 2964 embedded: {type: Boolean, reflectToAttribute: true}, |
| 2965 lastFocused: {type: Object, notify: true}, |
| 2966 ironListTabIndex: {type: Number, observer: "ironListTabIndexChanged_"}, |
| 2967 hasTimeGap: Boolean, |
| 2968 index: Number, |
| 2969 numberOfItems: Number, |
| 2970 path: String, |
| 2971 searchTerm: String |
| 2972 }, |
| 2973 row_: null, |
| 2974 attached: function() { |
| 2975 Polymer.RenderStatus.afterNextRender(this, function() { |
| 2976 this.row_ = new HistoryFocusRow( |
| 2977 this.$["main-container"], null, new FocusRowDelegate(this)); |
| 2978 this.row_.makeActive(this.ironListTabIndex == 0); |
| 2979 this.listen(this, "focus", "onFocus_"); |
| 2980 this.listen(this, "dom-change", "onDomChange_") |
| 2981 }) |
| 2982 }, |
| 2983 detached: function() { |
| 2984 this.unlisten(this, "focus", "onFocus_"); |
| 2985 this.unlisten(this, "dom-change", "onDomChange_"); |
| 2986 if (this.row_) |
| 2987 this.row_.destroy() |
| 2988 }, |
| 2989 onFocus_: function() { |
| 2990 if (this.lastFocused) |
| 2991 this.row_.getEquivalentElement(this.lastFocused).focus(); |
| 2992 else |
| 2993 this.row_.getFirstFocusable().focus(); |
| 2994 this.tabIndex = -1 |
| 2995 }, |
| 2996 ironListTabIndexChanged_: function() { |
| 2997 if (this.row_) |
| 2998 this.row_.makeActive(this.ironListTabIndex == 0) |
| 2999 }, |
| 3000 onDomChange_: function() { |
| 3001 if (this.row_) |
| 3002 this.row_.addItems() |
| 3003 }, |
| 3004 onItemClick_: function(e) { |
| 3005 for (var i = 0; i < e.path.length; i++) { |
| 3006 var elem = e.path[i]; |
| 3007 if (elem.id != "checkbox" && |
| 3008 (elem.nodeName == "A" || elem.nodeName == "BUTTON")) { |
| 3009 return |
| 3010 } |
| 3011 } |
| 3012 if (this.selectionNotAllowed_()) |
| 3013 return; |
| 3014 this.$.checkbox.focus(); |
| 3015 this.fire( |
| 3016 "history-checkbox-select", {element: this, shiftKey: e.shiftKey}) |
| 3017 }, |
| 3018 onItemMousedown_: function(e) { |
| 3019 if (e.shiftKey) |
| 3020 e.preventDefault() |
| 3021 }, |
| 3022 getEntrySummary_: function() { |
| 3023 var item = this.item; |
| 3024 return loadTimeData.getStringF( |
| 3025 "entrySummary", item.dateTimeOfDay, |
| 3026 item.starred ? loadTimeData.getString("bookmarked") : "", item.title, |
| 3027 item.domain) |
| 3028 }, |
| 3029 getAriaChecked_: function(selected) { |
| 3030 return selected ? "true" : "false" |
| 3031 }, |
| 3032 onRemoveBookmarkTap_: function() { |
| 3033 if (!this.item.starred) |
| 3034 return; |
| 3035 if (this.$$("#bookmark-star") == this.root.activeElement) |
| 3036 this.$["menu-button"].focus(); |
| 3037 var browserService = md_history.BrowserService.getInstance(); |
| 3038 browserService.removeBookmark(this.item.url); |
| 3039 browserService.recordAction("BookmarkStarClicked"); |
| 3040 this.fire("remove-bookmark-stars", this.item.url) |
| 3041 }, |
| 3042 onMenuButtonTap_: function(e) { |
| 3043 this.fire("open-menu", { |
| 3044 target: Polymer.dom(e).localTarget, |
| 3045 index: this.index, |
| 3046 item: this.item, |
| 3047 path: this.path |
| 3048 }); |
| 3049 e.stopPropagation() |
| 3050 }, |
| 3051 onLinkClick_: function() { |
| 3052 var browserService = md_history.BrowserService.getInstance(); |
| 3053 browserService.recordAction("EntryLinkClick"); |
| 3054 if (this.searchTerm) |
| 3055 browserService.recordAction("SearchResultClick"); |
| 3056 if (this.index == undefined) |
| 3057 return; |
| 3058 browserService.recordHistogram( |
| 3059 "HistoryPage.ClickPosition", |
| 3060 Math.min(this.index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); |
| 3061 if (this.index <= UMA_MAX_SUBSET_BUCKET_VALUE) { |
| 3062 browserService.recordHistogram( |
| 3063 "HistoryPage.ClickPositionSubset", this.index, |
| 3064 UMA_MAX_SUBSET_BUCKET_VALUE) |
| 3065 } |
| 3066 }, |
| 3067 onLinkRightClick_: function() { |
| 3068 md_history.BrowserService.getInstance().recordAction( |
| 3069 "EntryLinkRightClick") |
| 3070 }, |
| 3071 showIcon_: function() { |
| 3072 this.$.icon.style.backgroundImage = cr.icon.getFavicon(this.item.url) |
| 3073 }, |
| 3074 selectionNotAllowed_: function() { |
| 3075 return !loadTimeData.getBoolean("allowDeletingHistory") |
| 3076 }, |
| 3077 cardTitle_: function(numberOfItems, historyDate, search) { |
| 3078 if (!search) |
| 3079 return this.item.dateRelativeDay; |
| 3080 return HistoryItem.searchResultsTitle(numberOfItems, search) |
| 3081 }, |
| 3082 addTimeTitle_: function() { |
| 3083 var el = this.$["time-accessed"]; |
| 3084 el.setAttribute("title", new Date(this.item.time).toString()); |
| 3085 this.unlisten(el, "mouseover", "addTimeTitle_") |
| 3086 } |
| 3087 }); |
| 3088 HistoryItem.needsTimeGap = function(visits, currentIndex, searchedTerm) { |
| 3089 if (currentIndex >= visits.length - 1 || visits.length == 0) |
| 3090 return false; |
| 3091 var currentItem = visits[currentIndex]; |
| 3092 var nextItem = visits[currentIndex + 1]; |
| 3093 if (searchedTerm) |
| 3094 return currentItem.dateShort != nextItem.dateShort; |
| 3095 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && |
| 3096 currentItem.dateRelativeDay == nextItem.dateRelativeDay |
| 3097 }; |
| 3098 HistoryItem.searchResultsTitle = function(numberOfResults, searchTerm) { |
| 3099 var resultId = numberOfResults == 1 ? "searchResult" : "searchResults"; |
| 3100 return loadTimeData.getStringF( |
| 3101 "foundSearchResults", numberOfResults, loadTimeData.getString(resultId), |
| 3102 searchTerm) |
| 3103 }; |
| 3104 return { |
| 3105 HistoryItem: HistoryItem |
| 3106 } |
| 3107 }); |
| 61 // Copyright 2016 The Chromium Authors. All rights reserved. | 3108 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 62 // Use of this source code is governed by a BSD-style license that can be | 3109 // Use of this source code is governed by a BSD-style license that can be |
| 63 // found in the LICENSE file. | 3110 // found in the LICENSE file. |
| 64 var SelectionTreeNode=function(currentPath){this.currentPath=currentPath;this.le
af=false;this.indexes=[];this.children=[]};SelectionTreeNode.prototype.addChild=
function(index,path){this.indexes.push(index);this.children[index]=new Selection
TreeNode(path)};var HistoryListBehavior={properties:{selectedPaths:{type:Object,
value:function(){return new Set}},lastSelectedPath:String},listeners:{"history-c
heckbox-select":"itemSelected_"},addNewResults:function(results,incremental,fini
shed){},hasResults:function(historyDataLength){return historyDataLength>0},noRes
ultsMessage:function(searchedTerm,isLoading){if(isLoading)return"";var messageId
=searchedTerm!==""?"noSearchResults":"noResults";return loadTimeData.getString(m
essageId)},unselectAllItems:function(){this.selectedPaths.forEach(function(path)
{this.set(path+".selected",false)}.bind(this));this.selectedPaths.clear()},delet
eSelected:function(){var toBeRemoved=Array.from(this.selectedPaths.values()).map
(function(path){return this.get(path)}.bind(this));md_history.BrowserService.get
Instance().deleteItems(toBeRemoved).then(function(){this.removeItemsByPath(Array
.from(this.selectedPaths));this.fire("unselect-all")}.bind(this))},removeItemsBy
Path:function(paths){if(paths.length==0)return;this.removeItemsBeneathNode_(this
.buildRemovalTree_(paths))},buildRemovalTree_:function(paths){var rootNode=new S
electionTreeNode(paths[0].split(".")[0]);paths.forEach(function(path){var compon
ents=path.split(".");var node=rootNode;components.shift();while(components.lengt
h>1){var index=Number(components.shift());var arrayName=components.shift();if(!n
ode.children[index])node.addChild(index,[node.currentPath,index,arrayName].join(
"."));node=node.children[index]}node.leaf=true;node.indexes.push(Number(componen
ts.shift()))});return rootNode},removeItemsBeneathNode_:function(node){var array
=this.get(node.currentPath);var splices=[];node.indexes.sort(function(a,b){retur
n b-a});node.indexes.forEach(function(index){if(node.leaf||this.removeItemsBenea
thNode_(node.children[index])){var item=array.splice(index,1)[0];splices.push({i
ndex:index,removed:[item],addedCount:0,object:array,type:"splice"})}}.bind(this)
);if(array.length==0&&node.currentPath.indexOf(".")!=-1)return true;this.notifyS
plices(node.currentPath,splices);return false},itemSelected_:function(e){var ite
m=e.detail.element;var paths=[];var itemPath=item.path;if(e.detail.shiftKey&&thi
s.lastSelectedPath){var itemPathComponents=itemPath.split(".");var itemIndex=Num
ber(itemPathComponents.pop());var itemArrayPath=itemPathComponents.join(".");var
lastItemPathComponents=this.lastSelectedPath.split(".");var lastItemIndex=Numbe
r(lastItemPathComponents.pop());if(itemArrayPath==lastItemPathComponents.join(".
")){for(var i=Math.min(itemIndex,lastItemIndex);i<=Math.max(itemIndex,lastItemIn
dex);i++){paths.push(itemArrayPath+"."+i)}}}if(paths.length==0)paths.push(item.p
ath);var selected=!this.selectedPaths.has(item.path);paths.forEach(function(path
){this.set(path+".selected",selected);if(selected){this.selectedPaths.add(path);
return}this.selectedPaths.delete(path)}.bind(this));this.lastSelectedPath=itemPa
th}}; | 3111 var SelectionTreeNode = function(currentPath) { |
| 3112 this.currentPath = currentPath; |
| 3113 this.leaf = false; |
| 3114 this.indexes = []; |
| 3115 this.children = [] |
| 3116 }; |
| 3117 SelectionTreeNode.prototype.addChild = function(index, path) { |
| 3118 this.indexes.push(index); |
| 3119 this.children[index] = new SelectionTreeNode(path) |
| 3120 }; |
| 3121 var HistoryListBehavior = { |
| 3122 properties: { |
| 3123 selectedPaths: { |
| 3124 type: Object, |
| 3125 value: function() { |
| 3126 return new Set |
| 3127 } |
| 3128 }, |
| 3129 lastSelectedPath: String |
| 3130 }, |
| 3131 listeners: {"history-checkbox-select": "itemSelected_"}, |
| 3132 addNewResults: function(results, incremental, finished) {}, |
| 3133 hasResults: function(historyDataLength) { |
| 3134 return historyDataLength > 0 |
| 3135 }, |
| 3136 noResultsMessage: function(searchedTerm, isLoading) { |
| 3137 if (isLoading) |
| 3138 return ""; |
| 3139 var messageId = searchedTerm !== "" ? "noSearchResults" : "noResults"; |
| 3140 return loadTimeData.getString(messageId) |
| 3141 }, |
| 3142 unselectAllItems: function() { |
| 3143 this.selectedPaths.forEach(function(path) { |
| 3144 this.set(path + ".selected", false) |
| 3145 }.bind(this)); |
| 3146 this.selectedPaths.clear() |
| 3147 }, |
| 3148 deleteSelected: function() { |
| 3149 var toBeRemoved = |
| 3150 Array.from(this.selectedPaths.values()).map(function(path) { |
| 3151 return this.get(path) |
| 3152 }.bind(this)); |
| 3153 md_history.BrowserService.getInstance() |
| 3154 .deleteItems(toBeRemoved) |
| 3155 .then(function() { |
| 3156 this.removeItemsByPath(Array.from(this.selectedPaths)); |
| 3157 this.fire("unselect-all") |
| 3158 }.bind(this)) |
| 3159 }, |
| 3160 removeItemsByPath: function(paths) { |
| 3161 if (paths.length == 0) |
| 3162 return; |
| 3163 this.removeItemsBeneathNode_(this.buildRemovalTree_(paths)) |
| 3164 }, |
| 3165 buildRemovalTree_: function(paths) { |
| 3166 var rootNode = new SelectionTreeNode(paths[0].split(".")[0]); |
| 3167 paths.forEach(function(path) { |
| 3168 var components = path.split("."); |
| 3169 var node = rootNode; |
| 3170 components.shift(); |
| 3171 while (components.length > 1) { |
| 3172 var index = Number(components.shift()); |
| 3173 var arrayName = components.shift(); |
| 3174 if (!node.children[index]) |
| 3175 node.addChild(index, [node.currentPath, index, arrayName].join(".")); |
| 3176 node = node.children[index] |
| 3177 } |
| 3178 node.leaf = true; |
| 3179 node.indexes.push(Number(components.shift())) |
| 3180 }); |
| 3181 return rootNode |
| 3182 }, |
| 3183 removeItemsBeneathNode_: function(node) { |
| 3184 var array = this.get(node.currentPath); |
| 3185 var splices = []; |
| 3186 node.indexes.sort(function(a, b) { |
| 3187 return b - a |
| 3188 }); |
| 3189 node.indexes.forEach(function(index) { |
| 3190 if (node.leaf || this.removeItemsBeneathNode_(node.children[index])) { |
| 3191 var item = array.splice(index, 1)[0]; |
| 3192 splices.push({ |
| 3193 index: index, |
| 3194 removed: [item], |
| 3195 addedCount: 0, |
| 3196 object: array, |
| 3197 type: "splice" |
| 3198 }) |
| 3199 } |
| 3200 }.bind(this)); |
| 3201 if (array.length == 0 && node.currentPath.indexOf(".") != -1) |
| 3202 return true; |
| 3203 this.notifySplices(node.currentPath, splices); |
| 3204 return false |
| 3205 }, |
| 3206 itemSelected_: function(e) { |
| 3207 var item = e.detail.element; |
| 3208 var paths = []; |
| 3209 var itemPath = item.path; |
| 3210 if (e.detail.shiftKey && this.lastSelectedPath) { |
| 3211 var itemPathComponents = itemPath.split("."); |
| 3212 var itemIndex = Number(itemPathComponents.pop()); |
| 3213 var itemArrayPath = itemPathComponents.join("."); |
| 3214 var lastItemPathComponents = this.lastSelectedPath.split("."); |
| 3215 var lastItemIndex = Number(lastItemPathComponents.pop()); |
| 3216 if (itemArrayPath == lastItemPathComponents.join(".")) { |
| 3217 for (var i = Math.min(itemIndex, lastItemIndex); |
| 3218 i <= Math.max(itemIndex, lastItemIndex); i++) { |
| 3219 paths.push(itemArrayPath + "." + i) |
| 3220 } |
| 3221 } |
| 3222 } |
| 3223 if (paths.length == 0) |
| 3224 paths.push(item.path); |
| 3225 var selected = !this.selectedPaths.has(item.path); |
| 3226 paths.forEach(function(path) { |
| 3227 this.set(path + ".selected", selected); |
| 3228 if (selected) { |
| 3229 this.selectedPaths.add(path); |
| 3230 return |
| 3231 } |
| 3232 this.selectedPaths.delete(path) |
| 3233 }.bind(this)); |
| 3234 this.lastSelectedPath = itemPath |
| 3235 } |
| 3236 }; |
| 65 // Copyright 2015 The Chromium Authors. All rights reserved. | 3237 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 66 // Use of this source code is governed by a BSD-style license that can be | 3238 // Use of this source code is governed by a BSD-style license that can be |
| 67 // found in the LICENSE file. | 3239 // found in the LICENSE file. |
| 68 Polymer({is:"history-list",behaviors:[HistoryListBehavior],properties:{searchedT
erm:{type:String,value:""},resultLoadingDisabled_:{type:Boolean,value:false},his
toryData_:Array,lastFocused_:Object,querying:Boolean},listeners:{"remove-bookmar
k-stars":"removeBookmarkStars_"},attached:function(){this.$["infinite-list"].not
ifyResize();this.$["infinite-list"].scrollTarget=this;this.$["scroll-threshold"]
.scrollTarget=this},removeBookmarkStars_:function(e){var url=e.detail;if(this.hi
storyData_===undefined)return;for(var i=0;i<this.historyData_.length;i++){if(thi
s.historyData_[i].url==url)this.set("historyData_."+i+".starred",false)}},addNew
Results:function(historyResults,incremental,finished){var results=historyResults
.slice();this.$["scroll-threshold"].clearTriggers();if(!incremental){this.result
LoadingDisabled_=false;if(this.historyData_)this.splice("historyData_",0,this.hi
storyData_.length);this.fire("unselect-all")}if(this.historyData_){results.unshi
ft("historyData_");this.push.apply(this,results)}else{this.set("historyData_",re
sults)}this.resultLoadingDisabled_=finished},loadMoreData_:function(){if(this.re
sultLoadingDisabled_||this.querying)return;this.fire("load-more-history")},needs
TimeGap_:function(item,index,length){return md_history.HistoryItem.needsTimeGap(
this.historyData_,index,this.searchedTerm)},isCardStart_:function(item,i,length)
{if(length==0||i>length-1)return false;return i==0||this.historyData_[i].dateRel
ativeDay!=this.historyData_[i-1].dateRelativeDay},isCardEnd_:function(item,i,len
gth){if(length==0||i>length-1)return false;return i==length-1||this.historyData_
[i].dateRelativeDay!=this.historyData_[i+1].dateRelativeDay},pathForItem_:functi
on(index){return"historyData_."+index}}); | 3240 Polymer({ |
| 3241 is: "history-list", |
| 3242 behaviors: [HistoryListBehavior], |
| 3243 properties: { |
| 3244 searchedTerm: {type: String, value: ""}, |
| 3245 resultLoadingDisabled_: {type: Boolean, value: false}, |
| 3246 historyData_: Array, |
| 3247 lastFocused_: Object, |
| 3248 querying: Boolean |
| 3249 }, |
| 3250 listeners: {"remove-bookmark-stars": "removeBookmarkStars_"}, |
| 3251 attached: function() { |
| 3252 this.$["infinite-list"].notifyResize(); |
| 3253 this.$["infinite-list"].scrollTarget = this; |
| 3254 this.$["scroll-threshold"].scrollTarget = this |
| 3255 }, |
| 3256 removeBookmarkStars_: function(e) { |
| 3257 var url = e.detail; |
| 3258 if (this.historyData_ === undefined) |
| 3259 return; |
| 3260 for (var i = 0; i < this.historyData_.length; i++) { |
| 3261 if (this.historyData_[i].url == url) |
| 3262 this.set("historyData_." + i + ".starred", false) |
| 3263 } |
| 3264 }, |
| 3265 addNewResults: function(historyResults, incremental, finished) { |
| 3266 var results = historyResults.slice(); |
| 3267 this.$["scroll-threshold"].clearTriggers(); |
| 3268 if (!incremental) { |
| 3269 this.resultLoadingDisabled_ = false; |
| 3270 if (this.historyData_) |
| 3271 this.splice("historyData_", 0, this.historyData_.length); |
| 3272 this.fire("unselect-all") |
| 3273 } |
| 3274 if (this.historyData_) { |
| 3275 results.unshift("historyData_"); |
| 3276 this.push.apply(this, results) |
| 3277 } else { |
| 3278 this.set("historyData_", results) |
| 3279 } |
| 3280 this.resultLoadingDisabled_ = finished |
| 3281 }, |
| 3282 loadMoreData_: function() { |
| 3283 if (this.resultLoadingDisabled_ || this.querying) |
| 3284 return; |
| 3285 this.fire("load-more-history") |
| 3286 }, |
| 3287 needsTimeGap_: function(item, index, length) { |
| 3288 return md_history.HistoryItem.needsTimeGap( |
| 3289 this.historyData_, index, this.searchedTerm) |
| 3290 }, |
| 3291 isCardStart_: function(item, i, length) { |
| 3292 if (length == 0 || i > length - 1) |
| 3293 return false; |
| 3294 return i == 0 || |
| 3295 this.historyData_[i].dateRelativeDay != |
| 3296 this.historyData_[i - 1].dateRelativeDay |
| 3297 }, |
| 3298 isCardEnd_: function(item, i, length) { |
| 3299 if (length == 0 || i > length - 1) |
| 3300 return false; |
| 3301 return i == length - 1 || |
| 3302 this.historyData_[i].dateRelativeDay != |
| 3303 this.historyData_[i + 1].dateRelativeDay |
| 3304 }, |
| 3305 pathForItem_: function(index) { |
| 3306 return "historyData_." + index |
| 3307 } |
| 3308 }); |
| 69 // Copyright 2016 The Chromium Authors. All rights reserved. | 3309 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 70 // Use of this source code is governed by a BSD-style license that can be | 3310 // Use of this source code is governed by a BSD-style license that can be |
| 71 // found in the LICENSE file. | 3311 // found in the LICENSE file. |
| 72 Polymer({is:"history-list-container",properties:{groupedRange:{type:Number,obser
ver:"groupedRangeChanged_"},selectedPage_:String,grouped:Boolean,queryState:Obje
ct,queryResult:Object,actionMenuModel_:Object},observers:["searchTermChanged_(qu
eryState.searchTerm)","groupedOffsetChanged_(queryState.groupedOffset)"],listene
rs:{"load-more-history":"loadMoreHistory_","open-menu":"openMenu_"},historyResul
t:function(info,results){this.initializeResults_(info,results);this.closeMenu_()
;if(info.term&&!this.queryState.incremental){Polymer.IronA11yAnnouncer.requestAv
ailability();this.fire("iron-announce",{text:md_history.HistoryItem.searchResult
sTitle(results.length,info.term)})}var list=this.getSelectedList_();list.addNewR
esults(results,this.queryState.incremental,info.finished)},queryHistory:function
(incremental){var queryState=this.queryState;var noResults=!this.queryResult||th
is.queryResult.results==null;if(queryState.queryingDisabled||!this.queryState.se
archTerm&&noResults){return}var dialog=this.$.dialog.getIfExists();if(!increment
al&&dialog&&dialog.open)dialog.close();this.set("queryState.querying",true);this
.set("queryState.incremental",incremental);var lastVisitTime=0;if(incremental){v
ar lastVisit=this.queryResult.results.slice(-1)[0];lastVisitTime=lastVisit?Math.
floor(lastVisit.time):0}var maxResults=this.groupedRange==HistoryRange.ALL_TIME?
RESULTS_PER_PAGE:0;chrome.send("queryHistory",[queryState.searchTerm,queryState.
groupedOffset,queryState.range,lastVisitTime,maxResults])},historyDeleted:functi
on(){if(this.getSelectedItemCount()>0)return;this.queryHistory(false)},getConten
tScrollTarget:function(){return this.getSelectedList_()},getSelectedItemCount:fu
nction(){return this.getSelectedList_().selectedPaths.size},unselectAllItems:fun
ction(count){var selectedList=this.getSelectedList_();if(selectedList)selectedLi
st.unselectAllItems(count)},deleteSelectedWithPrompt:function(){if(!loadTimeData
.getBoolean("allowDeletingHistory"))return;var browserService=md_history.Browser
Service.getInstance();browserService.recordAction("RemoveSelected");if(this.quer
yState.searchTerm!="")browserService.recordAction("SearchResultRemove");this.$.d
ialog.get().showModal();this.$$(".action-button").focus()},groupedRangeChanged_:
function(range,oldRange){this.selectedPage_=range==HistoryRange.ALL_TIME?"infini
te-list":"grouped-list";if(oldRange==undefined)return;this.set("queryState.group
edOffset",0);if(this.queryResult.info){this.set("queryResult.results",[]);this.h
istoryResult(this.queryResult.info,[])}this.queryHistory(false);this.fire("histo
ry-view-changed")},searchTermChanged_:function(){this.queryHistory(false);if(thi
s.queryState.searchTerm)md_history.BrowserService.getInstance().recordAction("Se
arch")},groupedOffsetChanged_:function(){this.queryHistory(false)},loadMoreHisto
ry_:function(){this.queryHistory(true)},initializeResults_:function(info,results
){if(results.length==0)return;var currentDate=results[0].dateRelativeDay;for(var
i=0;i<results.length;i++){results[i].selected=false;results[i].readableTimestam
p=info.term==""?results[i].dateTimeOfDay:results[i].dateShort;if(results[i].date
RelativeDay!=currentDate){currentDate=results[i].dateRelativeDay}}},onDialogConf
irmTap_:function(){md_history.BrowserService.getInstance().recordAction("Confirm
RemoveSelected");this.getSelectedList_().deleteSelected();var dialog=assert(this
.$.dialog.getIfExists());dialog.close()},onDialogCancelTap_:function(){md_histor
y.BrowserService.getInstance().recordAction("CancelRemoveSelected");var dialog=a
ssert(this.$.dialog.getIfExists());dialog.close()},closeMenu_:function(){var men
u=this.$.sharedMenu.getIfExists();if(menu&&menu.open){this.actionMenuModel_=null
;menu.close()}},openMenu_:function(e){var target=e.detail.target;this.actionMenu
Model_=e.detail;var menu=this.$.sharedMenu.get();menu.showAt(target)},onMoreFrom
SiteTap_:function(){md_history.BrowserService.getInstance().recordAction("EntryM
enuShowMoreFromSite");var menu=assert(this.$.sharedMenu.getIfExists());this.set(
"queryState.searchTerm",this.actionMenuModel_.item.domain);this.actionMenuModel_
=null;this.closeMenu_()},onRemoveFromHistoryTap_:function(){var browserService=m
d_history.BrowserService.getInstance();browserService.recordAction("EntryMenuRem
oveFromHistory");var menu=assert(this.$.sharedMenu.getIfExists());var itemData=t
his.actionMenuModel_;browserService.deleteItems([itemData.item]).then(function(i
tems){this.fire("unselect-all");this.getSelectedList_().removeItemsByPath([itemD
ata.path]);var index=itemData.index;if(index==undefined)return;var browserServic
e=md_history.BrowserService.getInstance();browserService.recordHistogram("Histor
yPage.RemoveEntryPosition",Math.min(index,UMA_MAX_BUCKET_VALUE),UMA_MAX_BUCKET_V
ALUE);if(index<=UMA_MAX_SUBSET_BUCKET_VALUE){browserService.recordHistogram("His
toryPage.RemoveEntryPositionSubset",index,UMA_MAX_SUBSET_BUCKET_VALUE)}}.bind(th
is));this.closeMenu_()},getSelectedList_:function(){return this.$$("#"+this.sele
ctedPage_)},canDeleteHistory_:function(){return loadTimeData.getBoolean("allowDe
letingHistory")}});(function(){"use strict";Polymer({is:"iron-location",properti
es:{path:{type:String,notify:true,value:function(){return window.decodeURICompon
ent(window.location.pathname)}},query:{type:String,notify:true,value:function(){
return window.decodeURIComponent(window.location.search.slice(1))}},hash:{type:S
tring,notify:true,value:function(){return window.decodeURIComponent(window.locat
ion.hash.slice(1))}},dwellTime:{type:Number,value:2e3},urlSpaceRegex:{type:Strin
g,value:""},_urlSpaceRegExp:{computed:"_makeRegExp(urlSpaceRegex)"},_lastChanged
At:{type:Number},_initialized:{type:Boolean,value:false}},hostAttributes:{hidden
:true},observers:["_updateUrl(path, query, hash)"],attached:function(){this.list
en(window,"hashchange","_hashChanged");this.listen(window,"location-changed","_u
rlChanged");this.listen(window,"popstate","_urlChanged");this.listen(document.bo
dy,"click","_globalOnClick");this._lastChangedAt=window.performance.now()-(this.
dwellTime-200);this._initialized=true;this._urlChanged()},detached:function(){th
is.unlisten(window,"hashchange","_hashChanged");this.unlisten(window,"location-c
hanged","_urlChanged");this.unlisten(window,"popstate","_urlChanged");this.unlis
ten(document.body,"click","_globalOnClick");this._initialized=false},_hashChange
d:function(){this.hash=window.decodeURIComponent(window.location.hash.substring(
1))},_urlChanged:function(){this._dontUpdateUrl=true;this._hashChanged();this.pa
th=window.decodeURIComponent(window.location.pathname);this.query=window.decodeU
RIComponent(window.location.search.substring(1));this._dontUpdateUrl=false;this.
_updateUrl()},_getUrl:function(){var partiallyEncodedPath=window.encodeURI(this.
path).replace(/\#/g,"%23").replace(/\?/g,"%3F");var partiallyEncodedQuery="";if(
this.query){partiallyEncodedQuery="?"+window.encodeURI(this.query).replace(/\#/g
,"%23")}var partiallyEncodedHash="";if(this.hash){partiallyEncodedHash="#"+windo
w.encodeURI(this.hash)}return partiallyEncodedPath+partiallyEncodedQuery+partial
lyEncodedHash},_updateUrl:function(){if(this._dontUpdateUrl||!this._initialized)
{return}if(this.path===window.decodeURIComponent(window.location.pathname)&&this
.query===window.decodeURIComponent(window.location.search.substring(1))&&this.ha
sh===window.decodeURIComponent(window.location.hash.substring(1))){return}var ne
wUrl=this._getUrl();var fullNewUrl=new URL(newUrl,window.location.protocol+"//"+
window.location.host).href;var now=window.performance.now();var shouldReplace=th
is._lastChangedAt+this.dwellTime>now;this._lastChangedAt=now;if(shouldReplace){w
indow.history.replaceState({},"",fullNewUrl)}else{window.history.pushState({},""
,fullNewUrl)}this.fire("location-changed",{},{node:window})},_globalOnClick:func
tion(event){if(event.defaultPrevented){return}var href=this._getSameOriginLinkHr
ef(event);if(!href){return}event.preventDefault();if(href===window.location.href
){return}window.history.pushState({},"",href);this.fire("location-changed",{},{n
ode:window})},_getSameOriginLinkHref:function(event){if(event.button!==0){return
null}if(event.metaKey||event.ctrlKey){return null}var eventPath=Polymer.dom(eve
nt).path;var anchor=null;for(var i=0;i<eventPath.length;i++){var element=eventPa
th[i];if(element.tagName==="A"&&element.href){anchor=element;break}}if(!anchor){
return null}if(anchor.target==="_blank"){return null}if((anchor.target==="_top"|
|anchor.target==="_parent")&&window.top!==window){return null}var href=anchor.hr
ef;var url;if(document.baseURI!=null){url=new URL(href,document.baseURI)}else{ur
l=new URL(href)}var origin;if(window.location.origin){origin=window.location.ori
gin}else{origin=window.location.protocol+"//"+window.location.hostname;if(window
.location.port){origin+=":"+window.location.port}}if(url.origin!==origin){return
null}var normalizedHref=url.pathname+url.search+url.hash;if(this._urlSpaceRegEx
p&&!this._urlSpaceRegExp.test(normalizedHref)){return null}var fullNormalizedHre
f=new URL(normalizedHref,window.location.href).href;return fullNormalizedHref},_
makeRegExp:function(urlSpaceRegex){return RegExp(urlSpaceRegex)}})})();"use stri
ct";Polymer({is:"iron-query-params",properties:{paramsString:{type:String,notify
:true,observer:"paramsStringChanged"},paramsObject:{type:Object,notify:true,valu
e:function(){return{}}},_dontReact:{type:Boolean,value:false}},hostAttributes:{h
idden:true},observers:["paramsObjectChanged(paramsObject.*)"],paramsStringChange
d:function(){this._dontReact=true;this.paramsObject=this._decodeParams(this.para
msString);this._dontReact=false},paramsObjectChanged:function(){if(this._dontRea
ct){return}this.paramsString=this._encodeParams(this.paramsObject)},_encodeParam
s:function(params){var encodedParams=[];for(var key in params){var value=params[
key];if(value===""){encodedParams.push(encodeURIComponent(key))}else if(value){e
ncodedParams.push(encodeURIComponent(key)+"="+encodeURIComponent(value.toString(
)))}}return encodedParams.join("&")},_decodeParams:function(paramString){var par
ams={};paramString=(paramString||"").replace(/\+/g,"%20");var paramList=paramStr
ing.split("&");for(var i=0;i<paramList.length;i++){var param=paramList[i].split(
"=");if(param[0]){params[decodeURIComponent(param[0])]=decodeURIComponent(param[
1]||"")}}return params}}); | 3312 Polymer({ |
| 3313 is: "history-list-container", |
| 3314 properties: { |
| 3315 groupedRange: {type: Number, observer: "groupedRangeChanged_"}, |
| 3316 selectedPage_: String, |
| 3317 grouped: Boolean, |
| 3318 queryState: Object, |
| 3319 queryResult: Object, |
| 3320 actionMenuModel_: Object |
| 3321 }, |
| 3322 observers: [ |
| 3323 "searchTermChanged_(queryState.searchTerm)", |
| 3324 "groupedOffsetChanged_(queryState.groupedOffset)" |
| 3325 ], |
| 3326 listeners: |
| 3327 {"load-more-history": "loadMoreHistory_", "open-menu": "openMenu_"}, |
| 3328 historyResult: function(info, results) { |
| 3329 this.initializeResults_(info, results); |
| 3330 this.closeMenu_(); |
| 3331 if (info.term && !this.queryState.incremental) { |
| 3332 Polymer.IronA11yAnnouncer.requestAvailability(); |
| 3333 this.fire("iron-announce", { |
| 3334 text: |
| 3335 md_history.HistoryItem.searchResultsTitle(results.length, info.term) |
| 3336 }) |
| 3337 } |
| 3338 var list = this.getSelectedList_(); |
| 3339 list.addNewResults(results, this.queryState.incremental, info.finished) |
| 3340 }, |
| 3341 queryHistory: function(incremental) { |
| 3342 var queryState = this.queryState; |
| 3343 var noResults = !this.queryResult || this.queryResult.results == null; |
| 3344 if (queryState.queryingDisabled || |
| 3345 !this.queryState.searchTerm && noResults) { |
| 3346 return |
| 3347 } |
| 3348 var dialog = this.$.dialog.getIfExists(); |
| 3349 if (!incremental && dialog && dialog.open) |
| 3350 dialog.close(); |
| 3351 this.set("queryState.querying", true); |
| 3352 this.set("queryState.incremental", incremental); |
| 3353 var lastVisitTime = 0; |
| 3354 if (incremental) { |
| 3355 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 3356 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0 |
| 3357 } |
| 3358 var maxResults = |
| 3359 this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| 3360 chrome.send("queryHistory", [ |
| 3361 queryState.searchTerm, queryState.groupedOffset, queryState.range, |
| 3362 lastVisitTime, maxResults |
| 3363 ]) |
| 3364 }, |
| 3365 historyDeleted: function() { |
| 3366 if (this.getSelectedItemCount() > 0) |
| 3367 return; |
| 3368 this.queryHistory(false) |
| 3369 }, |
| 3370 getContentScrollTarget: function() { |
| 3371 return this.getSelectedList_() |
| 3372 }, |
| 3373 getSelectedItemCount: function() { |
| 3374 return this.getSelectedList_().selectedPaths.size |
| 3375 }, |
| 3376 unselectAllItems: function(count) { |
| 3377 var selectedList = this.getSelectedList_(); |
| 3378 if (selectedList) |
| 3379 selectedList.unselectAllItems(count) |
| 3380 }, |
| 3381 deleteSelectedWithPrompt: function() { |
| 3382 if (!loadTimeData.getBoolean("allowDeletingHistory")) |
| 3383 return; |
| 3384 var browserService = md_history.BrowserService.getInstance(); |
| 3385 browserService.recordAction("RemoveSelected"); |
| 3386 if (this.queryState.searchTerm != "") |
| 3387 browserService.recordAction("SearchResultRemove"); |
| 3388 this.$.dialog.get().showModal(); |
| 3389 this.$$(".action-button").focus() |
| 3390 }, |
| 3391 groupedRangeChanged_: function(range, oldRange) { |
| 3392 this.selectedPage_ = |
| 3393 range == HistoryRange.ALL_TIME ? "infinite-list" : "grouped-list"; |
| 3394 if (oldRange == undefined) |
| 3395 return; |
| 3396 this.set("queryState.groupedOffset", 0); |
| 3397 if (this.queryResult.info) { |
| 3398 this.set("queryResult.results", []); |
| 3399 this.historyResult(this.queryResult.info, []) |
| 3400 } |
| 3401 this.queryHistory(false); |
| 3402 this.fire("history-view-changed") |
| 3403 }, |
| 3404 searchTermChanged_: function() { |
| 3405 this.queryHistory(false); |
| 3406 if (this.queryState.searchTerm) |
| 3407 md_history.BrowserService.getInstance().recordAction("Search") |
| 3408 }, |
| 3409 groupedOffsetChanged_: function() { |
| 3410 this.queryHistory(false) |
| 3411 }, |
| 3412 loadMoreHistory_: function() { |
| 3413 this.queryHistory(true) |
| 3414 }, |
| 3415 initializeResults_: function(info, results) { |
| 3416 if (results.length == 0) |
| 3417 return; |
| 3418 var currentDate = results[0].dateRelativeDay; |
| 3419 for (var i = 0; i < results.length; i++) { |
| 3420 results[i].selected = false; |
| 3421 results[i].readableTimestamp = |
| 3422 info.term == "" ? results[i].dateTimeOfDay : results[i].dateShort; |
| 3423 if (results[i].dateRelativeDay != currentDate) { |
| 3424 currentDate = results[i].dateRelativeDay |
| 3425 } |
| 3426 } |
| 3427 }, |
| 3428 onDialogConfirmTap_: function() { |
| 3429 md_history.BrowserService.getInstance().recordAction( |
| 3430 "ConfirmRemoveSelected"); |
| 3431 this.getSelectedList_().deleteSelected(); |
| 3432 var dialog = assert(this.$.dialog.getIfExists()); |
| 3433 dialog.close() |
| 3434 }, |
| 3435 onDialogCancelTap_: function() { |
| 3436 md_history.BrowserService.getInstance().recordAction( |
| 3437 "CancelRemoveSelected"); |
| 3438 var dialog = assert(this.$.dialog.getIfExists()); |
| 3439 dialog.close() |
| 3440 }, |
| 3441 closeMenu_: function() { |
| 3442 var menu = this.$.sharedMenu.getIfExists(); |
| 3443 if (menu && menu.open) { |
| 3444 this.actionMenuModel_ = null; |
| 3445 menu.close() |
| 3446 } |
| 3447 }, |
| 3448 openMenu_: function(e) { |
| 3449 var target = e.detail.target; |
| 3450 this.actionMenuModel_ = e.detail; |
| 3451 var menu = this.$.sharedMenu.get(); |
| 3452 menu.showAt(target) |
| 3453 }, |
| 3454 onMoreFromSiteTap_: function() { |
| 3455 md_history.BrowserService.getInstance().recordAction( |
| 3456 "EntryMenuShowMoreFromSite"); |
| 3457 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 3458 this.set("queryState.searchTerm", this.actionMenuModel_.item.domain); |
| 3459 this.actionMenuModel_ = null; |
| 3460 this.closeMenu_() |
| 3461 }, |
| 3462 onRemoveFromHistoryTap_: function() { |
| 3463 var browserService = md_history.BrowserService.getInstance(); |
| 3464 browserService.recordAction("EntryMenuRemoveFromHistory"); |
| 3465 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 3466 var itemData = this.actionMenuModel_; |
| 3467 browserService.deleteItems([itemData.item]).then(function(items) { |
| 3468 this.fire("unselect-all"); |
| 3469 this.getSelectedList_().removeItemsByPath([itemData.path]); |
| 3470 var index = itemData.index; |
| 3471 if (index == undefined) |
| 3472 return; |
| 3473 var browserService = md_history.BrowserService.getInstance(); |
| 3474 browserService.recordHistogram( |
| 3475 "HistoryPage.RemoveEntryPosition", |
| 3476 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); |
| 3477 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { |
| 3478 browserService.recordHistogram( |
| 3479 "HistoryPage.RemoveEntryPositionSubset", index, |
| 3480 UMA_MAX_SUBSET_BUCKET_VALUE) |
| 3481 } |
| 3482 }.bind(this)); |
| 3483 this.closeMenu_() |
| 3484 }, |
| 3485 getSelectedList_: function() { |
| 3486 return this.$$("#" + this.selectedPage_) |
| 3487 }, |
| 3488 canDeleteHistory_: function() { |
| 3489 return loadTimeData.getBoolean("allowDeletingHistory") |
| 3490 } |
| 3491 }); |
| 3492 (function() { |
| 3493 "use strict"; |
| 3494 Polymer({ |
| 3495 is: "iron-location", |
| 3496 properties: { |
| 3497 path: { |
| 3498 type: String, |
| 3499 notify: true, |
| 3500 value: function() { |
| 3501 return window.decodeURIComponent(window.location.pathname) |
| 3502 } |
| 3503 }, |
| 3504 query: { |
| 3505 type: String, |
| 3506 notify: true, |
| 3507 value: function() { |
| 3508 return window.decodeURIComponent(window.location.search.slice(1)) |
| 3509 } |
| 3510 }, |
| 3511 hash: { |
| 3512 type: String, |
| 3513 notify: true, |
| 3514 value: function() { |
| 3515 return window.decodeURIComponent(window.location.hash.slice(1)) |
| 3516 } |
| 3517 }, |
| 3518 dwellTime: {type: Number, value: 2e3}, |
| 3519 urlSpaceRegex: {type: String, value: ""}, |
| 3520 _urlSpaceRegExp: {computed: "_makeRegExp(urlSpaceRegex)"}, |
| 3521 _lastChangedAt: {type: Number}, |
| 3522 _initialized: {type: Boolean, value: false} |
| 3523 }, |
| 3524 hostAttributes: {hidden: true}, |
| 3525 observers: ["_updateUrl(path, query, hash)"], |
| 3526 attached: function() { |
| 3527 this.listen(window, "hashchange", "_hashChanged"); |
| 3528 this.listen(window, "location-changed", "_urlChanged"); |
| 3529 this.listen(window, "popstate", "_urlChanged"); |
| 3530 this.listen(document.body, "click", "_globalOnClick"); |
| 3531 this._lastChangedAt = window.performance.now() - (this.dwellTime - 200); |
| 3532 this._initialized = true; |
| 3533 this._urlChanged() |
| 3534 }, |
| 3535 detached: function() { |
| 3536 this.unlisten(window, "hashchange", "_hashChanged"); |
| 3537 this.unlisten(window, "location-changed", "_urlChanged"); |
| 3538 this.unlisten(window, "popstate", "_urlChanged"); |
| 3539 this.unlisten(document.body, "click", "_globalOnClick"); |
| 3540 this._initialized = false |
| 3541 }, |
| 3542 _hashChanged: function() { |
| 3543 this.hash = window.decodeURIComponent(window.location.hash.substring(1)) |
| 3544 }, |
| 3545 _urlChanged: function() { |
| 3546 this._dontUpdateUrl = true; |
| 3547 this._hashChanged(); |
| 3548 this.path = window.decodeURIComponent(window.location.pathname); |
| 3549 this.query = |
| 3550 window.decodeURIComponent(window.location.search.substring(1)); |
| 3551 this._dontUpdateUrl = false; |
| 3552 this._updateUrl() |
| 3553 }, |
| 3554 _getUrl: function() { |
| 3555 var partiallyEncodedPath = window.encodeURI(this.path) |
| 3556 .replace(/\#/g, "%23") |
| 3557 .replace(/\?/g, "%3F"); |
| 3558 var partiallyEncodedQuery = ""; |
| 3559 if (this.query) { |
| 3560 partiallyEncodedQuery = |
| 3561 "?" + window.encodeURI(this.query).replace(/\#/g, "%23") |
| 3562 } |
| 3563 var partiallyEncodedHash = ""; |
| 3564 if (this.hash) { |
| 3565 partiallyEncodedHash = "#" + window.encodeURI(this.hash) |
| 3566 } |
| 3567 return partiallyEncodedPath + partiallyEncodedQuery + partiallyEncodedHash |
| 3568 }, |
| 3569 _updateUrl: function() { |
| 3570 if (this._dontUpdateUrl || !this._initialized) { |
| 3571 return |
| 3572 } |
| 3573 if (this.path === window.decodeURIComponent(window.location.pathname) && |
| 3574 this.query === |
| 3575 window.decodeURIComponent(window.location.search.substring(1)) && |
| 3576 this.hash === |
| 3577 window.decodeURIComponent(window.location.hash.substring(1))) { |
| 3578 return |
| 3579 } |
| 3580 var newUrl = this._getUrl(); |
| 3581 var fullNewUrl = |
| 3582 new URL( |
| 3583 newUrl, window.location.protocol + "//" + window.location.host) |
| 3584 .href; |
| 3585 var now = window.performance.now(); |
| 3586 var shouldReplace = this._lastChangedAt + this.dwellTime > now; |
| 3587 this._lastChangedAt = now; |
| 3588 if (shouldReplace) { |
| 3589 window.history.replaceState({}, "", fullNewUrl) |
| 3590 } else { |
| 3591 window.history.pushState({}, "", fullNewUrl) |
| 3592 } |
| 3593 this.fire("location-changed", {}, {node: window}) |
| 3594 }, |
| 3595 _globalOnClick: function(event) { |
| 3596 if (event.defaultPrevented) { |
| 3597 return |
| 3598 } |
| 3599 var href = this._getSameOriginLinkHref(event); |
| 3600 if (!href) { |
| 3601 return |
| 3602 } |
| 3603 event.preventDefault(); |
| 3604 if (href === window.location.href) { |
| 3605 return |
| 3606 } |
| 3607 window.history.pushState({}, "", href); |
| 3608 this.fire("location-changed", {}, {node: window}) |
| 3609 }, |
| 3610 _getSameOriginLinkHref: function(event) { |
| 3611 if (event.button !== 0) { |
| 3612 return null |
| 3613 } |
| 3614 if (event.metaKey || event.ctrlKey) { |
| 3615 return null |
| 3616 } |
| 3617 var eventPath = Polymer.dom(event).path; |
| 3618 var anchor = null; |
| 3619 for (var i = 0; i < eventPath.length; i++) { |
| 3620 var element = eventPath[i]; |
| 3621 if (element.tagName === "A" && element.href) { |
| 3622 anchor = element; |
| 3623 break |
| 3624 } |
| 3625 } |
| 3626 if (!anchor) { |
| 3627 return null |
| 3628 } |
| 3629 if (anchor.target === "_blank") { |
| 3630 return null |
| 3631 } |
| 3632 if ((anchor.target === "_top" || anchor.target === "_parent") && |
| 3633 window.top !== window) { |
| 3634 return null |
| 3635 } |
| 3636 var href = anchor.href; |
| 3637 var url; |
| 3638 if (document.baseURI != null) { |
| 3639 url = new URL(href, document.baseURI) |
| 3640 } else { |
| 3641 url = new URL(href) |
| 3642 } |
| 3643 var origin; |
| 3644 if (window.location.origin) { |
| 3645 origin = window.location.origin |
| 3646 } else { |
| 3647 origin = window.location.protocol + "//" + window.location.hostname; |
| 3648 if (window.location.port) { |
| 3649 origin += ":" + window.location.port |
| 3650 } |
| 3651 } |
| 3652 if (url.origin !== origin) { |
| 3653 return null |
| 3654 } |
| 3655 var normalizedHref = url.pathname + url.search + url.hash; |
| 3656 if (this._urlSpaceRegExp && !this._urlSpaceRegExp.test(normalizedHref)) { |
| 3657 return null |
| 3658 } |
| 3659 var fullNormalizedHref = |
| 3660 new URL(normalizedHref, window.location.href).href; |
| 3661 return fullNormalizedHref |
| 3662 }, |
| 3663 _makeRegExp: function(urlSpaceRegex) { |
| 3664 return RegExp(urlSpaceRegex) |
| 3665 } |
| 3666 }) |
| 3667 })(); |
| 3668 "use strict"; |
| 3669 Polymer({ |
| 3670 is: "iron-query-params", |
| 3671 properties: { |
| 3672 paramsString: {type: String, notify: true, observer: "paramsStringChanged"}, |
| 3673 paramsObject: { |
| 3674 type: Object, |
| 3675 notify: true, |
| 3676 value: function() { |
| 3677 return {} |
| 3678 } |
| 3679 }, |
| 3680 _dontReact: {type: Boolean, value: false} |
| 3681 }, |
| 3682 hostAttributes: {hidden: true}, |
| 3683 observers: ["paramsObjectChanged(paramsObject.*)"], |
| 3684 paramsStringChanged: function() { |
| 3685 this._dontReact = true; |
| 3686 this.paramsObject = this._decodeParams(this.paramsString); |
| 3687 this._dontReact = false |
| 3688 }, |
| 3689 paramsObjectChanged: function() { |
| 3690 if (this._dontReact) { |
| 3691 return |
| 3692 } |
| 3693 this.paramsString = this._encodeParams(this.paramsObject) |
| 3694 }, |
| 3695 _encodeParams: function(params) { |
| 3696 var encodedParams = []; |
| 3697 for (var key in params) { |
| 3698 var value = params[key]; |
| 3699 if (value === "") { |
| 3700 encodedParams.push(encodeURIComponent(key)) |
| 3701 } else if (value) { |
| 3702 encodedParams.push( |
| 3703 encodeURIComponent(key) + "=" + |
| 3704 encodeURIComponent(value.toString())) |
| 3705 } |
| 3706 } |
| 3707 return encodedParams.join("&") |
| 3708 }, |
| 3709 _decodeParams: function(paramString) { |
| 3710 var params = {}; |
| 3711 paramString = (paramString || "").replace(/\+/g, "%20"); |
| 3712 var paramList = paramString.split("&"); |
| 3713 for (var i = 0; i < paramList.length; i++) { |
| 3714 var param = paramList[i].split("="); |
| 3715 if (param[0]) { |
| 3716 params[decodeURIComponent(param[0])] = |
| 3717 decodeURIComponent(param[1] || "") |
| 3718 } |
| 3719 } |
| 3720 return params |
| 3721 } |
| 3722 }); |
| 73 // Copyright 2016 The Chromium Authors. All rights reserved. | 3723 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 74 // Use of this source code is governed by a BSD-style license that can be | 3724 // Use of this source code is governed by a BSD-style license that can be |
| 75 // found in the LICENSE file. | 3725 // found in the LICENSE file. |
| 76 Polymer({is:"history-router",properties:{selectedPage:{type:String,observer:"ser
ializePath_",notify:true},queryState:{type:Object,notify:true},path_:{type:Strin
g,observer:"pathChanged_"},queryParams_:Object},observers:["queryParamsChanged_(
queryParams_.*)","searchTermChanged_(queryState.searchTerm)"],attached:function(
){if(window.location.hash){window.location.href=window.location.href.split("#")[
0]+"?"+window.location.hash.substr(1)}},serializePath_:function(){var page=this.
selectedPage=="history"?"":this.selectedPage;this.path_="/"+page},pathChanged_:f
unction(){var sections=this.path_.substr(1).split("/");this.selectedPage=section
s[0]||"history"},queryParamsChanged_:function(){this.set("queryState.searchTerm"
,this.queryParams_.q||"")},searchTermChanged_:function(){this.set("queryParams_.
q",this.queryState.searchTerm||null)}});Polymer.IronMultiSelectableBehaviorImpl=
{properties:{multi:{type:Boolean,value:false,observer:"multiChanged"},selectedVa
lues:{type:Array,notify:true},selectedItems:{type:Array,readOnly:true,notify:tru
e}},observers:["_updateSelected(selectedValues.splices)"],select:function(value)
{if(this.multi){if(this.selectedValues){this._toggleSelected(value)}else{this.se
lectedValues=[value]}}else{this.selected=value}},multiChanged:function(multi){th
is._selection.multi=multi},get _shouldUpdateSelection(){return this.selected!=nu
ll||this.selectedValues!=null&&this.selectedValues.length},_updateAttrForSelecte
d:function(){if(!this.multi){Polymer.IronSelectableBehavior._updateAttrForSelect
ed.apply(this)}else if(this._shouldUpdateSelection){this.selectedValues=this.sel
ectedItems.map(function(selectedItem){return this._indexToValue(this.indexOf(sel
ectedItem))},this).filter(function(unfilteredValue){return unfilteredValue!=null
},this)}},_updateSelected:function(){if(this.multi){this._selectMulti(this.selec
tedValues)}else{this._selectSelected(this.selected)}},_selectMulti:function(valu
es){if(values){var selectedItems=this._valuesToItems(values);this._selection.cle
ar(selectedItems);for(var i=0;i<selectedItems.length;i++){this._selection.setIte
mSelected(selectedItems[i],true)}if(this.fallbackSelection&&this.items.length&&!
this._selection.get().length){var fallback=this._valueToItem(this.fallbackSelect
ion);if(fallback){this.selectedValues=[this.fallbackSelection]}}}else{this._sele
ction.clear()}},_selectionChange:function(){var s=this._selection.get();if(this.
multi){this._setSelectedItems(s)}else{this._setSelectedItems([s]);this._setSelec
tedItem(s)}},_toggleSelected:function(value){var i=this.selectedValues.indexOf(v
alue);var unselected=i<0;if(unselected){this.push("selectedValues",value)}else{t
his.splice("selectedValues",i,1)}},_valuesToItems:function(values){return values
==null?null:values.map(function(value){return this._valueToItem(value)},this)}};
Polymer.IronMultiSelectableBehavior=[Polymer.IronSelectableBehavior,Polymer.Iron
MultiSelectableBehaviorImpl];Polymer({is:"iron-selector",behaviors:[Polymer.Iron
MultiSelectableBehavior]}); | 3726 Polymer({ |
| 3727 is: "history-router", |
| 3728 properties: { |
| 3729 selectedPage: {type: String, observer: "serializePath_", notify: true}, |
| 3730 queryState: {type: Object, notify: true}, |
| 3731 path_: {type: String, observer: "pathChanged_"}, |
| 3732 queryParams_: Object |
| 3733 }, |
| 3734 observers: [ |
| 3735 "queryParamsChanged_(queryParams_.*)", |
| 3736 "searchTermChanged_(queryState.searchTerm)" |
| 3737 ], |
| 3738 attached: function() { |
| 3739 if (window.location.hash) { |
| 3740 window.location.href = window.location.href.split("#")[0] + "?" + |
| 3741 window.location.hash.substr(1) |
| 3742 } |
| 3743 }, |
| 3744 serializePath_: function() { |
| 3745 var page = this.selectedPage == "history" ? "" : this.selectedPage; |
| 3746 this.path_ = "/" + page |
| 3747 }, |
| 3748 pathChanged_: function() { |
| 3749 var sections = this.path_.substr(1).split("/"); |
| 3750 this.selectedPage = sections[0] || "history" |
| 3751 }, |
| 3752 queryParamsChanged_: function() { |
| 3753 this.set("queryState.searchTerm", this.queryParams_.q || "") |
| 3754 }, |
| 3755 searchTermChanged_: function() { |
| 3756 this.set("queryParams_.q", this.queryState.searchTerm || null) |
| 3757 } |
| 3758 }); |
| 3759 Polymer.IronMultiSelectableBehaviorImpl = { |
| 3760 properties: { |
| 3761 multi: {type: Boolean, value: false, observer: "multiChanged"}, |
| 3762 selectedValues: {type: Array, notify: true}, |
| 3763 selectedItems: {type: Array, readOnly: true, notify: true} |
| 3764 }, |
| 3765 observers: ["_updateSelected(selectedValues.splices)"], |
| 3766 select: function(value) { |
| 3767 if (this.multi) { |
| 3768 if (this.selectedValues) { |
| 3769 this._toggleSelected(value) |
| 3770 } else { |
| 3771 this.selectedValues = [value] |
| 3772 } |
| 3773 } else { |
| 3774 this.selected = value |
| 3775 } |
| 3776 }, |
| 3777 multiChanged: function(multi) { |
| 3778 this._selection.multi = multi |
| 3779 }, |
| 3780 get _shouldUpdateSelection() { |
| 3781 return this.selected != null || |
| 3782 this.selectedValues != null && this.selectedValues.length |
| 3783 }, |
| 3784 _updateAttrForSelected: function() { |
| 3785 if (!this.multi) { |
| 3786 Polymer.IronSelectableBehavior._updateAttrForSelected.apply(this) |
| 3787 } else if (this._shouldUpdateSelection) { |
| 3788 this.selectedValues = |
| 3789 this.selectedItems |
| 3790 .map( |
| 3791 function(selectedItem) { |
| 3792 return this._indexToValue(this.indexOf(selectedItem)) |
| 3793 }, |
| 3794 this) |
| 3795 .filter(function(unfilteredValue) { |
| 3796 return unfilteredValue != null |
| 3797 }, this) |
| 3798 } |
| 3799 }, |
| 3800 _updateSelected: function() { |
| 3801 if (this.multi) { |
| 3802 this._selectMulti(this.selectedValues) |
| 3803 } else { |
| 3804 this._selectSelected(this.selected) |
| 3805 } |
| 3806 }, |
| 3807 _selectMulti: function(values) { |
| 3808 if (values) { |
| 3809 var selectedItems = this._valuesToItems(values); |
| 3810 this._selection.clear(selectedItems); |
| 3811 for (var i = 0; i < selectedItems.length; i++) { |
| 3812 this._selection.setItemSelected(selectedItems[i], true) |
| 3813 } |
| 3814 if (this.fallbackSelection && this.items.length && |
| 3815 !this._selection.get().length) { |
| 3816 var fallback = this._valueToItem(this.fallbackSelection); |
| 3817 if (fallback) { |
| 3818 this.selectedValues = [this.fallbackSelection] |
| 3819 } |
| 3820 } |
| 3821 } else { |
| 3822 this._selection.clear() |
| 3823 } |
| 3824 }, |
| 3825 _selectionChange: function() { |
| 3826 var s = this._selection.get(); |
| 3827 if (this.multi) { |
| 3828 this._setSelectedItems(s) |
| 3829 } else { |
| 3830 this._setSelectedItems([s]); |
| 3831 this._setSelectedItem(s) |
| 3832 } |
| 3833 }, |
| 3834 _toggleSelected: function(value) { |
| 3835 var i = this.selectedValues.indexOf(value); |
| 3836 var unselected = i < 0; |
| 3837 if (unselected) { |
| 3838 this.push("selectedValues", value) |
| 3839 } else { |
| 3840 this.splice("selectedValues", i, 1) |
| 3841 } |
| 3842 }, |
| 3843 _valuesToItems: function(values) { |
| 3844 return values == null ? null : values.map(function(value) { |
| 3845 return this._valueToItem(value) |
| 3846 }, this) |
| 3847 } |
| 3848 }; |
| 3849 Polymer.IronMultiSelectableBehavior = |
| 3850 [Polymer.IronSelectableBehavior, Polymer.IronMultiSelectableBehaviorImpl]; |
| 3851 Polymer( |
| 3852 {is: "iron-selector", behaviors: [Polymer.IronMultiSelectableBehavior]}); |
| 77 // Copyright 2016 The Chromium Authors. All rights reserved. | 3853 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 78 // Use of this source code is governed by a BSD-style license that can be | 3854 // Use of this source code is governed by a BSD-style license that can be |
| 79 // found in the LICENSE file. | 3855 // found in the LICENSE file. |
| 80 Polymer({is:"history-side-bar",behaviors:[Polymer.IronA11yKeysBehavior],properti
es:{selectedPage:{type:String,notify:true},drawer:{type:Boolean,reflectToAttribu
te:true},showFooter:Boolean},keyBindings:{"space:keydown":"onSpacePressed_"},onS
pacePressed_:function(e){e.detail.keyboardEvent.path[0].click()},onSelectorActiv
ate_:function(){this.fire("history-close-drawer")},onClearBrowsingDataTap_:funct
ion(e){var browserService=md_history.BrowserService.getInstance();browserService
.recordAction("InitClearBrowsingData");browserService.openClearBrowsingData();th
is.$["cbd-ripple"].upAction();e.preventDefault()},onItemClick_:function(e){e.pre
ventDefault()}}); | 3856 Polymer({ |
| 3857 is: "history-side-bar", |
| 3858 behaviors: [Polymer.IronA11yKeysBehavior], |
| 3859 properties: { |
| 3860 selectedPage: {type: String, notify: true}, |
| 3861 drawer: {type: Boolean, reflectToAttribute: true}, |
| 3862 showFooter: Boolean |
| 3863 }, |
| 3864 keyBindings: {"space:keydown": "onSpacePressed_"}, |
| 3865 onSpacePressed_: function(e) { |
| 3866 e.detail.keyboardEvent.path[0].click() |
| 3867 }, |
| 3868 onSelectorActivate_: function() { |
| 3869 this.fire("history-close-drawer") |
| 3870 }, |
| 3871 onClearBrowsingDataTap_: function(e) { |
| 3872 var browserService = md_history.BrowserService.getInstance(); |
| 3873 browserService.recordAction("InitClearBrowsingData"); |
| 3874 browserService.openClearBrowsingData(); |
| 3875 this.$["cbd-ripple"].upAction(); |
| 3876 e.preventDefault() |
| 3877 }, |
| 3878 onItemClick_: function(e) { |
| 3879 e.preventDefault() |
| 3880 } |
| 3881 }); |
| 81 // Copyright 2016 The Chromium Authors. All rights reserved. | 3882 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 82 // Use of this source code is governed by a BSD-style license that can be | 3883 // Use of this source code is governed by a BSD-style license that can be |
| 83 // found in the LICENSE file. | 3884 // found in the LICENSE file. |
| 84 cr.define("md_history",function(){var lazyLoadPromise=null;function ensureLazyLo
aded(){if(!lazyLoadPromise){lazyLoadPromise=new Promise(function(resolve,reject)
{Polymer.Base.importHref("chrome://history/lazy_load.html",resolve,reject,true)}
)}return lazyLoadPromise}return{ensureLazyLoaded:ensureLazyLoaded}});Polymer({is
:"history-app",behaviors:[Polymer.IronScrollTargetBehavior],properties:{selected
Page_:{type:String,observer:"selectedPageChanged_"},grouped_:{type:Boolean,refle
ctToAttribute:true},queryState_:{type:Object,value:function(){return{incremental
:false,querying:true,queryingDisabled:false,_range:HistoryRange.ALL_TIME,searchT
erm:"",groupedOffset:0,set range(val){this._range=Number(val)},get range(){retur
n this._range}}}},queryResult_:{type:Object,value:function(){return{info:null,re
sults:null,sessionList:null}}},isUserSignedIn_:{type:Boolean,value:loadTimeData.
getBoolean("isUserSignedIn")},toolbarShadow_:{type:Boolean,reflectToAttribute:tr
ue,notify:true},showMenuPromo_:{type:Boolean,value:function(){return loadTimeDat
a.getBoolean("showMenuPromo")}},hasDrawer_:Boolean,showSidebarFooter:Boolean,has
SyncedResults:Boolean},listeners:{"cr-toolbar-menu-promo-close":"onCrToolbarMenu
PromoClose_","cr-toolbar-menu-promo-shown":"onCrToolbarMenuPromoShown_","cr-tool
bar-menu-tap":"onCrToolbarMenuTap_","delete-selected":"deleteSelected","history-
checkbox-select":"checkboxSelected","history-close-drawer":"closeDrawer_","histo
ry-view-changed":"historyViewChanged_","opened-changed":"onOpenedChanged_","unse
lect-all":"unselectAll"},boundOnCanExecute_:null,boundOnCommand_:null,attached:f
unction(){this.grouped_=loadTimeData.getBoolean("groupByDomain");cr.ui.decorate(
"command",cr.ui.Command);this.boundOnCanExecute_=this.onCanExecute_.bind(this);t
his.boundOnCommand_=this.onCommand_.bind(this);document.addEventListener("canExe
cute",this.boundOnCanExecute_);document.addEventListener("command",this.boundOnC
ommand_)},detached:function(){document.removeEventListener("canExecute",this.bou
ndOnCanExecute_);document.removeEventListener("command",this.boundOnCommand_)},o
nFirstRender:function(){setTimeout(function(){chrome.send("metricsHandler:record
Time",["History.ResultsRenderedTime",window.performance.now()])});var searchFiel
d=this.$.toolbar.searchField;if(!searchField.narrow){searchField.getSearchInput(
).focus()}md_history.ensureLazyLoaded().then(function(){window.requestIdleCallba
ck(function(){document.fonts.load("bold 12px Roboto")})})},_scrollHandler:functi
on(){if(this.scrollTarget)this.toolbarShadow_=this.scrollTarget.scrollTop!=0},on
CrToolbarMenuPromoClose_:function(){this.showMenuPromo_=false},onCrToolbarMenuPr
omoShown_:function(){md_history.BrowserService.getInstance().menuPromoShown()},o
nCrToolbarMenuTap_:function(){var drawer=this.$$("#drawer");if(drawer)drawer.tog
gle()},onOpenedChanged_:function(e){if(e.detail.value)this.showMenuPromo_=false}
,checkboxSelected:function(e){var toolbar=this.$.toolbar;toolbar.count=this.$.hi
story.getSelectedItemCount()},unselectAll:function(){var listContainer=this.$.hi
story;var toolbar=this.$.toolbar;listContainer.unselectAllItems(toolbar.count);t
oolbar.count=0},deleteSelected:function(){this.$.history.deleteSelectedWithPromp
t()},historyResult:function(info,results){this.set("queryState_.querying",false)
;this.set("queryResult_.info",info);this.set("queryResult_.results",results);var
listContainer=this.$["history"];listContainer.historyResult(info,results)},focu
sToolbarSearchField:function(){this.$.toolbar.showSearchField()},onCanExecute_:f
unction(e){e=e;switch(e.command.id){case"find-command":case"toggle-grouped":e.ca
nExecute=true;break;case"slash-command":e.canExecute=!this.$.toolbar.searchField
.isSearchFocused();break;case"delete-command":e.canExecute=this.$.toolbar.count>
0;break}},onCommand_:function(e){if(e.command.id=="find-command"||e.command.id==
"slash-command")this.focusToolbarSearchField();if(e.command.id=="delete-command"
)this.deleteSelected();if(e.command.id=="toggle-grouped")this.grouped_=!this.gro
uped_},setForeignSessions:function(sessionList){this.set("queryResult_.sessionLi
st",sessionList)},historyDeleted:function(){this.$.history.historyDeleted()},upd
ateSignInState:function(isUserSignedIn){this.isUserSignedIn_=isUserSignedIn},syn
cedTabsSelected_:function(selectedPage){return selectedPage=="syncedTabs"},shoul
dShowSpinner_:function(querying,incremental,searchTerm){return querying&&!increm
ental&&searchTerm!=""},showSyncNotice_:function(hasSyncedResults,selectedPage){r
eturn hasSyncedResults&&selectedPage!="syncedTabs"},selectedPageChanged_:functio
n(){this.unselectAll();this.historyViewChanged_()},historyViewChanged_:function(
){requestAnimationFrame(function(){md_history.ensureLazyLoaded().then(function()
{if(!this.$.content.selectedItem)return;this.scrollTarget=this.$.content.selecte
dItem.getContentScrollTarget();this._scrollHandler()}.bind(this))}.bind(this));t
his.recordHistoryPageView_()},getSelectedPage_:function(selectedPage,items){retu
rn selectedPage},closeDrawer_:function(){var drawer=this.$$("#drawer");if(drawer
)drawer.close()},recordHistoryPageView_:function(){var histogramValue=HistoryPag
eViewHistogram.END;switch(this.selectedPage_){case"syncedTabs":histogramValue=th
is.isUserSignedIn_?HistoryPageViewHistogram.SYNCED_TABS:HistoryPageViewHistogram
.SIGNIN_PROMO;break;default:switch(this.queryState_.range){case HistoryRange.ALL
_TIME:histogramValue=HistoryPageViewHistogram.HISTORY;break;case HistoryRange.WE
EK:histogramValue=HistoryPageViewHistogram.GROUPED_WEEK;break;case HistoryRange.
MONTH:histogramValue=HistoryPageViewHistogram.GROUPED_MONTH;break}break}md_histo
ry.BrowserService.getInstance().recordHistogram("History.HistoryPageView",histog
ramValue,HistoryPageViewHistogram.END)}}); | 3885 cr.define("md_history", function() { |
| 3886 var lazyLoadPromise = null; |
| 3887 function ensureLazyLoaded() { |
| 3888 if (!lazyLoadPromise) { |
| 3889 lazyLoadPromise = new Promise(function(resolve, reject) { |
| 3890 Polymer.Base.importHref( |
| 3891 "chrome://history/lazy_load.html", resolve, reject, true) |
| 3892 }) |
| 3893 } |
| 3894 return lazyLoadPromise |
| 3895 } |
| 3896 return { |
| 3897 ensureLazyLoaded: ensureLazyLoaded |
| 3898 } |
| 3899 }); |
| 3900 Polymer({ |
| 3901 is: "history-app", |
| 3902 behaviors: [Polymer.IronScrollTargetBehavior], |
| 3903 properties: { |
| 3904 selectedPage_: {type: String, observer: "selectedPageChanged_"}, |
| 3905 grouped_: {type: Boolean, reflectToAttribute: true}, |
| 3906 queryState_: { |
| 3907 type: Object, |
| 3908 value: function() { |
| 3909 return { |
| 3910 incremental: false, querying: true, queryingDisabled: false, |
| 3911 _range: HistoryRange.ALL_TIME, searchTerm: "", groupedOffset: 0, |
| 3912 set range(val){this._range = Number(val)}, get range() { |
| 3913 return this._range |
| 3914 } |
| 3915 } |
| 3916 } |
| 3917 }, |
| 3918 queryResult_: { |
| 3919 type: Object, |
| 3920 value: function() { |
| 3921 return { |
| 3922 info: null, results: null, sessionList: null |
| 3923 } |
| 3924 } |
| 3925 }, |
| 3926 isUserSignedIn_: |
| 3927 {type: Boolean, value: loadTimeData.getBoolean("isUserSignedIn")}, |
| 3928 toolbarShadow_: {type: Boolean, reflectToAttribute: true, notify: true}, |
| 3929 showMenuPromo_: { |
| 3930 type: Boolean, |
| 3931 value: function() { |
| 3932 return loadTimeData.getBoolean("showMenuPromo") |
| 3933 } |
| 3934 }, |
| 3935 hasDrawer_: Boolean, |
| 3936 showSidebarFooter: Boolean, |
| 3937 hasSyncedResults: Boolean |
| 3938 }, |
| 3939 listeners: { |
| 3940 "cr-toolbar-menu-promo-close": "onCrToolbarMenuPromoClose_", |
| 3941 "cr-toolbar-menu-promo-shown": "onCrToolbarMenuPromoShown_", |
| 3942 "cr-toolbar-menu-tap": "onCrToolbarMenuTap_", |
| 3943 "delete-selected": "deleteSelected", |
| 3944 "history-checkbox-select": "checkboxSelected", |
| 3945 "history-close-drawer": "closeDrawer_", |
| 3946 "history-view-changed": "historyViewChanged_", |
| 3947 "opened-changed": "onOpenedChanged_", |
| 3948 "unselect-all": "unselectAll" |
| 3949 }, |
| 3950 boundOnCanExecute_: null, |
| 3951 boundOnCommand_: null, |
| 3952 attached: function() { |
| 3953 this.grouped_ = loadTimeData.getBoolean("groupByDomain"); |
| 3954 cr.ui.decorate("command", cr.ui.Command); |
| 3955 this.boundOnCanExecute_ = this.onCanExecute_.bind(this); |
| 3956 this.boundOnCommand_ = this.onCommand_.bind(this); |
| 3957 document.addEventListener("canExecute", this.boundOnCanExecute_); |
| 3958 document.addEventListener("command", this.boundOnCommand_) |
| 3959 }, |
| 3960 detached: function() { |
| 3961 document.removeEventListener("canExecute", this.boundOnCanExecute_); |
| 3962 document.removeEventListener("command", this.boundOnCommand_) |
| 3963 }, |
| 3964 onFirstRender: function() { |
| 3965 setTimeout(function() { |
| 3966 chrome.send( |
| 3967 "metricsHandler:recordTime", |
| 3968 ["History.ResultsRenderedTime", window.performance.now()]) |
| 3969 }); |
| 3970 var searchField = this.$.toolbar.searchField; |
| 3971 if (!searchField.narrow) { |
| 3972 searchField.getSearchInput().focus() |
| 3973 } |
| 3974 md_history.ensureLazyLoaded().then(function() { |
| 3975 window.requestIdleCallback(function() { |
| 3976 document.fonts.load("bold 12px Roboto") |
| 3977 }) |
| 3978 }) |
| 3979 }, |
| 3980 _scrollHandler: function() { |
| 3981 if (this.scrollTarget) |
| 3982 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0 |
| 3983 }, |
| 3984 onCrToolbarMenuPromoClose_: function() { |
| 3985 this.showMenuPromo_ = false |
| 3986 }, |
| 3987 onCrToolbarMenuPromoShown_: function() { |
| 3988 md_history.BrowserService.getInstance().menuPromoShown() |
| 3989 }, |
| 3990 onCrToolbarMenuTap_: function() { |
| 3991 var drawer = this.$$("#drawer"); |
| 3992 if (drawer) |
| 3993 drawer.toggle() |
| 3994 }, |
| 3995 onOpenedChanged_: function(e) { |
| 3996 if (e.detail.value) |
| 3997 this.showMenuPromo_ = false |
| 3998 }, |
| 3999 checkboxSelected: function(e) { |
| 4000 var toolbar = this.$.toolbar; |
| 4001 toolbar.count = this.$.history.getSelectedItemCount() |
| 4002 }, |
| 4003 unselectAll: function() { |
| 4004 var listContainer = this.$.history; |
| 4005 var toolbar = this.$.toolbar; |
| 4006 listContainer.unselectAllItems(toolbar.count); |
| 4007 toolbar.count = 0 |
| 4008 }, |
| 4009 deleteSelected: function() { |
| 4010 this.$.history.deleteSelectedWithPrompt() |
| 4011 }, |
| 4012 historyResult: function(info, results) { |
| 4013 this.set("queryState_.querying", false); |
| 4014 this.set("queryResult_.info", info); |
| 4015 this.set("queryResult_.results", results); |
| 4016 var listContainer = this.$["history"]; |
| 4017 listContainer.historyResult(info, results) |
| 4018 }, |
| 4019 focusToolbarSearchField: function() { |
| 4020 this.$.toolbar.showSearchField() |
| 4021 }, |
| 4022 onCanExecute_: function(e) { |
| 4023 e = e; |
| 4024 switch (e.command.id) { |
| 4025 case "find-command": |
| 4026 case "toggle-grouped": |
| 4027 e.canExecute = true; |
| 4028 break; |
| 4029 case "slash-command": |
| 4030 e.canExecute = !this.$.toolbar.searchField.isSearchFocused(); |
| 4031 break; |
| 4032 case "delete-command": |
| 4033 e.canExecute = this.$.toolbar.count > 0; |
| 4034 break |
| 4035 } |
| 4036 }, |
| 4037 onCommand_: function(e) { |
| 4038 if (e.command.id == "find-command" || e.command.id == "slash-command") |
| 4039 this.focusToolbarSearchField(); |
| 4040 if (e.command.id == "delete-command") |
| 4041 this.deleteSelected(); |
| 4042 if (e.command.id == "toggle-grouped") |
| 4043 this.grouped_ = !this.grouped_ |
| 4044 }, |
| 4045 setForeignSessions: function(sessionList) { |
| 4046 this.set("queryResult_.sessionList", sessionList) |
| 4047 }, |
| 4048 historyDeleted: function() { |
| 4049 this.$.history.historyDeleted() |
| 4050 }, |
| 4051 updateSignInState: function(isUserSignedIn) { |
| 4052 this.isUserSignedIn_ = isUserSignedIn |
| 4053 }, |
| 4054 syncedTabsSelected_: function(selectedPage) { |
| 4055 return selectedPage == "syncedTabs" |
| 4056 }, |
| 4057 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
| 4058 return querying && !incremental && searchTerm != "" |
| 4059 }, |
| 4060 showSyncNotice_: function(hasSyncedResults, selectedPage) { |
| 4061 return hasSyncedResults && selectedPage != "syncedTabs" |
| 4062 }, |
| 4063 selectedPageChanged_: function() { |
| 4064 this.unselectAll(); |
| 4065 this.historyViewChanged_() |
| 4066 }, |
| 4067 historyViewChanged_: function() { |
| 4068 requestAnimationFrame(function() { |
| 4069 md_history.ensureLazyLoaded().then(function() { |
| 4070 if (!this.$.content.selectedItem) |
| 4071 return; |
| 4072 this.scrollTarget = |
| 4073 this.$.content.selectedItem.getContentScrollTarget(); |
| 4074 this._scrollHandler() |
| 4075 }.bind(this)) |
| 4076 }.bind(this)); |
| 4077 this.recordHistoryPageView_() |
| 4078 }, |
| 4079 getSelectedPage_: function(selectedPage, items) { |
| 4080 return selectedPage |
| 4081 }, |
| 4082 closeDrawer_: function() { |
| 4083 var drawer = this.$$("#drawer"); |
| 4084 if (drawer) |
| 4085 drawer.close() |
| 4086 }, |
| 4087 recordHistoryPageView_: function() { |
| 4088 var histogramValue = HistoryPageViewHistogram.END; |
| 4089 switch (this.selectedPage_) { |
| 4090 case "syncedTabs": |
| 4091 histogramValue = this.isUserSignedIn_ ? |
| 4092 HistoryPageViewHistogram.SYNCED_TABS : |
| 4093 HistoryPageViewHistogram.SIGNIN_PROMO; |
| 4094 break; |
| 4095 default: |
| 4096 switch (this.queryState_.range) { |
| 4097 case HistoryRange.ALL_TIME: |
| 4098 histogramValue = HistoryPageViewHistogram.HISTORY; |
| 4099 break; |
| 4100 case HistoryRange.WEEK: |
| 4101 histogramValue = HistoryPageViewHistogram.GROUPED_WEEK; |
| 4102 break; |
| 4103 case HistoryRange.MONTH: |
| 4104 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; |
| 4105 break |
| 4106 } |
| 4107 break |
| 4108 } |
| 4109 md_history.BrowserService.getInstance().recordHistogram( |
| 4110 "History.HistoryPageView", histogramValue, HistoryPageViewHistogram.END) |
| 4111 } |
| 4112 }); |
| OLD | NEW |