From 62347a8f7bd3384d0141c9fc5683c0881e5dc5d8 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Mon, 15 Dec 2014 18:21:20 +0900 Subject: [PATCH] Bug 966157 - Part 1. Implement remote NS_QUERY_EDITOR_RECT. r=masayuki --- dom/events/EventStateManager.cpp | 4 +++- dom/ipc/PBrowser.ipdl | 7 +++++++ dom/ipc/TabParent.cpp | 15 +++++++++++++++ dom/ipc/TabParent.h | 2 ++ widget/PuppetWidget.cpp | 20 ++++++++++++++++++++ widget/PuppetWidget.h | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index b2100c9591a3..bee6a04825b5 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -742,7 +742,9 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, break; case NS_QUERY_EDITOR_RECT: { - // XXX remote event + if (RemoteQueryContentEvent(aEvent)) { + break; + } ContentEventHandler handler(mPresContext); handler.OnQueryEditorRect(aEvent->AsQueryContentEvent()); } diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index c09226643744..1caff32ba7f1 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -227,6 +227,13 @@ parent: prio(urgent) sync NotifyIMEMouseButtonEvent(IMENotification notification) returns (bool consumedByIME); + /** + * Notifies chrome to currect editor rect + * + * rect Rect of current focused editor + */ + prio(urgent) async NotifyIMEEditorRect(nsIntRect rect); + /** * Instructs chrome to end any pending composition * diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 919230f1a9e1..0fa7dca2587d 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1453,6 +1453,13 @@ TabParent::RecvNotifyIMEMouseButtonEvent( return true; } +bool +TabParent::RecvNotifyIMEEditorRect(const nsIntRect& aRect) +{ + mIMEEditorRect = aRect; + return true; +} + bool TabParent::RecvRequestFocus(const bool& aCanRaise) { @@ -1598,6 +1605,8 @@ TabParent::RecvDispatchAfterKeyboardEvent(const WidgetKeyboardEvent& aEvent) * Cocoa widget always queries selected offset, so it works on it. * * For NS_QUERY_CARET_RECT, fail if cached offset isn't equals to input + * + * For NS_QUERY_EDITOR_RECT, always success */ bool TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent) @@ -1682,6 +1691,12 @@ TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent) aEvent.mSucceeded = true; } break; + case NS_QUERY_EDITOR_RECT: + { + aEvent.mReply.mRect = mIMEEditorRect - GetChildProcessOffset(); + aEvent.mSucceeded = true; + } + break; } return true; } diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 44c02175f3fd..44fb9eccb4f2 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -178,6 +178,7 @@ public: virtual bool RecvNotifyIMETextHint(const nsString& aText) MOZ_OVERRIDE; virtual bool RecvNotifyIMEMouseButtonEvent(const widget::IMENotification& aEventMessage, bool* aConsumedByIME) MOZ_OVERRIDE; + virtual bool RecvNotifyIMEEditorRect(const nsIntRect& aRect) MOZ_OVERRIDE; virtual bool RecvEndIMEComposition(const bool& aCancel, nsString* aComposition) MOZ_OVERRIDE; virtual bool RecvGetInputContext(int32_t* aIMEEnabled, @@ -398,6 +399,7 @@ protected: InfallibleTArray mIMECompositionRects; uint32_t mIMECaretOffset; nsIntRect mIMECaretRect; + nsIntRect mIMEEditorRect; // The number of event series we're currently capturing. int32_t mEventCaptureDepth; diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 1177bd25cace..7aa6a7b43f77 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -530,6 +530,7 @@ PuppetWidget::NotifyIMEOfFocusChange(bool aFocus) IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE); notification.mSelectionChangeData.mCausedByComposition = false; NotifyIMEOfSelectionChange(notification); // Update selection + NotifyIMEOfEditorRect(); } else { mIMELastBlurSeqno = chromeSeqno; } @@ -577,6 +578,25 @@ PuppetWidget::NotifyIMEOfUpdateComposition() return NS_OK; } +nsresult +PuppetWidget::NotifyIMEOfEditorRect() +{ +#ifndef MOZ_CROSS_PROCESS_IME + return NS_OK; +#endif + + nsEventStatus status; + WidgetQueryContentEvent editorRectEvent(true, NS_QUERY_EDITOR_RECT, this); + InitEvent(editorRectEvent); + DispatchEvent(&editorRectEvent, status); + if (editorRectEvent.mSucceeded) { + mTabChild->SendNotifyIMEEditorRect(editorRectEvent.mReply.mRect); + } + + return NS_OK; +} + + nsIMEUpdatePreference PuppetWidget::GetIMEUpdatePreference() { diff --git a/widget/PuppetWidget.h b/widget/PuppetWidget.h index 60489452254a..6eed9ceefc32 100644 --- a/widget/PuppetWidget.h +++ b/widget/PuppetWidget.h @@ -216,6 +216,7 @@ private: nsresult NotifyIMEOfUpdateComposition(); nsresult NotifyIMEOfTextChange(const IMENotification& aIMENotification); nsresult NotifyIMEOfMouseButtonEvent(const IMENotification& aIMENotification); + nsresult NotifyIMEOfEditorRect(); class PaintTask : public nsRunnable { public: