Skip to content

Commit

Permalink
Propogate click events from webviews and close popups like autocomple…
Browse files Browse the repository at this point in the history
…te list when clicking outside the chrome area. Fixes mozilla#1123. r=vporof
  • Loading branch information
jsantell committed Sep 20, 2016
1 parent aad2e5e commit 4b94d66
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/ui/browser-modern/views/browser/page/index.jsx
Expand Up @@ -204,6 +204,26 @@ class Page extends Component {
break;
}
});

// We cannot bind click events on the actual webview node, but mousedown
// works, so convert that to a propogated click.
this.webview.addEventListener('mousedown', e => {
this.handleWebviewClick(e);
});
}

/**
* Intercept and propogate clicks from the webview so we can react (like close popups)
* on events from webview.
*/
handleWebviewClick() {
const ev = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window,
relatedTarget: this.webview,
});
this.webview.dispatchEvent(ev);
}

render() {
Expand Down
21 changes: 21 additions & 0 deletions app/ui/shared/widgets/autocompleted-search.jsx
Expand Up @@ -37,13 +37,34 @@ class AutocompletedSearch extends Component {
this.shouldComponentUpdate = ComponentUtil.shouldMixedPropsComponentUpdate.bind(this, {
immutables: ['dataSrc'],
});
this.handleWindowClick = this.handleWindowClick.bind(this);

this.state = {
showSelectionList: false,
selectedIndex: 0,
};
}

componentWillMount() {
if (typeof window === 'object') {
window.addEventListener('click', this.handleWindowClick);
}
}

componentWillUnmount() {
if (typeof window === 'object') {
window.removeEventListener('click', this.handleWindowClick);
}
}

handleWindowClick() {
// This component's button won't be available if hasn't rendered yet.
// We also can't call `setState` on components which haven't rendered yet.
if (this.state.showSelectionList && this.inputbar) {
this.setState({ showSelectionList: false });
}
}

handleInputChange = e => {
this.setState({ showSelectionList: !!e.target.value });
this.setState({ selectedIndex: 0 });
Expand Down

0 comments on commit 4b94d66

Please sign in to comment.