Bug 840409 part.7 Define new notification for IME of focus or selection change and handle them in widget::IMEHandler::NotifyIME() r=jimm, feedback=roc

This commit is contained in:
Masayuki Nakano 2013-02-25 13:00:06 +09:00
parent 649b4e4874
commit 9abe38168e
6 changed files with 27 additions and 12 deletions

View File

@ -102,7 +102,15 @@ typedef uint16_t Modifiers;
// NotificationToIME is shared by nsIMEStateManager and TextComposition. // NotificationToIME is shared by nsIMEStateManager and TextComposition.
enum NotificationToIME { enum NotificationToIME {
// XXX We should replace NOTIFY_IME_OF_CURSOR_POS_CHANGED with
// NOTIFY_IME_OF_SELECTION_CHANGE later.
NOTIFY_IME_OF_CURSOR_POS_CHANGED, NOTIFY_IME_OF_CURSOR_POS_CHANGED,
// An editable content is getting focus
NOTIFY_IME_OF_FOCUS,
// An editable content is losing focus
NOTIFY_IME_OF_BLUR,
// Selection in the focused editable content is changed
NOTIFY_IME_OF_SELECTION_CHANGE,
REQUEST_TO_COMMIT_COMPOSITION, REQUEST_TO_COMMIT_COMPOSITION,
REQUEST_TO_CANCEL_COMPOSITION REQUEST_TO_CANCEL_COMPOSITION
}; };

View File

@ -104,6 +104,14 @@ IMEHandler::NotifyIME(nsWindow* aWindow,
#ifdef NS_ENABLE_TSF #ifdef NS_ENABLE_TSF
if (sIsInTSFMode) { if (sIsInTSFMode) {
switch (aNotification) { switch (aNotification) {
case NOTIFY_IME_OF_SELECTION_CHANGE:
return nsTextStore::OnSelectionChange();
case NOTIFY_IME_OF_FOCUS:
return nsTextStore::OnFocusChange(true, aWindow,
aWindow->GetInputContext().mIMEState.mEnabled);
case NOTIFY_IME_OF_BLUR:
return nsTextStore::OnFocusChange(false, aWindow,
aWindow->GetInputContext().mIMEState.mEnabled);
case REQUEST_TO_COMMIT_COMPOSITION: case REQUEST_TO_COMMIT_COMPOSITION:
if (nsTextStore::IsComposingOn(aWindow)) { if (nsTextStore::IsComposingOn(aWindow)) {
nsTextStore::CommitComposition(false); nsTextStore::CommitComposition(false);

View File

@ -2817,9 +2817,7 @@ nsTextStore::OnFocusChange(bool aGotFocus,
GetIMEEnabledName(aIMEEnabled), sTsfThreadMgr, sTsfTextStore)); GetIMEEnabledName(aIMEEnabled), sTsfThreadMgr, sTsfTextStore));
// no change notifications if TSF is disabled // no change notifications if TSF is disabled
if (!sTsfThreadMgr || !sTsfTextStore) { NS_ENSURE_TRUE(sTsfThreadMgr && sTsfTextStore, NS_ERROR_NOT_AVAILABLE);
return NS_ERROR_NOT_AVAILABLE;
}
if (aGotFocus) { if (aGotFocus) {
bool bRet = sTsfTextStore->Create(aFocusedWidget, aIMEEnabled); bool bRet = sTsfTextStore->Create(aFocusedWidget, aIMEEnabled);

View File

@ -133,7 +133,7 @@ public:
static nsresult OnSelectionChange(void) static nsresult OnSelectionChange(void)
{ {
if (!sTsfTextStore) return NS_OK; NS_ENSURE_TRUE(sTsfTextStore, NS_ERROR_NOT_AVAILABLE);
return sTsfTextStore->OnSelectionChangeInternal(); return sTsfTextStore->OnSelectionChangeInternal();
} }

View File

@ -7467,17 +7467,14 @@ nsWindow::GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState)
return NS_OK; return NS_OK;
} }
#ifdef NS_ENABLE_TSF
NS_IMETHODIMP NS_IMETHODIMP
nsWindow::OnIMEFocusChange(bool aFocus) nsWindow::OnIMEFocusChange(bool aFocus)
{ {
nsresult rv = nsTextStore::OnFocusChange(aFocus, this, return IMEHandler::NotifyIME(this, aFocus ? NOTIFY_IME_OF_FOCUS :
mInputContext.mIMEState.mEnabled); NOTIFY_IME_OF_BLUR);
if (rv == NS_ERROR_NOT_AVAILABLE)
rv = NS_OK; // TSF is not enabled, maybe.
return rv;
} }
#ifdef NS_ENABLE_TSF
NS_IMETHODIMP NS_IMETHODIMP
nsWindow::OnIMETextChange(uint32_t aStart, nsWindow::OnIMETextChange(uint32_t aStart,
uint32_t aOldEnd, uint32_t aOldEnd,
@ -7485,13 +7482,15 @@ nsWindow::OnIMETextChange(uint32_t aStart,
{ {
return nsTextStore::OnTextChange(aStart, aOldEnd, aNewEnd); return nsTextStore::OnTextChange(aStart, aOldEnd, aNewEnd);
} }
#endif // #ifdef NS_ENABLE_TSF
NS_IMETHODIMP NS_IMETHODIMP
nsWindow::OnIMESelectionChange(void) nsWindow::OnIMESelectionChange(void)
{ {
return nsTextStore::OnSelectionChange(); return IMEHandler::NotifyIME(this, NOTIFY_IME_OF_SELECTION_CHANGE);
} }
#ifdef NS_ENABLE_TSF
nsIMEUpdatePreference nsIMEUpdatePreference
nsWindow::GetIMEUpdatePreference() nsWindow::GetIMEUpdatePreference()
{ {

View File

@ -176,10 +176,12 @@ public:
virtual nsTransparencyMode GetTransparencyMode(); virtual nsTransparencyMode GetTransparencyMode();
virtual void UpdateOpaqueRegion(const nsIntRegion& aOpaqueRegion); virtual void UpdateOpaqueRegion(const nsIntRegion& aOpaqueRegion);
#endif // MOZ_XUL #endif // MOZ_XUL
#ifdef NS_ENABLE_TSF
NS_IMETHOD OnIMEFocusChange(bool aFocus); NS_IMETHOD OnIMEFocusChange(bool aFocus);
#ifdef NS_ENABLE_TSF
NS_IMETHOD OnIMETextChange(uint32_t aStart, uint32_t aOldEnd, uint32_t aNewEnd); NS_IMETHOD OnIMETextChange(uint32_t aStart, uint32_t aOldEnd, uint32_t aNewEnd);
#endif // NS_ENABLE_TSF
NS_IMETHOD OnIMESelectionChange(void); NS_IMETHOD OnIMESelectionChange(void);
#ifdef NS_ENABLE_TSF
virtual nsIMEUpdatePreference GetIMEUpdatePreference(); virtual nsIMEUpdatePreference GetIMEUpdatePreference();
#endif // NS_ENABLE_TSF #endif // NS_ENABLE_TSF
NS_IMETHOD GetNonClientMargins(nsIntMargin &margins); NS_IMETHOD GetNonClientMargins(nsIntMargin &margins);