3
3
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
5
const React = require ( 'react' )
6
- const { StyleSheet, css} = require ( 'aphrodite' )
6
+ const { StyleSheet, css} = require ( 'aphrodite/no-important ' )
7
7
const Immutable = require ( 'immutable' )
8
8
9
9
// Components
@@ -23,7 +23,8 @@ const windowActions = require('../../../../js/actions/windowActions')
23
23
// Store
24
24
const windowStore = require ( '../../../../js/stores/windowStore' )
25
25
26
- // State
26
+ // State helpers
27
+ const privateState = require ( '../../../common/state/tabContentState/privateState' )
27
28
const audioState = require ( '../../../common/state/tabContentState/audioState' )
28
29
const tabUIState = require ( '../../../common/state/tabUIState' )
29
30
const tabState = require ( '../../../common/state/tabState' )
@@ -33,6 +34,7 @@ const dragTypes = require('../../../../js/constants/dragTypes')
33
34
34
35
// Styles
35
36
const globalStyles = require ( '../styles/global' )
37
+ const { theme} = require ( '../styles/theme' )
36
38
37
39
// Utils
38
40
const cx = require ( '../../../../js/lib/classSet' )
@@ -200,10 +202,10 @@ class Tab extends React.Component {
200
202
this . tabNode . addEventListener ( 'auxclick' , this . onAuxClick . bind ( this ) )
201
203
}
202
204
203
- componentDidUpdate ( ) {
205
+ componentDidUpdate ( prevProps ) {
204
206
// if a tab was just pinned, unobserve its intersection
205
207
// this gives us some more performance boost
206
- if ( this . props . isPinnedTab ) {
208
+ if ( prevProps . isPinnedTab !== this . props . isPinnedTab ) {
207
209
this . observer . unobserve ( this . tabSentinel )
208
210
}
209
211
}
@@ -234,24 +236,33 @@ class Tab extends React.Component {
234
236
mergeProps ( state , ownProps ) {
235
237
const currentWindow = state . get ( 'currentWindow' )
236
238
const frame = frameStateUtil . getFrameByKey ( currentWindow , ownProps . frameKey ) || Immutable . Map ( )
239
+ const frameKey = ownProps . frameKey
240
+ const tabId = frame . get ( 'tabId' , tabState . TAB_ID_NONE )
241
+ const isPinned = tabState . isTabPinned ( state , tabId )
242
+
243
+ // TODO: this should have its own method
237
244
const notifications = state . get ( 'notifications' )
238
245
const notificationOrigins = notifications ? notifications . map ( bar => bar . get ( 'frameOrigin' ) ) : false
239
246
const notificationBarActive = frame . get ( 'location' ) && notificationOrigins &&
240
247
notificationOrigins . includes ( UrlUtil . getUrlOrigin ( frame . get ( 'location' ) ) )
241
- const tabId = frame . get ( 'tabId' , tabState . TAB_ID_NONE )
242
248
243
249
const props = { }
244
250
// used in renderer
245
251
props . frameKey = ownProps . frameKey
246
252
props . isPrivateTab = frame . get ( 'isPrivate' )
247
253
props . notificationBarActive = notificationBarActive
254
+
255
+ // used in renderer
256
+ props . frameKey = frameKey
257
+ props . isPinnedTab = isPinned
258
+ props . isPrivateTab = privateState . isPrivateTab ( currentWindow , frameKey )
248
259
props . isActive = frameStateUtil . isFrameKeyActive ( currentWindow , props . frameKey )
249
260
props . tabWidth = currentWindow . getIn ( [ 'ui' , 'tabs' , 'fixTabWidth' ] )
250
- props . isPinnedTab = tabState . isTabPinned ( state , tabId )
251
- props . canPlayAudio = audioState . canPlayAudio ( currentWindow , props . frameKey )
252
- props . themeColor = tabUIState . getThemeColor ( currentWindow , props . frameKey )
261
+ props . themeColor = tabUIState . getThemeColor ( currentWindow , frameKey )
253
262
props . title = frame . get ( 'title' )
254
263
props . partOfFullPageSet = ownProps . partOfFullPageSet
264
+ props . showAudioTopBorder = audioState . showAudioTopBorder ( currentWindow , frameKey , isPinned )
265
+ props . centralizeTabIcons = tabUIState . centralizeTabIcons ( currentWindow , frameKey , isPinned )
255
266
256
267
// used in other functions
257
268
props . totalTabs = state . get ( 'tabs' ) . size
@@ -265,7 +276,7 @@ class Tab extends React.Component {
265
276
render ( ) {
266
277
// we don't want themeColor if tab is private
267
278
const perPageStyles = ! this . props . isPrivateTab && StyleSheet . create ( {
268
- themeColor : {
279
+ tab_themeColor : {
269
280
color : this . props . themeColor ? getTextColorForBackground ( this . props . themeColor ) : 'inherit' ,
270
281
background : this . props . themeColor ? this . props . themeColor : 'inherit' ,
271
282
':hover' : {
@@ -301,13 +312,15 @@ class Tab extends React.Component {
301
312
className = { css (
302
313
styles . tab ,
303
314
// Windows specific style
304
- isWindows && styles . tabForWindows ,
305
- this . props . isPinnedTab && styles . isPinned ,
306
- this . props . isActive && styles . active ,
307
- this . props . isActive && this . props . themeColor && perPageStyles . themeColor ,
315
+ isWindows && styles . tab_forWindows ,
316
+ this . props . isPinnedTab && styles . tab_pinned ,
317
+ this . props . isActive && styles . tab_active ,
318
+ this . props . showAudioTopBorder && styles . tab_audioTopBorder ,
319
+ this . props . isActive && this . props . themeColor && perPageStyles . tab_themeColor ,
308
320
// Private color should override themeColor
309
- this . props . isPrivateTab && styles . private ,
310
- this . props . isActive && this . props . isPrivateTab && styles . activePrivateTab
321
+ this . props . isPrivateTab && styles . tab_private ,
322
+ this . props . isActive && this . props . isPrivateTab && styles . tab_active_private ,
323
+ this . props . centralizeTabIcons && styles . tab__content_centered
311
324
) }
312
325
data-test-id = 'tab'
313
326
data-frame-key = { this . props . frameKey }
@@ -323,7 +336,10 @@ class Tab extends React.Component {
323
336
ref = { ( node ) => { this . tabSentinel = node } }
324
337
className = { css ( styles . tab__sentinel ) }
325
338
/>
326
- < div className = { css ( styles . tabId ) } >
339
+ < div className = { css (
340
+ styles . tab__identity ,
341
+ this . props . centralizeTabIcons && styles . tab__content_centered
342
+ ) } >
327
343
< Favicon tabId = { this . props . tabId } />
328
344
< AudioTabIcon tabId = { this . props . tabId } />
329
345
< TabTitle tabId = { this . props . tabId } />
@@ -337,34 +353,39 @@ class Tab extends React.Component {
337
353
}
338
354
339
355
const styles = StyleSheet . create ( {
340
- // Windows specific style
341
- tabForWindows : {
342
- color : '#555'
343
- } ,
344
-
345
356
tab : {
346
357
borderWidth : '0 1px 0 0' ,
347
358
borderStyle : 'solid' ,
348
359
borderColor : '#bbb' ,
349
360
boxSizing : 'border-box' ,
350
- color : '#5a5a5a' ,
361
+ color : theme . tab . color ,
351
362
display : 'flex' ,
352
363
marginTop : '0' ,
353
- transition : `transform 200ms ease, ${ globalStyles . transition . tabBackgroundTransition } ` ,
364
+ transition : theme . tab . transition ,
354
365
left : '0' ,
355
366
opacity : '1' ,
356
- width : '100%' ,
367
+ height : '-webkit-fill-available' ,
368
+ width : '-webkit-fill-available' ,
357
369
alignItems : 'center' ,
358
370
justifyContent : 'space-between' ,
359
- padding : globalStyles . spacing . defaultTabPadding ,
371
+ padding : 0 ,
360
372
position : 'relative' ,
361
373
362
- // globalStyles.spacing.tabHeight has been set to globalStyles.spacing.tabsToolbarHeight,
363
- // which is 1px extra due to the border-top of .tabsToolbar
364
- height : '-webkit-fill-available' ,
374
+ ':hover' : {
375
+ background : theme . tab . hover . background
376
+ }
377
+ } ,
378
+
379
+ // Windows specific style
380
+ tab_forWindows : {
381
+ color : theme . tab . forWindows . color
382
+ } ,
383
+
384
+ tab_active : {
385
+ background : theme . tab . active . background ,
365
386
366
387
':hover' : {
367
- background : 'linear-gradient(to bottom, rgba(255, 255, 255, 0.8), rgba(250, 250, 250, 0.4))'
388
+ background : theme . tab . active . background
368
389
}
369
390
} ,
370
391
@@ -380,59 +401,56 @@ const styles = StyleSheet.create({
380
401
width : globalStyles . spacing . sentinelSize
381
402
} ,
382
403
383
- tabId : {
384
- justifyContent : 'center' ,
404
+ tab_audioTopBorder : {
405
+ '::before' : {
406
+ content : `''` ,
407
+ display : 'block' ,
408
+ position : 'absolute' ,
409
+ top : 0 ,
410
+ left : 0 ,
411
+ right : 0 ,
412
+ height : '2px' ,
413
+ background : 'lightskyblue'
414
+ }
415
+ } ,
416
+
417
+ tab__identity : {
418
+ justifyContent : 'flex-start' ,
385
419
alignItems : 'center' ,
386
420
display : 'flex' ,
387
421
flex : '1' ,
388
-
389
- // @see https://bugzilla.mozilla.org/show_bug.cgi?id=1108514#c5
390
- minWidth : '0' ,
391
-
392
- // prevent the icons wrapper from being the target of mouse events.
393
- pointerEvents : 'none'
422
+ minWidth : '0' , // @see https://bugzilla.mozilla.org/show_bug.cgi?id=1108514#c5
423
+ marginLeft : globalStyles . spacing . defaultTabMargin
394
424
} ,
395
425
396
- isPinned : {
426
+ tab__content_centered : {
427
+ justifyContent : 'center' ,
428
+ flex : 'auto' ,
397
429
padding : 0 ,
398
- width : `calc(${ globalStyles . spacing . tabsToolbarHeight } * 1.1)` ,
399
- justifyContent : 'center'
430
+ margin : 0
400
431
} ,
401
432
402
- active : {
403
- background : `rgba(255, 255, 255, 1.0)` ,
404
- marginTop : '0' ,
405
- borderWidth : '0 1px 0 0' ,
406
- borderStyle : 'solid' ,
407
- borderColor : '#bbb' ,
408
- color : '#000' ,
409
-
410
- ':hover' : {
411
- background : `linear-gradient(to bottom, #fff, ${ globalStyles . color . chromePrimary } )`
412
- }
433
+ tab_pinned : {
434
+ padding : 0 ,
435
+ width : '28px' ,
436
+ justifyContent : 'center'
413
437
} ,
414
438
415
- activePrivateTab : {
416
- background : globalStyles . color . privateTabBackgroundActive ,
439
+ tab_active_private : {
440
+ background : theme . tab . active . private . background ,
441
+ color : theme . tab . active . private . color ,
417
442
418
443
':hover' : {
419
- background : globalStyles . color . privateTabBackgroundActive
444
+ background : theme . tab . active . private . background
420
445
}
421
446
} ,
422
447
423
- private : {
424
- background : 'rgba(75, 60, 110, 0.2)' ,
448
+ tab_private : {
449
+ background : theme . tab . private . background ,
425
450
426
451
':hover' : {
427
- background : globalStyles . color . privateTabBackgroundActive
428
- }
429
- } ,
430
-
431
- dragging : {
432
- ':hover' : {
433
- closeTab : {
434
- opacity : '0'
435
- }
452
+ color : theme . tab . active . private . color ,
453
+ background : theme . tab . active . private . background
436
454
}
437
455
}
438
456
} )
0 commit comments