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.
Merge pull request #1 from brave/tabs
Basic tab structure
- Loading branch information
Showing
10 changed files
with
619 additions
and
2 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,197 @@ | ||
const React = require('react') | ||
const ReactDOM = require('react-dom') | ||
|
||
const ImmutableComponent = require('./immutableComponent') | ||
|
||
const AppActions = require('../actions/appActions') | ||
const cx = require('../lib/classSet.js') | ||
|
||
const getFavicon = require('../lib/faviconUtil.js') | ||
|
||
class DragIndicator extends ImmutableComponent { | ||
constructor (props) { | ||
super(props) | ||
} | ||
|
||
render () { | ||
return <hr className={cx({ | ||
dragIndicator: true, | ||
dragActive: this.props.active, | ||
dragIndicatorEnd: this.props.end | ||
})}/> | ||
} | ||
} | ||
|
||
class Tab extends ImmutableComponent { | ||
constructor (props) { | ||
super(props) | ||
} | ||
|
||
get displayValue () { | ||
// YouTube tries to change the title to add a play icon when | ||
// there is audio. Since we have our own audio indicator we get | ||
// rid of it. | ||
return (this.props.frameProps.get('title') || | ||
this.props.frameProps.get('location')).replace('▶ ', '') | ||
} | ||
|
||
onDragStart (e) { | ||
AppActions.tabDragStart(this.props.frameProps) | ||
} | ||
|
||
onDragEnd () { | ||
AppActions.tabDragStop(this.props.frameProps) | ||
} | ||
|
||
onDragOver (e) { | ||
e.preventDefault() | ||
|
||
// Otherise, only accept it if we have some frameProps | ||
if (!this.props.activeDraggedTab) { | ||
AppActions.tabDraggingOn(this.props.frameProps) | ||
return | ||
} | ||
|
||
let rect = ReactDOM.findDOMNode(this.refs.tab).getBoundingClientRect() | ||
if (e.clientX > rect.left && e.clientX < rect.left + rect.width / 2 && | ||
!this.props.frameProps.get('tabIsDraggingOverLeftHalf')) { | ||
AppActions.tabDragDraggingOverLeftHalf(this.props.frameProps) | ||
} else if (e.clientX < rect.right && e.clientX >= rect.left + rect.width / 2 && | ||
!this.props.frameProps.get('tabIsDraggingOverRightHalf')) { | ||
AppActions.tabDragDraggingOverRightHalf(this.props.frameProps) | ||
} | ||
} | ||
|
||
onDragLeave () { | ||
if (this.props.frameProps.get('tabIsDraggingOverLeftHalf') || | ||
this.props.frameProps.get('tabIsDraggingOn') || | ||
this.props.frameProps.get('tabIsDraggingOverLeftHalf')) { | ||
AppActions.tabDragExit(this.props.frameProps) | ||
} else if (this.props.frameProps.get('tabIsDraggingOverRightHalf')) { | ||
AppActions.tabDragExitRightHalf(this.props.frameProps) | ||
} | ||
} | ||
|
||
onDrop (e) { | ||
let sourceFrameProps = this.props.activeDraggedTab | ||
if (!sourceFrameProps) { | ||
return | ||
} | ||
|
||
if (this.props.frameProps.get('tabIsDraggingOverLeftHalf')) { | ||
AppActions.moveTab(sourceFrameProps, this.props.frameProps, true) | ||
} else { | ||
AppActions.moveTab(sourceFrameProps, this.props.frameProps, false) | ||
} | ||
AppActions.tabDragExit(this.props.frameProps) | ||
} | ||
|
||
setActiveFrame () { | ||
AppActions.setActiveFrame(this.props.frameProps) | ||
} | ||
|
||
render () { | ||
const thumbnailWidth = 160 | ||
const thumbnailHeight = 100 | ||
|
||
let thumbnailStyle = { | ||
backgroundSize: `${thumbnailWidth} ${thumbnailHeight}`, | ||
width: thumbnailWidth, | ||
height: thumbnailHeight | ||
} | ||
if (this.props.frameProps.get('thumbnailUrl')) { | ||
thumbnailStyle.backgroundImage = `url(${this.props.frameProps.get('thumbnailUrl')})` | ||
} | ||
|
||
// Style based on theme-color | ||
var activeTabStyle = {} | ||
if (this.props.isActive && (this.props.frameProps.get('themeColor') || this.props.frameProps.get('computedThemeColor'))) { | ||
activeTabStyle.backgroundColor = this.props.frameProps.get('themeColor') || this.props.frameProps.get('computedThemeColor') | ||
} | ||
|
||
const iconStyle = { | ||
backgroundImage: `url(${getFavicon(this.props.frameProps)})`, | ||
backgroundSize: 16, | ||
width: 16, | ||
height: 16 | ||
} | ||
|
||
let playIcon = null | ||
if (this.props.frameProps.get('audioPlaybackActive') || | ||
this.props.frameProps.get('audioMuted')) { | ||
playIcon = <span className={cx({ | ||
playIcon: true, | ||
fa: true, | ||
'fa-volume-up': this.props.frameProps.get('audioPlaybackActive') && | ||
!this.props.frameProps.get('audioMuted'), | ||
'fa-volume-off': this.props.frameProps.get('audioMuted') | ||
})} | ||
onClick={this.props.frameProps.get('audioMuted') ? this.props.onUnmuteFrame : this.props.onMuteFrame} /> | ||
} | ||
|
||
return <div className='tabArea' | ||
style={{ | ||
width: `${this.props.tabWidth}%` | ||
}}> | ||
<DragIndicator active={this.props.frameProps.get('tabIsDraggingOverLeftHalf')}/> | ||
<div className={cx({ | ||
tab: true, | ||
active: this.props.isActive, | ||
private: this.props.isPrivate, | ||
draggingOn: this.props.frameProps.get('tabIsDraggingOn'), | ||
dragging: this.props.frameProps.get('tabIsDragging'), | ||
'dragging-over': this.props.frameProps.get('tabIsDraggingOverLeftHalf') || | ||
this.props.frameProps.get('tabIsDraggingOverRightHalf') | ||
})} | ||
ref='tab' | ||
draggable='true' | ||
title={this.props.frameProps.get('title')} | ||
onDragStart={this.onDragStart.bind(this)} | ||
onDragEnd={this.onDragEnd.bind(this)} | ||
onDragLeave={this.onDragLeave.bind(this)} | ||
onDragOver={this.onDragOver.bind(this)} | ||
onDrop={this.onDrop.bind(this)} | ||
onClick={this.setActiveFrame.bind(this)} | ||
style={activeTabStyle}> | ||
<div className='thumbnail' | ||
style={thumbnailStyle} /> | ||
<span onClick={this.props.onCloseFrame} | ||
className='closeTab fa fa-times-circle'/> | ||
<div className='tabIcon' style={iconStyle}/> | ||
<div className='tabTitle'> | ||
{playIcon} | ||
{this.displayValue} | ||
</div> | ||
</div> | ||
<DragIndicator | ||
end | ||
active={this.props.frameProps.get('tabIsDraggingOverRightHalf')}/> | ||
</div> | ||
} | ||
} | ||
|
||
class Tabs extends ImmutableComponent { | ||
constructor () { | ||
super() | ||
} | ||
|
||
render () { | ||
var tabWidth = 100 / this.props.frames.size | ||
|
||
return <div className='tabs'> | ||
<div className='tabRow'> | ||
{ | ||
this.props.frames.map(frameProps => <Tab | ||
activeDraggedTab={this.props.tabs.get('activeDraggedTab')} | ||
frameProps={frameProps} | ||
key={'tab-' + frameProps.get('key')} | ||
isActive={this.props.activeFrame === frameProps} | ||
isPrivate={frameProps.get('isPrivate')} | ||
tabWidth={tabWidth} />) | ||
} | ||
</div> | ||
</div> | ||
} | ||
} | ||
|
||
module.exports = Tabs |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
module.exports = { | ||
APP_SET_URL: 1, | ||
APP_SET_NAVBAR_INPUT: 2, | ||
APP_NEW_FRAME: 3 | ||
APP_NEW_FRAME: 3, | ||
APP_SET_ACTIVE_FRAME: 4, | ||
APP_TAB_DRAG_START: 5, | ||
APP_TAB_DRAG_STOP: 6, | ||
APP_TAB_DRAGGING_OVER_LEFT: 7, | ||
APP_TAB_DRAGGING_OVER_RIGHT: 8, | ||
APP_TAB_DRAGGING_ON: 9, | ||
APP_TAB_DRAG_EXIT: 10, | ||
APP_TAB_DRAG_EXIT_RIGHT: 11, | ||
APP_TAB_MOVE: 12 | ||
} |
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,74 @@ | ||
const Immutable = require('immutable') | ||
|
||
/** | ||
* Determines the path of a relative URL from the hosted app | ||
*/ | ||
export function getAppUrl (relativeUrl = './') { | ||
return new window.URL(relativeUrl, window.location).href | ||
} | ||
|
||
/** | ||
* Returns the URL to the application's manifest | ||
*/ | ||
export function getManifestUrl () { | ||
return getAppUrl('./manifest.webapp') | ||
} | ||
|
||
// Map of source about: URLs mapped to target URLs | ||
export const aboutUrls = new Immutable.Map({ | ||
'about:about': getAppUrl('./about-about.html'), | ||
'about:blank': getAppUrl('./about-blank.html'), | ||
'about:history': getAppUrl('./about-history.html'), | ||
'about:newtab': getAppUrl('./about-newtab.html'), | ||
'about:preferences': getAppUrl('./about-preferences.html'), | ||
'about:settings': getAppUrl('./about-settings.html') | ||
}) | ||
|
||
// Map of target URLs mapped to source about: URLs | ||
const aboutUrlsReverse = new Immutable.Map(aboutUrls.reduce((obj, v, k) => { | ||
obj[v] = k | ||
return obj | ||
}, {})) | ||
|
||
/** | ||
* Obtains the target URL associated with an about: source URL | ||
* Example: | ||
* about:blank -> http://localhost:8000/about-blank/index.html | ||
*/ | ||
export function getTargetAboutUrl (input) { | ||
return aboutUrls.get(input) | ||
} | ||
|
||
/** | ||
* Obtains the source about: URL associated with a target URL | ||
* Example: | ||
* http://localhost:8000/about-blank.html -> about:blank | ||
*/ | ||
export function getSourceAboutUrl (input) { | ||
return aboutUrlsReverse.get(input) | ||
} | ||
|
||
/** | ||
* Determines if the passed in string is a source about: URL | ||
* Example: isSourceAboutUrl('about:blank') -> true | ||
*/ | ||
export function isSourceAboutUrl (input) { | ||
return !!getTargetAboutUrl(input) | ||
} | ||
|
||
/** | ||
* Determines if the passed in string is the target of a source about: URL | ||
* Example: isTargetAboutUrl('http://localhost:8000/about-blank/index.html') -> true | ||
*/ | ||
export function isTargetAboutUrl (input) { | ||
return !!getSourceAboutUrl(input) | ||
} | ||
|
||
/** | ||
* Determines whether the passed in string is pointing to a URL that | ||
* should be privileged (mozapp attribute on the iframe) | ||
* For now this is the same as an about URL. | ||
*/ | ||
export function isPrivilegedUrl (input) { | ||
return isSourceAboutUrl(input) | ||
} |
Oops, something went wrong.