This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
248 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
const Immutable = require('immutable') | ||
const tabState = require('./tabState.js') | ||
const config = require('../../../js/constants/config.js') | ||
const eventUtil = require('../../../js/lib/eventUtil.js') | ||
const appActions = require('../../../js/actions/appActions.js') | ||
const windowActions = require('../../../js/actions/windowActions.js') | ||
const UrlUtil = require('../../../js/lib/urlutil.js') | ||
const locale = require('../../locale.js') | ||
const CommonMenu = require('../commonMenu.js') | ||
|
||
const onBackButtonHistoryMenu = (tabId, partitionNumber, history, rect) => { | ||
const menuTemplate = [] | ||
|
||
if (tabId > -1 && history && history.entries.length > 0) { | ||
const stopIndex = Math.max(((history.currentIndex - config.navigationBar.maxHistorySites) - 1), -1) | ||
for (let index = (history.currentIndex - 1); index > stopIndex; index--) { | ||
const url = history.entries[index].url | ||
|
||
menuTemplate.push({ | ||
label: history.entries[index].display, | ||
icon: history.entries[index].icon, | ||
click: (e) => { | ||
if (eventUtil.isForSecondaryAction(e)) { | ||
appActions.createTabRequested({ | ||
url, | ||
partitionNumber: partitionNumber, | ||
active: !!e.shiftKey | ||
}) | ||
} else { | ||
appActions.onNavigateIndex(tabId, index) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// Always display "Show History" link | ||
menuTemplate.push( | ||
CommonMenu.separatorMenuItem, | ||
{ | ||
label: locale.translation('showAllHistory'), | ||
click: () => { | ||
appActions.createTabRequested({ | ||
url: 'about:history' | ||
}) | ||
windowActions.setContextMenuDetail() | ||
} | ||
}) | ||
} | ||
|
||
windowActions.setContextMenuDetail(Immutable.fromJS({ | ||
left: rect.left, | ||
top: rect.bottom, | ||
template: menuTemplate | ||
})) | ||
} | ||
|
||
const onForwardButtonHistoryMenu = (tabId, partitionNumber, history, rect) => { | ||
const menuTemplate = [] | ||
|
||
if (tabId > -1 && history && history.entries.length > 0) { | ||
const stopIndex = Math.max(((history.currentIndex - config.navigationBar.maxHistorySites) - 1), -1) | ||
for (let index = (history.currentIndex - 1); index > stopIndex; index--) { | ||
const url = history.entries[index].url | ||
|
||
menuTemplate.push({ | ||
label: history.entries[index].display, | ||
icon: history.entries[index].icon, | ||
click: (e) => { | ||
if (eventUtil.isForSecondaryAction(e)) { | ||
appActions.createTabRequested({ | ||
url, | ||
partitionNumber: partitionNumber, | ||
active: !!e.shiftKey | ||
}) | ||
} else { | ||
appActions.onNavigateIndex(tabId, index) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// Always display "Show History" link | ||
menuTemplate.push( | ||
CommonMenu.separatorMenuItem, | ||
{ | ||
label: locale.translation('showAllHistory'), | ||
click: () => { | ||
appActions.createTabRequested({ | ||
url: 'about:history' | ||
}) | ||
windowActions.setContextMenuDetail() | ||
} | ||
}) | ||
} | ||
|
||
windowActions.setContextMenuDetail(Immutable.fromJS({ | ||
left: rect.left, | ||
top: rect.bottom, | ||
template: menuTemplate | ||
})) | ||
} | ||
|
||
const historyState = { | ||
getHistoryItems: (state, webContent) => { | ||
const historyCount = webContent.getEntryCount() | ||
const currentIndex = webContent.getCurrentEntryIndex() | ||
const sites = state ? state.get('sites') : null | ||
|
||
let history = { | ||
count: historyCount, | ||
currentIndex, | ||
entries: [] | ||
} | ||
|
||
for (let index = 0; index < historyCount; index++) { | ||
const url = webContent.getURLAtIndex(index) | ||
const title = webContent.getTitleAtIndex(index) | ||
|
||
let entry = { | ||
index: index, | ||
url: url, | ||
display: title || url, | ||
icon: null | ||
} | ||
|
||
if (url.startsWith('chrome-extension://')) { | ||
// TODO: return brave lion (or better: get icon from extension if possible as data URI) | ||
} else { | ||
if (sites) { | ||
const site = sites.find(function (element) { return element.get('location') === url }) | ||
if (site) { entry.icon = site.get('favicon') } | ||
} | ||
|
||
if (!entry.icon) { entry.icon = UrlUtil.getDefaultFaviconUrl(url) } | ||
} | ||
|
||
history.entries.push(entry) | ||
} | ||
|
||
return history | ||
}, | ||
|
||
onBackButtonHistory: (state, tabId, webContent, rect) => { | ||
const tabValue = tabState.getByTabId(state, tabId) | ||
|
||
onBackButtonHistoryMenu( | ||
tabValue.get('tabId'), | ||
tabValue.get('partitionNumber'), | ||
historyState.getHistoryItems(state, webContent), | ||
rect | ||
) | ||
}, | ||
|
||
onForwardButtonHistoryMenu: (state, tabId, webContent, rect) => { | ||
const tabValue = tabState.getByTabId(state, tabId) | ||
|
||
onForwardButtonHistoryMenu( | ||
tabValue.get('tabId'), | ||
tabValue.get('partitionNumber'), | ||
historyState.getHistoryItems(state, webContent), | ||
rect | ||
) | ||
} | ||
} | ||
|
||
module.exports = historyState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.