Bug 1468557 - Remove nsXBLWindowKeyHandler::mUserHandler and nsXBLSpecialDocInfo::mUserHTMLBindings draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 13 Jun 2018 12:32:55 -0700
changeset 808196 f01160eb661cc2d5047375a5175bf115225c85f3
parent 806725 9941eb8c3b29d152851220b5d9791326c35e1c68
push id113307
push usertimdream@gmail.com
push dateMon, 18 Jun 2018 17:00:29 +0000
bugs1468557
milestone62.0a1
Bug 1468557 - Remove nsXBLWindowKeyHandler::mUserHandler and nsXBLSpecialDocInfo::mUserHTMLBindings MozReview-Commit-ID: KMa9S381Je4
dom/xbl/nsXBLWindowKeyHandler.cpp
dom/xbl/nsXBLWindowKeyHandler.h
--- a/dom/xbl/nsXBLWindowKeyHandler.cpp
+++ b/dom/xbl/nsXBLWindowKeyHandler.cpp
@@ -38,34 +38,29 @@
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 
 class nsXBLSpecialDocInfo : public nsIObserver
 {
 public:
   RefPtr<nsXBLDocumentInfo> mHTMLBindings;
-  RefPtr<nsXBLDocumentInfo> mUserHTMLBindings;
 
   static const char sHTMLBindingStr[];
   static const char sUserHTMLBindingStr[];
 
   bool mInitialized;
 
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   void LoadDocInfo();
-  void GetAllHandlers(const char* aType,
-                      nsXBLPrototypeHandler** handler,
-                      nsXBLPrototypeHandler** userHandler);
-  void GetHandlers(nsXBLDocumentInfo* aInfo,
-                   const nsACString& aRef,
-                   nsXBLPrototypeHandler** aResult);
+  void GetHandlers(const nsACString& aRef,
+                   nsXBLPrototypeHandler** handler);
 
   nsXBLSpecialDocInfo() : mInitialized(false) {}
 
 protected:
   virtual ~nsXBLSpecialDocInfo() {}
 
 };
 
@@ -78,17 +73,16 @@ NS_IMETHODIMP
 nsXBLSpecialDocInfo::Observe(nsISupports* aSubject,
                              const char* aTopic,
                              const char16_t* aData)
 {
   MOZ_ASSERT(!strcmp(aTopic, "xpcom-shutdown"), "wrong topic");
 
   // On shutdown, clear our fields to avoid an extra cycle collection.
   mHTMLBindings = nullptr;
-  mUserHTMLBindings = nullptr;
   mInitialized = false;
   nsContentUtils::UnregisterShutdownObserver(this);
 
   return NS_OK;
 }
 
 void nsXBLSpecialDocInfo::LoadDocInfo()
 {
@@ -114,41 +108,27 @@ void nsXBLSpecialDocInfo::LoadDocInfo()
                                       getter_AddRefs(mHTMLBindings));
 }
 
 //
 // GetHandlers
 //
 //
 void
-nsXBLSpecialDocInfo::GetHandlers(nsXBLDocumentInfo* aInfo,
-                                 const nsACString& aRef,
-                                 nsXBLPrototypeHandler** aResult)
+nsXBLSpecialDocInfo::GetHandlers(const nsACString& aRef,
+                                 nsXBLPrototypeHandler** aHandler)
 {
-  nsXBLPrototypeBinding* binding = aInfo->GetPrototypeBinding(aRef);
-
-  NS_ASSERTION(binding, "No binding found for the XBL window key handler.");
-  if (!binding)
-    return;
-
-  *aResult = binding->GetPrototypeHandlers();
-}
+  if (mHTMLBindings) {
+    nsXBLPrototypeBinding* binding = mHTMLBindings->GetPrototypeBinding(aRef);
 
-void
-nsXBLSpecialDocInfo::GetAllHandlers(const char* aType,
-                                    nsXBLPrototypeHandler** aHandler,
-                                    nsXBLPrototypeHandler** aUserHandler)
-{
-  if (mUserHTMLBindings) {
-    nsAutoCString type(aType);
-    type.AppendLiteral("User");
-    GetHandlers(mUserHTMLBindings, type, aUserHandler);
-  }
-  if (mHTMLBindings) {
-    GetHandlers(mHTMLBindings, nsDependentCString(aType), aHandler);
+    NS_ASSERTION(binding, "No binding found for the XBL window key handler.");
+    if (!binding)
+      return;
+
+    *aHandler = binding->GetPrototypeHandlers();
   }
 }
 
 // Init statics
 static StaticRefPtr<nsXBLSpecialDocInfo> sXBLSpecialDocInfo;
 uint32_t nsXBLWindowKeyHandler::sRefCnt = 0;
 
 /* static */ void
@@ -158,18 +138,17 @@ nsXBLWindowKeyHandler::EnsureSpecialDocI
     sXBLSpecialDocInfo = new nsXBLSpecialDocInfo();
   }
   sXBLSpecialDocInfo->LoadDocInfo();
 }
 
 nsXBLWindowKeyHandler::nsXBLWindowKeyHandler(Element* aElement,
                                              EventTarget* aTarget)
   : mTarget(aTarget),
