Bug 1166436 part.3 mozilla::ContentCache should store active composition information and TabParent should use them r=m_kato

This commit is contained in:
Masayuki Nakano
2015-06-05 18:28:19 +09:00
parent 1811b8227a
commit 73284ee831
4 changed files with 117 additions and 61 deletions

View File

@@ -6,9 +6,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ContentCache.h"
#include "mozilla/TextEvents.h"
#include "nsIWidget.h"
namespace mozilla {
using namespace widget;
ContentCache::ContentCache()
: mCompositionStart(UINT32_MAX)
, mCompositionEventsDuringRequest(0)
, mIsComposing(false)
, mRequestedToCommitOrCancelComposition(false)
{
}
void
ContentCache::Clear()
{
@@ -28,4 +40,65 @@ ContentCache::SetSelection(uint32_t aAnchorOffset, uint32_t aFocusOffset)
mSelection.mFocus = aFocusOffset;
}
bool
ContentCache::OnCompositionEvent(const WidgetCompositionEvent& aEvent)
{
if (!aEvent.CausesDOMTextEvent()) {
MOZ_ASSERT(aEvent.message == NS_COMPOSITION_START);
mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
mCompositionStart = SelectionStart();
// XXX What's this case??
if (mRequestedToCommitOrCancelComposition) {
mCommitStringByRequest = aEvent.mData;
mCompositionEventsDuringRequest++;
return false;
}
return true;
}
// XXX Why do we ignore following composition events here?
// TextComposition must handle following events correctly!
// During REQUEST_TO_COMMIT_COMPOSITION or REQUEST_TO_CANCEL_COMPOSITION,
// widget usually sends a NS_COMPOSITION_CHANGE event to finalize or
// clear the composition, respectively.
// Because the event will not reach content in time, we intercept it
// here and pass the text as the DidRequestToCommitOrCancelComposition()
// return value.
if (mRequestedToCommitOrCancelComposition) {
mCommitStringByRequest = aEvent.mData;
mCompositionEventsDuringRequest++;
return false;
}
// We must be able to simulate the selection because
// we might not receive selection updates in time
if (!mIsComposing) {
mCompositionStart = SelectionStart();
}
// XXX This causes different behavior from non-e10s mode.
// Selection range should represent caret position in the composition
// string but this means selection range is all of the composition string.
SetSelection(mCompositionStart + aEvent.mData.Length());
mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
return true;
}
uint32_t
ContentCache::RequestToCommitComposition(nsIWidget* aWidget,
bool aCancel,
nsAString& aLastString)
{
mRequestedToCommitOrCancelComposition = true;
mCompositionEventsDuringRequest = 0;
aWidget->NotifyIME(IMENotification(aCancel ? REQUEST_TO_CANCEL_COMPOSITION :
REQUEST_TO_COMMIT_COMPOSITION));
mRequestedToCommitOrCancelComposition = false;
aLastString = mCommitStringByRequest;
mCommitStringByRequest.Truncate(0);
return mCompositionEventsDuringRequest;
}
} // namespace mozilla