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

Unified Diff: third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js

Issue 1766433002: Roll Polymer to 1.3.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js
diff --git a/third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js b/third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js
index 861e7f75d414a30575dae0a0599e8dcd77ca9c80..910830b5ddc39d31cd6512189f76e29eb21e4695 100644
--- a/third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js
+++ b/third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js
@@ -189,6 +189,25 @@
},
/**
+ * The CSS selector for the element that should receive focus when the drawer is open.
+ * By default, when the drawer opens, it focuses the first tabbable element. That is,
+ * the first element that can receive focus.
+ */
+ drawerFocusSelector: {
+ type: String,
+ value:
+ 'a[href]:not([tabindex="-1"]),'+
+ 'area[href]:not([tabindex="-1"]),'+
+ 'input:not([disabled]):not([tabindex="-1"]),'+
+ 'select:not([disabled]):not([tabindex="-1"]),'+
+ 'textarea:not([disabled]):not([tabindex="-1"]),'+
+ 'button:not([disabled]):not([tabindex="-1"]),'+
+ 'iframe:not([tabindex="-1"]),'+
+ '[tabindex]:not([tabindex="-1"]),'+
+ '[contentEditable=true]:not([tabindex="-1"])'
+ },
+
+ /**
* Whether the transition is enabled.
*/
_transition: {
@@ -202,13 +221,22 @@
tap: '_onTap',
track: '_onTrack',
down: '_downHandler',
- up: '_upHandler'
+ up: '_upHandler',
+ transitionend: '_onTransitionEnd'
},
observers: [
- '_forceNarrowChanged(forceNarrow, defaultSelected)'
+ '_forceNarrowChanged(forceNarrow, defaultSelected)',
+ '_toggleFocusListener(selected)'
],
+ ready: function() {
+ // Avoid transition at the beginning e.g. page loads and enable
+ // transitions only after the element is rendered and ready.
+ this._transition = true;
+ this._boundFocusListener = this._didFocus.bind(this);
+ },
+
/**
* Toggles the panel open and closed.
*
@@ -240,16 +268,19 @@
this.selected = 'main';
},
- ready: function() {
- // Avoid transition at the beginning e.g. page loads and enable
- // transitions only after the element is rendered and ready.
- this._transition = true;
- },
-
- _onMainTransitionEnd: function (e) {
- if (e.currentTarget === this.$.main && (e.propertyName === 'left' || e.propertyName === 'right')) {
+ _onTransitionEnd: function (e) {
+ var target = Polymer.dom(e).localTarget;
+ if (target !== this) {
+ // ignore events coming from the light dom
+ return;
+ }
+ if (e.propertyName === 'left' || e.propertyName === 'right') {
this.notifyResize();
}
+ if (e.propertyName === 'transform' && this.selected === 'drawer') {
+ var focusedChild = this._getAutoFocusedNode();
+ focusedChild && focusedChild.focus();
+ }
},
_computeIronSelectorClass: function(narrow, transition, dragging, rightDrawer, peeking) {
@@ -302,15 +333,12 @@
this._trackEnd(event);
break;
}
-
},
_responsiveChange: function(narrow) {
this._setNarrow(narrow);
- if (this.narrow) {
- this.selected = this.defaultSelected;
- }
+ this.selected = this.narrow ? this.defaultSelected : null;
this.setScrollDirection(this._swipeAllowed() ? 'y' : 'all');
this.fire('paper-responsive-change', {narrow: this.narrow});
@@ -446,14 +474,49 @@
if (translateX === null) {
return '';
}
-
return this.hasWillChange ? 'translateX(' + translateX + 'px)' :
'translate3d(' + translateX + 'px, 0, 0)';
},
_moveDrawer: function(translateX) {
this.transform(this._transformForTranslateX(translateX), this.$.drawer);
- }
+ },
+
+ _getDrawerContent: function() {
+ return Polymer.dom(this.$.drawerContent).getDistributedNodes()[0];
+ },
+
+ _getAutoFocusedNode: function() {
+ var drawerContent = this._getDrawerContent();
+ return Polymer.dom(drawerContent).querySelector(this.drawerFocusSelector) || drawerContent;
+ },
+
+ _toggleFocusListener: function(selected) {
+ if (selected === 'drawer') {
+ document.addEventListener('focus', this._boundFocusListener, true);
+ } else {
+ document.removeEventListener('focus', this._boundFocusListener, true);
+ }
+ },
+
+ _didFocus: function(event) {
+ var path = Polymer.dom(event).path;
+ var focusedChild = path[0];
+ var drawerContent = this._getDrawerContent();
+ var focusedChildCameFromDrawer = false;
+ var autoFocusedNode = this._getAutoFocusedNode();
+
+ while (!focusedChildCameFromDrawer && path[0] && path[0].hasAttribute) {
+ focusedChildCameFromDrawer = path.shift() === drawerContent;
+ }
+ if (!focusedChildCameFromDrawer && autoFocusedNode) {
+ autoFocusedNode.focus();
+ }
+ },
+ _isDrawerClosed: function(narrow, selected) {
+ return !narrow || selected !== 'drawer';
+ }
});
+
}());

Powered by Google App Engine
This is Rietveld 408576698