summarylogtreecommitdiffstats
path: root/D187418.patch
blob: b95ec3f1a449a13de06135b6941b1fe42786d0eb (plain)
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
81
82
83
84
85
86
87
88
diff --git a/layout/xul/nsXULTooltipListener.cpp b/layout/xul/nsXULTooltipListener.cpp
--- a/layout/xul/nsXULTooltipListener.cpp
+++ b/layout/xul/nsXULTooltipListener.cpp
@@ -368,47 +368,50 @@
   GetTooltipFor(sourceNode, getter_AddRefs(tooltipNode));
   if (!tooltipNode || sourceNode == tooltipNode)
     return NS_ERROR_FAILURE;  // the target node doesn't need a tooltip
 
   // set the node in the document that triggered the tooltip and show it
-  if (tooltipNode->GetComposedDoc() &&
-      nsContentUtils::IsChromeDoc(tooltipNode->GetComposedDoc())) {
-    // Make sure the target node is still attached to some document.
-    // It might have been deleted.
-    if (sourceNode->IsInComposedDoc()) {
-      if (!mIsSourceTree) {
-        mLastTreeRow = -1;
-        mLastTreeCol = nullptr;
-      }
+  // Make sure the document still has focus.
+  auto* doc = tooltipNode->GetComposedDoc();
+  if (!doc || !nsContentUtils::IsChromeDoc(doc) ||
+      !doc->HasFocus(IgnoreErrors())) {
+    return NS_OK;
+  }
+  // Make sure the target node is still attached to some document.
+  // It might have been deleted.
+  if (sourceNode->IsInComposedDoc()) {
+    if (!mIsSourceTree) {
+      mLastTreeRow = -1;
+      mLastTreeCol = nullptr;
+    }
 
-      mCurrentTooltip = do_GetWeakReference(tooltipNode);
-      LaunchTooltip();
-      mTargetNode = nullptr;
-
-      nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
-      if (!currentTooltip) return NS_OK;
+    mCurrentTooltip = do_GetWeakReference(tooltipNode);
+    LaunchTooltip();
+    mTargetNode = nullptr;
 
-      // listen for popuphidden on the tooltip node, so that we can
-      // be sure DestroyPopup is called even if someone else closes the tooltip
-      currentTooltip->AddSystemEventListener(u"popuphiding"_ns, this, false,
-                                             false);
+    nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip);
+    if (!currentTooltip) return NS_OK;
+
+    // listen for popuphidden on the tooltip node, so that we can
+    // be sure DestroyPopup is called even if someone else closes the tooltip
+    currentTooltip->AddSystemEventListener(u"popuphiding"_ns, this, false,
+                                           false);
 
-      // listen for mousedown, mouseup, keydown, and mouse events at
-      // document level
-      if (Document* doc = sourceNode->GetComposedDoc()) {
-        // Probably, we should listen to untrusted events for hiding tooltips
-        // on content since tooltips might disturb something of web
-        // applications.  If we don't specify the aWantsUntrusted of
-        // AddSystemEventListener(), the event target sets it to TRUE if the
-        // target is in content.
-        doc->AddSystemEventListener(u"wheel"_ns, this, true);
-        doc->AddSystemEventListener(u"mousedown"_ns, this, true);
-        doc->AddSystemEventListener(u"mouseup"_ns, this, true);
-        doc->AddSystemEventListener(u"keydown"_ns, this, true);
-      }
-      mSourceNode = nullptr;
+    // listen for mousedown, mouseup, keydown, and mouse events at
+    // document level
+    if (Document* doc = sourceNode->GetComposedDoc()) {
+      // Probably, we should listen to untrusted events for hiding tooltips
+      // on content since tooltips might disturb something of web
+      // applications.  If we don't specify the aWantsUntrusted of
+      // AddSystemEventListener(), the event target sets it to TRUE if the
+      // target is in content.
+      doc->AddSystemEventListener(u"wheel"_ns, this, true);
+      doc->AddSystemEventListener(u"mousedown"_ns, this, true);
+      doc->AddSystemEventListener(u"mouseup"_ns, this, true);
+      doc->AddSystemEventListener(u"keydown"_ns, this, true);
     }
+    mSourceNode = nullptr;
   }
 
   return NS_OK;
 }