Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / UIDirectionManager.cpp
blob5caa306d41b24ea39dc198ae892b5086cdfd2461
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/UIDirectionManager.h"
8 #include "mozilla/Preferences.h"
9 #include "nsIWindowMediator.h"
10 #include "nsDocShell.h"
11 #include "mozilla/dom/Document.h"
12 #include "mozilla/SimpleEnumerator.h"
14 namespace mozilla {
15 namespace dom {
17 /* static */
18 void OnPrefChange(const char* aPrefName, void*) {
19 // Iterate over all of the windows and notify them of the direction change.
20 nsCOMPtr<nsIWindowMediator> windowMediator =
21 do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
22 NS_ENSURE_TRUE_VOID(windowMediator);
24 nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
25 windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
26 NS_ENSURE_TRUE_VOID(windowEnumerator);
28 for (auto& elements : SimpleEnumerator<nsISupports>(windowEnumerator)) {
29 nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(elements);
30 if (window->Closed()) {
31 continue;
34 nsCOMPtr<nsIDocShell> rootDocShell = window->GetDocShell();
35 nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
36 rootDocShell->GetDocShellEnumerator(nsIDocShell::typeAll,
37 nsIDocShell::ENUMERATE_FORWARDS,
38 getter_AddRefs(docShellEnumerator));
39 NS_ENSURE_TRUE_VOID(docShellEnumerator);
40 for (auto& docShell : SimpleEnumerator<nsIDocShell>(docShellEnumerator)) {
41 if (nsCOMPtr<nsPIDOMWindowOuter> win = do_GetInterface(docShell)) {
42 if (dom::Document* doc = win->GetExtantDoc()) {
43 doc->ResetDocumentDirection();
50 /* static */
51 void UIDirectionManager::Initialize() {
52 DebugOnly<nsresult> rv =
53 Preferences::RegisterCallback(OnPrefChange, "intl.uidirection");
54 MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed to observe \"intl.uidirection\"");
57 /* static */
58 void UIDirectionManager::Shutdown() {
59 Preferences::UnregisterCallback(OnPrefChange, "intl.uidirection");
62 } // namespace dom
63 } // namespace mozilla