Bug 1186017 part.1 Rename nsGtkIMModule to mozilla::widget::IMContextWrapper r=m_kato+kerlt

This commit is contained in:
Masayuki Nakano 2015-07-27 08:23:04 +09:00
parent a7bf18ea61
commit cde1c85687
6 changed files with 463 additions and 371 deletions

View File

@ -5,8 +5,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsGtkIMModule_h__
#define __nsGtkIMModule_h__
#ifndef IMContextWrapper_h_
#define IMContextWrapper_h_
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@ -22,20 +22,18 @@
class nsWindow;
class nsGtkIMModule
{
protected:
typedef mozilla::widget::IMENotification IMENotification;
typedef mozilla::widget::InputContext InputContext;
typedef mozilla::widget::InputContextAction InputContextAction;
namespace mozilla {
namespace widget {
class IMContextWrapper final
{
public:
// aOwnerWindow is a pointer of the owner window. When aOwnerWindow is
// destroyed, the related IME contexts are released (i.e., IME cannot be
// used with the instance after that).
explicit nsGtkIMModule(nsWindow* aOwnerWindow);
explicit IMContextWrapper(nsWindow* aOwnerWindow);
NS_INLINE_DECL_REFCOUNTING(nsGtkIMModule)
NS_INLINE_DECL_REFCOUNTING(IMContextWrapper)
// "Enabled" means the users can use all IMEs.
// I.e., the focus is in the normal editors.
@ -72,7 +70,7 @@ public:
void OnLayoutChange();
protected:
~nsGtkIMModule();
~IMContextWrapper();
// Owner of an instance of this class. This should be top level window.
// The owner window must release the contexts when it's destroyed because
@ -205,7 +203,7 @@ protected:
{
uint32_t mOffset;
uint32_t mLength;
mozilla::WritingMode mWritingMode;
WritingMode mWritingMode;
Selection()
: mOffset(UINT32_MAX)
@ -217,11 +215,11 @@ protected:
{
mOffset = UINT32_MAX;
mLength = UINT32_MAX;
mWritingMode = mozilla::WritingMode();
mWritingMode = WritingMode();
}
void Assign(const IMENotification& aIMENotification);
void Assign(const mozilla::WidgetQueryContentEvent& aSelectedTextEvent);
void Assign(const WidgetQueryContentEvent& aSelectedTextEvent);
bool IsValid() const { return mOffset != UINT32_MAX; }
bool Collapsed() const { return !mLength; }
@ -230,8 +228,8 @@ protected:
if (NS_WARN_IF(!IsValid())) {
return UINT32_MAX;
}
mozilla::CheckedInt<uint32_t> endOffset =
mozilla::CheckedInt<uint32_t>(mOffset) + mLength;
CheckedInt<uint32_t> endOffset =
CheckedInt<uint32_t>(mOffset) + mLength;
if (NS_WARN_IF(!endOffset.isValid())) {
return UINT32_MAX;
}
@ -264,10 +262,10 @@ protected:
// before key down
bool mSetCursorPositionOnKeyEvent;
// sLastFocusedModule is a pointer to the last focused instance of this
// class. When a instance is destroyed and sLastFocusedModule refers it,
// sLastFocusedContext is a pointer to the last focused instance of this
// class. When a instance is destroyed and sLastFocusedContext refers it,
// this is cleared. So, this refers valid pointer always.
static nsGtkIMModule* sLastFocusedModule;
static IMContextWrapper* sLastFocusedContext;
// sUseSimpleContext indeicates if password editors and editors with
// |ime-mode: disabled;| should use GtkIMContextSimple.
@ -276,32 +274,32 @@ protected:
// Callback methods for native IME events. These methods should call
// the related instance methods simply.
static gboolean OnRetrieveSurroundingCallback(GtkIMContext *aContext,
nsGtkIMModule *aModule);
static gboolean OnDeleteSurroundingCallback(GtkIMContext *aContext,
gint aOffset,
gint aNChars,
nsGtkIMModule *aModule);
static void OnCommitCompositionCallback(GtkIMContext *aContext,
const gchar *aString,
nsGtkIMModule* aModule);
static void OnChangeCompositionCallback(GtkIMContext *aContext,
nsGtkIMModule* aModule);
static void OnStartCompositionCallback(GtkIMContext *aContext,
nsGtkIMModule* aModule);
static void OnEndCompositionCallback(GtkIMContext *aContext,
nsGtkIMModule* aModule);
static gboolean OnRetrieveSurroundingCallback(GtkIMContext* aContext,
IMContextWrapper* aModule);
static gboolean OnDeleteSurroundingCallback(GtkIMContext* aContext,
gint aOffset,
gint aNChars,
IMContextWrapper* aModule);
static void OnCommitCompositionCallback(GtkIMContext* aContext,
const gchar* aString,
IMContextWrapper* aModule);
static void OnChangeCompositionCallback(GtkIMContext* aContext,
IMContextWrapper* aModule);
static void OnStartCompositionCallback(GtkIMContext* aContext,
IMContextWrapper* aModule);
static void OnEndCompositionCallback(GtkIMContext* aContext,
IMContextWrapper* aModule);
// The instance methods for the native IME events.
gboolean OnRetrieveSurroundingNative(GtkIMContext *aContext);
gboolean OnDeleteSurroundingNative(GtkIMContext *aContext,
gint aOffset,
gint aNChars);
void OnCommitCompositionNative(GtkIMContext *aContext,
const gchar *aString);
void OnChangeCompositionNative(GtkIMContext *aContext);
void OnStartCompositionNative(GtkIMContext *aContext);
void OnEndCompositionNative(GtkIMContext *aContext);
gboolean OnRetrieveSurroundingNative(GtkIMContext* aContext);
gboolean OnDeleteSurroundingNative(GtkIMContext* aContext,
gint aOffset,
gint aNChars);
void OnCommitCompositionNative(GtkIMContext* aContext,
const gchar* aString);
void OnChangeCompositionNative(GtkIMContext* aContext);
void OnStartCompositionNative(GtkIMContext* aContext);
void OnEndCompositionNative(GtkIMContext* aContext);
/**
* GetCurrentContext() returns current IM context which is chosen with the
@ -349,7 +347,7 @@ protected:
* of current composition. This should be
* mDispatchedCompositionString.
*/
already_AddRefed<mozilla::TextRangeArray>
already_AddRefed<TextRangeArray>
CreateTextRangeArray(GtkIMContext* aContext,
const nsAString& aLastDispatchedData);
@ -379,10 +377,10 @@ protected:
uint32_t aNChars);
// Initializes the GUI event.
void InitEvent(mozilla::WidgetGUIEvent& aEvent);
void InitEvent(WidgetGUIEvent& aEvent);
// Called before destroying the context to work around some platform bugs.
void PrepareToDestroyContext(GtkIMContext *aContext);
void PrepareToDestroyContext(GtkIMContext* aContext);
/**
* WARNING:
@ -430,4 +428,7 @@ protected:
const nsAString* aCommitString = nullptr);
};
#endif // __nsGtkIMModule_h__
} // namespace widget
} // namespace mozilla
#endif // #ifndef IMContextWrapper_h_

View File

@ -20,8 +20,6 @@ UNIFIED_SOURCES += [
'nsBidiKeyboard.cpp',
'nsColorPicker.cpp',
'nsFilePicker.cpp',
'nsGtkIMModule.cpp',
'nsGtkKeyUtils.cpp',
'nsImageToPixbuf.cpp',
'nsLookAndFeel.cpp',
'nsNativeThemeGTK.cpp',
@ -35,6 +33,8 @@ UNIFIED_SOURCES += [
]
SOURCES += [
'IMContextWrapper.cpp', # methods for logging conflict with other files
'nsGtkKeyUtils.cpp', # methods for logging conflict with other files
'nsWindow.cpp', # conflicts with X11 headers
]

View File

@ -19,6 +19,7 @@
#include <X11/XKBlib.h>
#include "WidgetUtils.h"
#include "keysym2ucs.h"
#include "nsGtkUtils.h"
#include "nsIBidiKeyboard.h"
#include "nsServiceManagerUtils.h"

View File

@ -632,8 +632,8 @@ nsWindow::Destroy(void)
NativeShow(false);
if (mIMModule) {
mIMModule->OnDestroyWindow(this);
if (mIMContext) {
mIMContext->OnDestroyWindow(this);
}
// make sure that we remove ourself as the focus window
@ -1367,8 +1367,8 @@ nsWindow::SetFocus(bool aRaise)
// Set this window to be the focused child window
gFocusWindow = this;
if (mIMModule) {
mIMModule->OnFocusWindow(this);
if (mIMContext) {
mIMContext->OnFocusWindow(this);
}
LOGFOCUS((" widget now has focus in SetFocus() [%p]\n",
@ -2793,8 +2793,8 @@ nsWindow::OnContainerFocusOutEvent(GdkEventFocus *aEvent)
if (gFocusWindow) {
nsRefPtr<nsWindow> kungFuDeathGrip = gFocusWindow;
if (gFocusWindow->mIMModule) {
gFocusWindow->mIMModule->OnBlurWindow(gFocusWindow);
if (gFocusWindow->mIMContext) {
gFocusWindow->mIMContext->OnBlurWindow(gFocusWindow);
}
gFocusWindow = nullptr;
}
@ -2857,9 +2857,9 @@ nsWindow::OnKeyPressEvent(GdkEventKey *aEvent)
// if we are in the middle of composing text, XIM gets to see it
// before mozilla does.
bool IMEWasEnabled = false;
if (mIMModule) {
IMEWasEnabled = mIMModule->IsEnabled();
if (mIMModule->OnKeyEvent(this, aEvent)) {
if (mIMContext) {
IMEWasEnabled = mIMContext->IsEnabled();
if (mIMContext->OnKeyEvent(this, aEvent)) {
return TRUE;
}
}
@ -2888,10 +2888,10 @@ nsWindow::OnKeyPressEvent(GdkEventKey *aEvent)
// If a keydown event handler causes to enable IME, i.e., it moves
// focus from IME unusable content to IME usable editor, we should
// send the native key event to IME for the first input on the editor.
if (!IMEWasEnabled && mIMModule && mIMModule->IsEnabled()) {
if (!IMEWasEnabled && mIMContext && mIMContext->IsEnabled()) {
// Notice our keydown event was already dispatched. This prevents
// unnecessary DOM keydown event in the editor.
if (mIMModule->OnKeyEvent(this, aEvent, true)) {
if (mIMContext->OnKeyEvent(this, aEvent, true)) {
return TRUE;
}
}
@ -2989,7 +2989,7 @@ nsWindow::OnKeyReleaseEvent(GdkEventKey *aEvent)
{
LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
if (mIMModule && mIMModule->OnKeyEvent(this, aEvent)) {
if (mIMContext && mIMContext->OnKeyEvent(this, aEvent)) {
return TRUE;
}
@ -3660,12 +3660,12 @@ nsWindow::Create(nsIWidget *aParent,
// We create input contexts for all containers, except for
// toplevel popup windows
if (mWindowType != eWindowType_popup) {
mIMModule = new nsGtkIMModule(this);
mIMContext = new IMContextWrapper(this);
}
} else if (!mIMModule) {
} else if (!mIMContext) {
nsWindow *container = GetContainerWindow();
if (container) {
mIMModule = container->mIMModule;
mIMContext = container->mIMContext;
}
}
@ -5970,27 +5970,27 @@ nsChildWindow::~nsChildWindow()
nsresult
nsWindow::NotifyIMEInternal(const IMENotification& aIMENotification)
{
if (MOZ_UNLIKELY(!mIMModule)) {
if (MOZ_UNLIKELY(!mIMContext)) {
return NS_ERROR_NOT_AVAILABLE;
}
switch (aIMENotification.mMessage) {
case REQUEST_TO_COMMIT_COMPOSITION:
case REQUEST_TO_CANCEL_COMPOSITION:
return mIMModule->EndIMEComposition(this);
return mIMContext->EndIMEComposition(this);
case NOTIFY_IME_OF_FOCUS:
mIMModule->OnFocusChangeInGecko(true);
mIMContext->OnFocusChangeInGecko(true);
return NS_OK;
case NOTIFY_IME_OF_BLUR:
mIMModule->OnFocusChangeInGecko(false);
mIMContext->OnFocusChangeInGecko(false);
return NS_OK;
case NOTIFY_IME_OF_POSITION_CHANGE:
mIMModule->OnLayoutChange();
mIMContext->OnLayoutChange();
return NS_OK;
case NOTIFY_IME_OF_COMPOSITION_UPDATE:
mIMModule->OnUpdateComposition();
mIMContext->OnUpdateComposition();
return NS_OK;
case NOTIFY_IME_OF_SELECTION_CHANGE:
mIMModule->OnSelectionChange(this, aIMENotification);
mIMContext->OnSelectionChange(this, aIMENotification);
return NS_OK;
default:
return NS_ERROR_NOT_IMPLEMENTED;
@ -6001,17 +6001,17 @@ NS_IMETHODIMP_(void)
nsWindow::SetInputContext(const InputContext& aContext,
const InputContextAction& aAction)
{
if (!mIMModule) {
if (!mIMContext) {
return;
}
mIMModule->SetInputContext(this, &aContext, &aAction);
mIMContext->SetInputContext(this, &aContext, &aAction);
}
NS_IMETHODIMP_(InputContext)
nsWindow::GetInputContext()
{
InputContext context;
if (!mIMModule) {
if (!mIMContext) {
context.mIMEState.mEnabled = IMEState::DISABLED;
context.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
// If IME context isn't available on this widget, we should set |this|
@ -6019,8 +6019,8 @@ nsWindow::GetInputContext()
// context per process.
context.mNativeIMEContext = this;
} else {
context = mIMModule->GetInputContext();
context.mNativeIMEContext = mIMModule;
context = mIMContext->GetInputContext();
context.mNativeIMEContext = mIMContext;
}
return context;
}

View File

@ -31,7 +31,7 @@
#endif
#include "mozilla/EventForwards.h"
#include "nsGtkIMModule.h"
#include "IMContextWrapper.h"
#undef LOG
#ifdef MOZ_LOGGING
@ -478,7 +478,7 @@ private:
virtual int32_t RoundsWidgetCoordinatesTo() override;
/**
* |mIMModule| takes all IME related stuff.
* |mIMContext| takes all IME related stuff.
*
* This is owned by the top-level nsWindow or the topmost child
* nsWindow embedded in a non-Gecko widget.
@ -490,7 +490,7 @@ private:
* level window is released, the children still have a valid pointer,
* however, IME doesn't work at that time.
*/
nsRefPtr<nsGtkIMModule> mIMModule;
nsRefPtr<mozilla::widget::IMContextWrapper> mIMContext;
// HiDPI scale conversion
gint GdkScaleFactor();