Bug 685395 part.2 Move IMEContext to mozilla::widget::InputContext r=roc

This commit is contained in:
Masayuki Nakano 2011-11-27 20:51:52 +09:00
parent 235ae0ff7d
commit cbcebd2356
23 changed files with 236 additions and 185 deletions

View File

@ -212,6 +212,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
using namespace mozilla::dom;
using namespace mozilla::layers;
using namespace mozilla::widget;
using namespace mozilla;
const char kLoadAsData[] = "loadAsData";
@ -4032,16 +4033,16 @@ nsContentUtils::GetWidgetStatusFromIMEStatus(PRUint32 aState)
{
switch (aState & nsIContent::IME_STATUS_MASK_ENABLED) {
case nsIContent::IME_STATUS_DISABLE:
return nsIWidget::IME_STATUS_DISABLED;
return InputContext::IME_DISABLED;
case nsIContent::IME_STATUS_ENABLE:
return nsIWidget::IME_STATUS_ENABLED;
return InputContext::IME_ENABLED;
case nsIContent::IME_STATUS_PASSWORD:
return nsIWidget::IME_STATUS_PASSWORD;
return InputContext::IME_PASSWORD;
case nsIContent::IME_STATUS_PLUGIN:
return nsIWidget::IME_STATUS_PLUGIN;
return InputContext::IME_PLUGIN;
default:
NS_ERROR("The given state doesn't have valid enable state");
return nsIWidget::IME_STATUS_ENABLED;
return InputContext::IME_ENABLED;
}
}

View File

