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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('bookmarks', function() {
6 /**
7 * Behavior which adds the 'mouse-focus' class to a target element when it
8 * gains focus from the mouse, allowing the outline to be hidden without
9 * affecting keyboard users.
10 * @polymerBehavior
11 */
12 var MouseFocusBehavior = {
13 attached: function() {
14 this.boundOnMousedown_ = this.onMousedown_.bind(this);
15 this.boundClearMouseFocus_ = this.clearMouseFocus.bind(this);
16
17 var target = this.getFocusTarget();
18 target.addEventListener('mousedown', this.boundOnMousedown_);
19 target.addEventListener('blur', this.boundClearMouseFocus_);
20 },
21
22 detached: function() {
23 var target = this.getFocusTarget();
24 target.removeEventListener('mousedown', this.boundOnMousedown_);
25 target.removeEventListener('blur', this.boundClearMouseFocus_);
26 },
27
28 /**
29 * Returns the element that should be watched for focus changes. Clients
30 * can override, but it is assumed that the return value is constant over
31 * the lifetime of the element.
32 * @return {!HTMLElement}
33 */
34 getFocusTarget: function() {
35 return this;
36 },
37
38 /** Reset the focus state when focus leaves the target element. */
39 clearMouseFocus: function() {
40 this.getFocusTarget().classList.remove('mouse-focus');
41 },
42
43 /** @private */
44 onMousedown_: function() {
45 this.getFocusTarget().classList.add('mouse-focus');
46 },
47 };
48
49 return {
50 MouseFocusBehavior: MouseFocusBehavior,
51 };
52 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698