зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1755779 - Rebuild the menus when there is a locale change; r=mstange
Most of the menus correctly rebuilt probably from the DOM change observer, but the main menu did not. This fixes the rebuilding of the main Firefox menu so that it will change the locale on live language switching. The LTR to RTL menu direction still needs fixing. See Bug 1755796. Differential Revision: https://phabricator.services.mozilla.com/D139182
This commit is contained in:
Родитель
65a0f5186d
Коммит
5ddcd683ca
|
@ -76,6 +76,7 @@ nsMenuBarX::nsMenuBarX(mozilla::dom::Element* aElement)
|
|||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
||||
mMenuGroupOwner = new nsMenuGroupOwnerX(aElement, this);
|
||||
mMenuGroupOwner->RegisterForLocaleChanges();
|
||||
mNativeMenu = [[GeckoNSMenu alloc] initWithTitle:@"MainMenuBar"];
|
||||
|
||||
mContent = aElement;
|
||||
|
@ -110,6 +111,8 @@ nsMenuBarX::~nsMenuBarX() {
|
|||
sPrefItemContent = nullptr;
|
||||
}
|
||||
|
||||
mMenuGroupOwner->UnregisterForLocaleChanges();
|
||||
|
||||
// make sure we unregister ourselves as a content observer
|
||||
if (mContent) {
|
||||
mMenuGroupOwner->UnregisterForContentChanges(mContent);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "nsIMutationObserver.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsTHashMap.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -40,7 +41,7 @@ enum {
|
|||
// The menu group owner observes DOM mutations, notifies registered nsChangeObservers, and manages
|
||||
// command registration.
|
||||
// There is one owner per menubar, and one per standalone native menu.
|
||||
class nsMenuGroupOwnerX : public nsIMutationObserver {
|
||||
class nsMenuGroupOwnerX : public nsIMutationObserver, public nsIObserver {
|
||||
public:
|
||||
// Both parameters can be null.
|
||||
nsMenuGroupOwnerX(mozilla::dom::Element* aElement, nsMenuBarX* aMenuBarIfMenuBar);
|
||||
|
@ -51,6 +52,9 @@ class nsMenuGroupOwnerX : public nsIMutationObserver {
|
|||
void UnregisterCommand(uint32_t aCommandID);
|
||||
nsMenuItemX* GetMenuItemForCommandID(uint32_t aCommandID);
|
||||
|
||||
void RegisterForLocaleChanges();
|
||||
void UnregisterForLocaleChanges();
|
||||
|
||||
// The representedObject that's used for all menu items under this menu group owner.
|
||||
MOZMenuItemRepresentedObject* GetRepresentedObject() { return mRepresentedObject; }
|
||||
|
||||
|
@ -58,6 +62,7 @@ class nsMenuGroupOwnerX : public nsIMutationObserver {
|
|||
nsMenuBarX* GetMenuBar() { return mMenuBar.get(); }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIMUTATIONOBSERVER
|
||||
|
||||
protected:
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMenuGroupOwnerX, nsIMutationObserver)
|
||||
NS_IMPL_ISUPPORTS(nsMenuGroupOwnerX, nsIObserver, nsIMutationObserver)
|
||||
|
||||
nsMenuGroupOwnerX::nsMenuGroupOwnerX(mozilla::dom::Element* aElement, nsMenuBarX* aMenuBarIfMenuBar)
|
||||
: mContent(aElement), mMenuBar(aMenuBarIfMenuBar) {
|
||||
|
@ -139,6 +139,29 @@ void nsMenuGroupOwnerX::UnregisterForContentChanges(nsIContent* aContent) {
|
|||
mContentToObserverTable.Remove(aContent);
|
||||
}
|
||||
|
||||
void nsMenuGroupOwnerX::RegisterForLocaleChanges() {
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->AddObserver(this, "intl:app-locales-changed", false);
|
||||
}
|
||||
}
|
||||
|
||||
void nsMenuGroupOwnerX::UnregisterForLocaleChanges() {
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(this, "intl:app-locales-changed");
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuGroupOwnerX::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) {
|
||||
if (mMenuBar && !strcmp(aTopic, "intl:app-locales-changed")) {
|
||||
// Rebuild the menu with the new locale strings.
|
||||
mMenuBar->SetNeedsRebuild();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsChangeObserver* nsMenuGroupOwnerX::LookupContentChangeObserver(nsIContent* aContent) {
|
||||
nsChangeObserver* result;
|
||||
if (mContentToObserverTable.Get(aContent, &result)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче