Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: notify focus change right away rather not on next tick (3-0-x) #14494

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_top_level_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ void TopLevelWindow::OnWindowEndSession() {
}

void TopLevelWindow::OnWindowBlur() {
Emit("blur");
EmitEventSoon("blur");
}

void TopLevelWindow::OnWindowFocus() {
Emit("focus");
EmitEventSoon("focus");
}

void TopLevelWindow::OnWindowShow() {
Expand Down
9 changes: 9 additions & 0 deletions atom/browser/api/atom_api_top_level_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_observer.h"
#include "atom/common/api/atom_api_native_image.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/handle.h"

namespace atom {
Expand Down Expand Up @@ -215,6 +216,14 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
// Remove this window from parent window's |child_windows_|.
void RemoveFromParentChildWindows();

template<typename... Args>
void EmitEventSoon(base::StringPiece eventName) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit<Args...>),
weak_factory_.GetWeakPtr(), eventName));
}

#if defined(OS_WIN)
typedef std::map<UINT, MessageCallback> MessageCallbackMap;
MessageCallbackMap messages_callback_map_;
Expand Down
10 changes: 4 additions & 6 deletions atom/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1104,12 +1104,10 @@ void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget,
if (changed_widget != widget())
return;

// Post the notification to next tick.
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(active ? &NativeWindow::NotifyWindowFocus
: &NativeWindow::NotifyWindowBlur,
GetWeakPtr()));
if (active)
NativeWindow::NotifyWindowFocus();
else
NativeWindow::NotifyWindowBlur();

// Hide menu bar when window is blured.
if (!active && IsMenuBarAutoHide() && IsMenuBarVisible())
Expand Down
16 changes: 5 additions & 11 deletions spec/api-browser-window-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ describe('BrowserWindow module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the test. Passes locally.
xdescribe('BrowserWindow.getFocusedWindow()', (done) => {
describe('BrowserWindow.getFocusedWindow()', (done) => {
it('returns the opener window when dev tools window is focused', (done) => {
w.show()
w.webContents.once('devtools-focused', () => {
Expand Down Expand Up @@ -611,8 +610,7 @@ describe('BrowserWindow module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the test. Passes locally.
xdescribe('BrowserWindow.alwaysOnTop() resets level on minimize', () => {
describe('BrowserWindow.alwaysOnTop() resets level on minimize', () => {
before(function () {
if (process.platform !== 'darwin') {
this.skip()
Expand Down Expand Up @@ -1817,8 +1815,7 @@ describe('BrowserWindow module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the tests. They pass locally.
xdescribe('document.visibilityState/hidden', () => {
describe('document.visibilityState/hidden', () => {
beforeEach(() => { w.destroy() })

function onVisibilityChange (callback) {
Expand Down Expand Up @@ -2421,7 +2418,6 @@ describe('BrowserWindow module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the test. It passes locally.
describe('kiosk state', () => {
before(function () {
// Only implemented on macOS.
Expand Down Expand Up @@ -2469,8 +2465,7 @@ describe('BrowserWindow module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the tests. They pass locally.
xdescribe('fullscreen state', () => {
describe('fullscreen state', () => {
before(function () {
// Only implemented on macOS.
if (process.platform !== 'darwin') {
Expand Down Expand Up @@ -2618,8 +2613,7 @@ describe('BrowserWindow module', () => {
}
})

// TODO(alexeykuzmin): [Ch66] Enable the test. Fails on CI bots, passes locally.
xit('exits HTML fullscreen when window leaves fullscreen', (done) => {
it('exits HTML fullscreen when window leaves fullscreen', (done) => {
w.destroy()
w = new BrowserWindow()
w.webContents.once('did-finish-load', () => {
Expand Down
3 changes: 1 addition & 2 deletions spec/api-web-contents-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ describe('webContents module', () => {
})
})

// TODO(alexeykuzmin): [Ch66] Enable the test. Passes locally.
xdescribe('focus()', () => {
describe('focus()', () => {
describe('when the web contents is hidden', () => {
it('does not blur the focused window', (done) => {
ipcMain.once('answer', (event, parentFocused, childFocused) => {
Expand Down
2 changes: 1 addition & 1 deletion vendor/libchromiumcontent
Submodule libchromiumcontent updated 0 files