Bug 1122090 - Send the allowed behaviour notification to APZ for touch blocks when touch-action is enabled. r=botond

This commit is contained in:
Kartikaya Gupta 2015-03-19 06:33:33 -04:00
parent 2ffdb16a4e
commit f709915b5c
11 changed files with 117 additions and 0 deletions

View File

@ -56,6 +56,7 @@ using mozilla::CommandInt from "mozilla/EventForwards.h";
using mozilla::Modifiers from "mozilla/EventForwards.h";
using mozilla::layers::GeckoContentController::APZStateChange from "mozilla/layers/GeckoContentController.h";
using mozilla::WritingMode from "WritingModes.h";
using mozilla::layers::TouchBehaviorFlags from "mozilla/layers/APZUtils.h";
namespace mozilla {
namespace dom {
@ -439,6 +440,13 @@ parent:
*/
SetTargetAPZC(uint64_t aInputBlockId, ScrollableLayerGuid[] aTargets);
/**
* Notifies the APZ code of the allowed touch-behaviours for a particular
* input block. Each item in the aFlags array corresponds to one touch point
* in the touch event.
*/
SetAllowedTouchBehavior(uint64_t aInputBlockId, TouchBehaviorFlags[] aFlags);
/**
* Updates the zoom constraints for a scrollable frame in this tab.
* The zoom controller code lives on the parent side and so this allows it to

View File

@ -813,6 +813,22 @@ private:
nsWeakPtr mTabChild;
};
class TabChildSetAllowedTouchBehaviorCallback : public SetAllowedTouchBehaviorCallback {
public:
explicit TabChildSetAllowedTouchBehaviorCallback(TabChild* aTabChild)
: mTabChild(do_GetWeakReference(static_cast<nsITabChild*>(aTabChild)))
{}
void Run(uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aFlags) const MOZ_OVERRIDE {
if (nsCOMPtr<nsITabChild> tabChild = do_QueryReferent(mTabChild)) {
static_cast<TabChild*>(tabChild.get())->SendSetAllowedTouchBehavior(aInputBlockId, aFlags);
}
}
private:
nsWeakPtr mTabChild;
};
class TabChildContentReceivedInputBlockCallback : public ContentReceivedInputBlockCallback {
public:
explicit TabChildContentReceivedInputBlockCallback(TabChild* aTabChild)
@ -848,6 +864,7 @@ TabChild::TabChild(nsIContentChild* aManager,
, mUpdateHitRegion(false)
, mIgnoreKeyPressEvent(false)
, mSetTargetAPZCCallback(new TabChildSetTargetAPZCCallback(this))
, mSetAllowedTouchBehaviorCallback(new TabChildSetAllowedTouchBehaviorCallback(this))
, mHasValidInnerSize(false)
, mDestroyed(false)
, mUniqueId(aTabId)
@ -2360,6 +2377,10 @@ TabChild::RecvRealTouchEvent(const WidgetTouchEvent& aEvent,
mWidget->GetDefaultScale(), GetPresShellResolution());
if (localEvent.message == NS_TOUCH_START && gfxPrefs::AsyncPanZoomEnabled()) {
if (gfxPrefs::TouchActionEnabled()) {
APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(WebWidget(),
localEvent, aInputBlockId, mSetAllowedTouchBehaviorCallback);
}
nsCOMPtr<nsIDocument> document = GetDocument();
APZCCallbackHelper::SendSetTargetAPZCNotification(WebWidget(), document,
localEvent, aGuid, aInputBlockId, mSetTargetAPZCCallback);

View File

@ -47,6 +47,7 @@ class RenderFrameChild;
namespace layers {
class APZEventState;
struct SetTargetAPZCCallback;
struct SetAllowedTouchBehaviorCallback;
}
namespace widget {
@ -243,6 +244,7 @@ class TabChild MOZ_FINAL : public TabChildBase,
typedef mozilla::layout::RenderFrameChild RenderFrameChild;
typedef mozilla::layers::APZEventState APZEventState;
typedef mozilla::layers::SetTargetAPZCCallback SetTargetAPZCCallback;
typedef mozilla::layers::SetAllowedTouchBehaviorCallback SetAllowedTouchBehaviorCallback;
public:
/**
@ -619,6 +621,7 @@ private:
bool mIgnoreKeyPressEvent;
nsRefPtr<APZEventState> mAPZEventState;
nsRefPtr<SetTargetAPZCCallback> mSetTargetAPZCCallback;
nsRefPtr<SetAllowedTouchBehaviorCallback> mSetAllowedTouchBehaviorCallback;
bool mHasValidInnerSize;
bool mDestroyed;
// Position of tab, relative to parent widget (typically the window)

View File

@ -2476,6 +2476,16 @@ TabParent::RecvSetTargetAPZC(const uint64_t& aInputBlockId,
return true;
}
bool
TabParent::RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
nsTArray<TouchBehaviorFlags>&& aFlags)
{
if (RenderFrameParent* rfp = GetRenderFrame()) {
rfp->SetAllowedTouchBehavior(aInputBlockId, aFlags);
}
return true;
}
already_AddRefed<nsILoadContext>
TabParent::GetLoadContext()
{

View File

@ -207,6 +207,8 @@ public:
const bool& aPreventDefault) MOZ_OVERRIDE;
virtual bool RecvSetTargetAPZC(const uint64_t& aInputBlockId,
nsTArray<ScrollableLayerGuid>&& aTargets) MOZ_OVERRIDE;
virtual bool RecvSetAllowedTouchBehavior(const uint64_t& aInputBlockId,
nsTArray<TouchBehaviorFlags>&& aTargets) MOZ_OVERRIDE;
virtual bool RecvSynthesizedMouseWheelEvent(const mozilla::WidgetWheelEvent& aEvent) MOZ_OVERRIDE;
virtual PColorPickerParent*

View File

@ -5,6 +5,7 @@
#include "APZCCallbackHelper.h"
#include "ContentHelper.h"
#include "gfxPlatform.h" // For gfxPlatform::UseTiling
#include "mozilla/dom/TabParent.h"
#include "nsIScrollableFrame.h"
@ -651,6 +652,20 @@ APZCCallbackHelper::SendSetTargetAPZCNotification(nsIWidget* aWidget,
}
}
void
APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(
nsIWidget* aWidget,
const WidgetTouchEvent& aEvent,
uint64_t aInputBlockId,
const nsRefPtr<SetAllowedTouchBehaviorCallback>& aCallback)
{
nsTArray<TouchBehaviorFlags> flags;
for (uint32_t i = 0; i < aEvent.touches.Length(); i++) {
flags.AppendElement(widget::ContentHelper::GetAllowedTouchBehavior(aWidget, aEvent.touches[i]->mRefPoint));
}
aCallback->Run(aInputBlockId, flags);
}
}
}

View File

@ -8,6 +8,7 @@
#include "FrameMetrics.h"
#include "mozilla/EventForwards.h"
#include "mozilla/layers/APZUtils.h"
#include "nsIDOMWindowUtils.h"
class nsIContent;
@ -29,6 +30,16 @@ protected:
virtual ~SetTargetAPZCCallback() {}
};
/* A base class for callbacks to be passed to
* APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification. */
struct SetAllowedTouchBehaviorCallback {
public:
NS_INLINE_DECL_REFCOUNTING(SetAllowedTouchBehaviorCallback)
virtual void Run(uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aFlags) const = 0;
protected:
virtual ~SetAllowedTouchBehaviorCallback() {}
};
/* This class contains some helper methods that facilitate implementing the
GeckoContentController callback interface required by the AsyncPanZoomController.
Since different platforms need to implement this interface in similar-but-
@ -163,6 +174,13 @@ public:
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId,
const nsRefPtr<SetTargetAPZCCallback>& aCallback);
/* Figure out the allowed touch behaviors of each touch point in |aEvent|
* and send that information to the provided callback. */
static void SendSetAllowedTouchBehaviorNotification(nsIWidget* aWidget,
const WidgetTouchEvent& aEvent,
uint64_t aInputBlockId,
const nsRefPtr<SetAllowedTouchBehaviorCallback>& aCallback);
};
}

