1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* 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/. */
#ifndef __nsNativeMenuService_h__
#define __nsNativeMenuService_h__
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsDataHashtable.h"
#include "nsINativeMenuService.h"
#include "nsTArray.h"
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
class nsMenuBar;
/*
* The main native menu service singleton. nsWebShellWindow calls in to this when
* a new top level window is created.
*
* Menubars are owned by their nsWindow. This service holds a weak reference to
* each menubar for the purpose of re-registering them with the shell if it
* needs to. The menubar is responsible for notifying the service when the last
* reference to it is dropped.
*/
class nsNativeMenuService final : public nsINativeMenuService {
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateNativeMenuBar(nsIWidget* aParent, nsIContent* aMenuBarNode) override;
// Returns the singleton addref'd for the service manager
static already_AddRefed<nsNativeMenuService> GetInstanceForServiceManager();
// Returns the singleton without increasing the reference count
static nsNativeMenuService* GetSingleton();
// Called by a menubar when it is deleted
void NotifyNativeMenuBarDestroyed(nsMenuBar* aMenuBar);
private:
nsNativeMenuService();
~nsNativeMenuService();
nsresult Init();
static void EnsureInitialized();
void SetOnline(bool aOnline);
void RegisterNativeMenuBar(nsMenuBar* aMenuBar);
static void name_owner_changed_cb(GObject* gobject,
GParamSpec* pspec,
gpointer user_data);
static void proxy_created_cb(GObject* source_object,
GAsyncResult* res,
gpointer user_data);
static void register_native_menubar_cb(GObject* source_object,
GAsyncResult* res,
gpointer user_data);
static gboolean map_event_cb(GtkWidget* widget, GdkEvent* event,
gpointer user_data);
void OnNameOwnerChanged();
void OnProxyCreated(GDBusProxy* aProxy);
void OnNativeMenuBarRegistered(nsMenuBar* aMenuBar,
bool aSuccess);
static void PrefChangedCallback(const char* aPref, void* aClosure);
void PrefChanged();
GCancellable* mCreateProxyCancellable;
GDBusProxy* mDbusProxy;
bool mOnline;
nsTArray<nsMenuBar* > mMenuBars;
nsDataHashtable<nsPtrHashKey<nsMenuBar>, GCancellable*> mMenuBarRegistrationCancellables;
static bool sShutdown;
static nsNativeMenuService* sService;
};
#endif /* __nsNativeMenuService_h__ */
|