Bug 1172171 - Add a chrome-only scrollend event. r?kats
MozReview-Commit-ID: 1mUqPdsb31I
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -34,16 +34,17 @@
#include "nsLayoutUtils.h"
#include "nsBidiPresUtils.h"
#include "nsBidiUtils.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/dom/Element.h"
+#include "mozilla/dom/Event.h"
#include "mozilla/dom/HTMLTextAreaElement.h"
#include <stdint.h>
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Telemetry.h"
#include "FrameLayerBuilder.h"
#include "nsSMILKeySpline.h"
#include "nsSubDocumentFrame.h"
#include "nsSVGOuterSVGFrame.h"
@@ -2180,16 +2181,17 @@ ScrollFrameHelper::CompleteAsyncScroll(c
AutoWeakFrame weakFrame(mOuter);
ScrollToImpl(mDestination, aRange, aOrigin);
if (!weakFrame.IsAlive()) {
return;
}
// We are done scrolling, set our destination to wherever we actually ended
// up scrolling to.
mDestination = GetScrollPosition();
+ FireScrollEndEvent();
}
bool
ScrollFrameHelper::HasPluginFrames()
{
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
if (XRE_IsContentProcess()) {
nsPresContext* presContext = mOuter->PresContext();
@@ -4404,16 +4406,27 @@ ScrollFrameHelper::FireScrollPortEvent()
mVerticalOverflow) ?
eScrollPortOverflow : eScrollPortUnderflow, nullptr);
event.mOrient = orient;
return EventDispatcher::Dispatch(mOuter->GetContent(),
mOuter->PresContext(), &event);
}
void
+ScrollFrameHelper::FireScrollEndEvent()
+{
+ MOZ_ASSERT(mOuter->GetContent());
+ nsContentUtils::DispatchEventOnlyToChrome(mOuter->GetContent()->OwnerDoc(),
+ mOuter->GetContent(),
+ NS_LITERAL_STRING("scrollend"),
+ true /* aCanBubble */,
+ false /* aCancelable */);
+}
+
+void
ScrollFrameHelper::ReloadChildFrames()
{
mScrolledFrame = nullptr;
mHScrollbarBox = nullptr;
mVScrollbarBox = nullptr;
mScrollCornerBox = nullptr;
mResizerBox = nullptr;
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -64,16 +64,17 @@ public:
// reload our child frame list.
// We need this if a scrollbar frame is recreated.
void ReloadChildFrames();
nsresult CreateAnonymousContent(
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter);
nsresult FireScrollPortEvent();
+ void FireScrollEndEvent();
void PostOverflowEvent();
void Destroy();
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists);
void AppendScrollPartsTo(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists,
@@ -394,16 +395,19 @@ public:
bool ShouldClampScrollPosition() const;
bool IsAlwaysActive() const;
void MarkRecentlyScrolled();
void MarkNotRecentlyScrolled();
nsExpirationState* GetExpirationState() { return &mActivityExpirationState; }
void SetTransformingByAPZ(bool aTransforming) {
+ if (mTransformingByAPZ && !aTransforming) {
+ FireScrollEndEvent();
+ }
mTransformingByAPZ = aTransforming;
if (!mozilla::css::TextOverflow::HasClippedOverflow(mOuter)) {
// If the block has some text-overflow stuff we should kick off a paint
// because we have special behaviour for it when APZ scrolling is active.
mOuter->SchedulePaint();
}
}
bool IsTransformingByAPZ() const {