Skip to content

Commit ebdf68c

Browse files
committed
Revert "Bug 1824053 - [1/4] Remove Win32 implementation of nsIWidget::SetBackgroundColor() r=win-reviewers,handyman"
This reverts commit e63e620.
1 parent d9d413a commit ebdf68c

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

widget/nsIWidget.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ class nsIWidget : public nsISupports {
749749
* @param aShouldLock bool
750750
*
751751
*/
752-
virtual void LockAspectRatio(bool aShouldLock) {};
752+
virtual void LockAspectRatio(bool aShouldLock){};
753753

754754
/**
755755
* Move or resize this widget. Any size constraints set for the window by
@@ -928,11 +928,10 @@ class nsIWidget : public nsISupports {
928928
}
929929

930930
/**
931-
* Set the native background color for this widget.
932-
*
933-
* Deprecated. Currently only implemented for iOS. (See bug 1901896.)
931+
* Set the background color for this widget
934932
*
935933
* @param aColor the new background color
934+
*
936935
*/
937936

938937
virtual void SetBackgroundColor(const nscolor& aColor) {}
@@ -1986,7 +1985,7 @@ class nsIWidget : public nsISupports {
19861985

19871986
virtual void UpdateZoomConstraints(
19881987
const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
1989-
const mozilla::Maybe<ZoomConstraints>& aConstraints) {};
1988+
const mozilla::Maybe<ZoomConstraints>& aConstraints){};
19901989

19911990
/**
19921991
* GetTextEventDispatcher() returns TextEventDispatcher belonging to the

widget/windows/nsWindow.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ static bool IsCloaked(HWND hwnd) {
703703

704704
nsWindow::nsWindow(bool aIsChildWindow)
705705
: nsBaseWidget(BorderStyle::Default),
706+
mBrush(::CreateSolidBrush(NSRGB_2_COLOREF(::GetSysColor(COLOR_BTNFACE)))),
706707
mFrameState(std::in_place, this),
707708
mIsChildWindow(aIsChildWindow),
708709
mLastPaintEndTime(TimeStamp::Now()),
@@ -1287,16 +1288,6 @@ static void RegisterWindowClass(const wchar_t* aClassName, UINT aExtraStyle,
12871288
aIconID ? ::LoadIconW(::GetModuleHandleW(nullptr), aIconID) : nullptr;
12881289
wc.lpszClassName = aClassName;
12891290

1290-
// Since we discard WM_ERASEBKGND events, the window-class background brush is
1291-
// mostly not used -- it shows up when resizing, but scarcely ever otherwise.
1292-
//
1293-
// In theory we could listen for theme changes and set this brush to an
1294-
// appropriate background color as needed; but given the hoops Win32 makes us
1295-
// jump through to change class data, it's probably not worth the trouble.
1296-
// (See bug 1901875.) Instead, we just make it dark grey, which is probably
1297-
// acceptable in either light or dark mode.
1298-
wc.hbrBackground = (HBRUSH)::GetStockObject(DKGRAY_BRUSH);
1299-
13001291
// Failures are ignored as they are handled when ::CreateWindow fails
13011292
::RegisterClassW(&wc);
13021293
}
@@ -2960,6 +2951,23 @@ HRGN nsWindow::ExcludeNonClientFromPaintRegion(HRGN aRegion) {
29602951
return rgn;
29612952
}
29622953

2954+
/**************************************************************
2955+
*
2956+
* SECTION: nsIWidget::SetBackgroundColor
2957+
*
2958+
* Sets the window background paint color.
2959+
*
2960+
**************************************************************/
2961+
2962+
void nsWindow::SetBackgroundColor(const nscolor& aColor) {
2963+
if (mBrush) ::DeleteObject(mBrush);
2964+
2965+
mBrush = ::CreateSolidBrush(NSRGB_2_COLOREF(aColor));
2966+
if (mWnd != nullptr) {
2967+
::SetClassLongPtrW(mWnd, GCLP_HBRBACKGROUND, (LONG_PTR)mBrush);
2968+
}
2969+
}
2970+
29632971
/**************************************************************
29642972
*
29652973
* SECTION: nsIWidget::SetCursor
@@ -7505,6 +7513,12 @@ void nsWindow::OnDestroy() {
75057513

75067514
IMEHandler::OnDestroyWindow(this);
75077515

7516+
// Free GDI window class objects
7517+
if (mBrush) {
7518+
VERIFY(::DeleteObject(mBrush));
7519+
mBrush = nullptr;
7520+
}
7521+
75087522
// Destroy any custom cursor resources.
75097523
if (mCursor.IsCustom()) {
75107524
SetCursor(Cursor{eCursor_standard});

widget/windows/nsWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class nsWindow final : public nsBaseWidget {
188188
[[nodiscard]] nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
189189
LayoutDeviceIntRect GetClientBounds() override;
190190
LayoutDeviceIntPoint GetClientOffset() override;
191+
void SetBackgroundColor(const nscolor& aColor) override;
191192
void SetCursor(const Cursor&) override;
192193
bool PrepareForFullscreenTransition(nsISupports** aData) override;
193194
void PerformFullscreenTransition(FullscreenTransitionStage aStage,
@@ -739,6 +740,7 @@ class nsWindow final : public nsBaseWidget {
739740
HWND mWnd = nullptr;
740741
HWND mTransitionWnd = nullptr;
741742
mozilla::Maybe<WNDPROC> mPrevWndProc;
743+
HBRUSH mBrush;
742744
IMEContext mDefaultIMC;
743745
HDEVNOTIFY mDeviceNotifyHandle = nullptr;
744746
bool mIsTopWidgetWindow = false;

xpfe/appshell/AppWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
217217
NS_ENSURE_SUCCESS(rv, rv);
218218

219219
LayoutDeviceIntRect r = mWindow->GetClientBounds();
220-
// Match the default background color of content. Previously important on
221-
// Windows, but no longer has any effect there.
220+
// Match the default background color of content. Important on windows
221+
// since we no longer use content child widgets.
222222
mWindow->SetBackgroundColor(NS_RGB(255, 255, 255));
223223

224224
// All Chrome BCs exist within the same BrowsingContextGroup, so we don't need

0 commit comments

Comments
 (0)