From 327fa03357e6aec2118859b4bf77d5f7e55cd535 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 0ed1cb5b65c..65563f80e40 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 c0922664374..1caff32ba7f 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 326210b366a..b187662a2a6 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1488,6 +1488,13 @@ TabParent::RecvNotifyIMEMouseButtonEvent( return true; } +bool +TabParent::RecvNotifyIMEEditorRect(const nsIntRect& aRect) +{ + mIMEEditorRect = aRect; + return true; +} + bool TabParent::RecvRequestFocus(const bool& aCanRaise) { @@ -1633,6 +1640,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) @@ -1717,6 +1726,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 ddcc2114421..1d9f0ca1e6a 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 1177bd25cac..7aa6a7b43f7 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 536a894656a..f79cb37fc21 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: