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

--HG--
extra : rebase_source : f9ef57d25a54442dd083560029437fcad885149c
This commit is contained in:
Botond Ballo 2016-08-08 16:12:40 -04:00
Родитель afa6c4d5f3
Коммит 7230352e0f
2 изменённых файлов: 42 добавлений и 32 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -48,6 +48,9 @@ public:
uint64_t aInputBlockId, bool aDefaultPrevented);
private:
nsWindow* mAndroidWindow;
void DispatchSingleTapToObservers(const LayoutDevicePoint& aPoint,
const ScrollableLayerGuid& aGuid) const;
};
} // namespace widget