Bug 1020801 - Notify the ScrollViewChange DOM event when APZ starts/stops to change the transform. r=ehsan

This commit is contained in:
peter chang 2014-09-23 06:37:00 -04:00
parent 0c7bf9375f
commit dc90ce6554
6 changed files with 77 additions and 22 deletions

View File

@ -3056,14 +3056,14 @@ nsDocShell::RemoveWeakScrollObserver(nsIScrollObserver* aObserver)
}
void
nsDocShell::NotifyAsyncPanZoomStarted()
nsDocShell::NotifyAsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos)
{
nsTObserverArray<nsWeakPtr>::ForwardIterator iter(mScrollObservers);
while (iter.HasMore()) {
nsWeakPtr ref = iter.GetNext();
nsCOMPtr<nsIScrollObserver> obs = do_QueryReferent(ref);
if (obs) {
obs->AsyncPanZoomStarted();
obs->AsyncPanZoomStarted(aScrollPos);
} else {
mScrollObservers.RemoveElement(ref);
}
@ -3071,14 +3071,14 @@ nsDocShell::NotifyAsyncPanZoomStarted()
}
void
nsDocShell::NotifyAsyncPanZoomStopped()
nsDocShell::NotifyAsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos)
{
nsTObserverArray<nsWeakPtr>::ForwardIterator iter(mScrollObservers);
while (iter.HasMore()) {
nsWeakPtr ref = iter.GetNext();
nsCOMPtr<nsIScrollObserver> obs = do_QueryReferent(ref);
if (obs) {
obs->AsyncPanZoomStopped();
obs->AsyncPanZoomStopped(aScrollPos);
} else {
mScrollObservers.RemoveElement(ref);
}

View File

@ -49,6 +49,7 @@
#include "nsCRT.h"
#include "prtime.h"
#include "nsRect.h"
#include "Units.h"
namespace mozilla {
namespace dom {
@ -250,10 +251,10 @@ public:
// Notify Scroll observers when an async panning/zooming transform
// has started being applied
void NotifyAsyncPanZoomStarted();
void NotifyAsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos);
// Notify Scroll observers when an async panning/zooming transform
// is no longer applied
void NotifyAsyncPanZoomStopped();
void NotifyAsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos);
// Add new profile timeline markers to this docShell. This will only add
// markers if the docShell is currently recording profile timeline markers.

View File

@ -7,10 +7,11 @@
#define nsIScrollObserver_h___
#include "nsISupports.h"
#include "Units.h"
#define NS_ISCROLLOBSERVER_IID \
{ 0x03465b77, 0x9ce2, 0x4d19, \
{ 0xb2, 0xf6, 0x82, 0xae, 0xee, 0x85, 0xc3, 0xbf } }
{ 0x00bc10e3, 0xaa59, 0x4aa3, \
{ 0x88, 0xe9, 0x43, 0x0a, 0x01, 0xa3, 0x88, 0x04 } }
class nsIScrollObserver : public nsISupports
{
@ -23,14 +24,16 @@ public:
virtual void ScrollPositionChanged() = 0;
/**
* Called when an async panning/zooming transform has started being applied.
* Called when an async panning/zooming transform has started being applied
* and passed the scroll offset
*/
virtual void AsyncPanZoomStarted(){};
virtual void AsyncPanZoomStarted(const mozilla::CSSIntPoint scrollPos){};
/**
* Called when an async panning/zooming transform is no longer applied.
* Called when an async panning/zooming transform is no longer applied
* and passed the scroll offset
*/
virtual void AsyncPanZoomStopped(){};
virtual void AsyncPanZoomStopped(const mozilla::CSSIntPoint scrollPos){};
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIScrollObserver, NS_ISCROLLOBSERVER_IID)

View File

@ -2000,9 +2000,9 @@ TabChild::RecvNotifyAPZStateChange(const ViewID& aViewId,
nsCOMPtr<nsIDocument> doc = GetDocument();
if (doc) {
nsCOMPtr<nsIDocShell> docshell(doc->GetDocShell());
if (docshell) {
if (docshell && sf) {
nsDocShell* nsdocshell = static_cast<nsDocShell*>(docshell.get());
nsdocshell->NotifyAsyncPanZoomStarted();
nsdocshell->NotifyAsyncPanZoomStarted(sf->GetScrollPositionCSSPixels());
}
}
break;
@ -2018,9 +2018,9 @@ TabChild::RecvNotifyAPZStateChange(const ViewID& aViewId,
nsCOMPtr<nsIDocument> doc = GetDocument();
if (doc) {
nsCOMPtr<nsIDocShell> docshell(doc->GetDocShell());
if (docshell) {
if (docshell && sf) {
nsDocShell* nsdocshell = static_cast<nsDocShell*>(docshell.get());
nsdocshell->NotifyAsyncPanZoomStopped();
nsdocshell->NotifyAsyncPanZoomStopped(sf->GetScrollPositionCSSPixels());
}
}
break;

View File

@ -24,6 +24,7 @@
#include "nsView.h"
#include "mozilla/dom/DOMRect.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScrollViewChangeEvent.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/TreeWalker.h"
#include "mozilla/Preferences.h"
@ -32,6 +33,7 @@
#include "nsFrameSelection.h"
using namespace mozilla;
using namespace mozilla::dom;
// We treat mouse/touch move as "REAL" move event once its move distance
// exceed this value, in CSS pixel.
@ -50,9 +52,10 @@ SelectionCarets::SelectionCarets(nsIPresShell *aPresShell)
: mActiveTouchId(-1)
, mCaretCenterToDownPointOffsetY(0)
, mDragMode(NONE)
, mVisible(false)
, mStartCaretVisible(false)
, mAPZenabled(false)
, mEndCaretVisible(false)
, mStartCaretVisible(false)
, mVisible(false)
{
MOZ_ASSERT(NS_IsMainThread());
@ -861,11 +864,52 @@ SelectionCarets::NotifySelectionChanged(nsIDOMDocument* aDoc,
return NS_OK;
}
static void
DispatchScrollViewChangeEvent(nsIPresShell *aPresShell, const dom::ScrollState aState, const mozilla::CSSIntPoint aScrollPos)
{
nsCOMPtr<nsIDocument> doc = aPresShell->GetDocument();
if (doc) {
bool ret;
ScrollViewChangeEventInit detail;
detail.mBubbles = true;
detail.mCancelable = false;
detail.mState = aState;
detail.mScrollX = aScrollPos.x;
detail.mScrollY = aScrollPos.y;
nsRefPtr<ScrollViewChangeEvent> event =
ScrollViewChangeEvent::Constructor(doc, NS_LITERAL_STRING("scrollviewchange"), detail);
event->SetTrusted(true);
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
doc->DispatchEvent(event, &ret);
}
}
void
SelectionCarets::AsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos)
{
// Receives the notifications from AsyncPanZoom, sets mAPZenabled as true here
// to bypass the notifications from ScrollPositionChanged callbacks
mAPZenabled = true;
SetVisibility(false);
DispatchScrollViewChangeEvent(mPresShell, dom::ScrollState::Started, aScrollPos);
}
void
SelectionCarets::AsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos)
{
UpdateSelectionCarets();
DispatchScrollViewChangeEvent(mPresShell, dom::ScrollState::Stopped, aScrollPos);
}
void
SelectionCarets::ScrollPositionChanged()
{
SetVisibility(false);
LaunchScrollEndDetector();
if (!mAPZenabled) {
SetVisibility(false);
//TODO: handling scrolling for selection bubble when APZ is off
LaunchScrollEndDetector();
}
}
void

View File

@ -64,6 +64,10 @@ public:
// nsIScrollObserver
virtual void ScrollPositionChanged() MOZ_OVERRIDE;
// AsyncPanZoom started/stopped callbacks from nsIScrollObserver
virtual void AsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos) MOZ_OVERRIDE;
virtual void AsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos) MOZ_OVERRIDE;
void Terminate()
{
mPresShell = nullptr;
@ -214,9 +218,12 @@ private:
nscoord mCaretCenterToDownPointOffsetY;
DragMode mDragMode;
bool mVisible;
bool mStartCaretVisible;
// True if AsyncPanZoom is enabled
bool mAPZenabled;
bool mEndCaretVisible;
bool mStartCaretVisible;
bool mVisible;
// Preference
static int32_t sSelectionCaretsInflateSize;