Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
Fix the context menu. r=jsantell
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Townsend <dtownsend@oxymoronical.com>
  • Loading branch information
Mossop committed Apr 26, 2016
1 parent 5fa0097 commit dc2b740
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
29 changes: 0 additions & 29 deletions app/content/preload/content.js
Expand Up @@ -10,35 +10,6 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
*/

import { ipcRenderer as ipc } from 'electron';

import './hover-status';
import './context-menu';
import './scroll';

window.addEventListener('message', (event) => {
if (event.origin !== 'atom://') {
return;
}

const data = JSON.parse(event.data);
if (data.source !== 'page') {
return;
}

if (data.target === 'host') {
ipc.sendToHost('channel-message', data.source, data.type, data.data);
} else if (data.target === 'main') {
ipc.send('channel-message', data.source, data.type, data.data);
}
}, false);

ipc.on('channel-message', (event, source, type, data) => {
const message = {
target: 'page',
source,
type,
data,
};
window.postMessage(JSON.stringify(message), 'atom://');
});
2 changes: 1 addition & 1 deletion app/content/preload/context-menu.js
Expand Up @@ -20,7 +20,7 @@ ipc.on('get-contextmenu-data', (event, pos) => {
const data = {
x: pos.x,
y: pos.y,
hasSelection: !!window.getSelection.toString(),
hasSelection: !!window.getSelection().toString(),
href: false,
img: false,
video: false,
Expand Down
16 changes: 4 additions & 12 deletions app/ui/browser/actions/external.js
Expand Up @@ -136,7 +136,7 @@ export function menuTabContext(pageIndex, dispatch) {
/**
* Right click on the page itself
*/
export function menuWebViewContext(e, dispatch) {
export function menuWebViewContext(webview, e, dispatch) {
const menu = new Menu();

if (e.href) {
Expand Down Expand Up @@ -171,33 +171,25 @@ export function menuWebViewContext(e, dispatch) {
if (e.hasSelection) {
menu.append(new MenuItem({
label: 'Copy',
click: ev => getCurrentWebView(ev.target.ownerDocument).copy(),
click: () => webview.copy(),
}));
}

menu.append(new MenuItem({
label: 'Select All',
click: ev => getCurrentWebView(ev.target.ownerDocument).selectAll(),
click: () => webview.selectAll(),
}));

menu.append(new MenuItem({ type: 'separator' }));

menu.append(new MenuItem({
label: 'Inspect Element',
click: ev => getCurrentWebView(ev.target.ownerDocument).inspectElement(e.x, e.y),
click: () => webview.inspectElement(e.x, e.y),
}));

menu.popup(remote.getCurrentWindow());
}

/**
* Right click somewhere in a web page
*/
export function contextMenu(e) {
const { offsetX: x, offsetY: y } = e.nativeEvent;
e.target.send('get-contextmenu-data', { x, y });
}

/**
* 'Zoom' on OSX
*/
Expand Down
11 changes: 8 additions & 3 deletions app/ui/browser/views/page/page.jsx
Expand Up @@ -19,7 +19,7 @@ import Status from './status';
import Search from './search';

import { fixURL } from '../../browser-util';
import { contextMenu, menuWebViewContext } from '../../actions/external';
import { menuWebViewContext } from '../../actions/external';
import { closeTab, setPageDetails, setUserTypedLocation } from '../../actions/main-actions';
import * as profileCommands from '../../../../shared/profile-commands';

Expand Down Expand Up @@ -101,6 +101,11 @@ class Page extends Component {
}

render() {
const requestContextData = (event) => {
const { offsetX: x, offsetY: y } = event.nativeEvent;
this.refs.webviewWrapper.webview.send('get-contextmenu-data', { x, y });
};

return (
<div className={`${PAGE_STYLE} ${this.props.isActive ? 'active-browser-page' : ''}`}
hidden={!this.props.isActive}>
Expand All @@ -119,7 +124,7 @@ class Page extends Component {
? WEB_VIEW_WRAPPER_CHROME_EXPANDED_STYLE
: WEB_VIEW_WRAPPER_CHROME_COLLAPSED_STYLE))}
guestInstanceId={this.props.page.guestInstanceId}
onContextMenu={() => this.props.dispatch(contextMenu())} />
onContextMenu={requestContextData} />
<Status page={this.props.page} />
</div>
);
Expand Down Expand Up @@ -183,7 +188,7 @@ function addListenersToWebView(webview, page, dispatch, ipcRenderer) {
}));
break;
case 'contextmenu-data':
menuWebViewContext(e.args[0], dispatch);
menuWebViewContext(webview, e.args[0], dispatch);
break;
case 'show-bookmarks':
console.warn('@TODO: ipc-message:show-bookmarks');
Expand Down

0 comments on commit dc2b740

Please sign in to comment.