Fix window.focus() in content processes (bug 902715, r=enndeakin).

This commit is contained in:
David Anderson 2013-09-20 15:07:51 -07:00
parent cb8c6abbfb
commit 24ea11d9cc
4 changed files with 33 additions and 0 deletions

View File

@ -216,6 +216,7 @@
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
#include "mozilla/dom/FunctionBinding.h"
#include "mozilla/dom/WindowBinding.h"
#include "mozilla/dom/TabChild.h"
#ifdef MOZ_WEBSPEECH
#include "mozilla/dom/SpeechSynthesis.h"
@ -5713,6 +5714,9 @@ nsGlobalWindow::Focus()
return fm->SetFocus(frameElement, flags);
}
}
else if (TabChild *child = TabChild::GetFrom(this)) {
child->SendRequestFocus(canFocus);
}
else if (canFocus) {
// if there is no parent, this must be a toplevel window, so raise the
// window if canFocus is true

View File

@ -163,6 +163,12 @@ parent:
*/
sync EndIMEComposition(bool cancel) returns (nsString composition);
/**
* Request that the parent process move focus to the browser's frame. If
* canRaise is true, the window can be raised if it is inactive.
*/
RequestFocus(bool canRaise);
sync GetInputContext() returns (int32_t IMEEnabled, int32_t IMEOpen,
intptr_t NativeIMEContext);

View File

@ -895,6 +895,28 @@ TabParent::RecvNotifyIMETextHint(const nsString& aText)
return true;
}
bool
TabParent::RecvRequestFocus(const bool& aCanRaise)
{
nsCOMPtr<nsIFocusManager> fm = nsFocusManager::GetFocusManager();
if (!fm) {
return true;
}
nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
if (!content || !content->OwnerDoc()) {
return true;
}
uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
if (aCanRaise)
flags |= nsIFocusManager::FLAG_RAISE;
nsCOMPtr<nsIDOMElement> node = do_QueryInterface(mFrameElement);
fm->SetFocus(node, flags);
return true;
}
/**
* Try to answer query event using cached text.
*

View File

@ -145,6 +145,7 @@ public:
const nsString& aActionHint,
const int32_t& aCause,
const int32_t& aFocusChange);
virtual bool RecvRequestFocus(const bool& aCanRaise);
virtual bool RecvSetCursor(const uint32_t& aValue);
virtual bool RecvSetBackgroundColor(const nscolor& aValue);
virtual bool RecvSetStatus(const uint32_t& aType, const nsString& aStatus);