mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
fix: notify focus change right away rather not on next tick (#14453)
* fix: Notify focus change right away, not on next tick * fix: emit the JS blur/focus events on next tick to avoid race condition * address feedback from review * fix: bind deferred Emit() calls to a WeakPtr This is so that the deferred Emit() calls will be canceled if the TopLevelWindow is destroyed. * chore: remove wip/test code cruft * fix: make linter happy * Enable disabled tests * refactor: cleaner impl of EmitEventSoon() * Revert "Merge branch 'fix-win-focus' of github.com:electron/electron into fix-win-focus" This reverts commit90576806eb, reversing changes made to9c13e47779. * Restore704722c1, which was removed in error. We apologise again for the fault in the subtitles. Those responsible for sacking the people who have just been sacked have been sacked.
This commit is contained in:
committed by
Charles Kerr
parent
e96433243c
commit
a2ab0d8ebe
@@ -163,11 +163,11 @@ void TopLevelWindow::OnWindowEndSession() {
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowBlur() {
|
||||
Emit("blur");
|
||||
EmitEventSoon("blur");
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowFocus() {
|
||||
Emit("focus");
|
||||
EmitEventSoon("focus");
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowShow() {
|
||||
|
||||
@@ -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 {
|
||||
@@ -222,6 +223,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_;
|
||||
|
||||
@@ -1109,12 +1109,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())
|
||||
|
||||
Reference in New Issue
Block a user