Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
calamity
2017/06/08 03:34:19
7
tsergeant
2017/06/08 05:03:40
ooooops
| |
| 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_, 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
| |
| 20 }, | |
| 21 | |
| 22 detached: function() { | |
| 23 var target = this.getFocusTarget(); | |
| 24 target.removeEventListener('mousedown', this.boundOnMousedown_); | |
| 25 target.removeEventListener('blur', this.boundClearMouseFocus_, true); | |
| 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 }); | |
| OLD | NEW |