2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
|
2018-08-14 10:38:03 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-09-15 13:03:29 +03:00
|
|
|
#ifndef GeckoSystemStateListener_h
|
|
|
|
#define GeckoSystemStateListener_h
|
2018-08-14 10:38:03 +03:00
|
|
|
|
|
|
|
#include "GeneratedJNINatives.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/PresShell.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2018-08-14 10:38:03 +03:00
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-09-15 13:03:29 +03:00
|
|
|
class GeckoSystemStateListener final
|
|
|
|
: public java::GeckoSystemStateListener::Natives<GeckoSystemStateListener> {
|
|
|
|
GeckoSystemStateListener() = delete;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-14 10:38:03 +03:00
|
|
|
public:
|
|
|
|
static void OnDeviceChanged() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-14 10:38:03 +03:00
|
|
|
// Iterate all toplevel windows
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator =
|
|
|
|
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE_VOID(windowMediator);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
|
|
|
windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
|
|
|
NS_ENSURE_TRUE_VOID(windowEnumerator);
|
|
|
|
|
|
|
|
bool more;
|
|
|
|
while (NS_SUCCEEDED(windowEnumerator->HasMoreElements(&more)) && more) {
|
|
|
|
nsCOMPtr<nsISupports> elements;
|
|
|
|
if (NS_FAILED(windowEnumerator->GetNext(getter_AddRefs(elements)))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(elements)) {
|
|
|
|
if (window->Closed()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
if (dom::Document* doc = window->GetExtantDoc()) {
|
2019-03-29 18:12:47 +03:00
|
|
|
if (PresShell* presShell = doc->GetPresShell()) {
|
2018-08-14 10:38:03 +03:00
|
|
|
presShell->ThemeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-08-14 10:38:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-09-15 13:03:29 +03:00
|
|
|
#endif // GeckoSystemStateListener_h
|