Bug 940952 - Replace apzc GeckoContentController pan notifications with more general purpose transform notifications. r=botond

This commit is contained in:
Jim Mathies 2013-11-26 14:14:39 -06:00
parent 71439d79ba
commit 06adfb766f
7 changed files with 70 additions and 41 deletions

View File

@ -28,8 +28,7 @@ var APZCObserver = {
}
let os = Services.obs;
os.addObserver(this, "apzc-handle-pan-begin", false);
os.addObserver(this, "apzc-handle-pan-end", false);
os.addObserver(this, "apzc-transform-begin", false);
// Fired by ContentAreaObserver
window.addEventListener("SizeChanged", this, true);
@ -45,8 +44,7 @@ var APZCObserver = {
}
let os = Services.obs;
os.removeObserver(this, "apzc-handle-pan-begin");
os.removeObserver(this, "apzc-handle-pan-end");
os.removeObserver(this, "apzc-transform-begin");
window.removeEventListener("SizeChanged", this, true);
@ -86,7 +84,7 @@ var APZCObserver = {
},
observe: function ao_observe(aSubject, aTopic, aData) {
if (aTopic == "apzc-handle-pan-begin") {
if (aTopic == "apzc-transform-begin") {
// When we're panning, hide the main scrollbars by setting imprecise
// input (which sets a property on the browser which hides the scrollbar
// via CSS). This reduces jittering from left to right. We may be able

View File

@ -358,13 +358,13 @@ var SelectionHelperUI = {
event.clientX, event.clientY);
break;
case "apzc-handle-pan-begin":
case "apzc-transform-begin":
if (this.isActive && this.layerMode == kContentLayer) {
this._hideMonocles();
}
break;
case "apzc-handle-pan-end":
case "apzc-transform-end":
// The selection range callback will check to see if the new
// position is off the screen, in which case it shuts down and
// clears the selection.
@ -549,8 +549,8 @@ var SelectionHelperUI = {
init: function () {
let os = Services.obs;
os.addObserver(this, "attach_edit_session_to_content", false);
os.addObserver(this, "apzc-handle-pan-begin", false);
os.addObserver(this, "apzc-handle-pan-end", false);
os.addObserver(this, "apzc-transform-begin", false);
os.addObserver(this, "apzc-transform-end", false);
},
_init: function _init(aMsgTarget) {

View File

@ -992,7 +992,7 @@ bool AsyncPanZoomController::DoFling(const TimeDuration& aDelta) {
if (!shouldContinueFlingX && !shouldContinueFlingY) {
SendAsyncScrollEvent();
RequestContentRepaint();
mState = NOTHING;
SetState(NOTHING);
return false;
}
@ -1016,8 +1016,7 @@ bool AsyncPanZoomController::DoFling(const TimeDuration& aDelta) {
}
void AsyncPanZoomController::CancelAnimation() {
ReentrantMonitorAutoEnter lock(mMonitor);
mState = NOTHING;
SetState(NOTHING);
}
void AsyncPanZoomController::SetCompositorParent(CompositorParent* aCompositorParent) {
@ -1268,7 +1267,7 @@ bool AsyncPanZoomController::SampleContentTransformForFrame(const TimeStamp& aSa
requestAnimationFrame = true;
if (aSampleTime - mAnimationStartTime >= ZOOM_TO_DURATION) {
mState = NOTHING;
SetState(NOTHING);
SendAsyncScrollEvent();
RequestContentRepaint();
}
@ -1376,7 +1375,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aLayerMetri
mY.CancelTouch();
mFrameMetrics = aLayerMetrics;
mState = NOTHING;
SetState(NOTHING);
} else {
// If we're not taking the aLayerMetrics wholesale we still need to pull
// in some things into our local mFrameMetrics because these things are
@ -1554,14 +1553,18 @@ void AsyncPanZoomController::SetState(PanZoomState aNewState) {
}
if (mGeckoContentController) {
if (IsPanningState(oldState) && !IsPanningState(aNewState)) {
mGeckoContentController->HandlePanEnd();
} else if (!IsPanningState(oldState) && IsPanningState(aNewState)) {
mGeckoContentController->HandlePanBegin();
if (!IsTransformingState(oldState) && IsTransformingState(aNewState)) {
mGeckoContentController->NotifyTransformBegin();
} else if (IsTransformingState(oldState) && !IsTransformingState(aNewState)) {
mGeckoContentController->NotifyTransformEnd();
}
}
}
bool AsyncPanZoomController::IsTransformingState(PanZoomState aState) {
return !(aState == NOTHING || aState == TOUCHING || aState == WAITING_LISTENERS);
}
bool AsyncPanZoomController::IsPanningState(PanZoomState aState) {
return (aState == PANNING || aState == PANNING_LOCKED_X || aState == PANNING_LOCKED_Y);
}

View File

@ -510,6 +510,19 @@ private:
prevented the default actions yet. we still need to abort animations. */
};
/**
* Helper to set the current state. Holds the monitor before actually setting
* it and fires content controller events based on state changes. Always set
* the state using this call, do not set it directly.
*/
void SetState(PanZoomState aState);
/**
* Internal helpers for checking general state of this apzc.
*/
bool IsTransformingState(PanZoomState aState);
bool IsPanningState(PanZoomState mState);
enum AxisLockMode {
FREE, /* No locking at all */
STANDARD, /* Default axis locking mode that remains locked until pan ends*/
@ -518,15 +531,6 @@ private:
static AxisLockMode GetAxisLockMode();
/**
* Helper to set the current state. Holds the monitor before actually setting
* it. If the monitor is already held by the current thread, it is safe to
* instead use: |mState = NEWSTATE;|
*/
void SetState(PanZoomState aState);
bool IsPanningState(PanZoomState mState);
uint64_t mLayersId;
nsRefPtr<CompositorParent> mCompositorParent;
TaskThrottler mPaintThrottler;

View File

@ -77,14 +77,12 @@ public:
}
/**
* Request any special actions be performed when panning starts
* General tranformation notices for consumers. These fire any time
* the apzc is modifying the view, including panning, zooming, and
* fling.
*/
virtual void HandlePanBegin() {}
/**
* Request any special actions be performed when panning ends
*/
virtual void HandlePanEnd() {}
virtual void NotifyTransformBegin() {}
virtual void NotifyTransformEnd() {}
GeckoContentController() {}
virtual ~GeckoContentController() {}

View File

@ -317,18 +317,44 @@ APZController::PostDelayedTask(Task* aTask, int aDelayMs)
MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
}
// async scroll notifications
// apzc notifications
class TransformedStartEvent : public nsRunnable
{
NS_IMETHOD Run() {
MetroUtils::FireObserver("apzc-transform-start", L"");
return NS_OK;
}
};
class TransformedEndEvent : public nsRunnable
{
NS_IMETHOD Run() {
MetroUtils::FireObserver("apzc-transform-end", L"");
return NS_OK;
}
};
void
APZController::HandlePanBegin()
APZController::NotifyTransformBegin()
{
MetroUtils::FireObserver("apzc-handle-pan-begin", L"");
if (NS_IsMainThread()) {
MetroUtils::FireObserver("apzc-transform-begin", L"");
return;
}
nsCOMPtr<nsIRunnable> runnable = new TransformedStartEvent();
NS_DispatchToMainThread(runnable);
}
void
APZController::HandlePanEnd()
APZController::NotifyTransformEnd()
{
MetroUtils::FireObserver("apzc-handle-pan-end", L"");
if (NS_IsMainThread()) {
MetroUtils::FireObserver("apzc-transform-end", L"");
return;
}
nsCOMPtr<nsIRunnable> runnable = new TransformedEndEvent();
NS_DispatchToMainThread(runnable);
}
} } }

View File

@ -37,8 +37,8 @@ public:
virtual void HandleLongTap(const mozilla::CSSIntPoint& aPoint, int32_t aModifiers);
virtual void SendAsyncScrollDOMEvent(bool aIsRoot, const mozilla::CSSRect &aContentRect, const mozilla::CSSSize &aScrollableSize);
virtual void PostDelayedTask(Task* aTask, int aDelayMs);
virtual void HandlePanBegin();
virtual void HandlePanEnd();
virtual void NotifyTransformBegin();
virtual void NotifyTransformEnd();
void SetWidgetListener(nsIWidgetListener* aWidgetListener);
void UpdateScrollOffset(const mozilla::layers::ScrollableLayerGuid& aScrollLayerId, CSSIntPoint& aScrollOffset);