Skip to content

Commit

Permalink
Handle in-process APZ events correctly on Windows. (bug 1111873 part …
Browse files Browse the repository at this point in the history
…2, r=kats)
  • Loading branch information
David Anderson committed Dec 18, 2014
1 parent b30f736 commit 2d7902f
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 9 deletions.
5 changes: 5 additions & 0 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,11 @@ TabParent::MaybeForwardEventToRenderFrame(WidgetInputEvent& aEvent,
if (aOutInputBlockId) {
*aOutInputBlockId = InputAPZContext::GetInputBlockId();
}

// Let the widget know that the event will be sent to the child process,
// which will (hopefully) send a confirmation notice back to APZ.
InputAPZContext::SetRoutedToChildProcess();

return nsEventStatus_eIgnore;
}

Expand Down
7 changes: 7 additions & 0 deletions gfx/layers/apz/src/APZCTreeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,13 @@ APZCTreeManager::SetTargetAPZC(uint64_t aInputBlockId,
mInputQueue->SetConfirmedTargetApzc(aInputBlockId, target);
}

void
APZCTreeManager::SetTargetAPZC(uint64_t aInputBlockId, const ScrollableLayerGuid& aTarget)
{
nsRefPtr<AsyncPanZoomController> target = GetTargetAPZC(aTarget);
mInputQueue->SetConfirmedTargetApzc(aInputBlockId, target);
}

void
APZCTreeManager::UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
const ZoomConstraints& aConstraints)
Expand Down
6 changes: 6 additions & 0 deletions gfx/layers/apz/src/APZCTreeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ class APZCTreeManager {
void SetTargetAPZC(uint64_t aInputBlockId,
const nsTArray<ScrollableLayerGuid>& aTargets);

/**
* Helper function for SetTargetAPZC when used with single-target events,
* such as mouse wheel events.
*/
void SetTargetAPZC(uint64_t aInputBlockId, const ScrollableLayerGuid& aTarget);

/**
* Updates any zoom constraints contained in the <meta name="viewport"> tag.
*/
Expand Down
16 changes: 16 additions & 0 deletions gfx/layers/apz/util/InputAPZContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace layers {

ScrollableLayerGuid InputAPZContext::sGuid;
uint64_t InputAPZContext::sBlockId = 0;
bool InputAPZContext::sRoutedToChildProcess = false;

/*static*/ ScrollableLayerGuid
InputAPZContext::GetTargetLayerGuid()
Expand All @@ -23,19 +24,34 @@ InputAPZContext::GetInputBlockId()
return sBlockId;
}

/*static*/ void
InputAPZContext::SetRoutedToChildProcess()
{
sRoutedToChildProcess = true;
}

InputAPZContext::InputAPZContext(const ScrollableLayerGuid& aGuid,
const uint64_t& aBlockId)
: mOldGuid(sGuid)
, mOldBlockId(sBlockId)
, mOldRoutedToChildProcess(sRoutedToChildProcess)
{
sGuid = aGuid;
sBlockId = aBlockId;
sRoutedToChildProcess = false;
}

InputAPZContext::~InputAPZContext()
{
sGuid = mOldGuid;
sBlockId = mOldBlockId;
sRoutedToChildProcess = mOldRoutedToChildProcess;
}

bool
InputAPZContext::WasRoutedToChildProcess()
{
return sRoutedToChildProcess;
}

}
Expand Down
5 changes: 5 additions & 0 deletions gfx/layers/apz/util/InputAPZContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ class MOZ_STACK_CLASS InputAPZContext
private:
static ScrollableLayerGuid sGuid;
static uint64_t sBlockId;
static bool sRoutedToChildProcess;

public:
static ScrollableLayerGuid GetTargetLayerGuid();
static uint64_t GetInputBlockId();
static void SetRoutedToChildProcess();

InputAPZContext(const ScrollableLayerGuid& aGuid,
const uint64_t& aBlockId);
~InputAPZContext();

bool WasRoutedToChildProcess();

