@@ -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,43 @@ class Tab extends ImmutableComponent {
163
166
! this . props . frame . get ( 'provisionalLocation' ) . startsWith ( 'chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/' ) )
164
167
}
165
168
166
- onMouseLeave ( ) {
169
+ onMouseLeave ( e ) {
170
+ windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , false )
171
+
167
172
if ( this . props . previewTabs ) {
168
- window . clearTimeout ( this . hoverTimeout )
169
- windowActions . setPreviewFrame ( null )
173
+ clearTimeout ( this . mouseTimeout )
174
+ const tabAsRelatedTarget = / ^ t a b _ / i. test ( e . relatedTarget . classList )
175
+
176
+ // We are taking for granted that user hovering over another tab
177
+ // means that he wants to sequentially preview a set of tabs,
178
+ // so if previewMode was set by defined mouse idle time,
179
+ // only cancel previewMode if the next event doesn't happen in another tab.
180
+ if ( ! tabAsRelatedTarget ) {
181
+ windowActions . setPreviewFrame ( null )
182
+ windowActions . setPreviewMode ( false )
183
+ }
170
184
}
171
- windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , false )
172
185
}
173
186
174
187
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 )
188
+ windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
179
189
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
190
+ this . mouseTimeout = null
191
+ if ( this . props . previewTabs && this . props . previewMode ) {
192
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
193
+ }
194
+ }
195
+
196
+ onMouseMove ( e ) {
197
+ // previewMode is only triggered if mouse is idle over a tab
198
+ // for a given amount of time based on timing defined in prefs->tabs
182
199
if ( this . props . previewTabs ) {
183
- this . hoverTimeout =
184
- window . setTimeout ( windowActions . setPreviewFrame . bind ( null , this . props . frame . get ( 'key' ) ) , previewMode ? 0 : 200 )
200
+ clearTimeout ( this . mouseTimeout )
201
+ this . mouseTimeout = setTimeout ( ( ) => {
202
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
203
+ windowActions . setPreviewMode ( true )
204
+ } , getSetting ( settings . TAB_PREVIEW_TIMING ) )
185
205
}
186
- windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
187
206
}
188
207
189
208
onAuxClick ( e ) {
@@ -288,6 +307,7 @@ class Tab extends ImmutableComponent {
288
307
partOfFullPageSet : this . props . partOfFullPageSet || ! ! this . props . tabWidth
289
308
} ) }
290
309
style = { this . props . tabWidth ? { flex : `0 0 ${ this . props . tabWidth } px` } : { } }
310
+ onMouseMove = { this . onMouseMove }
291
311
onMouseEnter = { this . onMouseEnter }
292
312
onMouseLeave = { this . onMouseLeave } >
293
313
{
@@ -369,8 +389,6 @@ class Tab extends ImmutableComponent {
369
389
}
370
390
371
391
const paymentsEnabled = ( ) => {
372
- const getSetting = require ( '../../../../js/settings' ) . getSetting
373
- const settings = require ( '../../../../js/constants/settings' )
374
392
return getSetting ( settings . PAYMENTS_ENABLED )
375
393
}
376
394
0 commit comments