зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
62240a4dd9
Коммит
4be4ddff3e
|
@ -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
|
||||
// this to be a 'focussed' widget for event dispatch
|
||||
- (BOOL)acceptsFirstResponder
|
||||
|
@ -3967,8 +3979,7 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
|
|||
if (!mGeckoChild)
|
||||
return NO;
|
||||
|
||||
nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(event);
|
||||
[self sendFocusEvent:NS_GOTFOCUS];
|
||||
|
||||
return [super becomeFirstResponder];
|
||||
}
|
||||
|
@ -3979,10 +3990,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
|
|||
// nil -- otherwise the keyboard focus can end up in the wrong NSView.
|
||||
- (BOOL)resignFirstResponder
|
||||
{
|
||||
if (mGeckoChild) {
|
||||
nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(event);
|
||||
}
|
||||
if (mGeckoChild)
|
||||
[self sendFocusEvent:NS_LOSTFOCUS];
|
||||
|
||||
return [super resignFirstResponder];
|
||||
}
|
||||
|
@ -4001,11 +4010,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
|
|||
if (isMozWindow)
|
||||
[[self window] setSuppressMakeKeyFront:YES];
|
||||
|
||||
nsGUIEvent focusEvent(PR_TRUE, NS_GOTFOCUS, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(focusEvent);
|
||||
|
||||
nsGUIEvent activateEvent(PR_TRUE, NS_ACTIVATE, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(activateEvent);
|
||||
[self sendFocusEvent:NS_GOTFOCUS];
|
||||
[self sendFocusEvent:NS_ACTIVATE];
|
||||
|
||||
if (isMozWindow)
|
||||
[[self window] setSuppressMakeKeyFront:NO];
|
||||
|
@ -4017,11 +4023,8 @@ static PRBool IsSpecialGeckoKey(UInt32 macKeyCode)
|
|||
if (!mGeckoChild)
|
||||
return;
|
||||
|
||||
nsGUIEvent deactivateEvent(PR_TRUE, NS_DEACTIVATE, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(deactivateEvent);
|
||||
|
||||
nsGUIEvent unfocusEvent(PR_TRUE, NS_LOSTFOCUS, mGeckoChild);
|
||||
mGeckoChild->DispatchWindowEvent(unfocusEvent);
|
||||
[self sendFocusEvent:NS_DEACTIVATE];
|
||||
[self sendFocusEvent:NS_LOSTFOCUS];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,8 +93,7 @@ class nsChildView;
|
|||
}
|
||||
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind;
|
||||
- (void)windowDidResize:(NSNotification*)aNotification;
|
||||
- (void)sendGotFocusAndActivate;
|
||||
- (void)sendLostFocusAndDeactivate;
|
||||
- (void)sendFocusEvent:(PRUint32)eventType;
|
||||
- (nsCocoaWindow*)geckoWidget;
|
||||
@end
|
||||
|
||||
|
|
|
@ -471,14 +471,16 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
|
|||
mVisible = PR_TRUE;
|
||||
mSheetNeedsShow = PR_FALSE;
|
||||
mSheetWindowParent = topNonSheetWindow;
|
||||
[[mSheetWindowParent delegate] sendLostFocusAndDeactivate];
|
||||
[[mSheetWindowParent delegate] sendFocusEvent:NS_LOSTFOCUS];
|
||||
[[mSheetWindowParent delegate] sendFocusEvent:NS_DEACTIVATE];
|
||||
[mWindow setAcceptsMouseMovedEvents:YES];
|
||||
[NSApp beginSheet:mWindow
|
||||
modalForWindow:mSheetWindowParent
|
||||
modalDelegate:mDelegate
|
||||
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
||||
contextInfo:mSheetWindowParent];
|
||||
[[mWindow delegate] sendGotFocusAndActivate];
|
||||
[[mWindow delegate] sendFocusEvent:NS_GOTFOCUS];
|
||||
[[mWindow delegate] sendFocusEvent:NS_ACTIVATE];
|
||||
SendSetZLevelEvent();
|
||||
}
|
||||
}
|
||||
|
@ -538,7 +540,8 @@ NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
|
|||
|
||||
[mWindow setAcceptsMouseMovedEvents:NO];
|
||||
|
||||
[[mWindow delegate] sendLostFocusAndDeactivate];
|
||||
[[mWindow delegate] sendFocusEvent:NS_LOSTFOCUS];
|
||||
[[mWindow delegate] sendFocusEvent:NS_DEACTIVATE];
|
||||
|
||||
nsCocoaWindow* siblingSheetToShow = nsnull;
|
||||
PRBool parentIsSheet = PR_FALSE;
|
||||
|
@ -1247,37 +1250,15 @@ gfxASurface* nsCocoaWindow::GetThebesSurface()
|
|||
}
|
||||
|
||||
|
||||
- (void)sendGotFocusAndActivate
|
||||
- (void)sendFocusEvent:(PRUint32)eventType
|
||||
{
|
||||
if (!mGeckoWindow)
|
||||
return;
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
|
||||
nsGUIEvent focusGuiEvent(PR_TRUE, NS_GOTFOCUS, mGeckoWindow);
|
||||
nsGUIEvent focusGuiEvent(PR_TRUE, eventType, mGeckoWindow);
|
||||
focusGuiEvent.time = PR_IntervalNow();
|
||||
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,
|
||||
// we set that in nsCocoaWindow::Show. 'contextInfo' is always the top-level
|
||||
// window, not another sheet itself.
|
||||
[[sheet delegate] sendLostFocusAndDeactivate];
|
||||
[[sheet delegate] sendFocusEvent:NS_LOSTFOCUS];
|
||||
[[sheet delegate] sendFocusEvent:NS_DEACTIVATE];
|
||||
[sheet orderOut:self];
|
||||
[[(NSWindow*)contextInfo delegate] sendGotFocusAndActivate];
|
||||
[[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_GOTFOCUS];
|
||||
[[(NSWindow*)contextInfo delegate] sendFocusEvent:NS_ACTIVATE];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -149,8 +149,10 @@
|
|||
}
|
||||
else {
|
||||
id delegate = [window delegate];
|
||||
if ([delegate respondsToSelector:@selector(sendGotFocusAndActivate)])
|
||||
[delegate sendGotFocusAndActivate];
|
||||
if ([delegate respondsToSelector:@selector(sendFocusEvent:)]) {
|
||||
[delegate sendFocusEvent:NS_GOTFOCUS];
|
||||
[delegate sendFocusEvent:NS_ACTIVATE];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,8 +165,10 @@
|
|||
}
|
||||
else {
|
||||
id delegate = [window delegate];
|
||||
if ([delegate respondsToSelector:@selector(sendLostFocusAndDeactivate)])
|
||||
[delegate sendLostFocusAndDeactivate];
|
||||
if ([delegate respondsToSelector:@selector(sendFocusEvent:)]) {
|
||||
[delegate sendFocusEvent:NS_LOSTFOCUS];
|
||||
[delegate sendFocusEvent:NS_DEACTIVATE];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче