@@ -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,46 @@ 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
+ // Matches tab_, tabArea, tabTitle, tabId, closeTab and
175
+ // all tab icons such as favicon, private and new session
176
+ const tabComponents = / t a b (? = _ | a r e a | t i t l e | i d ) | c l o s e t a b | i c o n / i
177
+ const tabAsRelatedTarget = tabComponents . test ( e . relatedTarget . classList )
178
+
179
+ // We are taking for granted that user hovering over another tab
180
+ // means that he wants to sequentially preview a set of tabs,
181
+ // so if previewMode was set by defined mouse idle time,
182
+ // only cancel previewMode if the next event doesn't happen in another tab.
183
+ if ( ! tabAsRelatedTarget ) {
184
+ windowActions . setPreviewFrame ( null )
185
+ windowActions . setPreviewMode ( false )
186
+ }
170
187
}
171
- windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , false )
172
188
}
173
189
174
190
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 )
191
+ windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
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
+ this . mouseTimeout = null
194
+ if ( this . props . previewTabs && this . props . previewMode ) {
195
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
196
+ }
197
+ }
198
+
199
+ onMouseMove ( e ) {
200
+ // previewMode is only triggered if mouse is idle over a tab
201
+ // for a given amount of time based on timing defined in prefs->tabs
182
202
if ( this . props . previewTabs ) {
183
- this . hoverTimeout =
184
- window . setTimeout ( windowActions . setPreviewFrame . bind ( null , this . props . frame . get ( 'key' ) ) , previewMode ? 0 : 200 )
203
+ clearTimeout ( this . mouseTimeout )
204
+ this . mouseTimeout = setTimeout ( ( ) => {
205
+ windowActions . setPreviewFrame ( this . props . frame . get ( 'key' ) )
206
+ windowActions . setPreviewMode ( true )
207
+ } , getSetting ( settings . TAB_PREVIEW_TIMING ) )
185
208
}
186
- windowActions . setTabHoverState ( this . props . frame . get ( 'key' ) , true )
187
209
}
188
210
189
211
onAuxClick ( e ) {
@@ -288,6 +310,7 @@ class Tab extends ImmutableComponent {
288
310
partOfFullPageSet : this . props . partOfFullPageSet || ! ! this . props . tabWidth
289
311
} ) }
290
312
style = { this . props . tabWidth ? { flex : `0 0 ${ this . props . tabWidth } px` } : { } }
313
+ onMouseMove = { this . onMouseMove }
291
314
onMouseEnter = { this . onMouseEnter }
292
315
onMouseLeave = { this . onMouseLeave } >
293
316
{
@@ -369,8 +392,6 @@ class Tab extends ImmutableComponent {
369
392
}
370
393
371
394
const paymentsEnabled = ( ) => {
372
- const getSetting = require ( '../../../../js/settings' ) . getSetting
373
- const settings = require ( '../../../../js/constants/settings' )
374
395
return getSetting ( settings . PAYMENTS_ENABLED )
375
396
}
376
397
0 commit comments