Index: ui/webui/resources/js/cr/ui/focus_without_ink.js |
diff --git a/ui/webui/resources/js/cr/ui/focus_without_ink.js b/ui/webui/resources/js/cr/ui/focus_without_ink.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..90ed1012f4f37d713e6736b5c308ad9a1dc8ba8e |
--- /dev/null |
+++ b/ui/webui/resources/js/cr/ui/focus_without_ink.js |
@@ -0,0 +1,46 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+cr.define('cr.ui', function() { |
+ if (cr.ui.focusWithoutInk) |
+ return; |
+ |
+ var hideInk = false; |
+ |
+ assert(!cr.isIOS, 'pointerdown doesn\'t work on iOS'); |
+ |
+ document.addEventListener('pointerdown', function() { |
+ hideInk = true; |
+ }, true); |
+ |
+ document.addEventListener('keydown', function() { |
+ hideInk = false; |
+ }, true); |
+ |
+ /** |
+ * Attempts to track whether focus outlines should be shown, and if they |
+ * shouldn't, removes the "ink" (ripple) from a control while focusing it. |
+ * This is helpful when a user is clicking/touching, because it's not super |
+ * helpful to show focus ripples in that case. This is Polymer-specific. |
+ * @param {!Element} toFocus |
+ */ |
+ var focusWithoutInk = function(toFocus) { |
+ assert('noink' in toFocus); |
+ assert(document == toFocus.ownerDocument); |
+ |
+ var origNoInk; |
+ |
+ if (hideInk) { |
+ origNoInk = toFocus.noink; |
+ toFocus.noink = true; |
+ } |
+ |
+ toFocus.focus(); |
+ |
+ if (hideInk) |
+ toFocus.noink = origNoInk; |
+ }; |
+ |
+ return {focusWithoutInk: focusWithoutInk}; |
+}); |