functionisHover(displayable, x, y) { if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) { var el = displayable; var isSilent; while (el) { // If clipped by ancestor. // FIXME: If clipPath has neither stroke nor fill, // el.clipPath.contain(x, y) will always return false. if (el.clipPath && !el.clipPath.contain(x, y)) { returnfalse; } if (el.silent) { isSilent = true; } el = el.parent; } return isSilent ? SILENT : true; }
rectContain: function (x, y) { var coord = this.transformCoordToLocal(x, y); var rect = this.getBoundingRect(); return rect.contain(coord[0], coord[1]); }
getBoundingRect: function () { // _rect变量做缓存用,计算完成后只在重绘时置空,避免重复计算 var rect = this._rect; var style = this.style; var needsUpdateRect = !rect; if (needsUpdateRect) { var path = this.path; if (!path) { // Create path on demand. path = this.path = newPathProxy(); } if (this.__dirtyPath) { path.beginPath(); this.buildPath(path, this.shape, false); } rect = path.getBoundingRect(); } this._rect = rect;
if (style.hasStroke()) { // ...
// Return rect with stroke return rectWithStroke; }
// subscribe to visibility change events document.addEventListener('visibilitychange', function () { // fires when user switches tabs, apps, goes to homescreen, etc. if (document.visibilityState === 'hidden') { document.title = 'Baby, Come Back!' } // fires when app transitions from prerender, user returns to the app / tab. if (document.visibilityState === 'visible') { document.title = defaultTitle; } });