Bug 935821 - Part 2. Support remote NS_QUERY_TEXT_RECT. r=smaug,masayuki

This commit is contained in:
Makoto Kato 2013-11-22 11:58:20 +09:00
parent bc6d141e6a
commit 428653986a
3 changed files with 56 additions and 1 deletions

View File

@ -1221,7 +1221,9 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
break;
case NS_QUERY_TEXT_RECT:
{
// XXX remote event
if (RemoteQueryContentEvent(aEvent)) {
break;
}
nsContentEventHandler handler(mPresContext);
handler.OnQueryTextRect(aEvent->AsQueryContentEvent());
}

View File

@ -207,6 +207,7 @@ TabParent::TabParent(ContentParent* aManager, const TabContext& aContext, uint32
, mIMECompositionEnding(false)
, mIMECompositionStart(0)
, mIMESeqno(0)
, mIMECompositionRectOffset(0)
, mEventCaptureDepth(0)
, mRect(0, 0, 0, 0)
, mDimensions(0, 0)
@ -996,6 +997,10 @@ bool
TabParent::RecvNotifyIMESelectedCompositionRect(const uint32_t& aOffset,
const nsIntRect& aRect)
{
// add rect to cache for another query
mIMECompositionRectOffset = aOffset;
mIMECompositionRect = aRect;
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
return true;
@ -1051,6 +1056,35 @@ TabParent::RecvRequestFocus(const bool& aCanRaise)
return true;
}
nsIntPoint
TabParent::GetChildProcessOffset()
{
// The "toplevel widget" in child processes is always at position
// 0,0. Map the event coordinates to match that.
nsIntPoint offset(0, 0);
nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
if (!frameLoader) {
return offset;
}
nsIFrame* targetFrame = frameLoader->GetPrimaryFrameOfOwningContent();
if (!targetFrame) {
return offset;
}
// Find out how far we're offset from the nearest widget.
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
return offset;
}
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(widget,
nsIntPoint(0, 0),
targetFrame);
return LayoutDeviceIntPoint::ToUntyped(LayoutDeviceIntPoint::FromAppUnitsToNearest(
pt, targetFrame->PresContext()->AppUnitsPerDevPixel()));
}
/**
* Try to answer query event using cached text.
*
@ -1064,6 +1098,9 @@ TabParent::RecvRequestFocus(const bool& aCanRaise)
* have out-of-bounds offsets, so that widget can request content without
* knowing the exact length of text. It's up to widget to handle cases when
* the returned offset/length are different from the queried offset/length.
*
* For NS_QUERY_TEXT_RECT, fail if cached offset/length aren't equals to input.
* Cocoa widget always queries selected offset, so it works on it.
*/
bool
TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent)
@ -1114,6 +1151,18 @@ TabParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent)
aEvent.mSucceeded = true;
}
break;
case NS_QUERY_TEXT_RECT:
{
if (aEvent.mInput.mOffset != mIMECompositionRectOffset ||
aEvent.mInput.mLength != 1) {
break;
}
aEvent.mReply.mOffset = mIMECompositionRectOffset;
aEvent.mReply.mRect = mIMECompositionRect - GetChildProcessOffset();
aEvent.mSucceeded = true;
}
break;
}
return true;
}

View File

@ -315,6 +315,7 @@ protected:
bool ShouldDelayDialogs();
bool AllowContentIME();
nsIntPoint GetChildProcessOffset();
virtual PRenderFrameParent* AllocPRenderFrameParent() MOZ_OVERRIDE;
virtual bool DeallocPRenderFrameParent(PRenderFrameParent* aFrame) MOZ_OVERRIDE;
@ -332,6 +333,9 @@ protected:
uint32_t mIMECompositionStart;
uint32_t mIMESeqno;
uint32_t mIMECompositionRectOffset;
nsIntRect mIMECompositionRect;
// The number of event series we're currently capturing.
int32_t mEventCaptureDepth;