Bug 1205466, make HasApzAwareListeners check faster, r=masayuki

This commit is contained in:
Olli Pettay 2015-09-17 13:16:20 +03:00
parent 688c48fefe
commit d85f6117d5
14 changed files with 81 additions and 32 deletions

View File

@ -135,8 +135,8 @@ class DestinationInsertionPointList;
// IID for the dom::Element interface
#define NS_ELEMENT_IID \
{ 0x31d3f3fb, 0xcdf8, 0x4e40, \
{ 0xb7, 0x09, 0x1a, 0x11, 0x43, 0x93, 0x61, 0x71 } }
{ 0xc67ed254, 0xfd3b, 0x4b10, \
{ 0x96, 0xa2, 0xc5, 0x8b, 0x7b, 0x64, 0x97, 0xd1 } }
class Element : public FragmentOrElement
{

View File

@ -12,8 +12,8 @@
class nsDOMAttributeMap;
#define NS_IATTRIBUTE_IID \
{ 0x233a9c4d, 0xb27f, 0x4662, \
{ 0xbd, 0x90, 0xba, 0xd6, 0x2e, 0x76, 0xc8, 0xe1 } }
{ 0x84d43da7, 0xb45d, 0x47ae, \
{ 0x8f, 0xbf, 0x95, 0x26, 0x78, 0x4d, 0x5e, 0x47 } }
class nsIAttribute : public nsINode
{

View File

@ -40,8 +40,8 @@ enum nsLinkState {
// IID for the nsIContent interface
#define NS_ICONTENT_IID \
{ 0x70f7e9ea, 0xa9bf, 0x48cc, \
{ 0xad, 0x9d, 0x8a, 0xca, 0xee, 0xd2, 0x9b, 0x68 } }
{ 0x52cebfc8, 0x79ba, 0x4e38, \
{ 0x8a, 0x4c, 0x7f, 0x9d, 0xb1, 0xa2, 0xb6, 0x1d } }
/**
* A node of content in a document's content model. This interface

View File

@ -155,8 +155,8 @@ typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0x292450a1, 0x285e, 0x4a09, \
{ 0x9a, 0xf9, 0x61, 0xf9, 0xb1, 0xbd, 0x27, 0xcc } }
{ 0x72391609, 0x673d, 0x4bec, \
{ 0xbd, 0x75, 0x64, 0xbf, 0x1f, 0x6a, 0x6b, 0x5e } }
// Enum for requesting a particular type of document when creating a doc
enum DocumentFlavor {

View File

@ -2833,3 +2833,12 @@ nsINode::AddAnimationObserverUnlessExists(
AddMutationObserverUnlessExists(aAnimationObserver);
OwnerDoc()->SetMayHaveAnimationObservers();
}
bool
nsINode::HasApzAwareListeners() const
{
if (NodeMayHaveApzAwareListeners()) {
return EventTarget::HasApzAwareListeners();
}
return false;
}

View File

@ -250,8 +250,8 @@ private:
// IID for the nsINode interface
#define NS_INODE_IID \
{ 0xe8fdd227, 0x27da, 0x46ee, \
{ 0xbe, 0xf3, 0x1a, 0xef, 0x5a, 0x8f, 0xc5, 0xb4 } }
{ 0x70ba4547, 0x7699, 0x44fc, \
{ 0xb3, 0x20, 0x52, 0xdb, 0xe3, 0xd1, 0xf9, 0x0a } }
/**
* An internal interface that abstracts some DOMNode-related parts that both
@ -949,6 +949,9 @@ public:
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv) override;
using nsIDOMEventTarget::AddSystemEventListener;
virtual bool HasApzAwareListeners() const override;
virtual nsIDOMWindow* GetOwnerGlobalForBindings() override;
virtual nsIGlobalObject* GetOwnerGlobal() const override;
@ -1495,6 +1498,8 @@ private:
ElementHasWeirdParserInsertionMode,
// Parser sets this flag if it has notified about the node.
ParserHasNotified,
// EventListenerManager sets this flag in case we have apz aware listeners.
MayHaveApzAwareListeners,
// Guard value
BooleanFlagCount
};
@ -1637,6 +1642,12 @@ public:
void SetHasRelevantHoverRules() { SetBoolFlag(NodeHasRelevantHoverRules); }
void SetParserHasNotified() { SetBoolFlag(ParserHasNotified); };
bool HasParserNotified() { return GetBoolFlag(ParserHasNotified); }
void SetMayHaveApzAwareListeners() { SetBoolFlag(MayHaveApzAwareListeners); }
bool NodeMayHaveApzAwareListeners() const
{
return GetBoolFlag(MayHaveApzAwareListeners);
}
protected:
void SetParentIsContent(bool aValue) { SetBoolFlag(ParentIsContent, aValue); }
void SetInDocument() { SetBoolFlag(IsInDocument); }

View File

@ -22,8 +22,8 @@ class TabParent;
} // namespace mozilla
#define NS_IWINDOWROOT_IID \
{ 0x238edca0, 0xb30d, 0x46d3, \
{ 0xb2, 0x6a, 0x17, 0xb6, 0x21, 0x28, 0x89, 0x7e } }
{ 0xb8724c49, 0xc398, 0x4f9b, \
{ 0x82, 0x59, 0x87, 0x27, 0xa6, 0x47, 0xdd, 0x0f } }
class nsPIWindowRoot : public mozilla::dom::EventTarget
{

View File

@ -405,6 +405,13 @@ EventListenerManager::AddEventListenerInternal(
}
}
if (IsApzAwareEvent(aTypeAtom)) {
nsCOMPtr<nsINode> node = do_QueryInterface(mTarget);
if (node) {
node->SetMayHaveApzAwareListeners();
}
}
if (aTypeAtom && mTarget) {
mTarget->EventListenerAdded(aTypeAtom);
}
@ -1490,6 +1497,30 @@ EventListenerManager::TraceListeners(JSTracer* aTrc)
}
}
bool
EventListenerManager::HasApzAwareListeners()
{
uint32_t count = mListeners.Length();
for (uint32_t i = 0; i < count; ++i) {
Listener* listener = &mListeners.ElementAt(i);
if (IsApzAwareEvent(listener->mTypeAtom)) {
return true;
}
}
return false;
}
bool
EventListenerManager::IsApzAwareEvent(nsIAtom* aEvent)
{
return aEvent == nsGkAtoms::ontouchstart ||
aEvent == nsGkAtoms::ontouchmove ||
aEvent == nsGkAtoms::onwheel ||
aEvent == nsGkAtoms::onDOMMouseScroll ||
aEvent == nsHtml5Atoms::onmousewheel ||
aEvent == nsGkAtoms::onMozMousePixelScroll;
}
already_AddRefed<nsIScriptGlobalObject>
EventListenerManager::GetScriptGlobalAndDocument(nsIDocument** aDoc)
{

View File

@ -443,6 +443,10 @@ public:
dom::EventTarget* GetTarget() { return mTarget; }
bool HasApzAwareListeners();
bool IsApzAwareEvent(nsIAtom* aEvent);
protected:
void HandleEventInternal(nsPresContext* aPresContext,
WidgetEvent* aEvent,

View File

@ -56,5 +56,12 @@ EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
}
bool
EventTarget::HasApzAwareListeners() const
{
EventListenerManager* elm = GetExistingListenerManager();
return elm && elm->HasApzAwareListeners();
}
} // namespace dom
} // namespace mozilla

View File

@ -28,8 +28,8 @@ template <class T> struct Nullable;
// IID for the dom::EventTarget interface
#define NS_EVENTTARGET_IID \
{ 0x605158a9, 0xe229, 0x45b1, \
{ 0xbc, 0x12, 0x02, 0x9f, 0xa3, 0xa9, 0x3f, 0xcb } }
{ 0xde651c36, 0x0053, 0x4c67, \
{ 0xb1, 0x3d, 0x67, 0xb9, 0x40, 0xfc, 0x82, 0xe4 } }
class EventTarget : public nsIDOMEventTarget,
public nsWrapperCache
@ -88,6 +88,8 @@ public:
*/
virtual EventListenerManager* GetExistingListenerManager() const = 0;
virtual bool HasApzAwareListeners() const;
protected:
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
const nsAString& aTypeString);

View File

@ -8199,20 +8199,6 @@ nsLayoutUtils::SetBSizeFromFontMetrics(const nsIFrame* aFrame,
aMetrics.BSize(aLineWM) += aFramePadding.BStartEnd(aFrameWM);
}
/* static */ bool
nsLayoutUtils::HasApzAwareListeners(EventListenerManager* aElm)
{
if (!aElm) {
return false;
}
return aElm->HasListenersFor(nsGkAtoms::ontouchstart) ||
aElm->HasListenersFor(nsGkAtoms::ontouchmove) ||
aElm->HasListenersFor(nsGkAtoms::onwheel) ||
aElm->HasListenersFor(nsGkAtoms::onDOMMouseScroll) ||
aElm->HasListenersFor(nsHtml5Atoms::onmousewheel) ||
aElm->HasListenersFor(nsGkAtoms::onMozMousePixelScroll);
}
/* static */ bool
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(nsIPresShell* aShell)
{
@ -8223,7 +8209,7 @@ nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(nsIPresShell* aShell)
nullptr, nullptr, &targets);
NS_ENSURE_SUCCESS(rv, false);
for (size_t i = 0; i < targets.Length(); i++) {
if (HasApzAwareListeners(targets[i]->GetExistingListenerManager())) {
if (targets[i]->HasApzAwareListeners()) {
return true;
}
}

View File

@ -2694,7 +2694,6 @@ public:
mozilla::WritingMode aLineWM,
mozilla::WritingMode aFrameWM);
static bool HasApzAwareListeners(mozilla::EventListenerManager* aElm);
static bool HasDocumentLevelListenersForApzAwareEvents(nsIPresShell* aShell);
/**

View File

@ -2009,8 +2009,8 @@ CheckForApzAwareEventHandlers(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
if (!content) {
return;
}
EventListenerManager* elm = nsContentUtils::GetExistingListenerManagerForNode(content);
if (nsLayoutUtils::HasApzAwareListeners(elm)) {
if (content->HasApzAwareListeners()) {
aBuilder->SetAncestorHasApzAwareEventHandler(true);
}
}