From a90027f7f10cb612599a2bc12b4b6f5a5c962bb8 Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Tue, 21 Mar 2017 04:21:44 -0300 Subject: [PATCH] Adjust min-threshold for closeTab Auditors: @bbondy, @bsclifton Fix #5431 --- app/renderer/components/styles/global.js | 2 +- app/renderer/components/tabContent.js | 40 +++++++----------- app/renderer/lib/tabUtil.js | 30 ++++++++++++++ js/components/tab.js | 8 +++- test/unit/app/renderer/tabContentTest.js | 52 +++++++++++++++++++++++- 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/app/renderer/components/styles/global.js b/app/renderer/components/styles/global.js index 1e942a3f25a..9fea2f140c0 100644 --- a/app/renderer/components/styles/global.js +++ b/app/renderer/components/styles/global.js @@ -11,7 +11,7 @@ const globalStyles = { medium: '66px', mediumSmall: '53px', small: '46px', - extraSmall: '33px', + extraSmall: '40px', smallest: '19px' } }, diff --git a/app/renderer/components/tabContent.js b/app/renderer/components/tabContent.js index cd67f5bbd6f..2a8e059edd9 100644 --- a/app/renderer/components/tabContent.js +++ b/app/renderer/components/tabContent.js @@ -9,6 +9,7 @@ const globalStyles = require('./styles/global') const {isWindows} = require('../../common/lib/platformUtil') const {getTextColorForBackground} = require('../../../js/lib/color') const {tabs} = require('../../../js/constants/config') +const {hasBreakpoint, hasRelativeCloseIcon, hasFixedCloseIcon} = require('../lib/tabUtil') const newSessionSvg = require('../../extensions/brave/img/tabs/new_session.svg') @@ -69,11 +70,16 @@ class Favicon extends ImmutableComponent { return this.props.tab.get('breakpoint') === 'smallest' } + get shouldHideFavicon () { + return (hasBreakpoint(this.props, 'extraSmall') && this.props.isActive) || + this.props.tab.get('location') === 'about:newtab' + } + render () { const iconStyles = StyleSheet.create({ favicon: {backgroundImage: `url(${this.favicon})`} }) - return this.props.tab.get('location') !== 'about:newtab' + return !this.shouldHideFavicon ? @@ -252,13 +246,9 @@ class CloseTabIcon extends ImmutableComponent { return !!this.props.tab.get('pinnedLocation') } - get narrowView () { - const sizes = ['extraSmall', 'smallest'] - return sizes.includes(this.props.tab.get('breakpoint')) - } - render () { - return this.props.tab.get('hoverState') && !this.narrowView && !this.isPinned + return !this.isPinned && + (hasRelativeCloseIcon(this.props) || hasFixedCloseIcon(this.props)) ? { // Execute resize handler at a rate of 15fps module.exports.tabUpdateFrameRate = 66 + +/** + * Check whether or not current breakpoint match defined criteria + * @param {Object} props - Object that hosts the tab breakpoint + * @param {Array} arr - Array of Strings including breakpoint names to check against + * @returns {Boolean} Whether or not the sizing criteria was match + */ +module.exports.hasBreakpoint = (props, arr) => { + arr = Array.isArray(arr) ? arr : [arr] + return arr.includes(props.tab.get('breakpoint')) +} + +/** + * Check whether or not closeTab icon is relative to hover state + * @param {Object} props - Object that hosts the tab props + * @returns {Boolean} Whether or not the tab has a relative closeTab icon + */ +module.exports.hasRelativeCloseIcon = (props) => { + return props.tab.get('hoverState') && + !module.exports.hasBreakpoint(props, ['small', 'extraSmall', 'smallest']) +} + +/** + * Check whether or not closeTab icon is always visible (fixed) in tab + * @param {Object} props - Object that hosts the tab props + * @returns {Boolean} Whether or not the close icon is always visible (fixed) + */ +module.exports.hasFixedCloseIcon = (props) => { + return props.isActive && module.exports.hasBreakpoint(props, ['small', 'extraSmall']) +} diff --git a/js/components/tab.js b/js/components/tab.js index 8bbe30886b4..d6cb2c72857 100644 --- a/js/components/tab.js +++ b/js/components/tab.js @@ -289,7 +289,12 @@ class Tab extends ImmutableComponent { this.narrowView && styles.tabIdNarrowView, this.props.tab.get('breakpoint') === 'smallest' && styles.tabIdMinAllowedSize )}> - + ) assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.closeTab) }) - it('should not show closeTab icon if tab size is too small', function () { + it('should show closeTab icon if tab size is small and tab is active', function () { + const wrapper = shallow( + + ) + assert.equal(wrapper.props().symbol, globalStyles.appIcons.closeTab) + }) + it('should not show closeTab icon if tab size is small and tab is not active', function () { + const wrapper = shallow( + + ) + assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.closeTab) + }) + it('should show closeTab icon if tab size is extraSmall and tab is active', function () { + const wrapper = shallow( + + ) + assert.equal(wrapper.props().symbol, globalStyles.appIcons.closeTab) + }) + it('should not show closeTab icon if tab size is extraSmall and tab is not active', function () { + const wrapper = shallow( + + ) + assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.closeTab) + }) + it('should not show closeTab icon if tab size is the smallest size', function () { const wrapper = shallow(