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

Commit 76c3165

Browse files
authored
Merge pull request #5696 from bsclifton/feat/new_tab_menu
New tab button can now show a dropdown
2 parents a94dc20 + 67ee2c7 commit 76c3165

File tree

6 files changed

+86
-14
lines changed

6 files changed

+86
-14
lines changed

js/components/longPressButton.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,24 @@ class LongPressButton extends ImmutableComponent {
1919
if (e.target.attributes.getNamedItem('disabled')) {
2020
return
2121
}
22+
if (e && e.preventDefault) {
23+
e.preventDefault()
24+
}
25+
if (e && e.stopPropagation) {
26+
e.stopPropagation()
27+
}
2228

2329
const self = this
2430
const target = e.target
2531
const LONG_PRESS_MILLISECONDS = 300
2632

33+
// Right click should immediately trigger the action
34+
if (e.button === 2) {
35+
self.props.onLongPress(target)
36+
return
37+
}
38+
39+
// Otherwise, it should wait before triggering
2740
this.longPressTimer = setTimeout(function () {
2841
self.isLocked = true
2942
self.props.onLongPress(target)
@@ -49,7 +62,9 @@ class LongPressButton extends ImmutableComponent {
4962
this.isLocked = false
5063
return
5164
}
52-
this.props.onClick(e)
65+
if (this.props.onClick) {
66+
this.props.onClick(e)
67+
}
5368
}
5469

5570
render () {

js/components/tabs.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const windowActions = require('../actions/windowActions')
1111
const windowStore = require('../stores/windowStore')
1212
const dragTypes = require('../constants/dragTypes')
1313
const cx = require('../lib/classSet')
14+
const contextMenus = require('../contextMenus')
1415

15-
const Button = require('./button')
16+
const LongPressButton = require('./longPressButton')
1617
const Tab = require('./tab')
1718
const dnd = require('../dnd')
1819
const dndData = require('../dndData')
@@ -24,6 +25,8 @@ class Tabs extends ImmutableComponent {
2425
this.onDrop = this.onDrop.bind(this)
2526
this.onPrevPage = this.onPrevPage.bind(this)
2627
this.onNextPage = this.onNextPage.bind(this)
28+
this.onNewTabLongPress = this.onNewTabLongPress.bind(this)
29+
this.wasNewTabClicked = this.wasNewTabClicked.bind(this)
2730
}
2831

2932
onPrevPage () {
@@ -82,11 +85,15 @@ class Tabs extends ImmutableComponent {
8285
e.preventDefault()
8386
}
8487
}
85-
88+
wasNewTabClicked (target) {
89+
return target.className === this.refs.newTabButton.props.className
90+
}
8691
newTab () {
8792
windowActions.newFrame()
8893
}
89-
94+
onNewTabLongPress (target) {
95+
contextMenus.onNewTabContextMenu(target)
96+
}
9097
render () {
9198
this.tabRefs = []
9299
const index = this.props.previewTabPageIndex !== undefined
@@ -125,10 +132,16 @@ class Tabs extends ImmutableComponent {
125132
onClick={this.onNextPage} />
126133
}
127134
})()}
128-
<Button label='+'
135+
136+
<LongPressButton
137+
ref='newTabButton'
138+
label='+'
129139
l10nId='newTabButton'
130-
className='navbutton newFrameButton'
131-
onClick={this.newTab} />
140+
className='browserButton navbutton newFrameButton'
141+
disabled={false}
142+
onClick={this.newTab}
143+
onLongPress={this.onNewTabLongPress}
144+
/>
132145
</span>
133146
</div>
134147
}

js/components/tabsToolbar.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class TabsToolbar extends ImmutableComponent {
2626
}
2727

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

@@ -51,7 +55,9 @@ class TabsToolbar extends ImmutableComponent {
5155
/>
5256
: null
5357
}
54-
<Tabs tabs={unpinnedTabs}
58+
<Tabs
59+
ref='tabs'
60+
tabs={unpinnedTabs}
5561
shouldAllowWindowDrag={this.props.shouldAllowWindowDrag}
5662
draggingOverData={this.props.draggingOverData}
5763
paintTabs={this.props.paintTabs}

