backout bug 685073 part.1 due to random crash

This commit is contained in:
Masayuki Nakano 2011-10-01 10:10:43 +09:00
Родитель 62ce0593d1
Коммит b566a70e5a
2 изменённых файлов: 34 добавлений и 82 удалений

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

@ -482,19 +482,9 @@ protected:
// Whether keypress event was consumed by web contents or chrome contents.
bool mKeyPressHandled;
KeyEventState(NSEvent* aNativeKeyEvent) : mKeyEvent(nsnull)
KeyEventState() : mKeyEvent(nsnull)
{
Clear();
Set(aNativeKeyEvent);
}
KeyEventState(const KeyEventState &aOther) : mKeyEvent(nsnull)
{
Clear();
mKeyEvent = [aOther.mKeyEvent retain];
mKeyDownHandled = aOther.mKeyDownHandled;
mKeyPressDispatched = aOther.mKeyPressDispatched;
mKeyPressHandled = aOther.mKeyPressHandled;
}
~KeyEventState()
@ -524,11 +514,6 @@ protected:
{
return mKeyDownHandled || mKeyPressHandled;
}
protected:
KeyEventState()
{
}
};
/**
@ -544,40 +529,15 @@ protected:
~AutoKeyEventStateCleaner()
{
NS_ASSERTION(mHandler->mCurrentKeyEvents.Length() > 0,
"The key event was removed by manually?");
mHandler->mCurrentKeyEvents.RemoveElementAt(0);
mHandler->mCurrentKeyEvent.Clear();
}
private:
nsRefPtr<TextInputHandlerBase> mHandler;
TextInputHandlerBase* mHandler;
};
/**
* mCurrentKeyEvents stores all key events which are being processed.
* When we call interpretKeyEvents, IME may generate other key events.
* mCurrentKeyEvents[0] is the latest key event.
*/
nsTArray<KeyEventState> mCurrentKeyEvents;
/**
*
*/
KeyEventState* PushKeyEvent(NSEvent* aNativeKeyEvent)
{
KeyEventState keyEventState(aNativeKeyEvent);
return mCurrentKeyEvents.InsertElementAt(0, keyEventState);
}
/**
* GetCurrentKeyEvent() returns current processing key event.
*/
KeyEventState* GetCurrentKeyEvent()
{
if (mCurrentKeyEvents.Length() == 0) {
return nsnull;
}
return &mCurrentKeyEvents[0];
}
// XXX If keydown event was nested, the key event is overwritten by newer
// event. This is wrong behavior. Some IMEs are making such situation.
KeyEventState mCurrentKeyEvent;
/**
* IsPrintableChar() checks whether the unicode character is
@ -1159,8 +1119,7 @@ public:
*/
bool KeyPressWasHandled()
{
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
return currentKeyEvent && currentKeyEvent->mKeyPressHandled;
return mCurrentKeyEvent.mKeyPressHandled;
}
protected:

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

