Bug 1175392 part.1 IMEContentObserver and TabParent should use IMEStateManager::NotifyIME() r=smaug

This commit is contained in:
Masayuki Nakano 2015-06-27 09:23:31 +09:00
parent c0075001d1
commit 8da507987c
4 changed files with 78 additions and 33 deletions

View File

@ -264,7 +264,7 @@ IMEContentObserver::NotifyIMEOfBlur()
// Anyway, as far as we know, IME doesn't try to query content when it loses
// focus. So, this may not cause any problem.
mIMEHasFocus = false;
widget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR), widget);
}
void
@ -513,7 +513,7 @@ IMEContentObserver::OnMouseButtonEvent(nsPresContext* aPresContext,
notification.mMouseButtonEventData.mButtons = aMouseEvent->buttons;
notification.mMouseButtonEventData.mModifiers = aMouseEvent->modifiers;
nsresult rv = mWidget->NotifyIME(notification);
nsresult rv = IMEStateManager::NotifyIME(notification, mWidget);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
@ -1659,7 +1659,8 @@ IMEContentObserver::FocusSetEvent::Run()
}
mIMEContentObserver->mIMEHasFocus = true;
mIMEContentObserver->mWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS));
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS),
mIMEContentObserver->mWidget);
return NS_OK;
}
@ -1704,7 +1705,7 @@ IMEContentObserver::SelectionChangeEvent::Run()
notification.mSelectionChangeData.mReversed = selection.mReply.mReversed;
notification.mSelectionChangeData.mCausedByComposition =
mCausedByComposition;
mIMEContentObserver->mWidget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, mIMEContentObserver->mWidget);
return NS_OK;
}
@ -1730,7 +1731,7 @@ IMEContentObserver::TextChangeEvent::Run()
notification.mTextChangeData.mNewEndOffset = mData.mAddedEndOffset;
notification.mTextChangeData.mCausedByComposition =
mData.mCausedOnlyByComposition;
mIMEContentObserver->mWidget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, mIMEContentObserver->mWidget);
return NS_OK;
}
@ -1750,8 +1751,8 @@ IMEContentObserver::PositionChangeEvent::Run()
return NS_OK;
}
mIMEContentObserver->mWidget->NotifyIME(
IMENotification(NOTIFY_IME_OF_POSITION_CHANGE));
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_POSITION_CHANGE),
mIMEContentObserver->mWidget);
return NS_OK;
}

View File

