Bug 1219150 - EventStateManager::{LatestUserInputStart, UserInputCount};r=smaug

To detect slow behaviors, it is useful to find out whether a user
input was handled between two instants.

This patch introduces EventStateManager::UserInputCount, which lets
client code determine whether user input was handled between two
points of execution, and EventStateManager::LatestUserInputStart,
which lets client code find out when the altest user input was
handled.

--HG--
extra : commitid : uK1v8pj0fi
This commit is contained in:
David Rajchenbach-Teller 2015-12-03 17:40:45 -08:00
parent e8eaae79a5
commit 186f04cf6f
2 changed files with 49 additions and 10 deletions

View File

@ -264,6 +264,7 @@ NS_INTERFACE_MAP_END
static uint32_t sESMInstanceCount = 0;
static bool sPointerEventEnabled = false;
uint64_t EventStateManager::sUserInputCounter = 0;
int32_t EventStateManager::sUserInputEventDepth = 0;
bool EventStateManager::sNormalLMouseEventInProcess = false;
EventStateManager* EventStateManager::sActiveESM = nullptr;
@ -279,6 +280,7 @@ nsWeakPtr EventStateManager::sPointerLockedElement;
// Reference to the document which requested pointer lock.
nsWeakPtr EventStateManager::sPointerLockedDoc;
nsCOMPtr<nsIContent> EventStateManager::sDragOverContent = nullptr;
TimeStamp EventStateManager::sLatestUserInputStart;
TimeStamp EventStateManager::sHandlingInputStart;
EventStateManager::WheelPrefs*

View File

@ -195,8 +195,9 @@ public:
static void StartHandlingUserInput()
{
++sUserInputEventDepth;
++sUserInputCounter;
if (sUserInputEventDepth == 1) {
sHandlingInputStart = TimeStamp::Now();
sLatestUserInputStart = sHandlingInputStart = TimeStamp::Now();
}
}
@ -209,17 +210,38 @@ public:
}
/**
* Returns true if the current code is being executed as a result of user input.
* This includes timers or anything else that is initiated from user input.
* However, mouse over events are not counted as user input, nor are
* page load events. If this method is called from asynchronously executed code,
* such as during layout reflows, it will return false. If more time has elapsed
* since the user input than is specified by the
* dom.event.handling-user-input-time-limit pref (default 1 second), this
* function also returns false.
* Returns true if the current code is being executed as a result of
* user input. This includes anything that is initiated by user,
* with the exception of page load events or mouse over events. If
* this method is called from asynchronously executed code, such as
* during layout reflows, it will return false. If more time has
* elapsed since the user input than is specified by the
* dom.event.handling-user-input-time-limit pref (default 1 second),
* this function also returns false.
*/
static bool IsHandlingUserInput();
/**
* Get the number of user inputs handled since process start. This
* includes anything that is initiated by user, with the exception
* of page load events or mouse over events.
*/
static uint64_t UserInputCount()
{
return sUserInputCounter;
}
/**
* Get the timestamp at which the latest user input was handled.
*
* Guaranteed to be monotonic. Until the first user input, return
* the epoch.
*/
static TimeStamp LatestUserInputStart()
{
return sLatestUserInputStart;
}
nsPresContext* GetPresContext() { return mPresContext; }
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EventStateManager,
@ -921,9 +943,14 @@ private:
bool m_haveShutdown;
// Time at which we began handling user input.
// Time at which we began handling user input. Reset to the epoch
// once we have finished handling user input.
static TimeStamp sHandlingInputStart;
// Time at which we began handling the latest user input. Not reset
// at the end of the input.
static TimeStamp sLatestUserInputStart;
RefPtr<OverOutElementsWrapper> mMouseEnterLeaveHelper;
nsRefPtrHashtable<nsUint32HashKey, OverOutElementsWrapper> mPointersEnterLeaveHelper;
@ -932,6 +959,16 @@ public:
// Array for accesskey support
nsCOMArray<nsIContent> mAccessKeys;
// The number of user inputs handled since process start. This
// includes anything that is initiated by user, with the exception
// of page load events or mouse over events.
static uint64_t sUserInputCounter;
// The current depth of user inputs. This includes anything that is
// initiated by user, with the exception of page load events or
// mouse over events. Incremented whenever we start handling a user
// input, decremented when we have finished handling a user
// input. This depth is *not* reset in case of nested event loops.
static int32_t sUserInputEventDepth;
static bool sNormalLMouseEventInProcess;