-    mHandler(nullptr),
-    mUserHandler(nullptr)
+    mHandler(nullptr)
 {
   mWeakPtrForElement = do_GetWeakReference(aElement);
   ++sRefCnt;
 }
 
 nsXBLWindowKeyHandler::~nsXBLWindowKeyHandler()
 {
   // If mWeakPtrForElement is non-null, we created a prototype handler.
@@ -251,20 +230,20 @@ nsXBLWindowKeyHandler::EnsureHandlers()
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(el));
     BuildHandlerChain(content, &mHandler);
   } else { // We are an XBL file of handlers.
     EnsureSpecialDocInfo();
 
     // Now determine which handlers we should be using.
     if (IsHTMLEditableFieldFocused()) {
-      sXBLSpecialDocInfo->GetAllHandlers("editor", &mHandler, &mUserHandler);
+      sXBLSpecialDocInfo->GetHandlers(NS_LITERAL_CSTRING("editor"), &mHandler);
     }
     else {
-      sXBLSpecialDocInfo->GetAllHandlers("browser", &mHandler, &mUserHandler);
+      sXBLSpecialDocInfo->GetHandlers(NS_LITERAL_CSTRING("browser"), &mHandler);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 nsXBLWindowKeyHandler::WalkHandlers(KeyboardEvent* aKeyEvent, nsAtom* aEventType)
@@ -278,31 +257,23 @@ nsXBLWindowKeyHandler::WalkHandlers(Keyb
     return NS_OK;
   }
 
   nsresult rv = EnsureHandlers();
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool isDisabled;
   nsCOMPtr<Element> el = GetElement(&isDisabled);
-  if (!el) {
-    if (mUserHandler) {
-      WalkHandlersInternal(aKeyEvent, aEventType, mUserHandler, true);
-      if (aKeyEvent->DefaultPrevented()) {
-        return NS_OK; // Handled by the user bindings. Our work here is done.
-      }
-    }
-  }
 
   // skip keysets that are disabled
   if (el && isDisabled) {
     return NS_OK;
   }
 
-  WalkHandlersInternal(aKeyEvent, aEventType, mHandler, true);
+  WalkHandlersInternal(aKeyEvent, aEventType, true);
 
   return NS_OK;
 }
 
 void
 nsXBLWindowKeyHandler::InstallKeyboardEventListenersTo(
                          EventListenerManager* aEventListenerManager)
 {
@@ -425,18 +396,17 @@ nsXBLWindowKeyHandler::RemoveKeyboardEve
 
 /* static */ KeyboardMap
 nsXBLWindowKeyHandler::CollectKeyboardShortcuts()
 {
   // Load the XBL handlers
   EnsureSpecialDocInfo();
 
   nsXBLPrototypeHandler* handlers = nullptr;
-  nsXBLPrototypeHandler* userHandlers = nullptr;
-  sXBLSpecialDocInfo->GetAllHandlers("browser", &handlers, &userHandlers);
+  sXBLSpecialDocInfo->GetHandlers(NS_LITERAL_CSTRING("browser"), &handlers);
 
   // Convert the handlers into keyboard shortcuts, using an AutoTArray with
   // the maximum amount of shortcuts used on any platform to minimize allocations
   AutoTArray<KeyboardShortcut, 48> shortcuts;
 
   // Append keyboard shortcuts for hardcoded actions like tab
   KeyboardShortcut::AppendHardcodedShortcuts(shortcuts);
 
@@ -444,25 +414,16 @@ nsXBLWindowKeyHandler::CollectKeyboardSh
        handler;
        handler = handler->GetNextHandler()) {
     KeyboardShortcut shortcut;
     if (handler->TryConvertToKeyboardShortcut(&shortcut)) {
       shortcuts.AppendElement(shortcut);
     }
   }
 
-  for (nsXBLPrototypeHandler* handler = userHandlers;
-       handler;
-       handler = handler->GetNextHandler()) {
-    KeyboardShortcut shortcut;
-    if (handler->TryConvertToKeyboardShortcut(&shortcut)) {
-      shortcuts.AppendElement(shortcut);
-    }
-  }
-
   return KeyboardMap(std::move(shortcuts));
 }
 
 nsAtom*
 nsXBLWindowKeyHandler::ConvertEventToDOMEventType(
                          const WidgetKeyboardEvent& aWidgetKeyboardEvent) const
 {
   if (aWidgetKeyboardEvent.IsKeyDownOrKeyDownOnPlugin()) {
@@ -638,68 +599,66 @@ nsXBLWindowKeyHandler::IsHTMLEditableFie
 // Given a particular DOM event and a pointer to the first handler in the list,
 // scan through the list to find something to handle the event. If aExecute = true,
 // the handler will be executed; otherwise just return an answer telling if a handler
 // for that event was found.
 //
 bool
 nsXBLWindowKeyHandler::WalkHandlersInternal(KeyboardEvent* aKeyEvent,
                                             nsAtom* aEventType,
-                                            nsXBLPrototypeHandler* aHandler,
                                             bool aExecute,
                                             bool* aOutReservedForChrome)
 {
   WidgetKeyboardEvent* nativeKeyboardEvent =
     aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
   MOZ_ASSERT(nativeKeyboardEvent);
 
   AutoShortcutKeyCandidateArray shortcutKeys;
   nativeKeyboardEvent->GetShortcutKeyCandidates(shortcutKeys);
 
   if (shortcutKeys.IsEmpty()) {
-    return WalkHandlersAndExecute(aKeyEvent, aEventType, aHandler,
+    return WalkHandlersAndExecute(aKeyEvent, aEventType,
                                   0, IgnoreModifierState(),
                                   aExecute, aOutReservedForChrome);
   }
 
   for (uint32_t i = 0; i < shortcutKeys.Length(); ++i) {
     ShortcutKeyCandidate& key = shortcutKeys[i];
     IgnoreModifierState ignoreModifierState;
     ignoreModifierState.mShift = key.mIgnoreShift;
-    if (WalkHandlersAndExecute(aKeyEvent, aEventType, aHandler,
+    if (WalkHandlersAndExecute(aKeyEvent, aEventType,
                                key.mCharCode, ignoreModifierState,
                                aExecute, aOutReservedForChrome)) {
       return true;
     }
   }
   return false;
 }
 
 bool
 nsXBLWindowKeyHandler::WalkHandlersAndExecute(
                          KeyboardEvent* aKeyEvent,
                          nsAtom* aEventType,
-                         nsXBLPrototypeHandler* aFirstHandler,
                          uint32_t aCharCode,
                          const IgnoreModifierState& aIgnoreModifierState,
                          bool aExecute,
                          bool* aOutReservedForChrome)
 {
   if (aOutReservedForChrome) {
     *aOutReservedForChrome = false;
   }
 
   WidgetKeyboardEvent* widgetKeyboardEvent =
     aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
   if (NS_WARN_IF(!widgetKeyboardEvent)) {
     return false;
   }
 
   // Try all of the handlers until we find one that matches the event.
-  for (nsXBLPrototypeHandler* handler = aFirstHandler;
+  for (nsXBLPrototypeHandler* handler = mHandler;
        handler;
        handler = handler->GetNextHandler()) {
     bool stopped = aKeyEvent->IsDispatchStopped();
     if (stopped) {
       // The event is finished, don't execute any more handlers
       return false;
     }
 
@@ -810,17 +769,17 @@ nsXBLWindowKeyHandler::WalkHandlersAndEx
 #ifdef XP_WIN
   // Windows native applications ignore Windows-Logo key state when checking
   // shortcut keys even if the key is pressed.  Therefore, if there is no
   // shortcut key which exactly matches current modifier state, we should
   // retry to look for a shortcut key without the Windows-Logo key press.
   if (!aIgnoreModifierState.mOS && widgetKeyboardEvent->IsOS()) {
     IgnoreModifierState ignoreModifierState(aIgnoreModifierState);
     ignoreModifierState.mOS = true;
-    return WalkHandlersAndExecute(aKeyEvent, aEventType, aFirstHandler,
+    return WalkHandlersAndExecute(aKeyEvent, aEventType,
                                   aCharCode, ignoreModifierState, aExecute);
   }
 #endif
 
   return false;
 }
 
 bool
@@ -858,17 +817,17 @@ nsXBLWindowKeyHandler::HasHandlerForEven
   bool isDisabled;
   nsCOMPtr<Element> el = GetElement(&isDisabled);
   if (el && isDisabled) {
     return false;
   }
 
   RefPtr<nsAtom> eventTypeAtom =
     ConvertEventToDOMEventType(*widgetKeyboardEvent);
-  return WalkHandlersInternal(aEvent, eventTypeAtom, mHandler, false,
+  return WalkHandlersInternal(aEvent, eventTypeAtom, false,
                               aOutReservedForChrome);
 }
 
 already_AddRefed<Element>
 nsXBLWindowKeyHandler::GetElement(bool* aIsDisabled)
 {
   nsCOMPtr<Element> element = do_QueryReferent(mWeakPtrForElement);
   if (element && aIsDisabled) {
--- a/dom/xbl/nsXBLWindowKeyHandler.h
+++ b/dom/xbl/nsXBLWindowKeyHandler.h
@@ -50,24 +50,22 @@ public:
 protected:
   virtual ~nsXBLWindowKeyHandler();
 
   nsresult WalkHandlers(KeyboardEvent* aKeyEvent, nsAtom* aEventType);
 
   // walk the handlers, looking for one to handle the event
   bool WalkHandlersInternal(KeyboardEvent* aKeyEvent,
                             nsAtom* aEventType,
-                            nsXBLPrototypeHandler* aHandler,
                             bool aExecute,
                             bool* aOutReservedForChrome = nullptr);
 
   // walk the handlers for aEvent, aCharCode and aIgnoreModifierState. Execute
   // it if aExecute = true.
   bool WalkHandlersAndExecute(KeyboardEvent* aKeyEvent, nsAtom* aEventType,
-                              nsXBLPrototypeHandler* aHandler,
                               uint32_t aCharCode,
                               const IgnoreModifierState& aIgnoreModifierState,
                               bool aExecute,
                               bool* aOutReservedForChrome = nullptr);
 
   // HandleEvent function for the capturing phase in the default event group.
   void HandleEventOnCaptureInDefaultEventGroup(KeyboardEvent* aEvent);
   // HandleEvent function for the capturing phase in the system event group.
@@ -126,17 +124,16 @@ protected:
 
   // Using weak pointer to the DOM Element.
   nsWeakPtr              mWeakPtrForElement;
   mozilla::dom::EventTarget* mTarget; // weak ref
 
   // these are not owning references; the prototype handlers are owned
   // by the prototype bindings which are owned by the docinfo.
   nsXBLPrototypeHandler* mHandler;     // platform bindings
-  nsXBLPrototypeHandler* mUserHandler; // user-specific bindings
 
   // holds reference count to document info about bindings
   static uint32_t sRefCnt;
 };
 
 already_AddRefed<nsXBLWindowKeyHandler>
 NS_NewXBLWindowKeyHandler(mozilla::dom::Element* aElement,
                           mozilla::dom::EventTarget* aTarget);