@ -997,7 +997,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
nsRefPtr<nsChildView> kungFuDeathGrip(mWidget);
KeyEventState* currentKeyEvent = PushKeyEvent(aNativeEvent);
mCurrentKeyEvent.Set(aNativeEvent);
AutoKeyEventStateCleaner remover(this);
BOOL nonDeadKeyPress = [[aNativeEvent characters] length] > 0;
@ -1015,12 +1015,12 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
}
#endif // #ifndef NP_NO_CARBON
currentKeyEvent->mKeyDownHandled = DispatchEvent(keydownEvent);
mCurrentKeyEvent.mKeyDownHandled = DispatchEvent(keydownEvent);
if (Destroyed()) {
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, "
"widget was destroyed by keydown event", this));
return currentKeyEvent->KeyDownOrPressHandled();
return mCurrentKeyEvent.KeyDownOrPressHandled();
}
// The key down event may have shifted the focus, in which
@ -1030,7 +1030,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, "
"view lost focus by keydown event", this));
return currentKeyEvent->KeyDownOrPressHandled();
return mCurrentKeyEvent.KeyDownOrPressHandled();
}
// If this is the context menu key command, send a context menu key event.
@ -1052,7 +1052,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
Destroyed() ? " and widget was destroyed" : ""));
[mView maybeInitContextMenuTracking];
// Bail, there is nothing else to do here.
return (cmEventHandled || currentKeyEvent->KeyDownOrPressHandled());
return (cmEventHandled || mCurrentKeyEvent.KeyDownOrPressHandled());
}
nsKeyEvent keypressEvent(PR_TRUE, NS_KEY_PRESS, mWidget);
@ -1066,16 +1066,16 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
// its owning shortcut key. See bug 477291.
if ((!keypressEvent.isChar || keypressEvent.isControl) &&
!IsIMEComposing()) {
if (currentKeyEvent->mKeyDownHandled) {
if (mCurrentKeyEvent.mKeyDownHandled) {
keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent);
currentKeyEvent->mKeyPressDispatched = PR_TRUE;
mCurrentKeyEvent.mKeyPressHandled = DispatchEvent(keypressEvent);
mCurrentKeyEvent.mKeyPressDispatched = PR_TRUE;
if (Destroyed()) {
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, "
"widget was destroyed by keypress event", this));
return currentKeyEvent->KeyDownOrPressHandled();
return mCurrentKeyEvent.KeyDownOrPressHandled();
}
}
}
@ -1098,7 +1098,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, widget was destroyed",
this));
return currentKeyEvent->KeyDownOrPressHandled();
return mCurrentKeyEvent.KeyDownOrPressHandled();
}
PR_LOG(gLog, PR_LOG_ALWAYS,
@ -1106,7 +1106,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
"IsIMEComposing()=%s",
this, TrueOrFalse(wasComposing), TrueOrFalse(IsIMEComposing())));
if (!currentKeyEvent->mKeyPressDispatched && nonDeadKeyPress &&
if (!mCurrentKeyEvent.mKeyPressDispatched && nonDeadKeyPress &&
!wasComposing && !IsIMEComposing()) {
nsKeyEvent keypressEvent(PR_TRUE, NS_KEY_PRESS, mWidget);
InitKeyEvent(aNativeEvent, keypressEvent);
@ -1124,10 +1124,10 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
// our default action for this key.
if (!(interpretKeyEventsCalled &&
IsNormalCharInputtingEvent(keypressEvent))) {
if (currentKeyEvent->mKeyDownHandled) {
if (mCurrentKeyEvent.mKeyDownHandled) {
keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent);
mCurrentKeyEvent.mKeyPressHandled = DispatchEvent(keypressEvent);
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, keypress event dispatched",
this));
@ -1139,9 +1139,9 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::HandleKeyDownEvent, "
"keydown handled=%s, keypress handled=%s",
this, TrueOrFalse(currentKeyEvent->mKeyDownHandled),
TrueOrFalse(currentKeyEvent->mKeyPressHandled)));
return currentKeyEvent->KeyDownOrPressHandled();
this, TrueOrFalse(mCurrentKeyEvent.mKeyDownHandled),
TrueOrFalse(mCurrentKeyEvent.mKeyPressHandled)));
return mCurrentKeyEvent.KeyDownOrPressHandled();
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
}
@ -1312,17 +1312,13 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
return;
}
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::InsertText, aAttrString=\"%s\", "
"IsIMEComposing()=%s, IgnoreIMEComposition()=%s, "
"keyevent=%p, keypressDispatched=%s",
this, GetCharacters([aAttrString string]), TrueOrFalse(IsIMEComposing()),
TrueOrFalse(IgnoreIMEComposition()),
currentKeyEvent ? currentKeyEvent->mKeyEvent : nsnull,
currentKeyEvent ?
TrueOrFalse(currentKeyEvent->mKeyPressDispatched) : "N/A"));
TrueOrFalse(IgnoreIMEComposition()), mCurrentKeyEvent.mKeyEvent,
TrueOrFalse(mCurrentKeyEvent.mKeyPressDispatched)));
if (IgnoreIMEComposition()) {
return;
@ -1341,7 +1337,7 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
// Don't let the same event be fired twice when hitting
// enter/return! (Bug 420502)
if (currentKeyEvent && currentKeyEvent->mKeyPressDispatched) {
if (mCurrentKeyEvent.mKeyPressDispatched) {
return;
}
@ -1363,8 +1359,8 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
EventRecord carbonEvent;
#endif // #ifndef NP_NO_CARBON
if (currentKeyEvent) {
NSEvent* keyEvent = currentKeyEvent->mKeyEvent;
if (mCurrentKeyEvent.mKeyEvent) {
NSEvent* keyEvent = mCurrentKeyEvent.mKeyEvent;
// XXX The ASCII characters inputting mode of egbridge (Japanese IME)
// might send the keyDown event with wrong keyboard layout if other
@ -1377,7 +1373,7 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
}
#endif // #ifndef NP_NO_CARBON
if (currentKeyEvent->mKeyDownHandled) {
if (mCurrentKeyEvent.mKeyDownHandled) {
keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
@ -1404,9 +1400,9 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
// Note: mWidget might have become null here. Don't count on it from here on.
if (currentKeyEvent) {
currentKeyEvent->mKeyPressHandled = keyPressHandled;
currentKeyEvent->mKeyPressDispatched = PR_TRUE;
if (mCurrentKeyEvent.mKeyEvent) {
mCurrentKeyEvent.mKeyPressHandled = keyPressHandled;
mCurrentKeyEvent.mKeyPressDispatched = PR_TRUE;
}
NS_OBJC_END_TRY_ABORT_BLOCK;
@ -1415,16 +1411,13 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
bool
TextInputHandler::DoCommandBySelector(const char* aSelector)
{
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandler::DoCommandBySelector, aSelector=\"%s\", "
"Destroyed()=%s, keypressHandled=%s",
this, aSelector ? aSelector : "", TrueOrFalse(Destroyed()),
currentKeyEvent ?
TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A"));
TrueOrFalse(mCurrentKeyEvent.mKeyPressHandled)));
return !Destroyed() && currentKeyEvent && currentKeyEvent->mKeyPressHandled;
return !Destroyed() && mCurrentKeyEvent.mKeyPressHandled;
}