re-factor and focus event code to make it more clear. also don't do work to calculate return values that we ignore anyway when sending focus events. part 1 of bug 354768, r=cbarrett sr=pav

This commit is contained in:
joshmoz@gmail.com 2007-08-02 16:01:32 -07:00
Родитель 62240a4dd9
Коммит 4be4ddff3e
4 изменённых файлов: 42 добавлений и 53 удалений

Просмотреть файл

@ -2127,6 +2127,18 @@ NSEvent* globalDragEvent = nil;
} }
- (void)sendFocusEvent:(PRUint32)eventType
{
if (!mGeckoChild)
return;
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent focusGuiEvent(PR_TRUE, eventType, mGeckoChild);
focusGuiEvent.time = PR_IntervalNow();
mGeckoChild->DispatchEvent(&focusGuiEvent, status);
}
// We accept key and mouse events, so don't keep passing them up the chain. Allow // We accept key and mouse events, so don't keep passing them up the chain. Allow
// this to be a 'focussed' widget for event dispatch // this to be a 'focussed' widget for event dispatch
- (BOOL)acceptsFirstResponder - (BOOL)acceptsFirstResponder
@ -3967,8 +3979,7 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
if (!mGeckoChild) if (!mGeckoChild)
return NO; return NO;
nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, mGeckoChild); [self sendFocusEvent:NS_GOTFOCUS];
mGeckoChild->DispatchWindowEvent(event);
return [super becomeFirstResponder]; return [super becomeFirstResponder];
} }
@ -3979,10 +3990,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
// nil -- otherwise the keyboard focus can end up in the wrong NSView. // nil -- otherwise the keyboard focus can end up in the wrong NSView.
- (BOOL)resignFirstResponder - (BOOL)resignFirstResponder
{ {
if (mGeckoChild) { if (mGeckoChild)
nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, mGeckoChild); [self sendFocusEvent:NS_LOSTFOCUS];
mGeckoChild->DispatchWindowEvent(event);
}
return [super resignFirstResponder]; return [super resignFirstResponder];
} }
@ -4001,11 +4010,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
if (isMozWindow) if (isMozWindow)
[[self window] setSuppressMakeKeyFront:YES]; [[self window] setSuppressMakeKeyFront:YES];
nsGUIEvent focusEvent(PR_TRUE, NS_GOTFOCUS, mGeckoChild); [self sendFocusEvent:NS_GOTFOCUS];
mGeckoChild->DispatchWindowEvent(focusEvent); [self sendFocusEvent:NS_ACTIVATE];
nsGUIEvent activateEvent(PR_TRUE, NS_ACTIVATE, mGeckoChild);
mGeckoChild->DispatchWindowEvent(activateEvent);
if (isMozWindow) if (isMozWindow)
[[self window] setSuppressMakeKeyFront:NO]; [[self window] setSuppressMakeKeyFront:NO];
@ -4017,11 +4023,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
if (!mGeckoChild) if (!mGeckoChild)
return; return;
nsGUIEvent deactivateEvent(PR_TRUE, NS_DEACTIVATE, mGeckoChild); [self sendFocusEvent:NS_DEACTIVATE];
mGeckoChild->DispatchWindowEvent(deactivateEvent); [self sendFocusEvent:NS_LOSTFOCUS];
nsGUIEvent unfocusEvent(PR_TRUE, NS_LOSTFOCUS, mGeckoChild);
mGeckoChild->DispatchWindowEvent(unfocusEvent);
} }

Просмотреть файл

