Bug 573689 key events lost while page is loading r=smaug, sr=roc

This commit is contained in:
Masayuki Nakano
2010-07-03 15:27:09 +09:00
parent b1d29d8053
commit c10c5b10f8
2 changed files with 59 additions and 31 deletions

View File

@@ -97,6 +97,7 @@ class gfxContext;
class nsIDOMEvent;
class nsDisplayList;
class nsDisplayListBuilder;
class nsPIDOMWindow;
typedef short SelectionType;
typedef PRUint64 nsFrameState;
@@ -129,8 +130,8 @@ typedef struct CapturingContentInfo {
} CapturingContentInfo;
#define NS_IPRESSHELL_IID \
{ 0x7ae0e29f, 0x4d2e, 0x4acd, \
{ 0xb5, 0x74, 0xb6, 0x40, 0x8a, 0xca, 0xb8, 0x4d } }
{ 0x6b32e1ca, 0xb295, 0x406d, \
{ 0xb2, 0x8b, 0x73, 0xda, 0xc3, 0x66, 0xc2, 0xa7 } }
// Constants for ScrollContentIntoView() function
#define NS_PRESSHELL_SCROLL_TOP 0
@@ -1002,6 +1003,11 @@ public:
PRUint64 GetPaintCount() { return mPaintCount; }
void IncrementPaintCount() { ++mPaintCount; }
/**
* Get the root DOM window of this presShell.
*/
virtual already_AddRefed<nsPIDOMWindow> GetRootWindow() = 0;
/**
* Refresh observer management.
*/

View File

@@ -808,6 +808,8 @@ public:
nsIntPoint& aPoint,
nsIntRect* aScreenRect);
virtual already_AddRefed<nsPIDOMWindow> GetRootWindow();
//nsIViewObserver interface
NS_IMETHOD Paint(nsIView* aDisplayRoot,
@@ -1247,6 +1249,7 @@ protected:
private:
PRBool InZombieDocument(nsIContent *aContent);
already_AddRefed<nsIPresShell> GetParentPresShell();
nsresult RetargetEventToParent(nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
@@ -6013,7 +6016,50 @@ PRBool PresShell::InZombieDocument(nsIContent *aContent)
return !doc || !doc->GetWindow();
}
nsresult PresShell::RetargetEventToParent(nsGUIEvent* aEvent,
already_AddRefed<nsPIDOMWindow>
PresShell::GetRootWindow()
{
nsCOMPtr<nsPIDOMWindow> window =
do_QueryInterface(mDocument->GetWindow());
if (window) {
nsCOMPtr<nsPIDOMWindow> rootWindow = window->GetPrivateRoot();
NS_ASSERTION(rootWindow, "nsPIDOMWindow::GetPrivateRoot() returns NULL");
return rootWindow.forget();
}
// If we don't have DOM window, we're zombie, we should find the root window
// with our parent shell.
nsCOMPtr<nsIPresShell> parent = GetParentPresShell();
NS_ENSURE_TRUE(parent, nsnull);
return parent->GetRootWindow();
}
already_AddRefed<nsIPresShell>
PresShell::GetParentPresShell()
{
NS_ENSURE_TRUE(mPresContext, nsnull);
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
if (!container) {
container = do_QueryReferent(mForwardingContainer);
}
// Now, find the parent pres shell and send the event there
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(container);
// Might have gone away, or never been around to start with
NS_ENSURE_TRUE(treeItem, nsnull);
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
treeItem->GetParent(getter_AddRefs(parentTreeItem));
nsCOMPtr<nsIDocShell> parentDocShell = do_QueryInterface(parentTreeItem);
NS_ENSURE_TRUE(parentDocShell && treeItem != parentTreeItem, nsnull);
nsIPresShell* parentPresShell = nsnull;
parentDocShell->GetPresShell(&parentPresShell);
return parentPresShell;
}
nsresult
PresShell::RetargetEventToParent(nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
// Send this events straight up to the parent pres shell.
@@ -6022,28 +6068,8 @@ nsresult PresShell::RetargetEventToParent(nsGUIEvent* aEvent,
// That way at least the UI key bindings can work.
nsCOMPtr<nsIPresShell> kungFuDeathGrip(this);
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
if (!container)
container = do_QueryReferent(mForwardingContainer);
// Now, find the parent pres shell and send the event there
nsCOMPtr<nsIDocShellTreeItem> treeItem =
do_QueryInterface(container);
if (!treeItem) {
// Might have gone away, or never been around to start with
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
treeItem->GetParent(getter_AddRefs(parentTreeItem));
nsCOMPtr<nsIDocShell> parentDocShell =
do_QueryInterface(parentTreeItem);
if (!parentDocShell || treeItem == parentTreeItem) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresShell> parentPresShell;
parentDocShell->GetPresShell(getter_AddRefs(parentPresShell));
nsCOMPtr<nsIPresShell> parentPresShell = GetParentPresShell();
NS_ENSURE_TRUE(parentPresShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIViewObserver> parentViewObserver =
do_QueryInterface(parentPresShell);
if (!parentViewObserver) {
@@ -6069,11 +6095,7 @@ PresShell::DisableNonTestMouseEvents(PRBool aDisable)
already_AddRefed<nsPIDOMWindow>
PresShell::GetFocusedDOMWindowInOurWindow()
{
nsCOMPtr<nsPIDOMWindow> window =
do_QueryInterface(mDocument->GetWindow());
NS_ENSURE_TRUE(window, nsnull);
nsCOMPtr<nsPIDOMWindow> rootWindow = window->GetPrivateRoot();
nsCOMPtr<nsPIDOMWindow> rootWindow = GetRootWindow();
NS_ENSURE_TRUE(rootWindow, nsnull);
nsPIDOMWindow* focusedWindow;
nsFocusManager::GetFocusedDescendant(rootWindow, PR_TRUE, &focusedWindow);