Bug 1083818 - Bypass the 10ms delay if the element being activated won't visually change. r=botond

This commit is contained in:
Kartikaya Gupta 2014-12-15 13:59:02 -05:00
parent 0f4e27fe54
commit 47e697b384
3 changed files with 65 additions and 9 deletions

View File

@ -2107,6 +2107,15 @@ TabChild::RecvHandleSingleTap(const CSSPoint& aPoint, const ScrollableLayerGuid&
}
LayoutDevicePoint currentPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid) * mWidget->GetDefaultScale();;
if (!mActiveElementManager->ActiveElementUsesStyle()) {
// If the active element isn't visually affected by the :active style, we
// have no need to wait the extra sActiveDurationMs to make the activation
// visually obvious to the user.
FireSingleTapEvent(currentPoint);
return true;
}
TABC_LOG("Active element uses style, scheduling timer for click event\n");
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
nsRefPtr<DelayedFireSingleTapEvent> callback =
new DelayedFireSingleTapEvent(this, currentPoint, timer);

View File

@ -4,14 +4,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ActiveElementManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "inIDOMUtils.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "mozilla/dom/Element.h"
#include "nsIDocument.h"
#include "nsStyleSet.h"
#define AEM_LOG(...)
// #define AEM_LOG(...) printf_stderr("AEM: " __VA_ARGS__)
@ -23,10 +23,10 @@ static int32_t sActivationDelayMs = 100;
static bool sActivationDelayMsSet = false;
ActiveElementManager::ActiveElementManager()
: mDomUtils(services::GetInDOMUtils()),
mCanBePan(false),
: mCanBePan(false),
mCanBePanSet(false),
mSetActiveTask(nullptr)
mSetActiveTask(nullptr),
mActiveElementUsesStyle(false)
{
if (!sActivationDelayMsSet) {
Preferences::AddIntVarCache(&sActivationDelayMs,
@ -129,13 +129,51 @@ ActiveElementManager::HandleTouchEnd(bool aWasClick)
ResetTouchBlockState();
}
bool
ActiveElementManager::ActiveElementUsesStyle() const
{
return mActiveElementUsesStyle;
}
static nsPresContext*
GetPresContextFor(nsIContent* aContent)
{
if (!aContent) {
return nullptr;
}
nsIPresShell* shell = aContent->OwnerDoc()->GetShell();
if (!shell) {
return nullptr;
}
return shell->GetPresContext();
}
static bool
ElementHasActiveStyle(dom::Element* aElement)
{
nsPresContext* pc = GetPresContextFor(aElement);
if (!pc) {
return false;
}
nsStyleSet* styleSet = pc->StyleSet();
for (dom::Element* e = aElement; e; e = e->GetParentElement()) {
if (styleSet->HasStateDependentStyle(pc, e, NS_EVENT_STATE_ACTIVE)) {
AEM_LOG("Element %p's style is dependent on the active state\n", e);
return true;
}
}
AEM_LOG("Element %p doesn't use active styles\n", aElement);
return false;
}
void
ActiveElementManager::SetActive(dom::Element* aTarget)
{
AEM_LOG("Setting active %p\n", aTarget);
if (mDomUtils) {
nsCOMPtr<nsIDOMElement> target = do_QueryInterface(aTarget);
mDomUtils->SetContentState(target, NS_EVENT_STATE_ACTIVE.GetInternalValue());
if (nsPresContext* pc = GetPresContextFor(aTarget)) {
pc->EventStateManager()->SetContentState(aTarget, NS_EVENT_STATE_ACTIVE);
mActiveElementUsesStyle = ElementHasActiveStyle(aTarget);
}
}

View File

@ -53,8 +53,13 @@ public:
* @param aWasClick whether the touch was a click
*/
void HandleTouchEnd(bool aWasClick);
/**
* @return true iff the currently active element (or one of its ancestors)
* actually had a style for the :active pseudo-class. The currently active
* element is the root element if no other elements are active.
*/
bool ActiveElementUsesStyle() const;
private:
nsCOMPtr<inIDOMUtils> mDomUtils;
/**
* The target of the first touch point in the current touch block.
*/
@ -73,6 +78,10 @@ private:
* A task for calling SetActive() after a timeout.
*/
CancelableTask* mSetActiveTask;
/**
* See ActiveElementUsesStyle() documentation.
*/
bool mActiveElementUsesStyle;
// Helpers
void TriggerElementActivation();