2014-08-09 01:42:20 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-04-25 05:26:51 +03:00
|
|
|
#include "AndroidContentController.h"
|
2015-11-14 01:14:45 +03:00
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2014-08-09 01:42:20 +04:00
|
|
|
#include "base/message_loop.h"
|
2015-11-14 01:14:45 +03:00
|
|
|
#include "mozilla/layers/APZCCallbackHelper.h"
|
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2014-08-09 01:42:20 +04:00
|
|
|
#include "nsWindow.h"
|
|
|
|
|
2014-08-09 02:15:37 +04:00
|
|
|
using mozilla::layers::APZCTreeManager;
|
2014-08-09 01:42:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
namespace android {
|
|
|
|
|
2015-04-25 05:26:51 +03:00
|
|
|
NativePanZoomController::GlobalRef AndroidContentController::sNativePanZoomController = nullptr;
|
2014-08-09 01:42:20 +04:00
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
NativePanZoomController::LocalRef
|
2015-04-25 05:26:51 +03:00
|
|
|
AndroidContentController::SetNativePanZoomController(NativePanZoomController::Param obj)
|
2014-08-09 01:42:20 +04:00
|
|
|
{
|
2015-03-27 22:18:19 +03:00
|
|
|
NativePanZoomController::LocalRef old = sNativePanZoomController;
|
|
|
|
sNativePanZoomController = obj;
|
2014-08-09 01:42:20 +04:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2014-08-09 02:15:37 +04:00
|
|
|
void
|
2015-04-25 05:26:51 +03:00
|
|
|
AndroidContentController::NotifyDefaultPrevented(uint64_t aInputBlockId,
|
|
|
|
bool aDefaultPrevented)
|
2014-08-09 02:15:37 +04:00
|
|
|
{
|
2014-08-09 02:15:38 +04:00
|
|
|
if (!AndroidBridge::IsJavaUiThread()) {
|
2014-08-09 02:15:37 +04:00
|
|
|
// The notification must reach the APZ on the Java UI thread (aka the
|
|
|
|
// APZ "controller" thread) but we get it from the Gecko thread, so we
|
|
|
|
// have to throw it onto the other thread.
|
2015-04-25 05:26:51 +03:00
|
|
|
AndroidBridge::Bridge()->PostTaskToUiThread(NewRunnableFunction(
|
2015-04-25 05:26:51 +03:00
|
|
|
&AndroidContentController::NotifyDefaultPrevented,
|
2014-10-24 21:29:34 +04:00
|
|
|
aInputBlockId, aDefaultPrevented), 0);
|
2014-08-09 02:15:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-09 02:15:38 +04:00
|
|
|
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
|
2014-08-09 02:15:37 +04:00
|
|
|
APZCTreeManager* controller = nsWindow::GetAPZCTreeManager();
|
|
|
|
if (controller) {
|
2014-12-09 13:35:12 +03:00
|
|
|
controller->ContentReceivedInputBlock(aInputBlockId, aDefaultPrevented);
|
2014-08-09 02:15:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 23:10:52 +03:00
|
|
|
void
|
|
|
|
AndroidContentController::HandleSingleTap(const CSSPoint& aPoint,
|
|
|
|
Modifiers aModifiers,
|
|
|
|
const ScrollableLayerGuid& aGuid)
|
|
|
|
{
|
|
|
|
// This function will get invoked first on the Java UI thread, and then
|
|
|
|
// again on the main thread (because of the code in ChromeProcessController::
|
|
|
|
// HandleSingleTap). We want to post the SingleTap message once; it can be
|
2015-11-14 01:14:45 +03:00
|
|
|
// done from either thread but we need access to the callback transform
|
|
|
|
// so we do it from the main thread.
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
CSSPoint point = mozilla::layers::APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);
|
|
|
|
|
|
|
|
nsIContent* content = nsLayoutUtils::FindContentFor(aGuid.mScrollId);
|
|
|
|
nsIPresShell* shell = content
|
|
|
|
? mozilla::layers::APZCCallbackHelper::GetRootContentDocumentPresShellForContent(content)
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
if (shell && 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);
|
|
|
|
nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", rounded.x, rounded.y);
|
2015-11-13 23:10:52 +03:00
|
|
|
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
|
|
|
|
NS_LITERAL_CSTRING("Gesture:SingleTap"), data));
|
|
|
|
}
|
|
|
|
|
|
|
|
ChromeProcessController::HandleSingleTap(aPoint, aModifiers, aGuid);
|
|
|
|
}
|
|
|
|
|
2014-08-09 01:42:20 +04:00
|
|
|
void
|
2015-04-25 05:26:51 +03:00
|
|
|
AndroidContentController::PostDelayedTask(Task* aTask, int aDelayMs)
|
2014-08-09 01:42:20 +04:00
|
|
|
{
|
|
|
|
AndroidBridge::Bridge()->PostTaskToUiThread(aTask, aDelayMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace android
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|