Skip to content

Commit

Permalink
Cleanup more TabChild stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Mar 19, 2014
1 parent 1edd231 commit ba1d720
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 124 deletions.
10 changes: 8 additions & 2 deletions dom/ipc/TabChild.cpp
Expand Up @@ -1486,6 +1486,12 @@ TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,

bool
TabChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
{
return TabChildBase::UpdateFrameHandler(aFrameMetrics);
}

bool
TabChildBase::UpdateFrameHandler(const FrameMetrics& aFrameMetrics)
{
MOZ_ASSERT(aFrameMetrics.mScrollId != FrameMetrics::NULL_SCROLL_ID);

Expand Down Expand Up @@ -1723,7 +1729,7 @@ TabChild::RecvMouseWheelEvent(const WidgetWheelEvent& event)
return true;
}

void
nsEventStatus
TabChildBase::DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
const LayoutDevicePoint& aRefPoint,
nsIWidget* aWidget)
Expand All @@ -1742,7 +1748,7 @@ TabChildBase::DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
}
event.widget = aWidget;

DispatchWidgetEvent(event);
return DispatchWidgetEvent(event);
}

static Touch*
Expand Down
10 changes: 6 additions & 4 deletions dom/ipc/TabChild.h
Expand Up @@ -164,6 +164,10 @@ class TabChildBase : public nsFrameScriptExecutor,
const bool& aIsRoot,
const mozilla::layers::ZoomConstraints& aConstraints) = 0;

nsEventStatus DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
const LayoutDevicePoint& aRefPoint,
nsIWidget* aWidget);

protected:
CSSSize GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewport);

Expand All @@ -184,17 +188,15 @@ class TabChildBase : public nsFrameScriptExecutor,
void DispatchMessageManagerMessage(const nsAString& aMessageName,
const nsAString& aJSONData);

void DispatchSynthesizedMouseEvent(uint32_t aMsg, uint64_t aTime,
const LayoutDevicePoint& aRefPoint,
nsIWidget* aWidget);

nsEventStatus DispatchWidgetEvent(WidgetGUIEvent& event);

bool HasValidInnerSize();
void InitializeRootMetrics();

mozilla::layers::FrameMetrics ProcessUpdateFrame(const mozilla::layers::FrameMetrics& aFrameMetrics);

bool UpdateFrameHandler(const mozilla::layers::FrameMetrics& aFrameMetrics);

protected:
float mOldViewportWidth;
bool mContentDocumentIsDisplayed;
Expand Down
26 changes: 20 additions & 6 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadChild.cpp
Expand Up @@ -642,6 +642,20 @@ EmbedLiteViewThreadChild::RecvAcknowledgeScrollUpdate(const FrameMetrics::ViewID
return true;
}

void
EmbedLiteViewThreadChild::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
{
if (aPoint) {
event.refPoint.x = aPoint->x;
event.refPoint.y = aPoint->y;
} else {
event.refPoint.x = 0;
event.refPoint.y = 0;
}

event.time = PR_Now() / 1000;
}

bool
EmbedLiteViewThreadChild::RecvHandleSingleTap(const nsIntPoint& aPoint)
{
Expand All @@ -651,7 +665,7 @@ EmbedLiteViewThreadChild::RecvHandleSingleTap(const nsIntPoint& aPoint)
nsPoint offset;
nsCOMPtr<nsIWidget> widget = mHelper->GetWidget(&offset);
WidgetCompositionEvent event(true, NS_COMPOSITION_END, widget);
mHelper->InitEvent(event, nullptr);
InitEvent(event, nullptr);
mHelper->DispatchWidgetEvent(event);
mIMEComposing = false;
}
Expand Down Expand Up @@ -724,27 +738,27 @@ EmbedLiteViewThreadChild::RecvHandleTextEvent(const nsString& commit, const nsSt

if (StartComposite) {
WidgetCompositionEvent event(true, NS_COMPOSITION_START, widget);
mHelper->InitEvent(event, nullptr);
InitEvent(event, nullptr);
mHelper->DispatchWidgetEvent(event);
}

if (StartComposite || UpdateComposite) {
WidgetCompositionEvent event(true, NS_COMPOSITION_UPDATE, widget);
mHelper->InitEvent(event, nullptr);
InitEvent(event, nullptr);
event.data = pushStr;
mHelper->DispatchWidgetEvent(event);
}

if (StartComposite || UpdateComposite || EndComposite) {
WidgetTextEvent event(true, NS_TEXT_TEXT, widget);
mHelper->InitEvent(event, nullptr);
InitEvent(event, nullptr);
event.theText = pushStr;
mHelper->DispatchWidgetEvent(event);
}

if (EndComposite) {
WidgetCompositionEvent event(true, NS_COMPOSITION_END, widget);
mHelper->InitEvent(event, nullptr);
InitEvent(event, nullptr);
mHelper->DispatchWidgetEvent(event);
}

Expand Down Expand Up @@ -840,7 +854,7 @@ EmbedLiteViewThreadChild::RecvInputDataTouchEvent(const ScrollableLayerGuid& aGu
}
if (status != nsEventStatus_eConsumeNoDefault && mDispatchSynthMouseEvents && sDispatchMouseEvents) {
// Touch event not handled
status = mHelper->DispatchSynthesizedMouseEvent(localEvent);
status = mHelper->DispatchSynthesizedMouseEvent(localEvent.message, localEvent.time, localEvent.refPoint, localEvent.widget);
if (status != nsEventStatus_eConsumeNoDefault && status != nsEventStatus_eConsumeDoDefault) {
mDispatchSynthMouseEvents = false;
}
Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/embedthread/EmbedLiteViewThreadChild.h
Expand Up @@ -122,6 +122,7 @@ class EmbedLiteViewThreadChild : public PEmbedLiteViewChild,

void InitGeckoWindow(const uint32_t& parentId);
EmbedLiteAppThreadChild* AppChild();
void InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint = nullptr);

uint32_t mId;
uint64_t mOuterId;
Expand Down
110 changes: 1 addition & 109 deletions embedding/embedlite/utils/TabChildHelper.cpp
Expand Up @@ -273,33 +273,7 @@ TabChildHelper::HandleEvent(nsIDOMEvent* aEvent)
bool
TabChildHelper::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
{
MOZ_ASSERT(aFrameMetrics.mScrollId != FrameMetrics::NULL_SCROLL_ID);

if (aFrameMetrics.mIsRoot) {
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());
if (APZCCallbackHelper::HasValidPresShellId(utils, aFrameMetrics)) {
mLastRootMetrics = ProcessUpdateFrame(aFrameMetrics);
APZCCallbackHelper::UpdateCallbackTransform(aFrameMetrics, mLastRootMetrics);
return true;
}
} else {
// aFrameMetrics.mIsRoot is false, so we are trying to update a subframe.
// This requires special handling.
nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(
aFrameMetrics.mScrollId);
if (content) {
FrameMetrics newSubFrameMetrics(aFrameMetrics);
APZCCallbackHelper::UpdateSubFrame(content, newSubFrameMetrics);
APZCCallbackHelper::UpdateCallbackTransform(aFrameMetrics, newSubFrameMetrics);
return true;
}
}

// We've recieved a message that is out of date and we want to ignore.
// However we can't reply without painting so we reply by painting the
// exact same thing as we did before.
mLastRootMetrics = ProcessUpdateFrame(mLastRootMetrics);
return true;
return TabChildBase::UpdateFrameHandler(aFrameMetrics);
}