private:
ScrollableLayerGuid mOldGuid;
uint64_t mOldBlockId;
bool mOldRoutedToChildProcess;
};

}
Expand Down
23 changes: 23 additions & 0 deletions widget/nsBaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "mozilla/VsyncDispatcher.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/layers/ChromeProcessController.h"
#include "mozilla/layers/InputAPZContext.h"
#include "mozilla/dom/TabParent.h"

#ifdef ACCESSIBILITY
#include "nsAccessibilityService.h"
Expand Down Expand Up @@ -940,6 +942,27 @@ void nsBaseWidget::ConfigureAPZCTreeManager()
}
}

nsEventStatus
nsBaseWidget::DispatchEventForAPZ(WidgetGUIEvent* aEvent,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId)
{
InputAPZContext context(aGuid, aInputBlockId);

nsEventStatus status;
DispatchEvent(aEvent, status);

if (mAPZC && !context.WasRoutedToChildProcess()) {
// APZ did not find a dispatch-to-content region in the child process,
// and EventStateManager did not route the event into the child process.
// It's safe to communicate to APZ that the event has been processed.
mAPZC->SetTargetAPZC(aInputBlockId, aGuid);
mAPZC->ContentReceivedInputBlock(aInputBlockId, aEvent->mFlags.mDefaultPrevented);
}

return status;
}

void
nsBaseWidget::GetPreferredCompositorBackends(nsTArray<LayersBackend>& aHints)
{
Expand Down
8 changes: 8 additions & 0 deletions widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CompositorChild;
class CompositorParent;
class APZCTreeManager;
class GeckoContentController;
struct ScrollableLayerGuid;
}

class VsyncDispatcher;
Expand Down Expand Up @@ -88,6 +89,7 @@ class nsBaseWidget : public nsIWidget
typedef mozilla::layers::CompositorParent CompositorParent;
typedef mozilla::layers::APZCTreeManager APZCTreeManager;
typedef mozilla::layers::GeckoContentController GeckoContentController;
typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
typedef mozilla::ScreenRotation ScreenRotation;

virtual ~nsBaseWidget();
Expand Down Expand Up @@ -311,6 +313,12 @@ class nsBaseWidget : public nsIWidget
virtual void ConfigureAPZCTreeManager();
virtual already_AddRefed<GeckoContentController> CreateRootContentController();

// Dispatch an event that has been routed through APZ directly from the
// widget.
nsEventStatus DispatchEventForAPZ(mozilla::WidgetGUIEvent* aEvent,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId);

const nsIntRegion RegionFromArray(const nsTArray<nsIntRect>& aRects);
void ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects);

Expand Down
18 changes: 9 additions & 9 deletions widget/windows/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3742,20 +3742,20 @@ bool nsWindow::DispatchKeyboardEvent(WidgetGUIEvent* event)

bool nsWindow::DispatchScrollEvent(WidgetGUIEvent* aEvent)
{
uint64_t inputBlockId = 0;
ScrollableLayerGuid guid;
nsEventStatus status;

if (mAPZC && aEvent->mClass == eWheelEventClass) {
nsEventStatus status = mAPZC->ReceiveInputEvent(*aEvent->AsWheelEvent(), &guid, &inputBlockId);
if (status == nsEventStatus_eConsumeNoDefault) {
uint64_t inputBlockId = 0;
ScrollableLayerGuid guid;

nsEventStatus result = mAPZC->ReceiveInputEvent(*aEvent->AsWheelEvent(), &guid, &inputBlockId);
if (result == nsEventStatus_eConsumeNoDefault) {
return true;
}
status = DispatchEventForAPZ(aEvent, guid, inputBlockId);
} else {
DispatchEvent(aEvent, status);
}

InputAPZContext context(guid, inputBlockId);

nsEventStatus status;
DispatchEvent(aEvent, status);
return ConvertStatus(status);
}

Expand Down

0 comments on commit 2d7902f

Please sign in to comment.