diff --git a/dom/html/HTMLObjectElement.cpp b/dom/html/HTMLObjectElement.cpp index eb4f5a7fbb77..a1f8df07658a 100644 --- a/dom/html/HTMLObjectElement.cpp +++ b/dom/html/HTMLObjectElement.cpp @@ -45,9 +45,6 @@ HTMLObjectElement::HTMLObjectElement(already_AddRefed& a HTMLObjectElement::~HTMLObjectElement() { -#ifdef XP_MACOSX - OnFocusBlurPlugin(this, false); -#endif UnregisterActivityObserver(); DestroyImageLoadingContent(); } @@ -116,50 +113,20 @@ NS_IMPL_NSICONSTRAINTVALIDATION(HTMLObjectElement) static nsIWidget* GetWidget(Element* aElement) { - return nsContentUtils::WidgetForDocument(aElement->OwnerDoc()); + nsIWidget* retval = NULL; + nsIFrame* frame = aElement->GetPrimaryFrame(); + if (frame) { + retval = frame->GetNearestWidget(); + } + return retval; } -Element* HTMLObjectElement::sLastFocused = nullptr; // Weak - -class PluginFocusSetter : public nsRunnable +static void OnFocusBlurPlugin(Element* aElement, bool aFocus) { -public: - PluginFocusSetter(nsIWidget* aWidget, Element* aElement) - : mWidget(aWidget), mElement(aElement) - { - } - - NS_IMETHOD Run() - { - if (mElement) { - HTMLObjectElement::sLastFocused = mElement; - bool value = true; - mWidget->SetPluginFocused(value); - } else if (!HTMLObjectElement::sLastFocused) { - bool value = false; - mWidget->SetPluginFocused(value); - } - - return NS_OK; - } - -private: - nsCOMPtr mElement; - nsCOMPtr mWidget; -}; - -void -HTMLObjectElement::OnFocusBlurPlugin(Element* aElement, bool aFocus) -{ - if (aFocus || aElement == sLastFocused) { - if (!aFocus) { - sLastFocused = nullptr; - } - nsIWidget* widget = GetWidget(aElement); - if (widget) { - nsContentUtils::AddScriptRunner( - new PluginFocusSetter(widget, aFocus ? aElement : nullptr)); - } + nsIWidget* widget = GetWidget(aElement); + if (widget) { + bool value = aFocus; + widget->SetPluginFocused(value); } } @@ -243,14 +210,6 @@ void HTMLObjectElement::UnbindFromTree(bool aDeep, bool aNullParent) { -#ifdef XP_MACOSX - // When a page is reloaded (when an nsIDocument's content is removed), the - // focused element isn't necessarily sent an NS_BLUR_CONTENT event. See - // nsFocusManager::ContentRemoved(). This means that a widget may think it - // still contains a focused plugin when it doesn't -- which in turn can - // disable text input in the browser window. See bug 1137229. - OnFocusBlurPlugin(this, false); -#endif nsObjectLoadingContent::UnbindFromTree(aDeep, aNullParent); nsGenericHTMLFormElement::UnbindFromTree(aDeep, aNullParent); } diff --git a/dom/html/HTMLObjectElement.h b/dom/html/HTMLObjectElement.h index 55112448b113..c1ab18685b92 100644 --- a/dom/html/HTMLObjectElement.h +++ b/dom/html/HTMLObjectElement.h @@ -33,11 +33,7 @@ public: #ifdef XP_MACOSX // nsIDOMEventTarget NS_IMETHOD PostHandleEvent(EventChainPostVisitor& aVisitor) override; - // Helper methods - static void OnFocusBlurPlugin(Element* aElement, bool aFocus); static void HandleFocusBlurPlugin(Element* aElement, WidgetEvent* aEvent); - // Weak pointer. Null if last action was blur. - static Element* sLastFocused; #endif // Element diff --git a/dom/html/HTMLSharedObjectElement.cpp b/dom/html/HTMLSharedObjectElement.cpp index 3674697f79de..d73907ba4727 100644 --- a/dom/html/HTMLSharedObjectElement.cpp +++ b/dom/html/HTMLSharedObjectElement.cpp @@ -62,9 +62,6 @@ HTMLSharedObjectElement::SetItemValueText(const nsAString& aValue) HTMLSharedObjectElement::~HTMLSharedObjectElement() { -#ifdef XP_MACOSX - HTMLObjectElement::OnFocusBlurPlugin(this, false); -#endif UnregisterActivityObserver(); DestroyImageLoadingContent(); } @@ -162,14 +159,6 @@ void HTMLSharedObjectElement::UnbindFromTree(bool aDeep, bool aNullParent) { -#ifdef XP_MACOSX - // When a page is reloaded (when an nsIDocument's content is removed), the - // focused element isn't necessarily sent an NS_BLUR_CONTENT event. See - // nsFocusManager::ContentRemoved(). This means that a widget may think it - // still contains a focused plugin when it doesn't -- which in turn can - // disable text input in the browser window. See bug 1137229. - HTMLObjectElement::OnFocusBlurPlugin(this, false); -#endif nsObjectLoadingContent::UnbindFromTree(aDeep, aNullParent); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); }