Bug 988143 - Enable Gecko Touch in Fennec, TouchCaret Scroll mods, r=ehsan

This commit is contained in:
Mark Capella 2015-05-14 22:06:13 -04:00
Родитель e4e9a24311
Коммит 98116624f3
4 изменённых файлов: 144 добавлений и 10 удалений

Просмотреть файл

@ -57,8 +57,6 @@ static const char* kSelectionCaretsLogModuleName = "SelectionCarets";
// We treat mouse/touch move as "REAL" move event once its move distance
// exceed this value, in CSS pixel.
static const int32_t kMoveStartTolerancePx = 5;
// Time for trigger scroll end event, in miliseconds.
static const int32_t kScrollEndTimerDelay = 300;
NS_IMPL_ISUPPORTS(SelectionCarets,
nsIReflowObserver,
@ -1286,10 +1284,11 @@ SelectionCarets::LaunchScrollEndDetector()
MOZ_ASSERT(mScrollEndDetectorTimer);
SELECTIONCARETS_LOG("Will fire scroll end after %d ms", kScrollEndTimerDelay);
SELECTIONCARETS_LOG("Will fire scroll end after %d ms",
TouchCaret::sScrollEndTimerDelay);
mScrollEndDetectorTimer->InitWithFuncCallback(FireScrollEnd,
this,
kScrollEndTimerDelay,
TouchCaret::sScrollEndTimerDelay,
nsITimer::TYPE_ONE_SHOT);
}

Просмотреть файл

