Bug 1010538 - Part 5 - Enable automatic smooth scrolling for anchor links. r=mstange

- When an anchor link is clicked, the SCROLL_SMOOTH_AUTO flag is now set by
  PresShell::GoToAnchor when calling PresShell::ScrollContentIntoView.
- Added an arguement, aAnimateScroll, to PresShell:GoToAnchor to indicate that
  the scroll may be animated.  This will only be set to true when an anchor
  link is clicked.  Opening a page with an anchor link will not trigger
  such animations.
This commit is contained in:
Kearwood (Kip) Gilbert 2014-09-15 15:54:42 -07:00
parent 233c40283c
commit 14bf556ab3
4 changed files with 13 additions and 7 deletions

View File

@ -10730,7 +10730,8 @@ nsDocShell::ScrollToAnchor(nsACString & aCurHash, nsACString & aNewHash,
nsresult rv = NS_ERROR_FAILURE;
NS_ConvertUTF8toUTF16 uStr(str);
if (!uStr.IsEmpty()) {
rv = shell->GoToAnchor(NS_ConvertUTF8toUTF16(str), scroll);
rv = shell->GoToAnchor(NS_ConvertUTF8toUTF16(str), scroll,
nsIPresShell::SCROLL_SMOOTH_AUTO);
}
nsMemory::Free(str);
@ -10764,7 +10765,8 @@ nsDocShell::ScrollToAnchor(nsACString & aCurHash, nsACString & aNewHash,
//
// When newHashName contains "%00", unescaped string may be empty.
// And GoToAnchor asserts if we ask it to scroll to an empty ref.
shell->GoToAnchor(uStr, scroll && !uStr.IsEmpty());
shell->GoToAnchor(uStr, scroll && !uStr.IsEmpty(),
nsIPresShell::SCROLL_SMOOTH_AUTO);
}
}
else {

View File

@ -591,9 +591,11 @@ public:
* document so that the anchor with the specified name is displayed at
* the top of the window. If |aAnchorName| is empty, then this informs
* the pres shell that there is no current target, and |aScroll| must
* be false.
* be false. If |aAdditionalScrollFlags| is nsIPresShell::SCROLL_SMOOTH_AUTO
* and |aScroll| is true, the scrolling may be performed with an animation.
*/
virtual nsresult GoToAnchor(const nsAString& aAnchorName, bool aScroll) = 0;
virtual nsresult GoToAnchor(const nsAString& aAnchorName, bool aScroll,
uint32_t aAdditionalScrollFlags = 0) = 0;
/**
* Tells the presshell to scroll again to the last anchor scrolled to by

View File

@ -3081,7 +3081,8 @@ PresShell::CreateReferenceRenderingContext()
}
nsresult
PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll)
PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll,
uint32_t aAdditionalScrollFlags)
{
if (!mDocument) {
return NS_ERROR_FAILURE;
@ -3188,7 +3189,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll)
rv = ScrollContentIntoView(content,
ScrollAxis(SCROLL_TOP, SCROLL_ALWAYS),
ScrollAxis(),
ANCHOR_SCROLL_FLAGS);
ANCHOR_SCROLL_FLAGS | aAdditionalScrollFlags);
NS_ENSURE_SUCCESS(rv, rv);
nsIScrollableFrame* rootScroll = GetRootScrollFrameAsScrollable();

View File

@ -123,7 +123,8 @@ public:
virtual void ClearFrameRefs(nsIFrame* aFrame) MOZ_OVERRIDE;
virtual already_AddRefed<nsRenderingContext> CreateReferenceRenderingContext();
virtual nsresult GoToAnchor(const nsAString& aAnchorName, bool aScroll) MOZ_OVERRIDE;
virtual nsresult GoToAnchor(const nsAString& aAnchorName, bool aScroll,
uint32_t aAdditionalScrollFlags = 0) MOZ_OVERRIDE;
virtual nsresult ScrollToAnchor() MOZ_OVERRIDE;
virtual nsresult ScrollContentIntoView(nsIContent* aContent,