Skip to content

Commit

Permalink
Adds z-index for windows when restoring from the session
Browse files Browse the repository at this point in the history
Resolves brave#10473

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Aug 29, 2017
1 parent c93dbd8 commit 2eeb806
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const settings = require('../../../js/constants/settings')
const getSetting = require('../../../js/settings').getSetting
const {zoomLevel} = require('../../common/constants/toolbarUserInterfaceScale')
const platformUtil = require('../../common/lib/platformUtil')
const windowActions = require('../../../js/actions/windowActions')
const {initWindowCacheState} = require('../../sessionStoreShutdown')

const isDarwin = platformUtil.isDarwin()
Expand Down Expand Up @@ -332,6 +333,7 @@ const windowsReducer = (state, action, immutableAction) => {
break
case appConstants.APP_WINDOW_CREATED:
state = windowState.maybeCreateWindow(state, action)
windowActions.onWindowFocus(action.getIn(['windowValue', 'windowId']), action.get('windowValue'))
break
case appConstants.APP_WINDOW_UPDATED:
state = windowState.maybeCreateWindow(state, action)
Expand Down
11 changes: 9 additions & 2 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ const updateWindow = (windowId, updateDefault = false) => {
}
}

const updateWindowFocus = (windowId) => {
const windowValue = getWindowValue(windowId)
if (windowValue) {
appActions.windowUpdated(windowValue)
windowActions.onWindowFocus(windowId, windowValue)
}
}

const siteMatchesTab = (site, tab) => {
const matchesLocation = getLocationIfPDF(tab.get('url')) === site.get('location')
const matchesPartition = tab.get('partitionNumber', 0) === site.get('partitionNumber', 0)
Expand Down Expand Up @@ -182,7 +190,6 @@ const api = {
LocalShortcuts.register(win)

appActions.windowCreated(windowValue)
windowActions.onWindowUpdate(windowId, windowValue)
})
win.once('closed', () => {
cleanupWindow(windowId)
Expand All @@ -192,7 +199,7 @@ const api = {
updateWindowDebounce(windowId)
})
win.on('focus', () => {
updateWindowDebounce(windowId, true)
updateWindowFocus(windowId)
})
win.on('show', () => {
updateWindowDebounce(windowId)
Expand Down
20 changes: 17 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,23 @@ app.on('ready', () => {
appActions.newWindow()
}
} else {
loadedPerWindowImmutableState.forEach((wndState) => {
appActions.newWindow(undefined, undefined, wndState)
})
loadedPerWindowImmutableState
.sort((a, b) => {
let comparison = 0
const aTime = a.getIn(['windowInfo', 'focusTime'], 0)
const bTime = b.getIn(['windowInfo', 'focusTime'], 0)

if (aTime > bTime) {
comparison = 1
} else if (aTime < bTime) {
comparison = -1
}

return comparison
})
.forEach((wndState) => {
appActions.newWindow(undefined, undefined, wndState)
})
}
process.emit(messages.APP_INITIALIZED)

Expand Down
10 changes: 10 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,16 @@ const windowActions = {
},
windowValue
})
},

onWindowFocus: function (windowId, windowValue) {
dispatch({
actionType: windowConstants.WINDOW_ON_WINDOW_FOCUS,
queryInfo: {
windowId
},
windowValue
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const windowConstants = {
WINDOW_ON_ADD_BOOKMARK_FOLDER: _,
WINDOW_ON_EDIT_BOOKMARK_FOLDER: _,
WINDOW_ON_BOOKMARK_FOLDER_CLOSE: _,
WINDOW_ON_WINDOW_UPDATE: _
WINDOW_ON_WINDOW_UPDATE: _,
WINDOW_ON_WINDOW_FOCUS: _
}

module.exports = mapValuesByKeys(windowConstants)
18 changes: 16 additions & 2 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* global performance */

const AppDispatcher = require('../dispatcher/appDispatcher')
const EventEmitter = require('events').EventEmitter
const appActions = require('../actions/appActions')
Expand Down Expand Up @@ -816,8 +818,20 @@ const doAction = (action) => {
break
}
case windowConstants.WINDOW_ON_WINDOW_UPDATE:
windowState = windowState.set('windowInfo', action.windowValue)
break
{
const oldInfo = windowState.get('windowInfo', Immutable.Map())
windowState = windowState.set('windowInfo', oldInfo.merge(action.windowValue))
break
}
case windowConstants.WINDOW_ON_WINDOW_FOCUS:
{
let value = makeImmutable(action.windowValue)
if (value) {
value = value.set('focusTime', performance.timing.navigationStart + performance.now())
windowState = windowState.set('windowInfo', value)
}
break
}
default:
break
}
Expand Down

0 comments on commit 2eeb806

Please sign in to comment.