From cd19a8d6b01707549602d7ce0b68cc7874b5adbc Mon Sep 17 00:00:00 2001 From: Akshendra Pratap Singh Date: Wed, 15 Oct 2014 07:42:00 +0200 Subject: [PATCH] Bug 1037990 - AccessLabelKey is now accessible event if the element is detached. r=bzbarsky --- .../html/content/src/nsGenericHTMLElement.cpp | 15 ++--- dom/events/EventStateManager.cpp | 12 ++-- dom/events/EventStateManager.h | 3 +- dom/events/test/mochitest.ini | 1 + dom/events/test/test_bug1037990.html | 61 +++++++++++++++++++ 5 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 dom/events/test/test_bug1037990.html diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 8580903b4f9b..065f691625b0 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -291,16 +291,11 @@ static const nsAttrValue::EnumTable kDirTable[] = { void nsGenericHTMLElement::GetAccessKeyLabel(nsString& aLabel) { - //XXXsmaug We shouldn't need PresContext for this. - nsPresContext *presContext = GetPresContext(eForComposedDoc); - - if (presContext) { - nsAutoString suffix; - GetAccessKey(suffix); - if (!suffix.IsEmpty() && - presContext->EventStateManager()->GetAccessKeyLabelPrefix(aLabel)) { - aLabel.Append(suffix); - } + nsAutoString suffix; + GetAccessKey(suffix); + if (!suffix.IsEmpty()) { + EventStateManager::GetAccessKeyLabelPrefix(this, aLabel); + aLabel.Append(suffix); } } diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 373b60fe054a..a966c873ff63 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -944,16 +944,21 @@ EventStateManager::ExecuteAccessKey(nsTArray& aAccessCharCodes, return false; } -bool -EventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix) +// static +void +EventStateManager::GetAccessKeyLabelPrefix(Element* aElement, nsAString& aPrefix) { aPrefix.Truncate(); nsAutoString separator, modifierText; nsContentUtils::GetModifierSeparatorText(separator); - nsCOMPtr container = mPresContext->GetContainerWeak(); + nsCOMPtr container = aElement->OwnerDoc()->GetDocShell(); int32_t modifierMask = GetAccessModifierMaskFor(container); + if (modifierMask == -1) { + return; + } + if (modifierMask & NS_MODIFIER_CONTROL) { nsContentUtils::GetControlText(modifierText); aPrefix.Append(modifierText + separator); @@ -974,7 +979,6 @@ EventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix) nsContentUtils::GetShiftText(modifierText); aPrefix.Append(modifierText + separator); } - return !aPrefix.IsEmpty(); } void diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index 20073f590c6c..68c0809853b3 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -40,6 +40,7 @@ class WheelTransaction; namespace dom { class DataTransfer; +class Element; class TabParent; } // namespace dom @@ -169,7 +170,7 @@ public: */ uint32_t GetRegisteredAccessKey(nsIContent* aContent); - bool GetAccessKeyLabelPrefix(nsAString& aPrefix); + static void GetAccessKeyLabelPrefix(dom::Element* aElement, nsAString& aPrefix); nsresult SetCursor(int32_t aCursor, imgIContainer* aContainer, bool aHaveHotspot, float aHotspotX, float aHotspotY, diff --git a/dom/events/test/mochitest.ini b/dom/events/test/mochitest.ini index 081c141e47e1..ac452c415ab2 100644 --- a/dom/events/test/mochitest.ini +++ b/dom/events/test/mochitest.ini @@ -22,6 +22,7 @@ skip-if = buildapp == 'b2g' skip-if = buildapp == 'b2g' [test_bug288392.html] [test_bug299673-1.html] +[test_bug1037990.html] [test_bug299673-2.html] [test_bug322588.html] skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || e10s #Bug 931116, b2g desktop specific, initial triage diff --git a/dom/events/test/test_bug1037990.html b/dom/events/test/test_bug1037990.html new file mode 100644 index 000000000000..025c8744b288 --- /dev/null +++ b/dom/events/test/test_bug1037990.html @@ -0,0 +1,61 @@ + + + + + + Test for Bug 1037990 + + + + +Mozilla Bug 1037990 +

+ +
+
+ + +