nsIWebNavigation*
Expand Down Expand Up @@ -412,16 +386,6 @@ TabChildHelper::CheckPermission(const nsAString& aPermission)
return false;
}

static nsIntPoint
ToWidgetPoint(float aX, float aY, const nsPoint& aOffset,
nsPresContext* aPresContext)
{
double appPerDev = aPresContext->AppUnitsPerDevPixel();
nscoord appPerCSS = nsPresContext::AppUnitsPerCSSPixel();
return nsIntPoint(NSToIntRound((aX * appPerCSS + aOffset.x) / appPerDev),
NSToIntRound((aY * appPerCSS + aOffset.y) / appPerDev));
}

bool
TabChildHelper::ConvertMutiTouchInputToEvent(const mozilla::MultiTouchInput& aData,
WidgetTouchEvent& aEvent)
Expand Down Expand Up @@ -516,78 +480,6 @@ TabChildHelper::GetPresContext()
return presContext;
}

void
TabChildHelper::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
{
if (aPoint) {
event.refPoint.x = aPoint->x;
event.refPoint.y = aPoint->y;
} else {
event.refPoint.x = 0;
event.refPoint.y = 0;
}

event.time = PR_Now() / 1000;
}

nsEventStatus
TabChildHelper::DispatchSynthesizedMouseEvent(const WidgetTouchEvent& aEvent)
{
// Synthesize a phony mouse event.
uint32_t msg;
switch (aEvent.message) {
case NS_TOUCH_START:
msg = NS_MOUSE_BUTTON_DOWN;
break;
case NS_TOUCH_MOVE:
msg = NS_MOUSE_MOVE;
break;
case NS_TOUCH_END:
case NS_TOUCH_CANCEL:
msg = NS_MOUSE_BUTTON_UP;
break;
default:
NS_ERROR("Unknown touch event message");
return nsEventStatus_eIgnore;
}

// get the widget to send the event to
nsPoint offset;
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
if (!widget) {
return nsEventStatus_eIgnore;
}

WidgetMouseEvent event(true, msg, widget, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);

event.widget = widget;
if (msg != NS_MOUSE_MOVE) {
event.clickCount = 1;
}
event.time = PR_IntervalNow();

nsPresContext* presContext = GetPresContext();
if (!presContext) {
return nsEventStatus_eIgnore;
}

nsIntPoint refPoint;
if (aEvent.touches.Length()) {
refPoint = aEvent.touches[0]->mRefPoint;
}

nsIntPoint pt = ToWidgetPoint(refPoint.x, refPoint.y, offset, presContext);
event.refPoint.x = pt.x;
event.refPoint.y = pt.y;
event.ignoreRootScrollFrame = true;

nsEventStatus status;
if NS_SUCCEEDED(widget->DispatchEvent(&event, status)) {
return status;
}
return nsEventStatus_eIgnore;
}

bool
TabChildHelper::DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
Expand Down
3 changes: 0 additions & 3 deletions embedding/embedlite/utils/TabChildHelper.h
Expand Up @@ -65,12 +65,9 @@ class TabChildHelper : public nsIDOMEventListener,
protected:
nsIWidget* GetWidget(nsPoint* aOffset);
nsPresContext* GetPresContext();
void InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint = nullptr);
// Sends a simulated mouse event from a touch event for compatibility.
bool ConvertMutiTouchInputToEvent(const mozilla::MultiTouchInput& aData,
WidgetTouchEvent& aEvent);
nsEventStatus DispatchSynthesizedMouseEvent(const WidgetTouchEvent& aEvent);

void CancelTapTracking();

private:
Expand Down

0 comments on commit ba1d720

Please sign in to comment.