Bug 1290823 - Factor out the code for dispatching a single tap event to observers into its own function. r=rbarker

This is not just a refactoring. It ensures that the early return in the
factored-out code only skips the dispatch to observers, *not* the
additional processing by ChromeProcessController.

MozReview-Commit-ID: F7xCoORKRlG
This commit is contained in:
Botond Ballo
2016-08-08 16:12:40 -04:00
parent 2254426fc3
commit d20d4975f4
2 changed files with 42 additions and 32 deletions

View File

@@ -43,6 +43,44 @@ AndroidContentController::NotifyDefaultPrevented(IAPZCTreeManager* aManager,
aManager->ContentReceivedInputBlock(aInputBlockId, aDefaultPrevented);
}
void
AndroidContentController::DispatchSingleTapToObservers(const LayoutDevicePoint& aPoint,
const ScrollableLayerGuid& aGuid) const
{
nsIContent* content = nsLayoutUtils::FindContentFor(aGuid.mScrollId);
nsIPresShell* shell = content
? mozilla::layers::APZCCallbackHelper::GetRootContentDocumentPresShellForContent(content)
: nullptr;
if (!shell || !shell->GetPresContext()) {
return;
}
CSSPoint point = mozilla::layers::APZCCallbackHelper::ApplyCallbackTransform(
aPoint / shell->GetPresContext()->CSSToDevPixelScale(), aGuid);
if (shell->ScaleToResolution()) {
// We need to convert from the root document to the root content document,
// by unapplying the resolution that's on the content document.
const float resolution = shell->GetResolution();
point.x /= resolution;
point.y /= resolution;
}
CSSIntPoint rounded = RoundedToInt(point);
nsAppShell::PostEvent([rounded] {
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
if (!obsServ) {
return;
}
nsPrintfCString data("{\"x\":%d,\"y\":%d}", rounded.x, rounded.y);
obsServ->NotifyObservers(nullptr, "Gesture:SingleTap",
NS_ConvertASCIItoUTF16(data).get());
});
}
void
AndroidContentController::HandleTap(TapType aType, const LayoutDevicePoint& aPoint,
Modifiers aModifiers,
@@ -55,38 +93,7 @@ AndroidContentController::HandleTap(TapType aType, const LayoutDevicePoint& aPoi
// done from either thread but we need access to the callback transform
// so we do it from the main thread.
if (NS_IsMainThread() && aType == TapType::eSingleTap) {
nsIContent* content = nsLayoutUtils::FindContentFor(aGuid.mScrollId);
nsIPresShell* shell = content
? mozilla::layers::APZCCallbackHelper::GetRootContentDocumentPresShellForContent(content)
: nullptr;
if (!shell || !shell->GetPresContext()) {
return;
}
CSSPoint point = mozilla::layers::APZCCallbackHelper::ApplyCallbackTransform(
aPoint / shell->GetPresContext()->CSSToDevPixelScale(), aGuid);
if (shell->ScaleToResolution()) {
// We need to convert from the root document to the root content document,
// by unapplying the resolution that's on the content document.
const float resolution = shell->GetResolution();
point.x /= resolution;
point.y /= resolution;
}
CSSIntPoint rounded = RoundedToInt(point);
nsAppShell::PostEvent([rounded] {
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
if (!obsServ) {
return;
}
nsPrintfCString data("{\"x\":%d,\"y\":%d}", rounded.x, rounded.y);
obsServ->NotifyObservers(nullptr, "Gesture:SingleTap",
NS_ConvertASCIItoUTF16(data).get());
});
DispatchSingleTapToObservers(aPoint, aGuid);
}
ChromeProcessController::HandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId);