Chromium Code Reviews| 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..828ae879aaaefa9311d1ad6d2c578c9d618a1449 |
| --- /dev/null |
| +++ b/chrome/browser/resources/md_bookmarks/mouse_focus_behavior.js |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
calamity
2017/06/08 03:34:19
7
tsergeant
2017/06/08 05:03:40
ooooops
|
| +// 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_, true); |
|
calamity
2017/06/08 03:34:19
Why is capture true here?
tsergeant
2017/06/08 05:03:40
Ah, this was leftover from experimenting with tryi
|
| + }, |
| + |
| + detached: function() { |
| + var target = this.getFocusTarget(); |
| + target.removeEventListener('mousedown', this.boundOnMousedown_); |
| + target.removeEventListener('blur', this.boundClearMouseFocus_, true); |
| + }, |
| + |
| + /** |
| + * 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, |
| + }; |
| +}); |