mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +00:00
Bug 1741452 - Use nsWeakPtr in mHwndRootWindowMap r=jrmuizel
Use nsWeakPtr instead of RefPtr<nsBaseWidget>, since nsBaseWidget::~nsBaseWidget() and nsWindow::~nsWindow() seem to expect that a widget might be released without calling Destroy(). Differential Revision: https://phabricator.services.mozilla.com/D135512
This commit is contained in:
parent
caf7db3528
commit
7963675e93
@ -382,7 +382,8 @@ void WinWindowOcclusionTracker::Enable(nsBaseWidget* aWindow, HWND aHwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
mHwndRootWindowMap.emplace(aHwnd, aWindow);
|
||||
nsWeakPtr weak = do_GetWeakReference(aWindow);
|
||||
mHwndRootWindowMap.emplace(aHwnd, weak);
|
||||
|
||||
RefPtr<Runnable> runnable = WrapRunnable(
|
||||
RefPtr<WindowOcclusionCalculator>(
|
||||
@ -623,9 +624,13 @@ void WinWindowOcclusionTracker::UpdateOcclusionState(
|
||||
} else if (aShowAllWindows) {
|
||||
occlState = OcclusionState::VISIBLE;
|
||||
}
|
||||
it->second->NotifyOcclusionState(occlState);
|
||||
|
||||
if (it->second->SizeMode() != nsSizeMode_Minimized) {
|
||||
nsCOMPtr<nsIWidget> widget = do_QueryReferent(it->second);
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
auto* baseWidget = static_cast<nsBaseWidget*>(widget.get());
|
||||
baseWidget->NotifyOcclusionState(occlState);
|
||||
if (baseWidget->SizeMode() != nsSizeMode_Minimized) {
|
||||
mNumVisibleRootWindows++;
|
||||
}
|
||||
}
|
||||
@ -688,11 +693,16 @@ void WinWindowOcclusionTracker::MarkNonIconicWindowsOccluded() {
|
||||
|
||||
// Set all visible root windows as occluded. If not visible,
|
||||
// set them as hidden.
|
||||
for (auto& [hwnd, window] : mHwndRootWindowMap) {
|
||||
auto state = (window->SizeMode() == nsSizeMode_Minimized)
|
||||
for (auto& [hwnd, weak] : mHwndRootWindowMap) {
|
||||
nsCOMPtr<nsIWidget> widget = do_QueryReferent(weak);
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
auto* baseWidget = static_cast<nsBaseWidget*>(widget.get());
|
||||
auto state = (baseWidget->SizeMode() == nsSizeMode_Minimized)
|
||||
? OcclusionState::HIDDEN
|
||||
: OcclusionState::OCCLUDED;
|
||||
window->NotifyOcclusionState(state);
|
||||
baseWidget->NotifyOcclusionState(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "mozilla/ThreadSafeWeakPtr.h"
|
||||
#include "mozilla/widget/WindowOcclusionState.h"
|
||||
#include "mozilla/widget/WinEventObserver.h"
|
||||
@ -284,7 +285,7 @@ class WinWindowOcclusionTracker final : public DisplayStatusListener,
|
||||
// Map of HWND to widget. Maintained on main thread, and used to send
|
||||
// occlusion state notifications to Windows from
|
||||
// mRootWindowHwndsOcclusionState.
|
||||
std::unordered_map<HWND, nsBaseWidget*> mHwndRootWindowMap;
|
||||
std::unordered_map<HWND, nsWeakPtr> mHwndRootWindowMap;
|
||||
|
||||
// This is set by UpdateOcclusionState(). It is currently only used by tests.
|
||||
int mNumVisibleRootWindows = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user