View File

@ -578,6 +578,17 @@ RenderFrameParent::SetTargetAPZC(uint64_t aInputBlockId,
}
}
void
RenderFrameParent::SetAllowedTouchBehavior(uint64_t aInputBlockId,
const nsTArray<TouchBehaviorFlags>& aFlags)
{
if (GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, aFlags));
}
}
void
RenderFrameParent::UpdateZoomConstraints(uint32_t aPresShellId,
ViewID aViewId,

View File

@ -11,6 +11,7 @@
#include "mozilla/Attributes.h"
#include <map>
#include "mozilla/layers/APZUtils.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layout/PRenderFrameParent.h"
#include "nsDisplayList.h"
@ -45,6 +46,7 @@ class RenderFrameParent : public PRenderFrameParent
typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
typedef mozilla::layers::TextureFactoryIdentifier TextureFactoryIdentifier;
typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
typedef mozilla::layers::TouchBehaviorFlags TouchBehaviorFlags;
typedef mozilla::layers::ZoomConstraints ZoomConstraints;
typedef FrameMetrics::ViewID ViewID;
@ -86,6 +88,8 @@ public:
bool aPreventDefault);
void SetTargetAPZC(uint64_t aInputBlockId,
const nsTArray<ScrollableLayerGuid>& aTargets);
void SetAllowedTouchBehavior(uint64_t aInputBlockId,
const nsTArray<TouchBehaviorFlags>& aFlags);
void UpdateZoomConstraints(uint32_t aPresShellId,
ViewID aViewId,

View File

@ -937,6 +937,23 @@ private:
nsRefPtr<APZCTreeManager> mTreeManager;
};
class ChromeProcessSetAllowedTouchBehaviorCallback : public SetAllowedTouchBehaviorCallback {
public:
explicit ChromeProcessSetAllowedTouchBehaviorCallback(APZCTreeManager* aTreeManager)
: mTreeManager(aTreeManager)
{}
void Run(uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aFlags) const MOZ_OVERRIDE {
MOZ_ASSERT(NS_IsMainThread());
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
mTreeManager.get(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, aFlags));
}
private:
nsRefPtr<APZCTreeManager> mTreeManager;
};
class ChromeProcessContentReceivedInputBlockCallback : public ContentReceivedInputBlockCallback {
public:
explicit ChromeProcessContentReceivedInputBlockCallback(APZCTreeManager* aTreeManager)
@ -965,6 +982,7 @@ void nsBaseWidget::ConfigureAPZCTreeManager()
mAPZEventState = new APZEventState(this,
new ChromeProcessContentReceivedInputBlockCallback(mAPZC));
mSetTargetAPZCCallback = new ChromeProcessSetTargetAPZCCallback(mAPZC);
mSetAllowedTouchBehaviorCallback = new ChromeProcessSetAllowedTouchBehaviorCallback(mAPZC);
nsRefPtr<GeckoContentController> controller = CreateRootContentController();
if (controller) {
@ -1001,6 +1019,10 @@ nsBaseWidget::ProcessUntransformedAPZEvent(WidgetInputEvent* aEvent,
// call into APZEventState::Process*Event() as well.
if (WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent()) {
if (touchEvent->message == NS_TOUCH_START) {
if (gfxPrefs::TouchActionEnabled()) {
APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(this, *touchEvent,
aInputBlockId, mSetAllowedTouchBehaviorCallback);
}
APZCCallbackHelper::SendSetTargetAPZCNotification(this, GetDocument(), *aEvent,
aGuid, aInputBlockId, mSetTargetAPZCCallback);
}

View File

@ -40,6 +40,7 @@ class GeckoContentController;
class APZEventState;
struct ScrollableLayerGuid;
struct SetTargetAPZCCallback;
struct SetAllowedTouchBehaviorCallback;
}
class CompositorVsyncDispatcher;
@ -95,6 +96,7 @@ protected:
typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
typedef mozilla::layers::APZEventState APZEventState;
typedef mozilla::layers::SetTargetAPZCCallback SetTargetAPZCCallback;
typedef mozilla::layers::SetAllowedTouchBehaviorCallback SetAllowedTouchBehaviorCallback;
typedef mozilla::ScreenRotation ScreenRotation;
virtual ~nsBaseWidget();
@ -456,6 +458,7 @@ protected:
nsRefPtr<APZCTreeManager> mAPZC;
nsRefPtr<APZEventState> mAPZEventState;
nsRefPtr<SetTargetAPZCCallback> mSetTargetAPZCCallback;
nsRefPtr<SetAllowedTouchBehaviorCallback> mSetAllowedTouchBehaviorCallback;
nsRefPtr<WidgetShutdownObserver> mShutdownObserver;
nsRefPtr<TextEventDispatcher> mTextEventDispatcher;
nsCursor mCursor;