Skip to content

Commit

Permalink
Bug 1665456 - Ensure window focus received for skele UI window r=mhowell
Browse files Browse the repository at this point in the history
Because we create our initial window much earlier, we do not receive the
initial activation and focus messages in the same way. Accordingly, we
need to refocus the window once everything is properly set up to handle
it.

Regarding testing, the intent is that this will be covered by existing
tests, since this is not intended to be a behavioral change for window
focus. It is not covered by tests currently only because the skele UI
is disabled by default.

Depends on D90467

Differential Revision: https://phabricator.services.mozilla.com/D90607
  • Loading branch information
squarewave committed Sep 18, 2020
1 parent b75a266 commit 31e64fd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,15 @@ class nsIWidget : public nsISupports {
*/
virtual void EnableIMEForPlugin(bool aEnable) {}

/**
* MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
* of the widget, in the event that we were not able to observe and respond to
* the initial focus event. This is necessary for the early skeleton UI
* window, which is displayed and receives its initial focus event before we
* can actually respond to it.
*/
virtual void MaybeDispatchInitialFocusEvent() {}

/*
* Notifies the input context changes.
*/
Expand Down
8 changes: 8 additions & 0 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ nsWindow::nsWindow(bool aIsChildWindow)
mMouseInDraggableArea = false;
mDestroyCalled = false;
mIsEarlyBlankWindow = false;
mWasPreXulSkeletonUI = false;
mResizable = false;
mHasTaskbarIconBeenCreated = false;
mMouseTransparent = false;
Expand Down Expand Up @@ -894,6 +895,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
if (aInitData->mWindowType == eWindowType_toplevel && !aParent) {
mWnd = ConsumeEarlyBlankWindowHandle();
if (mWnd) {
mWasPreXulSkeletonUI = true;
::SetWindowLongPtrW(mWnd, GWL_STYLE, style);
::SetWindowLongPtrW(mWnd, GWL_EXSTYLE, extendedStyle);
}
Expand Down Expand Up @@ -8674,6 +8676,12 @@ bool nsWindow::SynchronouslyRepaintOnResize() {
return !gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled();
}

void nsWindow::MaybeDispatchInitialFocusEvent() {
if (mWasPreXulSkeletonUI && ::GetActiveWindow() == mWnd) {
DispatchFocusToTopLevelWindow(true);
}
}

already_AddRefed<nsIWidget> nsIWidget::CreateTopLevelWindow() {
nsCOMPtr<nsIWidget> window = new nsWindow();
return window.forget();
Expand Down
2 changes: 2 additions & 0 deletions widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class nsWindow final : public nsWindowBase {
mozilla::widget::CompositorWidgetInitData* aInitData) override;
bool IsTouchWindow() const { return mTouchWindow; }
bool SynchronouslyRepaintOnResize() override;
virtual void MaybeDispatchInitialFocusEvent() override;

protected:
virtual ~nsWindow();
Expand Down Expand Up @@ -605,6 +606,7 @@ class nsWindow final : public nsWindowBase {
bool mOpeningAnimationSuppressed;
bool mAlwaysOnTop;
bool mIsEarlyBlankWindow;
bool mWasPreXulSkeletonUI;
bool mResizable;
DWORD_PTR mOldStyle;
DWORD_PTR mOldExStyle;
Expand Down
2 changes: 2 additions & 0 deletions xpfe/appshell/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
// Attach a WebProgress listener.during initialization...
mDocShell->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);

mWindow->MaybeDispatchInitialFocusEvent();

return rv;
}

Expand Down

0 comments on commit 31e64fd

Please sign in to comment.