From 5189a2da1c1d904f4620f216a16a336aab11ad02 Mon Sep 17 00:00:00 2001 From: Tatiana Meshkova Date: Mon, 21 Jan 2013 20:43:11 -0800 Subject: [PATCH] Fixed composition with preEdit string, make it really works with swype keyboard --- .../embedthread/EmbedLiteViewThreadChild.cpp | 40 +++++++++++++------ .../embedthread/EmbedLiteViewThreadChild.h | 1 + .../tests/qt/qtwidget/qgraphicsmozview.cpp | 37 +---------------- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp b/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp index e5c9fa0bacf4..d504f264e163 100644 --- a/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp +++ b/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp @@ -44,6 +44,7 @@ EmbedLiteViewThreadChild::EmbedLiteViewThreadChild(uint32_t aId) , mDispatchSynthMouseEvents(true) , mHadResizeSinceLastFrameUpdate(false) , mModalDepth(0) + , mIsComposition(false) { LOGT(); AddRef(); @@ -347,31 +348,46 @@ EmbedLiteViewThreadChild::RecvHandleTextEvent(const nsString& commit, const nsSt if (!widget) return false; - { - nsCompositionEvent event(true, NS_COMPOSITION_START, widget); - mHelper->InitEvent(event, nullptr); - event.data = commit; - mHelper->DispatchWidgetEvent(event); + // probably logic here is over engineered, but clean enough + bool prevIsComposition = mIsComposition; + bool StartComposite = !prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty(); + bool UpdateComposite = prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty(); + bool EndComposite = prevIsComposition && !commit.IsEmpty() && preEdit.IsEmpty(); + mIsComposition = UpdateComposite || StartComposite; + nsString pushStr = preEdit.IsEmpty() ? commit : preEdit; + if (!commit.IsEmpty() && !EndComposite) { + StartComposite = UpdateComposite = EndComposite = true; } + if (StartComposite) { - nsCompositionEvent event(true, NS_COMPOSITION_UPDATE, widget); + nsCompositionEvent event(true, NS_COMPOSITION_START, widget); mHelper->InitEvent(event, nullptr); - event.data = commit; + event.data = pushStr; mHelper->DispatchWidgetEvent(event); } + if (StartComposite || UpdateComposite || EndComposite) { - nsTextEvent event(true, NS_TEXT_TEXT, widget); - mHelper->InitEvent(event, nullptr); - event.theText = commit; - mHelper->DispatchWidgetEvent(event); + { + nsCompositionEvent event(true, NS_COMPOSITION_UPDATE, widget); + mHelper->InitEvent(event, nullptr); + event.data = pushStr; + mHelper->DispatchWidgetEvent(event); + } + { + nsTextEvent event(true, NS_TEXT_TEXT, widget); + mHelper->InitEvent(event, nullptr); + event.theText = pushStr; + mHelper->DispatchWidgetEvent(event); + } } + if (EndComposite) { nsCompositionEvent event(true, NS_COMPOSITION_END, widget); mHelper->InitEvent(event, nullptr); - event.data = commit; + event.data = pushStr; mHelper->DispatchWidgetEvent(event); } diff --git a/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h b/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h index a2b159c3b1d4..45df83f3bd67 100644 --- a/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h +++ b/embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h @@ -103,6 +103,7 @@ class EmbedLiteViewThreadChild : public PEmbedLiteViewChild, bool mDispatchSynthMouseEvents; bool mHadResizeSinceLastFrameUpdate; int mModalDepth; + bool mIsComposition; std::map modalWinMap; DISALLOW_EVIL_CONSTRUCTORS(EmbedLiteViewThreadChild); diff --git a/embedding/embedlite/tests/qt/qtwidget/qgraphicsmozview.cpp b/embedding/embedlite/tests/qt/qtwidget/qgraphicsmozview.cpp index 75302fdbce53..0d5464b0d1e6 100644 --- a/embedding/embedlite/tests/qt/qtwidget/qgraphicsmozview.cpp +++ b/embedding/embedlite/tests/qt/qtwidget/qgraphicsmozview.cpp @@ -645,39 +645,6 @@ void QGraphicsMozView::keyReleaseEvent(QKeyEvent* event) QVariant QGraphicsMozView::inputMethodQuery(Qt::InputMethodQuery aQuery) const { - if (aQuery == 10001) { -// LOGT("VisualizationPriorityQuery"); - } - if (aQuery == 10003) { -// LOGT("ImCorrectionEnabledQuery"); - } - if (aQuery == 10004) { -// LOGT("ImModeQuery"); - } - if (aQuery == 10005) { -// LOGT("InputMethodToolbarIdQuery"); - } - if (aQuery == 10006) { -// LOGT("InputMethodAttributeExtensionIdQuery"); - } - if (aQuery == 10007) { -// LOGT("InputMethodToolbarQuery"); - } - if (aQuery == Qt::ImCurrentSelection) { -// LOGT("Qt::ImCurrentSelection"); - } - if (aQuery == Qt::ImMicroFocus) { -// LOGT("Qt::ImMicroFocus"); - } - if (aQuery == Qt::ImSurroundingText) { -// LOGT("Qt::ImSurroundingText"); - } - if (aQuery == Qt::ImCursorPosition) { -// LOGT("Qt::ImCursorPosition"); - } - if (aQuery == Qt::ImAnchorPosition) { -// LOGT("Qt::ImAnchorPosition"); - } - - return QVariant(0); + static bool commitNow = getenv("DO_FAST_COMMIT") != 0; + return commitNow ? QVariant(0) : QVariant(); }