Skip to content

Commit

Permalink
Bug 1373739 - Make headless widgets hidden by default, matching other…
Browse files Browse the repository at this point in the history
… platforms. r=bdahl

It seems that my reworking of how the z-index events are sent in the patch
pertaining to active window tracking made it so that we can have headless
widgets default to being invisible again, which matches the behavior on all
other platforms. This then allows us to avoid applying size mode change side
effects while a window/widget is invisible, matching the behavior on Windows and
allowing the relevant web platform tests to pass despite the low screen
resolution with which we run Windows VMs in testing (eg.
open-features-non-integer-height.html).

MozReview-Commit-ID: 3xnaEn7RImP
  • Loading branch information
spinda committed Jul 11, 2017
1 parent 70d4794 commit be082bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
29 changes: 22 additions & 7 deletions widget/headless/HeadlessWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ HeadlessWidget::Create(nsIWidget* aParent,

mBounds = aRect;
mRestoreBounds = aRect;
mVisible = true;
mVisible = false;
mEnabled = true;

if (aParent) {
Expand Down Expand Up @@ -131,6 +131,8 @@ HeadlessWidget::Show(bool aState)
// Top-level windows are activated/raised when shown.
if (aState && mTopLevel == this)
RaiseWindow();

ApplySizeModeSideEffects();
}

bool
Expand Down Expand Up @@ -246,18 +248,29 @@ HeadlessWidget::SetSizeMode(nsSizeMode aMode)
if (aMode == mSizeMode) {
return;
}
if (mSizeMode == nsSizeMode_Normal) {
// Store the last normal size bounds so it can be restored when entering
// normal mode again.
mRestoreBounds = mBounds;
}

nsBaseWidget::SetSizeMode(aMode);

// Normally in real widget backends a window event would be triggered that
// would cause the window manager to handle resizing the window. In headless
// the window must manually be resized.
switch(aMode) {
ApplySizeModeSideEffects();
}

void
HeadlessWidget::ApplySizeModeSideEffects()
{
if (!mVisible || mEffectiveSizeMode == mSizeMode) {
return;
}

if (mEffectiveSizeMode == nsSizeMode_Normal) {
// Store the last normal size bounds so it can be restored when entering
// normal mode again.
mRestoreBounds = mBounds;
}

switch(mSizeMode) {
case nsSizeMode_Normal: {
Resize(mRestoreBounds.x, mRestoreBounds.y, mRestoreBounds.width, mRestoreBounds.height, false);
break;
Expand All @@ -281,6 +294,8 @@ HeadlessWidget::SetSizeMode(nsSizeMode aMode)
default:
break;
}

mEffectiveSizeMode = mSizeMode;
}

nsresult
Expand Down
5 changes: 4 additions & 1 deletion widget/headless/HeadlessWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace widget {
class HeadlessWidget : public nsBaseWidget
{
public:
HeadlessWidget() {}
HeadlessWidget() : mEffectiveSizeMode(nsSizeMode_Normal) {}

NS_DECL_ISUPPORTS_INHERITED

Expand Down Expand Up @@ -95,10 +95,13 @@ class HeadlessWidget : public nsBaseWidget
nsIWidget* mTopLevel;
// The size mode before entering fullscreen mode.
nsSizeMode mLastSizeMode;
// The last size mode set while the window was visible.
nsSizeMode mEffectiveSizeMode;
InputContext mInputContext;
// In headless there is no window manager to track window bounds
// across size mode changes, so we must track it to emulate.
LayoutDeviceIntRect mRestoreBounds;
void ApplySizeModeSideEffects();
// Similarly, we must track the active window ourselves in order
// to dispatch (de)activation events properly.
void RaiseWindow();
Expand Down

0 comments on commit be082bc

Please sign in to comment.