Bug 1146020 - Make APZCCallbackHandler extend from ChromeProcessController. r=kats

This is one of the first steps to implement use APZC on Fennec.
This commit is contained in:
Danilo Cesar Lemes de Paula 2015-03-27 15:18:19 -04:00
parent 6297e4787d
commit 52d7018838
4 changed files with 26 additions and 136 deletions

View File

@ -25,13 +25,15 @@ namespace mozilla {
namespace widget {
namespace android {
StaticRefPtr<APZCCallbackHandler> APZCCallbackHandler::sInstance;
StaticRefPtr<APZCCallbackHandler> APZCCallbackHandler::sInstance;
NativePanZoomController::GlobalRef APZCCallbackHandler::sNativePanZoomController = nullptr;
NativePanZoomController::LocalRef
APZCCallbackHandler::SetNativePanZoomController(NativePanZoomController::Param obj)
{
NativePanZoomController::LocalRef old = mNativePanZoomController;
mNativePanZoomController = obj;
NativePanZoomController::LocalRef old = sNativePanZoomController;
sNativePanZoomController = obj;
return old;
}
@ -56,111 +58,6 @@ APZCCallbackHandler::NotifyDefaultPrevented(uint64_t aInputBlockId,
}
}
nsIDOMWindowUtils*
APZCCallbackHandler::GetDOMWindowUtils()
{
nsIAndroidBrowserApp* browserApp = nullptr;
if (!nsAppShell::gAppShell) {
return nullptr;
}
nsAppShell::gAppShell->GetBrowserApp(&browserApp);
if (!browserApp) {
return nullptr;
}
nsIBrowserTab* tab = nullptr;
if (browserApp->GetSelectedTab(&tab) != NS_OK) {
return nullptr;
}
nsIDOMWindow* window = nullptr;
if (tab->GetWindow(&window) != NS_OK) {
return nullptr;
}
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
return utils.get();
}
void
APZCCallbackHandler::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aFrameMetrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID);
if (aFrameMetrics.GetIsRoot()) {
nsIDOMWindowUtils* utils = GetDOMWindowUtils();
if (utils && APZCCallbackHelper::HasValidPresShellId(utils, aFrameMetrics)) {
FrameMetrics metrics = aFrameMetrics;
APZCCallbackHelper::UpdateRootFrame(utils, metrics);
}
} else {
// aFrameMetrics.mIsRoot is false, so we are trying to update a subframe.
// This requires special handling.
nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(aFrameMetrics.GetScrollId());
if (content) {
FrameMetrics newSubFrameMetrics(aFrameMetrics);
APZCCallbackHelper::UpdateSubFrame(content, newSubFrameMetrics);
}
}
}
void
APZCCallbackHandler::RequestFlingSnap(const FrameMetrics::ViewID& aScrollId,
const mozilla::CSSPoint& aDestination)
{
APZCCallbackHelper::RequestFlingSnap(aScrollId, aDestination);
}
void
APZCCallbackHandler::AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
const uint32_t& aScrollGeneration)
{
APZCCallbackHelper::AcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
}
void
APZCCallbackHandler::HandleDoubleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid)
{
CSSIntPoint point = RoundedToInt(aPoint);
nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
NS_LITERAL_CSTRING("Gesture:DoubleTap"), data));
}
void
APZCCallbackHandler::HandleSingleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid)
{
// FIXME Send the modifier data to Gecko for use in mouse events.
CSSIntPoint point = RoundedToInt(aPoint);
nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
NS_LITERAL_CSTRING("Gesture:SingleTap"), data));
}
void
APZCCallbackHandler::HandleLongTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId)
{
// TODO send content response back to APZC
CSSIntPoint point = RoundedToInt(aPoint);
nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
NS_LITERAL_CSTRING("Gesture:LongPress"), data));
}
void
APZCCallbackHandler::SendAsyncScrollDOMEvent(bool aIsRoot,
const CSSRect& aContentRect,
const CSSSize& aScrollableSize)
{
// no-op, we don't want to support this event on fennec, and we
// want to get rid of this entirely. See bug 898075.
}
void
APZCCallbackHandler::PostDelayedTask(Task* aTask, int aDelayMs)
{

View File

@ -6,7 +6,8 @@
#ifndef APZCCallbackHandler_h__
#define APZCCallbackHandler_h__
#include "mozilla/layers/GeckoContentController.h"
#include "mozilla/layers/ChromeProcessController.h"
#include "mozilla/layers/APZEventState.h"
#include "mozilla/EventForwards.h" // for Modifiers
#include "mozilla/StaticPtr.h"
#include "mozilla/TimeStamp.h"
@ -18,45 +19,35 @@ namespace mozilla {
namespace widget {
namespace android {
class APZCCallbackHandler final : public mozilla::layers::GeckoContentController
class APZCCallbackHandler final : public mozilla::layers::ChromeProcessController
{
private:
static StaticRefPtr<APZCCallbackHandler> sInstance;
NativePanZoomController::GlobalRef mNativePanZoomController;
static NativePanZoomController::GlobalRef sNativePanZoomController;
private:
APZCCallbackHandler()
: mNativePanZoomController(nullptr)
APZCCallbackHandler(nsIWidget* aWidget, mozilla::layers::APZEventState* aAPZEventState)
: mozilla::layers::ChromeProcessController(aWidget, aAPZEventState)
{}
nsIDOMWindowUtils* GetDOMWindowUtils();
public:
static void Initialize(nsIWidget* aWidget, mozilla::layers::APZEventState* aAPZEventState) {
MOZ_ASSERT(!sInstance.get(), "APZCCallbackHandler.Initialize() got called twice");
sInstance = new APZCCallbackHandler(aWidget, aAPZEventState);
}
static APZCCallbackHandler* GetInstance() {
if (sInstance.get() == nullptr) {
sInstance = new APZCCallbackHandler();
}
MOZ_ASSERT(sInstance.get(), "Calling APZCCallbackHandler.GetInstance() before it's initialization");
return sInstance.get();
}
NativePanZoomController::LocalRef SetNativePanZoomController(NativePanZoomController::Param obj);
static NativePanZoomController::LocalRef SetNativePanZoomController(NativePanZoomController::Param obj);
void NotifyDefaultPrevented(uint64_t aInputBlockId, bool aDefaultPrevented);
public: // GeckoContentController methods
void RequestContentRepaint(const mozilla::layers::FrameMetrics& aFrameMetrics) override;
void RequestFlingSnap(const mozilla::layers::FrameMetrics::ViewID& aScrollId,
const mozilla::CSSPoint& aDestination) override;
void AcknowledgeScrollUpdate(const mozilla::layers::FrameMetrics::ViewID& aScrollId,
const uint32_t& aScrollGeneration) override;
void HandleDoubleTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid) override;
void HandleSingleTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid) override;
void HandleLongTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
const mozilla::layers::ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId) override;
void SendAsyncScrollDOMEvent(bool aIsRoot, const mozilla::CSSRect& aContentRect,
const mozilla::CSSSize& aScrollableSize) override;
public: // ChromeProcessController methods
void PostDelayedTask(Task* aTask, int aDelayMs) override;
};

View File

@ -903,7 +903,7 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject ins
const auto& newRef = NativePanZoomController::Ref::From(instance);
NativePanZoomController::LocalRef oldRef =
APZCCallbackHandler::GetInstance()->SetNativePanZoomController(newRef);
APZCCallbackHandler::SetNativePanZoomController(newRef);
MOZ_ASSERT(!oldRef, "Registering a new NPZC when we already have one");
}
@ -947,7 +947,7 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject
}
NativePanZoomController::LocalRef oldRef =
APZCCallbackHandler::GetInstance()->SetNativePanZoomController(nullptr);
APZCCallbackHandler::SetNativePanZoomController(nullptr);
MOZ_ASSERT(oldRef, "Clearing a non-existent NPZC");
}

View File

@ -2486,6 +2486,8 @@ nsWindow::ConfigureAPZCTreeManager()
already_AddRefed<GeckoContentController>
nsWindow::CreateRootContentController()
{
widget::android::APZCCallbackHandler::Initialize(this, mAPZEventState);
nsRefPtr<widget::android::APZCCallbackHandler> controller =
widget::android::APZCCallbackHandler::GetInstance();
return controller.forget();