mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1167022 part.4 Get rid of MozIMEFocus(In|Out) events r=smaug
This commit is contained in:
parent
e370b5e7e0
commit
91298b51a5
@ -43,7 +43,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(IMEContentObserver)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IMEContentObserver)
|
||||
nsAutoScriptBlocker scriptBlocker;
|
||||
|
||||
tmp->NotifyIMEOfBlur(true);
|
||||
tmp->NotifyIMEOfBlur();
|
||||
tmp->UnregisterObservers();
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWidget)
|
||||
@ -170,12 +170,6 @@ IMEContentObserver::Init(nsIWidget* aWidget,
|
||||
NS_ENSURE_TRUE_VOID(mRootContent);
|
||||
|
||||
if (firstInitialization) {
|
||||
if (IMEStateManager::IsTestingIME()) {
|
||||
nsIDocument* doc = aPresContext->Document();
|
||||
(new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusIn"),
|
||||
false, false))->RunDOMEventWhenSafe();
|
||||
}
|
||||
|
||||
aWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS));
|
||||
|
||||
// NOTIFY_IME_OF_FOCUS might cause recreating IMEContentObserver
|
||||
@ -220,7 +214,7 @@ IMEContentObserver::ObserveEditableNode()
|
||||
}
|
||||
|
||||
void
|
||||
IMEContentObserver::NotifyIMEOfBlur(bool aPostEvent)
|
||||
IMEContentObserver::NotifyIMEOfBlur()
|
||||
{
|
||||
// If this failed to initialize, mRootContent may be null, then, we
|
||||
// should not call NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR))
|
||||
@ -228,19 +222,6 @@ IMEContentObserver::NotifyIMEOfBlur(bool aPostEvent)
|
||||
return;
|
||||
}
|
||||
|
||||
if (IMEStateManager::IsTestingIME() && mEditableNode) {
|
||||
nsIDocument* doc = mEditableNode->OwnerDoc();
|
||||
if (doc) {
|
||||
nsRefPtr<AsyncEventDispatcher> dispatcher =
|
||||
new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusOut"),
|
||||
false, false);
|
||||
if (aPostEvent) {
|
||||
dispatcher->PostDOMEvent();
|
||||
} else {
|
||||
dispatcher->RunDOMEventWhenSafe();
|
||||
}
|
||||
}
|
||||
}
|
||||
// A test event handler might destroy the widget.
|
||||
if (mWidget) {
|
||||
mWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
|
||||
@ -282,7 +263,7 @@ IMEContentObserver::Destroy()
|
||||
{
|
||||
// WARNING: When you change this method, you have to check Unlink() too.
|
||||
|
||||
NotifyIMEOfBlur(false);
|
||||
NotifyIMEOfBlur();
|
||||
UnregisterObservers();
|
||||
|
||||
mEditor = nullptr;
|
||||
|
@ -160,10 +160,8 @@ private:
|
||||
void ObserveEditableNode();
|
||||
/**
|
||||
* NotifyIMEOfBlur() notifies IME of blur.
|
||||
* @param aPostEvent When true, DOM event will be posted to the thread.
|
||||
* Otherwise, dispatched when safe.
|
||||
*/
|
||||
void NotifyIMEOfBlur(bool aPostEvent);
|
||||
void NotifyIMEOfBlur();
|
||||
/**
|
||||
* UnregisterObservers() unregisters all listeners and observers.
|
||||
*/
|
||||
|
@ -180,7 +180,6 @@ GetNotifyIMEMessageName(IMEMessage aMessage)
|
||||
nsIContent* IMEStateManager::sContent = nullptr;
|
||||
nsPresContext* IMEStateManager::sPresContext = nullptr;
|
||||
bool IMEStateManager::sInstalledMenuKeyboardListener = false;
|
||||
bool IMEStateManager::sIsTestingIME = false;
|
||||
bool IMEStateManager::sIsGettingNewIMEState = false;
|
||||
|
||||
// sActiveIMEContentObserver points to the currently active IMEContentObserver.
|
||||
@ -1206,12 +1205,6 @@ IMEStateManager::CreateIMEContentObserver(nsIEditor* aEditor)
|
||||
return;
|
||||
}
|
||||
|
||||
static bool sInitializeIsTestingIME = true;
|
||||
if (sInitializeIsTestingIME) {
|
||||
Preferences::AddBoolVarCache(&sIsTestingIME, "test.IME", false);
|
||||
sInitializeIsTestingIME = false;
|
||||
}
|
||||
|
||||
MOZ_LOG(sISMLog, PR_LOG_DEBUG,
|
||||
("ISM: IMEStateManager::CreateIMEContentObserver() is creating an "
|
||||
"IMEContentObserver instance..."));
|
||||
|
@ -138,7 +138,6 @@ public:
|
||||
|
||||
static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
|
||||
nsIContent* aContent);
|
||||
static bool IsTestingIME() { return sIsTestingIME; }
|
||||
|
||||
protected:
|
||||
static nsresult OnChangeFocusInternal(nsPresContext* aPresContext,
|
||||
@ -162,7 +161,6 @@ protected:
|
||||
static nsIContent* sContent;
|
||||
static nsPresContext* sPresContext;
|
||||
static bool sInstalledMenuKeyboardListener;
|
||||
static bool sIsTestingIME;
|
||||
static bool sIsGettingNewIMEState;
|
||||
|
||||
class MOZ_STACK_CLASS GettingNewIMEStateBlocker final
|
||||
|
@ -145,6 +145,32 @@ const kIMEOpenSupported = false;
|
||||
|
||||
function runBasicTest(aIsEditable, aInDesignMode, aDescription)
|
||||
{
|
||||
var onIMEFocusBlurHandler = null;
|
||||
var TIPCallback = function(aTIP, aNotification) {
|
||||
switch (aNotification.type) {
|
||||
case "request-to-commit":
|
||||
aTIP.commitComposition();
|
||||
break;
|
||||
case "request-to-cancel":
|
||||
aTIP.cancelComposition();
|
||||
break;
|
||||
case "notify-focus":
|
||||
case "notify-blur":
|
||||
if (onIMEFocusBlurHandler) {
|
||||
onIMEFocusBlurHandler(aNotification);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
var TIP = Components.classes["@mozilla.org/text-input-processor;1"]
|
||||
.createInstance(Components.interfaces.nsITextInputProcessor);
|
||||
if (!TIP.beginInputTransactionForTests(window, TIPCallback)) {
|
||||
ok(false, "runBasicTest(): failed to begin input transaction");
|
||||
return;
|
||||
}
|
||||
|
||||
function test(aTest)
|
||||
{
|
||||
function moveFocus(aTest, aFocusEventHandler)
|
||||
@ -171,22 +197,12 @@ function runBasicTest(aIsEditable, aInDesignMode, aDescription)
|
||||
}
|
||||
|
||||
focusEventTarget.addEventListener("focus", aFocusEventHandler, true);
|
||||
document.addEventListener("MozIMEFocusIn", aFocusEventHandler, true);
|
||||
document.addEventListener("MozIMEFocusOut", aFocusEventHandler, true);
|
||||
if (subDocument) {
|
||||
subDocument.addEventListener("MozIMEFocusIn", aFocusEventHandler, true);
|
||||
subDocument.addEventListener("MozIMEFocusOut", aFocusEventHandler, true);
|
||||
}
|
||||
onIMEFocusBlurHandler = aFocusEventHandler;
|
||||
|
||||
element.focus();
|
||||
|
||||
focusEventTarget.removeEventListener("focus", aFocusEventHandler, true);
|
||||
document.removeEventListener("MozIMEFocusIn", aFocusEventHandler, true);
|
||||
document.removeEventListener("MozIMEFocusOut", aFocusEventHandler, true);
|
||||
if (element.contentDocument) {
|
||||
subDocument.removeEventListener("MozIMEFocusIn", aFocusEventHandler, true);
|
||||
subDocument.removeEventListener("MozIMEFocusOut", aFocusEventHandler, true);
|
||||
}
|
||||
onIMEFocusBlurHandler = null;
|
||||
|
||||
var focusedElement = gFM.focusedElement;
|
||||
if (focusedElement) {
|
||||
@ -222,8 +238,8 @@ function runBasicTest(aIsEditable, aInDesignMode, aDescription)
|
||||
var enabled = gUtils.IME_STATUS_ENABLED;
|
||||
if (kIMEEnabledSupported) {
|
||||
var focusEventCount = 0;
|
||||
var mozIMEFocusInCount = 0;
|
||||
var mozIMEFocusOutCount = 0;
|
||||
var IMEReceivesFocus = 0;
|
||||
var IMEReceivesBlur = 0;
|
||||
var IMEHasFocus = false;
|
||||
|
||||
function onFocus(aEvent)
|
||||
@ -234,29 +250,29 @@ function runBasicTest(aIsEditable, aInDesignMode, aDescription)
|
||||
is(gUtils.IMEStatus, aTest.expectedEnabled,
|
||||
aDescription + ": " + aTest.description + ", wrong enabled state at focus event");
|
||||
break;
|
||||
case "MozIMEFocusIn":
|
||||
mozIMEFocusInCount++;
|
||||
case "notify-focus":
|
||||
IMEReceivesFocus++;
|
||||
IMEHasFocus = true;
|
||||
is(gUtils.IMEStatus, aTest.expectedEnabled,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusIn event must be fired after IME state is updated");
|
||||
", IME should receive a focus notification after IME state is updated");
|
||||
break;
|
||||
case "MozIMEFocusOut":
|
||||
mozIMEFocusOutCount++;
|
||||
case "notify-blur":
|
||||
IMEReceivesBlur++;
|
||||
IMEHasFocus = false;
|
||||
var changingStatus = !(aIsEditable && aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED);
|
||||
if (aTest.toDesignModeEditor) {
|
||||
is(gUtils.IME_STATUS_ENABLED, aTest.expectedEnabled,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event must be fired after IME state is updated");
|
||||
", IME should receive a blur notification after IME state is updated");
|
||||
} else if (changingStatus) {
|
||||
isnot(gUtils.IMEStatus, aTest.expectedEnabled,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event must be fired before IME state is updated");
|
||||
", IME should receive a blur notification before IME state is updated");
|
||||
} else {
|
||||
is(gUtils.IMEStatus, aTest.expectedEnabled,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event must be fired with expected IME state if the state isn't being changed");
|
||||
", IME should receive a blur notification and its context has expected IME state if the state isn't being changed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -271,42 +287,42 @@ function runBasicTest(aIsEditable, aInDesignMode, aDescription)
|
||||
ok(focusEventCount > 0,
|
||||
aDescription + ": " + aTest.description + ", focus event is never fired");
|
||||
if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED || aTest.expectedEnabled == gUtils.IME_STATUS_PASSWORD) {
|
||||
ok(mozIMEFocusInCount > 0,
|
||||
aDescription + ": " + aTest.description + ", MozIMEFocusIn event should be fired");
|
||||
ok(IMEReceivesFocus > 0,
|
||||
aDescription + ": " + aTest.description + ", IME should receive a focus notification");
|
||||
if (aInDesignMode && !aTest.toDesignModeEditor) {
|
||||
is(mozIMEFocusOutCount, 0,
|
||||
is(IMEReceivesBlur, 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event shouldn't be fired in designMode since focus isn't moved from another editor");
|
||||
", IME shouldn't receive a blur notification in designMode since focus isn't moved from another editor");
|
||||
} else {
|
||||
ok(mozIMEFocusOutCount > 0,
|
||||
ok(IMEReceivesBlur > 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event should be fired for the previous focused editor");
|
||||
", IME should receive a blur notification for the previous focused editor");
|
||||
}
|
||||
ok(IMEHasFocus,
|
||||
aDescription + ": " + aTest.description +
|
||||
", The latest MozIMEFocus* event must be MozIMEFocusIn");
|
||||
", IME should have focus right now");
|
||||
} else {
|
||||
is(mozIMEFocusInCount, 0,
|
||||
is(IMEReceivesFocus, 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusIn event shouldn't be fired");
|
||||
ok(mozIMEFocusOutCount > 0,
|
||||
", IME shouldn't receive a focus notification");
|
||||
ok(IMEReceivesBlur > 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event should be fired");
|
||||
", IME should receive a blur notification");
|
||||
ok(!IMEHasFocus,
|
||||
aDescription + ": " + aTest.description +
|
||||
", The latest MozIMEFocus* event must be MozIMEFocusOut");
|
||||
", IME shouldn't have focus right now");
|
||||
}
|
||||
} else {
|
||||
todo(focusEventCount > 0,
|
||||
aDescription + ": " + aTest.description + ", focus event should be fired");
|
||||
}
|
||||
} else {
|
||||
is(mozIMEFocusInCount, 0,
|
||||
is(IMEReceivesFocus, 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusIn event shouldn't be fired at testing non-focusable element");
|
||||
is(mozIMEFocusOutCount, 0,
|
||||
", IME shouldn't receive a focus notification at testing non-focusable element");
|
||||
is(IMEReceivesBlur, 0,
|
||||
aDescription + ": " + aTest.description +
|
||||
", MozIMEFocusOut event shouldn't be fired at testing non-focusable element");
|
||||
", IME shouldn't receive a blur notification at testing non-focusable element");
|
||||
}
|
||||
|
||||
enabled = gUtils.IMEStatus;
|
||||
@ -1449,7 +1465,6 @@ function runTests()
|
||||
if (!kIMEEnabledSupported && !kIMEOpenSupported)
|
||||
return;
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set":[["test.IME", true]]}, function() {
|
||||
// test for normal contents.
|
||||
runBasicTest(false, false, "Testing of normal contents");
|
||||
|
||||
@ -1499,7 +1514,6 @@ function runTests()
|
||||
// This will call onFinish(), so, this test must be the last.
|
||||
runEditableSubframeTests();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onFinish()
|
||||
|
Loading…
Reference in New Issue
Block a user