@ -169,6 +169,8 @@ GetNotifyIMEMessageName(IMEMessage aMessage)
return "NOTIFY_IME_OF_COMPOSITION_UPDATE";
case NOTIFY_IME_OF_POSITION_CHANGE:
return "NOTIFY_IME_OF_POSITION_CHANGE";
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
return "NOTIFY_IME_OF_MOUSE_BUTTON_EVENT";
case REQUEST_TO_COMMIT_COMPOSITION:
return "REQUEST_TO_COMMIT_COMPOSITION";
case REQUEST_TO_CANCEL_COMPOSITION:
@ -1092,21 +1094,24 @@ IMEStateManager::OnCompositionEventDiscarded(
// static
nsresult
IMEStateManager::NotifyIME(IMEMessage aMessage,
nsIWidget* aWidget)
nsIWidget* aWidget,
bool aOriginIsRemote)
{
nsRefPtr<TextComposition> composition;
if (aWidget && sTextCompositions) {
composition = sTextCompositions->GetCompositionFor(aWidget);
}
bool isSynthesizedForTests =
composition && composition->IsSynthesizedForTests();
return IMEStateManager::NotifyIME(IMENotification(aMessage), aWidget,
aOriginIsRemote);
}
// static
nsresult
IMEStateManager::NotifyIME(const IMENotification& aNotification,
nsIWidget* aWidget,
bool aOriginIsRemote)
{
MOZ_LOG(sISMLog, LogLevel::Info,
("ISM: IMEStateManager::NotifyIME(aMessage=%s, aWidget=0x%p), "
"composition=0x%p, composition->IsSynthesizedForTests()=%s",
GetNotifyIMEMessageName(aMessage), aWidget, composition.get(),
GetBoolName(isSynthesizedForTests)));
("ISM: IMEStateManager::NotifyIME(aNotification={ mMessage=%s }, "
"aWidget=0x%p, aOriginIsRemote=%s)",
GetNotifyIMEMessageName(aNotification.mMessage), aWidget,
GetBoolName(aOriginIsRemote)));
if (NS_WARN_IF(!aWidget)) {
MOZ_LOG(sISMLog, LogLevel::Error,
@ -1114,7 +1119,34 @@ IMEStateManager::NotifyIME(IMEMessage aMessage,
return NS_ERROR_INVALID_ARG;
}
switch (aMessage) {
switch (aNotification.mMessage) {
case NOTIFY_IME_OF_FOCUS:
case NOTIFY_IME_OF_BLUR:
case NOTIFY_IME_OF_SELECTION_CHANGE:
case NOTIFY_IME_OF_TEXT_CHANGE:
case NOTIFY_IME_OF_POSITION_CHANGE:
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
return aWidget->NotifyIME(aNotification);
default:
// Other notifications should be sent only when there is composition.
// So, we need to handle the others below.
break;
}
nsRefPtr<TextComposition> composition;
if (sTextCompositions) {
composition = sTextCompositions->GetCompositionFor(aWidget);
}
bool isSynthesizedForTests =
composition && composition->IsSynthesizedForTests();
MOZ_LOG(sISMLog, LogLevel::Info,
("ISM: IMEStateManager::NotifyIME(), composition=0x%p, "
"composition->IsSynthesizedForTests()=%s",
composition.get(), GetBoolName(isSynthesizedForTests)));
switch (aNotification.mMessage) {
case REQUEST_TO_COMMIT_COMPOSITION:
return composition ?
composition->RequestToCommit(aWidget, false) : NS_OK;
@ -1123,7 +1155,7 @@ IMEStateManager::NotifyIME(IMEMessage aMessage,
composition->RequestToCommit(aWidget, true) : NS_OK;
case NOTIFY_IME_OF_COMPOSITION_UPDATE:
return composition && !isSynthesizedForTests ?
aWidget->NotifyIME(IMENotification(aMessage)) : NS_OK;
aWidget->NotifyIME(aNotification) : NS_OK;
default:
MOZ_CRASH("Unsupported notification");
}
@ -1135,11 +1167,14 @@ IMEStateManager::NotifyIME(IMEMessage aMessage,
// static
nsresult
IMEStateManager::NotifyIME(IMEMessage aMessage,
nsPresContext* aPresContext)
nsPresContext* aPresContext,
bool aOriginIsRemote)
{
MOZ_LOG(sISMLog, LogLevel::Info,
("ISM: IMEStateManager::NotifyIME(aMessage=%s, aPresContext=0x%p)",
GetNotifyIMEMessageName(aMessage), aPresContext));
("ISM: IMEStateManager::NotifyIME(aMessage=%s, aPresContext=0x%p, "
"aOriginIsRemote=%s)",
GetNotifyIMEMessageName(aMessage), aPresContext,
GetBoolName(aOriginIsRemote)));
NS_ENSURE_TRUE(aPresContext, NS_ERROR_INVALID_ARG);
@ -1150,7 +1185,7 @@ IMEStateManager::NotifyIME(IMEMessage aMessage,
"nsPresContext"));
return NS_ERROR_NOT_AVAILABLE;
}
return NotifyIME(aMessage, widget);
return NotifyIME(aMessage, widget, aOriginIsRemote);
}
// static

View File

@ -33,6 +33,7 @@ class TextComposition;
class IMEStateManager
{
typedef widget::IMEMessage IMEMessage;
typedef widget::IMENotification IMENotification;
typedef widget::IMEState IMEState;
typedef widget::InputContext InputContext;
typedef widget::InputContextAction InputContextAction;
@ -140,8 +141,15 @@ public:
* Send a notification to IME. It depends on the IME or platform spec what
* will occur (or not occur).
*/
static nsresult NotifyIME(IMEMessage aMessage, nsIWidget* aWidget);
static nsresult NotifyIME(IMEMessage aMessage, nsPresContext* aPresContext);
static nsresult NotifyIME(const IMENotification& aNotification,
nsIWidget* aWidget,
bool aOriginIsRemote = false);
static nsresult NotifyIME(IMEMessage aMessage,
nsIWidget* aWidget,
bool aOriginIsRemote = false);
static nsresult NotifyIME(IMEMessage aMessage,
nsPresContext* aPresContext,
bool aOriginIsRemote = false);
static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
nsIContent* aContent);

View File

@ -22,6 +22,7 @@
#include "mozilla/EventStateManager.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/Hal.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/ipc/DocumentRendererParent.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "mozilla/layers/CompositorParent.h"
@ -1937,7 +1938,7 @@ TabParent::RecvNotifyIMEFocus(const bool& aFocus,
IMENotification notification(aFocus ? NOTIFY_IME_OF_FOCUS :
NOTIFY_IME_OF_BLUR);
mContentCache.AssignContent(aContentCache, &notification);
widget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, widget, true);
if (aFocus) {
*aPreference = widget->GetIMEUpdatePreference();
@ -1972,7 +1973,7 @@ TabParent::RecvNotifyIMETextChange(const ContentCache& aContentCache,
notification.mTextChangeData.mCausedByComposition = aCausedByComposition;
mContentCache.AssignContent(aContentCache, &notification);
widget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, widget, true);
return true;
}
@ -1988,7 +1989,7 @@ TabParent::RecvNotifyIMESelectedCompositionRect(
IMENotification notification(NOTIFY_IME_OF_COMPOSITION_UPDATE);
mContentCache.AssignContent(aContentCache, &notification);
widget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, widget, true);
return true;
}
@ -2011,7 +2012,7 @@ TabParent::RecvNotifyIMESelection(const ContentCache& aContentCache,
mContentCache.InitNotification(notification);
notification.mSelectionChangeData.mCausedByComposition =
aCausedByComposition;
widget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, widget, true);
}
return true;
}
@ -2039,7 +2040,7 @@ TabParent::RecvNotifyIMEMouseButtonEvent(
*aConsumedByIME = false;
return true;
}
nsresult rv = widget->NotifyIME(aIMENotification);
nsresult rv = IMEStateManager::NotifyIME(aIMENotification, widget, true);
*aConsumedByIME = rv == NS_SUCCESS_EVENT_CONSUMED;
return true;
}
@ -2058,7 +2059,7 @@ TabParent::RecvNotifyIMEPositionChange(const ContentCache& aContentCache)
const nsIMEUpdatePreference updatePreference =
widget->GetIMEUpdatePreference();
if (updatePreference.WantPositionChanged()) {
widget->NotifyIME(notification);
IMEStateManager::NotifyIME(notification, widget, true);
}
return true;
}