Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Make URLbar accessible on first launch
Browse files Browse the repository at this point in the history
Fix brave/browser-laptop#6280

This fix turned out to be too aggressive: f4e1e2e

So it's a partial backout of that keeping the parts that keep brave/browser-laptop#6122 fixed

Auditors: @bsclifton
  • Loading branch information
bbondy committed Dec 23, 2016
1 parent a642ebb commit bcdb019
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,10 @@ void WebContents::CopyImageAt(int x, int y) {
host->CopyImageAt(x, y);
}

void WebContents::Focus() {
web_contents()->Focus();
}

#if !defined(OS_MACOSX)
bool WebContents::IsFocused() const {
auto view = web_contents()->GetRenderWidgetHostView();
Expand Down Expand Up @@ -1956,6 +1960,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling)
.SetMethod("findInPage", &WebContents::FindInPage)
.SetMethod("stopFindInPage", &WebContents::StopFindInPage)
.SetMethod("focus", &WebContents::Focus)
.SetMethod("isFocused", &WebContents::IsFocused)
.SetMethod("_clone", &WebContents::Clone)
.SetMethod("_send", &WebContents::SendIPCMessage)
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void CopyImageAt(int x, int y);

// Focus.
void Focus();
bool IsFocused() const;
void SetActive(bool active);
void SetTabIndex(int index);
Expand Down
11 changes: 11 additions & 0 deletions lib/browser/api/browser-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ BrowserWindow.prototype._init = function () {
this.webContents.once('render-view-ready', () => {
this.notifyReady()
})
// Sometimes the webContents doesn't get focus when window is shown, so we
// have to force focusing on webContents in this case. The safest way is to
// focus it when we first start to load URL, if we do it earlier it won't
// have effect, if we do it later we might move focus in the page.
//
// Though this hack is only needed on macOS when the app is launched from
// Finder, we still do it on all platforms in case of other bugs we don't
// know.
this.webContents.once('load-url', function () {
this.focus()
})

// Redirect focus/blur event to app instance too.
this.on('blur', (event) => {
Expand Down

0 comments on commit bcdb019

Please sign in to comment.