@ -56,7 +56,10 @@ static const char* kTouchCaretLogModuleName = "TouchCaret";
// boundary by 61 app units (1 pixel + 1 app unit).
static const int32_t kBoundaryAppUnits = 61;
NS_IMPL_ISUPPORTS(TouchCaret, nsISelectionListener)
NS_IMPL_ISUPPORTS(TouchCaret,
nsISelectionListener,
nsIScrollObserver,
nsISupportsWeakReference)
/*static*/ int32_t TouchCaret::sTouchCaretInflateSize = 0;
/*static*/ int32_t TouchCaret::sTouchCaretExpirationTime = 0;
@ -69,6 +72,7 @@ TouchCaret::TouchCaret(nsIPresShell* aPresShell)
: mState(TOUCHCARET_NONE),
mActiveTouchId(-1),
mCaretCenterToDownPointOffsetY(0),
mInAsyncPanZoomGesture(false),
mVisible(false),
mIsValidTap(false),
mActionBarViewID(0)
@ -99,6 +103,43 @@ TouchCaret::TouchCaret(nsIPresShell* aPresShell)
MOZ_ASSERT(mPresShell, "Hey, pres shell should support weak refs");
}
void
TouchCaret::Init()
{
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
if (!presShell) {
return;
}
nsPresContext* presContext = presShell->GetPresContext();
MOZ_ASSERT(presContext, "PresContext should be given in PresShell::Init()");
nsIDocShell* docShell = presContext->GetDocShell();
if (!docShell) {
return;
}
docShell->AddWeakScrollObserver(this);
mDocShell = static_cast<nsDocShell*>(docShell);
}
void
TouchCaret::Terminate()
{
nsRefPtr<nsDocShell> docShell(mDocShell.get());
if (docShell) {
docShell->RemoveWeakScrollObserver(this);
}
if (mScrollEndDetectorTimer) {
mScrollEndDetectorTimer->Cancel();
mScrollEndDetectorTimer = nullptr;
}
mDocShell = WeakPtr<nsDocShell>();
mPresShell = nullptr;
}
TouchCaret::~TouchCaret()
{
TOUCHCARET_LOG("Destructor");
@ -427,6 +468,76 @@ TouchCaret::NotifySelectionChanged(nsIDOMDocument* aDoc, nsISelection* aSel,
return NS_OK;
}
/**
* Used to update caret position after PanZoom stops for
* extended caret visibility. Never needed by MOZ_WIDGET_GONK.
*/
void
TouchCaret::AsyncPanZoomStarted()
{
if (mVisible) {
if (sTouchcaretExtendedvisibility) {
mInAsyncPanZoomGesture = true;
}
}
}
void
TouchCaret::AsyncPanZoomStopped()
{
if (mInAsyncPanZoomGesture) {
mInAsyncPanZoomGesture = false;
UpdatePosition();
}
}
/**
* Used to update caret position after Scroll stops for
* extended caret visibility. Never needed by MOZ_WIDGET_GONK.
*/
void
TouchCaret::ScrollPositionChanged()
{
if (mVisible) {
if (sTouchcaretExtendedvisibility) {
// Launch scroll end detector.
LaunchScrollEndDetector();
}
}
}
void
TouchCaret::LaunchScrollEndDetector()
{
if (!mScrollEndDetectorTimer) {
mScrollEndDetectorTimer = do_CreateInstance("@mozilla.org/timer;1");
}
MOZ_ASSERT(mScrollEndDetectorTimer);
mScrollEndDetectorTimer->InitWithFuncCallback(FireScrollEnd,
this,
sScrollEndTimerDelay,
nsITimer::TYPE_ONE_SHOT);
}
void
TouchCaret::CancelScrollEndDetector()
{
if (mScrollEndDetectorTimer) {
mScrollEndDetectorTimer->Cancel();
}
}
/* static */void
TouchCaret::FireScrollEnd(nsITimer* aTimer, void* aTouchCaret)
{
nsRefPtr<TouchCaret> self = static_cast<TouchCaret*>(aTouchCaret);
NS_PRECONDITION(aTimer == self->mScrollEndDetectorTimer,
"Unexpected timer");
self->UpdatePosition();
}
void
TouchCaret::SyncVisibilityWithCaret()
{

Просмотреть файл

@ -27,7 +27,9 @@ namespace mozilla {
* TouchCaret is also responsible for touch caret visibility. Touch caret
* won't be shown when timer expires or while key event causes selection change.
*/
class TouchCaret final : public nsISelectionListener
class TouchCaret final : public nsISelectionListener,
public nsIScrollObserver,
public nsSupportsWeakReference
{
public:
explicit TouchCaret(nsIPresShell* aPresShell);
@ -35,10 +37,15 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSISELECTIONLISTENER
void Terminate()
{
mPresShell = nullptr;
}
void Init();
void Terminate();
// nsIScrollObserver
virtual void ScrollPositionChanged() override;
// AsyncPanZoom started/stopped callbacks from nsIScrollObserver
virtual void AsyncPanZoomStarted() override;
virtual void AsyncPanZoomStopped() override;
/**
* Handle mouse and touch event only.
@ -273,7 +280,21 @@ private:
return sTouchCaretExpirationTime;
}
void LaunchScrollEndDetector();
void CancelScrollEndDetector();
static void FireScrollEnd(nsITimer* aTimer, void* aSelectionCarets);
// This timer is used for detecting scroll end. We don't have
// scroll end event now, so we will fire this event with a
// const time when we scroll. So when timer triggers, we treat it
// as scroll end event.
nsCOMPtr<nsITimer> mScrollEndDetectorTimer;
nsWeakPtr mPresShell;
WeakPtr<nsDocShell> mDocShell;
// True if AsyncPanZoom is started
bool mInAsyncPanZoomGesture;
// Touch caret visibility
bool mVisible;
@ -291,6 +312,8 @@ private:
// The auto scroll timer's interval in miliseconds.
friend class SelectionCarets;
static const int32_t sAutoScrollTimerDelay = 30;
// Time for trigger scroll end event, in miliseconds.
static const int32_t sScrollEndTimerDelay = 300;
// Unique ID of current Mobile ActionBar view.
static uint32_t sActionBarViewCount;

Просмотреть файл

@ -899,6 +899,7 @@ PresShell::Init(nsIDocument* aDocument,
if (TouchCaretPrefEnabled() && !AccessibleCaretEnabled()) {
// Create touch caret handle
mTouchCaret = new TouchCaret(this);
mTouchCaret->Init();
}
if (SelectionCaretPrefEnabled() && !AccessibleCaretEnabled()) {