blob: bd996760bbfeb22486eda6e46ae773e0594a6003 [file] [log] [blame]
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<script>
(function(window) {
'use strict';
// Must be declared outside behavior implementation to be accessed inside
// behavior functions.
/** @return {!Object} */
const getKeyboardEvent = function(e) {
e = Polymer.dom(e.detail ? e.detail.keyboardEvent : e);
// When e is a keyboardEvent, e.event is not null.
if (e.event) { e = e.event; }
return e;
};
window.Gerrit = window.Gerrit || {};
/** @polymerBehavior KeyboardShortcutBehavior */
Gerrit.KeyboardShortcutBehavior = [{
modifierPressed(e) {
e = getKeyboardEvent(e);
return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
},
isModifierPressed(e, modifier) {
return getKeyboardEvent(e)[modifier];
},
shouldSuppressKeyboardShortcut(e) {
e = getKeyboardEvent(e);
const tagName = Polymer.dom(e).rootTarget.tagName;
if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
return true;
}
for (let i = 0; e.path && i < e.path.length; i++) {
if (e.path[i].tagName === 'GR-OVERLAY') { return true; }
}
return false;
},
// Alias for getKeyboardEvent.
/** @return {!Object} */
getKeyboardEvent(e) {
return getKeyboardEvent(e);
},
getRootTarget(e) {
return Polymer.dom(getKeyboardEvent(e)).rootTarget;
},
},
Polymer.IronA11yKeysBehavior,
];
})(window);
</script>