Bug 1052343 part.2 Don't assume that there is nsTextStore instance even during in TSF mode r=emk

This commit is contained in:
Masayuki Nakano 2014-09-02 09:27:25 +09:00
parent 4a049f8136
commit bc41125f3f
4 changed files with 36 additions and 26 deletions

View File

@ -289,7 +289,7 @@ IMEHandler::SetInputContext(nsWindow* aWindow,
if (sIsInTSFMode) { if (sIsInTSFMode) {
nsTextStore::SetInputContext(aWindow, aInputContext, aAction); nsTextStore::SetInputContext(aWindow, aInputContext, aAction);
if (IsTSFAvailable()) { if (IsTSFAvailable()) {
aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager();
if (sIsIMMEnabled) { if (sIsIMMEnabled) {
// Associate IME context for IMM-IMEs. // Associate IME context for IMM-IMEs.
AssociateIMEContext(aWindow, enable); AssociateIMEContext(aWindow, enable);
@ -354,7 +354,7 @@ IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext)
nsTextStore::SetInputContext(aWindow, aInputContext, nsTextStore::SetInputContext(aWindow, aInputContext,
InputContextAction(InputContextAction::CAUSE_UNKNOWN, InputContextAction(InputContextAction::CAUSE_UNKNOWN,
InputContextAction::GOT_FOCUS)); InputContextAction::GOT_FOCUS));
aInputContext.mNativeIMEContext = nsTextStore::GetTextStore(); aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager();
MOZ_ASSERT(aInputContext.mNativeIMEContext); MOZ_ASSERT(aInputContext.mNativeIMEContext);
// IME context isn't necessary in pure TSF mode. // IME context isn't necessary in pure TSF mode.
if (!sIsIMMEnabled) { if (!sIsIMMEnabled) {

View File

@ -3669,7 +3669,7 @@ nsTextStore::OnFocusChange(bool aGotFocus,
sTsfThreadMgr, sEnabledTextStore)); sTsfThreadMgr, sEnabledTextStore));
// no change notifications if TSF is disabled // no change notifications if TSF is disabled
NS_ENSURE_TRUE(sTsfThreadMgr && sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); NS_ENSURE_TRUE(IsInTSFMode(), NS_ERROR_NOT_AVAILABLE);
nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr; nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr;
if (aGotFocus && aIMEState.IsEditable()) { if (aGotFocus && aIMEState.IsEditable()) {
@ -4208,12 +4208,17 @@ nsTextStore::SetInputContext(nsWindowBase* aWidget,
PR_LOG(sTextStoreLog, PR_LOG_DEBUG, PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
("TSF: nsTextStore::SetInputContext(aWidget=%p, " ("TSF: nsTextStore::SetInputContext(aWidget=%p, "
"aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), " "aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), "
"ThinksHavingFocus()=%s", "sEnabledTextStore=0x%p, ThinksHavingFocus()=%s",
aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled), aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled),
GetFocusChangeName(aAction.mFocusChange), GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore,
GetBoolName(ThinksHavingFocus()))); GetBoolName(ThinksHavingFocus())));
NS_ENSURE_TRUE_VOID(sEnabledTextStore); NS_ENSURE_TRUE_VOID(IsInTSFMode());
if (!sEnabledTextStore) {
return;
}
sEnabledTextStore->SetInputScope(aContext.mHTMLInputType); sEnabledTextStore->SetInputScope(aContext.mHTMLInputType);
if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) { if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {

View File

@ -134,9 +134,11 @@ public:
static void CommitComposition(bool aDiscard) static void CommitComposition(bool aDiscard)
{ {
NS_ENSURE_TRUE_VOID(sEnabledTextStore); NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
if (sEnabledTextStore) {
sEnabledTextStore->CommitCompositionInternal(aDiscard); sEnabledTextStore->CommitCompositionInternal(aDiscard);
} }
}
static void SetInputContext(nsWindowBase* aWidget, static void SetInputContext(nsWindowBase* aWidget,
const InputContext& aContext, const InputContext& aContext,
@ -147,28 +149,30 @@ public:
const IMEState& aIMEState); const IMEState& aIMEState);
static nsresult OnTextChange(const IMENotification& aIMENotification) static nsresult OnTextChange(const IMENotification& aIMENotification)
{ {
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore->OnTextChangeInternal(aIMENotification); return sEnabledTextStore ?
sEnabledTextStore->OnTextChangeInternal(aIMENotification) : NS_OK;
} }
static nsresult OnSelectionChange(void) static nsresult OnSelectionChange(void)
{ {
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore->OnSelectionChangeInternal(); return sEnabledTextStore ?
sEnabledTextStore->OnSelectionChangeInternal() : NS_OK;
} }
static nsresult OnLayoutChange() static nsresult OnLayoutChange()
{ {
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore->OnLayoutChangeInternal(); return sEnabledTextStore ?
sEnabledTextStore->OnLayoutChangeInternal() : NS_OK;
} }
static nsresult OnMouseButtonEvent(const IMENotification& aIMENotification) static nsresult OnMouseButtonEvent(const IMENotification& aIMENotification)
{ {
if (NS_WARN_IF(!sEnabledTextStore)) { NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return NS_ERROR_NOT_AVAILABLE; return sEnabledTextStore ?
} sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification) : NS_OK;
return sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification);
} }
static nsIMEUpdatePreference GetIMEUpdatePreference(); static nsIMEUpdatePreference GetIMEUpdatePreference();
@ -195,9 +199,9 @@ public:
return sMessagePump; return sMessagePump;
} }
static void* GetTextStore() static void* GetThreadManager()
{ {
return static_cast<void*>(sEnabledTextStore); return static_cast<void*>(sTsfThreadMgr);
} }
static bool ThinksHavingFocus() static bool ThinksHavingFocus()

View File

@ -1542,6 +1542,7 @@ NS_IMETHODIMP_(void)
MetroWidget::SetInputContext(const InputContext& aContext, MetroWidget::SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) const InputContextAction& aAction)
{ {
// XXX This should set mInputContext.mNativeIMEContext properly
mInputContext = aContext; mInputContext = aContext;
nsTextStore::SetInputContext(this, mInputContext, aAction); nsTextStore::SetInputContext(this, mInputContext, aAction);
bool enable = (mInputContext.mIMEState.mEnabled == IMEState::ENABLED || bool enable = (mInputContext.mIMEState.mEnabled == IMEState::ENABLED ||