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

Unified Diff: chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js

Issue 2920413002: MD Bookmarks: Focus sidebar nodes on click without showing an outline (Closed)
Patch Set: Fix override comment Created 3 years, 6 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: chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js
diff --git a/chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js b/chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js
new file mode 100644
index 0000000000000000000000000000000000000000..2aec0e9ddf13e1ffef1730eaa0f5d609c4a88cb5
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js
@@ -0,0 +1,52 @@
+// 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('bookmarks', function() {
+ /**
+ * Behavior which adds the 'mouse-focus' class to a target element when it
+ * gains focus from the mouse, allowing the outline to be hidden without
+ * affecting keyboard users.
+ * @polymerBehavior
+ */
+ var MouseFocusBehavior = {
+ attached: function() {
+ this.boundOnMousedown_ = this.onMousedown_.bind(this);
+ this.boundClearMouseFocus_ = this.clearMouseFocus.bind(this);
+
+ var target = this.getFocusTarget();
+ target.addEventListener('mousedown', this.boundOnMousedown_);
+ target.addEventListener('blur', this.boundClearMouseFocus_);
+ },
+
+ detached: function() {
+ var target = this.getFocusTarget();
+ target.removeEventListener('mousedown', this.boundOnMousedown_);
+ target.removeEventListener('blur', this.boundClearMouseFocus_);
+ },
+
+ /**
+ * Returns the element that should be watched for focus changes. Clients
+ * can override, but it is assumed that the return value is constant over
+ * the lifetime of the element.
+ * @return {!HTMLElement}
+ */
+ getFocusTarget: function() {
+ return this;
+ },
+
+ /** Reset the focus state when focus leaves the target element. */
+ clearMouseFocus: function() {
+ this.getFocusTarget().classList.remove('mouse-focus');
+ },
+
+ /** @private */
+ onMousedown_: function() {
+ this.getFocusTarget().classList.add('mouse-focus');
+ },
+ };
+
+ return {
+ MouseFocusBehavior: MouseFocusBehavior,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698