@@ -26,6 +26,7 @@ const windowStore = require('../../../../js/stores/windowStore')
26
26
// Constants
27
27
const dragTypes = require ( '../../../../js/constants/dragTypes' )
28
28
const messages = require ( '../../../../js/constants/messages' )
29
+ const settings = require ( '../../../../js/constants/settings' )
29
30
30
31
// Styles
31
32
const styles = require ( '../styles/tab' )
@@ -42,10 +43,12 @@ const {getTabBreakpoint, tabUpdateFrameRate} = require('../../lib/tabUtil')
42
43
const { isWindows} = require ( '../../../common/lib/platformUtil' )
43
44
const { getCurrentWindowId} = require ( '../../currentWindow' )
44
45
const UrlUtil = require ( '../../../../js/lib/urlutil' )
46
+ const getSetting = require ( '../../../../js/settings' ) . getSetting
45
47
46
48
class Tab extends ImmutableComponent {
47
49
constructor ( ) {
48
50
super ( )
51
+ this . onMouseMove = this . onMouseMove . bind ( this )
49
52
this . onMouseEnter = this . onMouseEnter . bind ( this )
50
53
this . onMouseLeave = this . onMouseLeave . bind ( this )
51
54
this . onUpdateTabSize = this . onUpdateTabSize . bind ( this )
@@ -163,27 +166,40 @@ class Tab extends ImmutableComponent {
163
166
! this . props . frame . get ( 'provisionalLocation' ) . startsWith ( 'chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/' ) )
164
167
}
165
168
166
- onMouseLeave ( ) {
167
- if ( this . props . previewTabs ) {
168
- window . clearTimeout ( this . hoverTimeout )
169
+ onMouseLeave ( e ) {
170
+ clearTimeout ( this . mouseTimeout )
171
+ const tabAsRelatedTarget = / ^ t a b _ / i. test ( e . relatedTarget . classList )
172
+
173
+ // We are taking for granted that user hovering over
174
+ // another tab means that he wants to sequentially
175
+ // preview a set of tabs, so if previewMode was
176
+ // set by defined mouse idle time, only cancel previewMode
177
+ // if the next event doesn't happen in another tab.
178
+ if ( this . props . previewTabs && ! tabAsRelatedTarget ) {
169
179
windowActions . setPreviewFrame ( null )
180
+ windowActions . setPreviewMode ( false )
170
181
}
171
182
windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , false )
172
183
}
173
184
174
185
onMouseEnter ( e ) {
175
- // relatedTarget inside mouseenter checks which element before this event was the pointer on
176
- // if this element has a tab-like class, then it's likely that the user was previewing
177
- // a sequency of tabs. Called here as previewMode.
178
- const previewMode = / t a b (? ! p a g e s ) / i. test ( e . relatedTarget . classList )
186
+ this . mouseTimeout = null
187
+ if ( this . props . previewMode ) {
188
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
189
+ }
190
+ windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
191
+ }
179
192
180
- // If user isn't in previewMode, we add a bit of delay to avoid tab from flashing out
181
- // as reported here: https://github.com/brave/browser-laptop/issues/1434
193
+ onMouseMove ( e ) {
194
+ // previewMode is only triggered if mouse is idle
195
+ // over a tab based on timing defined in prefs->tabs
182
196
if ( this . props . previewTabs ) {
183
- this . hoverTimeout =
184
- window . setTimeout ( windowActions . setPreviewFrame . bind ( null , this . props . frame . get ( 'key' ) ) , previewMode ? 0 : 200 )
197
+ clearTimeout ( this . mouseTimeout )
198
+ this . mouseTimeout = setTimeout ( ( ) => {
199
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
200
+ windowActions . setPreviewMode ( true )
201
+ } , getSetting ( settings . TAB_PREVIEW_TIMING ) )
185
202
}
186
- windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
187
203
}
188
204
189
205
onAuxClick ( e ) {
@@ -288,6 +304,7 @@ class Tab extends ImmutableComponent {
288
304
partOfFullPageSet : this . props . partOfFullPageSet || ! ! this . props . tabWidth
289
305
} ) }
290
306
style = { this . props . tabWidth ? { flex : `0 0 ${ this . props . tabWidth } px` } : { } }
307
+ onMouseMove = { this . onMouseMove }
291
308
onMouseEnter = { this . onMouseEnter }
292
309
onMouseLeave = { this . onMouseLeave } >
293
310
{
@@ -369,8 +386,6 @@ class Tab extends ImmutableComponent {
369
386
}
370
387
371
388
const paymentsEnabled = ( ) => {
372
- const getSetting = require ( '../../../../js/settings' ) . getSetting
373
- const settings = require ( '../../../../js/constants/settings' )
374
389
return getSetting ( settings . PAYMENTS_ENABLED )
375
390
}
376
391
0 commit comments