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

View File

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

View File

@ -134,8 +134,10 @@ public:
static void CommitComposition(bool aDiscard)
{
NS_ENSURE_TRUE_VOID(sEnabledTextStore);
sEnabledTextStore->CommitCompositionInternal(aDiscard);
NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
if (sEnabledTextStore) {
sEnabledTextStore->CommitCompositionInternal(aDiscard);
}
}
static void SetInputContext(nsWindowBase* aWidget,
@ -147,28 +149,30 @@ public:
const IMEState& aIMEState);
static nsresult OnTextChange(const IMENotification& aIMENotification)
{
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
return sEnabledTextStore->OnTextChangeInternal(aIMENotification);
NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore ?
sEnabledTextStore->OnTextChangeInternal(aIMENotification) : NS_OK;
}
static nsresult OnSelectionChange(void)
{
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
return sEnabledTextStore->OnSelectionChangeInternal();
NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore ?
sEnabledTextStore->OnSelectionChangeInternal() : NS_OK;
}
static nsresult OnLayoutChange()
{
NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
return sEnabledTextStore->OnLayoutChangeInternal();
NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore ?
sEnabledTextStore->OnLayoutChangeInternal() : NS_OK;
}
static nsresult OnMouseButtonEvent(const IMENotification& aIMENotification)
{
if (NS_WARN_IF(!sEnabledTextStore)) {
return NS_ERROR_NOT_AVAILABLE;
}
return sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification);
NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
return sEnabledTextStore ?
sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification) : NS_OK;
}
static nsIMEUpdatePreference GetIMEUpdatePreference();
@ -195,32 +199,32 @@ public:
return sMessagePump;
}
static void* GetTextStore()
static void* GetThreadManager()
{
return static_cast<void*>(sEnabledTextStore);
return static_cast<void*>(sTsfThreadMgr);
}
static bool ThinksHavingFocus()
static bool ThinksHavingFocus()
{
return (sEnabledTextStore && sEnabledTextStore->mContext);
}
static bool IsInTSFMode()
static bool IsInTSFMode()
{
return sTsfThreadMgr != nullptr;
}
static bool IsComposing()
static bool IsComposing()
{
return (sEnabledTextStore && sEnabledTextStore->mComposition.IsComposing());
}
static bool IsComposingOn(nsWindowBase* aWidget)
static bool IsComposingOn(nsWindowBase* aWidget)
{
return (IsComposing() && sEnabledTextStore->mWidget == aWidget);
}
static bool IsIMM_IME()
static bool IsIMM_IME()
{
if (!sEnabledTextStore ||
!sEnabledTextStore->EnsureInitActiveTIPKeyboard()) {
@ -229,7 +233,7 @@ public:
return sEnabledTextStore->mIsIMM_IME;
}
static bool IsIMM_IME(HKL aHKL)
static bool IsIMM_IME(HKL aHKL)
{
return (::ImmGetIMEFileNameW(aHKL, nullptr, 0) > 0);
}

View File

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