mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 13:21:28 +00:00
Bug 960866 part.3 Remove nsEditor::mIsIMEComposing r=ehsan+smaug
This commit is contained in:
parent
60004ecf5b
commit
5bda7611c7
@ -27,7 +27,8 @@ TextComposition::TextComposition(nsPresContext* aPresContext,
|
||||
mPresContext(aPresContext), mNode(aNode),
|
||||
mNativeContext(aEvent->widget->GetInputContext().mNativeIMEContext),
|
||||
mCompositionStartOffset(0), mCompositionTargetOffset(0),
|
||||
mIsSynthesizedForTests(aEvent->mFlags.mIsSynthesizedForTests)
|
||||
mIsSynthesizedForTests(aEvent->mFlags.mIsSynthesizedForTests),
|
||||
mIsComposing(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,6 +50,8 @@ TextComposition::DispatchEvent(WidgetGUIEvent* aEvent,
|
||||
nsEventDispatcher::Dispatch(mNode, mPresContext,
|
||||
aEvent, nullptr, aStatus, aCallBack);
|
||||
|
||||
MOZ_ASSERT_IF(aEvent->message == NS_COMPOSITION_END, !mIsComposing);
|
||||
|
||||
// Notify composition update to widget if possible
|
||||
NotityUpdateComposition(aEvent);
|
||||
}
|
||||
@ -123,6 +126,12 @@ TextComposition::NotifyIME(widget::NotificationToIME aNotification)
|
||||
return nsIMEStateManager::NotifyIME(aNotification, mPresContext);
|
||||
}
|
||||
|
||||
void
|
||||
TextComposition::EditorWillHandleTextEvent(const WidgetTextEvent* aTextEvent)
|
||||
{
|
||||
mIsComposing = aTextEvent->IsComposing();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* TextComposition::CompositionEventDispatcher
|
||||
******************************************************************************/
|
||||
|
@ -73,6 +73,18 @@ public:
|
||||
*/
|
||||
uint32_t OffsetOfTargetClause() const { return mCompositionTargetOffset; }
|
||||
|
||||
/**
|
||||
* Returns true if there is non-empty composition string and it's not fixed.
|
||||
* Otherwise, false.
|
||||
*/
|
||||
bool IsComposing() const { return mIsComposing; }
|
||||
|
||||
/**
|
||||
* EditorWillHandleTextEvent() must be called before the focused editor
|
||||
* handles the text event.
|
||||
*/
|
||||
void EditorWillHandleTextEvent(const WidgetTextEvent* aTextEvent);
|
||||
|
||||
private:
|
||||
// This class holds nsPresContext weak. This instance shouldn't block
|
||||
// destroying it. When the presContext is being destroyed, it's notified to
|
||||
@ -98,6 +110,9 @@ private:
|
||||
// See the comment for IsSynthesizedForTests().
|
||||
bool mIsSynthesizedForTests;
|
||||
|
||||
// See the comment for IsComposing().
|
||||
bool mIsComposing;
|
||||
|
||||
// Hide the default constructor and copy constructor.
|
||||
TextComposition() {}
|
||||
TextComposition(const TextComposition& aOther);
|
||||
|
@ -144,7 +144,6 @@ nsEditor::nsEditor()
|
||||
, mDirection(eNone)
|
||||
, mDocDirtyState(-1)
|
||||
, mSpellcheckCheckboxState(eTriUnset)
|
||||
, mIsIMEComposing(false)
|
||||
, mShouldTxnSetSelection(true)
|
||||
, mDidPreDestroy(false)
|
||||
, mDidPostCreate(false)
|
||||
@ -2058,7 +2057,6 @@ nsEditor::EndIMEComposition()
|
||||
mIMETextNode = nullptr;
|
||||
mIMETextOffset = 0;
|
||||
mIMEBufferLength = 0;
|
||||
mIsIMEComposing = false;
|
||||
mComposition = nullptr;
|
||||
|
||||
// notify editor observers of action
|
||||
@ -4201,39 +4199,10 @@ nsEditor::GetIMEBufferLength()
|
||||
return mIMEBufferLength;
|
||||
}
|
||||
|
||||
void
|
||||
nsEditor::SetIsIMEComposing(){
|
||||
// We set mIsIMEComposing according to mIMETextRangeList.
|
||||
nsCOMPtr<nsIPrivateTextRange> rangePtr;
|
||||
uint16_t listlen, type;
|
||||
|
||||
mIsIMEComposing = false;
|
||||
listlen = mIMETextRangeList->GetLength();
|
||||
|
||||
for (uint16_t i = 0; i < listlen; i++)
|
||||
{
|
||||
rangePtr = mIMETextRangeList->Item(i);
|
||||
if (!rangePtr) continue;
|
||||
nsresult result = rangePtr->GetRangeType(&type);
|
||||
if (NS_FAILED(result)) continue;
|
||||
if ( type == nsIPrivateTextRange::TEXTRANGE_RAWINPUT ||
|
||||
type == nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT ||
|
||||
type == nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT ||
|
||||
type == nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT )
|
||||
{
|
||||
mIsIMEComposing = true;
|
||||
#ifdef DEBUG_IME
|
||||
printf("nsEditor::mIsIMEComposing = true\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool
|
||||
nsEditor::IsIMEComposing() {
|
||||
return mIsIMEComposing;
|
||||
nsEditor::IsIMEComposing() const
|
||||
{
|
||||
return mComposition && mComposition->IsComposing();
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -600,8 +600,10 @@ public:
|
||||
nsINode* GetFirstEditableNode(nsINode* aRoot);
|
||||
|
||||
int32_t GetIMEBufferLength();
|
||||
bool IsIMEComposing(); /* test if IME is in composition state */
|
||||
void SetIsIMEComposing(); /* call this before |IsIMEComposing()| */
|
||||
/**
|
||||
* Returns true if there is composition string and not fixed.
|
||||
*/
|
||||
bool IsIMEComposing() const;
|
||||
|
||||
/** from html rules code - migration in progress */
|
||||
static nsresult GetTagString(nsIDOMNode *aNode, nsAString& outString);
|
||||
@ -864,8 +866,6 @@ protected:
|
||||
int8_t mDocDirtyState; // -1 = not initialized
|
||||
uint8_t mSpellcheckCheckboxState; // a Tristate value
|
||||
|
||||
bool mIsIMEComposing; // is IME in composition state?
|
||||
|
||||
bool mShouldTxnSetSelection; // turn off for conservative selection adjustment by txns
|
||||
bool mDidPreDestroy; // whether PreDestroy has been called
|
||||
bool mDidPostCreate; // whether PostCreate has been called
|
||||
|
@ -20,6 +20,7 @@ FAIL_ON_WARNINGS = True
|
||||
LOCAL_INCLUDES += [
|
||||
'../base',
|
||||
'/content/base/src',
|
||||
'/dom/events',
|
||||
'/editor/txmgr/src',
|
||||
]
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
#include "TextComposition.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Selection.h"
|
||||
@ -848,17 +849,18 @@ nsPlaintextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent)
|
||||
|
||||
nsRefPtr<nsCaret> caretP = ps->GetCaret();
|
||||
|
||||
// Update information of clauses in the new composition string.
|
||||
// This will be refered by followed methods.
|
||||
nsCOMPtr<nsIPrivateTextEvent> privateTextEvent =
|
||||
do_QueryInterface(aDOMTextEvent);
|
||||
NS_ENSURE_TRUE(privateTextEvent, NS_ERROR_INVALID_ARG);
|
||||
|
||||
// XXX This approach is ugly, we should sort out the text event handling.
|
||||
mComposition->EditorWillHandleTextEvent(widgetTextEvent);
|
||||
|
||||
// Update information of clauses in the new composition string.
|
||||
// This will be refered by followed methods.
|
||||
mIMETextRangeList = privateTextEvent->GetInputRange();
|
||||
NS_ABORT_IF_FALSE(mIMETextRangeList, "mIMETextRangeList must not be nullptr");
|
||||
|
||||
// We set mIsIMEComposing properly.
|
||||
SetIsIMEComposing();
|
||||
|
||||
{
|
||||
nsAutoPlaceHolderBatch batch(this, nsGkAtoms::IMETxnName);
|
||||
|
||||
@ -875,7 +877,7 @@ nsPlaintextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent)
|
||||
// Note that if committed, we don't need to notify it since it will be
|
||||
// notified at followed compositionend event.
|
||||
// NOTE: We must notify after the auto batch will be gone.
|
||||
if (mIsIMEComposing) {
|
||||
if (IsIMEComposing()) {
|
||||
NotifyEditorObservers();
|
||||
}
|
||||
|
||||
|
@ -236,6 +236,16 @@ public:
|
||||
// Currently, we don't need to copy the other members because they are
|
||||
// for internal use only (not available from JS).
|
||||
}
|
||||
|
||||
bool IsComposing() const
|
||||
{
|
||||
for (uint32_t i = 0; i < rangeCount; i++) {
|
||||
if (rangeArray[i].IsClause()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -147,6 +147,14 @@ struct TextRange
|
||||
TextRangeStyle mRangeStyle;
|
||||
|
||||
uint32_t Length() const { return mEndOffset - mStartOffset; }
|
||||
|
||||
bool IsClause() const
|
||||
{
|
||||
MOZ_ASSERT(mRangeType >= NS_TEXTRANGE_CARETPOSITION &&
|
||||
mRangeType <= NS_TEXTRANGE_SELECTEDCONVERTEDTEXT,
|
||||
"Invalid range type");
|
||||
return mRangeType != NS_TEXTRANGE_CARETPOSITION;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
|
Loading…
x
Reference in New Issue
Block a user