@ -68,6 +68,8 @@
#include "nsIForm.h"
#include "nsHTMLFormElement.h"
using namespace mozilla::widget;
/******************************************************************/
/* nsIMEStateManager */
/******************************************************************/
@ -88,7 +90,7 @@ nsIMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
nsCOMPtr<nsIWidget> widget = GetWidget(sPresContext);
if (widget) {
PRUint32 newState = GetNewIMEState(sPresContext, nsnull);
SetIMEState(newState, nsnull, widget, IMEContext::FOCUS_REMOVED);
SetIMEState(newState, nsnull, widget, InputContext::FOCUS_REMOVED);
}
sContent = nsnull;
sPresContext = nsnull;
@ -113,7 +115,7 @@ nsIMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
if (NS_FAILED(rv))
widget->ResetInputState();
PRUint32 newState = GetNewIMEState(sPresContext, nsnull);
SetIMEState(newState, nsnull, widget, IMEContext::FOCUS_REMOVED);
SetIMEState(newState, nsnull, widget, InputContext::FOCUS_REMOVED);
}
sContent = nsnull;
@ -166,12 +168,12 @@ nsIMEStateManager::OnChangeFocus(nsPresContext* aPresContext,
// the enabled state isn't changing, we should do nothing.
return NS_OK;
}
IMEContext context;
InputContext context;
if (!widget || NS_FAILED(widget->GetInputMode(context))) {
// this platform doesn't support IME controlling
return NS_OK;
}
if (context.mStatus ==
if (context.mIMEEnabled ==
nsContentUtils::GetWidgetStatusFromIMEStatus(newEnabledState)) {
// the enabled state isn't changing.
return NS_OK;
@ -205,8 +207,8 @@ nsIMEStateManager::OnInstalledMenuKeyboardListener(bool aInstalling)
{
sInstalledMenuKeyboardListener = aInstalling;
PRUint32 reason = aInstalling ? IMEContext::FOCUS_MOVED_TO_MENU
: IMEContext::FOCUS_MOVED_FROM_MENU;
PRUint32 reason = aInstalling ? InputContext::FOCUS_MOVED_TO_MENU
: InputContext::FOCUS_MOVED_FROM_MENU;
OnChangeFocus(sPresContext, sContent, reason);
}
@ -225,13 +227,13 @@ nsIMEStateManager::UpdateIMEState(PRUint32 aNewIMEState, nsIContent* aContent)
}
// Don't update IME state when enabled state isn't actually changed.
IMEContext context;
InputContext context;
nsresult rv = widget->GetInputMode(context);
if (NS_FAILED(rv)) {
return; // This platform doesn't support controling the IME state.
}
PRUint32 newEnabledState = aNewIMEState & nsIContent::IME_STATUS_MASK_ENABLED;
if (context.mStatus ==
if (context.mIMEEnabled ==
nsContentUtils::GetWidgetStatusFromIMEStatus(newEnabledState)) {
return;
}
@ -239,7 +241,8 @@ nsIMEStateManager::UpdateIMEState(PRUint32 aNewIMEState, nsIContent* aContent)
// commit current composition
widget->ResetInputState();
SetIMEState(aNewIMEState, aContent, widget, IMEContext::EDITOR_STATE_MODIFIED);
SetIMEState(aNewIMEState, aContent, widget,
InputContext::EDITOR_STATE_MODIFIED);
}
PRUint32
@ -300,8 +303,8 @@ nsIMEStateManager::SetIMEState(PRUint32 aState,
return;
PRUint32 state = nsContentUtils::GetWidgetStatusFromIMEStatus(aState);
IMEContext context;
context.mStatus = state;
InputContext context;
context.mIMEEnabled = state;
if (aContent && aContent->GetNameSpaceID() == kNameSpaceID_XHTML &&
(aContent->Tag() == nsGkAtoms::input ||
@ -337,7 +340,7 @@ nsIMEStateManager::SetIMEState(PRUint32 aState,
}
if (XRE_GetProcessType() == GeckoProcessType_Content) {
context.mReason = aReason | IMEContext::FOCUS_FROM_CONTENT_PROCESS;
context.mReason = aReason | InputContext::FOCUS_FROM_CONTENT_PROCESS;
} else {
context.mReason = aReason;
}

View File

@ -86,6 +86,7 @@
using namespace mozilla::dom;
using namespace mozilla::layers;
using namespace mozilla::widget;
static bool IsUniversalXPConnectCapable()
{
@ -1039,11 +1040,12 @@ nsDOMWindowUtils::GetIMEIsOpen(bool *aState)
return NS_ERROR_FAILURE;
// Open state should not be available when IME is not enabled.
IMEContext context;
InputContext context;
nsresult rv = widget->GetInputMode(context);
NS_ENSURE_SUCCESS(rv, rv);
if (context.mStatus != nsIWidget::IME_STATUS_ENABLED)
if (context.mIMEEnabled != InputContext::IME_ENABLED) {
return NS_ERROR_NOT_AVAILABLE;
}
return widget->GetIMEOpenState(aState);
}
@ -1057,11 +1059,11 @@ nsDOMWindowUtils::GetIMEStatus(PRUint32 *aState)
if (!widget)
return NS_ERROR_FAILURE;
IMEContext context;
InputContext context;
nsresult rv = widget->GetInputMode(context);
NS_ENSURE_SUCCESS(rv, rv);
*aState = context.mStatus;
*aState = context.mIMEEnabled;
return NS_OK;
}
@ -1075,7 +1077,7 @@ nsDOMWindowUtils::GetFocusedInputType(char** aType)
return NS_ERROR_FAILURE;
}
IMEContext context;
InputContext context;
nsresult rv = widget->GetInputMode(context);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -96,6 +96,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::widget;
//#define DEBUG_FOCUS 1
//#define DEBUG_FOCUS_NAVIGATION 1
@ -340,13 +341,13 @@ nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
PRUint32
nsFocusManager::GetFocusMoveReason(PRUint32 aFlags)
{
PRUint32 reason = IMEContext::FOCUS_MOVED_UNKNOWN;
PRUint32 reason = InputContext::FOCUS_MOVED_UNKNOWN;
if (aFlags & nsIFocusManager::FLAG_BYMOUSE) {
reason = IMEContext::FOCUS_MOVED_BY_MOUSE;
reason = InputContext::FOCUS_MOVED_BY_MOUSE;
} else if (aFlags & nsIFocusManager::FLAG_BYKEY) {
reason = IMEContext::FOCUS_MOVED_BY_KEY;
reason = InputContext::FOCUS_MOVED_BY_KEY;
} else if (aFlags & nsIFocusManager::FLAG_BYMOVEFOCUS) {
reason = IMEContext::FOCUS_MOVED_BY_MOVEFOCUS;
reason = InputContext::FOCUS_MOVED_BY_MOVEFOCUS;
}
return reason;
@ -964,7 +965,8 @@ nsFocusManager::WindowHidden(nsIDOMWindow* aWindow)
nsIMEStateManager::OnTextStateBlur(nsnull, nsnull);
if (presShell) {
nsIMEStateManager::OnChangeFocus(presShell->GetPresContext(), nsnull, IMEContext::FOCUS_REMOVED);
nsIMEStateManager::OnChangeFocus(presShell->GetPresContext(), nsnull,
InputContext::FOCUS_REMOVED);
SetCaretVisible(presShell, false, nsnull);
}
@ -1523,8 +1525,10 @@ nsFocusManager::Blur(nsPIDOMWindow* aWindowToClear,
// This has to happen before the focus is cleared below, otherwise, the IME
// compositionend event won't get fired at the element being blurred.
nsIMEStateManager::OnTextStateBlur(nsnull, nsnull);
if (mActiveWindow)
nsIMEStateManager::OnChangeFocus(presShell->GetPresContext(), nsnull, IMEContext::FOCUS_REMOVED);
if (mActiveWindow) {
nsIMEStateManager::OnChangeFocus(presShell->GetPresContext(), nsnull,
InputContext::FOCUS_REMOVED);
}
// now adjust the actual focus, by clearing the fields in the focus manager
// and in the window.
@ -1803,7 +1807,8 @@ nsFocusManager::Focus(nsPIDOMWindow* aWindow,
nsIMEStateManager::OnTextStateFocus(presContext, aContent);
} else {
nsIMEStateManager::OnTextStateBlur(presContext, nsnull);
nsIMEStateManager::OnChangeFocus(presContext, nsnull, IMEContext::FOCUS_REMOVED);
nsIMEStateManager::OnChangeFocus(presContext, nsnull,
InputContext::FOCUS_REMOVED);
if (!aWindowRaised) {
aWindow->UpdateCommands(NS_LITERAL_STRING("focus"));
}
@ -1826,7 +1831,8 @@ nsFocusManager::Focus(nsPIDOMWindow* aWindow,
nsPresContext* presContext = presShell->GetPresContext();
nsIMEStateManager::OnTextStateBlur(presContext, nsnull);
nsIMEStateManager::OnChangeFocus(presContext, nsnull, IMEContext::FOCUS_REMOVED);
nsIMEStateManager::OnChangeFocus(presContext, nsnull,
InputContext::FOCUS_REMOVED);
if (!aWindowRaised)
aWindow->UpdateCommands(NS_LITERAL_STRING("focus"));

View File

@ -74,6 +74,7 @@
using namespace mozilla::dom;
using namespace mozilla::ipc;
using namespace mozilla::layout;
using namespace mozilla::widget;
// The flags passed by the webProgress notifications are 16 bits shifted
// from the ones registered by webProgressListeners.
@ -567,13 +568,13 @@ TabParent::RecvGetIMEEnabled(PRUint32* aValue)
{
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
*aValue = nsIWidget::IME_STATUS_DISABLED;
*aValue = InputContext::IME_DISABLED;
return true;
}
IMEContext context;
InputContext context;
widget->GetInputMode(context);
*aValue = context.mStatus;
*aValue = context.mIMEEnabled;
return true;
}
@ -587,8 +588,8 @@ TabParent::RecvSetInputMode(const PRUint32& aValue, const nsString& aType, const
if (!widget || !AllowContentIME())
return true;
IMEContext context;
context.mStatus = aValue;
InputContext context;
context.mIMEEnabled = aValue;
context.mHTMLInputType.Assign(aType);
context.mActionHint.Assign(aAction);
context.mReason = aReason;

View File

@ -231,8 +231,51 @@ struct nsIMEUpdatePreference {
* Contains IMEStatus plus information about the current
* input context that the IME can use as hints if desired.
*/
struct IMEContext {
PRUint32 mStatus;
namespace mozilla {
namespace widget {
struct InputContext {
/**
* IME enabled states, the mIMEEnabled value of SetInputMode()/GetInputMode()
* should be one value of following values.
*
* WARNING: If you change these values, you also need to edit:
* nsIDOMWindowUtils.idl
* nsDOMWindowUtils::SetIMEEnabled
* nsContentUtils::GetWidgetStatusFromIMEStatus
*/
enum {
/**
* 'Disabled' means the user cannot use IME. So, the IME open state should
* be 'closed' during 'disabled'.
*/
IME_DISABLED = 0,
/**
* 'Enabled' means the user can use IME.
*/
IME_ENABLED = 1,
/**
* 'Password' state is a special case for the password editors.
* E.g., on mac, the password editors should disable the non-Roman
* keyboard layouts at getting focus. Thus, the password editor may have
* special rules on some platforms.
*/
IME_PASSWORD = 2,
/**
* This state is used when a plugin is focused.
* When a plug-in is focused content, we should send native events
* directly. Because we don't process some native events, but they may
* be needed by the plug-in.
*/
IME_PLUGIN = 3,
/**
* IME enabled state mask.
*/
IME_ENABLED_STATE_MASK = 0xF
};
PRUint32 mIMEEnabled;
/* Does the change come from a trusted source */
enum {
@ -264,6 +307,8 @@ struct IMEContext {
nsString mActionHint;
};
} // namespace widget
} // namespace mozilla
/**
* The base class for all the widgets. It provides the interface for
@ -277,6 +322,7 @@ class nsIWidget : public nsISupports {
typedef mozilla::layers::LayerManager LayerManager;
typedef LayerManager::LayersBackend LayersBackend;
typedef mozilla::layers::PLayersChild PLayersChild;
typedef mozilla::widget::InputContext InputContext;
// Used in UpdateThemeGeometries.
struct ThemeGeometry {
@ -1260,41 +1306,6 @@ class nsIWidget : public nsISupports {
*/
NS_IMETHOD GetIMEOpenState(bool* aState) = 0;
/*
* IME enabled states, the aState value of SetIMEEnabled/GetIMEEnabled
* should be one value of following values.
*
* WARNING: If you change these values, you also need to edit:
* nsIDOMWindowUtils.idl
* nsDOMWindowUtils::SetIMEEnabled
* nsContentUtils::GetWidgetStatusFromIMEStatus
*/
enum IMEStatus {
/*
* 'Disabled' means the user cannot use IME. So, the open state should be
* 'closed' during 'disabled'.
*/
IME_STATUS_DISABLED = 0,
/*
* 'Enabled' means the user can use IME.
*/
IME_STATUS_ENABLED = 1,
/*
* 'Password' state is a special case for the password editors.
* E.g., on mac, the password editors should disable the non-Roman
* keyboard layouts at getting focus. Thus, the password editor may have
* special rules on some platforms.
*/
IME_STATUS_PASSWORD = 2,
/*
* This state is used when a plugin is focused.
* When a plug-in is focused content, we should send native events
* directly. Because we don't process some native events, but they may
* be needed by the plug-in.
*/
IME_STATUS_PLUGIN = 3
};
/*
* Destruct and don't commit the IME composition string.
*/
@ -1304,14 +1315,15 @@ class nsIWidget : public nsISupports {
* Notifies the IME if the input context changes.
*
* aContext cannot be null.
* Set mStatus to 'Enabled' or 'Disabled' or 'Password'.
* Set mIMEEnabled to 'Enabled' or 'Disabled' or 'Password' or 'Plugin'.
*/
NS_IMETHOD SetInputMode(const IMEContext& aContext) = 0;
NS_IMETHOD SetInputMode(const InputContext& aContext) = 0;
/*
* Get IME is 'Enabled' or 'Disabled' or 'Password' and other input context
* Get IME is 'Enabled' or 'Disabled' or 'Password' or 'Plugin' and
* other input context
*/
NS_IMETHOD GetInputMode(IMEContext& aContext) = 0;
NS_IMETHOD GetInputMode(InputContext& aContext) = 0;
/**
* Set accelerated rendering to 'True' or 'False'

View File

@ -84,6 +84,7 @@ using mozilla::unused;
#define TILE_HEIGHT 2048
using namespace mozilla;
using namespace mozilla::widget;
NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
@ -2046,16 +2047,17 @@ nsWindow::ResetInputState()
}
NS_IMETHODIMP
nsWindow::SetInputMode(const IMEContext& aContext)
nsWindow::SetInputMode(const InputContext& aContext)
{
ALOGIME("IME: SetInputMode: s=%d trusted=%d", aContext.mStatus, aContext.mReason);
ALOGIME("IME: SetInputMode: s=%d trusted=%d",
aContext.mIMEEnabled, aContext.mReason);
mIMEContext = aContext;
mInputContext = aContext;
// Ensure that opening the virtual keyboard is allowed for this specific
// IMEContext depending on the content.ime.strict.policy pref
if (aContext.mStatus != nsIWidget::IME_STATUS_DISABLED &&
aContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) {
// InputContext depending on the content.ime.strict.policy pref
if (aContext.mIMEEnabled != InputContext::IME_DISABLED &&
aContext.mIMEEnabled != InputContext::IME_PLUGIN) {
if (Preferences::GetBool("content.ime.strict_policy", false) &&
!aContext.FocusMovedByUser() &&
aContext.FocusMovedInContentProcess()) {
@ -2063,14 +2065,16 @@ nsWindow::SetInputMode(const IMEContext& aContext)
}
}
AndroidBridge::NotifyIMEEnabled(int(aContext.mStatus), aContext.mHTMLInputType, aContext.mActionHint);
AndroidBridge::NotifyIMEEnabled(int(aContext.mIMEEnabled),
aContext.mHTMLInputType,
aContext.mActionHint);
return NS_OK;
}
NS_IMETHODIMP
nsWindow::GetInputMode(IMEContext& aContext)
nsWindow::GetInputMode(InputContext& aContext)
{
aContext = mIMEContext;
aContext = mInputContext;
return NS_OK;
}

View File

@ -155,8 +155,8 @@ public:
NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD ResetInputState();
NS_IMETHOD SetInputMode(const IMEContext& aContext);
NS_IMETHOD GetInputMode(IMEContext& aContext);
NS_IMETHOD SetInputMode(const InputContext& aContext);
NS_IMETHOD GetInputMode(InputContext& aContext);
NS_IMETHOD CancelIMEComposition();
NS_IMETHOD OnIMEFocusChange(bool aFocus);
@ -211,7 +211,7 @@ protected:
nsString mIMELastDispatchedComposingText;
nsAutoTArray<nsTextRange, 4> mIMERanges;
IMEContext mIMEContext;
InputContext mInputContext;
static void DumpWindows();
static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0);

View File

@ -448,8 +448,8 @@ public:
NS_IMETHOD ResetInputState();
NS_IMETHOD SetIMEOpenState(bool aState);
NS_IMETHOD GetIMEOpenState(bool* aState);
NS_IMETHOD SetInputMode(const IMEContext& aContext);
NS_IMETHOD GetInputMode(IMEContext& aContext);
NS_IMETHOD SetInputMode(const InputContext& aContext);
NS_IMETHOD GetInputMode(InputContext& aContext);
NS_IMETHOD CancelIMEComposition();
NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode,
bool* aLEDState);
@ -543,7 +543,7 @@ protected:
NSView<mozView>* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
nsRefPtr<mozilla::widget::TextInputHandler> mTextInputHandler;
IMEContext mIMEContext;
InputContext mInputContext;
NSView<mozView>* mParentView;
nsIWidget* mParentWidget;

View File

@ -1689,21 +1689,21 @@ NS_IMETHODIMP nsChildView::GetIMEOpenState(bool* aState)
return NS_OK;
}
NS_IMETHODIMP nsChildView::SetInputMode(const IMEContext& aContext)
NS_IMETHODIMP nsChildView::SetInputMode(const InputContext& aContext)
{
NS_ENSURE_TRUE(mTextInputHandler, NS_ERROR_NOT_AVAILABLE);
mIMEContext = aContext;
switch (aContext.mStatus) {
case nsIWidget::IME_STATUS_ENABLED:
case nsIWidget::IME_STATUS_PLUGIN:
mInputContext = aContext;
switch (aContext.mIMEEnabled) {
case InputContext::IME_ENABLED:
case InputContext::IME_PLUGIN:
mTextInputHandler->SetASCIICapableOnly(false);
mTextInputHandler->EnableIME(true);
break;
case nsIWidget::IME_STATUS_DISABLED:
case InputContext::IME_DISABLED:
mTextInputHandler->SetASCIICapableOnly(false);
mTextInputHandler->EnableIME(false);
break;
case nsIWidget::IME_STATUS_PASSWORD:
case InputContext::IME_PASSWORD:
mTextInputHandler->SetASCIICapableOnly(true);
mTextInputHandler->EnableIME(false);
break;
@ -1713,9 +1713,9 @@ NS_IMETHODIMP nsChildView::SetInputMode(const IMEContext& aContext)
return NS_OK;
}
NS_IMETHODIMP nsChildView::GetInputMode(IMEContext& aContext)
NS_IMETHODIMP nsChildView::GetInputMode(InputContext& aContext)
{
aContext = mIMEContext;
aContext = mInputContext;
return NS_OK;
}

View File

@ -58,6 +58,7 @@
#endif
using namespace mozilla;
using namespace mozilla::widget;
#ifdef PR_LOGGING
PRLogModuleInfo* gGtkIMLog = nsnull;
@ -85,13 +86,13 @@ static const char*
GetEnabledStateName(PRUint32 aState)
{
switch (aState) {
case nsIWidget::IME_STATUS_DISABLED:
case InputContext::IME_DISABLED:
return "DISABLED";
case nsIWidget::IME_STATUS_ENABLED:
case InputContext::IME_ENABLED:
return "ENABLED";
case nsIWidget::IME_STATUS_PASSWORD:
case InputContext::IME_PASSWORD:
return "PASSWORD";
case nsIWidget::IME_STATUS_PLUGIN:
case InputContext::IME_PLUGIN:
return "PLUG_IN";
default:
return "UNKNOWN ENABLED STATUS!!";
@ -121,7 +122,7 @@ nsGtkIMModule::nsGtkIMModule(nsWindow* aOwnerWindow) :
gGtkIMLog = PR_NewLogModule("nsGtkIMModuleWidgets");
}
#endif
mIMEContext.mStatus = nsIWidget::IME_STATUS_ENABLED;
mInputContext.mIMEEnabled = InputContext::IME_ENABLED;
Init();
}
@ -257,7 +258,7 @@ nsGtkIMModule::OnDestroyWindow(nsWindow* aWindow)
mOwnerWindow = nsnull;
mLastFocusedWindow = nsnull;
mIMEContext.mStatus = nsIWidget::IME_STATUS_DISABLED;
mInputContext.mIMEEnabled = InputContext::IME_DISABLED;
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
(" SUCCEEDED, Completely destroyed"));
@ -542,15 +543,16 @@ nsGtkIMModule::CancelIMEComposition(nsWindow* aCaller)
}
nsresult
nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
nsGtkIMModule::SetInputMode(nsWindow* aCaller, const InputContext* aContext)
{
if (aContext->mStatus == mIMEContext.mStatus || NS_UNLIKELY(IsDestroyed())) {
if (aContext->mIMEEnabled == mInputContext.mIMEEnabled ||
NS_UNLIKELY(IsDestroyed())) {
return NS_OK;
}
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
("GtkIMModule(%p): SetInputMode, aCaller=%p, aState=%s mHTMLInputType=%s",
this, aCaller, GetEnabledStateName(aContext->mStatus),
this, aCaller, GetEnabledStateName(aContext->mIMEEnabled),
NS_ConvertUTF16toUTF8(aContext->mHTMLInputType).get()));
if (aCaller != mLastFocusedWindow) {
@ -568,7 +570,7 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
if (sLastFocusedModule != this) {
mIMEContext = *aContext;
mInputContext = *aContext;
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
(" SUCCEEDED, but we're not active"));
return NS_OK;
@ -580,7 +582,7 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
Blur();
}
mIMEContext = *aContext;
mInputContext = *aContext;
// Even when aState is not enabled state, we need to set IME focus.
// Because some IMs are updating the status bar of them at this time.
@ -593,14 +595,14 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
if (im) {
if (IsEnabled()) {
// Ensure that opening the virtual keyboard is allowed for this specific
// IMEContext depending on the content.ime.strict.policy pref
if (mIMEContext.mStatus != nsIWidget::IME_STATUS_DISABLED &&
mIMEContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) {
// InputContext depending on the content.ime.strict.policy pref
if (mInputContext.mIMEEnabled != InputContext::IME_DISABLED &&
mInputContext.mIMEEnabled != InputContext::IME_PLUGIN) {
bool useStrictPolicy =
Preferences::GetBool("content.ime.strict_policy", false);
if (useStrictPolicy && !mIMEContext.FocusMovedByUser() &&
mIMEContext.FocusMovedInContentProcess()) {
if (useStrictPolicy && !mInputContext.FocusMovedByUser() &&
mInputContext.FocusMovedInContentProcess()) {
return NS_OK;
}
}
@ -611,10 +613,10 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
int mode;
g_object_get(im, "hildon-input-mode", &mode, NULL);
if (mIMEContext.mStatus == nsIWidget::IME_STATUS_ENABLED ||
mIMEContext.mStatus == nsIWidget::IME_STATUS_PLUGIN) {
if (mInputContext.mIMEEnabled == InputContext::IME_ENABLED ||
mInputContext.mIMEEnabled == InputContext::IME_PLUGIN) {
mode &= ~HILDON_GTK_INPUT_MODE_INVISIBLE;
} else if (mIMEContext.mStatus == nsIWidget::IME_STATUS_PASSWORD) {
} else if (mInputContext.mIMEEnabled == InputContext::IME_PASSWORD) {
mode |= HILDON_GTK_INPUT_MODE_INVISIBLE;
}
@ -659,10 +661,10 @@ nsGtkIMModule::SetInputMode(nsWindow* aCaller, const IMEContext* aContext)
}
nsresult
nsGtkIMModule::GetInputMode(IMEContext* aContext)
nsGtkIMModule::GetInputMode(InputContext* aContext)
{
NS_ENSURE_ARG_POINTER(aContext);
*aContext = mIMEContext;
*aContext = mInputContext;
return NS_OK;
}
@ -685,7 +687,7 @@ nsGtkIMModule::GetContext()
}
#ifndef NS_IME_ENABLED_ON_PASSWORD_FIELD
if (mIMEContext.mStatus == nsIWidget::IME_STATUS_PASSWORD) {
if (mInputContext.mIMEEnabled == InputContext::IME_PASSWORD) {
return mSimpleContext;
}
#endif // NS_IME_ENABLED_ON_PASSWORD_FIELD
@ -696,19 +698,19 @@ nsGtkIMModule::GetContext()
bool
nsGtkIMModule::IsEnabled()
{
return mIMEContext.mStatus == nsIWidget::IME_STATUS_ENABLED ||
return mInputContext.mIMEEnabled == InputContext::IME_ENABLED ||
#ifdef NS_IME_ENABLED_ON_PASSWORD_FIELD
mIMEContext.mStatus == nsIWidget::IME_STATUS_PASSWORD ||
mInputContext.mIMEEnabled == InputContext::IME_PASSWORD ||
#endif // NS_IME_ENABLED_ON_PASSWORD_FIELD
mIMEContext.mStatus == nsIWidget::IME_STATUS_PLUGIN;
mInputContext.mIMEEnabled == InputContext::IME_PLUGIN;
}
bool
nsGtkIMModule::IsEditable()
{
return mIMEContext.mStatus == nsIWidget::IME_STATUS_ENABLED ||
mIMEContext.mStatus == nsIWidget::IME_STATUS_PLUGIN ||
mIMEContext.mStatus == nsIWidget::IME_STATUS_PASSWORD;
return mInputContext.mIMEEnabled == InputContext::IME_ENABLED ||
mInputContext.mIMEEnabled == InputContext::IME_PLUGIN ||
mInputContext.mIMEEnabled == InputContext::IME_PASSWORD;
}
void

View File

@ -47,6 +47,7 @@
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "nsGUIEvent.h"
#include "nsIWidget.h"
// If software keyboard is needed in password field and uses GTK2 IM module
// for inputting characters, we need to enable IME in password field too.
@ -58,6 +59,9 @@ class nsWindow;
class nsGtkIMModule
{
protected:
typedef mozilla::widget::InputContext InputContext;
public:
nsrefcnt AddRef()
{
@ -112,8 +116,9 @@ public:
// IME related nsIWidget methods.
nsresult ResetInputState(nsWindow* aCaller);
nsresult SetInputMode(nsWindow* aCaller, const IMEContext* aContext);
nsresult GetInputMode(IMEContext* aContext);
nsresult SetInputMode(nsWindow* aCaller,
const InputContext* aContext);
nsresult GetInputMode(InputContext* aContext);
nsresult CancelIMEComposition(nsWindow* aCaller);
// If a software keyboard has been opened, this returns TRUE.
@ -148,9 +153,9 @@ protected:
// always "closed", so it closes IME forcedly.
GtkIMContext *mDummyContext;
// IME enabled state and other things defined in IMEContext.
// IME enabled state and other things defined in InputContext.
// Use following helper methods if you don't need the detail of the status.
IMEContext mIMEContext;
InputContext mInputContext;
// mCompositionStart is the start offset of the composition string in the
// current content. When <textarea> or <input> have focus, it means offset

View File

@ -115,6 +115,7 @@
#include "stdlib.h"
using namespace mozilla;
using namespace mozilla::widget;
static bool sAccessibilityChecked = false;
/* static */
@ -6576,16 +6577,16 @@ nsWindow::ResetInputState()
}
NS_IMETHODIMP
nsWindow::SetInputMode(const IMEContext& aContext)
nsWindow::SetInputMode(const InputContext& aContext)
{
return mIMModule ? mIMModule->SetInputMode(this, &aContext) : NS_OK;
}
NS_IMETHODIMP
nsWindow::GetInputMode(IMEContext& aContext)
nsWindow::GetInputMode(InputContext& aContext)
{
if (!mIMModule) {
aContext.mStatus = nsIWidget::IME_STATUS_DISABLED;
aContext.mIMEEnabled = InputContext::IME_DISABLED;
return NS_OK;
}
return mIMModule->GetInputMode(&aContext);

View File

@ -320,8 +320,8 @@ public:
bool *aIsCancelled);
NS_IMETHOD ResetInputState();
NS_IMETHOD SetInputMode(const IMEContext& aContext);
NS_IMETHOD GetInputMode(IMEContext& aContext);
NS_IMETHOD SetInputMode(const InputContext& aContext);
NS_IMETHOD GetInputMode(InputContext& aContext);
NS_IMETHOD CancelIMEComposition();
NS_IMETHOD OnIMEFocusChange(bool aFocus);
NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, bool* aLEDState);

View File

@ -154,6 +154,7 @@ extern "C" {
}
using namespace mozilla;
using namespace mozilla::widget;
// imported in nsWidgetFactory.cpp
bool gDisableNativeTheme = false;
@ -3215,22 +3216,24 @@ x11EventFilter(void* message, long* result)
#endif
NS_IMETHODIMP
nsWindow::SetInputMode(const IMEContext& aContext)
nsWindow::SetInputMode(const InputContext& aContext)
{
NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
// SetSoftwareKeyboardState uses mIMEContext,
// so, before calling that, record aContext in mIMEContext.
mIMEContext = aContext;
// SetSoftwareKeyboardState uses mInputContext,
// so, before calling that, record aContext in mInputContext.
mInputContext = aContext;
#if defined(MOZ_X11) && (MOZ_PLATFORM_MAEMO == 6)
if (sPluginIMEAtom) {
static QCoreApplication::EventFilter currentEventFilter = NULL;
if (mIMEContext.mStatus == nsIWidget::IME_STATUS_PLUGIN && currentEventFilter != x11EventFilter) {
if (mInputContext.mIMEEnabled == InputContext::IME_PLUGIN &&
currentEventFilter != x11EventFilter) {
// Install event filter for listening Plugin IME state changes
previousEventFilter = QCoreApplication::instance()->setEventFilter(x11EventFilter);
currentEventFilter = x11EventFilter;
} else if (mIMEContext.mStatus != nsIWidget::IME_STATUS_PLUGIN && currentEventFilter == x11EventFilter) {
} else if (mInputContext.mIMEEnabled != InputContext::IME_PLUGIN &&
currentEventFilter == x11EventFilter) {
// Remove event filter
QCoreApplication::instance()->setEventFilter(previousEventFilter);
currentEventFilter = previousEventFilter;
@ -3243,10 +3246,10 @@ nsWindow::SetInputMode(const IMEContext& aContext)
}
#endif
switch (mIMEContext.mStatus) {
case nsIWidget::IME_STATUS_ENABLED:
case nsIWidget::IME_STATUS_PASSWORD:
case nsIWidget::IME_STATUS_PLUGIN:
switch (mInputContext.mIMEEnabled) {
case InputContext::IME_ENABLED:
case InputContext::IME_PASSWORD:
case InputContext::IME_PLUGIN:
SetSoftwareKeyboardState(true);
break;
default:
@ -3258,9 +3261,9 @@ nsWindow::SetInputMode(const IMEContext& aContext)
}
NS_IMETHODIMP
nsWindow::GetInputMode(IMEContext& aContext)
nsWindow::GetInputMode(InputContext& aContext)
{
aContext = mIMEContext;
aContext = mInputContext;
return NS_OK;
}
@ -3268,14 +3271,15 @@ void
nsWindow::SetSoftwareKeyboardState(bool aOpen)
{
if (aOpen) {
NS_ENSURE_TRUE(mIMEContext.mStatus != nsIWidget::IME_STATUS_DISABLED,);
NS_ENSURE_TRUE(mInputContext.mIMEEnabled !=
InputContext::IME_DISABLED, );
// Ensure that opening the virtual keyboard is allowed for this specific
// IMEContext depending on the content.ime.strict.policy pref
if (mIMEContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) {
// InputContext depending on the content.ime.strict.policy pref
if (mInputContext.mIMEEnabled != InputContext::IME_PLUGIN) {
if (Preferences::GetBool("content.ime.strict_policy", false) &&
!mIMEContext.FocusMovedByUser() &&
mIMEContext.FocusMovedInContentProcess()) {
!mInputContext.FocusMovedByUser() &&
mInputContext.FocusMovedInContentProcess()) {
return;
}
}

View File

@ -194,8 +194,8 @@ public:
NS_IMETHOD GetAttention(PRInt32 aCycleCount);
NS_IMETHOD BeginResizeDrag (nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
NS_IMETHODIMP SetInputMode(const IMEContext& aContext);
NS_IMETHODIMP GetInputMode(IMEContext& aContext);
NS_IMETHODIMP SetInputMode(const InputContext& aContext);
NS_IMETHODIMP GetInputMode(InputContext& aContext);
//
// utility methods
@ -250,7 +250,7 @@ protected:
// leaving fullscreen
nsSizeMode mLastSizeMode;
IMEContext mIMEContext;
InputContext mInputContext;
/**
* Event handlers (proxied from the actual qwidget).

View File

@ -46,6 +46,7 @@
#include "mozilla/Preferences.h"
using namespace mozilla;
using namespace mozilla::widget;
/******************************************************************/
/* nsTextStore */
@ -1637,7 +1638,7 @@ nsTextStore::SetInputModeInternal(PRUint32 aState)
VARIANT variant;
variant.vt = VT_I4;
variant.lVal = aState != nsIWidget::IME_STATUS_ENABLED;
variant.lVal = aState != InputContext::IME_ENABLED;
// Set two contexts, the base context (mContext) and the top
// if the top context is not the same as the base context

View File

@ -110,6 +110,9 @@ public: /*ITfContextOwnerCompositionSink*/
STDMETHODIMP OnUpdateComposition(ITfCompositionView*, ITfRange*);
STDMETHODIMP OnEndComposition(ITfCompositionView*);
protected:
typedef mozilla::widget::InputContext InputContext;
public:
static void Initialize(void);
static void Terminate(void);
@ -122,10 +125,10 @@ public:
sTsfTextStore->CommitCompositionInternal(aDiscard);
}
static void SetInputMode(const IMEContext& aContext)
static void SetInputMode(const InputContext& aContext)
{
if (!sTsfTextStore) return;
sTsfTextStore->SetInputModeInternal(aContext.mStatus);
sTsfTextStore->SetInputModeInternal(aContext.mIMEEnabled);
}
static nsresult OnFocusChange(bool, nsWindow*, PRUint32);

View File

@ -406,7 +406,7 @@ nsWindow::nsWindow() : nsBaseWidget()
mLastKeyboardLayout = 0;
mAssumeWheelIsZoomUntil = 0;
mBlurSuppressLevel = 0;
mIMEContext.mStatus = nsIWidget::IME_STATUS_ENABLED;
mInputContext.mIMEEnabled = InputContext::IME_ENABLED;
#ifdef MOZ_XUL
mTransparentSurface = nsnull;
mMemoryDC = nsnull;
@ -8065,36 +8065,37 @@ NS_IMETHODIMP nsWindow::GetIMEOpenState(bool* aState)
return NS_OK;
}
NS_IMETHODIMP nsWindow::SetInputMode(const IMEContext& aContext)
NS_IMETHODIMP nsWindow::SetInputMode(const InputContext& aContext)
{
PRUint32 status = aContext.mStatus;
PRUint32 status = aContext.mIMEEnabled;
#ifdef NS_ENABLE_TSF
nsTextStore::SetInputMode(aContext);
#endif //NS_ENABLE_TSF
#ifdef DEBUG_KBSTATE
PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
("SetInputMode: %s\n", (status == nsIWidget::IME_STATUS_ENABLED ||
status == nsIWidget::IME_STATUS_PLUGIN) ?
("SetInputMode: %s\n", (status == InputContext::IME_ENABLED ||
status == InputContext::IME_PLUGIN) ?
"Enabled" : "Disabled"));
#endif
if (nsIMM32Handler::IsComposing()) {
ResetInputState();
}
mIMEContext = aContext;
bool enable = (status == nsIWidget::IME_STATUS_ENABLED ||
status == nsIWidget::IME_STATUS_PLUGIN);
mInputContext = aContext;
bool enable = (status == InputContext::IME_ENABLED ||
status == InputContext::IME_PLUGIN);
AssociateDefaultIMC(enable);
return NS_OK;
}
NS_IMETHODIMP nsWindow::GetInputMode(IMEContext& aContext)
NS_IMETHODIMP nsWindow::GetInputMode(InputContext& aContext)
{
#ifdef DEBUG_KBSTATE
PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
("GetInputMode: %s\n", mIMEContext.mStatus ? "Enabled" : "Disabled");
("GetInputMode: %s\n", mInputContext.mIMEEnabled ?
"Enabled" : "Disabled");
#endif
aContext = mIMEContext;
aContext = mInputContext;
return NS_OK;
}
@ -8127,7 +8128,8 @@ nsWindow::GetToggledKeyState(PRUint32 aKeyCode, bool* aLEDState)
NS_IMETHODIMP
nsWindow::OnIMEFocusChange(bool aFocus)
{
nsresult rv = nsTextStore::OnFocusChange(aFocus, this, mIMEContext.mStatus);
nsresult rv = nsTextStore::OnFocusChange(aFocus, this,
mInputContext.mIMEEnabled);
if (rv == NS_ERROR_NOT_AVAILABLE)
rv = NS_ERROR_NOT_IMPLEMENTED; // TSF is not enabled, maybe.
return rv;

View File

@ -181,8 +181,8 @@ public:
NS_IMETHOD ResetInputState();
NS_IMETHOD SetIMEOpenState(bool aState);
NS_IMETHOD GetIMEOpenState(bool* aState);
NS_IMETHOD SetInputMode(const IMEContext& aContext);
NS_IMETHOD GetInputMode(IMEContext& aContext);
NS_IMETHOD SetInputMode(const InputContext& aContext);
NS_IMETHOD GetInputMode(InputContext& aContext);
NS_IMETHOD CancelIMEComposition();
NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, bool* aLEDState);
NS_IMETHOD RegisterTouchWindow();
@ -262,7 +262,10 @@ public:
virtual bool AutoErase(HDC dc);
nsIntPoint* GetLastPoint() { return &mLastPoint; }
// needed in nsIMM32Handler.cpp
bool PluginHasFocus() { return mIMEContext.mStatus == nsIWidget::IME_STATUS_PLUGIN; }
bool PluginHasFocus()
{
return mInputContext.mIMEEnabled == InputContext::IME_PLUGIN;
}
bool IsTopLevelWidget() { return mIsTopWidgetWindow; }
/**
* Start allowing Direct3D9 to be used by widgets when GetLayerManager is
@ -533,7 +536,7 @@ protected:
PRUint32 mBlurSuppressLevel;
DWORD_PTR mOldStyle;
DWORD_PTR mOldExStyle;
IMEContext mIMEContext;
InputContext mInputContext;
nsNativeDragTarget* mNativeDragTarget;
HKL mLastKeyboardLayout;
nsPopupType mPopupType;

View File

@ -409,10 +409,11 @@ PuppetWidget::SetIMEOpenState(bool aState)
}
NS_IMETHODIMP
PuppetWidget::SetInputMode(const IMEContext& aContext)
PuppetWidget::SetInputMode(const InputContext& aContext)
{
if (mTabChild &&
mTabChild->SendSetInputMode(aContext.mStatus, aContext.mHTMLInputType,
mTabChild->SendSetInputMode(aContext.mIMEEnabled,
aContext.mHTMLInputType,
aContext.mActionHint, aContext.mReason))
return NS_OK;
return NS_ERROR_FAILURE;
@ -428,10 +429,10 @@ PuppetWidget::GetIMEOpenState(bool *aState)
}
NS_IMETHODIMP
PuppetWidget::GetInputMode(IMEContext& aContext)
PuppetWidget::GetInputMode(InputContext& aContext)
{
if (mTabChild &&
mTabChild->SendGetIMEEnabled(&aContext.mStatus))
mTabChild->SendGetIMEEnabled(&aContext.mIMEEnabled))
return NS_OK;
return NS_ERROR_FAILURE;
}

View File

@ -170,8 +170,8 @@ public:
NS_IMETHOD ResetInputState();
NS_IMETHOD SetIMEOpenState(bool aState);
NS_IMETHOD GetIMEOpenState(bool *aState);
NS_IMETHOD SetInputMode(const IMEContext& aContext);
NS_IMETHOD GetInputMode(IMEContext& aContext);
NS_IMETHOD SetInputMode(const InputContext& aContext);
NS_IMETHOD GetInputMode(InputContext& aContext);
NS_IMETHOD CancelComposition();
NS_IMETHOD OnIMEFocusChange(bool aFocus);
NS_IMETHOD OnIMETextChange(PRUint32 aOffset, PRUint32 aEnd,

View File

@ -144,8 +144,8 @@ public:
NS_IMETHOD ResetInputState() { return NS_OK; }
NS_IMETHOD SetIMEOpenState(bool aState) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetIMEOpenState(bool* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetInputMode(const IMEContext& aContext) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetInputMode(IMEContext& aContext) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetInputMode(const InputContext& aContext) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetInputMode(InputContext& aContext) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD CancelIMEComposition() { return NS_OK; }
NS_IMETHOD SetAcceleratedRendering(bool aEnabled);
virtual bool GetAcceleratedRendering();