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

Use muon's tab_strip_model for driving index and active (0.18.x) #10727

Merged
merged 2 commits into from
Aug 31, 2017
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
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime = electron
target_arch = x64
brave_electron_version = 4.3.13
brave_electron_version = 4.3.14
chromedriver_version = 2.29
target = v4.3.13
target = v4.3.14
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
106 changes: 42 additions & 64 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const windows = require('../windows')
const {getWebContents} = require('../webContentsCache')
const {BrowserWindow} = require('electron')
const tabState = require('../../common/state/tabState')
const windowState = require('../../common/state/windowState')
const tabActions = require('../../common/actions/tabActions')
const siteSettings = require('../../../js/state/siteSettings')
const siteSettingsState = require('../../common/state/siteSettingsState')
Expand All @@ -22,62 +21,8 @@ const {getFlashResourceId} = require('../../../js/flash')
const {l10nErrorText} = require('../../common/lib/httpUtil')
const Immutable = require('immutable')
const dragTypes = require('../../../js/constants/dragTypes')
const getSetting = require('../../../js/settings').getSetting
const settings = require('../../../js/constants/settings')
const {tabCloseAction} = require('../../common/constants/settingsEnums')
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')

const updateActiveTab = (state, closeTabId) => {
if (!tabState.getByTabId(state, closeTabId)) {
return
}

const index = tabState.getIndex(state, closeTabId)
if (index === -1) {
return
}

const windowId = tabState.getWindowId(state, closeTabId)
if (windowId === windowState.WINDOW_ID_NONE) {
return
}

const lastActiveTabId = tabState.getTabsByLastActivated(state, windowId).last()
if (lastActiveTabId !== closeTabId && !tabState.isActive(state, closeTabId)) {
return
}

let nextTabId = tabState.TAB_ID_NONE
switch (getSetting(settings.TAB_CLOSE_ACTION)) {
case tabCloseAction.LAST_ACTIVE:
nextTabId = tabState.getLastActiveTabId(state, windowId)
break
case tabCloseAction.PARENT:
{
const openerTabId = tabState.getOpenerTabId(state, closeTabId)
if (openerTabId !== tabState.TAB_ID_NONE) {
nextTabId = openerTabId
}
break
}
}

// DEFAULT: always fall back to NEXT
if (nextTabId === tabState.TAB_ID_NONE) {
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index)
if (nextTabId === tabState.TAB_ID_NONE) {
// no unpinned tabs so find the next pinned tab
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index, true)
}
}

if (nextTabId !== tabState.TAB_ID_NONE) {
setImmediate(() => {
tabs.setActive(nextTabId)
})
}
}

const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'

Expand Down Expand Up @@ -125,7 +70,23 @@ const tabsReducer = (state, action, immutableAction) => {
case appConstants.APP_TAB_CREATED:
state = tabState.maybeCreateTab(state, action)
break
case appConstants.APP_TAB_MOVED: {
case appConstants.APP_TAB_ATTACHED:
state = tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
break
case appConstants.APP_TAB_WILL_ATTACH: {
const tabId = action.get('tabId')
const tabValue = tabState.getByTabId(state, tabId)
if (!tabValue) {
break
}
const oldWindowId = tabState.getWindowId(state, tabId)
state = tabs.updateTabsStateForWindow(state, oldWindowId)
break
}
case appConstants.APP_TAB_MOVED:
state = tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
break
case appConstants.APP_TAB_DETACH_MENU_ITEM_CLICKED: {
setImmediate(() => {
const tabId = action.get('tabId')
const frameOpts = frameOptsFromFrame(action.get('frameOpts'))
Expand Down Expand Up @@ -153,6 +114,7 @@ const tabsReducer = (state, action, immutableAction) => {
break
case appConstants.APP_TAB_UPDATED:
state = tabState.maybeCreateTab(state, action)
// tabs.debugTabs(state)
break
case appConstants.APP_TAB_CLOSE_REQUESTED:
{
Expand Down Expand Up @@ -189,7 +151,7 @@ const tabsReducer = (state, action, immutableAction) => {
tabs.closeTab(tabId, action.get('forceClosePinned'))
})
} else {
state = windows.closeWindow(state, windowId)
windows.closeWindow(windowId)
}
}
}
Expand All @@ -201,8 +163,21 @@ const tabsReducer = (state, action, immutableAction) => {
if (tabId === tabState.TAB_ID_NONE) {
break
}
updateActiveTab(state, tabId)
const nextActiveTabId = tabs.getNextActiveTab(state, tabId)

// Must be called before tab is removed
// But still check for no tabId because on tab detach there's a dummy tabId
const tabValue = tabState.getByTabId(state, tabId)
if (tabValue) {
const windowIdOfTabBeingRemoved = tabState.getWindowId(state, tabId)
state = tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
}
state = tabState.removeTabByTabId(state, tabId)
setImmediate(() => {
if (nextActiveTabId !== tabState.TAB_ID_NONE) {
tabs.setActive(nextActiveTabId)
}
})
}
break
case appConstants.APP_ALLOW_FLASH_ONCE:
Expand All @@ -220,9 +195,7 @@ const tabsReducer = (state, action, immutableAction) => {
})
break
case appConstants.APP_TAB_PINNED:
setImmediate(() => {
tabs.pin(state, action.get('tabId'), action.get('pinned'))
})
state = tabs.pin(state, action.get('tabId'), action.get('pinned'))
break
case windowConstants.WINDOW_SET_AUDIO_MUTED:
setImmediate(() => {
Expand Down Expand Up @@ -362,10 +335,15 @@ const tabsReducer = (state, action, immutableAction) => {
const dragData = state.get('dragData')
if (dragData && dragData.get('type') === dragTypes.TAB) {
const frame = dragData.get('data')
const frameOpts = frameOptsFromFrame(frame).toJS()
let frameOpts = frameOptsFromFrame(frame)
const browserOpts = { positionByMouseCursor: true }
frameOpts.indexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverKey'])
frameOpts.prependIndexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
const tabIdForIndex = dragData.getIn(['dragOverData', 'draggingOverKey'])
const tabForIndex = tabState.getByTabId(state, tabIdForIndex)
const dropWindowId = dragData.get('dropWindowId')
if (dropWindowId != null && dropWindowId !== -1 && tabForIndex) {
const prependIndexByTabId = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
frameOpts = frameOpts.set('index', tabForIndex.get('index') + (prependIndexByTabId ? 0 : 1))
}
tabs.moveTo(state, frame.get('tabId'), frameOpts, browserOpts, dragData.get('dropWindowId'))
}
break
Expand Down
9 changes: 7 additions & 2 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ const windowsReducer = (state, action, immutableAction) => {
}
break
case appConstants.APP_CLOSE_WINDOW:
state = windows.closeWindow(state, action.get('windowId'))
windows.closeWindow(action.get('windowId'))
break
case appConstants.APP_WINDOW_CLOSED:
state = windowState.removeWindow(state, action)
sessionStoreShutdown.removeWindowFromCache(action.getIn(['windowValue', 'windowId']))
const windowId = action.getIn(['windowValue', 'windowId'])
sessionStoreShutdown.removeWindowFromCache(windowId)
windows.cleanupWindow(windowId)
break
case appConstants.APP_WINDOW_CREATED:
state = windowState.maybeCreateWindow(state, action)
break
case appConstants.APP_TAB_STRIP_EMPTY:
windows.closeWindow(action.get('windowId'))
break
case appConstants.APP_WINDOW_UPDATED:
state = windowState.maybeCreateWindow(state, action)
break
Expand Down
Loading