@ -93,8 +93,7 @@ class nsChildView;
} }
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind; - (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
- (void)windowDidResize:(NSNotification*)aNotification; - (void)windowDidResize:(NSNotification*)aNotification;
- (void)sendGotFocusAndActivate; - (void)sendFocusEvent:(PRUint32)eventType;
- (void)sendLostFocusAndDeactivate;
- (nsCocoaWindow*)geckoWidget; - (nsCocoaWindow*)geckoWidget;
@end @end

Просмотреть файл

@ -471,14 +471,16 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
mVisible = PR_TRUE; mVisible = PR_TRUE;
mSheetNeedsShow = PR_FALSE; mSheetNeedsShow = PR_FALSE;
mSheetWindowParent = topNonSheetWindow; mSheetWindowParent = topNonSheetWindow;
[[mSheetWindowParent delegate] sendLostFocusAndDeactivate]; [[mSheetWindowParent delegate] sendFocusEvent:NS_LOSTFOCUS];
[[mSheetWindowParent delegate] sendFocusEvent:NS_DEACTIVATE];
[mWindow setAcceptsMouseMovedEvents:YES]; [mWindow setAcceptsMouseMovedEvents:YES];
[NSApp beginSheet:mWindow [NSApp beginSheet:mWindow
modalForWindow:mSheetWindowParent modalForWindow:mSheetWindowParent
modalDelegate:mDelegate modalDelegate:mDelegate
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
contextInfo:mSheetWindowParent]; contextInfo:mSheetWindowParent];
[[mWindow delegate] sendGotFocusAndActivate]; [[mWindow delegate] sendFocusEvent:NS_GOTFOCUS];
[[mWindow delegate] sendFocusEvent:NS_ACTIVATE];
SendSetZLevelEvent(); SendSetZLevelEvent();
} }
} }
@ -538,7 +540,8 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
[mWindow setAcceptsMouseMovedEvents:NO]; [mWindow setAcceptsMouseMovedEvents:NO];
[[mWindow delegate] sendLostFocusAndDeactivate]; [[mWindow delegate] sendFocusEvent:NS_LOSTFOCUS];
[[mWindow delegate] sendFocusEvent:NS_DEACTIVATE];
nsCocoaWindow* siblingSheetToShow = nsnull; nsCocoaWindow* siblingSheetToShow = nsnull;
PRBool parentIsSheet = PR_FALSE; PRBool parentIsSheet = PR_FALSE;
@ -1247,37 +1250,15 @@ gfxASurface* nsCocoaWindow::GetThebesSurface()
} }
- (void)sendGotFocusAndActivate - (void)sendFocusEvent:(PRUint32)eventType
{ {
if (!mGeckoWindow) if (!mGeckoWindow)
return; return;
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent focusGuiEvent(PR_TRUE, eventType, mGeckoWindow);
nsGUIEvent focusGuiEvent(PR_TRUE, NS_GOTFOCUS, mGeckoWindow);
focusGuiEvent.time = PR_IntervalNow(); focusGuiEvent.time = PR_IntervalNow();
mGeckoWindow->DispatchEvent(&focusGuiEvent, status); mGeckoWindow->DispatchEvent(&focusGuiEvent, status);
nsGUIEvent activateGuiEvent(PR_TRUE, NS_ACTIVATE, mGeckoWindow);
activateGuiEvent.time = PR_IntervalNow();
mGeckoWindow->DispatchEvent(&activateGuiEvent, status);
}
- (void)sendLostFocusAndDeactivate
{
if (!mGeckoWindow)
return;
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent deactivateGuiEvent(PR_TRUE, NS_DEACTIVATE, mGeckoWindow);
deactivateGuiEvent.time = PR_IntervalNow();
mGeckoWindow->DispatchEvent(&deactivateGuiEvent, status);
nsGUIEvent lostfocusGuiEvent(PR_TRUE, NS_LOSTFOCUS, mGeckoWindow);
lostfocusGuiEvent.time = PR_IntervalNow();
mGeckoWindow->DispatchEvent(&lostfocusGuiEvent, status);
} }
@ -1286,9 +1267,11 @@ gfxASurface* nsCocoaWindow::GetThebesSurface()
// Note: 'contextInfo' is the window that is the parent of the sheet, // Note: 'contextInfo' is the window that is the parent of the sheet,
// we set that in nsCocoaWindow::Show. 'contextInfo' is always the top-level // we set that in nsCocoaWindow::Show. 'contextInfo' is always the top-level
// window, not another sheet itself. // window, not another sheet itself.
[[sheet delegate] sendLostFocusAndDeactivate]; [[sheet delegate] sendFocusEvent:NS_LOSTFOCUS];
[[sheet delegate] sendFocusEvent:NS_DEACTIVATE];
[sheet orderOut:self]; [sheet orderOut:self];
[[(NSWindow*)contextInfo delegate] sendGotFocusAndActivate]; [[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_GOTFOCUS];
[[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_ACTIVATE];
} }

Просмотреть файл

@ -149,8 +149,10 @@
} }
else { else {
id delegate = [window delegate]; id delegate = [window delegate];
if ([delegate respondsToSelector:@selector(sendGotFocusAndActivate)]) if ([delegate respondsToSelector:@selector(sendFocusEvent:)]) {
[delegate sendGotFocusAndActivate]; [delegate sendFocusEvent:NS_GOTFOCUS];
[delegate sendFocusEvent:NS_ACTIVATE];
}
} }
} }
@ -163,8 +165,10 @@
} }
else { else {
id delegate = [window delegate]; id delegate = [window delegate];
if ([delegate respondsToSelector:@selector(sendLostFocusAndDeactivate)]) if ([delegate respondsToSelector:@selector(sendFocusEvent:)]) {
[delegate sendLostFocusAndDeactivate]; [delegate sendFocusEvent:NS_LOSTFOCUS];
[delegate sendFocusEvent:NS_DEACTIVATE];
}
} }
} }