js/contextMenus.js

+16
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,21 @@ function onTabContextMenu (frameProps, e) {
12481248
tabMenu.destroy()
12491249
}
12501250

1251+
function onNewTabContextMenu (target) {
1252+
const rect = target.getBoundingClientRect()
1253+
const menuTemplate = [
1254+
CommonMenu.newPrivateTabMenuItem(),
1255+
CommonMenu.newPartitionedTabMenuItem(),
1256+
CommonMenu.newWindowMenuItem()
1257+
]
1258+
1259+
windowActions.setContextMenuDetail(Immutable.fromJS({
1260+
left: rect.left,
1261+
top: rect.bottom + 2,
1262+
template: menuTemplate
1263+
}))
1264+
}
1265+
12511266
function onTabsToolbarContextMenu (activeFrame, closestDestinationDetail, isParent, e) {
12521267
e.stopPropagation()
12531268
const tabsToolbarMenu = Menu.buildFromTemplate(tabsToolbarTemplateInit(activeFrame, closestDestinationDetail, isParent))
@@ -1458,6 +1473,7 @@ module.exports = {
14581473
onHamburgerMenu,
14591474
onMainContextMenu,
14601475
onTabContextMenu,
1476+
onNewTabContextMenu,
14611477
onTabsToolbarContextMenu,
14621478
onDownloadsToolbarContextMenu,
14631479
onTabPageContextMenu,

test/about/braveTest.js

-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('about:brave tests', function () {
2323
.waitUntil(function () {
2424
return this.getText('table.sortableTable td[data-sort="Brave"]')
2525
.then((textValue) => {
26-
console.log(textValue)
2726
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
2827
})
2928
})
@@ -33,7 +32,6 @@ describe('about:brave tests', function () {
3332
.waitUntil(function () {
3433
return this.getText('table.sortableTable td[data-sort="Muon"]')
3534
.then((textValue) => {
36-
console.log(textValue)
3735
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
3836
})
3937
})
@@ -43,7 +41,6 @@ describe('about:brave tests', function () {
4341
.waitUntil(function () {
4442
return this.getText('table.sortableTable td[data-sort="Update Channel"]')
4543
.then((textValue) => {
46-
console.log(textValue)
4744
return textValue && String(textValue).length > 0 && String(textValue) !== 'null'
4845
})
4946
})

test/components/tabTest.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* global describe, it, before */
1+
/* global describe, it, before, beforeEach */
22

33
const Brave = require('../lib/brave')
44
const messages = require('../../js/constants/messages')
55
const settings = require('../../js/constants/settings')
6-
const {urlInput, backButton, forwardButton, activeTabTitle} = require('../lib/selectors')
6+
const {urlInput, backButton, forwardButton, activeTabTitle, newFrameButton} = require('../lib/selectors')
77

8-
describe('tabs', function () {
8+
describe('tab tests', function () {
99
function * setup (client) {
1010
yield client
1111
.waitForUrl(Brave.newTabUrl)
@@ -73,6 +73,31 @@ describe('tabs', function () {
7373
})
7474
})
7575

76+
describe('new tab button', function () {
77+
Brave.beforeEach(this)
78+
beforeEach(function * () {
79+
yield setup(this.app.client)
80+
})
81+
82+
it('creates a new tab when clicked', function * () {
83+
yield this.app.client
84+
.click(newFrameButton)
85+
.waitForExist('.tab[data-frame-key="2"]')
86+
})
87+
it('shows a context menu when long pressed (click and hold)', function * () {
88+
yield this.app.client
89+
.moveToObject(newFrameButton)
90+
.buttonDown(0)
91+
.waitForExist('.contextMenu .contextMenuItem .contextMenuItemText')
92+
.buttonUp(0)
93+
})
94+
it('shows a context menu when right clicked', function * () {
95+
yield this.app.client
96+
.rightClick(newFrameButton)
97+
.waitForExist('.contextMenu .contextMenuItem .contextMenuItemText')
98+
})
99+
})
100+
76101
describe('tab order', function () {
77102
describe('sequentially by default', function () {
78103
Brave.beforeAll(this)

0 commit comments

Comments
 (0)