2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsDOMTextEvent.h"
|
|
|
|
#include "nsPrivateTextRange.h"
|
2013-07-03 08:56:26 -07:00
|
|
|
#include "prtime.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMTextEvent::nsDOMTextEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent* aEvent)
|
2013-03-09 03:34:29 -08:00
|
|
|
: nsDOMUIEvent(aOwner, aPresContext,
|
2013-10-01 00:22:59 -07:00
|
|
|
aEvent ? aEvent : new WidgetTextEvent(false, 0, nullptr))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mEvent->eventStructType == NS_TEXT_EVENT, "event type mismatch");
|
|
|
|
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// extract the IME composition string
|
|
|
|
//
|
2013-10-17 23:10:24 -07:00
|
|
|
WidgetTextEvent* te = mEvent->AsTextEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
mText = te->theText;
|
|
|
|
|
|
|
|
//
|
|
|
|
// build the range list -- ranges need to be DOM-ified since the
|
|
|
|
// IME transaction will hold a ref, the widget representation
|
|
|
|
// isn't persistent
|
|
|
|
//
|
|
|
|
mTextRange = new nsPrivateTextRangeList(te->rangeCount);
|
|
|
|
if (mTextRange) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for(i = 0; i < te->rangeCount; i++) {
|
|
|
|
nsRefPtr<nsPrivateTextRange> tempPrivateTextRange = new
|
2009-04-22 20:27:12 -07:00
|
|
|
nsPrivateTextRange(te->rangeArray[i]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tempPrivateTextRange) {
|
|
|
|
mTextRange->AppendTextRange(tempPrivateTextRange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMTextEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_METHOD nsDOMTextEvent::GetText(nsString& aText)
|
|
|
|
{
|
|
|
|
aText = mText;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-09 16:31:19 -07:00
|
|
|
NS_METHOD_(already_AddRefed<nsIPrivateTextRangeList>) nsDOMTextEvent::GetInputRange()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-09 16:31:19 -07:00
|
|
|
if (mEvent->message == NS_TEXT_TEXT) {
|
|
|
|
nsRefPtr<nsPrivateTextRangeList> textRange = mTextRange;
|
2013-04-22 04:15:59 -07:00
|
|
|
return textRange.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewDOMTextEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMTextEvent* it = new nsDOMTextEvent(aOwner, aPresContext, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|