2010-03-19 07:21:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
#ifndef IMContextWrapper_h_
|
|
|
|
#define IMContextWrapper_h_
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2014-03-04 17:48:27 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2010-03-19 07:21:16 +03:00
|
|
|
#include "nsTArray.h"
|
2011-11-27 15:51:52 +04:00
|
|
|
#include "nsIWidget.h"
|
2015-06-11 13:50:15 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2015-06-11 13:50:15 +03:00
|
|
|
#include "WritingModes.h"
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
class nsWindow;
|
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
2011-11-27 15:51:52 +04:00
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
class IMContextWrapper final
|
|
|
|
{
|
2010-03-19 07:21:16 +03:00
|
|
|
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).
|
2015-07-27 02:23:04 +03:00
|
|
|
explicit IMContextWrapper(nsWindow* aOwnerWindow);
|
2014-11-10 12:07:45 +03:00
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(IMContextWrapper)
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2011-01-14 16:40:08 +03:00
|
|
|
// "Enabled" means the users can use all IMEs.
|
|
|
|
// I.e., the focus is in the normal editors.
|
2014-11-10 12:07:44 +03:00
|
|
|
bool IsEnabled() const;
|
2011-01-14 16:40:08 +03:00
|
|
|
|
2015-08-06 09:57:58 +03:00
|
|
|
nsIMEUpdatePreference GetIMEUpdatePreference() const;
|
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// OnFocusWindow is a notification that aWindow is going to be focused.
|
|
|
|
void OnFocusWindow(nsWindow* aWindow);
|
|
|
|
// OnBlurWindow is a notification that aWindow is going to be unfocused.
|
|
|
|
void OnBlurWindow(nsWindow* aWindow);
|
|
|
|
// OnDestroyWindow is a notification that aWindow is going to be destroyed.
|
|
|
|
void OnDestroyWindow(nsWindow* aWindow);
|
|
|
|
// OnFocusChangeInGecko is a notification that an editor gets focus.
|
2011-09-29 10:19:26 +04:00
|
|
|
void OnFocusChangeInGecko(bool aFocus);
|
2014-09-26 04:05:13 +04:00
|
|
|
// OnSelectionChange is a notification that selection (caret) is changed
|
|
|
|
// in the focused editor.
|
2015-06-11 13:50:15 +03:00
|
|
|
void OnSelectionChange(nsWindow* aCaller,
|
|
|
|
const IMENotification& aIMENotification);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// OnKeyEvent is called when aWindow gets a native key press event or a
|
|
|
|
// native key release event. If this returns TRUE, the key event was
|
|
|
|
// filtered by IME. Otherwise, this returns FALSE.
|
|
|
|
// NOTE: When the keypress event starts composition, this returns TRUE but
|
|
|
|
// this dispatches keydown event before compositionstart event.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool OnKeyEvent(nsWindow* aWindow, GdkEventKey* aEvent,
|
|
|
|
bool aKeyDownEventWasSent = false);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// IME related nsIWidget methods.
|
2014-09-26 04:05:13 +04:00
|
|
|
nsresult EndIMEComposition(nsWindow* aCaller);
|
2011-11-27 15:51:52 +04:00
|
|
|
void SetInputContext(nsWindow* aCaller,
|
|
|
|
const InputContext* aContext,
|
|
|
|
const InputContextAction* aAction);
|
|
|
|
InputContext GetInputContext();
|
2014-01-16 14:04:48 +04:00
|
|
|
void OnUpdateComposition();
|
2015-06-11 13:50:15 +03:00
|
|
|
void OnLayoutChange();
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
protected:
|
2015-07-27 02:23:04 +03:00
|
|
|
~IMContextWrapper();
|
2014-11-10 12:07:45 +03:00
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// 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
|
|
|
|
// the IME contexts need the native window. If OnDestroyWindow() is called
|
|
|
|
// with the owner window, it'll release IME contexts. Otherwise, it'll
|
|
|
|
// just clean up any existing composition if it's related to the destroying
|
|
|
|
// child window.
|
|
|
|
nsWindow* mOwnerWindow;
|
|
|
|
|
|
|
|
// A last focused window in this class's context.
|
|
|
|
nsWindow* mLastFocusedWindow;
|
|
|
|
|
|
|
|
// Actual context. This is used for handling the user's input.
|
2014-11-10 12:07:44 +03:00
|
|
|
GtkIMContext* mContext;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// mSimpleContext is used for the password field and
|
2014-01-28 13:02:08 +04:00
|
|
|
// the |ime-mode: disabled;| editors if sUseSimpleContext is true.
|
|
|
|
// These editors disable IME. But dead keys should work. Fortunately,
|
|
|
|
// the simple IM context of GTK2 support only them.
|
2014-11-10 12:07:44 +03:00
|
|
|
GtkIMContext* mSimpleContext;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// mDummyContext is a dummy context and will be used in Focus()
|
|
|
|
// when the state of mEnabled means disabled. This context's IME state is
|
|
|
|
// always "closed", so it closes IME forcedly.
|
2014-11-10 12:07:44 +03:00
|
|
|
GtkIMContext* mDummyContext;
|
|
|
|
|
|
|
|
// mComposingContext is not nullptr while one of mContext, mSimpleContext
|
|
|
|
// and mDummyContext has composition.
|
|
|
|
// XXX: We don't assume that two or more context have composition same time.
|
|
|
|
GtkIMContext* mComposingContext;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
// IME enabled state and other things defined in InputContext.
|
2010-03-19 07:21:16 +03:00
|
|
|
// Use following helper methods if you don't need the detail of the status.
|
2011-11-27 15:51:52 +04:00
|
|
|
InputContext mInputContext;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// mCompositionStart is the start offset of the composition string in the
|
|
|
|
// current content. When <textarea> or <input> have focus, it means offset
|
|
|
|
// from the first character of them. When a HTML editor has focus, it
|
|
|
|
// means offset from the first character of the root element of the editor.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCompositionStart;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2011-09-22 13:17:40 +04:00
|
|
|
// mDispatchedCompositionString is the latest composition string which
|
|
|
|
// was dispatched by compositionupdate event.
|
|
|
|
nsString mDispatchedCompositionString;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2012-03-09 08:27:51 +04:00
|
|
|
// mSelectedString is the selected string which was removed by first
|
2014-10-07 14:01:47 +04:00
|
|
|
// compositionchange event.
|
2012-03-09 08:27:51 +04:00
|
|
|
nsString mSelectedString;
|
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// OnKeyEvent() temporarily sets mProcessingKeyEvent to the given native
|
|
|
|
// event.
|
|
|
|
GdkEventKey* mProcessingKeyEvent;
|
|
|
|
|
2015-06-11 13:50:15 +03:00
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
uint32_t mOffset;
|
|
|
|
uint32_t mLength;
|
|
|
|
|
|
|
|
Range()
|
|
|
|
: mOffset(UINT32_MAX)
|
|
|
|
, mLength(UINT32_MAX)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid() const { return mOffset != UINT32_MAX; }
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mOffset = UINT32_MAX;
|
|
|
|
mLength = UINT32_MAX;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// current target offset and length of IME composition
|
|
|
|
Range mCompositionTargetRange;
|
2014-01-16 14:04:48 +04:00
|
|
|
|
2012-03-09 08:27:51 +04:00
|
|
|
// mCompositionState indicates current status of composition.
|
|
|
|
enum eCompositionState {
|
|
|
|
eCompositionState_NotComposing,
|
|
|
|
eCompositionState_CompositionStartDispatched,
|
2014-11-25 08:02:34 +03:00
|
|
|
eCompositionState_CompositionChangeEventDispatched
|
2012-03-09 08:27:51 +04:00
|
|
|
};
|
|
|
|
eCompositionState mCompositionState;
|
|
|
|
|
2015-03-19 19:52:24 +03:00
|
|
|
bool IsComposing() const
|
2012-03-09 08:27:51 +04:00
|
|
|
{
|
|
|
|
return (mCompositionState != eCompositionState_NotComposing);
|
|
|
|
}
|
|
|
|
|
2015-03-19 19:52:24 +03:00
|
|
|
bool IsComposingOn(GtkIMContext* aContext) const
|
|
|
|
{
|
|
|
|
return IsComposing() && mComposingContext == aContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsComposingOnCurrentContext() const
|
|
|
|
{
|
|
|
|
return IsComposingOn(GetCurrentContext());
|
|
|
|
}
|
|
|
|
|
2012-03-09 08:27:51 +04:00
|
|
|
bool EditorHasCompositionString()
|
|
|
|
{
|
2014-10-07 14:01:49 +04:00
|
|
|
return (mCompositionState ==
|
|
|
|
eCompositionState_CompositionChangeEventDispatched);
|
2012-03-09 08:27:51 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 21:17:15 +04:00
|
|
|
/**
|
|
|
|
* Checks if aContext is valid context for handling composition.
|
|
|
|
*
|
|
|
|
* @param aContext An IM context which is specified by native
|
|
|
|
* composition events.
|
|
|
|
* @return true if the context is valid context for
|
|
|
|
* handling composition. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool IsValidContext(GtkIMContext* aContext) const;
|
|
|
|
|
2012-03-09 08:27:51 +04:00
|
|
|
const char* GetCompositionStateName()
|
|
|
|
{
|
|
|
|
switch (mCompositionState) {
|
|
|
|
case eCompositionState_NotComposing:
|
|
|
|
return "NotComposing";
|
|
|
|
case eCompositionState_CompositionStartDispatched:
|
|
|
|
return "CompositionStartDispatched";
|
2014-10-07 14:01:49 +04:00
|
|
|
case eCompositionState_CompositionChangeEventDispatched:
|
|
|
|
return "CompositionChangeEventDispatched";
|
2012-03-09 08:27:51 +04:00
|
|
|
default:
|
|
|
|
return "InvaildState";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 13:50:15 +03:00
|
|
|
struct Selection final
|
|
|
|
{
|
|
|
|
uint32_t mOffset;
|
|
|
|
uint32_t mLength;
|
2015-07-27 02:23:04 +03:00
|
|
|
WritingMode mWritingMode;
|
2015-06-11 13:50:15 +03:00
|
|
|
|
|
|
|
Selection()
|
|
|
|
: mOffset(UINT32_MAX)
|
|
|
|
, mLength(UINT32_MAX)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mOffset = UINT32_MAX;
|
|
|
|
mLength = UINT32_MAX;
|
2015-07-27 02:23:04 +03:00
|
|
|
mWritingMode = WritingMode();
|
2015-06-11 13:50:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Assign(const IMENotification& aIMENotification);
|
2015-07-27 02:23:04 +03:00
|
|
|
void Assign(const WidgetQueryContentEvent& aSelectedTextEvent);
|
2015-06-11 13:50:15 +03:00
|
|
|
|
|
|
|
bool IsValid() const { return mOffset != UINT32_MAX; }
|
|
|
|
bool Collapsed() const { return !mLength; }
|
|
|
|
uint32_t EndOffset() const
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!IsValid())) {
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2015-07-27 02:23:04 +03:00
|
|
|
CheckedInt<uint32_t> endOffset =
|
|
|
|
CheckedInt<uint32_t>(mOffset) + mLength;
|
2015-06-11 13:50:15 +03:00
|
|
|
if (NS_WARN_IF(!endOffset.isValid())) {
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
return endOffset.value();
|
|
|
|
}
|
|
|
|
} mSelection;
|
|
|
|
bool EnsureToCacheSelection(nsAString* aSelectedString = nullptr);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// mIsIMFocused is set to TRUE when we call gtk_im_context_focus_in(). And
|
|
|
|
// it's set to FALSE when we call gtk_im_context_focus_out().
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsIMFocused;
|
2010-03-19 07:21:16 +03:00
|
|
|
// mFilterKeyEvent is used by OnKeyEvent(). If the commit event should
|
|
|
|
// be processed as simple key event, this is set to TRUE by the commit
|
|
|
|
// handler.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFilterKeyEvent;
|
2011-01-14 16:40:08 +03:00
|
|
|
// mKeyDownEventWasSent is used by OnKeyEvent() and
|
|
|
|
// DispatchCompositionStart(). DispatchCompositionStart() dispatches
|
|
|
|
// a keydown event if the composition start is caused by a native
|
|
|
|
// keypress event. If this is true, the keydown event has been dispatched.
|
|
|
|
// Then, DispatchCompositionStart() doesn't dispatch keydown event.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mKeyDownEventWasSent;
|
2015-03-17 10:07:02 +03:00
|
|
|
// mIsDeletingSurrounding is true while OnDeleteSurroundingNative() is
|
|
|
|
// trying to delete the surrounding text.
|
|
|
|
bool mIsDeletingSurrounding;
|
2015-06-11 13:50:15 +03:00
|
|
|
// mLayoutChanged is true after OnLayoutChange() is called. This is reset
|
|
|
|
// when NS_COMPOSITION_CHANGE is being dispatched.
|
|
|
|
bool mLayoutChanged;
|
2015-06-26 10:08:29 +03:00
|
|
|
// mSetCursorPositionOnKeyEvent true when caret rect or position is updated
|
|
|
|
// with no composition. If true, we update candidate window position
|
|
|
|
// before key down
|
|
|
|
bool mSetCursorPositionOnKeyEvent;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
// sLastFocusedContext is a pointer to the last focused instance of this
|
|
|
|
// class. When a instance is destroyed and sLastFocusedContext refers it,
|
2010-03-19 07:21:16 +03:00
|
|
|
// this is cleared. So, this refers valid pointer always.
|
2015-07-27 02:23:04 +03:00
|
|
|
static IMContextWrapper* sLastFocusedContext;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-01-28 13:02:08 +04:00
|
|
|
// sUseSimpleContext indeicates if password editors and editors with
|
|
|
|
// |ime-mode: disabled;| should use GtkIMContextSimple.
|
|
|
|
// If true, they use GtkIMContextSimple. Otherwise, not.
|
|
|
|
static bool sUseSimpleContext;
|
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// Callback methods for native IME events. These methods should call
|
|
|
|
// the related instance methods simply.
|
2015-07-27 02:23:04 +03:00
|
|
|
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);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// The instance methods for the native IME events.
|
2015-07-27 02:23:04 +03:00
|
|
|
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);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-11-10 12:07:43 +03:00
|
|
|
/**
|
2014-11-10 12:07:44 +03:00
|
|
|
* GetCurrentContext() returns current IM context which is chosen with the
|
|
|
|
* enabled state.
|
2014-11-10 12:07:43 +03:00
|
|
|
* WARNING:
|
|
|
|
* When this class receives some signals for a composition after focus
|
|
|
|
* is moved in Gecko, the result of this may be different from given
|
|
|
|
* context by the signals.
|
|
|
|
*/
|
2014-11-10 12:07:44 +03:00
|
|
|
GtkIMContext* GetCurrentContext() const;
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-11-10 12:07:44 +03:00
|
|
|
/**
|
|
|
|
* GetActiveContext() returns a composing context or current context.
|
|
|
|
*/
|
|
|
|
GtkIMContext* GetActiveContext() const
|
|
|
|
{
|
|
|
|
return mComposingContext ? mComposingContext : GetCurrentContext();
|
|
|
|
}
|
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// If the owner window and IM context have been destroyed, returns TRUE.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDestroyed() { return !mOwnerWindow; }
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// Sets focus to the instance of this class.
|
|
|
|
void Focus();
|
|
|
|
|
|
|
|
// Steals focus from the instance of this class.
|
|
|
|
void Blur();
|
|
|
|
|
|
|
|
// Initializes the instance.
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
// Reset the current composition of IME. All native composition events
|
|
|
|
// during this processing are ignored.
|
|
|
|
void ResetIME();
|
|
|
|
|
|
|
|
// Gets the current composition string by the native APIs.
|
2014-10-23 21:17:15 +04:00
|
|
|
void GetCompositionString(GtkIMContext* aContext,
|
|
|
|
nsAString& aCompositionString);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-11-10 12:07:43 +03:00
|
|
|
/**
|
|
|
|
* Generates our text range array from current composition string.
|
|
|
|
*
|
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
2015-08-19 10:37:39 +03:00
|
|
|
* @param aCompositionString The data to be dispatched with
|
|
|
|
* compositionchange event.
|
2014-11-10 12:07:43 +03:00
|
|
|
*/
|
2015-07-27 02:23:04 +03:00
|
|
|
already_AddRefed<TextRangeArray>
|
2014-11-10 12:07:43 +03:00
|
|
|
CreateTextRangeArray(GtkIMContext* aContext,
|
2015-08-19 10:37:39 +03:00
|
|
|
const nsAString& aCompositionString);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2015-08-19 10:37:39 +03:00
|
|
|
/**
|
|
|
|
* SetTextRange() initializes aTextRange with aPangoAttrIter.
|
|
|
|
*
|
|
|
|
* @param aPangoAttrIter An iter which represents a clause of the
|
|
|
|
* composition string.
|
|
|
|
* @param aUTF8CompositionString The whole composition string (UTF-8).
|
2015-08-19 10:37:39 +03:00
|
|
|
* @param aUTF16CaretOffset The caret offset in the composition
|
|
|
|
* string encoded as UTF-16.
|
2015-08-19 10:37:39 +03:00
|
|
|
* @param aTextRange The result.
|
|
|
|
* @return true if this initializes aTextRange.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool SetTextRange(PangoAttrIterator* aPangoAttrIter,
|
|
|
|
const gchar* aUTF8CompositionString,
|
2015-08-19 10:37:39 +03:00
|
|
|
uint32_t aUTF16CaretOffset,
|
2015-08-19 10:37:39 +03:00
|
|
|
TextRange& aTextRange) const;
|
|
|
|
|
2015-08-19 10:37:39 +03:00
|
|
|
/**
|
|
|
|
* ToNscolor() converts the PangoColor in aPangoAttrColor to nscolor.
|
|
|
|
*/
|
|
|
|
static nscolor ToNscolor(PangoAttrColor* aPangoAttrColor);
|
|
|
|
|
2014-11-10 12:07:43 +03:00
|
|
|
/**
|
2015-06-11 13:50:15 +03:00
|
|
|
* Move the candidate window with "fake" cursor position.
|
2014-11-10 12:07:43 +03:00
|
|
|
*
|
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
|
|
|
*/
|
2015-06-11 13:50:15 +03:00
|
|
|
void SetCursorPosition(GtkIMContext* aContext);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// Queries the current selection offset of the window.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetSelectionOffset(nsWindow* aWindow);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2010-03-24 18:04:39 +03:00
|
|
|
// Get current paragraph text content and cursor position
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult GetCurrentParagraph(nsAString& aText, uint32_t& aCursorPos);
|
2010-03-24 18:04:39 +03:00
|
|
|
|
2014-11-10 12:07:43 +03:00
|
|
|
/**
|
|
|
|
* Delete text portion
|
|
|
|
*
|
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
|
|
|
* @param aOffset Start offset of the range to delete.
|
|
|
|
* @param aNChars Count of characters to delete. It depends
|
|
|
|
* on |g_utf8_strlen()| what is one character.
|
|
|
|
*/
|
|
|
|
nsresult DeleteText(GtkIMContext* aContext,
|
|
|
|
int32_t aOffset,
|
|
|
|
uint32_t aNChars);
|
2010-03-24 18:04:39 +03:00
|
|
|
|
2010-03-19 07:21:16 +03:00
|
|
|
// Initializes the GUI event.
|
2015-07-27 02:23:04 +03:00
|
|
|
void InitEvent(WidgetGUIEvent& aEvent);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
// Called before destroying the context to work around some platform bugs.
|
2015-07-27 02:23:04 +03:00
|
|
|
void PrepareToDestroyContext(GtkIMContext* aContext);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WARNING:
|
|
|
|
* Following methods dispatch gecko events. Then, the focused widget
|
|
|
|
* can be destroyed, and also it can be stolen focus. If they returns
|
|
|
|
* FALSE, callers cannot continue the composition.
|
|
|
|
* - DispatchCompositionStart
|
2014-10-07 14:01:49 +04:00
|
|
|
* - DispatchCompositionChangeEvent
|
2014-11-25 08:02:34 +03:00
|
|
|
* - DispatchCompositionCommitEvent
|
2010-03-19 07:21:16 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-10 12:07:42 +03:00
|
|
|
/**
|
|
|
|
* Dispatches a composition start event.
|
|
|
|
*
|
2014-11-10 12:07:43 +03:00
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
2014-11-10 12:07:42 +03:00
|
|
|
* @return true if the focused widget is neither
|
|
|
|
* destroyed nor changed. Otherwise, false.
|
|
|
|
*/
|
2014-11-10 12:07:43 +03:00
|
|
|
bool DispatchCompositionStart(GtkIMContext* aContext);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-11-10 12:07:42 +03:00
|
|
|
/**
|
|
|
|
* Dispatches a compositionchange event.
|
|
|
|
*
|
2014-11-10 12:07:43 +03:00
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
2014-11-10 12:07:42 +03:00
|
|
|
* @param aCompositionString New composition string.
|
|
|
|
* @return true if the focused widget is neither
|
|
|
|
* destroyed nor changed. Otherwise, false.
|
|
|
|
*/
|
2014-11-10 12:07:43 +03:00
|
|
|
bool DispatchCompositionChangeEvent(GtkIMContext* aContext,
|
|
|
|
const nsAString& aCompositionString);
|
2010-03-19 07:21:16 +03:00
|
|
|
|
2014-11-10 12:07:42 +03:00
|
|
|
/**
|
2014-11-25 08:02:34 +03:00
|
|
|
* Dispatches a compositioncommit event or compositioncommitasis event.
|
2014-11-10 12:07:42 +03:00
|
|
|
*
|
2014-11-10 12:07:43 +03:00
|
|
|
* @param aContext A GtkIMContext which is being handled.
|
2014-11-25 08:02:34 +03:00
|
|
|
* @param aCommitString If this is nullptr, the composition will
|
|
|
|
* be committed with last dispatched data.
|
|
|
|
* Otherwise, the composition will be
|
|
|
|
* committed with this value.
|
2014-11-10 12:07:42 +03:00
|
|
|
* @return true if the focused widget is neither
|
|
|
|
* destroyed nor changed. Otherwise, false.
|
|
|
|
*/
|
2014-11-25 08:02:34 +03:00
|
|
|
bool DispatchCompositionCommitEvent(
|
|
|
|
GtkIMContext* aContext,
|
|
|
|
const nsAString* aCommitString = nullptr);
|
2010-03-19 07:21:16 +03:00
|
|
|
};
|
|
|
|
|
2015-07-27 02:23:04 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef IMContextWrapper_h_
|