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

Side by Side Diff: chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js

Issue 2954273002: [MD Bookmarks] Restore focus after closing a dialog or context menu. (Closed)
Patch Set: fix deps Created 3 years, 5 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('bookmarks', function() { 5 cr.define('bookmarks', function() {
6 /** @const */
7 var MOUSE_FOCUS_CLASS = 'mouse-focus';
8
6 /** 9 /**
7 * Behavior which adds the 'mouse-focus' class to a target element when it 10 * 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 11 * gains focus from the mouse, allowing the outline to be hidden without
9 * affecting keyboard users. 12 * affecting keyboard users.
10 * @polymerBehavior 13 * @polymerBehavior
11 */ 14 */
12 var MouseFocusBehavior = { 15 var MouseFocusBehavior = {
13 attached: function() { 16 attached: function() {
14 this.boundOnMousedown_ = this.onMousedown_.bind(this); 17 this.boundOnMousedown_ = this.onMousedown_.bind(this);
15 this.boundClearMouseFocus_ = this.clearMouseFocus.bind(this); 18 this.boundClearMouseFocus_ = this.clearMouseFocus.bind(this);
16 19
17 var target = this.getFocusTarget(); 20 var target = this.getFocusTarget();
18 target.addEventListener('mousedown', this.boundOnMousedown_); 21 target.addEventListener('mousedown', this.boundOnMousedown_);
22 target.addEventListener('contextmenu', this.boundOnMousedown_);
19 target.addEventListener('blur', this.boundClearMouseFocus_); 23 target.addEventListener('blur', this.boundClearMouseFocus_);
20 }, 24 },
21 25
22 detached: function() { 26 detached: function() {
23 var target = this.getFocusTarget(); 27 var target = this.getFocusTarget();
24 target.removeEventListener('mousedown', this.boundOnMousedown_); 28 target.removeEventListener('mousedown', this.boundOnMousedown_);
29 target.removeEventListener('contextmenu', this.boundOnMousedown_);
25 target.removeEventListener('blur', this.boundClearMouseFocus_); 30 target.removeEventListener('blur', this.boundClearMouseFocus_);
26 }, 31 },
27 32
28 /** 33 /**
29 * Returns the element that should be watched for focus changes. Clients 34 * 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 35 * can override, but it is assumed that the return value is constant over
31 * the lifetime of the element. 36 * the lifetime of the element.
32 * @return {!HTMLElement} 37 * @return {!HTMLElement}
33 */ 38 */
34 getFocusTarget: function() { 39 getFocusTarget: function() {
35 return this; 40 return this;
36 }, 41 },
37 42
38 /** Reset the focus state when focus leaves the target element. */ 43 /** Reset the focus state when focus leaves the target element. */
39 clearMouseFocus: function() { 44 clearMouseFocus: function() {
40 this.getFocusTarget().classList.remove('mouse-focus'); 45 this.getFocusTarget().classList.remove(MOUSE_FOCUS_CLASS);
41 }, 46 },
42 47
43 /** @private */ 48 /** @private */
44 onMousedown_: function() { 49 onMousedown_: function() {
45 this.getFocusTarget().classList.add('mouse-focus'); 50 this.addMouseFocusClass(this.getFocusTarget());
51 },
52
53 /**
54 * @param {HTMLElement} element
55 * @return {boolean}
56 */
57 isMouseFocused: function(element) {
58 return element.classList.contains(MOUSE_FOCUS_CLASS);
59 },
60
61 /** @param {HTMLElement} element */
62 addMouseFocusClass: function(element) {
63 element.classList.add(MOUSE_FOCUS_CLASS);
46 }, 64 },
47 }; 65 };
48 66
49 return { 67 return {
50 MouseFocusBehavior: MouseFocusBehavior, 68 MouseFocusBehavior: MouseFocusBehavior,
51 }; 69 };
52 }); 70 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698