2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* rendering object to wrap rendering objects that should be scrollable */
|
|
|
|
|
2013-09-24 18:43:43 -07:00
|
|
|
#include "nsGfxScrollFrame.h"
|
|
|
|
|
2013-04-28 03:02:35 -07:00
|
|
|
#include "base/compiler_specific.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPresContext.h"
|
2013-01-03 05:23:11 -08:00
|
|
|
#include "nsView.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScrollable.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsContentList.h"
|
2013-01-12 13:53:01 -08:00
|
|
|
#include "nsIDocumentInlines.h"
|
2011-04-07 18:05:49 -07:00
|
|
|
#include "nsFontMetrics.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsINodeInfo.h"
|
2011-07-11 07:05:09 -07:00
|
|
|
#include "nsScrollbarFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScrollbarMediator.h"
|
|
|
|
#include "nsITextControlFrame.h"
|
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsPresState.h"
|
2008-02-19 10:47:34 -08:00
|
|
|
#include "nsIHTMLDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsBidiUtils.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2011-06-11 19:30:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-08 19:27:13 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2013-06-09 17:37:16 -07:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2011-02-10 00:58:11 -08:00
|
|
|
#include "FrameLayerBuilder.h"
|
2011-03-25 21:30:19 -07:00
|
|
|
#include "nsSMILKeySpline.h"
|
2011-12-05 04:38:46 -08:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2012-03-19 01:34:19 -07:00
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-03 03:35:14 -07:00
|
|
|
#include "ScrollbarActivity.h"
|
2012-08-06 05:02:08 -07:00
|
|
|
#include "nsRefreshDriver.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "nsThemeConstants.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
#include "nsIScrollPositionListener.h"
|
2013-09-06 06:35:16 -07:00
|
|
|
#include "StickyScrollContainer.h"
|
2013-10-01 14:00:38 -07:00
|
|
|
#include "nsIFrameInlines.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2013-02-24 16:59:21 -08:00
|
|
|
#include <cstdlib> // for std::abs(int/long)
|
|
|
|
#include <cmath> // for std::abs(float/double)
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
using namespace mozilla;
|
2010-04-30 06:12:05 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-05-02 07:58:00 -07:00
|
|
|
using namespace mozilla::layout;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
//----------nsHTMLScrollFrame-------------------------------------------
|
|
|
|
|
|
|
|
nsIFrame*
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, bool aIsRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsHTMLScrollFrame(aPresShell, aContext, aIsRoot);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLScrollFrame)
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, bool aIsRoot)
|
2011-12-27 12:18:48 -08:00
|
|
|
: nsContainerFrame(aContext),
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper(ALLOW_THIS_IN_INITIALIZER_LIST(this), aIsRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-16 14:17:40 -07:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::ScrollbarActivityStarted() const
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mScrollbarActivity) {
|
|
|
|
mHelper.mScrollbarActivity->ActivityStarted();
|
2013-08-16 14:17:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::ScrollbarActivityStopped() const
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mScrollbarActivity) {
|
|
|
|
mHelper.mScrollbarActivity->ActivityStopped();
|
2013-08-16 14:17:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2011-05-06 13:04:44 -07:00
|
|
|
nsHTMLScrollFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
return mHelper.CreateAnonymousContent(aElements);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2010-10-15 08:34:35 -07:00
|
|
|
nsHTMLScrollFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFilter)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.AppendAnonymousContentTo(aElements, aFilter);
|
2010-02-11 09:34:01 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsHTMLScrollFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-11 16:53:34 -07:00
|
|
|
DestroyAbsoluteFrames(aDestructRoot);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.Destroy();
|
2011-12-27 12:18:48 -08:00
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLScrollFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-27 12:18:48 -08:00
|
|
|
nsresult rv = nsContainerFrame::SetInitialChildList(aListID, aChildList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLScrollFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "Only main list supported");
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrames.AppendFrames(nullptr, aFrameList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLScrollFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "Only main list supported");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrames.InsertFrames(nullptr, aPrevFrame, aFrameList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLScrollFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "Only main list supported");
|
2007-11-18 14:24:21 -08:00
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplittableType
|
|
|
|
nsHTMLScrollFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLScrollFrame::GetType() const
|
|
|
|
{
|
2013-03-04 12:57:01 -08:00
|
|
|
return nsGkAtoms::scrollFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
HTML scrolling implementation
|
|
|
|
|
|
|
|
All other things being equal, we prefer layouts with fewer scrollbars showing.
|
|
|
|
*/
|
|
|
|
|
2013-04-11 20:20:45 -07:00
|
|
|
struct MOZ_STACK_CLASS ScrollReflowState {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsHTMLReflowState& mReflowState;
|
|
|
|
nsBoxLayoutState mBoxState;
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles mStyles;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin mComputedBorder;
|
|
|
|
|
2007-12-04 19:05:57 -08:00
|
|
|
// === Filled in by ReflowScrolledFrame ===
|
2011-12-05 04:38:46 -08:00
|
|
|
nsOverflowAreas mContentsOverflowAreas;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mReflowedContentsWithHScrollbar;
|
|
|
|
bool mReflowedContentsWithVScrollbar;
|
2007-12-04 19:05:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// === Filled in when TryLayout succeeds ===
|
|
|
|
// The size of the inside-border area
|
|
|
|
nsSize mInsideBorderSize;
|
|
|
|
// Whether we decided to show the horizontal scrollbar
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mShowHScrollbar;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Whether we decided to show the vertical scrollbar
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mShowVScrollbar;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ScrollReflowState(nsIScrollableFrame* aFrame,
|
|
|
|
const nsHTMLReflowState& aState) :
|
|
|
|
mReflowState(aState),
|
2008-04-09 21:39:41 -07:00
|
|
|
// mBoxState is just used for scrollbars so we don't need to
|
|
|
|
// worry about the reflow depth here
|
|
|
|
mBoxState(aState.frame->PresContext(), aState.rendContext, 0),
|
2007-03-22 10:30:00 -07:00
|
|
|
mStyles(aFrame->GetScrollbarStyles()) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// XXXldb Can this go away?
|
|
|
|
static nsSize ComputeInsideBorderSize(ScrollReflowState* aState,
|
|
|
|
const nsSize& aDesiredInsideBorderSize)
|
|
|
|
{
|
|
|
|
// aDesiredInsideBorderSize is the frame size; i.e., it includes
|
|
|
|
// borders and padding (but the scrolled child doesn't have
|
|
|
|
// borders). The scrolled child has the same padding as us.
|
|
|
|
nscoord contentWidth = aState->mReflowState.ComputedWidth();
|
|
|
|
if (contentWidth == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
contentWidth = aDesiredInsideBorderSize.width -
|
2013-12-27 09:59:21 -08:00
|
|
|
aState->mReflowState.ComputedPhysicalPadding().LeftRight();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-02 11:08:05 -07:00
|
|
|
nscoord contentHeight = aState->mReflowState.ComputedHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (contentHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
contentHeight = aDesiredInsideBorderSize.height -
|
2013-12-27 09:59:21 -08:00
|
|
|
aState->mReflowState.ComputedPhysicalPadding().TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 07:26:05 -07:00
|
|
|
contentWidth = aState->mReflowState.ApplyMinMaxWidth(contentWidth);
|
|
|
|
contentHeight = aState->mReflowState.ApplyMinMaxHeight(contentHeight);
|
2013-12-27 09:59:21 -08:00
|
|
|
return nsSize(contentWidth + aState->mReflowState.ComputedPhysicalPadding().LeftRight(),
|
|
|
|
contentHeight + aState->mReflowState.ComputedPhysicalPadding().TopBottom());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-05 20:00:57 -07:00
|
|
|
GetScrollbarMetrics(nsBoxLayoutState& aState, nsIFrame* aBox, nsSize* aMin,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSize* aPref, bool aVertical)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aState.GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aMin) {
|
|
|
|
*aMin = aBox->GetMinSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(aBox, *aMin);
|
2013-05-02 07:58:00 -07:00
|
|
|
if (aMin->width < 0) {
|
|
|
|
aMin->width = 0;
|
|
|
|
}
|
|
|
|
if (aMin->height < 0) {
|
|
|
|
aMin->height = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aPref) {
|
|
|
|
*aPref = aBox->GetPrefSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(aBox, *aPref);
|
2013-05-02 07:58:00 -07:00
|
|
|
if (aPref->width < 0) {
|
|
|
|
aPref->width = 0;
|
|
|
|
}
|
|
|
|
if (aPref->height < 0) {
|
|
|
|
aPref->height = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assuming that we know the metrics for our wrapped frame and
|
|
|
|
* whether the horizontal and/or vertical scrollbars are present,
|
2011-10-17 07:59:28 -07:00
|
|
|
* compute the resulting layout and return true if the layout is
|
2007-03-22 10:30:00 -07:00
|
|
|
* consistent. If the layout is consistent then we fill in the
|
|
|
|
* computed fields of the ScrollReflowState.
|
|
|
|
*
|
|
|
|
* The layout is consistent when both scrollbars are showing if and only
|
|
|
|
* if they should be showing. A horizontal scrollbar should be showing if all
|
|
|
|
* following conditions are met:
|
|
|
|
* 1) the style is not HIDDEN
|
|
|
|
* 2) our inside-border height is at least the scrollbar height (i.e., the
|
|
|
|
* scrollbar fits vertically)
|
|
|
|
* 3) our scrollport width (the inside-border width minus the width allocated for a
|
|
|
|
* vertical scrollbar, if showing) is at least the scrollbar's min-width
|
|
|
|
* (i.e., the scrollbar fits horizontally)
|
|
|
|
* 4) the style is SCROLL, or the kid's overflow-area XMost is
|
|
|
|
* greater than the scrollport width
|
|
|
|
*
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aForce if true, then we just assume the layout is consistent.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLScrollFrame::TryLayout(ScrollReflowState* aState,
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLReflowMetrics* aKidMetrics,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAssumeHScroll, bool aAssumeVScroll,
|
|
|
|
bool aForce, nsresult* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-04 19:05:57 -08:00
|
|
|
*aResult = NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((aState->mStyles.mVertical == NS_STYLE_OVERFLOW_HIDDEN && aAssumeVScroll) ||
|
|
|
|
(aState->mStyles.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN && aAssumeHScroll)) {
|
|
|
|
NS_ASSERTION(!aForce, "Shouldn't be forcing a hidden scrollbar to show!");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-12-04 19:05:57 -08:00
|
|
|
|
|
|
|
if (aAssumeVScroll != aState->mReflowedContentsWithVScrollbar ||
|
2008-02-23 02:15:59 -08:00
|
|
|
(aAssumeHScroll != aState->mReflowedContentsWithHScrollbar &&
|
|
|
|
ScrolledContentDependsOnHeight(aState))) {
|
2007-12-04 19:05:57 -08:00
|
|
|
nsresult rv = ReflowScrolledFrame(aState, aAssumeHScroll, aAssumeVScroll,
|
2011-10-17 07:59:28 -07:00
|
|
|
aKidMetrics, false);
|
2007-12-04 19:05:57 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aResult = rv;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-12-04 19:05:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize vScrollbarMinSize(0, 0);
|
|
|
|
nsSize vScrollbarPrefSize(0, 0);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mVScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mHelper.mVScrollbarBox,
|
2007-03-22 10:30:00 -07:00
|
|
|
&vScrollbarMinSize,
|
2012-07-30 07:20:58 -07:00
|
|
|
aAssumeVScroll ? &vScrollbarPrefSize : nullptr, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nscoord vScrollbarDesiredWidth = aAssumeVScroll ? vScrollbarPrefSize.width : 0;
|
2008-02-24 17:21:08 -08:00
|
|
|
nscoord vScrollbarMinHeight = aAssumeVScroll ? vScrollbarMinSize.height : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSize hScrollbarMinSize(0, 0);
|
|
|
|
nsSize hScrollbarPrefSize(0, 0);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mHelper.mHScrollbarBox,
|
2007-03-22 10:30:00 -07:00
|
|
|
&hScrollbarMinSize,
|
2012-07-30 07:20:58 -07:00
|
|
|
aAssumeHScroll ? &hScrollbarPrefSize : nullptr, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nscoord hScrollbarDesiredHeight = aAssumeHScroll ? hScrollbarPrefSize.height : 0;
|
2008-02-24 17:21:08 -08:00
|
|
|
nscoord hScrollbarMinWidth = aAssumeHScroll ? hScrollbarMinSize.width : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// First, compute our inside-border size and scrollport size
|
|
|
|
// XXXldb Can we depend more on ComputeSize here?
|
|
|
|
nsSize desiredInsideBorderSize;
|
|
|
|
desiredInsideBorderSize.width = vScrollbarDesiredWidth +
|
2013-12-27 09:59:52 -08:00
|
|
|
std::max(aKidMetrics->Width(), hScrollbarMinWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
desiredInsideBorderSize.height = hScrollbarDesiredHeight +
|
2013-12-27 09:59:52 -08:00
|
|
|
std::max(aKidMetrics->Height(), vScrollbarMinHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
aState->mInsideBorderSize =
|
|
|
|
ComputeInsideBorderSize(aState, desiredInsideBorderSize);
|
2013-01-15 04:22:03 -08:00
|
|
|
nsSize scrollPortSize = nsSize(std::max(0, aState->mInsideBorderSize.width - vScrollbarDesiredWidth),
|
|
|
|
std::max(0, aState->mInsideBorderSize.height - hScrollbarDesiredHeight));
|
2012-02-22 08:23:47 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aForce) {
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect =
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.GetScrolledRectInternal(aState->mContentsOverflowAreas.ScrollableOverflow(),
|
2011-12-05 04:38:46 -08:00
|
|
|
scrollPortSize);
|
2008-04-24 01:14:06 -07:00
|
|
|
nscoord oneDevPixel = aState->mBoxState.PresContext()->DevPixelsToAppUnits(1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// If the style is HIDDEN then we already know that aAssumeHScroll is false
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wantHScrollbar =
|
2007-03-22 10:30:00 -07:00
|
|
|
aState->mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 01:14:06 -07:00
|
|
|
scrolledRect.XMost() >= scrollPortSize.width + oneDevPixel ||
|
|
|
|
scrolledRect.x <= -oneDevPixel;
|
2012-02-22 08:23:47 -08:00
|
|
|
if (scrollPortSize.width < hScrollbarMinSize.width)
|
2011-10-17 07:59:28 -07:00
|
|
|
wantHScrollbar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (wantHScrollbar != aAssumeHScroll)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// If the style is HIDDEN then we already know that aAssumeVScroll is false
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aState->mStyles.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wantVScrollbar =
|
2007-03-22 10:30:00 -07:00
|
|
|
aState->mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 01:14:06 -07:00
|
|
|
scrolledRect.YMost() >= scrollPortSize.height + oneDevPixel ||
|
|
|
|
scrolledRect.y <= -oneDevPixel;
|
2012-02-22 08:23:47 -08:00
|
|
|
if (scrollPortSize.height < vScrollbarMinSize.height)
|
2011-10-17 07:59:28 -07:00
|
|
|
wantVScrollbar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (wantVScrollbar != aAssumeVScroll)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord vScrollbarActualWidth = aState->mInsideBorderSize.width - scrollPortSize.width;
|
|
|
|
|
|
|
|
aState->mShowHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mShowVScrollbar = aAssumeVScroll;
|
|
|
|
nsPoint scrollPortOrigin(aState->mComputedBorder.left,
|
|
|
|
aState->mComputedBorder.top);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.IsScrollbarOnRight()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
scrollPortOrigin.x += vScrollbarActualWidth;
|
|
|
|
}
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrollPort = nsRect(scrollPortOrigin, scrollPortSize);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-02-23 02:15:59 -08:00
|
|
|
nsHTMLScrollFrame::ScrolledContentDependsOnHeight(ScrollReflowState* aState)
|
|
|
|
{
|
|
|
|
// Return true if ReflowScrolledFrame is going to do something different
|
|
|
|
// based on the presence of a horizontal scrollbar.
|
2013-10-28 19:27:50 -07:00
|
|
|
return (mHelper.mScrolledFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT) ||
|
2008-02-23 02:15:59 -08:00
|
|
|
aState->mReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE ||
|
2013-12-27 09:59:21 -08:00
|
|
|
aState->mReflowState.ComputedMinHeight() > 0 ||
|
|
|
|
aState->mReflowState.ComputedMaxHeight() != NS_UNCONSTRAINEDSIZE;
|
2008-02-23 02:15:59 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLScrollFrame::ReflowScrolledFrame(ScrollReflowState* aState,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAssumeHScroll,
|
|
|
|
bool aAssumeVScroll,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aFirstPass)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-15 04:22:03 -08:00
|
|
|
// these could be NS_UNCONSTRAINEDSIZE ... std::min arithmetic should
|
2007-03-22 10:30:00 -07:00
|
|
|
// be OK
|
2013-12-27 09:59:21 -08:00
|
|
|
nscoord paddingLR = aState->mReflowState.ComputedPhysicalPadding().LeftRight();
|
2007-12-04 19:05:57 -08:00
|
|
|
|
|
|
|
nscoord availWidth = aState->mReflowState.ComputedWidth() + paddingLR;
|
|
|
|
|
|
|
|
nscoord computedHeight = aState->mReflowState.ComputedHeight();
|
2013-12-27 09:59:21 -08:00
|
|
|
nscoord computedMinHeight = aState->mReflowState.ComputedMinHeight();
|
|
|
|
nscoord computedMaxHeight = aState->mReflowState.ComputedMaxHeight();
|
2007-12-06 16:10:31 -08:00
|
|
|
if (!ShouldPropagateComputedHeightToScrolledContent()) {
|
|
|
|
computedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
computedMinHeight = 0;
|
|
|
|
computedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
2007-12-04 19:05:57 -08:00
|
|
|
if (aAssumeHScroll) {
|
2012-08-03 03:35:14 -07:00
|
|
|
nsSize hScrollbarPrefSize;
|
2013-10-28 19:27:50 -07:00
|
|
|
GetScrollbarMetrics(aState->mBoxState, mHelper.mHScrollbarBox,
|
2012-08-12 03:43:47 -07:00
|
|
|
nullptr, &hScrollbarPrefSize, false);
|
2007-12-04 19:05:57 -08:00
|
|
|
if (computedHeight != NS_UNCONSTRAINEDSIZE)
|
2013-01-15 04:22:03 -08:00
|
|
|
computedHeight = std::max(0, computedHeight - hScrollbarPrefSize.height);
|
|
|
|
computedMinHeight = std::max(0, computedMinHeight - hScrollbarPrefSize.height);
|
2007-12-04 19:05:57 -08:00
|
|
|
if (computedMaxHeight != NS_UNCONSTRAINEDSIZE)
|
2013-01-15 04:22:03 -08:00
|
|
|
computedMaxHeight = std::max(0, computedMaxHeight - hScrollbarPrefSize.height);
|
2007-12-04 19:05:57 -08:00
|
|
|
}
|
2007-12-06 16:10:31 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aAssumeVScroll) {
|
2012-08-03 03:35:14 -07:00
|
|
|
nsSize vScrollbarPrefSize;
|
2013-10-28 19:27:50 -07:00
|
|
|
GetScrollbarMetrics(aState->mBoxState, mHelper.mVScrollbarBox,
|
2012-08-12 03:43:47 -07:00
|
|
|
nullptr, &vScrollbarPrefSize, true);
|
2013-01-15 04:22:03 -08:00
|
|
|
availWidth = std::max(0, availWidth - vScrollbarPrefSize.width);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Pass false for aInit so we can pass in the correct padding.
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLReflowState kidReflowState(presContext, aState->mReflowState,
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrolledFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
|
2013-09-09 13:29:05 -07:00
|
|
|
-1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
|
2012-07-30 07:20:58 -07:00
|
|
|
kidReflowState.Init(presContext, -1, -1, nullptr,
|
2013-12-27 09:59:21 -08:00
|
|
|
&aState->mReflowState.ComputedPhysicalPadding());
|
2007-03-22 10:30:00 -07:00
|
|
|
kidReflowState.mFlags.mAssumingHScrollbar = aAssumeHScroll;
|
|
|
|
kidReflowState.mFlags.mAssumingVScrollbar = aAssumeVScroll;
|
2007-12-04 19:05:57 -08:00
|
|
|
kidReflowState.SetComputedHeight(computedHeight);
|
2013-12-27 09:59:21 -08:00
|
|
|
kidReflowState.ComputedMinHeight() = computedMinHeight;
|
|
|
|
kidReflowState.ComputedMaxHeight() = computedMaxHeight;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-14 05:00:00 -08:00
|
|
|
// Temporarily set mHasHorizontalScrollbar/mHasVerticalScrollbar to
|
|
|
|
// reflect our assumptions while we reflow the child.
|
2013-10-28 19:27:50 -07:00
|
|
|
bool didHaveHorizontalScrollbar = mHelper.mHasHorizontalScrollbar;
|
|
|
|
bool didHaveVerticalScrollbar = mHelper.mHasVerticalScrollbar;
|
|
|
|
mHelper.mHasHorizontalScrollbar = aAssumeHScroll;
|
|
|
|
mHelper.mHasVerticalScrollbar = aAssumeVScroll;
|
2010-01-14 05:00:00 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsReflowStatus status;
|
2013-10-28 19:27:50 -07:00
|
|
|
nsresult rv = ReflowChild(mHelper.mScrolledFrame, presContext, *aMetrics,
|
2007-03-22 10:30:00 -07:00
|
|
|
kidReflowState, 0, 0,
|
2012-08-17 12:04:06 -07:00
|
|
|
NS_FRAME_NO_MOVE_FRAME, status);
|
2010-01-14 05:00:00 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHasHorizontalScrollbar = didHaveHorizontalScrollbar;
|
|
|
|
mHelper.mHasVerticalScrollbar = didHaveVerticalScrollbar;
|
2010-01-14 05:00:00 -08:00
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
// Don't resize or position the view (if any) because we're going to resize
|
2007-03-22 10:30:00 -07:00
|
|
|
// it to the correct size anyway in PlaceScrollArea. Allowing it to
|
|
|
|
// resize here would size it to the natural height of the frame,
|
|
|
|
// which will usually be different from the scrollport height;
|
|
|
|
// invalidating the difference will cause unnecessary repainting.
|
2013-10-28 19:27:50 -07:00
|
|
|
FinishReflowChild(mHelper.mScrolledFrame, presContext,
|
2014-01-16 17:34:44 -08:00
|
|
|
*aMetrics, &kidReflowState, 0, 0,
|
2012-08-17 12:04:06 -07:00
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_SIZE_VIEW);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX Some frames (e.g., nsObjectFrame, nsFrameFrame, nsTextFrame) don't bother
|
|
|
|
// setting their mOverflowArea. This is wrong because every frame should
|
|
|
|
// always set mOverflowArea. In fact nsObjectFrame and nsFrameFrame don't
|
|
|
|
// support the 'outline' property because of this. Rather than fix the world
|
|
|
|
// right now, just fix up the overflow area if necessary. Note that we don't
|
2009-04-05 17:31:50 -07:00
|
|
|
// check HasOverflowRect() because it could be set even though the
|
2007-03-22 10:30:00 -07:00
|
|
|
// overflow area doesn't include the frame bounds.
|
2010-10-06 21:25:46 -07:00
|
|
|
aMetrics->UnionOverflowAreasWithDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-05 04:38:46 -08:00
|
|
|
aState->mContentsOverflowAreas = aMetrics->mOverflowAreas;
|
2007-12-04 19:05:57 -08:00
|
|
|
aState->mReflowedContentsWithHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mReflowedContentsWithVScrollbar = aAssumeVScroll;
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-02-23 02:15:59 -08:00
|
|
|
nsHTMLScrollFrame::GuessHScrollbarNeeded(const ScrollReflowState& aState)
|
|
|
|
{
|
|
|
|
if (aState.mStyles.mHorizontal != NS_STYLE_OVERFLOW_AUTO)
|
|
|
|
// no guessing required
|
|
|
|
return aState.mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL;
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
return mHelper.mHasHorizontalScrollbar;
|
2008-02-23 02:15:59 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLScrollFrame::GuessVScrollbarNeeded(const ScrollReflowState& aState)
|
|
|
|
{
|
|
|
|
if (aState.mStyles.mVertical != NS_STYLE_OVERFLOW_AUTO)
|
|
|
|
// no guessing required
|
|
|
|
return aState.mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL;
|
|
|
|
|
|
|
|
// If we've had at least one non-initial reflow, then just assume
|
|
|
|
// the state of the vertical scrollbar will be what we determined
|
|
|
|
// last time.
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHadNonInitialReflow) {
|
|
|
|
return mHelper.mHasVerticalScrollbar;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// If this is the initial reflow, guess false because usually
|
2007-03-22 10:30:00 -07:00
|
|
|
// we have very little content by then.
|
2007-04-25 19:29:21 -07:00
|
|
|
if (InInitialReflow())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mIsRoot) {
|
|
|
|
nsIFrame *f = mHelper.mScrolledFrame->GetFirstPrincipalChild();
|
2012-03-19 01:34:19 -07:00
|
|
|
if (f && f->GetType() == nsGkAtoms::svgOuterSVGFrame &&
|
|
|
|
static_cast<nsSVGOuterSVGFrame*>(f)->VerticalScrollbarNotNeeded()) {
|
|
|
|
// Common SVG case - avoid a bad guess.
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-30 09:38:42 -07:00
|
|
|
// Assume that there will be a scrollbar; it seems to me
|
2007-03-22 10:30:00 -07:00
|
|
|
// that 'most pages' do have a scrollbar, and anyway, it's cheaper
|
|
|
|
// to do an extra reflow for the pages that *don't* need a
|
|
|
|
// scrollbar (because on average they will have less content).
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For non-viewports, just guess that we don't need a scrollbar.
|
|
|
|
// XXX I wonder if statistically this is the right idea; I'm
|
|
|
|
// basically guessing that there are a lot of overflow:auto DIVs
|
|
|
|
// that get their intrinsic size and don't overflow
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-04-25 19:29:21 -07:00
|
|
|
nsHTMLScrollFrame::InInitialReflow() const
|
|
|
|
{
|
|
|
|
// We're in an initial reflow if NS_FRAME_FIRST_REFLOW is set, unless we're a
|
2007-05-01 10:15:08 -07:00
|
|
|
// root scrollframe. In that case we want to skip this clause altogether.
|
|
|
|
// The guess here is that there are lots of overflow:auto divs out there that
|
|
|
|
// end up auto-sizing so they don't overflow, and that the root basically
|
|
|
|
// always needs a scrollbar if it did last time we loaded this page (good
|
|
|
|
// assumption, because our initial reflow is no longer synchronous).
|
2013-10-28 19:27:50 -07:00
|
|
|
return !mHelper.mIsRoot && (GetStateBits() & NS_FRAME_FIRST_REFLOW);
|
2007-04-25 19:29:21 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
|
|
|
const nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2013-12-27 09:59:52 -08:00
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.GetWritingMode(), aDesiredSize.mFlags);
|
2008-02-23 02:15:59 -08:00
|
|
|
nsresult rv = ReflowScrolledFrame(aState, GuessHScrollbarNeeded(*aState),
|
2011-10-17 07:59:28 -07:00
|
|
|
GuessVScrollbarNeeded(*aState), &kidDesiredSize, true);
|
2007-12-04 19:05:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// There's an important special case ... if the child appears to fit
|
|
|
|
// in the inside-border rect (but overflows the scrollport), we
|
|
|
|
// should try laying it out without a vertical scrollbar. It will
|
|
|
|
// usually fit because making the available-width wider will not
|
|
|
|
// normally make the child taller. (The only situation I can think
|
|
|
|
// of is when you have a line containing %-width inline replaced
|
|
|
|
// elements whose percentages sum to more than 100%, so increasing
|
|
|
|
// the available width makes the line break where it was fitting
|
|
|
|
// before.) If we don't treat this case specially, then we will
|
|
|
|
// decide that showing scrollbars is OK because the content
|
|
|
|
// overflows when we're showing scrollbars and we won't try to
|
|
|
|
// remove the vertical scrollbar.
|
|
|
|
|
|
|
|
// Detecting when we enter this special case is important for when
|
|
|
|
// people design layouts that exactly fit the container "most of the
|
|
|
|
// time".
|
2007-12-04 19:05:57 -08:00
|
|
|
|
|
|
|
// XXX Is this check really sufficient to catch all the incremental cases
|
|
|
|
// where the ideal case doesn't have a scrollbar?
|
|
|
|
if ((aState->mReflowedContentsWithHScrollbar || aState->mReflowedContentsWithVScrollbar) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_SCROLL &&
|
|
|
|
aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize insideBorderSize =
|
|
|
|
ComputeInsideBorderSize(aState,
|
2013-12-27 09:59:52 -08:00
|
|
|
nsSize(kidDesiredSize.Width(), kidDesiredSize.Height()));
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect =
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.GetScrolledRectInternal(kidDesiredSize.ScrollableOverflow(),
|
2010-10-06 21:25:47 -07:00
|
|
|
insideBorderSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsRect(nsPoint(0, 0), insideBorderSize).Contains(scrolledRect)) {
|
2007-12-04 19:05:57 -08:00
|
|
|
// Let's pretend we had no scrollbars coming in here
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = ReflowScrolledFrame(aState, false, false,
|
|
|
|
&kidDesiredSize, false);
|
2007-12-04 19:05:57 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 19:05:57 -08:00
|
|
|
// Try vertical scrollbar settings that leave the vertical scrollbar unchanged.
|
|
|
|
// Do this first because changing the vertical scrollbar setting is expensive,
|
|
|
|
// forcing a reflow always.
|
|
|
|
|
2008-02-23 02:15:59 -08:00
|
|
|
// Try leaving the horizontal scrollbar unchanged first. This will be more
|
|
|
|
// efficient.
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, aState->mReflowedContentsWithHScrollbar,
|
2011-10-17 07:59:28 -07:00
|
|
|
aState->mReflowedContentsWithVScrollbar, false, &rv))
|
2007-12-01 03:49:13 -08:00
|
|
|
return NS_OK;
|
2008-02-23 02:15:59 -08:00
|
|
|
if (TryLayout(aState, &kidDesiredSize, !aState->mReflowedContentsWithHScrollbar,
|
2011-10-17 07:59:28 -07:00
|
|
|
aState->mReflowedContentsWithVScrollbar, false, &rv))
|
2007-12-01 03:49:13 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-04 19:05:57 -08:00
|
|
|
// OK, now try toggling the vertical scrollbar. The performance advantage
|
2008-02-23 02:15:59 -08:00
|
|
|
// of trying the status-quo horizontal scrollbar state
|
2007-12-04 19:05:57 -08:00
|
|
|
// does not exist here (we'll have to reflow due to the vertical scrollbar
|
|
|
|
// change), so always try no horizontal scrollbar first.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newVScrollbarState = !aState->mReflowedContentsWithVScrollbar;
|
2011-10-17 07:59:28 -07:00
|
|
|
if (TryLayout(aState, &kidDesiredSize, false, newVScrollbarState, false, &rv))
|
2007-12-04 19:05:57 -08:00
|
|
|
return NS_OK;
|
2011-10-17 07:59:28 -07:00
|
|
|
if (TryLayout(aState, &kidDesiredSize, true, newVScrollbarState, false, &rv))
|
2007-12-04 19:05:57 -08:00
|
|
|
return NS_OK;
|
2007-12-01 02:38:09 -08:00
|
|
|
|
2007-12-11 18:28:50 -08:00
|
|
|
// OK, we're out of ideas. Try again enabling whatever scrollbars we can
|
|
|
|
// enable and force the layout to stick even if it's inconsistent.
|
|
|
|
// This just happens sometimes.
|
|
|
|
TryLayout(aState, &kidDesiredSize,
|
|
|
|
aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_HIDDEN,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, &rv);
|
2007-12-04 19:05:57 -08:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 20:01:15 -07:00
|
|
|
nsHTMLScrollFrame::PlaceScrollArea(const ScrollReflowState& aState,
|
|
|
|
const nsPoint& aScrollPosition)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
nsIFrame *scrolledFrame = mHelper.mScrolledFrame;
|
2009-10-07 20:01:15 -07:00
|
|
|
// Set the x,y of the scrolled frame to the correct value
|
2013-10-28 19:27:50 -07:00
|
|
|
scrolledFrame->SetPosition(mHelper.mScrollPort.TopLeft() - aScrollPosition);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsRect scrolledArea;
|
2008-02-27 01:46:22 -08:00
|
|
|
// Preserve the width or height of empty rects
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize portSize = mHelper.mScrollPort.Size();
|
2011-12-05 04:38:46 -08:00
|
|
|
nsRect scrolledRect =
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.GetScrolledRectInternal(aState.mContentsOverflowAreas.ScrollableOverflow(),
|
2011-12-05 04:38:46 -08:00
|
|
|
portSize);
|
2011-04-18 20:07:23 -07:00
|
|
|
scrolledArea.UnionRectEdges(scrolledRect,
|
|
|
|
nsRect(nsPoint(0,0), portSize));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Store the new overflow area. Note that this changes where an outline
|
|
|
|
// of the scrolled frame would be painted, but scrolled frames can't have
|
|
|
|
// outlines (the outline would go on this scrollframe instead).
|
2009-04-05 17:31:50 -07:00
|
|
|
// Using FinishAndStoreOverflow is needed so the overflow rect
|
2007-03-22 10:30:00 -07:00
|
|
|
// gets set correctly. It also messes with the overflow rect in the
|
|
|
|
// -moz-hidden-unscrollable case, but scrolled frames can't have
|
|
|
|
// 'overflow' either.
|
|
|
|
// This needs to happen before SyncFrameViewAfterReflow so
|
2009-04-05 17:31:50 -07:00
|
|
|
// HasOverflowRect() will return the correct value.
|
2010-10-06 21:25:45 -07:00
|
|
|
nsOverflowAreas overflow(scrolledArea, scrolledArea);
|
|
|
|
scrolledFrame->FinishAndStoreOverflow(overflow,
|
2007-03-22 10:30:00 -07:00
|
|
|
scrolledFrame->GetSize());
|
|
|
|
|
|
|
|
// Note that making the view *exactly* the size of the scrolled area
|
|
|
|
// is critical, since the view scrolling code uses the size of the
|
|
|
|
// scrolled view to clamp scroll requests.
|
2009-10-07 20:01:15 -07:00
|
|
|
// Normally the scrolledFrame won't have a view but in some cases it
|
|
|
|
// might create its own.
|
2007-03-30 14:11:41 -07:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(scrolledFrame->PresContext(),
|
2007-03-22 10:30:00 -07:00
|
|
|
scrolledFrame,
|
2009-10-07 20:01:15 -07:00
|
|
|
scrolledFrame->GetView(),
|
2010-10-06 21:25:46 -07:00
|
|
|
scrolledArea,
|
2009-10-07 20:01:15 -07:00
|
|
|
0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-28 12:37:06 -08:00
|
|
|
nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsHTMLScrollFrame::GetIntrinsicVScrollbarWidth(nsRenderingContext *aRenderingContext)
|
2008-02-28 12:37:06 -08:00
|
|
|
{
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles ss = GetScrollbarStyles();
|
2013-10-28 19:27:50 -07:00
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_SCROLL || !mHelper.mVScrollbarBox)
|
2008-02-28 12:37:06 -08:00
|
|
|
return 0;
|
|
|
|
|
2008-04-09 21:39:41 -07:00
|
|
|
// Don't need to worry about reflow depth here since it's
|
|
|
|
// just for scrollbars
|
|
|
|
nsBoxLayoutState bls(PresContext(), aRenderingContext, 0);
|
2008-02-28 12:37:06 -08:00
|
|
|
nsSize vScrollbarPrefSize(0, 0);
|
2013-10-28 19:27:50 -07:00
|
|
|
GetScrollbarMetrics(bls, mHelper.mVScrollbarBox,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, &vScrollbarPrefSize, true);
|
2008-02-28 12:37:06 -08:00
|
|
|
return vScrollbarPrefSize.width;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsHTMLScrollFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
nscoord result = mHelper.mScrolledFrame->GetMinWidth(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2008-02-28 12:37:06 -08:00
|
|
|
return result + GetIntrinsicVScrollbarWidth(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsHTMLScrollFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
nscoord result = mHelper.mScrolledFrame->GetPrefWidth(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
2008-02-28 12:37:06 -08:00
|
|
|
return NSCoordSaturatingAdd(result, GetIntrinsicVScrollbarWidth(aRenderingContext));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::GetPadding(nsMargin& aMargin)
|
|
|
|
{
|
|
|
|
// Our padding hangs out on the inside of the scrollframe, but XUL doesn't
|
|
|
|
// reaize that. If we're stuck inside a XUL box, we need to claim no
|
|
|
|
// padding.
|
|
|
|
// @see also nsXULScrollFrame::GetPadding.
|
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-06-15 14:03:49 -07:00
|
|
|
nsHTMLScrollFrame::IsCollapsed()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// We're never collapsed in the box sense.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-17 06:35:32 -08:00
|
|
|
// Return the <browser> if the scrollframe is for the root frame directly
|
|
|
|
// inside a <browser>.
|
|
|
|
static nsIContent*
|
|
|
|
GetBrowserRoot(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
nsIDocument* doc = aContent->GetCurrentDoc();
|
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
nsCOMPtr<nsIContent> frameContent =
|
|
|
|
do_QueryInterface(win->GetFrameElementInternal());
|
|
|
|
if (frameContent &&
|
|
|
|
frameContent->NodeInfo()->Equals(nsGkAtoms::browser, kNameSpaceID_XUL))
|
|
|
|
return frameContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLScrollFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.HandleScrollbarStyleSwitching();
|
2013-07-16 05:58:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
ScrollReflowState state(this, aReflowState);
|
|
|
|
// sanity check: ensure that if we have no scrollbar, we treat it
|
|
|
|
// as hidden.
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mVScrollbarBox || mHelper.mNeverHasVerticalScrollbar)
|
2007-03-22 10:30:00 -07:00
|
|
|
state.mStyles.mVertical = NS_STYLE_OVERFLOW_HIDDEN;
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mHScrollbarBox || mHelper.mNeverHasHorizontalScrollbar)
|
2007-03-22 10:30:00 -07:00
|
|
|
state.mStyles.mHorizontal = NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
|
|
|
|
//------------ Handle Incremental Reflow -----------------
|
2011-09-28 23:19:26 -07:00
|
|
|
bool reflowHScrollbar = true;
|
|
|
|
bool reflowVScrollbar = true;
|
|
|
|
bool reflowScrollCorner = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aReflowState.ShouldReflowAllKids()) {
|
|
|
|
#define NEEDS_REFLOW(frame_) \
|
2007-05-06 12:16:51 -07:00
|
|
|
((frame_) && NS_SUBTREE_DIRTY(frame_))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
reflowHScrollbar = NEEDS_REFLOW(mHelper.mHScrollbarBox);
|
|
|
|
reflowVScrollbar = NEEDS_REFLOW(mHelper.mVScrollbarBox);
|
|
|
|
reflowScrollCorner = NEEDS_REFLOW(mHelper.mScrollCornerBox) ||
|
|
|
|
NEEDS_REFLOW(mHelper.mResizerBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#undef NEEDS_REFLOW
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mIsRoot) {
|
|
|
|
mHelper.mCollapsedResizer = true;
|
2011-01-17 06:35:32 -08:00
|
|
|
|
|
|
|
nsIContent* browserRoot = GetBrowserRoot(mContent);
|
|
|
|
if (browserRoot) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool showResizer = browserRoot->HasAttr(kNameSpaceID_None, nsGkAtoms::showresizer);
|
2013-10-28 19:27:50 -07:00
|
|
|
reflowScrollCorner = showResizer == mHelper.mCollapsedResizer;
|
|
|
|
mHelper.mCollapsedResizer = !showResizer;
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRect oldScrollAreaBounds = mHelper.mScrollPort;
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect oldScrolledAreaBounds =
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrolledFrame->GetScrollableOverflowRectRelativeToParent();
|
|
|
|
nsPoint oldScrollPosition = mHelper.GetScrollPosition();
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
state.mComputedBorder = aReflowState.ComputedPhysicalBorderPadding() -
|
|
|
|
aReflowState.ComputedPhysicalPadding();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = ReflowContents(&state, aDesiredSize);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2010-03-28 18:46:59 -07:00
|
|
|
|
|
|
|
// Restore the old scroll position, for now, even if that's not valid anymore
|
|
|
|
// because we changed size. We'll fix it up in a post-reflow callback, because
|
|
|
|
// our current size may only be temporary (e.g. we're compute XUL desired sizes).
|
2009-10-07 20:01:15 -07:00
|
|
|
PlaceScrollArea(state, oldScrollPosition);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mPostedReflowCallback) {
|
2009-06-23 18:35:00 -07:00
|
|
|
// Make sure we'll try scrolling to restored position
|
2013-10-28 19:27:50 -07:00
|
|
|
PresContext()->PresShell()->PostReflowCallback(&mHelper);
|
|
|
|
mHelper.mPostedReflowCallback = true;
|
2009-06-23 18:35:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
bool didHaveHScrollbar = mHelper.mHasHorizontalScrollbar;
|
|
|
|
bool didHaveVScrollbar = mHelper.mHasVerticalScrollbar;
|
|
|
|
mHelper.mHasHorizontalScrollbar = state.mShowHScrollbar;
|
|
|
|
mHelper.mHasVerticalScrollbar = state.mShowVScrollbar;
|
|
|
|
nsRect newScrollAreaBounds = mHelper.mScrollPort;
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect newScrolledAreaBounds =
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrolledFrame->GetScrollableOverflowRectRelativeToParent();
|
|
|
|
if (mHelper.mSkippedScrollbarLayout ||
|
2007-03-22 10:30:00 -07:00
|
|
|
reflowHScrollbar || reflowVScrollbar || reflowScrollCorner ||
|
|
|
|
(GetStateBits() & NS_FRAME_IS_DIRTY) ||
|
|
|
|
didHaveHScrollbar != state.mShowHScrollbar ||
|
|
|
|
didHaveVScrollbar != state.mShowVScrollbar ||
|
2011-04-18 20:07:23 -07:00
|
|
|
!oldScrollAreaBounds.IsEqualEdges(newScrollAreaBounds) ||
|
|
|
|
!oldScrolledAreaBounds.IsEqualEdges(newScrolledAreaBounds)) {
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mSupppressScrollbarUpdate) {
|
|
|
|
mHelper.mSkippedScrollbarLayout = false;
|
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mHScrollbarBox, state.mShowHScrollbar);
|
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mVScrollbarBox, state.mShowVScrollbar);
|
2007-03-22 10:30:00 -07:00
|
|
|
// place and reflow scrollbars
|
|
|
|
nsRect insideBorderArea =
|
|
|
|
nsRect(nsPoint(state.mComputedBorder.left, state.mComputedBorder.top),
|
|
|
|
state.mInsideBorderSize);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.LayoutScrollbars(state.mBoxState, insideBorderArea,
|
2009-10-07 20:01:15 -07:00
|
|
|
oldScrollAreaBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mSkippedScrollbarLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = state.mInsideBorderSize.width +
|
2007-03-22 10:30:00 -07:00
|
|
|
state.mComputedBorder.LeftRight();
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Height() = state.mInsideBorderSize.height +
|
2007-03-22 10:30:00 -07:00
|
|
|
state.mComputedBorder.TopBottom();
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.IsIgnoringViewportClipping()) {
|
2011-12-05 04:38:46 -08:00
|
|
|
aDesiredSize.mOverflowAreas.UnionWith(
|
2013-10-28 19:27:50 -07:00
|
|
|
state.mContentsOverflowAreas + mHelper.mScrolledFrame->GetPosition());
|
2011-12-05 04:38:46 -08:00
|
|
|
}
|
2009-12-13 19:40:55 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.UpdateSticky();
|
2011-05-11 16:53:34 -07:00
|
|
|
FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!InInitialReflow() && !mHelper.mHadNonInitialReflow) {
|
|
|
|
mHelper.mHadNonInitialReflow = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mIsRoot && !oldScrolledAreaBounds.IsEqualEdges(newScrolledAreaBounds)) {
|
|
|
|
mHelper.PostScrolledAreaEvent();
|
2009-09-11 16:13:56 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.PostOverflowEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:13:56 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLScroll"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
a11y::AccType
|
|
|
|
nsHTMLScrollFrame::AccessibleType()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-17 09:51:29 -08:00
|
|
|
// Create an accessible regardless of focusable state because the state can be
|
2012-02-17 09:38:43 -08:00
|
|
|
// changed during frame life cycle without any notifications to accessibility.
|
|
|
|
if (mContent->IsRootOfNativeAnonymousSubtree() ||
|
2013-08-23 13:20:07 -07:00
|
|
|
GetScrollbarStyles() ==
|
2012-02-17 09:38:43 -08:00
|
|
|
ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN) ) {
|
2012-12-12 02:04:12 -08:00
|
|
|
return a11y::eNoType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-17 09:38:43 -08:00
|
|
|
|
2012-12-17 17:25:52 -08:00
|
|
|
return a11y::eHyperTextType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsHTMLScrollFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2013-05-02 07:58:00 -07:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollbarOwner)
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
2011-12-27 12:18:48 -08:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------nsXULScrollFrame-------------------------------------------
|
|
|
|
|
|
|
|
nsIFrame*
|
2013-06-16 22:16:27 -07:00
|
|
|
NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
|
|
|
|
bool aIsRoot, bool aClipAllDescendants)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-16 22:16:27 -07:00
|
|
|
return new (aPresShell) nsXULScrollFrame(aPresShell, aContext, aIsRoot,
|
|
|
|
aClipAllDescendants);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsXULScrollFrame)
|
|
|
|
|
2013-06-16 22:16:27 -07:00
|
|
|
nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext,
|
|
|
|
bool aIsRoot, bool aClipAllDescendants)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsBoxFrame(aShell, aContext, aIsRoot),
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper(ALLOW_THIS_IN_INITIALIZER_LIST(this), aIsRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-04 12:57:01 -08:00
|
|
|
SetLayoutManager(nullptr);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mClipAllDescendants = aClipAllDescendants;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-16 14:17:40 -07:00
|
|
|
void
|
|
|
|
nsXULScrollFrame::ScrollbarActivityStarted() const
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mScrollbarActivity) {
|
|
|
|
mHelper.mScrollbarActivity->ActivityStarted();
|
2013-08-16 14:17:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULScrollFrame::ScrollbarActivityStopped() const
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mScrollbarActivity) {
|
|
|
|
mHelper.mScrollbarActivity->ActivityStopped();
|
2013-08-16 14:17:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 12:57:01 -08:00
|
|
|
nsMargin
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetDesiredScrollbarSizes(nsBoxLayoutState* aState)
|
2013-03-04 12:57:01 -08:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aState && aState->GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin result(0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (mVScrollbarBox) {
|
|
|
|
nsSize size = mVScrollbarBox->GetPrefSize(*aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mVScrollbarBox, size);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (IsScrollbarOnRight())
|
|
|
|
result.left = size.width;
|
|
|
|
else
|
|
|
|
result.right = size.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHScrollbarBox) {
|
|
|
|
nsSize size = mHScrollbarBox->GetPrefSize(*aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mHScrollbarBox, size);
|
2007-03-22 10:30:00 -07:00
|
|
|
// We don't currently support any scripts that would require a scrollbar
|
|
|
|
// at the top. (Are there any?)
|
|
|
|
result.bottom = size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-26 15:05:10 -07:00
|
|
|
nscoord
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetNondisappearingScrollbarWidth(nsBoxLayoutState* aState)
|
2013-05-26 15:05:10 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aState && aState->GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
|
|
|
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
|
|
|
|
// We're using overlay scrollbars, so we need to get the width that
|
|
|
|
// non-disappearing scrollbars would have.
|
|
|
|
nsITheme* theme = aState->PresContext()->GetTheme();
|
|
|
|
if (theme &&
|
|
|
|
theme->ThemeSupportsWidget(aState->PresContext(),
|
|
|
|
mVScrollbarBox,
|
|
|
|
NS_THEME_SCROLLBAR_NON_DISAPPEARING)) {
|
|
|
|
nsIntSize size;
|
|
|
|
nsRenderingContext* rendContext = aState->GetRenderingContext();
|
|
|
|
if (rendContext) {
|
|
|
|
bool canOverride = true;
|
|
|
|
theme->GetMinimumWidgetSize(rendContext,
|
|
|
|
mVScrollbarBox,
|
|
|
|
NS_THEME_SCROLLBAR_NON_DISAPPEARING,
|
|
|
|
&size,
|
|
|
|
&canOverride);
|
|
|
|
if (size.width) {
|
|
|
|
return aState->PresContext()->DevPixelsToAppUnits(size.width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetDesiredScrollbarSizes(aState).LeftRight();
|
|
|
|
}
|
|
|
|
|
2013-07-16 05:58:44 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::HandleScrollbarStyleSwitching()
|
2013-07-16 05:58:44 -07:00
|
|
|
{
|
|
|
|
// Check if we switched between scrollbar styles.
|
|
|
|
if (mScrollbarActivity &&
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) == 0) {
|
|
|
|
mScrollbarActivity->Destroy();
|
|
|
|
mScrollbarActivity = nullptr;
|
|
|
|
mOuter->PresContext()->ThemeChanged();
|
|
|
|
}
|
|
|
|
else if (!mScrollbarActivity &&
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
|
|
|
|
mScrollbarActivity = new ScrollbarActivity(do_QueryFrame(mOuter));
|
|
|
|
mOuter->PresContext()->ThemeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2011-05-06 13:04:44 -07:00
|
|
|
nsXULScrollFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
return mHelper.CreateAnonymousContent(aElements);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2010-10-15 08:34:35 -07:00
|
|
|
nsXULScrollFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFilter)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.AppendAnonymousContentTo(aElements, aFilter);
|
2010-02-11 09:34:01 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsXULScrollFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.Destroy();
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsXULScrollFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsresult rv = nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsXULScrollFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsresult rv = nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsXULScrollFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsresult rv = nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsXULScrollFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsresult rv = nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.ReloadChildFrames();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplittableType
|
|
|
|
nsXULScrollFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::GetPadding(nsMargin& aMargin)
|
|
|
|
{
|
2013-03-04 12:57:01 -08:00
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsXULScrollFrame::GetType() const
|
|
|
|
{
|
2013-03-04 12:57:01 -08:00
|
|
|
return nsGkAtoms::scrollFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsXULScrollFrame::GetBoxAscent(nsBoxLayoutState& aState)
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mScrolledFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nscoord ascent = mHelper.mScrolledFrame->GetBoxAscent(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin m(0,0,0,0);
|
|
|
|
GetBorderAndPadding(m);
|
|
|
|
ascent += m.top;
|
|
|
|
GetMargin(m);
|
|
|
|
ascent += m.top;
|
|
|
|
|
|
|
|
return ascent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetPrefSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aState);
|
|
|
|
#endif
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize pref = mHelper.mScrolledFrame->GetPrefSize(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles styles = GetScrollbarStyles();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// scrolled frames don't have their own margins
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mVScrollbarBox &&
|
2007-03-22 10:30:00 -07:00
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize vSize = mHelper.mVScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mHelper.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
pref.width += vSize.width;
|
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHScrollbarBox &&
|
2007-03-22 10:30:00 -07:00
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize hSize = mHelper.mHScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mHelper.mHScrollbarBox, hSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
pref.height += hSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddBorderAndPadding(pref);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSPrefSize(this, pref, widthSet, heightSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
return pref;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aState);
|
|
|
|
#endif
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize min = mHelper.mScrolledFrame->GetMinSizeForScrollArea(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles styles = GetScrollbarStyles();
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mVScrollbarBox &&
|
2007-03-22 10:30:00 -07:00
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize vSize = mHelper.mVScrollbarBox->GetMinSize(aState);
|
|
|
|
AddMargin(mHelper.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
min.width += vSize.width;
|
|
|
|
if (min.height < vSize.height)
|
|
|
|
min.height = vSize.height;
|
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHScrollbarBox &&
|
2007-03-22 10:30:00 -07:00
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize hSize = mHelper.mHScrollbarBox->GetMinSize(aState);
|
|
|
|
AddMargin(mHelper.mHScrollbarBox, hSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
min.height += hSize.height;
|
|
|
|
if (min.width < hSize.width)
|
|
|
|
min.width = hSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddBorderAndPadding(min);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSMinSize(aState, this, min, widthSet, heightSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetMaxSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
PropagateDebug(aState);
|
|
|
|
#endif
|
|
|
|
|
2008-02-26 17:51:57 -08:00
|
|
|
nsSize maxSize(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-26 17:51:57 -08:00
|
|
|
AddBorderAndPadding(maxSize);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSMaxSize(this, maxSize, widthSet, heightSet);
|
2008-02-26 17:51:57 -08:00
|
|
|
return maxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("XULScroll"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = aState.LayoutFlags();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = Layout(aState);
|
|
|
|
aState.SetLayoutFlags(flags);
|
|
|
|
|
|
|
|
nsBox::DoLayout(aState);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsXULScrollFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2013-05-02 07:58:00 -07:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollbarOwner)
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
//-------------------- Helper ----------------------
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
#define SMOOTH_SCROLL_PREF_NAME "general.smoothScroll"
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
const double kCurrentVelocityWeighting = 0.25;
|
|
|
|
const double kStopDecelerationWeighting = 0.4;
|
|
|
|
|
2012-03-31 06:08:00 -07:00
|
|
|
// AsyncScroll has ref counting.
|
2013-10-28 19:27:50 -07:00
|
|
|
class ScrollFrameHelper::AsyncScroll MOZ_FINAL : public nsARefreshObserver {
|
2009-10-07 20:01:15 -07:00
|
|
|
public:
|
2011-03-25 21:30:19 -07:00
|
|
|
typedef mozilla::TimeStamp TimeStamp;
|
|
|
|
typedef mozilla::TimeDuration TimeDuration;
|
|
|
|
|
2013-04-17 17:03:29 -07:00
|
|
|
AsyncScroll(nsPoint aStartPos)
|
2012-03-31 06:08:00 -07:00
|
|
|
: mIsFirstIteration(true)
|
2013-04-17 17:03:29 -07:00
|
|
|
, mStartPos(aStartPos)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mCallee(nullptr)
|
2012-03-31 06:08:00 -07:00
|
|
|
{}
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
~AsyncScroll() {
|
2012-03-31 06:08:00 -07:00
|
|
|
RemoveObserver();
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
nsPoint PositionAt(TimeStamp aTime);
|
|
|
|
nsSize VelocityAt(TimeStamp aTime); // In nscoords per second
|
|
|
|
|
2013-04-17 17:03:29 -07:00
|
|
|
void InitSmoothScroll(TimeStamp aTime, nsPoint aDestination,
|
2012-02-07 16:53:18 -08:00
|
|
|
nsIAtom *aOrigin, const nsRect& aRange);
|
|
|
|
void Init(const nsRect& aRange) {
|
|
|
|
mRange = aRange;
|
|
|
|
}
|
2011-03-25 21:30:19 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsFinished(TimeStamp aTime) {
|
2011-03-25 21:30:19 -07:00
|
|
|
return aTime > mStartTime + mDuration; // XXX or if we've hit the wall
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp mStartTime;
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2013-04-17 17:03:51 -07:00
|
|
|
// mPrevEventTime holds previous 3 timestamps for intervals averaging (to
|
2012-03-11 13:55:00 -07:00
|
|
|
// reduce duration fluctuations). When AsyncScroll is constructed and no
|
|
|
|
// previous timestamps are available (indicated with mIsFirstIteration),
|
2013-04-17 17:03:51 -07:00
|
|
|
// initialize mPrevEventTime using imaginary previous timestamps with maximum
|
2012-03-11 13:55:00 -07:00
|
|
|
// relevant intervals between them.
|
2013-04-17 17:03:51 -07:00
|
|
|
TimeStamp mPrevEventTime[3];
|
2012-03-11 13:55:00 -07:00
|
|
|
bool mIsFirstIteration;
|
|
|
|
|
|
|
|
// Cached Preferences values to avoid re-reading them when extending an existing
|
2013-03-04 12:57:01 -08:00
|
|
|
// animation for the same event origin (can be as frequent as every 10(!)ms for
|
2012-03-26 02:53:45 -07:00
|
|
|
// a quick roll of the mouse wheel).
|
|
|
|
// These values are minimum and maximum animation duration per event origin,
|
|
|
|
// and a global ratio which defines how longer is the animation's duration
|
|
|
|
// compared to the average recent events intervals (such that for a relatively
|
|
|
|
// consistent events rate, the next event arrives before current animation ends)
|
|
|
|
nsCOMPtr<nsIAtom> mOrigin;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mOriginMinMS;
|
|
|
|
int32_t mOriginMaxMS;
|
2012-03-11 13:55:00 -07:00
|
|
|
double mIntervalRatio;
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
TimeDuration mDuration;
|
|
|
|
nsPoint mStartPos;
|
|
|
|
nsPoint mDestination;
|
2012-02-07 16:53:18 -08:00
|
|
|
// Allowed destination positions around mDestination
|
|
|
|
nsRect mRange;
|
2011-03-25 21:30:19 -07:00
|
|
|
nsSMILKeySpline mTimingFunctionX;
|
|
|
|
nsSMILKeySpline mTimingFunctionY;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsSmoothScroll;
|
2011-03-25 21:30:19 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
double ProgressAt(TimeStamp aTime) {
|
2011-10-28 11:33:28 -07:00
|
|
|
return clamped((aTime - mStartTime) / mDuration, 0.0, 1.0);
|
2011-03-25 21:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord VelocityComponent(double aTimeProgress,
|
|
|
|
nsSMILKeySpline& aTimingFunction,
|
|
|
|
nscoord aStart, nscoord aDestination);
|
|
|
|
|
|
|
|
// Initializes the timing function in such a way that the current velocity is
|
|
|
|
// preserved.
|
|
|
|
void InitTimingFunction(nsSMILKeySpline& aTimingFunction,
|
|
|
|
nscoord aCurrentPos, nscoord aCurrentVelocity,
|
|
|
|
nscoord aDestination);
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2013-04-17 17:03:51 -07:00
|
|
|
TimeDuration CalcDurationForEventTime(TimeStamp aTime, nsIAtom *aOrigin);
|
2012-03-31 06:08:00 -07:00
|
|
|
|
|
|
|
// The next section is observer/callback management
|
2013-10-28 19:27:50 -07:00
|
|
|
// Bodies of WillRefresh and RefreshDriver contain ScrollFrameHelper specific code.
|
2012-03-31 06:08:00 -07:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(AsyncScroll)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a refresh observer for smooth scroll iterations (and start observing).
|
|
|
|
* Should be used at most once during the lifetime of this object.
|
|
|
|
* Return value: true on success, false otherwise.
|
|
|
|
*/
|
2013-10-28 19:27:50 -07:00
|
|
|
bool SetRefreshObserver(ScrollFrameHelper *aCallee) {
|
2012-03-31 06:08:00 -07:00
|
|
|
NS_ASSERTION(aCallee && !mCallee, "AsyncScroll::SetRefreshObserver - Invalid usage.");
|
|
|
|
|
2012-09-05 03:29:15 -07:00
|
|
|
if (!RefreshDriver(aCallee)->AddRefreshObserver(this, Flush_Style)) {
|
2012-03-31 06:08:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCallee = aCallee;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) {
|
|
|
|
// The callback may release "this".
|
|
|
|
// We don't access members after returning, so no need for KungFuDeathGrip.
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScrollCallback(mCallee, aTime);
|
2012-03-31 06:08:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper *mCallee;
|
2012-03-31 06:08:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRefreshDriver* RefreshDriver(ScrollFrameHelper* aCallee) {
|
2012-03-31 06:08:00 -07:00
|
|
|
return aCallee->mOuter->PresContext()->RefreshDriver();
|
|
|
|
}
|
|
|
|
|
2013-03-04 12:57:01 -08:00
|
|
|
/*
|
2012-03-31 06:08:00 -07:00
|
|
|
* The refresh driver doesn't hold a reference to its observers,
|
|
|
|
* so releasing this object can (and is) used to remove the observer on DTOR.
|
|
|
|
* Currently, this object is released once the scrolling ends.
|
|
|
|
*/
|
|
|
|
void RemoveObserver() {
|
|
|
|
if (mCallee) {
|
2012-09-05 03:29:15 -07:00
|
|
|
RefreshDriver(mCallee)->RemoveRefreshObserver(this, Flush_Style);
|
2012-03-31 06:08:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
};
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
nsPoint
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScroll::PositionAt(TimeStamp aTime) {
|
2011-03-25 21:30:19 -07:00
|
|
|
double progressX = mTimingFunctionX.GetSplineValue(ProgressAt(aTime));
|
|
|
|
double progressY = mTimingFunctionY.GetSplineValue(ProgressAt(aTime));
|
2012-05-22 02:55:15 -07:00
|
|
|
return nsPoint(NSToCoordRound((1 - progressX) * mStartPos.x + progressX * mDestination.x),
|
|
|
|
NSToCoordRound((1 - progressY) * mStartPos.y + progressY * mDestination.y));
|
2011-03-25 21:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScroll::VelocityAt(TimeStamp aTime) {
|
2011-03-25 21:30:19 -07:00
|
|
|
double timeProgress = ProgressAt(aTime);
|
|
|
|
return nsSize(VelocityComponent(timeProgress, mTimingFunctionX,
|
|
|
|
mStartPos.x, mDestination.x),
|
|
|
|
VelocityComponent(timeProgress, mTimingFunctionY,
|
|
|
|
mStartPos.y, mDestination.y));
|
|
|
|
}
|
|
|
|
|
2012-03-11 13:55:00 -07:00
|
|
|
/*
|
2013-04-17 17:03:51 -07:00
|
|
|
* Calculate duration, possibly dynamically according to events rate and event origin.
|
2012-03-11 13:55:00 -07:00
|
|
|
* (also maintain previous timestamps - which are only used here).
|
|
|
|
*/
|
2013-04-17 17:03:51 -07:00
|
|
|
TimeDuration
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::
|
2013-04-17 17:03:51 -07:00
|
|
|
AsyncScroll::CalcDurationForEventTime(TimeStamp aTime, nsIAtom *aOrigin) {
|
2012-03-26 02:53:45 -07:00
|
|
|
if (!aOrigin){
|
|
|
|
aOrigin = nsGkAtoms::other;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read preferences only on first iteration or for a different event origin.
|
|
|
|
if (mIsFirstIteration || aOrigin != mOrigin) {
|
|
|
|
mOrigin = aOrigin;
|
|
|
|
mOriginMinMS = mOriginMaxMS = 0;
|
|
|
|
bool isOriginSmoothnessEnabled = false;
|
2012-03-11 13:55:00 -07:00
|
|
|
mIntervalRatio = 1;
|
|
|
|
|
|
|
|
// Default values for all preferences are defined in all.js
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t kDefaultMinMS = 150, kDefaultMaxMS = 150;
|
2012-03-26 02:53:45 -07:00
|
|
|
static const bool kDefaultIsSmoothEnabled = true;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString originName;
|
2012-03-26 02:53:45 -07:00
|
|
|
aOrigin->ToUTF8String(originName);
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefBase = NS_LITERAL_CSTRING("general.smoothScroll.") + originName;
|
2012-03-26 02:53:45 -07:00
|
|
|
|
|
|
|
isOriginSmoothnessEnabled = Preferences::GetBool(prefBase.get(), kDefaultIsSmoothEnabled);
|
|
|
|
if (isOriginSmoothnessEnabled) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefMin = prefBase + NS_LITERAL_CSTRING(".durationMinMS");
|
|
|
|
nsAutoCString prefMax = prefBase + NS_LITERAL_CSTRING(".durationMaxMS");
|
2012-03-26 02:53:45 -07:00
|
|
|
mOriginMinMS = Preferences::GetInt(prefMin.get(), kDefaultMinMS);
|
|
|
|
mOriginMaxMS = Preferences::GetInt(prefMax.get(), kDefaultMaxMS);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t kSmoothScrollMaxAllowedAnimationDurationMS = 10000;
|
2012-03-26 02:53:45 -07:00
|
|
|
mOriginMaxMS = clamped(mOriginMaxMS, 0, kSmoothScrollMaxAllowedAnimationDurationMS);
|
|
|
|
mOriginMinMS = clamped(mOriginMinMS, 0, mOriginMaxMS);
|
|
|
|
}
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2012-03-26 02:53:45 -07:00
|
|
|
// Keep the animation duration longer than the average event intervals
|
|
|
|
// (to "connect" consecutive scroll animations before the scroll comes to a stop).
|
|
|
|
static const double kDefaultDurationToIntervalRatio = 2; // Duplicated at all.js
|
|
|
|
mIntervalRatio = Preferences::GetInt("general.smoothScroll.durationToIntervalRatio",
|
|
|
|
kDefaultDurationToIntervalRatio * 100) / 100.0;
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2012-03-26 02:53:45 -07:00
|
|
|
// Duration should be at least as long as the intervals -> ratio is at least 1
|
2013-01-15 04:22:03 -08:00
|
|
|
mIntervalRatio = std::max(1.0, mIntervalRatio);
|
2012-03-11 13:55:00 -07:00
|
|
|
|
|
|
|
if (mIsFirstIteration) {
|
|
|
|
// Starting a new scroll (i.e. not when extending an existing scroll animation),
|
|
|
|
// create imaginary prev timestamps with maximum relevant intervals between them.
|
|
|
|
|
|
|
|
// Longest relevant interval (which results in maximum duration)
|
2012-03-26 02:53:45 -07:00
|
|
|
TimeDuration maxDelta = TimeDuration::FromMilliseconds(mOriginMaxMS / mIntervalRatio);
|
2013-04-17 17:03:51 -07:00
|
|
|
mPrevEventTime[0] = aTime - maxDelta;
|
|
|
|
mPrevEventTime[1] = mPrevEventTime[0] - maxDelta;
|
|
|
|
mPrevEventTime[2] = mPrevEventTime[1] - maxDelta;
|
2012-03-11 13:55:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Average last 3 delta durations (rounding errors up to 2ms are negligible for us)
|
2013-04-17 17:03:51 -07:00
|
|
|
int32_t eventsDeltaMs = (aTime - mPrevEventTime[2]).ToMilliseconds() / 3;
|
|
|
|
mPrevEventTime[2] = mPrevEventTime[1];
|
|
|
|
mPrevEventTime[1] = mPrevEventTime[0];
|
|
|
|
mPrevEventTime[0] = aTime;
|
2012-03-11 13:55:00 -07:00
|
|
|
|
|
|
|
// Modulate duration according to events rate (quicker events -> shorter durations).
|
|
|
|
// The desired effect is to use longer duration when scrolling slowly, such that
|
|
|
|
// it's easier to follow, but reduce the duration to make it feel more snappy when
|
|
|
|
// scrolling quickly. To reduce fluctuations of the duration, we average event
|
|
|
|
// intervals using the recent 4 timestamps (now + three prev -> 3 intervals).
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t durationMS = clamped<int32_t>(eventsDeltaMs * mIntervalRatio, mOriginMinMS, mOriginMaxMS);
|
2012-03-11 13:55:00 -07:00
|
|
|
|
2013-04-17 17:03:51 -07:00
|
|
|
return TimeDuration::FromMilliseconds(durationMS);
|
2012-03-11 13:55:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScroll::InitSmoothScroll(TimeStamp aTime,
|
2012-03-11 13:55:00 -07:00
|
|
|
nsPoint aDestination,
|
2012-02-07 16:53:18 -08:00
|
|
|
nsIAtom *aOrigin,
|
|
|
|
const nsRect& aRange) {
|
2013-04-17 17:05:10 -07:00
|
|
|
mRange = aRange;
|
|
|
|
TimeDuration duration = CalcDurationForEventTime(aTime, aOrigin);
|
2013-04-17 17:03:29 -07:00
|
|
|
nsSize currentVelocity(0, 0);
|
|
|
|
if (!mIsFirstIteration) {
|
2013-04-17 17:05:10 -07:00
|
|
|
// If an additional event has not changed the destination, then do not let
|
|
|
|
// another minimum duration reset slow things down. If it would then
|
|
|
|
// instead continue with the existing timing function.
|
|
|
|
if (aDestination == mDestination &&
|
|
|
|
aTime + duration > mStartTime + mDuration)
|
|
|
|
return;
|
|
|
|
|
2013-04-17 17:03:29 -07:00
|
|
|
currentVelocity = VelocityAt(aTime);
|
|
|
|
mStartPos = PositionAt(aTime);
|
|
|
|
}
|
2011-03-25 21:30:19 -07:00
|
|
|
mStartTime = aTime;
|
2013-04-17 17:05:10 -07:00
|
|
|
mDuration = duration;
|
2011-03-25 21:30:19 -07:00
|
|
|
mDestination = aDestination;
|
2013-04-17 17:03:29 -07:00
|
|
|
InitTimingFunction(mTimingFunctionX, mStartPos.x, currentVelocity.width,
|
|
|
|
aDestination.x);
|
|
|
|
InitTimingFunction(mTimingFunctionY, mStartPos.y, currentVelocity.height,
|
|
|
|
aDestination.y);
|
|
|
|
mIsFirstIteration = false;
|
2011-03-25 21:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nscoord
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScroll::VelocityComponent(double aTimeProgress,
|
2011-03-25 21:30:19 -07:00
|
|
|
nsSMILKeySpline& aTimingFunction,
|
|
|
|
nscoord aStart,
|
|
|
|
nscoord aDestination)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2011-03-25 21:30:19 -07:00
|
|
|
double dt, dxy;
|
|
|
|
aTimingFunction.GetSplineDerivativeValues(aTimeProgress, dt, dxy);
|
|
|
|
if (dt == 0)
|
|
|
|
return dxy >= 0 ? nscoord_MAX : nscoord_MIN;
|
|
|
|
|
|
|
|
const TimeDuration oneSecond = TimeDuration::FromSeconds(1);
|
|
|
|
double slope = dxy / dt;
|
2012-05-22 02:55:15 -07:00
|
|
|
return NSToCoordRound(slope * (aDestination - aStart) / (mDuration / oneSecond));
|
2011-03-25 21:30:19 -07:00
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScroll::InitTimingFunction(nsSMILKeySpline& aTimingFunction,
|
2011-03-25 21:30:19 -07:00
|
|
|
nscoord aCurrentPos,
|
|
|
|
nscoord aCurrentVelocity,
|
|
|
|
nscoord aDestination)
|
|
|
|
{
|
|
|
|
if (aDestination == aCurrentPos || kCurrentVelocityWeighting == 0) {
|
|
|
|
aTimingFunction.Init(0, 0, 1 - kStopDecelerationWeighting, 1);
|
|
|
|
return;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
2011-03-25 21:30:19 -07:00
|
|
|
|
|
|
|
const TimeDuration oneSecond = TimeDuration::FromSeconds(1);
|
|
|
|
double slope = aCurrentVelocity * (mDuration / oneSecond) / (aDestination - aCurrentPos);
|
|
|
|
double normalization = sqrt(1.0 + slope * slope);
|
|
|
|
double dt = 1.0 / normalization * kCurrentVelocityWeighting;
|
|
|
|
double dxy = slope / normalization * kCurrentVelocityWeighting;
|
|
|
|
aTimingFunction.Init(dt, dxy, 1 - kStopDecelerationWeighting, 1);
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2009-10-07 20:01:15 -07:00
|
|
|
IsSmoothScrollingEnabled()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
return Preferences::GetBool(SMOOTH_SCROLL_PREF_NAME, false);
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
class ScrollFrameActivityTracker MOZ_FINAL : public nsExpirationTracker<ScrollFrameHelper,4> {
|
2010-07-15 14:08:05 -07:00
|
|
|
public:
|
2010-09-02 02:18:39 -07:00
|
|
|
// Wait for 3-4s between scrolls before we remove our layers.
|
|
|
|
// That's 4 generations of 1s each.
|
|
|
|
enum { TIMEOUT_MS = 1000 };
|
2010-07-15 14:08:05 -07:00
|
|
|
ScrollFrameActivityTracker()
|
2013-10-28 19:27:50 -07:00
|
|
|
: nsExpirationTracker<ScrollFrameHelper,4>(TIMEOUT_MS) {}
|
2010-07-15 14:08:05 -07:00
|
|
|
~ScrollFrameActivityTracker() {
|
|
|
|
AgeAllGenerations();
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
virtual void NotifyExpired(ScrollFrameHelper *aObject) {
|
2010-07-15 14:08:05 -07:00
|
|
|
RemoveObject(aObject);
|
2011-01-04 00:46:59 -08:00
|
|
|
aObject->MarkInactive();
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
static ScrollFrameActivityTracker *gScrollFrameActivityTracker = nullptr;
|
2010-07-15 14:08:05 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollFrameHelper(nsContainerFrame* aOuter,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsRoot)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mHScrollbarBox(nullptr)
|
|
|
|
, mVScrollbarBox(nullptr)
|
|
|
|
, mScrolledFrame(nullptr)
|
|
|
|
, mScrollCornerBox(nullptr)
|
|
|
|
, mResizerBox(nullptr)
|
2011-03-09 13:35:27 -08:00
|
|
|
, mOuter(aOuter)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mAsyncScroll(nullptr)
|
2013-12-16 09:04:45 -08:00
|
|
|
, mOriginOfLastScroll(nullptr)
|
2011-03-09 13:35:27 -08:00
|
|
|
, mDestination(0, 0)
|
|
|
|
, mScrollPosAtLastPaint(0, 0)
|
|
|
|
, mRestorePos(-1, -1)
|
|
|
|
, mLastPos(-1, -1)
|
2012-08-16 16:40:10 -07:00
|
|
|
, mScrollPosForLayerPixelAlignment(-1, -1)
|
2013-02-24 16:59:21 -08:00
|
|
|
, mLastUpdateImagesPos(-1, -1)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mNeverHasVerticalScrollbar(false)
|
|
|
|
, mNeverHasHorizontalScrollbar(false)
|
|
|
|
, mHasVerticalScrollbar(false)
|
|
|
|
, mHasHorizontalScrollbar(false)
|
|
|
|
, mFrameIsUpdatingScrollbar(false)
|
|
|
|
, mDidHistoryRestore(false)
|
2011-03-09 13:35:27 -08:00
|
|
|
, mIsRoot(aIsRoot)
|
2013-06-16 22:16:27 -07:00
|
|
|
, mClipAllDescendants(aIsRoot)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mSupppressScrollbarUpdate(false)
|
|
|
|
, mSkippedScrollbarLayout(false)
|
|
|
|
, mHadNonInitialReflow(false)
|
|
|
|
, mHorizontalOverflow(false)
|
|
|
|
, mVerticalOverflow(false)
|
|
|
|
, mPostedReflowCallback(false)
|
|
|
|
, mMayHaveDirtyFixedChildren(false)
|
|
|
|
, mUpdateScrollbarAttributes(false)
|
|
|
|
, mCollapsedResizer(false)
|
2013-11-01 20:47:21 -07:00
|
|
|
, mShouldBuildScrollableLayer(false)
|
2012-11-13 22:26:33 -08:00
|
|
|
, mHasBeenScrolled(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-01-04 00:46:56 -08:00
|
|
|
mScrollingActive = IsAlwaysActive();
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
|
2012-08-03 03:35:14 -07:00
|
|
|
mScrollbarActivity = new ScrollbarActivity(do_QueryFrame(aOuter));
|
|
|
|
}
|
2013-09-14 17:05:04 -07:00
|
|
|
|
|
|
|
EnsureImageVisPrefsCached();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::~ScrollFrameHelper()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-15 14:08:05 -07:00
|
|
|
if (mActivityExpirationState.IsTracked()) {
|
|
|
|
gScrollFrameActivityTracker->RemoveObject(this);
|
|
|
|
}
|
|
|
|
if (gScrollFrameActivityTracker &&
|
|
|
|
gScrollFrameActivityTracker->IsEmpty()) {
|
|
|
|
delete gScrollFrameActivityTracker;
|
2012-07-30 07:20:58 -07:00
|
|
|
gScrollFrameActivityTracker = nullptr;
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
2012-01-18 20:13:02 -08:00
|
|
|
|
|
|
|
if (mScrollActivityTimer) {
|
|
|
|
mScrollActivityTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mScrollActivityTimer = nullptr;
|
2012-01-18 20:13:02 -08:00
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-10-28 19:27:50 -07:00
|
|
|
* Callback function from AsyncScroll, used in ScrollFrameHelper::ScrollTo
|
2009-10-07 20:01:15 -07:00
|
|
|
*/
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScrollCallback(void* anInstance, mozilla::TimeStamp aTime)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper* self = static_cast<ScrollFrameHelper*>(anInstance);
|
2009-10-07 20:01:15 -07:00
|
|
|
if (!self || !self->mAsyncScroll)
|
|
|
|
return;
|
|
|
|
|
2012-05-22 02:55:15 -07:00
|
|
|
nsRect range = self->mAsyncScroll->mRange;
|
2009-10-07 20:01:15 -07:00
|
|
|
if (self->mAsyncScroll->mIsSmoothScroll) {
|
2012-02-07 16:53:18 -08:00
|
|
|
if (!self->mAsyncScroll->IsFinished(aTime)) {
|
|
|
|
nsPoint destination = self->mAsyncScroll->PositionAt(aTime);
|
2013-06-09 17:37:16 -07:00
|
|
|
// Allow this scroll operation to land on any pixel boundary between the
|
|
|
|
// current position and the final allowed range. (We don't want
|
|
|
|
// intermediate steps to be more constrained than the final step!)
|
|
|
|
nsRect intermediateRange =
|
|
|
|
nsRect(self->GetScrollPosition(), nsSize()).UnionEdges(range);
|
|
|
|
self->ScrollToImpl(destination, intermediateRange);
|
2013-08-08 15:04:59 -07:00
|
|
|
// 'self' might be destroyed here
|
2012-02-07 16:53:18 -08:00
|
|
|
return;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 16:53:18 -08:00
|
|
|
|
|
|
|
// Apply desired destination range since this is the last step of scrolling.
|
2012-07-30 07:20:58 -07:00
|
|
|
self->mAsyncScroll = nullptr;
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(self->mOuter);
|
2012-02-07 16:53:18 -08:00
|
|
|
self->ScrollToImpl(self->mDestination, range);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-22 09:24:06 -07:00
|
|
|
// We are done scrolling, set our destination to wherever we actually ended
|
|
|
|
// up scrolling to.
|
|
|
|
self->mDestination = self->GetScrollPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2012-05-14 22:58:09 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollToCSSPixels(const CSSIntPoint& aScrollPosition)
|
2012-05-14 22:58:09 -07:00
|
|
|
{
|
|
|
|
nsPoint current = GetScrollPosition();
|
2013-07-10 02:58:13 -07:00
|
|
|
CSSIntPoint currentCSSPixels = GetScrollPositionCSSPixels();
|
2013-07-01 00:14:36 -07:00
|
|
|
nsPoint pt = CSSPoint::ToAppUnits(aScrollPosition);
|
2012-05-14 22:58:09 -07:00
|
|
|
nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f);
|
|
|
|
nsRect range(pt.x - halfPixel, pt.y - halfPixel, 2*halfPixel - 1, 2*halfPixel - 1);
|
2012-11-22 17:25:23 -08:00
|
|
|
// XXX I don't think the following blocks are needed anymore, now that
|
|
|
|
// ScrollToImpl simply tries to scroll an integer number of layer
|
|
|
|
// pixels from the current position
|
2012-08-10 04:17:06 -07:00
|
|
|
if (currentCSSPixels.x == aScrollPosition.x) {
|
2012-05-14 22:58:09 -07:00
|
|
|
pt.x = current.x;
|
|
|
|
range.x = pt.x;
|
|
|
|
range.width = 0;
|
|
|
|
}
|
2012-08-10 04:17:06 -07:00
|
|
|
if (currentCSSPixels.y == aScrollPosition.y) {
|
2012-05-14 22:58:09 -07:00
|
|
|
pt.y = current.y;
|
|
|
|
range.y = pt.y;
|
|
|
|
range.height = 0;
|
|
|
|
}
|
|
|
|
ScrollTo(pt, nsIScrollableFrame::INSTANT, &range);
|
2013-08-08 15:04:59 -07:00
|
|
|
// 'this' might be destroyed here
|
2012-05-14 22:58:09 -07:00
|
|
|
}
|
|
|
|
|
2012-11-22 17:25:23 -08:00
|
|
|
void
|
2013-12-16 09:04:45 -08:00
|
|
|
ScrollFrameHelper::ScrollToCSSPixelsApproximate(const CSSPoint& aScrollPosition,
|
|
|
|
nsIAtom *aOrigin)
|
2012-11-22 17:25:23 -08:00
|
|
|
{
|
2013-05-30 18:30:13 -07:00
|
|
|
nsPoint pt = CSSPoint::ToAppUnits(aScrollPosition);
|
2012-11-22 17:25:23 -08:00
|
|
|
nscoord halfRange = nsPresContext::CSSPixelsToAppUnits(1000);
|
|
|
|
nsRect range(pt.x - halfRange, pt.y - halfRange, 2*halfRange - 1, 2*halfRange - 1);
|
2013-12-16 09:04:45 -08:00
|
|
|
ScrollToWithOrigin(pt, nsIScrollableFrame::INSTANT, aOrigin, &range);
|
2013-08-08 15:04:59 -07:00
|
|
|
// 'this' might be destroyed here
|
2012-11-22 17:25:23 -08:00
|
|
|
}
|
|
|
|
|
2013-07-10 02:58:13 -07:00
|
|
|
CSSIntPoint
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollPositionCSSPixels()
|
2012-08-10 04:17:06 -07:00
|
|
|
{
|
2013-07-10 02:58:13 -07:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(GetScrollPosition());
|
2012-08-10 04:17:06 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
/*
|
|
|
|
* this method wraps calls to ScrollToImpl(), either in one shot or incrementally,
|
2012-03-11 13:55:00 -07:00
|
|
|
* based on the setting of the smoothness scroll pref
|
2009-10-07 20:01:15 -07:00
|
|
|
*/
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollToWithOrigin(nsPoint aScrollPosition,
|
2012-03-26 02:53:45 -07:00
|
|
|
nsIScrollableFrame::ScrollMode aMode,
|
2012-02-07 16:53:18 -08:00
|
|
|
nsIAtom *aOrigin,
|
|
|
|
const nsRect* aRange)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2012-02-07 16:53:18 -08:00
|
|
|
nsRect scrollRange = GetScrollRangeForClamping();
|
|
|
|
mDestination = scrollRange.ClampPoint(aScrollPosition);
|
|
|
|
|
|
|
|
nsRect range = aRange ? *aRange : nsRect(aScrollPosition, nsSize(0, 0));
|
2009-10-07 20:01:15 -07:00
|
|
|
|
|
|
|
if (aMode == nsIScrollableFrame::INSTANT) {
|
|
|
|
// Asynchronous scrolling is not allowed, so we'll kill any existing
|
2012-02-07 16:53:18 -08:00
|
|
|
// async-scrolling process and do an instant scroll.
|
2012-07-30 07:20:58 -07:00
|
|
|
mAsyncScroll = nullptr;
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2013-12-16 09:04:45 -08:00
|
|
|
ScrollToImpl(mDestination, range, aOrigin);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-22 09:24:06 -07:00
|
|
|
// We are done scrolling, set our destination to wherever we actually ended
|
|
|
|
// up scrolling to.
|
|
|
|
mDestination = GetScrollPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-25 21:30:19 -07:00
|
|
|
TimeStamp now = TimeStamp::Now();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSmoothScroll = (aMode == nsIScrollableFrame::SMOOTH) &&
|
2011-02-04 00:00:06 -08:00
|
|
|
IsSmoothScrollingEnabled();
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2013-04-17 17:03:29 -07:00
|
|
|
if (!mAsyncScroll) {
|
|
|
|
mAsyncScroll = new AsyncScroll(GetScrollPosition());
|
2012-03-31 06:08:00 -07:00
|
|
|
if (!mAsyncScroll->SetRefreshObserver(this)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mAsyncScroll = nullptr;
|
2012-03-31 06:08:00 -07:00
|
|
|
// Observer setup failed. Scroll the normal way.
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2013-12-16 09:04:45 -08:00
|
|
|
ScrollToImpl(mDestination, range, aOrigin);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-22 09:24:06 -07:00
|
|
|
// We are done scrolling, set our destination to wherever we actually
|
|
|
|
// ended up scrolling to.
|
|
|
|
mDestination = GetScrollPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAsyncScroll->mIsSmoothScroll = isSmoothScroll;
|
|
|
|
|
|
|
|
if (isSmoothScroll) {
|
2013-04-17 17:03:29 -07:00
|
|
|
mAsyncScroll->InitSmoothScroll(now, mDestination, aOrigin, range);
|
2012-02-07 16:53:18 -08:00
|
|
|
} else {
|
|
|
|
mAsyncScroll->Init(range);
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't use nsContainerFrame::PositionChildViews here because
|
|
|
|
// we don't want to invalidate views that have moved.
|
2010-10-14 18:03:45 -07:00
|
|
|
static void AdjustViews(nsIFrame* aFrame)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = aFrame->GetView();
|
2009-10-07 20:01:15 -07:00
|
|
|
if (view) {
|
|
|
|
nsPoint pt;
|
|
|
|
aFrame->GetParent()->GetClosestView(&pt);
|
|
|
|
pt += aFrame->GetPosition();
|
|
|
|
view->SetPosition(pt.x, pt.y);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:54:29 -07:00
|
|
|
// Call AdjustViews recursively for all child frames except the popup list as
|
|
|
|
// the views for popups are not scrolled.
|
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
if (lists.CurrentID() == nsIFrame::kPopupList) {
|
|
|
|
continue;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
AdjustViews(childFrames.get());
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-01-04 00:46:56 -08:00
|
|
|
CanScrollWithBlitting(nsIFrame* aFrame)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2011-10-20 18:41:36 -07:00
|
|
|
if (aFrame->GetStateBits() & NS_SCROLLFRAME_INVALIDATE_CONTENTS_ON_SCROLL)
|
|
|
|
return false;
|
|
|
|
|
2010-04-22 19:41:38 -07:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
2010-07-15 14:08:02 -07:00
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
2009-10-07 20:01:15 -07:00
|
|
|
if (nsSVGIntegrationUtils::UsingEffectsForFrame(f) ||
|
2012-07-22 20:00:36 -07:00
|
|
|
f->IsFrameOfType(nsIFrame::eSVG) ||
|
|
|
|
f->GetStateBits() & NS_FRAME_NO_COMPONENT_ALPHA) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
2011-01-04 00:46:56 -08:00
|
|
|
if (nsLayoutUtils::IsPopup(f))
|
2010-04-22 19:41:38 -07:00
|
|
|
break;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
bool ScrollFrameHelper::IsIgnoringViewportClipping() const
|
2011-12-05 04:38:46 -08:00
|
|
|
{
|
|
|
|
if (!mIsRoot)
|
|
|
|
return false;
|
|
|
|
nsSubDocumentFrame* subdocFrame = static_cast<nsSubDocumentFrame*>
|
|
|
|
(nsLayoutUtils::GetCrossDocParentFrame(mOuter->PresContext()->PresShell()->GetRootFrame()));
|
|
|
|
return subdocFrame && !subdocFrame->ShouldClipSubdocument();
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
bool ScrollFrameHelper::ShouldClampScrollPosition() const
|
2012-02-17 15:41:13 -08:00
|
|
|
{
|
|
|
|
if (!mIsRoot)
|
|
|
|
return true;
|
|
|
|
nsSubDocumentFrame* subdocFrame = static_cast<nsSubDocumentFrame*>
|
|
|
|
(nsLayoutUtils::GetCrossDocParentFrame(mOuter->PresContext()->PresShell()->GetRootFrame()));
|
|
|
|
return !subdocFrame || subdocFrame->ShouldClampScrollPosition();
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
bool ScrollFrameHelper::IsAlwaysActive() const
|
2010-07-15 14:08:05 -07:00
|
|
|
{
|
2012-11-22 15:29:05 -08:00
|
|
|
if (nsDisplayItem::ForceActiveLayers()) {
|
|
|
|
return true;
|
2013-11-22 10:14:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = mOuter->StyleDisplay();
|
|
|
|
if (disp && (disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_SCROLL)) {
|
|
|
|
return true;
|
2012-11-22 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
2013-03-04 12:57:01 -08:00
|
|
|
// Unless this is the root scrollframe for a non-chrome document
|
2012-11-13 22:26:33 -08:00
|
|
|
// which is the direct child of a chrome document, we default to not
|
|
|
|
// being "active".
|
|
|
|
if (!(mIsRoot && mOuter->PresContext()->IsRootContentDocument())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have scrolled before, then we should stay active.
|
|
|
|
if (mHasBeenScrolled) {
|
2012-11-18 20:19:22 -08:00
|
|
|
return true;
|
2012-11-13 22:26:33 -08:00
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2012-11-13 22:26:33 -08:00
|
|
|
// If we're overflow:hidden, then start as inactive until
|
|
|
|
// we get scrolled manually.
|
|
|
|
ScrollbarStyles styles = GetScrollbarStylesFromFrame();
|
|
|
|
return (styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN);
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
void ScrollFrameHelper::MarkInactive()
|
2011-01-04 00:46:59 -08:00
|
|
|
{
|
|
|
|
if (IsAlwaysActive() || !mScrollingActive)
|
|
|
|
return;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mScrollingActive = false;
|
2011-01-04 00:46:59 -08:00
|
|
|
mOuter->InvalidateFrameSubtree();
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
void ScrollFrameHelper::MarkActive()
|
2010-07-15 14:08:05 -07:00
|
|
|
{
|
2012-11-18 20:19:22 -08:00
|
|
|
mScrollingActive = true;
|
2010-07-15 14:08:05 -07:00
|
|
|
if (IsAlwaysActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mActivityExpirationState.IsTracked()) {
|
|
|
|
gScrollFrameActivityTracker->MarkUsed(this);
|
|
|
|
} else {
|
|
|
|
if (!gScrollFrameActivityTracker) {
|
|
|
|
gScrollFrameActivityTracker = new ScrollFrameActivityTracker();
|
|
|
|
}
|
|
|
|
gScrollFrameActivityTracker->AddObject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
void ScrollFrameHelper::ScrollVisual(nsPoint aOldScrolledFramePos)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2012-11-13 22:26:33 -08:00
|
|
|
// Mark this frame as having been scrolled. If this is the root
|
|
|
|
// scroll frame of a content document, then IsAlwaysActive()
|
|
|
|
// will return true from now on and MarkInactive() won't
|
|
|
|
// have any effect.
|
|
|
|
mHasBeenScrolled = true;
|
|
|
|
|
2010-10-14 18:03:45 -07:00
|
|
|
AdjustViews(mScrolledFrame);
|
|
|
|
// We need to call this after fixing up the view positions
|
|
|
|
// to be consistent with the frame hierarchy.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canScrollWithBlitting = CanScrollWithBlitting(mOuter);
|
2011-10-20 18:41:36 -07:00
|
|
|
mOuter->RemoveStateBits(NS_SCROLLFRAME_INVALIDATE_CONTENTS_ON_SCROLL);
|
2011-01-04 00:46:59 -08:00
|
|
|
if (IsScrollingActive()) {
|
|
|
|
if (!canScrollWithBlitting) {
|
|
|
|
MarkInactive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canScrollWithBlitting) {
|
|
|
|
MarkActive();
|
2010-07-15 14:08:02 -07:00
|
|
|
}
|
2011-03-09 13:35:27 -08:00
|
|
|
|
2012-08-28 22:39:31 -07:00
|
|
|
mOuter->SchedulePaint();
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2012-02-07 16:53:18 -08:00
|
|
|
/**
|
2013-06-09 17:37:16 -07:00
|
|
|
* Clamp desired scroll position aDesired and range [aDestLower, aDestUpper]
|
|
|
|
* to [aBoundLower, aBoundUpper] and then select the appunit value from among
|
|
|
|
* aBoundLower, aBoundUpper and those such that (aDesired - aCurrent) *
|
|
|
|
* aRes/aAppUnitsPerPixel is an integer (or as close as we can get
|
|
|
|
* modulo rounding to appunits) that is in [aDestLower, aDestUpper] and
|
|
|
|
* closest to aDesired. If no such value exists, return the nearest in
|
|
|
|
* [aDestLower, aDestUpper].
|
2012-02-07 16:53:18 -08:00
|
|
|
*/
|
|
|
|
static nscoord
|
2013-06-09 17:37:16 -07:00
|
|
|
ClampAndAlignWithPixels(nscoord aDesired,
|
|
|
|
nscoord aBoundLower, nscoord aBoundUpper,
|
|
|
|
nscoord aDestLower, nscoord aDestUpper,
|
|
|
|
nscoord aAppUnitsPerPixel, double aRes,
|
|
|
|
nscoord aCurrent)
|
2012-02-07 16:53:18 -08:00
|
|
|
{
|
2013-06-09 17:37:16 -07:00
|
|
|
// Intersect scroll range with allowed range, by clamping the ends
|
|
|
|
// of aRange to be within bounds
|
|
|
|
nscoord destLower = clamped(aDestLower, aBoundLower, aBoundUpper);
|
|
|
|
nscoord destUpper = clamped(aDestUpper, aBoundLower, aBoundUpper);
|
|
|
|
|
|
|
|
nscoord desired = clamped(aDesired, destLower, destUpper);
|
|
|
|
|
2012-08-04 05:26:38 -07:00
|
|
|
double currentLayerVal = (aRes*aCurrent)/aAppUnitsPerPixel;
|
2013-06-09 17:37:16 -07:00
|
|
|
double desiredLayerVal = (aRes*desired)/aAppUnitsPerPixel;
|
2012-08-04 05:26:38 -07:00
|
|
|
double delta = desiredLayerVal - currentLayerVal;
|
2013-06-09 17:37:16 -07:00
|
|
|
double nearestLayerVal = NS_round(delta) + currentLayerVal;
|
2012-07-12 22:03:54 -07:00
|
|
|
|
2012-08-04 05:26:38 -07:00
|
|
|
// Convert back from ThebesLayer space to appunits relative to the top-left
|
|
|
|
// of the scrolled frame.
|
2013-06-09 17:37:16 -07:00
|
|
|
nscoord aligned =
|
|
|
|
NSToCoordRoundWithClamp(nearestLayerVal*aAppUnitsPerPixel/aRes);
|
|
|
|
|
|
|
|
// Use a bound if it is within the allowed range and closer to desired than
|
|
|
|
// the nearest pixel-aligned value.
|
|
|
|
if (aBoundUpper == destUpper &&
|
|
|
|
static_cast<decltype(Abs(desired))>(aBoundUpper - desired) <
|
|
|
|
Abs(desired - aligned))
|
|
|
|
return aBoundUpper;
|
|
|
|
|
|
|
|
if (aBoundLower == destLower &&
|
|
|
|
static_cast<decltype(Abs(desired))>(desired - aBoundLower) <
|
|
|
|
Abs(aligned - desired))
|
|
|
|
return aBoundLower;
|
|
|
|
|
|
|
|
// Accept the nearest pixel-aligned value if it is within the allowed range.
|
|
|
|
if (aligned >= destLower && aligned <= destUpper)
|
|
|
|
return aligned;
|
|
|
|
|
|
|
|
// Check if opposite pixel boundary fits into allowed range.
|
|
|
|
double oppositeLayerVal =
|
|
|
|
nearestLayerVal + ((nearestLayerVal < desiredLayerVal) ? 1.0 : -1.0);
|
|
|
|
nscoord opposite =
|
|
|
|
NSToCoordRoundWithClamp(oppositeLayerVal*aAppUnitsPerPixel/aRes);
|
|
|
|
if (opposite >= destLower && opposite <= destUpper) {
|
|
|
|
return opposite;
|
2012-02-07 16:53:18 -08:00
|
|
|
}
|
2013-06-09 17:37:16 -07:00
|
|
|
|
|
|
|
// No alignment available.
|
|
|
|
return desired;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2012-02-07 16:53:18 -08:00
|
|
|
/**
|
2012-08-04 05:26:38 -07:00
|
|
|
* Clamp desired scroll position aPt to aBounds and then snap
|
|
|
|
* it to the same layer pixel edges as aCurrent, keeping it within aRange
|
|
|
|
* during snapping. aCurrent is the current scroll position.
|
2012-02-07 16:53:18 -08:00
|
|
|
*/
|
|
|
|
static nsPoint
|
2012-08-04 05:26:38 -07:00
|
|
|
ClampAndAlignWithLayerPixels(const nsPoint& aPt,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
const nsRect& aRange,
|
|
|
|
const nsPoint& aCurrent,
|
|
|
|
nscoord aAppUnitsPerPixel,
|
|
|
|
const gfxSize& aScale)
|
2012-02-07 16:53:18 -08:00
|
|
|
{
|
2013-06-09 17:37:16 -07:00
|
|
|
return nsPoint(ClampAndAlignWithPixels(aPt.x, aBounds.x, aBounds.XMost(),
|
|
|
|
aRange.x, aRange.XMost(),
|
|
|
|
aAppUnitsPerPixel, aScale.width,
|
|
|
|
aCurrent.x),
|
|
|
|
ClampAndAlignWithPixels(aPt.y, aBounds.y, aBounds.YMost(),
|
|
|
|
aRange.y, aRange.YMost(),
|
|
|
|
aAppUnitsPerPixel, aScale.height,
|
|
|
|
aCurrent.y));
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
|
2012-01-18 20:13:02 -08:00
|
|
|
/* static */ void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollActivityCallback(nsITimer *aTimer, void* anInstance)
|
2012-01-18 20:13:02 -08:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper* self = static_cast<ScrollFrameHelper*>(anInstance);
|
2012-01-18 20:13:02 -08:00
|
|
|
|
|
|
|
// Fire the synth mouse move.
|
|
|
|
self->mScrollActivityTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
self->mScrollActivityTimer = nullptr;
|
2012-01-18 20:13:02 -08:00
|
|
|
self->mOuter->PresContext()->PresShell()->SynthesizeMouseMove(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScheduleSyntheticMouseMove()
|
2012-01-18 20:13:02 -08:00
|
|
|
{
|
|
|
|
if (!mScrollActivityTimer) {
|
|
|
|
mScrollActivityTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mScrollActivityTimer)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScrollActivityTimer->InitWithFuncCallback(
|
|
|
|
ScrollActivityCallback, this, 100, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
void
|
2013-12-16 09:04:45 -08:00
|
|
|
ScrollFrameHelper::ScrollToImpl(nsPoint aPt, const nsRect& aRange, nsIAtom* aOrigin)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
2013-12-16 09:04:45 -08:00
|
|
|
if (aOrigin == nullptr) {
|
|
|
|
// If no origin was specified, we still want to set it to something that's
|
|
|
|
// non-null, so that we can use nullness to distinguish if the frame was scrolled
|
|
|
|
// at all. Default it to some generic placeholder.
|
|
|
|
aOrigin = nsGkAtoms::other;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-08-04 05:26:38 -07:00
|
|
|
// 'scale' is our estimate of the scale factor that will be applied
|
|
|
|
// when rendering the scrolled content to its own ThebesLayer.
|
|
|
|
gfxSize scale = FrameLayerBuilder::GetThebesLayerScaleForFrame(mScrolledFrame);
|
|
|
|
nsPoint curPos = GetScrollPosition();
|
2012-08-16 16:40:10 -07:00
|
|
|
nsPoint alignWithPos = mScrollPosForLayerPixelAlignment == nsPoint(-1,-1)
|
|
|
|
? curPos : mScrollPosForLayerPixelAlignment;
|
2012-08-04 05:26:38 -07:00
|
|
|
// Try to align aPt with curPos so they have an integer number of layer
|
|
|
|
// pixels between them. This gives us the best chance of scrolling without
|
|
|
|
// having to invalidate due to changes in subpixel rendering.
|
|
|
|
// Note that when we actually draw into a ThebesLayer, the coordinates
|
|
|
|
// that get mapped onto the layer buffer pixels are from the display list,
|
|
|
|
// which are relative to the display root frame's top-left increasing down,
|
|
|
|
// whereas here our coordinates are scroll positions which increase upward
|
|
|
|
// and are relative to the scrollport top-left. This difference doesn't actually
|
|
|
|
// matter since all we are about is that there be an integer number of
|
|
|
|
// layer pixels between pt and curPos.
|
2012-02-07 16:53:18 -08:00
|
|
|
nsPoint pt =
|
2012-08-04 05:26:38 -07:00
|
|
|
ClampAndAlignWithLayerPixels(aPt,
|
|
|
|
GetScrollRangeForClamping(),
|
|
|
|
aRange,
|
2012-08-16 16:40:10 -07:00
|
|
|
alignWithPos,
|
2012-08-04 05:26:38 -07:00
|
|
|
appUnitsPerDevPixel,
|
|
|
|
scale);
|
2009-10-07 20:01:15 -07:00
|
|
|
if (pt == curPos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-24 16:59:21 -08:00
|
|
|
bool needImageVisibilityUpdate = (mLastUpdateImagesPos == nsPoint(-1,-1));
|
|
|
|
|
|
|
|
nsPoint dist(std::abs(pt.x - mLastUpdateImagesPos.x),
|
|
|
|
std::abs(pt.y - mLastUpdateImagesPos.y));
|
2013-09-15 11:51:35 -07:00
|
|
|
nsSize scrollPortSize = GetScrollPositionClampingScrollPortSize();
|
|
|
|
nscoord horzAllowance = std::max(scrollPortSize.width / std::max(sHorzScrollFraction, 1),
|
2013-02-24 16:59:21 -08:00
|
|
|
nsPresContext::AppUnitsPerCSSPixel());
|
2013-09-15 11:51:35 -07:00
|
|
|
nscoord vertAllowance = std::max(scrollPortSize.height / std::max(sVertScrollFraction, 1),
|
2013-02-24 16:59:21 -08:00
|
|
|
nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
if (dist.x >= horzAllowance || dist.y >= vertAllowance) {
|
|
|
|
needImageVisibilityUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needImageVisibilityUpdate) {
|
|
|
|
presContext->PresShell()->ScheduleImageVisibilityUpdate();
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
// notify the listeners.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mListeners.Length(); i++) {
|
2009-10-07 20:01:15 -07:00
|
|
|
mListeners[i]->ScrollPositionWillChange(pt.x, pt.y);
|
|
|
|
}
|
2011-12-05 04:38:46 -08:00
|
|
|
|
|
|
|
nsPoint oldScrollFramePos = mScrolledFrame->GetPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
// Update frame position for scrolling
|
|
|
|
mScrolledFrame->SetPosition(mScrollPort.TopLeft() - pt);
|
2013-12-16 09:04:45 -08:00
|
|
|
mOriginOfLastScroll = aOrigin;
|
2009-10-07 20:01:15 -07:00
|
|
|
|
|
|
|
// We pass in the amount to move visually
|
2011-12-05 04:38:46 -08:00
|
|
|
ScrollVisual(oldScrollFramePos);
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2012-01-18 20:13:02 -08:00
|
|
|
ScheduleSyntheticMouseMove();
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2009-10-07 20:01:15 -07:00
|
|
|
UpdateScrollbarPosition();
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
PostScrollEvent();
|
|
|
|
|
|
|
|
// notify the listeners.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mListeners.Length(); i++) {
|
2009-10-07 20:01:15 -07:00
|
|
|
mListeners[i]->ScrollPositionDidChange(pt.x, pt.y);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-15 14:08:03 -07:00
|
|
|
static void
|
|
|
|
AppendToTop(nsDisplayListBuilder* aBuilder, nsDisplayList* aDest,
|
2013-12-09 19:14:53 -08:00
|
|
|
nsDisplayList* aSource, nsIFrame* aSourceFrame, bool aOwnLayer,
|
|
|
|
uint32_t aFlags, mozilla::layers::FrameMetrics::ViewID aScrollTargetId)
|
2010-07-15 14:08:03 -07:00
|
|
|
{
|
2011-05-30 16:12:06 -07:00
|
|
|
if (aSource->IsEmpty())
|
|
|
|
return;
|
2010-07-15 14:08:03 -07:00
|
|
|
if (aOwnLayer) {
|
2010-08-13 03:01:13 -07:00
|
|
|
aDest->AppendNewToTop(
|
2013-12-09 19:14:53 -08:00
|
|
|
new (aBuilder) nsDisplayOwnLayer(aBuilder, aSourceFrame, aSource,
|
|
|
|
aFlags, aScrollTargetId));
|
2010-07-15 14:08:03 -07:00
|
|
|
} else {
|
|
|
|
aDest->AppendToTop(aSource);
|
2013-03-04 12:57:01 -08:00
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
}
|
|
|
|
|
2013-07-22 21:21:55 -07:00
|
|
|
struct HoveredStateComparator
|
|
|
|
{
|
|
|
|
bool Equals(nsIFrame* A, nsIFrame* B) const {
|
|
|
|
bool aHovered = A->GetContent()->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::hover);
|
|
|
|
bool bHovered = B->GetContent()->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::hover);
|
|
|
|
return aHovered == bHovered;
|
|
|
|
}
|
|
|
|
bool LessThan(nsIFrame* A, nsIFrame* B) const {
|
|
|
|
bool aHovered = A->GetContent()->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::hover);
|
|
|
|
bool bHovered = B->GetContent()->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::hover);
|
|
|
|
return !aHovered && bHovered;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-20 04:30:14 -08:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AppendScrollPartsTo(nsDisplayListBuilder* aBuilder,
|
2011-12-20 04:30:14 -08:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists,
|
|
|
|
bool& aCreateLayer,
|
|
|
|
bool aPositioned)
|
|
|
|
{
|
2013-12-03 10:21:09 -08:00
|
|
|
nsITheme* theme = mOuter->PresContext()->GetTheme();
|
|
|
|
if (theme &&
|
|
|
|
theme->ShouldHideScrollbars()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:10:13 -07:00
|
|
|
bool overlayScrollbars =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0;
|
|
|
|
|
2013-07-22 21:21:55 -07:00
|
|
|
nsAutoTArray<nsIFrame*, 3> scrollParts;
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* kid = mOuter->GetFirstPrincipalChild(); kid; kid = kid->GetNextSibling()) {
|
2011-12-20 04:30:14 -08:00
|
|
|
if (kid == mScrolledFrame ||
|
2013-07-18 07:10:13 -07:00
|
|
|
(kid->IsPositioned() || overlayScrollbars) != aPositioned)
|
2011-12-20 04:30:14 -08:00
|
|
|
continue;
|
|
|
|
|
2013-07-22 21:21:55 -07:00
|
|
|
scrollParts.AppendElement(kid);
|
|
|
|
}
|
|
|
|
|
2013-12-09 19:14:53 -08:00
|
|
|
mozilla::layers::FrameMetrics::ViewID scrollTargetId = aCreateLayer
|
|
|
|
? nsLayoutUtils::FindOrCreateIDFor(mScrolledFrame->GetContent())
|
|
|
|
: mozilla::layers::FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
|
2013-07-22 21:21:55 -07:00
|
|
|
scrollParts.Sort(HoveredStateComparator());
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < scrollParts.Length(); ++i) {
|
2011-12-20 04:30:14 -08:00
|
|
|
nsDisplayListCollection partList;
|
2013-07-22 21:21:55 -07:00
|
|
|
mOuter->BuildDisplayListForChild(
|
|
|
|
aBuilder, scrollParts[i], aDirtyRect, partList,
|
|
|
|
nsIFrame::DISPLAY_CHILD_FORCE_STACKING_CONTEXT);
|
2011-12-20 04:30:14 -08:00
|
|
|
|
|
|
|
// Don't append textarea resizers to the positioned descendants because
|
|
|
|
// we don't want them to float on top of overlapping elements.
|
2013-07-22 21:21:55 -07:00
|
|
|
bool appendToPositioned = aPositioned &&
|
|
|
|
!(scrollParts[i] == mResizerBox && !mIsRoot);
|
2011-12-20 04:30:14 -08:00
|
|
|
|
|
|
|
nsDisplayList* dest = appendToPositioned ?
|
|
|
|
aLists.PositionedDescendants() : aLists.BorderBackground();
|
|
|
|
|
2013-12-09 19:14:53 -08:00
|
|
|
uint32_t flags = 0;
|
|
|
|
if (scrollParts[i] == mVScrollbarBox) {
|
|
|
|
flags |= nsDisplayOwnLayer::VERTICAL_SCROLLBAR;
|
|
|
|
}
|
|
|
|
if (scrollParts[i] == mHScrollbarBox) {
|
|
|
|
flags |= nsDisplayOwnLayer::HORIZONTAL_SCROLLBAR;
|
|
|
|
}
|
|
|
|
|
2011-12-20 04:30:14 -08:00
|
|
|
// DISPLAY_CHILD_FORCE_STACKING_CONTEXT put everything into
|
|
|
|
// partList.PositionedDescendants().
|
|
|
|
::AppendToTop(aBuilder, dest,
|
2013-07-22 21:21:55 -07:00
|
|
|
partList.PositionedDescendants(), scrollParts[i],
|
2013-12-09 19:14:53 -08:00
|
|
|
aCreateLayer, flags, scrollTargetId);
|
2010-10-21 05:07:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
class ScrollLayerWrapper : public nsDisplayWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScrollLayerWrapper(nsIFrame* aScrollFrame, nsIFrame* aScrolledFrame)
|
|
|
|
: mCount(0)
|
|
|
|
, mProps(aScrolledFrame->Properties())
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
|
|
|
{
|
|
|
|
SetCount(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsDisplayItem* WrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList) {
|
|
|
|
SetCount(++mCount);
|
2011-05-01 18:53:58 -07:00
|
|
|
return new (aBuilder) nsDisplayScrollLayer(aBuilder, aList, mScrolledFrame, mScrolledFrame, mScrollFrame);
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsDisplayItem* WrapItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
|
2014-01-27 16:51:35 -08:00
|
|
|
// If the display item is for a frame that is absolutely positioned, it
|
|
|
|
// should only scroll with the scrolled content if its frame its contained
|
|
|
|
// within the scrolled content's frame.
|
|
|
|
bool shouldWrap = !aItem->Frame()->IsAbsolutelyPositioned() ||
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(mScrolledFrame, aItem->Frame(), nullptr);
|
|
|
|
if (shouldWrap) {
|
|
|
|
SetCount(++mCount);
|
|
|
|
return new (aBuilder) nsDisplayScrollLayer(aBuilder, aItem, aItem->Frame(), mScrolledFrame, mScrollFrame);
|
|
|
|
} else {
|
|
|
|
return aItem;
|
|
|
|
}
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-04-11 17:17:44 -07:00
|
|
|
void SetCount(intptr_t aCount) {
|
2011-05-01 18:53:01 -07:00
|
|
|
mProps.Set(nsIFrame::ScrollLayerCount(), reinterpret_cast<void*>(aCount));
|
|
|
|
}
|
|
|
|
|
2012-04-11 17:17:44 -07:00
|
|
|
intptr_t mCount;
|
2011-05-01 18:53:01 -07:00
|
|
|
FrameProperties mProps;
|
|
|
|
nsIFrame* mScrollFrame;
|
|
|
|
nsIFrame* mScrolledFrame;
|
|
|
|
};
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
/* static */ bool ScrollFrameHelper::sImageVisPrefsCached = false;
|
|
|
|
/* static */ uint32_t ScrollFrameHelper::sHorzExpandScrollPort = 0;
|
|
|
|
/* static */ uint32_t ScrollFrameHelper::sVertExpandScrollPort = 1;
|
|
|
|
/* static */ int32_t ScrollFrameHelper::sHorzScrollFraction = 2;
|
|
|
|
/* static */ int32_t ScrollFrameHelper::sVertScrollFraction = 2;
|
2013-09-14 17:05:04 -07:00
|
|
|
|
|
|
|
/* static */ void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::EnsureImageVisPrefsCached()
|
2013-09-14 17:05:04 -07:00
|
|
|
{
|
|
|
|
if (!sImageVisPrefsCached) {
|
|
|
|
Preferences::AddUintVarCache(&sHorzExpandScrollPort,
|
|
|
|
"layout.imagevisibility.numscrollportwidths", (uint32_t)0);
|
|
|
|
Preferences::AddUintVarCache(&sVertExpandScrollPort,
|
|
|
|
"layout.imagevisibility.numscrollportheights", 1);
|
|
|
|
|
|
|
|
Preferences::AddIntVarCache(&sHorzScrollFraction,
|
|
|
|
"layout.imagevisibility.amountscrollbeforeupdatehorizontal", 2);
|
|
|
|
Preferences::AddIntVarCache(&sVertScrollFraction,
|
|
|
|
"layout.imagevisibility.amountscrollbeforeupdatevertical", 2);
|
|
|
|
|
|
|
|
sImageVisPrefsCached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-14 17:05:04 -07:00
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ExpandRect(const nsRect& aRect) const
|
2013-09-14 17:05:04 -07:00
|
|
|
{
|
2013-09-14 17:05:04 -07:00
|
|
|
// We don't want to expand a rect in a direction that we can't scroll, so we
|
|
|
|
// check the scroll range.
|
|
|
|
nsRect scrollRange = GetScrollRangeForClamping();
|
|
|
|
nsPoint scrollPos = GetScrollPosition();
|
|
|
|
nsMargin expand(0, 0, 0, 0);
|
|
|
|
|
|
|
|
nscoord vertShift = sVertExpandScrollPort * aRect.height;
|
|
|
|
if (scrollRange.y < scrollPos.y) {
|
|
|
|
expand.top = vertShift;
|
|
|
|
}
|
|
|
|
if (scrollPos.y < scrollRange.YMost()) {
|
|
|
|
expand.bottom = vertShift;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord horzShift = sHorzExpandScrollPort * aRect.width;
|
|
|
|
if (scrollRange.x < scrollPos.x) {
|
|
|
|
expand.left = horzShift;
|
|
|
|
}
|
|
|
|
if (scrollPos.x < scrollRange.XMost()) {
|
|
|
|
expand.right = horzShift;
|
|
|
|
}
|
|
|
|
|
2013-09-14 17:05:04 -07:00
|
|
|
nsRect rect = aRect;
|
2013-09-14 17:05:04 -07:00
|
|
|
rect.Inflate(expand);
|
2013-09-14 17:05:04 -07:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-12-16 11:53:06 -08:00
|
|
|
static bool IsFocused(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// Some content elements, like the GetContent() of a scroll frame
|
|
|
|
// for a text input field, are inside anonymous subtrees, but the focus
|
|
|
|
// manager always reports a non-anonymous element as the focused one, so
|
|
|
|
// walk up the tree until we reach a non-anonymous element.
|
|
|
|
while (aContent && aContent->IsInAnonymousSubtree()) {
|
|
|
|
aContent = aContent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aContent ? nsContentUtils::IsFocusedContent(aContent) : false;
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2013-02-24 16:59:21 -08:00
|
|
|
if (aBuilder->IsForImageVisibility()) {
|
|
|
|
mLastUpdateImagesPos = GetScrollPosition();
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
mOuter->DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2010-03-19 04:49:34 -07:00
|
|
|
|
2010-07-15 14:08:02 -07:00
|
|
|
if (aBuilder->IsPaintingToWindow()) {
|
|
|
|
mScrollPosAtLastPaint = GetScrollPosition();
|
2011-01-04 00:46:59 -08:00
|
|
|
if (IsScrollingActive() && !CanScrollWithBlitting(mOuter)) {
|
|
|
|
MarkInactive();
|
|
|
|
}
|
2012-08-16 16:40:10 -07:00
|
|
|
if (IsScrollingActive()) {
|
|
|
|
if (mScrollPosForLayerPixelAlignment == nsPoint(-1,-1)) {
|
|
|
|
mScrollPosForLayerPixelAlignment = mScrollPosAtLastPaint;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mScrollPosForLayerPixelAlignment = nsPoint(-1,-1);
|
|
|
|
}
|
2010-07-15 14:08:02 -07:00
|
|
|
}
|
|
|
|
|
2011-12-05 04:38:46 -08:00
|
|
|
if (aBuilder->GetIgnoreScrollFrame() == mOuter || IsIgnoringViewportClipping()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't clip the scrolled child, and don't paint scrollbars/scrollcorner.
|
|
|
|
// The scrolled frame shouldn't have its own background/border, so we
|
2009-03-29 17:29:36 -07:00
|
|
|
// can just pass aLists directly.
|
2013-02-14 03:08:08 -08:00
|
|
|
mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame,
|
|
|
|
aDirtyRect, aLists);
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:03 -07:00
|
|
|
// We put scrollbars in their own layers when this is the root scroll
|
|
|
|
// frame and we are a toplevel content document. In this situation, the
|
|
|
|
// scrollbar(s) would normally be assigned their own layer anyway, since
|
|
|
|
// they're not scrolled with the rest of the document. But when both
|
|
|
|
// scrollbars are visible, the layer's visible rectangle would be the size
|
|
|
|
// of the viewport, so most layer implementations would create a layer buffer
|
|
|
|
// that's much larger than necessary. Creating independent layers for each
|
|
|
|
// scrollbar works around the problem.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool createLayersForScrollbars = mIsRoot &&
|
2010-09-11 11:24:50 -07:00
|
|
|
mOuter->PresContext()->IsRootContentDocument();
|
2010-07-15 14:08:03 -07:00
|
|
|
|
2011-12-20 04:30:14 -08:00
|
|
|
// Now display the scrollbars and scrollcorner. These parts are drawn
|
|
|
|
// in the border-background layer, on top of our own background and
|
|
|
|
// borders and underneath borders and backgrounds of later elements
|
|
|
|
// in the tree.
|
|
|
|
// Note that this does not apply for overlay scrollbars; those are drawn
|
|
|
|
// in the positioned-elements layer on top of everything else by the call
|
|
|
|
// to AppendScrollPartsTo(..., true) further down.
|
|
|
|
AppendScrollPartsTo(aBuilder, aDirtyRect, aLists, createLayersForScrollbars,
|
|
|
|
false);
|
2009-02-25 23:00:36 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Overflow clipping can never clip frames outside our subtree, so there
|
|
|
|
// is no need to worry about whether we are a moving frame that might clip
|
|
|
|
// non-moving frames.
|
|
|
|
nsRect dirtyRect;
|
|
|
|
// Not all our descendants will be clipped by overflow clipping, but all
|
|
|
|
// the ones that aren't clipped will be out of flow frames that have already
|
|
|
|
// had dirty rects saved for them by their parent frames calling
|
|
|
|
// MarkOutOfFlowChildrenForDisplayList, so it's safe to restrict our
|
|
|
|
// dirty rect here.
|
2011-03-15 16:20:19 -07:00
|
|
|
dirtyRect.IntersectRect(aDirtyRect, mScrollPort);
|
|
|
|
|
2011-03-09 13:35:27 -08:00
|
|
|
// Override the dirty rectangle if the displayport has been set.
|
2012-04-17 05:08:29 -07:00
|
|
|
nsRect displayPort;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool usingDisplayport =
|
2012-04-17 05:08:29 -07:00
|
|
|
nsLayoutUtils::GetDisplayPort(mOuter->GetContent(), &displayPort) &&
|
|
|
|
!aBuilder->IsForEventDelivery();
|
|
|
|
if (usingDisplayport) {
|
|
|
|
dirtyRect = displayPort;
|
|
|
|
}
|
2010-10-21 05:07:55 -07:00
|
|
|
|
2013-02-24 16:59:21 -08:00
|
|
|
if (aBuilder->IsForImageVisibility()) {
|
|
|
|
// We expand the dirty rect to catch images just outside of the scroll port.
|
2013-09-14 17:05:04 -07:00
|
|
|
// We use the dirty rect instead of the whole scroll port to prevent
|
|
|
|
// too much expansion in the presence of very large (bigger than the
|
|
|
|
// viewport) scroll ports.
|
2013-09-14 17:05:04 -07:00
|
|
|
dirtyRect = ExpandRect(dirtyRect);
|
2013-02-24 16:59:21 -08:00
|
|
|
}
|
|
|
|
|
2013-10-01 19:29:24 -07:00
|
|
|
nsDisplayListCollection scrolledContent;
|
2013-03-04 01:56:02 -08:00
|
|
|
{
|
2013-04-04 04:36:45 -07:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
2013-03-04 01:56:02 -08:00
|
|
|
|
|
|
|
if (usingDisplayport) {
|
|
|
|
nsRect clip = displayPort + aBuilder->ToReferenceFrame(mOuter);
|
2013-11-07 16:36:59 -08:00
|
|
|
|
|
|
|
// If we are using a display port, then ignore any pre-existing clip
|
|
|
|
// passed down from our parents, and use only the clip computed here
|
|
|
|
// based on the display port. The pre-existing clip would just defeat
|
|
|
|
// the purpose of a display port which is to paint regions that are not
|
|
|
|
// currently visible so that they can be brought into view asynchronously.
|
|
|
|
// Notes:
|
|
|
|
// - The pre-existing clip state will be restored when the
|
|
|
|
// AutoSaveRestore goes out of scope, so there is no permanent change
|
|
|
|
// to this clip state.
|
|
|
|
// - We still set a clip to the scroll port further below where we
|
|
|
|
// build the scroll wrapper. This doesn't prevent us from painting
|
|
|
|
// the entire displayport, but it lets the compositor know to
|
|
|
|
// clip to the scroll port after compositing.
|
|
|
|
clipState.Clear();
|
|
|
|
|
2013-06-16 22:16:27 -07:00
|
|
|
if (mClipAllDescendants) {
|
2013-04-04 04:36:45 -07:00
|
|
|
clipState.ClipContentDescendants(clip);
|
2013-03-04 01:56:02 -08:00
|
|
|
} else {
|
2013-04-04 04:36:45 -07:00
|
|
|
clipState.ClipContainingBlockDescendants(clip, nullptr);
|
2013-03-04 01:56:02 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsRect clip = mScrollPort + aBuilder->ToReferenceFrame(mOuter);
|
2013-07-25 18:36:05 -07:00
|
|
|
nscoord radii[8];
|
|
|
|
bool haveRadii = mOuter->GetPaddingBoxBorderRadii(radii);
|
2013-03-04 01:56:02 -08:00
|
|
|
// Our override of GetBorderRadii ensures we never have a radius at
|
|
|
|
// the corners where we have a scrollbar.
|
2013-06-16 22:16:27 -07:00
|
|
|
if (mClipAllDescendants) {
|
2013-07-25 18:36:05 -07:00
|
|
|
clipState.ClipContentDescendants(clip, haveRadii ? radii : nullptr);
|
2013-03-04 01:56:02 -08:00
|
|
|
} else {
|
2013-04-04 04:36:45 -07:00
|
|
|
clipState.ClipContainingBlockDescendants(clip, haveRadii ? radii : nullptr);
|
2013-03-04 01:56:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 19:29:24 -07:00
|
|
|
mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame, dirtyRect, scrolledContent);
|
2013-03-04 01:56:02 -08:00
|
|
|
}
|
2011-03-15 16:20:19 -07:00
|
|
|
|
|
|
|
// Since making new layers is expensive, only use nsDisplayScrollLayer
|
2013-10-23 02:04:42 -07:00
|
|
|
// if the area is scrollable and we're the content process (unless we're on
|
|
|
|
// B2G, where we support async scrolling for scrollable elements in the
|
|
|
|
// parent process as well).
|
2012-05-17 11:19:07 -07:00
|
|
|
// When a displayport is being used, force building of a layer so that
|
|
|
|
// CompositorParent can always find the scrollable layer for the root content
|
|
|
|
// document.
|
2013-10-23 02:04:42 -07:00
|
|
|
// If the element is marked 'scrollgrab', also force building of a layer
|
|
|
|
// so that APZ can implement scroll grabbing.
|
2014-01-26 14:50:31 -08:00
|
|
|
mShouldBuildScrollableLayer = usingDisplayport || nsContentUtils::HasScrollgrab(mOuter->GetContent());
|
2013-11-01 20:47:21 -07:00
|
|
|
bool shouldBuildLayer = false;
|
2013-10-23 02:04:42 -07:00
|
|
|
if (mShouldBuildScrollableLayer) {
|
2013-11-01 20:47:21 -07:00
|
|
|
shouldBuildLayer = true;
|
2012-05-17 11:19:07 -07:00
|
|
|
} else {
|
|
|
|
nsRect scrollRange = GetScrollRange();
|
|
|
|
ScrollbarStyles styles = GetScrollbarStylesFromFrame();
|
2013-12-16 11:53:06 -08:00
|
|
|
bool isFocused = IsFocused(mOuter->GetContent());
|
2013-12-16 11:53:02 -08:00
|
|
|
bool isVScrollable = (scrollRange.height > 0)
|
|
|
|
&& (styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
bool isHScrollable = (scrollRange.width > 0)
|
|
|
|
&& (styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN);
|
2013-12-16 11:53:06 -08:00
|
|
|
// The check for scroll bars was added in bug 825692 to prevent layerization
|
|
|
|
// of text inputs for performance reasons. However, if a text input is
|
|
|
|
// focused we want to layerize it so we can async scroll it (bug 946408).
|
|
|
|
bool wantLayerV = isVScrollable && (mVScrollbarBox || isFocused);
|
|
|
|
bool wantLayerH = isHScrollable && (mHScrollbarBox || isFocused);
|
2013-10-18 12:56:51 -07:00
|
|
|
// TODO Turn this on for inprocess OMTC on all platforms
|
2013-07-02 08:16:05 -07:00
|
|
|
bool wantSubAPZC = (XRE_GetProcessType() == GeckoProcessType_Content);
|
2013-10-18 12:56:51 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
|
|
|
|
wantSubAPZC = true;
|
|
|
|
}
|
|
|
|
#endif
|
2013-11-01 20:47:21 -07:00
|
|
|
shouldBuildLayer =
|
2013-07-02 08:16:05 -07:00
|
|
|
wantSubAPZC &&
|
2013-12-16 11:53:02 -08:00
|
|
|
(wantLayerV || wantLayerH) &&
|
2014-01-03 12:48:57 -08:00
|
|
|
// If we are the root scroll frame for the display root then we don't need a scroll
|
|
|
|
// info layer to make a RecordFrameMetrics call for us as
|
|
|
|
// nsDisplayList::PaintForFrame already calls RecordFrameMetrics for us.
|
|
|
|
(!mIsRoot || aBuilder->RootReferenceFrame()->PresContext() != mOuter->PresContext());
|
2012-05-17 11:19:07 -07:00
|
|
|
}
|
2011-03-15 16:20:19 -07:00
|
|
|
|
2013-11-01 20:47:21 -07:00
|
|
|
if (shouldBuildLayer) {
|
2011-05-01 18:53:01 -07:00
|
|
|
// ScrollLayerWrapper must always be created because it initializes the
|
|
|
|
// scroll layer count. The display lists depend on this.
|
|
|
|
ScrollLayerWrapper wrapper(mOuter, mScrolledFrame);
|
|
|
|
|
2013-10-23 02:04:42 -07:00
|
|
|
if (mShouldBuildScrollableLayer) {
|
2013-10-17 15:02:42 -07:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
2013-10-24 09:31:26 -07:00
|
|
|
|
|
|
|
// For root scrollframes in documents where the CSS viewport has been
|
|
|
|
// modified, the CSS viewport no longer corresponds to what is visible,
|
|
|
|
// so we don't want to clip the content to it. For root scrollframes
|
|
|
|
// in documents where the CSS viewport is NOT modified, the mScrollPort
|
|
|
|
// is the same as the CSS viewport, modulo scrollbars.
|
|
|
|
if (!(mIsRoot && mOuter->PresContext()->PresShell()->GetIsViewportOverridden())) {
|
|
|
|
nsRect clip = mScrollPort + aBuilder->ToReferenceFrame(mOuter);
|
|
|
|
if (mClipAllDescendants) {
|
|
|
|
clipState.ClipContentDescendants(clip);
|
|
|
|
} else {
|
|
|
|
clipState.ClipContainingBlockDescendants(clip);
|
|
|
|
}
|
2013-10-17 15:02:42 -07:00
|
|
|
}
|
2013-10-24 09:31:26 -07:00
|
|
|
|
2011-04-11 13:53:01 -07:00
|
|
|
// Once a displayport is set, assume that scrolling needs to be fast
|
|
|
|
// so create a layer with all the content inside. The compositor
|
|
|
|
// process will be able to scroll the content asynchronously.
|
2013-10-01 19:29:24 -07:00
|
|
|
wrapper.WrapListsInPlace(aBuilder, mOuter, scrolledContent);
|
2011-04-29 21:01:29 -07:00
|
|
|
}
|
2011-05-01 18:53:01 -07:00
|
|
|
|
|
|
|
// In case we are not using displayport or the nsDisplayScrollLayers are
|
|
|
|
// flattened during visibility computation, we still need to export the
|
|
|
|
// metadata about this scroll box to the compositor process.
|
|
|
|
nsDisplayScrollInfoLayer* layerItem = new (aBuilder) nsDisplayScrollInfoLayer(
|
|
|
|
aBuilder, mScrolledFrame, mOuter);
|
2013-10-01 19:29:24 -07:00
|
|
|
scrolledContent.BorderBackground()->AppendNewToBottom(layerItem);
|
2011-03-15 16:20:19 -07:00
|
|
|
}
|
2013-10-01 19:29:24 -07:00
|
|
|
scrolledContent.MoveTo(aLists);
|
2011-03-15 16:20:19 -07:00
|
|
|
|
2011-12-20 04:30:14 -08:00
|
|
|
// Now display overlay scrollbars and the resizer, if we have one.
|
2013-12-09 19:14:54 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// TODO: only layerize the overlay scrollbars if this scrollframe can be
|
|
|
|
// panned asynchronously. For now just always layerize on B2G because.
|
|
|
|
// that's where we want the layerized scrollbars
|
|
|
|
createLayersForScrollbars = true;
|
|
|
|
#endif
|
2011-12-20 04:30:14 -08:00
|
|
|
AppendScrollPartsTo(aBuilder, aDirtyRect, aLists, createLayersForScrollbars,
|
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-14 17:05:04 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::IsRectNearlyVisible(const nsRect& aRect) const
|
2013-09-14 17:05:04 -07:00
|
|
|
{
|
2013-09-15 11:51:35 -07:00
|
|
|
// Use the right rect depending on if a display port is set.
|
|
|
|
nsRect displayPort;
|
|
|
|
bool usingDisplayport = nsLayoutUtils::GetDisplayPort(mOuter->GetContent(), &displayPort);
|
|
|
|
return aRect.Intersects(ExpandRect(usingDisplayport ? displayPort : mScrollPort));
|
2013-09-14 17:05:04 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void HandleScrollPref(nsIScrollable *aScrollable, int32_t aOrientation,
|
|
|
|
uint8_t& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pref;
|
2007-03-22 10:30:00 -07:00
|
|
|
aScrollable->GetDefaultScrollbarPreferences(aOrientation, &pref);
|
|
|
|
switch (pref) {
|
|
|
|
case nsIScrollable::Scrollbar_Auto:
|
|
|
|
// leave |aValue| untouched
|
|
|
|
break;
|
|
|
|
case nsIScrollable::Scrollbar_Never:
|
|
|
|
aValue = NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
break;
|
|
|
|
case nsIScrollable::Scrollbar_Always:
|
|
|
|
aValue = NS_STYLE_OVERFLOW_SCROLL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollbarStylesFromFrame() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!presContext->IsDynamic() &&
|
|
|
|
!(mIsRoot && presContext->HasPaginatedScrolling())) {
|
|
|
|
return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
|
2012-10-23 16:34:54 -07:00
|
|
|
if (!mIsRoot) {
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleDisplay* disp = mOuter->StyleDisplay();
|
2012-10-23 16:34:54 -07:00
|
|
|
return ScrollbarStyles(disp->mOverflowX, disp->mOverflowY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-23 16:34:54 -07:00
|
|
|
ScrollbarStyles result = presContext->GetViewportOverflowOverride();
|
2013-11-20 11:18:25 -08:00
|
|
|
nsCOMPtr<nsISupports> container = presContext->GetContainerWeak();
|
2012-10-23 16:34:54 -07:00
|
|
|
nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
|
|
|
|
if (scrollable) {
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
|
|
|
|
result.mHorizontal);
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_Y,
|
|
|
|
result.mVertical);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollRange() const
|
2012-04-24 11:52:35 -07:00
|
|
|
{
|
|
|
|
return GetScrollRange(mScrollPort.width, mScrollPort.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollRange(nscoord aWidth, nscoord aHeight) const
|
2009-08-31 21:11:11 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect range = GetScrolledRect();
|
2013-06-05 20:47:39 -07:00
|
|
|
range.width = std::max(range.width - aWidth, 0);
|
|
|
|
range.height = std::max(range.height - aHeight, 0);
|
2009-08-31 21:11:11 -07:00
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2012-04-24 11:52:35 -07:00
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollRangeForClamping() const
|
2012-04-24 11:52:35 -07:00
|
|
|
{
|
2012-02-07 16:53:18 -08:00
|
|
|
if (!ShouldClampScrollPosition()) {
|
|
|
|
return nsRect(nscoord_MIN/2, nscoord_MIN/2,
|
|
|
|
nscoord_MAX - nscoord_MIN/2, nscoord_MAX - nscoord_MIN/2);
|
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
nsSize scrollPortSize = GetScrollPositionClampingScrollPortSize();
|
|
|
|
return GetScrollRange(scrollPortSize.width, scrollPortSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrollPositionClampingScrollPortSize() const
|
2012-06-10 16:44:50 -07:00
|
|
|
{
|
2012-04-24 11:52:35 -07:00
|
|
|
nsIPresShell* presShell = mOuter->PresContext()->PresShell();
|
|
|
|
if (mIsRoot && presShell->IsScrollPositionClampingScrollPortSizeSet()) {
|
2012-06-10 16:44:50 -07:00
|
|
|
return presShell->GetScrollPositionClampingScrollPortSize();
|
2012-04-24 11:52:35 -07:00
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
return mScrollPort.Size();
|
2012-04-24 11:52:35 -07:00
|
|
|
}
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
AdjustForWholeDelta(int32_t aDelta, nscoord* aCoord)
|
2009-08-31 21:11:11 -07:00
|
|
|
{
|
|
|
|
if (aDelta < 0) {
|
|
|
|
*aCoord = nscoord_MIN;
|
|
|
|
} else if (aDelta > 0) {
|
|
|
|
*aCoord = nscoord_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 12:20:57 -08:00
|
|
|
/**
|
|
|
|
* Calculate lower/upper scrollBy range in given direction.
|
|
|
|
* @param aDelta specifies scrollBy direction, if 0 then range will be 0 size
|
|
|
|
* @param aPos desired destination in AppUnits
|
|
|
|
* @param aNeg/PosTolerance defines relative range distance
|
|
|
|
* below and above of aPos point
|
|
|
|
* @param aMultiplier used for conversion of tolerance into appUnis
|
|
|
|
*/
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
CalcRangeForScrollBy(int32_t aDelta, nscoord aPos,
|
2012-02-07 12:20:57 -08:00
|
|
|
float aNegTolerance,
|
|
|
|
float aPosTolerance,
|
|
|
|
nscoord aMultiplier,
|
|
|
|
nscoord* aLower, nscoord* aUpper)
|
|
|
|
{
|
|
|
|
if (!aDelta) {
|
|
|
|
*aLower = *aUpper = aPos;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*aLower = aPos - NSToCoordRound(aMultiplier * (aDelta > 0 ? aNegTolerance : aPosTolerance));
|
|
|
|
*aUpper = aPos + NSToCoordRound(aMultiplier * (aDelta > 0 ? aPosTolerance : aNegTolerance));
|
|
|
|
}
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollBy(nsIntPoint aDelta,
|
2009-08-31 21:11:11 -07:00
|
|
|
nsIScrollableFrame::ScrollUnit aUnit,
|
|
|
|
nsIScrollableFrame::ScrollMode aMode,
|
2012-03-26 02:50:30 -07:00
|
|
|
nsIntPoint* aOverflow,
|
|
|
|
nsIAtom *aOrigin)
|
2009-08-31 21:11:11 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize deltaMultiplier;
|
2012-02-07 12:20:57 -08:00
|
|
|
float negativeTolerance;
|
|
|
|
float positiveTolerance;
|
2012-03-26 02:50:30 -07:00
|
|
|
if (!aOrigin){
|
|
|
|
aOrigin = nsGkAtoms::other;
|
|
|
|
}
|
|
|
|
bool isGenericOrigin = (aOrigin == nsGkAtoms::other);
|
2009-08-31 21:11:11 -07:00
|
|
|
switch (aUnit) {
|
|
|
|
case nsIScrollableFrame::DEVICE_PIXELS: {
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord appUnitsPerDevPixel =
|
|
|
|
mOuter->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
deltaMultiplier = nsSize(appUnitsPerDevPixel, appUnitsPerDevPixel);
|
2012-03-26 02:50:30 -07:00
|
|
|
if (isGenericOrigin){
|
|
|
|
aOrigin = nsGkAtoms::pixels;
|
|
|
|
}
|
2013-04-28 03:02:35 -07:00
|
|
|
negativeTolerance = positiveTolerance = 0.5f;
|
2009-08-31 21:11:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIScrollableFrame::LINES: {
|
2009-10-07 20:01:15 -07:00
|
|
|
deltaMultiplier = GetLineScrollAmount();
|
2012-03-26 02:50:30 -07:00
|
|
|
if (isGenericOrigin){
|
|
|
|
aOrigin = nsGkAtoms::lines;
|
|
|
|
}
|
2013-04-28 03:02:35 -07:00
|
|
|
negativeTolerance = positiveTolerance = 0.1f;
|
2009-08-31 21:11:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIScrollableFrame::PAGES: {
|
2009-10-07 20:01:15 -07:00
|
|
|
deltaMultiplier = GetPageScrollAmount();
|
2012-03-26 02:50:30 -07:00
|
|
|
if (isGenericOrigin){
|
|
|
|
aOrigin = nsGkAtoms::pages;
|
|
|
|
}
|
2013-04-28 03:02:35 -07:00
|
|
|
negativeTolerance = 0.05f;
|
2012-02-07 12:20:57 -08:00
|
|
|
positiveTolerance = 0;
|
2009-08-31 21:11:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIScrollableFrame::WHOLE: {
|
|
|
|
nsPoint pos = GetScrollPosition();
|
|
|
|
AdjustForWholeDelta(aDelta.x, &pos.x);
|
|
|
|
AdjustForWholeDelta(aDelta.y, &pos.y);
|
|
|
|
ScrollTo(pos, aMode);
|
2013-08-08 15:04:59 -07:00
|
|
|
// 'this' might be destroyed here
|
2009-10-07 20:01:15 -07:00
|
|
|
if (aOverflow) {
|
|
|
|
*aOverflow = nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
return;
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid scroll mode");
|
|
|
|
return;
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint newPos = mDestination +
|
|
|
|
nsPoint(aDelta.x*deltaMultiplier.width, aDelta.y*deltaMultiplier.height);
|
2012-02-07 12:20:57 -08:00
|
|
|
// Calculate desired range values.
|
|
|
|
nscoord rangeLowerX, rangeUpperX, rangeLowerY, rangeUpperY;
|
|
|
|
CalcRangeForScrollBy(aDelta.x, newPos.x, negativeTolerance, positiveTolerance,
|
|
|
|
deltaMultiplier.width, &rangeLowerX, &rangeUpperX);
|
|
|
|
CalcRangeForScrollBy(aDelta.y, newPos.y, negativeTolerance, positiveTolerance,
|
|
|
|
deltaMultiplier.height, &rangeLowerY, &rangeUpperY);
|
|
|
|
nsRect range(rangeLowerX,
|
|
|
|
rangeLowerY,
|
|
|
|
rangeUpperX - rangeLowerX,
|
|
|
|
rangeUpperY - rangeLowerY);
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2012-02-07 12:20:57 -08:00
|
|
|
ScrollToWithOrigin(newPos, aMode, aOrigin, &range);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
if (aOverflow) {
|
2012-08-29 18:05:16 -07:00
|
|
|
nsPoint clampAmount = newPos - mDestination;
|
2009-10-07 20:01:15 -07:00
|
|
|
float appUnitsPerDevPixel = mOuter->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
*aOverflow = nsIntPoint(
|
2012-08-29 18:05:16 -07:00
|
|
|
NSAppUnitsToIntPixels(clampAmount.x, appUnitsPerDevPixel),
|
|
|
|
NSAppUnitsToIntPixels(clampAmount.y, appUnitsPerDevPixel));
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetLineScrollAmount() const
|
2009-08-31 21:11:11 -07:00
|
|
|
{
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(mOuter, getter_AddRefs(fm),
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(mOuter));
|
2009-10-07 20:01:15 -07:00
|
|
|
NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit");
|
2012-08-19 09:46:21 -07:00
|
|
|
static nscoord sMinLineScrollAmountInPixels = -1;
|
|
|
|
if (sMinLineScrollAmountInPixels < 0) {
|
|
|
|
Preferences::AddIntVarCache(&sMinLineScrollAmountInPixels,
|
|
|
|
"mousewheel.min_line_scroll_amount", 1);
|
|
|
|
}
|
2013-02-19 13:46:27 -08:00
|
|
|
int32_t appUnitsPerDevPixel = mOuter->PresContext()->AppUnitsPerDevPixel();
|
2012-10-28 22:44:31 -07:00
|
|
|
nscoord minScrollAmountInAppUnits =
|
2013-01-15 04:22:03 -08:00
|
|
|
std::max(1, sMinLineScrollAmountInPixels) * appUnitsPerDevPixel;
|
2012-10-28 22:44:31 -07:00
|
|
|
nscoord horizontalAmount = fm ? fm->AveCharWidth() : 0;
|
|
|
|
nscoord verticalAmount = fm ? fm->MaxHeight() : 0;
|
2013-01-15 04:22:03 -08:00
|
|
|
return nsSize(std::max(horizontalAmount, minScrollAmountInAppUnits),
|
|
|
|
std::max(verticalAmount, minScrollAmountInAppUnits));
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
|
2012-08-09 04:17:40 -07:00
|
|
|
/**
|
|
|
|
* Compute the scrollport size excluding any fixed-pos headers and
|
|
|
|
* footers. A header or footer is an box that spans that entire width
|
|
|
|
* of the viewport and touches the top (or bottom, respectively) of the
|
2013-02-13 20:36:02 -08:00
|
|
|
* viewport. We also want to consider fixed elements that stack or overlap
|
|
|
|
* to effectively create a larger header or footer. Headers and footers that
|
|
|
|
* cover more than a third of the the viewport are ignored since they
|
|
|
|
* probably aren't true headers and footers and we don't want to restrict
|
|
|
|
* scrolling too much in such cases. This is a bit conservative --- some
|
|
|
|
* pages use elements as headers or footers that don't span the entire width
|
|
|
|
* of the viewport --- but it should be a good start.
|
2012-08-09 04:17:40 -07:00
|
|
|
*/
|
2013-02-13 20:36:02 -08:00
|
|
|
struct TopAndBottom
|
|
|
|
{
|
|
|
|
TopAndBottom(nscoord aTop, nscoord aBottom) : top(aTop), bottom(aBottom) {}
|
|
|
|
|
|
|
|
nscoord top, bottom;
|
|
|
|
};
|
|
|
|
struct TopComparator
|
|
|
|
{
|
|
|
|
bool Equals(const TopAndBottom& A, const TopAndBottom& B) const {
|
|
|
|
return A.top == B.top;
|
|
|
|
}
|
|
|
|
bool LessThan(const TopAndBottom& A, const TopAndBottom& B) const {
|
|
|
|
return A.top < B.top;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct ReverseBottomComparator
|
|
|
|
{
|
|
|
|
bool Equals(const TopAndBottom& A, const TopAndBottom& B) const {
|
|
|
|
return A.bottom == B.bottom;
|
|
|
|
}
|
|
|
|
bool LessThan(const TopAndBottom& A, const TopAndBottom& B) const {
|
|
|
|
return A.bottom > B.bottom;
|
|
|
|
}
|
|
|
|
};
|
2012-08-09 04:17:40 -07:00
|
|
|
static nsSize
|
|
|
|
GetScrollPortSizeExcludingHeadersAndFooters(nsIFrame* aViewportFrame,
|
|
|
|
const nsRect& aScrollPort)
|
|
|
|
{
|
2013-02-13 20:36:02 -08:00
|
|
|
nsTArray<TopAndBottom> list;
|
2012-08-09 04:17:40 -07:00
|
|
|
nsFrameList fixedFrames = aViewportFrame->GetChildList(nsIFrame::kFixedList);
|
|
|
|
for (nsFrameList::Enumerator iterator(fixedFrames); !iterator.AtEnd();
|
|
|
|
iterator.Next()) {
|
|
|
|
nsIFrame* f = iterator.get();
|
|
|
|
nsRect r = f->GetRect().Intersect(aScrollPort);
|
|
|
|
if (r.x == 0 && r.width == aScrollPort.width &&
|
|
|
|
r.height <= aScrollPort.height/3) {
|
2013-02-13 20:36:02 -08:00
|
|
|
list.AppendElement(TopAndBottom(r.y, r.YMost()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list.Sort(TopComparator());
|
|
|
|
nscoord headerBottom = 0;
|
2013-02-14 09:57:50 -08:00
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
2013-02-13 20:36:02 -08:00
|
|
|
if (list[i].top <= headerBottom) {
|
|
|
|
headerBottom = std::max(headerBottom, list[i].bottom);
|
2012-08-09 04:17:40 -07:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 20:36:02 -08:00
|
|
|
|
|
|
|
list.Sort(ReverseBottomComparator());
|
|
|
|
nscoord footerTop = aScrollPort.height;
|
2013-02-14 09:57:50 -08:00
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
2013-02-13 20:36:02 -08:00
|
|
|
if (list[i].bottom >= footerTop) {
|
|
|
|
footerTop = std::min(footerTop, list[i].top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
headerBottom = std::min(aScrollPort.height/3, headerBottom);
|
|
|
|
footerTop = std::max(aScrollPort.height - aScrollPort.height/3, footerTop);
|
|
|
|
|
2012-08-09 04:17:40 -07:00
|
|
|
return nsSize(aScrollPort.width, footerTop - headerBottom);
|
|
|
|
}
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
nsSize
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetPageScrollAmount() const
|
2009-08-31 21:11:11 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize lineScrollAmount = GetLineScrollAmount();
|
2012-08-09 04:17:40 -07:00
|
|
|
nsSize effectiveScrollPortSize;
|
|
|
|
if (mIsRoot) {
|
|
|
|
// Reduce effective scrollport height by the height of any fixed-pos
|
|
|
|
// headers or footers
|
|
|
|
nsIFrame* root = mOuter->PresContext()->PresShell()->GetRootFrame();
|
|
|
|
effectiveScrollPortSize =
|
|
|
|
GetScrollPortSizeExcludingHeadersAndFooters(root, mScrollPort);
|
|
|
|
} else {
|
|
|
|
effectiveScrollPortSize = mScrollPort.Size();
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
// The page increment is the size of the page, minus the smaller of
|
|
|
|
// 10% of the size or 2 lines.
|
|
|
|
return nsSize(
|
2012-08-09 04:17:40 -07:00
|
|
|
effectiveScrollPortSize.width -
|
2013-01-15 04:22:03 -08:00
|
|
|
std::min(effectiveScrollPortSize.width/10, 2*lineScrollAmount.width),
|
2012-08-09 04:17:40 -07:00
|
|
|
effectiveScrollPortSize.height -
|
2013-01-15 04:22:03 -08:00
|
|
|
std::min(effectiveScrollPortSize.height/10, 2*lineScrollAmount.height));
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* this code is resposible for restoring the scroll position back to some
|
|
|
|
* saved position. if the user has not moved the scroll position manually
|
|
|
|
* we keep scrolling down until we get to our original position. keep in
|
|
|
|
* mind that content could incrementally be coming in. we only want to stop
|
|
|
|
* when we reach our new position.
|
|
|
|
*/
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollToRestoredPosition()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
if (mRestorePos.y == -1 || mLastPos.x == -1 || mLastPos.y == -1) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// make sure our scroll position did not change for where we last put
|
|
|
|
// it. if it does then the user must have moved it, and we no longer
|
|
|
|
// need to restore.
|
2011-02-06 23:59:20 -08:00
|
|
|
//
|
|
|
|
// In the RTL case, we check whether the scroll position changed using the
|
|
|
|
// logical scroll position, but we scroll to the physical scroll position in
|
|
|
|
// all cases
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if we didn't move, we still need to restore
|
2011-02-06 23:59:20 -08:00
|
|
|
if (GetLogicalScrollPosition() == mLastPos) {
|
2009-10-07 20:01:15 -07:00
|
|
|
// if our desired position is different to the scroll position, scroll.
|
2007-03-22 10:30:00 -07:00
|
|
|
// remember that we could be incrementally loading so we may enter
|
|
|
|
// and scroll many times.
|
2011-03-27 23:37:57 -07:00
|
|
|
if (mRestorePos != mLastPos /* GetLogicalScrollPosition() */) {
|
|
|
|
nsPoint scrollToPos = mRestorePos;
|
|
|
|
if (!IsLTR())
|
|
|
|
// convert from logical to physical scroll position
|
2013-03-04 12:57:01 -08:00
|
|
|
scrollToPos.x = mScrollPort.x -
|
2011-03-27 23:37:57 -07:00
|
|
|
(mScrollPort.XMost() - scrollToPos.x - mScrolledFrame->GetRect().width);
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2011-03-27 23:37:57 -07:00
|
|
|
ScrollTo(scrollToPos, nsIScrollableFrame::INSTANT);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
// Re-get the scroll position, it might not be exactly equal to
|
|
|
|
// mRestorePos due to rounding and clamping.
|
2011-02-06 23:59:20 -08:00
|
|
|
mLastPos = GetLogicalScrollPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// if we reached the position then stop
|
2009-10-07 20:01:15 -07:00
|
|
|
mRestorePos.y = -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// user moved the position, so we won't need to restore
|
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::FireScrollPortEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mAsyncScrollPortEvent.Forget();
|
2007-10-08 01:42:43 -07:00
|
|
|
|
|
|
|
// Keep this in sync with PostOverflowEvent().
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize scrollportSize = mScrollPort.Size();
|
|
|
|
nsSize childSize = GetScrolledRect().Size();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
bool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
bool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!vertChanged && !horizChanged) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If both either overflowed or underflowed then we dispatch only one
|
|
|
|
// DOM event.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool both = vertChanged && horizChanged &&
|
2007-03-22 10:30:00 -07:00
|
|
|
newVerticalOverflow == newHorizontalOverflow;
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScrollPortEvent::orientType orient;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (both) {
|
2013-09-26 23:20:56 -07:00
|
|
|
orient = InternalScrollPortEvent::both;
|
2007-03-22 10:30:00 -07:00
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
mVerticalOverflow = newVerticalOverflow;
|
|
|
|
}
|
|
|
|
else if (vertChanged) {
|
2013-09-26 23:20:56 -07:00
|
|
|
orient = InternalScrollPortEvent::vertical;
|
2007-03-22 10:30:00 -07:00
|
|
|
mVerticalOverflow = newVerticalOverflow;
|
|
|
|
if (horizChanged) {
|
|
|
|
// We need to dispatch a separate horizontal DOM event. Do that the next
|
|
|
|
// time around since dispatching the vertical DOM event might destroy
|
|
|
|
// the frame.
|
|
|
|
PostOverflowEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-09-26 23:20:56 -07:00
|
|
|
orient = InternalScrollPortEvent::horizontal;
|
2007-03-22 10:30:00 -07:00
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
}
|
|
|
|
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScrollPortEvent event(true,
|
|
|
|
(orient == InternalScrollPortEvent::horizontal ? mHorizontalOverflow :
|
|
|
|
mVerticalOverflow) ?
|
|
|
|
NS_SCROLLPORT_OVERFLOW : NS_SCROLLPORT_UNDERFLOW, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.orient = orient;
|
|
|
|
return nsEventDispatcher::Dispatch(mOuter->GetContent(),
|
2007-03-30 14:11:41 -07:00
|
|
|
mOuter->PresContext(), &event);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ReloadChildFrames()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mScrolledFrame = nullptr;
|
|
|
|
mHScrollbarBox = nullptr;
|
|
|
|
mVScrollbarBox = nullptr;
|
|
|
|
mScrollCornerBox = nullptr;
|
|
|
|
mResizerBox = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* frame = mOuter->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (frame) {
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (content == mOuter->GetContent()) {
|
|
|
|
NS_ASSERTION(!mScrolledFrame, "Already found the scrolled frame");
|
|
|
|
mScrolledFrame = frame;
|
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::orient, value);
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
// probably a scrollbar then
|
|
|
|
if (value.LowerCaseEqualsLiteral("horizontal")) {
|
|
|
|
NS_ASSERTION(!mHScrollbarBox, "Found multiple horizontal scrollbars?");
|
|
|
|
mHScrollbarBox = frame;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!mVScrollbarBox, "Found multiple vertical scrollbars?");
|
|
|
|
mVScrollbarBox = frame;
|
|
|
|
}
|
2011-01-17 06:35:32 -08:00
|
|
|
} else if (content->Tag() == nsGkAtoms::resizer) {
|
|
|
|
NS_ASSERTION(!mResizerBox, "Found multiple resizers");
|
|
|
|
mResizerBox = frame;
|
2013-01-21 02:31:40 -08:00
|
|
|
} else if (content->Tag() == nsGkAtoms::scrollcorner) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// probably a scrollcorner
|
|
|
|
NS_ASSERTION(!mScrollCornerBox, "Found multiple scrollcorners");
|
|
|
|
mScrollCornerBox = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::CreateAnonymousContent(
|
2011-05-06 13:04:44 -07:00
|
|
|
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* parent = mOuter->GetParent();
|
|
|
|
|
2010-11-19 08:56:06 -08:00
|
|
|
// Don't create scrollbars if we're an SVG document being used as an image,
|
|
|
|
// or if we're printing/print previewing.
|
|
|
|
// (In the printing case, we allow scrollbars if this is the child of the
|
|
|
|
// viewport & paginated scrolling is enabled, because then we must be the
|
|
|
|
// scroll frame for the print preview window, & that does need scrollbars.)
|
|
|
|
if (presContext->Document()->IsBeingUsedAsImage() ||
|
|
|
|
(!presContext->IsDynamic() &&
|
|
|
|
!(mIsRoot && presContext->HasPaginatedScrolling()))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = true;
|
2010-11-19 08:56:06 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
// Check if the frame is resizable.
|
2013-02-16 13:51:02 -08:00
|
|
|
int8_t resizeStyle = mOuter->StyleDisplay()->mResize;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isResizable = resizeStyle != NS_STYLE_RESIZE_NONE;
|
2010-03-19 04:49:34 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *scrollable = do_QueryFrame(mOuter);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-08 16:30:02 -08:00
|
|
|
// If we're the scrollframe for the root, then we want to construct
|
|
|
|
// our scrollbar frames no matter what. That way later dynamic
|
|
|
|
// changes to propagated overflow styles will show or hide
|
|
|
|
// scrollbars on the viewport without requiring frame reconstruction
|
|
|
|
// of the viewport (good!).
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canHaveHorizontal;
|
|
|
|
bool canHaveVertical;
|
2010-03-08 16:30:02 -08:00
|
|
|
if (!mIsRoot) {
|
2010-04-06 13:01:34 -07:00
|
|
|
ScrollbarStyles styles = scrollable->GetScrollbarStyles();
|
2010-03-08 16:30:02 -08:00
|
|
|
canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
if (!canHaveHorizontal && !canHaveVertical && !isResizable) {
|
|
|
|
// Nothing to do.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
canHaveHorizontal = true;
|
|
|
|
canHaveVertical = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The anonymous <div> used by <inputs> never gets scrollbars.
|
2009-01-12 11:20:59 -08:00
|
|
|
nsITextControlFrame* textFrame = do_QueryFrame(parent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (textFrame) {
|
|
|
|
// Make sure we are not a text area.
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> textAreaElement(do_QueryInterface(parent->GetContent()));
|
|
|
|
if (!textAreaElement) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNodeInfoManager *nodeInfoManager =
|
|
|
|
presContext->Document()->NodeInfoManager();
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbar, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XUL,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-09-25 15:46:52 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (canHaveHorizontal) {
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = nodeInfo;
|
2010-08-19 16:12:46 -07:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mHScrollbarContent), ni.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("horizontal"), false);
|
2010-07-16 06:01:39 -07:00
|
|
|
mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("always"), false);
|
2013-07-25 18:31:35 -07:00
|
|
|
if (mIsRoot) {
|
|
|
|
mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::root_,
|
|
|
|
NS_LITERAL_STRING("true"), false);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aElements.AppendElement(mHScrollbarContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canHaveVertical) {
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = nodeInfo;
|
2010-08-19 16:12:46 -07:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mVScrollbarContent), ni.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("vertical"), false);
|
2010-07-16 06:01:39 -07:00
|
|
|
mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("always"), false);
|
2013-07-25 18:31:35 -07:00
|
|
|
if (mIsRoot) {
|
|
|
|
mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::root_,
|
|
|
|
NS_LITERAL_STRING("true"), false);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aElements.AppendElement(mVScrollbarContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
if (isResizable) {
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::resizer, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XUL,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-03-19 04:49:34 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2011-01-17 06:35:32 -08:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mResizerContent), nodeInfo.forget());
|
2010-03-19 04:49:34 -07:00
|
|
|
|
|
|
|
nsAutoString dir;
|
2010-03-23 10:14:47 -07:00
|
|
|
switch (resizeStyle) {
|
2010-03-19 04:49:34 -07:00
|
|
|
case NS_STYLE_RESIZE_HORIZONTAL:
|
|
|
|
if (IsScrollbarOnRight()) {
|
|
|
|
dir.AssignLiteral("right");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dir.AssignLiteral("left");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_RESIZE_VERTICAL:
|
|
|
|
dir.AssignLiteral("bottom");
|
|
|
|
break;
|
|
|
|
case NS_STYLE_RESIZE_BOTH:
|
|
|
|
dir.AssignLiteral("bottomend");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("only resizable types should have resizers");
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mResizerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, dir, false);
|
2011-01-17 06:35:32 -08:00
|
|
|
|
|
|
|
if (mIsRoot) {
|
|
|
|
nsIContent* browserRoot = GetBrowserRoot(mOuter->GetContent());
|
|
|
|
mCollapsedResizer = !(browserRoot &&
|
|
|
|
browserRoot->HasAttr(kNameSpaceID_None, nsGkAtoms::showresizer));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mResizerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::element,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("_parent"), false);
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mResizerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("always"), false);
|
2010-03-19 04:49:34 -07:00
|
|
|
|
2011-01-17 06:35:32 -08:00
|
|
|
if (!aElements.AppendElement(mResizerContent))
|
2010-03-19 04:49:34 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2011-01-17 06:35:32 -08:00
|
|
|
|
|
|
|
if (canHaveHorizontal && canHaveVertical) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollcorner, nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_XUL,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-08-19 16:12:46 -07:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mScrollCornerContent), nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aElements.AppendElement(mScrollCornerContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFilter)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mHScrollbarContent);
|
|
|
|
aElements.MaybeAppendElement(mVScrollbarContent);
|
|
|
|
aElements.MaybeAppendElement(mScrollCornerContent);
|
2011-01-17 06:35:32 -08:00
|
|
|
aElements.MaybeAppendElement(mResizerContent);
|
2010-02-11 09:34:01 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::Destroy()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-03 03:35:14 -07:00
|
|
|
if (mScrollbarActivity) {
|
2013-05-02 07:58:00 -07:00
|
|
|
mScrollbarActivity->Destroy();
|
2012-08-12 03:43:47 -07:00
|
|
|
mScrollbarActivity = nullptr;
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Unbind any content created in CreateAnonymousContent from the tree
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mHScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mVScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mScrollCornerContent);
|
2011-01-17 06:35:32 -08:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mResizerContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mPostedReflowCallback) {
|
2007-03-30 14:11:41 -07:00
|
|
|
mOuter->PresContext()->PresShell()->CancelReflowCallback(this);
|
2011-10-17 07:59:28 -07:00
|
|
|
mPostedReflowCallback = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when we want to update the scrollbar position, either because scrolling happened
|
|
|
|
* or the user moved the scrollbar position and we need to undo that (e.g., when the user
|
|
|
|
* clicks to scroll and we're using smooth scrolling, so we need to put the thumb back
|
|
|
|
* to its initial position for the start of the smooth sequence).
|
|
|
|
*/
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::UpdateScrollbarPosition()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrameIsUpdatingScrollbar = true;
|
2009-10-07 20:01:15 -07:00
|
|
|
|
|
|
|
nsPoint pt = GetScrollPosition();
|
|
|
|
if (mVScrollbarBox) {
|
2007-03-22 10:30:00 -07:00
|
|
|
SetCoordAttribute(mVScrollbarBox->GetContent(), nsGkAtoms::curpos,
|
2009-10-07 20:01:15 -07:00
|
|
|
pt.y - GetScrolledRect().y);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
if (mHScrollbarBox) {
|
2007-03-22 10:30:00 -07:00
|
|
|
SetCoordAttribute(mHScrollbarBox->GetContent(), nsGkAtoms::curpos,
|
2009-10-07 20:01:15 -07:00
|
|
|
pt.x - GetScrolledRect().x);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-09-29 15:18:20 -07:00
|
|
|
}
|
2008-09-03 14:35:52 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrameIsUpdatingScrollbar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
void ScrollFrameHelper::CurPosAttributeChanged(nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "aContent must not be null");
|
|
|
|
NS_ASSERTION((mHScrollbarBox && mHScrollbarBox->GetContent() == aContent) ||
|
|
|
|
(mVScrollbarBox && mVScrollbarBox->GetContent() == aContent),
|
|
|
|
"unexpected child");
|
|
|
|
|
|
|
|
// Attribute changes on the scrollbars happen in one of three ways:
|
|
|
|
// 1) The scrollbar changed the attribute in response to some user event
|
|
|
|
// 2) We changed the attribute in response to a ScrollPositionDidChange
|
|
|
|
// callback from the scrolling view
|
|
|
|
// 3) We changed the attribute to adjust the scrollbars for the start
|
|
|
|
// of a smooth scroll operation
|
|
|
|
//
|
2009-10-07 20:01:15 -07:00
|
|
|
// In cases 2 and 3 we do not need to scroll because we're just
|
|
|
|
// updating our scrollbar.
|
|
|
|
if (mFrameIsUpdatingScrollbar)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRect scrolledRect = GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-11 15:44:29 -07:00
|
|
|
nsPoint current = GetScrollPosition() - scrolledRect.TopLeft();
|
2011-02-09 20:35:01 -08:00
|
|
|
nsPoint dest;
|
2012-05-09 22:24:19 -07:00
|
|
|
nsRect allowedRange;
|
|
|
|
dest.x = GetCoordAttribute(mHScrollbarBox, nsGkAtoms::curpos, current.x,
|
|
|
|
&allowedRange.x, &allowedRange.width);
|
|
|
|
dest.y = GetCoordAttribute(mVScrollbarBox, nsGkAtoms::curpos, current.y,
|
|
|
|
&allowedRange.y, &allowedRange.height);
|
2012-05-09 22:24:20 -07:00
|
|
|
current += scrolledRect.TopLeft();
|
2012-05-09 22:24:19 -07:00
|
|
|
dest += scrolledRect.TopLeft();
|
|
|
|
allowedRange += scrolledRect.TopLeft();
|
2011-02-09 20:35:01 -08:00
|
|
|
|
2012-05-09 22:24:20 -07:00
|
|
|
// Don't try to scroll if we're already at an acceptable place.
|
|
|
|
// Don't call Contains here since Contains returns false when the point is
|
|
|
|
// on the bottom or right edge of the rectangle.
|
|
|
|
if (allowedRange.ClampPoint(current) == current) {
|
2011-02-09 20:35:01 -08:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-15 21:51:21 -07:00
|
|
|
if (mScrollbarActivity) {
|
2013-07-31 18:43:56 -07:00
|
|
|
nsRefPtr<ScrollbarActivity> scrollbarActivity(mScrollbarActivity);
|
|
|
|
scrollbarActivity->ActivityOccurred();
|
2013-07-15 21:51:21 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSmooth = aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::smooth);
|
2009-10-07 20:01:15 -07:00
|
|
|
if (isSmooth) {
|
|
|
|
// Make sure an attribute-setting callback occurs even if the view
|
|
|
|
// didn't actually move yet. We need to make sure other listeners
|
|
|
|
// see that the scroll position is not (yet) what they thought it
|
|
|
|
// was.
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2009-10-07 20:01:15 -07:00
|
|
|
UpdateScrollbarPosition();
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-26 02:53:45 -07:00
|
|
|
ScrollToWithOrigin(dest,
|
|
|
|
isSmooth ? nsIScrollableFrame::SMOOTH : nsIScrollableFrame::INSTANT,
|
2012-05-09 22:24:19 -07:00
|
|
|
nsGkAtoms::scrollbars, &allowedRange);
|
2013-08-08 15:04:59 -07:00
|
|
|
// 'this' might be destroyed here
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ============= Scroll events ========== */
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrollEvent::Run()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper)
|
|
|
|
mHelper->FireScrollEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::FireScrollEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mScrollEvent.Forget();
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent event(true, NS_SCROLL_EVENT, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsIContent* content = mOuter->GetContent();
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* prescontext = mOuter->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
// Fire viewport scroll events at the document (where they
|
|
|
|
// will bubble to the window)
|
|
|
|
if (mIsRoot) {
|
|
|
|
nsIDocument* doc = content->GetCurrentDoc();
|
|
|
|
if (doc) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(doc, prescontext, &event, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// scroll events fired at elements don't bubble (although scroll events
|
|
|
|
// fired at documents do, to the window)
|
2012-12-15 17:26:03 -08:00
|
|
|
event.mFlags.mBubbles = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(content, prescontext, &event, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::PostScrollEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mScrollEvent.IsPending())
|
|
|
|
return;
|
|
|
|
|
2011-10-25 21:14:31 -07:00
|
|
|
nsRootPresContext* rpc = mOuter->PresContext()->GetRootPresContext();
|
|
|
|
if (!rpc)
|
|
|
|
return;
|
|
|
|
mScrollEvent = new ScrollEvent(this);
|
|
|
|
rpc->AddWillPaintObserver(mScrollEvent.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AsyncScrollPortEvent::Run()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper) {
|
|
|
|
mHelper->mOuter->PresContext()->GetPresShell()->
|
2009-04-21 16:53:52 -07:00
|
|
|
FlushPendingNotifications(Flush_InterruptibleLayout);
|
2007-04-13 07:07:40 -07:00
|
|
|
}
|
2013-10-28 19:27:50 -07:00
|
|
|
return mHelper ? mHelper->FireScrollPortEvent() : NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsXULScrollFrame::AddHorizontalScrollbar(nsBoxLayoutState& aState, bool aOnBottom)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mHScrollbarBox)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return AddRemoveScrollbar(aState, aOnBottom, true, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsXULScrollFrame::AddVerticalScrollbar(nsBoxLayoutState& aState, bool aOnRight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mVScrollbarBox)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return AddRemoveScrollbar(aState, aOnRight, false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULScrollFrame::RemoveHorizontalScrollbar(nsBoxLayoutState& aState, bool aOnBottom)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// removing a scrollbar should always fit
|
2013-10-01 22:02:23 -07:00
|
|
|
DebugOnly<bool> result = AddRemoveScrollbar(aState, aOnBottom, true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(result, "Removing horizontal scrollbar failed to fit??");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULScrollFrame::RemoveVerticalScrollbar(nsBoxLayoutState& aState, bool aOnRight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// removing a scrollbar should always fit
|
2013-10-01 22:02:23 -07:00
|
|
|
DebugOnly<bool> result = AddRemoveScrollbar(aState, aOnRight, false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(result, "Removing vertical scrollbar failed to fit??");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(nsBoxLayoutState& aState,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aOnRightOrBottom, bool aHorizontal, bool aAdd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aHorizontal) {
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mNeverHasHorizontalScrollbar || !mHelper.mHScrollbarBox)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize hSize = mHelper.mHScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mHelper.mHScrollbarBox, hSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mHScrollbarBox, aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasHorizontalScrollbar;
|
|
|
|
bool fit = AddRemoveScrollbar(hasHorizontalScrollbar,
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrollPort.y,
|
|
|
|
mHelper.mScrollPort.height,
|
2011-03-03 13:18:42 -08:00
|
|
|
hSize.height, aOnRightOrBottom, aAdd);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHasHorizontalScrollbar = hasHorizontalScrollbar; // because mHasHorizontalScrollbar is a bool
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!fit)
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mHScrollbarBox, !aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return fit;
|
|
|
|
} else {
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mNeverHasVerticalScrollbar || !mHelper.mVScrollbarBox)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize vSize = mHelper.mVScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mHelper.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mVScrollbarBox, aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasVerticalScrollbar;
|
|
|
|
bool fit = AddRemoveScrollbar(hasVerticalScrollbar,
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrollPort.x,
|
|
|
|
mHelper.mScrollPort.width,
|
2011-03-03 13:18:42 -08:00
|
|
|
vSize.width, aOnRightOrBottom, aAdd);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHasVerticalScrollbar = hasVerticalScrollbar; // because mHasVerticalScrollbar is a bool
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!fit)
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.SetScrollbarVisibility(mHelper.mVScrollbarBox, !aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return fit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(bool& aHasScrollbar, nscoord& aXY,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord& aSize, nscoord aSbSize,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aOnRightOrBottom, bool aAdd)
|
2013-03-04 12:57:01 -08:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord size = aSize;
|
|
|
|
nscoord xy = aXY;
|
|
|
|
|
|
|
|
if (size != NS_INTRINSICSIZE) {
|
|
|
|
if (aAdd) {
|
|
|
|
size -= aSbSize;
|
2011-03-03 13:18:42 -08:00
|
|
|
if (!aOnRightOrBottom && size >= 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
xy += aSbSize;
|
|
|
|
} else {
|
|
|
|
size += aSbSize;
|
2011-03-03 13:18:42 -08:00
|
|
|
if (!aOnRightOrBottom)
|
2007-03-22 10:30:00 -07:00
|
|
|
xy -= aSbSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not enough room? Yes? Return true.
|
|
|
|
if (size >= 0) {
|
|
|
|
aHasScrollbar = aAdd;
|
|
|
|
aSize = size;
|
|
|
|
aXY = xy;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
aHasScrollbar = false;
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::LayoutScrollArea(nsBoxLayoutState& aState,
|
|
|
|
const nsPoint& aScrollPosition)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldflags = aState.LayoutFlags();
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRect childRect = nsRect(mHelper.mScrollPort.TopLeft() - aScrollPosition,
|
|
|
|
mHelper.mScrollPort.Size());
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t flags = NS_FRAME_NO_MOVE_VIEW;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsSize minSize = mHelper.mScrolledFrame->GetMinSize(aState);
|
2012-10-09 22:00:05 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (minSize.height > childRect.height)
|
|
|
|
childRect.height = minSize.height;
|
2012-10-09 22:00:05 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (minSize.width > childRect.width)
|
|
|
|
childRect.width = minSize.width;
|
|
|
|
|
|
|
|
aState.SetLayoutFlags(flags);
|
2011-02-12 22:38:29 -08:00
|
|
|
ClampAndSetBounds(aState, childRect, aScrollPosition);
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrolledFrame->Layout(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
childRect = mHelper.mScrolledFrame->GetRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (childRect.width < mHelper.mScrollPort.width ||
|
|
|
|
childRect.height < mHelper.mScrollPort.height)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
childRect.width = std::max(childRect.width, mHelper.mScrollPort.width);
|
|
|
|
childRect.height = std::max(childRect.height, mHelper.mScrollPort.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-06 21:25:47 -07:00
|
|
|
// remove overflow areas when we update the bounds,
|
2007-03-22 10:30:00 -07:00
|
|
|
// because we've already accounted for it
|
2010-10-06 21:25:47 -07:00
|
|
|
// REVIEW: Have we accounted for both?
|
2011-10-17 07:59:28 -07:00
|
|
|
ClampAndSetBounds(aState, childRect, aScrollPosition, true);
|
2011-02-06 23:59:20 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aState.SetLayoutFlags(oldflags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
void ScrollFrameHelper::PostOverflowEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mAsyncScrollPortEvent.IsPending())
|
|
|
|
return;
|
|
|
|
|
2007-10-08 01:42:43 -07:00
|
|
|
// Keep this in sync with FireScrollPortEvent().
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize scrollportSize = mScrollPort.Size();
|
|
|
|
nsSize childSize = GetScrolledRect().Size();
|
2007-10-08 01:42:43 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
bool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
2007-10-08 01:42:43 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
bool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
2007-10-08 01:42:43 -07:00
|
|
|
|
|
|
|
if (!vertChanged && !horizChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-12 21:01:41 -07:00
|
|
|
nsRootPresContext* rpc = mOuter->PresContext()->GetRootPresContext();
|
|
|
|
if (!rpc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mAsyncScrollPortEvent = new AsyncScrollPortEvent(this);
|
|
|
|
rpc->AddWillPaintObserver(mAsyncScrollPortEvent.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::IsLTR() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//TODO make bidi code set these from preferences
|
|
|
|
|
|
|
|
nsIFrame *frame = mOuter;
|
|
|
|
// XXX This is a bit on the slow side.
|
|
|
|
if (mIsRoot) {
|
|
|
|
// If we're the root scrollframe, we need the root element's style data.
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext *presContext = mOuter->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument *document = presContext->Document();
|
2010-04-30 06:12:05 -07:00
|
|
|
Element *root = document->GetRootElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-30 06:12:05 -07:00
|
|
|
// But for HTML and XHTML we want the body element.
|
2008-02-19 10:47:34 -08:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
|
2008-02-19 10:46:21 -08:00
|
|
|
if (htmlDoc) {
|
2010-04-30 06:12:05 -07:00
|
|
|
Element *bodyElement = document->GetBodyElement();
|
|
|
|
if (bodyElement)
|
|
|
|
root = bodyElement; // we can trust the document to hold on to it
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (root) {
|
2009-12-24 13:20:06 -08:00
|
|
|
nsIFrame *rootsFrame = root->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rootsFrame)
|
|
|
|
frame = rootsFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
return frame->StyleVisibility()->mDirection != NS_STYLE_DIRECTION_RTL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::IsScrollbarOnRight() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext *presContext = mOuter->PresContext();
|
2010-04-08 09:11:14 -07:00
|
|
|
|
|
|
|
// The position of the scrollbar in top-level windows depends on the pref
|
|
|
|
// layout.scrollbar.side. For non-top-level elements, it depends only on the
|
|
|
|
// directionaliy of the element (equivalent to a value of "1" for the pref).
|
|
|
|
if (!mIsRoot)
|
|
|
|
return IsLTR();
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (presContext->GetCachedIntPref(kPresContext_ScrollbarSide)) {
|
|
|
|
default:
|
|
|
|
case 0: // UI directionality
|
|
|
|
return presContext->GetCachedIntPref(kPresContext_BidiDirection)
|
|
|
|
== IBMBIDI_TEXTDIRECTION_LTR;
|
|
|
|
case 1: // Document / content directionality
|
|
|
|
return IsLTR();
|
|
|
|
case 2: // Always right
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
case 3: // Always left
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reflow the scroll area if it needs it and return its size. Also determine if the reflow will
|
|
|
|
* cause any of the scrollbars to need to be reflowed.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsXULScrollFrame::Layout(nsBoxLayoutState& aState)
|
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
bool scrollbarRight = mHelper.IsScrollbarOnRight();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool scrollbarBottom = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the content rect
|
|
|
|
nsRect clientRect(0,0,0,0);
|
|
|
|
GetClientRect(clientRect);
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRect oldScrollAreaBounds = mHelper.mScrollPort;
|
|
|
|
nsPoint oldScrollPosition = mHelper.GetLogicalScrollPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// the scroll area size starts off as big as our content area
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mScrollPort = clientRect;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**************
|
|
|
|
Our basic strategy here is to first try laying out the content with
|
|
|
|
the scrollbars in their current state. We're hoping that that will
|
|
|
|
just "work"; the content will overflow wherever there's a scrollbar
|
|
|
|
already visible. If that does work, then there's no need to lay out
|
|
|
|
the scrollarea. Otherwise we fix up the scrollbars; first we add a
|
|
|
|
vertical one to scroll the content if necessary, or remove it if
|
|
|
|
it's not needed. Then we reflow the content if the scrollbar
|
|
|
|
changed. Then we add a horizontal scrollbar if necessary (or
|
|
|
|
remove if not needed), and if that changed, we reflow the content
|
|
|
|
again. At this point, any scrollbars that are needed to scroll the
|
|
|
|
content have been added.
|
|
|
|
|
|
|
|
In the second phase we check to see if any scrollbars are too small
|
|
|
|
to display, and if so, we remove them. We check the horizontal
|
|
|
|
scrollbar first; removing it might make room for the vertical
|
|
|
|
scrollbar, and if we have room for just one scrollbar we'll save
|
|
|
|
the vertical one.
|
|
|
|
|
|
|
|
Finally we position and size the scrollbars and scrollcorner (the
|
|
|
|
square that is needed in the corner of the window when two
|
|
|
|
scrollbars are visible), and reflow any fixed position views
|
|
|
|
(if we're the viewport and we added or removed a scrollbar).
|
|
|
|
**************/
|
|
|
|
|
|
|
|
ScrollbarStyles styles = GetScrollbarStyles();
|
|
|
|
|
|
|
|
// Look at our style do we always have vertical or horizontal scrollbars?
|
|
|
|
if (styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL)
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHasHorizontalScrollbar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (styles.mVertical == NS_STYLE_OVERFLOW_SCROLL)
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHasVerticalScrollbar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasHorizontalScrollbar)
|
2009-10-07 20:01:15 -07:00
|
|
|
AddHorizontalScrollbar(aState, scrollbarBottom);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasVerticalScrollbar)
|
2009-10-07 20:01:15 -07:00
|
|
|
AddVerticalScrollbar(aState, scrollbarRight);
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// layout our the scroll area
|
2009-10-07 20:01:15 -07:00
|
|
|
LayoutScrollArea(aState, oldScrollPosition);
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// now look at the content area and see if we need scrollbars or not
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needsLayout = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if we have 'auto' scrollbars look at the vertical case
|
|
|
|
if (styles.mVertical != NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
// These are only good until the call to LayoutScrollArea.
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRect scrolledRect = mHelper.GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// There are two cases to consider
|
2013-10-28 19:27:50 -07:00
|
|
|
if (scrolledRect.height <= mHelper.mScrollPort.height
|
2007-03-22 10:30:00 -07:00
|
|
|
|| styles.mVertical != NS_STYLE_OVERFLOW_AUTO) {
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasVerticalScrollbar) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We left room for the vertical scrollbar, but it's not needed;
|
|
|
|
// remove it.
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveVerticalScrollbar(aState, scrollbarRight);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mHasVerticalScrollbar) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We didn't leave room for the vertical scrollbar, but it turns
|
|
|
|
// out we needed it
|
2009-10-07 20:01:15 -07:00
|
|
|
if (AddVerticalScrollbar(aState, scrollbarRight))
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok layout at the right size
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
2009-10-07 20:01:15 -07:00
|
|
|
LayoutScrollArea(resizeState, oldScrollPosition);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if scrollbars are auto look at the horizontal case
|
|
|
|
if (styles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL)
|
|
|
|
{
|
|
|
|
// These are only good until the call to LayoutScrollArea.
|
2013-10-28 19:27:50 -07:00
|
|
|
nsRect scrolledRect = mHelper.GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if the child is wider that the scroll area
|
|
|
|
// and we don't have a scrollbar add one.
|
2013-10-28 19:27:50 -07:00
|
|
|
if ((scrolledRect.width > mHelper.mScrollPort.width)
|
2007-03-22 10:30:00 -07:00
|
|
|
&& styles.mHorizontal == NS_STYLE_OVERFLOW_AUTO) {
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mHasHorizontalScrollbar) {
|
2013-03-04 12:57:01 -08:00
|
|
|
// no scrollbar?
|
2009-10-07 20:01:15 -07:00
|
|
|
if (AddHorizontalScrollbar(aState, scrollbarBottom))
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-18 22:32:50 -07:00
|
|
|
// if we added a horizontal scrollbar and we did not have a vertical
|
|
|
|
// there is a chance that by adding the horizontal scrollbar we will
|
2013-03-04 12:57:01 -08:00
|
|
|
// suddenly need a vertical scrollbar. Is a special case but its
|
2007-03-22 10:30:00 -07:00
|
|
|
// important.
|
2011-02-06 23:59:20 -08:00
|
|
|
//if (!mHasVerticalScrollbar && scrolledRect.height > scrollAreaRect.height - sbSize.height)
|
2007-03-22 10:30:00 -07:00
|
|
|
// printf("****Gfx Scrollbar Special case hit!!*****\n");
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if the area is smaller or equal to and we have a scrollbar then
|
|
|
|
// remove it.
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasHorizontalScrollbar) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveHorizontalScrollbar(aState, scrollbarBottom);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we only need to set the rect. The inner child stays the same size.
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
2009-10-07 20:01:15 -07:00
|
|
|
LayoutScrollArea(resizeState, oldScrollPosition);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// get the preferred size of the scrollbars
|
|
|
|
nsSize hMinSize(0, 0);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHScrollbarBox && mHelper.mHasHorizontalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mHelper.mHScrollbarBox, &hMinSize, nullptr, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsSize vMinSize(0, 0);
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mVScrollbarBox && mHelper.mHasVerticalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mHelper.mVScrollbarBox, &vMinSize, nullptr, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable scrollbars that are too small
|
|
|
|
// Disable horizontal scrollbar first. If we have to disable only one
|
|
|
|
// scrollbar, we'd rather keep the vertical scrollbar.
|
|
|
|
// Note that we always give horizontal scrollbars their preferred height,
|
|
|
|
// never their min-height. So check that there's room for the preferred height.
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasHorizontalScrollbar &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(hMinSize.width > clientRect.width - vMinSize.width
|
|
|
|
|| hMinSize.height > clientRect.height)) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveHorizontalScrollbar(aState, scrollbarBottom);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Now disable vertical scrollbar if necessary
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper.mHasVerticalScrollbar &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(vMinSize.height > clientRect.height - hMinSize.height
|
|
|
|
|| vMinSize.width > clientRect.width)) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveVerticalScrollbar(aState, scrollbarRight);
|
2011-10-17 07:59:28 -07:00
|
|
|
needsLayout = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// we only need to set the rect. The inner child stays the same size.
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
2009-10-07 20:01:15 -07:00
|
|
|
LayoutScrollArea(resizeState, oldScrollPosition);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mSupppressScrollbarUpdate) {
|
|
|
|
mHelper.LayoutScrollbars(aState, clientRect, oldScrollAreaBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-10-28 19:27:50 -07:00
|
|
|
if (!mHelper.mPostedReflowCallback) {
|
2009-06-23 18:35:00 -07:00
|
|
|
// Make sure we'll try scrolling to restored position
|
2013-10-28 19:27:50 -07:00
|
|
|
PresContext()->PresShell()->PostReflowCallback(&mHelper);
|
|
|
|
mHelper.mPostedReflowCallback = true;
|
2009-06-23 18:35:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.mHadNonInitialReflow = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.UpdateSticky();
|
2013-09-06 06:35:16 -07:00
|
|
|
|
2012-01-27 19:35:59 -08:00
|
|
|
// Set up overflow areas for block frames for the benefit of
|
|
|
|
// text-overflow.
|
2013-10-28 19:27:50 -07:00
|
|
|
nsIFrame* f = mHelper.mScrolledFrame->GetContentInsertionFrame();
|
2012-01-27 19:35:59 -08:00
|
|
|
if (nsLayoutUtils::GetAsBlock(f)) {
|
|
|
|
nsRect origRect = f->GetRect();
|
|
|
|
nsRect clippedRect = origRect;
|
2013-10-28 19:27:50 -07:00
|
|
|
clippedRect.MoveBy(mHelper.mScrollPort.TopLeft());
|
|
|
|
clippedRect.IntersectRect(clippedRect, mHelper.mScrollPort);
|
2012-01-27 19:35:59 -08:00
|
|
|
nsOverflowAreas overflow = f->GetOverflowAreas();
|
|
|
|
f->FinishAndStoreOverflow(overflow, clippedRect.Size());
|
|
|
|
clippedRect.MoveTo(origRect.TopLeft());
|
|
|
|
f->SetRect(clippedRect);
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:27:50 -07:00
|
|
|
mHelper.PostOverflowEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::FinishReflowForScrollbar(nsIContent* aContent,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord aMinXY, nscoord aMaxXY,
|
|
|
|
nscoord aCurPosXY,
|
|
|
|
nscoord aPageIncrement,
|
|
|
|
nscoord aIncrement)
|
|
|
|
{
|
|
|
|
// Scrollbars assume zero is the minimum position, so translate for them.
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::curpos, aCurPosXY - aMinXY);
|
|
|
|
SetScrollbarEnabled(aContent, aMaxXY - aMinXY);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::maxpos, aMaxXY - aMinXY);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::pageincrement, aPageIncrement);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::increment, aIncrement);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ReflowFinished()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-22 16:08:59 -07:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-10-17 07:59:28 -07:00
|
|
|
mPostedReflowCallback = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-23 18:35:00 -07:00
|
|
|
ScrollToRestoredPosition();
|
|
|
|
|
2012-02-07 16:53:18 -08:00
|
|
|
// Clamp current scroll position to new bounds. Normally this won't
|
|
|
|
// do anything.
|
|
|
|
nsPoint currentScrollPos = GetScrollPosition();
|
|
|
|
ScrollToImpl(currentScrollPos, nsRect(currentScrollPos, nsSize(0, 0)));
|
2012-05-09 22:24:20 -07:00
|
|
|
if (!mAsyncScroll) {
|
|
|
|
// We need to have mDestination track the current scroll position,
|
|
|
|
// in case it falls outside the new reflow area. mDestination is used
|
|
|
|
// by ScrollBy as its starting position.
|
|
|
|
mDestination = GetScrollPosition();
|
|
|
|
}
|
2010-03-28 18:46:59 -07:00
|
|
|
|
2009-06-23 18:35:00 -07:00
|
|
|
if (NS_SUBTREE_DIRTY(mOuter) || !mUpdateScrollbarAttributes)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-06-11 18:46:33 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mUpdateScrollbarAttributes = false;
|
2009-06-23 18:35:00 -07:00
|
|
|
|
2009-06-11 18:46:33 -07:00
|
|
|
// Update scrollbar attributes.
|
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
|
|
|
|
2007-12-20 15:49:46 -08:00
|
|
|
if (mMayHaveDirtyFixedChildren) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mMayHaveDirtyFixedChildren = false;
|
2007-12-20 15:49:46 -08:00
|
|
|
nsIFrame* parentFrame = mOuter->GetParent();
|
|
|
|
for (nsIFrame* fixedChild =
|
2011-08-24 13:54:30 -07:00
|
|
|
parentFrame->GetFirstChild(nsIFrame::kFixedList);
|
2007-12-20 15:49:46 -08:00
|
|
|
fixedChild; fixedChild = fixedChild->GetNextSibling()) {
|
|
|
|
// force a reflow of the fixed child
|
2009-06-11 18:46:33 -07:00
|
|
|
presContext->PresShell()->
|
2007-12-20 15:49:46 -08:00
|
|
|
FrameNeedsReflow(fixedChild, nsIPresShell::eResize,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledContentRect = GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord minX = scrolledContentRect.x;
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord maxX = scrolledContentRect.XMost() - mScrollPort.width;
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord minY = scrolledContentRect.y;
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord maxY = scrolledContentRect.YMost() - mScrollPort.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Suppress handling of the curpos attribute changes we make here.
|
2009-10-07 20:01:15 -07:00
|
|
|
NS_ASSERTION(!mFrameIsUpdatingScrollbar, "We shouldn't be reentering here");
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrameIsUpdatingScrollbar = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> vScroll =
|
2012-07-30 07:20:58 -07:00
|
|
|
mVScrollbarBox ? mVScrollbarBox->GetContent() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> hScroll =
|
2012-07-30 07:20:58 -07:00
|
|
|
mHScrollbarBox ? mHScrollbarBox->GetContent() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Note, in some cases mOuter may get deleted while finishing reflow
|
2013-08-08 15:04:59 -07:00
|
|
|
// for scrollbars. XXXmats is this still true now that we have a script
|
|
|
|
// blocker in this scope? (if not, remove the weak frame checks below).
|
2007-03-22 10:30:00 -07:00
|
|
|
if (vScroll || hScroll) {
|
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint scrollPos = GetScrollPosition();
|
2012-10-28 22:44:31 -07:00
|
|
|
nsSize lineScrollAmount = GetLineScrollAmount();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (vScroll) {
|
2012-10-28 22:44:31 -07:00
|
|
|
const double kScrollMultiplier =
|
|
|
|
Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
|
|
|
|
NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
|
2012-10-28 22:44:31 -07:00
|
|
|
nscoord increment = lineScrollAmount.height * kScrollMultiplier;
|
|
|
|
// We normally use (scrollArea.height - increment) for height
|
2008-02-23 23:35:08 -08:00
|
|
|
// of page scrolling. However, it is too small when
|
2012-10-28 22:44:31 -07:00
|
|
|
// increment is very large. (If increment is larger than
|
2008-02-23 23:35:08 -08:00
|
|
|
// scrollArea.height, direction of scrolling will be opposite).
|
|
|
|
// To avoid it, we use (float(scrollArea.height) * 0.8) as
|
|
|
|
// lower bound value of height of page scrolling. (bug 383267)
|
2012-10-28 22:44:31 -07:00
|
|
|
// XXX shouldn't we use GetPageScrollAmount here?
|
2012-10-28 22:44:31 -07:00
|
|
|
nscoord pageincrement = nscoord(mScrollPort.height - increment);
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord pageincrementMin = nscoord(float(mScrollPort.height) * 0.8);
|
|
|
|
FinishReflowForScrollbar(vScroll, minY, maxY, scrollPos.y,
|
2013-01-15 04:22:03 -08:00
|
|
|
std::max(pageincrement, pageincrementMin),
|
2012-10-28 22:44:31 -07:00
|
|
|
increment);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (hScroll) {
|
2012-10-28 22:44:31 -07:00
|
|
|
const double kScrollMultiplier =
|
|
|
|
Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
|
|
|
|
NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
|
|
|
|
nscoord increment = lineScrollAmount.width * kScrollMultiplier;
|
2009-10-07 20:01:15 -07:00
|
|
|
FinishReflowForScrollbar(hScroll, minX, maxX, scrollPos.x,
|
|
|
|
nscoord(float(mScrollPort.width) * 0.8),
|
2012-10-28 22:44:31 -07:00
|
|
|
increment);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mFrameIsUpdatingScrollbar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// We used to rely on the curpos attribute changes above to scroll the
|
|
|
|
// view. However, for scrolling to the left of the viewport, we
|
|
|
|
// rescale the curpos attribute, which means that operations like
|
|
|
|
// resizing the window while it is scrolled all the way to the left
|
|
|
|
// hold the curpos attribute constant at 0 while still requiring
|
|
|
|
// scrolling. So we suppress the effect of the changes above with
|
2009-10-07 20:01:15 -07:00
|
|
|
// mFrameIsUpdatingScrollbar and call CurPosAttributeChanged here.
|
2007-03-22 10:30:00 -07:00
|
|
|
// (It actually even works some of the time without this, thanks to
|
|
|
|
// nsSliderFrame::AttributeChanged's handling of maxpos, but not when
|
|
|
|
// we hide the scrollbar on a large size change, such as
|
|
|
|
// maximization.)
|
|
|
|
if (!mHScrollbarBox && !mVScrollbarBox)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
CurPosAttributeChanged(mVScrollbarBox ? mVScrollbarBox->GetContent()
|
|
|
|
: mHScrollbarBox->GetContent());
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-30 23:22:44 -08:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ReflowCallbackCanceled()
|
2007-11-30 23:22:44 -08:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mPostedReflowCallback = false;
|
2007-11-30 23:22:44 -08:00
|
|
|
}
|
|
|
|
|
2011-06-15 14:03:49 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::UpdateOverflow()
|
2011-06-15 14:03:49 -07:00
|
|
|
{
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(mOuter);
|
|
|
|
ScrollbarStyles ss = sf->GetScrollbarStyles();
|
|
|
|
|
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
GetScrollPosition() != nsPoint()) {
|
|
|
|
// If there are scrollbars, or we're not at the beginning of the pane,
|
|
|
|
// the scroll position may change. In this case, mark the frame as
|
2013-10-17 03:05:15 -07:00
|
|
|
// needing reflow. Don't use NS_FRAME_IS_DIRTY as dirty as that means
|
|
|
|
// we have to reflow the frame and all its descendants, and we don't
|
|
|
|
// have to do that here. Only this frame needs to be reflowed.
|
2011-06-15 14:03:49 -07:00
|
|
|
mOuter->PresContext()->PresShell()->FrameNeedsReflow(
|
2013-10-17 03:05:15 -07:00
|
|
|
mOuter, nsIPresShell::eResize, NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
// Ensure that next time nsHTMLScrollFrame::Reflow runs, we don't skip
|
|
|
|
// updating the scrollbars. (Because the overflow area of the scrolled
|
|
|
|
// frame has probably just been updated, Reflow won't see it change.)
|
|
|
|
mSkippedScrollbarLayout = true;
|
2013-08-10 09:55:29 -07:00
|
|
|
return false; // reflowing will update overflow
|
2011-06-15 14:03:49 -07:00
|
|
|
}
|
2013-08-10 09:55:29 -07:00
|
|
|
return mOuter->nsContainerFrame::UpdateOverflow();
|
2011-06-15 14:03:49 -07:00
|
|
|
}
|
|
|
|
|
2013-09-06 06:35:16 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::UpdateSticky()
|
2013-09-06 06:35:16 -07:00
|
|
|
{
|
|
|
|
StickyScrollContainer* ssc = StickyScrollContainer::
|
|
|
|
GetStickyScrollContainerForScrollFrame(mOuter);
|
|
|
|
if (ssc) {
|
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(mOuter);
|
|
|
|
ssc->UpdatePositions(scrollFrame->GetScrollPosition(), mOuter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::AdjustScrollbarRectForResizer(
|
2010-03-19 04:49:34 -07:00
|
|
|
nsIFrame* aFrame, nsPresContext* aPresContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsRect& aRect, bool aHasResizer, bool aVertical)
|
2008-08-08 09:11:54 -07:00
|
|
|
{
|
|
|
|
if ((aVertical ? aRect.width : aRect.height) == 0)
|
|
|
|
return;
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
// if a content resizer is present, use its size. Otherwise, check if the
|
|
|
|
// widget has a resizer.
|
|
|
|
nsRect resizerRect;
|
2011-01-17 06:35:32 -08:00
|
|
|
if (aHasResizer) {
|
|
|
|
resizerRect = mResizerBox->GetRect();
|
2010-03-19 04:49:34 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-07-18 19:23:48 -07:00
|
|
|
nsPoint offset;
|
|
|
|
nsIWidget* widget = aFrame->GetNearestWidget(offset);
|
2010-03-19 04:49:34 -07:00
|
|
|
nsIntRect widgetRect;
|
|
|
|
if (!widget || !widget->ShowsResizeIndicator(&widgetRect))
|
|
|
|
return;
|
2008-08-08 09:11:54 -07:00
|
|
|
|
2010-03-23 11:55:35 -07:00
|
|
|
resizerRect = nsRect(aPresContext->DevPixelsToAppUnits(widgetRect.x) - offset.x,
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.y) - offset.y,
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.width),
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.height));
|
2010-03-19 04:49:34 -07:00
|
|
|
}
|
2008-08-08 09:11:54 -07:00
|
|
|
|
2009-10-04 19:14:38 -07:00
|
|
|
if (!resizerRect.Contains(aRect.BottomRight() - nsPoint(1, 1)))
|
2008-08-08 09:11:54 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (aVertical)
|
2013-01-15 04:22:03 -08:00
|
|
|
aRect.height = std::max(0, resizerRect.y - aRect.y);
|
2008-08-08 09:11:54 -07:00
|
|
|
else
|
2013-01-15 04:22:03 -08:00
|
|
|
aRect.width = std::max(0, resizerRect.x - aRect.x);
|
2008-08-08 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
static void
|
|
|
|
AdjustOverlappingScrollbars(nsRect& aVRect, nsRect& aHRect)
|
|
|
|
{
|
|
|
|
if (aVRect.IsEmpty() || aHRect.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const nsRect oldVRect = aVRect;
|
|
|
|
const nsRect oldHRect = aHRect;
|
|
|
|
if (oldVRect.Contains(oldHRect.BottomRight() - nsPoint(1, 1))) {
|
|
|
|
aHRect.width = std::max(0, oldVRect.x - oldHRect.x);
|
|
|
|
} else if (oldVRect.Contains(oldHRect.BottomLeft() - nsPoint(0, 1))) {
|
|
|
|
nscoord overlap = std::min(oldHRect.width, oldVRect.XMost() - oldHRect.x);
|
|
|
|
aHRect.x += overlap;
|
|
|
|
aHRect.width -= overlap;
|
|
|
|
}
|
|
|
|
if (oldHRect.Contains(oldVRect.BottomRight() - nsPoint(1, 1))) {
|
|
|
|
aVRect.height = std::max(0, oldHRect.y - oldVRect.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::LayoutScrollbars(nsBoxLayoutState& aState,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aContentArea,
|
2009-10-07 20:01:15 -07:00
|
|
|
const nsRect& aOldScrollArea)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mSupppressScrollbarUpdate,
|
|
|
|
"This should have been suppressed");
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasResizer = HasResizer();
|
|
|
|
bool scrollbarOnLeft = !IsScrollbarOnRight();
|
2010-03-19 04:49:34 -07:00
|
|
|
|
|
|
|
// place the scrollcorner
|
2011-01-17 06:35:32 -08:00
|
|
|
if (mScrollCornerBox || mResizerBox) {
|
|
|
|
NS_PRECONDITION(!mScrollCornerBox || mScrollCornerBox->IsBoxFrame(), "Must be a box frame!");
|
2010-03-19 04:49:34 -07:00
|
|
|
|
|
|
|
nsRect r(0, 0, 0, 0);
|
|
|
|
if (aContentArea.x != mScrollPort.x || scrollbarOnLeft) {
|
|
|
|
// scrollbar (if any) on left
|
|
|
|
r.x = aContentArea.x;
|
2011-01-17 06:35:32 -08:00
|
|
|
r.width = mScrollPort.x - aContentArea.x;
|
2010-03-19 04:49:34 -07:00
|
|
|
NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
|
|
|
|
} else {
|
|
|
|
// scrollbar (if any) on right
|
2011-01-17 06:35:32 -08:00
|
|
|
r.width = aContentArea.XMost() - mScrollPort.XMost();
|
2010-03-19 04:49:34 -07:00
|
|
|
r.x = aContentArea.XMost() - r.width;
|
|
|
|
NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
|
|
|
|
}
|
|
|
|
if (aContentArea.y != mScrollPort.y) {
|
|
|
|
NS_ERROR("top scrollbars not supported");
|
|
|
|
} else {
|
|
|
|
// scrollbar (if any) on bottom
|
2011-01-17 06:35:32 -08:00
|
|
|
r.height = aContentArea.YMost() - mScrollPort.YMost();
|
2010-03-19 04:49:34 -07:00
|
|
|
r.y = aContentArea.YMost() - r.height;
|
|
|
|
NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
|
|
|
|
}
|
2011-01-17 06:35:32 -08:00
|
|
|
|
|
|
|
if (mScrollCornerBox) {
|
2012-08-28 22:39:31 -07:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mScrollCornerBox, r);
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasResizer) {
|
|
|
|
// if a resizer is present, get its size. Assume a default size of 15 pixels.
|
|
|
|
nscoord defaultSize = nsPresContext::CSSPixelsToAppUnits(15);
|
2013-05-02 07:58:00 -07:00
|
|
|
nsSize resizerMinSize = mResizerBox->GetMinSize(aState);
|
|
|
|
|
|
|
|
nscoord vScrollbarWidth = mVScrollbarBox ?
|
2013-02-19 14:03:48 -08:00
|
|
|
mVScrollbarBox->GetPrefSize(aState).width : defaultSize;
|
2013-05-02 07:58:00 -07:00
|
|
|
r.width = std::max(std::max(r.width, vScrollbarWidth), resizerMinSize.width);
|
|
|
|
if (aContentArea.x == mScrollPort.x && !scrollbarOnLeft) {
|
|
|
|
r.x = aContentArea.XMost() - r.width;
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
nscoord hScrollbarHeight = mHScrollbarBox ?
|
2013-02-19 14:03:48 -08:00
|
|
|
mHScrollbarBox->GetPrefSize(aState).height : defaultSize;
|
2013-05-02 07:58:00 -07:00
|
|
|
r.height = std::max(std::max(r.height, hScrollbarHeight), resizerMinSize.height);
|
|
|
|
if (aContentArea.y == mScrollPort.y) {
|
|
|
|
r.y = aContentArea.YMost() - r.height;
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
|
2012-08-28 22:39:31 -07:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mResizerBox, r);
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
|
|
|
else if (mResizerBox) {
|
|
|
|
// otherwise lay out the resizer with an empty rectangle
|
2012-08-28 22:39:31 -07:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mResizerBox, nsRect());
|
2011-01-17 06:35:32 -08:00
|
|
|
}
|
2010-03-19 04:49:34 -07:00
|
|
|
}
|
|
|
|
|
2008-08-08 09:11:54 -07:00
|
|
|
nsPresContext* presContext = mScrolledFrame->PresContext();
|
2013-05-02 07:58:00 -07:00
|
|
|
nsRect vRect;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mVScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
2013-05-02 07:58:00 -07:00
|
|
|
vRect = mScrollPort;
|
2009-10-07 20:01:15 -07:00
|
|
|
vRect.width = aContentArea.width - mScrollPort.width;
|
2010-03-19 04:49:34 -07:00
|
|
|
vRect.x = scrollbarOnLeft ? aContentArea.x : mScrollPort.XMost();
|
2012-08-03 03:35:14 -07:00
|
|
|
if (mHasVerticalScrollbar) {
|
|
|
|
nsMargin margin;
|
|
|
|
mVScrollbarBox->GetMargin(margin);
|
|
|
|
vRect.Deflate(margin);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
AdjustScrollbarRectForResizer(mOuter, presContext, vRect, hasResizer, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
nsRect hRect;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mHScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
2013-05-02 07:58:00 -07:00
|
|
|
hRect = mScrollPort;
|
2009-10-07 20:01:15 -07:00
|
|
|
hRect.height = aContentArea.height - mScrollPort.height;
|
2011-10-17 07:59:28 -07:00
|
|
|
hRect.y = true ? mScrollPort.YMost() : aContentArea.y;
|
2012-08-03 03:35:14 -07:00
|
|
|
if (mHasHorizontalScrollbar) {
|
|
|
|
nsMargin margin;
|
|
|
|
mHScrollbarBox->GetMargin(margin);
|
|
|
|
hRect.Deflate(margin);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
AdjustScrollbarRectForResizer(mOuter, presContext, hRect, hasResizer, false);
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-23 14:14:00 -07:00
|
|
|
if (!LookAndFeel::GetInt(LookAndFeel::eIntID_AllowOverlayScrollbarsOverlap)) {
|
|
|
|
AdjustOverlappingScrollbars(vRect, hRect);
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
if (mVScrollbarBox) {
|
|
|
|
nsBoxFrame::LayoutChildAt(aState, mVScrollbarBox, vRect);
|
|
|
|
}
|
|
|
|
if (mHScrollbarBox) {
|
2012-08-28 22:39:31 -07:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mHScrollbarBox, hRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// may need to update fixed position children of the viewport,
|
|
|
|
// if the client area changed size because of an incremental
|
|
|
|
// reflow of a descendant. (If the outer frame is dirty, the fixed
|
|
|
|
// children will be re-laid out anyway)
|
2013-03-04 12:57:01 -08:00
|
|
|
if (aOldScrollArea.Size() != mScrollPort.Size() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!(mOuter->GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
|
|
|
mIsRoot) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mMayHaveDirtyFixedChildren = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-04 12:57:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// post reflow callback to modify scrollbar attributes
|
2011-10-17 07:59:28 -07:00
|
|
|
mUpdateScrollbarAttributes = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mPostedReflowCallback) {
|
|
|
|
aState.PresContext()->PresShell()->PostReflowCallback(this);
|
2011-10-17 07:59:28 -07:00
|
|
|
mPostedReflowCallback = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
#if DEBUG
|
|
|
|
static bool ShellIsAlive(nsWeakPtr& aWeakPtr)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aWeakPtr));
|
|
|
|
return !!shell;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-08 15:04:59 -07:00
|
|
|
DebugOnly<nsWeakPtr> weakShell(
|
|
|
|
do_GetWeakReference(mOuter->PresContext()->PresShell()));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aMaxPos) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-08-08 15:04:59 -07:00
|
|
|
MOZ_ASSERT(ShellIsAlive(weakShell), "pres shell was destroyed by scrolling");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord aSize)
|
|
|
|
{
|
2013-08-08 15:04:59 -07:00
|
|
|
DebugOnly<nsWeakPtr> weakShell(
|
|
|
|
do_GetWeakReference(mOuter->PresContext()->PresShell()));
|
2007-03-22 10:30:00 -07:00
|
|
|
// convert to pixels
|
|
|
|
aSize = nsPresContext::AppUnitsToIntCSSPixels(aSize);
|
|
|
|
|
|
|
|
// only set the attribute if it changed.
|
|
|
|
|
|
|
|
nsAutoString newValue;
|
|
|
|
newValue.AppendInt(aSize);
|
|
|
|
|
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, aAtom, newValue, eCaseMatters))
|
|
|
|
return;
|
|
|
|
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(mOuter);
|
|
|
|
nsCOMPtr<nsIContent> kungFuDeathGrip = aContent;
|
2011-10-17 07:59:28 -07:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, aAtom, newValue, true);
|
2013-08-08 15:04:59 -07:00
|
|
|
MOZ_ASSERT(ShellIsAlive(weakShell), "pres shell was destroyed by scrolling");
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
if (mScrollbarActivity) {
|
2013-07-31 18:43:56 -07:00
|
|
|
nsRefPtr<ScrollbarActivity> scrollbarActivity(mScrollbarActivity);
|
|
|
|
scrollbarActivity->ActivityOccurred();
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:20:35 -07:00
|
|
|
static void
|
|
|
|
ReduceRadii(nscoord aXBorder, nscoord aYBorder,
|
|
|
|
nscoord& aXRadius, nscoord& aYRadius)
|
|
|
|
{
|
|
|
|
// In order to ensure that the inside edge of the border has no
|
|
|
|
// curvature, we need at least one of its radii to be zero.
|
|
|
|
if (aXRadius <= aXBorder || aYRadius <= aYBorder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// For any corner where we reduce the radii, preserve the corner's shape.
|
2013-01-15 04:22:03 -08:00
|
|
|
double ratio = std::max(double(aXBorder) / aXRadius,
|
2010-09-07 15:20:35 -07:00
|
|
|
double(aYBorder) / aYRadius);
|
|
|
|
aXRadius *= ratio;
|
|
|
|
aYRadius *= ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement an override for nsIFrame::GetBorderRadii to ensure that
|
|
|
|
* the clipping region for the border radius does not clip the scrollbars.
|
|
|
|
*
|
|
|
|
* In other words, we require that the border radius be reduced until the
|
|
|
|
* inner border radius at the inner edge of the border is 0 wherever we
|
|
|
|
* have scrollbars.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetBorderRadii(nscoord aRadii[8]) const
|
2010-09-07 15:20:35 -07:00
|
|
|
{
|
|
|
|
if (!mOuter->nsContainerFrame::GetBorderRadii(aRadii))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-09-07 15:20:35 -07:00
|
|
|
|
|
|
|
// Since we can use GetActualScrollbarSizes (rather than
|
|
|
|
// GetDesiredScrollbarSizes) since this doesn't affect reflow, we
|
|
|
|
// probably should.
|
|
|
|
nsMargin sb = GetActualScrollbarSizes();
|
|
|
|
nsMargin border = mOuter->GetUsedBorder();
|
|
|
|
|
|
|
|
if (sb.left > 0 || sb.top > 0) {
|
|
|
|
ReduceRadii(border.left, border.top,
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_Y]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.top > 0 || sb.right > 0) {
|
|
|
|
ReduceRadii(border.right, border.top,
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_Y]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.right > 0 || sb.bottom > 0) {
|
|
|
|
ReduceRadii(border.right, border.bottom,
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb.bottom > 0 || sb.left > 0) {
|
|
|
|
ReduceRadii(border.left, border.bottom,
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_Y]);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-09-07 15:20:35 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrolledRect() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect result =
|
2010-10-06 21:25:47 -07:00
|
|
|
GetScrolledRectInternal(mScrolledFrame->GetScrollableOverflowRect(),
|
2009-10-07 20:01:15 -07:00
|
|
|
mScrollPort.Size());
|
|
|
|
|
2013-06-05 20:47:39 -07:00
|
|
|
if (result.width < mScrollPort.width) {
|
|
|
|
NS_WARNING("Scrolled rect smaller than scrollport?");
|
|
|
|
}
|
|
|
|
if (result.height < mScrollPort.height) {
|
|
|
|
NS_WARNING("Scrolled rect smaller than scrollport?");
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetScrolledRectInternal(const nsRect& aScrolledFrameOverflowArea,
|
2009-10-07 20:01:15 -07:00
|
|
|
const nsSize& aScrollPortSize) const
|
|
|
|
{
|
2013-01-28 17:38:22 -08:00
|
|
|
return nsLayoutUtils::GetScrolledRect(mScrolledFrame,
|
|
|
|
aScrolledFrameOverflowArea, aScrollPortSize,
|
|
|
|
IsLTR() ? NS_STYLE_DIRECTION_LTR : NS_STYLE_DIRECTION_RTL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetActualScrollbarSizes() const
|
2010-01-13 04:57:00 -08:00
|
|
|
{
|
2010-04-02 15:25:40 -07:00
|
|
|
nsRect r = mOuter->GetPaddingRect() - mOuter->GetPosition();
|
|
|
|
|
2013-03-06 00:05:55 -08:00
|
|
|
return nsMargin(mScrollPort.y - r.y,
|
2010-04-02 15:25:40 -07:00
|
|
|
r.XMost() - mScrollPort.XMost(),
|
2013-03-06 00:05:55 -08:00
|
|
|
r.YMost() - mScrollPort.YMost(),
|
|
|
|
mScrollPort.x - r.x);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::SetScrollbarVisibility(nsIFrame* aScrollbar, bool aVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-07-11 07:05:09 -07:00
|
|
|
nsScrollbarFrame* scrollbar = do_QueryFrame(aScrollbar);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (scrollbar) {
|
|
|
|
// See if we have a mediator.
|
|
|
|
nsIScrollbarMediator* mediator = scrollbar->GetScrollbarMediator();
|
|
|
|
if (mediator) {
|
|
|
|
// Inform the mediator of the visibility change.
|
2009-01-12 11:20:59 -08:00
|
|
|
mediator->VisibilityChanged(aVisible);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:24:19 -07:00
|
|
|
nscoord
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::GetCoordAttribute(nsIFrame* aBox, nsIAtom* aAtom,
|
2012-05-09 22:24:19 -07:00
|
|
|
nscoord aDefaultValue,
|
|
|
|
nscoord* aRangeStart,
|
|
|
|
nscoord* aRangeLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aBox) {
|
|
|
|
nsIContent* content = aBox->GetContent();
|
|
|
|
|
|
|
|
nsAutoString value;
|
2012-05-09 22:24:19 -07:00
|
|
|
content->GetAttr(kNameSpaceID_None, aAtom, value);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!value.IsEmpty())
|
|
|
|
{
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult error;
|
2012-05-09 22:24:19 -07:00
|
|
|
// convert it to appunits
|
|
|
|
nscoord result = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
|
|
|
nscoord halfPixel = nsPresContext::CSSPixelsToAppUnits(0.5f);
|
|
|
|
// Any nscoord value that would round to the attribute value when converted
|
|
|
|
// to CSS pixels is allowed.
|
|
|
|
*aRangeStart = result - halfPixel;
|
|
|
|
*aRangeLength = halfPixel*2 - 1;
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 22:24:19 -07:00
|
|
|
// Only this exact default value is allowed.
|
|
|
|
*aRangeStart = aDefaultValue;
|
|
|
|
*aRangeLength = 0;
|
|
|
|
return aDefaultValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresState*
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::SaveState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollbarMediator* mediator = do_QueryFrame(GetScrolledFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mediator) {
|
|
|
|
// child handles its own scroll state, so don't bother saving state here
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-22 05:49:49 -07:00
|
|
|
// Don't store a scroll state if we never have been scrolled or restored
|
|
|
|
// a previous scroll state.
|
|
|
|
if (!mHasBeenScrolled && !mDidHistoryRestore) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2008-12-12 11:25:22 -08:00
|
|
|
nsPresState* state = new nsPresState();
|
2013-03-20 19:44:37 -07:00
|
|
|
// Save mRestorePos instead of our actual current scroll position, if it's
|
|
|
|
// valid and we haven't moved since the last update of mLastPos (same check
|
|
|
|
// that ScrollToRestoredPosition uses). This ensures if a reframe occurs
|
|
|
|
// while we're in the process of loading content to scroll to a restored
|
|
|
|
// position, we'll keep trying after the reframe.
|
|
|
|
nsPoint pt = GetLogicalScrollPosition();
|
|
|
|
if (mRestorePos.y != -1 && pt == mLastPos) {
|
|
|
|
pt = mRestorePos;
|
|
|
|
}
|
|
|
|
state->SetScrollState(pt);
|
2008-12-12 11:25:22 -08:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::RestoreState(nsPresState* aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
mRestorePos = aState->GetScrollState();
|
2011-10-17 07:59:28 -07:00
|
|
|
mDidHistoryRestore = true;
|
2011-02-06 23:59:20 -08:00
|
|
|
mLastPos = mScrolledFrame ? GetLogicalScrollPosition() : nsPoint(0,0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-25 00:04:18 -07:00
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::PostScrolledAreaEvent()
|
2009-10-25 00:04:18 -07:00
|
|
|
{
|
2010-01-11 13:45:19 -08:00
|
|
|
if (mScrolledAreaEvent.IsPending()) {
|
2009-10-25 00:04:18 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-01-11 13:45:19 -08:00
|
|
|
mScrolledAreaEvent = new ScrolledAreaEvent(this);
|
2011-03-24 10:41:23 -07:00
|
|
|
nsContentUtils::AddScriptRunner(mScrolledAreaEvent.get());
|
2009-10-25 00:04:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrolledArea change event dispatch
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::ScrolledAreaEvent::Run()
|
2009-10-25 00:04:18 -07:00
|
|
|
{
|
2013-10-28 19:27:50 -07:00
|
|
|
if (mHelper) {
|
|
|
|
mHelper->FireScrolledAreaEvent();
|
2010-01-11 13:45:19 -08:00
|
|
|
}
|
2009-10-25 00:04:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-28 19:27:50 -07:00
|
|
|
ScrollFrameHelper::FireScrolledAreaEvent()
|
2009-10-25 00:04:18 -07:00
|
|
|
{
|
2010-01-11 13:45:19 -08:00
|
|
|
mScrolledAreaEvent.Forget();
|
2009-10-25 00:04:18 -07:00
|
|
|
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScrollAreaEvent event(true, NS_SCROLLEDAREACHANGED, nullptr);
|
2009-10-25 00:04:18 -07:00
|
|
|
nsPresContext *prescontext = mOuter->PresContext();
|
|
|
|
nsIContent* content = mOuter->GetContent();
|
|
|
|
|
2010-10-06 21:25:47 -07:00
|
|
|
event.mArea = mScrolledFrame->GetScrollableOverflowRectRelativeToParent();
|
2009-10-25 00:04:18 -07:00
|
|
|
|
|
|
|
nsIDocument *doc = content->GetCurrentDoc();
|
|
|
|
if (doc) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(doc, prescontext, &event, nullptr);
|
2009-10-25 00:04:18 -07:00
|
|
|
}
|
|
|
|
}
|
2012-09-23 21:30:33 -07:00
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsIScrollableFrame::GetPerceivedScrollingDirections() const
|
|
|
|
{
|
|
|
|
nscoord oneDevPixel = GetScrolledFrame()->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
uint32_t directions = GetScrollbarVisibility();
|
|
|
|
nsRect scrollRange = GetScrollRange();
|
|
|
|
if (scrollRange.width >= oneDevPixel) {
|
|
|
|
directions |= HORIZONTAL;
|
|
|
|
}
|
|
|
|
if (scrollRange.height >= oneDevPixel) {
|
|
|
|
directions |= VERTICAL;
|
|
|
|
}
|
|
|
|
return directions;
|
|
|
|
}
|