Bug 563321: Work around focus regression when creating new tabs. sr=pink
--- a/src/embedding/CHBrowserView.h
+++ b/src/embedding/CHBrowserView.h
@@ -204,16 +204,17 @@ extern const char* const kHTMLMIMEType;
@interface CHBrowserView : NSView
{
nsIWebBrowser* _webBrowser;
CHBrowserListener* _listener;
NSWindow* mWindow;
nsIPrintSettings* mPrintSettings; // we own this
BOOL mUseGlobalPrintSettings;
+ BOOL mHasPendingActivation;
}
// class method to get at the browser view for a given nsIDOMWindow
+ (CHBrowserView*)browserViewFromDOMWindow:(nsIDOMWindow*)inWindow;
// NSView overrides
- (id)initWithFrame:(NSRect)frame;
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow;
--- a/src/embedding/CHBrowserView.mm
+++ b/src/embedding/CHBrowserView.mm
@@ -450,16 +450,19 @@ const char* const kHTMLMIMEType = "text/
if (flags & NSLoadFlagsBypassClassifier) {
navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CLASSIFIER;
}
nsresult rv = nav->LoadURI(specStr.get(), navFlags, referrerURI, nsnull, nsnull);
if (NS_FAILED(rv)) {
// XXX need to throw
}
+
+ if (mHasPendingActivation && ([[self window] firstResponder] == self))
+ [self setActive:YES];
}
- (void)reload:(unsigned int)flags
{
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
if ( !nav )
return;
@@ -1503,24 +1506,37 @@ const char* const kHTMLMIMEType = "text/
[[self browserContainer] willShowPrompt];
}
- (void)doAfterPromptDismissal
{
[[self browserContainer] didDismissPrompt];
}
-- (void)setActive: (BOOL)aIsActive
+- (void)setActive:(BOOL)aIsActive
{
nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
if (wbf) {
- if (aIsActive)
+ if (aIsActive) {
+ // If presShell is NULL, core will get into a broken focus state, so
+ // defer the call until we have loaded something.
+ nsCOMPtr<nsIDocShell> docShell = [self docShell];
+ nsCOMPtr<nsIPresShell> presShell;
+ if (docShell)
+ docShell->GetPresShell(getter_AddRefs(presShell));
+ if (!presShell) {
+ mHasPendingActivation = YES;
+ return;
+ }
+
wbf->Activate();
- else
+ mHasPendingActivation = NO;
+ } else {
wbf->Deactivate();
+ }
}
}
-(NSMenu*)contextMenu
{
return [[self browserContainer] contextMenu];
}