Bug 695623 - xul:browser is subject of focus event when tabbing from chrome to content process, r=davidb, olli.pettay
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 26 Oct 2011 15:42:20 +0900
changeset 79235 9367d1dae799e7a91ec24f199b75d6951897021c
parent 79234 fef6e3628e258cc5847576cff8489e7713c5eb0e
child 79236 ebd6501de8832c3fc3762f23cbad042d1bddc50f
push id21380
push userbmo@edmorley.co.uk
push dateWed, 26 Oct 2011 23:31:27 +0000
treeherderautoland@16a8d2ab5240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb, olli.pettay
bugs695623
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 695623 - xul:browser is subject of focus event when tabbing from chrome to content process, r=davidb, olli.pettay
accessible/src/base/FocusManager.cpp
accessible/src/base/FocusManager.h
content/events/src/nsEventStateManager.h
--- a/accessible/src/base/FocusManager.cpp
+++ b/accessible/src/base/FocusManager.cpp
@@ -36,16 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "FocusManager.h"
 
 #include "nsAccessibilityService.h"
 #include "nsAccUtils.h"
 #include "nsRootAccessible.h"
 
+#include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 
 namespace dom = mozilla::dom;
 using namespace mozilla::a11y;
 
 FocusManager::FocusManager()
 {
 }
@@ -347,30 +348,41 @@ FocusManager::ProcessFocusEvent(AccEvent
       // we receive focus event, for example if the node is removed from DOM.
       nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
                               anchorJump, fromUserInputFlag);
     }
     targetDocument->SetAnchorJump(nsnull);
   }
 }
 
-nsIContent*
-FocusManager::FocusedDOMElm() const
+nsINode*
+FocusManager::FocusedDOMNode() const
 {
   nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
-  return DOMFocusManager->GetFocusedContent();
-}
+  nsIContent* focusedElm = DOMFocusManager->GetFocusedContent();
 
-nsIDocument*
-FocusManager::FocusedDOMDocument() const
-{
-  nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
+  // No focus on remote target elements like xul:browser having DOM focus and
+  // residing in chrome process because it means an element in content process
+  // keeps the focus.
+  if (focusedElm) {
+    if (nsEventStateManager::IsRemoteTarget(focusedElm))
+      return nsnull;
+    return focusedElm;
+  }
 
+  // Otherwise the focus can be on DOM document.
   nsCOMPtr<nsIDOMWindow> focusedWnd;
   DOMFocusManager->GetFocusedWindow(getter_AddRefs(focusedWnd));
   if (focusedWnd) {
     nsCOMPtr<nsIDOMDocument> DOMDoc;
     focusedWnd->GetDocument(getter_AddRefs(DOMDoc));
     nsCOMPtr<nsIDocument> DOMDocNode(do_QueryInterface(DOMDoc));
     return DOMDocNode;
   }
   return nsnull;
 }
+
+nsIDocument*
+FocusManager::FocusedDOMDocument() const
+{
+  nsINode* focusedNode = FocusedDOMNode();
+  return focusedNode ? focusedNode->OwnerDoc() : nsnull;
+}
--- a/accessible/src/base/FocusManager.h
+++ b/accessible/src/base/FocusManager.h
@@ -141,28 +141,17 @@ protected:
 
 private:
   FocusManager(const FocusManager&);
   FocusManager& operator =(const FocusManager&);
 
   /**
    * Return DOM node having DOM focus.
    */
-  inline nsINode* FocusedDOMNode() const
-  {
-    nsINode* focusedNode = FocusedDOMElm();
-    if (focusedNode)
-      return focusedNode;
-    return FocusedDOMDocument();
-  }
-
-  /**
-   * Return DOM element having DOM focus.
-   */
-  nsIContent* FocusedDOMElm() const;
+  nsINode* FocusedDOMNode() const;
 
   /**
    * Return DOM document having DOM focus.
    */
   nsIDocument* FocusedDOMDocument() const;
 
 private:
   nsRefPtr<nsAccessible> mActiveItem;
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -223,16 +223,18 @@ public:
   // Sets aNewESM to be the active event state manager, and
   // if aContent is non-null, marks the object as active.
   static void SetActiveManager(nsEventStateManager* aNewESM,
                                nsIContent* aContent);
 
   // Sets the full-screen event state on aElement to aIsFullScreen.
   static void SetFullScreenState(mozilla::dom::Element* aElement, bool aIsFullScreen);
 
+  static bool IsRemoteTarget(nsIContent* aTarget);
+
 protected:
   friend class MouseEnterLeaveDispatcher;
 
   void UpdateCursor(nsPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
   /**
    * Turn a GUI mouse event into a mouse event targeted at the specified
    * content.  This returns the primary frame for the content (or null
    * if it goes away during the event).
@@ -460,17 +462,16 @@ protected:
                                nsIFrame* aTargetFrame);
   void DoQuerySelectedText(nsQueryContentEvent* aEvent);
 
   bool RemoteQueryContentEvent(nsEvent *aEvent);
   mozilla::dom::TabParent *GetCrossProcessTarget();
   bool IsTargetCrossProcess(nsGUIEvent *aEvent);
 
   void DispatchCrossProcessEvent(nsEvent* aEvent, nsIFrameLoader* remote);
-  bool IsRemoteTarget(nsIContent* target);
   bool HandleCrossProcessEvent(nsEvent *aEvent,
                                  nsIFrame* aTargetFrame,
                                  nsEventStatus *aStatus);
 
 private:
   static inline void DoStateChange(mozilla::dom::Element* aElement,
                                    nsEventStates aState, bool aAddState);
   static inline void DoStateChange(nsIContent* aContent, nsEventStates aState,