Bug 917322 part.5 Implement TextEventDispatcher::StartComposition() and nsDOMWindowUtils should use it r=smaug
This commit is contained in:
@@ -2134,6 +2134,35 @@ InitEvent(WidgetGUIEvent& aEvent, LayoutDeviceIntPoint* aPt = nullptr)
|
|||||||
aEvent.time = PR_IntervalNow();
|
aEvent.time = PR_IntervalNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsDOMWindowUtils::GetTextEventDispatcher(TextEventDispatcher** aDispatcher)
|
||||||
|
{
|
||||||
|
if (!aDispatcher) {
|
||||||
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
*aDispatcher = nullptr;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIWidget> widget(GetWidget());
|
||||||
|
if (NS_WARN_IF(!widget)) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEventDispatcher* dispatcher = widget->GetTextEventDispatcher();
|
||||||
|
nsresult rv = dispatcher->GetState();
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
NS_ADDREF(*aDispatcher = dispatcher);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (rv == NS_ERROR_NOT_INITIALIZED) {
|
||||||
|
rv = dispatcher->InitForTests();
|
||||||
|
}
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
NS_ADDREF(*aDispatcher = dispatcher);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDOMWindowUtils::SendCompositionEvent(const nsAString& aType,
|
nsDOMWindowUtils::SendCompositionEvent(const nsAString& aType,
|
||||||
const nsAString& aData,
|
const nsAString& aData,
|
||||||
@@ -2149,7 +2178,13 @@ nsDOMWindowUtils::SendCompositionEvent(const nsAString& aType,
|
|||||||
|
|
||||||
uint32_t msg;
|
uint32_t msg;
|
||||||
if (aType.EqualsLiteral("compositionstart")) {
|
if (aType.EqualsLiteral("compositionstart")) {
|
||||||
msg = NS_COMPOSITION_START;
|
nsRefPtr<TextEventDispatcher> dispatcher;
|
||||||
|
nsresult rv = GetTextEventDispatcher(getter_AddRefs(dispatcher));
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
|
return dispatcher->StartComposition(status);
|
||||||
} else if (aType.EqualsLiteral("compositionend")) {
|
} else if (aType.EqualsLiteral("compositionend")) {
|
||||||
// Now we don't support manually dispatching composition end with this
|
// Now we don't support manually dispatching composition end with this
|
||||||
// API. A compositionend is dispatched when this is called with
|
// API. A compositionend is dispatched when this is called with
|
||||||
@@ -2205,11 +2240,9 @@ nsDOMWindowUtils::CreateCompositionStringSynthesizer(
|
|||||||
if (NS_WARN_IF(!widget)) {
|
if (NS_WARN_IF(!widget)) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
nsRefPtr<TextEventDispatcher> dispatcher(widget->GetTextEventDispatcher());
|
nsRefPtr<TextEventDispatcher> dispatcher;
|
||||||
nsresult rv = dispatcher->GetState();
|
nsresult rv = GetTextEventDispatcher(getter_AddRefs(dispatcher));
|
||||||
if (rv == NS_ERROR_NOT_INITIALIZED) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
dispatcher->InitForTests();
|
|
||||||
} else if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
NS_ADDREF(*aResult = new CompositionStringSynthesizer(dispatcher));
|
NS_ADDREF(*aResult = new CompositionStringSynthesizer(dispatcher));
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ private:
|
|||||||
class nsDOMWindowUtils MOZ_FINAL : public nsIDOMWindowUtils,
|
class nsDOMWindowUtils MOZ_FINAL : public nsIDOMWindowUtils,
|
||||||
public nsSupportsWeakReference
|
public nsSupportsWeakReference
|
||||||
{
|
{
|
||||||
|
typedef mozilla::widget::TextEventDispatcher
|
||||||
|
TextEventDispatcher;
|
||||||
public:
|
public:
|
||||||
explicit nsDOMWindowUtils(nsGlobalWindow *aWindow);
|
explicit nsDOMWindowUtils(nsGlobalWindow *aWindow);
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
@@ -78,6 +80,17 @@ protected:
|
|||||||
nsPresContext* GetPresContext();
|
nsPresContext* GetPresContext();
|
||||||
nsIDocument* GetDocument();
|
nsIDocument* GetDocument();
|
||||||
mozilla::layers::LayerTransactionChild* GetLayerTransaction();
|
mozilla::layers::LayerTransactionChild* GetLayerTransaction();
|
||||||
|
/**
|
||||||
|
* GetTextEventDispatcher() retrieves a TextEventDispatcher
|
||||||
|
* belonging to the widget (result of GetWidget()) and initializes it.
|
||||||
|
*
|
||||||
|
* @param [out] aDispatcher The TextEventDispatcher belonging to
|
||||||
|
* the widget which has already been
|
||||||
|
* initialized and addrefed.
|
||||||
|
* @return The result of TextEventDispatcher::InitForTest().
|
||||||
|
*/
|
||||||
|
nsresult GetTextEventDispatcher(
|
||||||
|
TextEventDispatcher** aDispatcher);
|
||||||
|
|
||||||
nsView* GetViewToDispatchEvent(nsPresContext* presContext, nsIPresShell** presShell);
|
nsView* GetViewToDispatchEvent(nsPresContext* presContext, nsIPresShell** presShell);
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,28 @@ TextEventDispatcher::InitEvent(WidgetCompositionEvent& aEvent) const
|
|||||||
aEvent.mFlags.mIsSynthesizedForTests = mForTests;
|
aEvent.mFlags.mIsSynthesizedForTests = mForTests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
TextEventDispatcher::StartComposition(nsEventStatus& aStatus)
|
||||||
|
{
|
||||||
|
aStatus = nsEventStatus_eIgnore;
|
||||||
|
|
||||||
|
nsresult rv = GetState();
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIWidget> widget(mWidget);
|
||||||
|
WidgetCompositionEvent compositionStartEvent(true, NS_COMPOSITION_START,
|
||||||
|
widget);
|
||||||
|
InitEvent(compositionStartEvent);
|
||||||
|
rv = widget->DispatchEvent(&compositionStartEvent, aStatus);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* TextEventDispatcher::PendingComposition
|
* TextEventDispatcher::PendingComposition
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
nsresult GetState() const;
|
nsresult GetState() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StartComposition() starts composition explicitly.
|
||||||
|
*/
|
||||||
|
nsresult StartComposition(nsEventStatus& aStatus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetPendingCompositionString() sets new composition string which will be
|
* SetPendingCompositionString() sets new composition string which will be
|
||||||
* dispatched with NS_COMPOSITION_CHANGE event by calling Flush().
|
* dispatched with NS_COMPOSITION_CHANGE event by calling Flush().
|
||||||
|
|||||||
Reference in New Issue
Block a user