Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

New tab button can now show a dropdown #5696

Merged
merged 2 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion js/components/longPressButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ class LongPressButton extends ImmutableComponent {
if (e.target.attributes.getNamedItem('disabled')) {
return
}
if (e && e.preventDefault) {
e.preventDefault()
}
if (e && e.stopPropagation) {
e.stopPropagation()
}

const self = this
const target = e.target
const LONG_PRESS_MILLISECONDS = 300

// Right click should immediately trigger the action
if (e.button === 2) {
self.props.onLongPress(target)
return
}

// Otherwise, it should wait before triggering
this.longPressTimer = setTimeout(function () {
self.isLocked = true
self.props.onLongPress(target)
Expand All @@ -49,7 +62,9 @@ class LongPressButton extends ImmutableComponent {
this.isLocked = false
return
}
this.props.onClick(e)
if (this.props.onClick) {
this.props.onClick(e)
}
}

render () {
Expand Down
25 changes: 19 additions & 6 deletions js/components/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const windowActions = require('../actions/windowActions')
const windowStore = require('../stores/windowStore')
const dragTypes = require('../constants/dragTypes')
const cx = require('../lib/classSet')
const contextMenus = require('../contextMenus')

const Button = require('./button')
const LongPressButton = require('./longPressButton')
const Tab = require('./tab')
const dnd = require('../dnd')
const dndData = require('../dndData')
Expand All @@ -24,6 +25,8 @@ class Tabs extends ImmutableComponent {
this.onDrop = this.onDrop.bind(this)
this.onPrevPage = this.onPrevPage.bind(this)
this.onNextPage = this.onNextPage.bind(this)
this.onNewTabLongPress = this.onNewTabLongPress.bind(this)
this.wasNewTabClicked = this.wasNewTabClicked.bind(this)
}

onPrevPage () {
Expand Down Expand Up @@ -82,11 +85,15 @@ class Tabs extends ImmutableComponent {
e.preventDefault()
}
}

wasNewTabClicked (target) {
return target.className === this.refs.newTabButton.props.className
}
newTab () {
windowActions.newFrame()
}

onNewTabLongPress (target) {
contextMenus.onNewTabContextMenu(target)
}
render () {
this.tabRefs = []
const index = this.props.previewTabPageIndex !== undefined
Expand Down Expand Up @@ -125,10 +132,16 @@ class Tabs extends ImmutableComponent {
onClick={this.onNextPage} />
}
})()}
<Button label='+'

<LongPressButton
ref='newTabButton'
label='+'
l10nId='newTabButton'
className='navbutton newFrameButton'
onClick={this.newTab} />
className='browserButton navbutton newFrameButton'
disabled={false}
onClick={this.newTab}
onLongPress={this.onNewTabLongPress}
/>
</span>
</div>
}
Expand Down
8 changes: 7 additions & 1 deletion js/components/tabsToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class TabsToolbar extends ImmutableComponent {
}

onContextMenu (e) {
if (this.refs.tabs.wasNewTabClicked(e.target)) {
// Don't show the tabs menu if the new tab "+"" was clicked
return
}
contextMenus.onTabsToolbarContextMenu(windowStore.getFrame(this.props.activeFrameKey), undefined, undefined, e)
}

Expand All @@ -51,7 +55,9 @@ class TabsToolbar extends ImmutableComponent {
/>
: null
}
<Tabs tabs={unpinnedTabs}
<Tabs
ref='tabs'
tabs={unpinnedTabs}
shouldAllowWindowDrag={this.props.shouldAllowWindowDrag}
draggingOverData={this.props.draggingOverData}
paintTabs={this.props.paintTabs}
Expand Down
16 changes: 16 additions & 0 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,21 @@ function onTabContextMenu (frameProps, e) {
tabMenu.destroy()
}

function onNewTabContextMenu (target) {
const rect = target.getBoundingClientRect()
const menuTemplate = [
CommonMenu.newPrivateTabMenuItem(),
CommonMenu.newPartitionedTabMenuItem(),
CommonMenu.newWindowMenuItem()
]

windowActions.setContextMenuDetail(Immutable.fromJS({
left: rect.left,
top: rect.bottom + 2,
template: menuTemplate
}))
}

function onTabsToolbarContextMenu (activeFrame, closestDestinationDetail, isParent, e) {
e.stopPropagation()
const tabsToolbarMenu = Menu.buildFromTemplate(tabsToolbarTemplateInit(activeFrame, closestDestinationDetail, isParent))
Expand Down Expand Up @@ -1458,6 +1473,7 @@ module.exports = {
onHamburgerMenu,
onMainContextMenu,
onTabContextMenu,
onNewTabContextMenu,
onTabsToolbarContextMenu,
onDownloadsToolbarContextMenu,
onTabPageContextMenu,
Expand Down
3 changes: 0 additions & 3 deletions test/about/braveTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('about:brave tests', function () {
.waitUntil(function () {
return this.getText('table.sortableTable td[data-sort="Brave"]')
.then((textValue) => {
console.log(textValue)
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
})
})
Expand All @@ -33,7 +32,6 @@ describe('about:brave tests', function () {
.waitUntil(function () {
return this.getText('table.sortableTable td[data-sort="Muon"]')
.then((textValue) => {
console.log(textValue)
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
})
})
Expand All @@ -43,7 +41,6 @@ describe('about:brave tests', function () {
.waitUntil(function () {
return this.getText('table.sortableTable td[data-sort="Update Channel"]')
.then((textValue) => {
console.log(textValue)
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
})
})
Expand Down
31 changes: 28 additions & 3 deletions test/components/tabTest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global describe, it, before */
/* global describe, it, before, beforeEach */

const Brave = require('../lib/brave')
const messages = require('../../js/constants/messages')
const settings = require('../../js/constants/settings')
const {urlInput, backButton, forwardButton, activeTabTitle} = require('../lib/selectors')
const {urlInput, backButton, forwardButton, activeTabTitle, newFrameButton} = require('../lib/selectors')

describe('tabs', function () {
describe('tab tests', function () {
function * setup (client) {
yield client
.waitForUrl(Brave.newTabUrl)
Expand Down Expand Up @@ -73,6 +73,31 @@ describe('tabs', function () {
})
})

describe('new tab button', function () {
Brave.beforeEach(this)
beforeEach(function * () {
yield setup(this.app.client)
})

it('creates a new tab when clicked', function * () {
yield this.app.client
.click(newFrameButton)
.waitForExist('.tab[data-frame-key="2"]')
})
it('shows a context menu when long pressed (click and hold)', function * () {
yield this.app.client
.moveToObject(newFrameButton)
.buttonDown(0)
.waitForExist('.contextMenu .contextMenuItem .contextMenuItemText')
.buttonUp(0)
})
it('shows a context menu when right clicked', function * () {
yield this.app.client
.rightClick(newFrameButton)
.waitForExist('.contextMenu .contextMenuItem .contextMenuItemText')
})
})

describe('tab order', function () {
describe('sequentially by default', function () {
Brave.beforeAll(this)
Expand Down