2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2010-04-27 09:15:02 -07:00
|
|
|
* Mats Palmgren <matspal@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* rendering object to wrap rendering objects that should be scrollable */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIScrollable.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsGfxScrollFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIDocumentObserver.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIScrollbarFrame.h"
|
|
|
|
#include "nsIScrollbarMediator.h"
|
|
|
|
#include "nsITextControlFrame.h"
|
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsPresState.h"
|
|
|
|
#include "nsIGlobalHistory3.h"
|
|
|
|
#include "nsDocShellCID.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"
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsBidiUtils.h"
|
2009-09-29 15:18:20 -07:00
|
|
|
#include "nsFrameManager.h"
|
2010-02-07 18:49:18 -08:00
|
|
|
#include "nsIPrefService.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
//----------nsHTMLScrollFrame-------------------------------------------
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsHTMLScrollFrame(aPresShell, aContext, aIsRoot);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLScrollFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
: nsHTMLContainerFrame(aContext),
|
|
|
|
mInner(this, aIsRoot, PR_FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
|
|
|
{
|
|
|
|
return mInner.CreateAnonymousContent(aElements);
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2010-02-20 16:52:50 -08:00
|
|
|
nsHTMLScrollFrame::AppendAnonymousContentTo(nsBaseContentList& aElements)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
2010-02-20 16:52:50 -08:00
|
|
|
mInner.AppendAnonymousContentTo(aElements);
|
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
|
|
|
{
|
|
|
|
mInner.Destroy();
|
2009-12-23 21:21:15 -08:00
|
|
|
nsHTMLContainerFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-07-28 05:53:20 -07:00
|
|
|
nsHTMLScrollFrame::SetInitialChildList(nsIAtom* aListName,
|
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsHTMLContainerFrame::SetInitialChildList(aListName, aChildList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
mFrames.AppendFrames(nsnull, aFrameList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
|
|
|
mFrames.InsertFrames(nsnull, aPrevFrame, aFrameList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
2007-11-18 14:24:21 -08:00
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplittableType
|
|
|
|
nsHTMLScrollFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsHTMLScrollFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLScrollFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::scrollFrame;
|
|
|
|
}
|
|
|
|
|
2008-07-13 15:21:11 -07:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::InvalidateInternal(const nsRect& aDamageRect,
|
|
|
|
nscoord aX, nscoord aY, nsIFrame* aForChild,
|
2008-09-18 02:47:21 -07:00
|
|
|
PRUint32 aFlags)
|
2008-07-13 15:21:11 -07:00
|
|
|
{
|
2009-07-26 14:29:01 -07:00
|
|
|
if (aForChild) {
|
|
|
|
if (aForChild == mInner.mScrolledFrame) {
|
|
|
|
// restrict aDamageRect to the scrollable view's bounds
|
|
|
|
nsRect damage = aDamageRect + nsPoint(aX, aY);
|
2010-07-15 14:08:02 -07:00
|
|
|
// damage is now in our coordinate system, which means it was
|
|
|
|
// translated using the current scroll position. Adjust it to
|
|
|
|
// reflect the scroll position at last paint, since that's what
|
|
|
|
// the layer system wants us to invalidate.
|
|
|
|
damage += GetScrollPosition() - mInner.mScrollPosAtLastPaint;
|
2009-07-26 14:29:01 -07:00
|
|
|
nsRect r;
|
2009-10-07 20:01:15 -07:00
|
|
|
if (r.IntersectRect(damage, mInner.mScrollPort)) {
|
2009-07-26 14:29:01 -07:00
|
|
|
nsHTMLContainerFrame::InvalidateInternal(r, 0, 0, aForChild, aFlags);
|
|
|
|
}
|
|
|
|
if (mInner.mIsRoot && r != damage) {
|
|
|
|
// Make sure we notify our prescontext about invalidations outside
|
|
|
|
// viewport clipping.
|
|
|
|
// This is important for things that are snapshotting the viewport,
|
|
|
|
// possibly outside the scrolled bounds.
|
|
|
|
// We don't need to propagate this any further up, though. Anyone who
|
|
|
|
// cares about scrolled-out-of-view invalidates had better be listening
|
|
|
|
// to our window directly.
|
2009-09-03 21:49:18 -07:00
|
|
|
PresContext()->NotifyInvalidation(damage, aFlags);
|
2009-07-26 14:29:01 -07:00
|
|
|
}
|
2009-07-21 17:44:49 -07:00
|
|
|
return;
|
2009-07-26 14:29:01 -07:00
|
|
|
} else if (aForChild == mInner.mHScrollbarBox) {
|
|
|
|
if (!mInner.mHasHorizontalScrollbar) {
|
|
|
|
// Our scrollbars may send up invalidations even when they're collapsed,
|
|
|
|
// because we just size a collapsed scrollbar to empty and some
|
|
|
|
// descendants may be non-empty. Suppress that invalidation here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (aForChild == mInner.mVScrollbarBox) {
|
|
|
|
if (!mInner.mHasVerticalScrollbar) {
|
|
|
|
// Our scrollbars may send up invalidations even when they're collapsed,
|
|
|
|
// because we just size a collapsed scrollbar to empty and some
|
|
|
|
// descendants may be non-empty. Suppress that invalidation here.
|
|
|
|
return;
|
|
|
|
}
|
2008-07-13 15:21:11 -07:00
|
|
|
}
|
|
|
|
}
|
2009-07-21 17:44:49 -07:00
|
|
|
|
2008-09-18 02:47:21 -07:00
|
|
|
nsHTMLContainerFrame::InvalidateInternal(aDamageRect, aX, aY, aForChild, aFlags);
|
2008-07-13 15:21:11 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
HTML scrolling implementation
|
|
|
|
|
|
|
|
All other things being equal, we prefer layouts with fewer scrollbars showing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ScrollReflowState {
|
|
|
|
const nsHTMLReflowState& mReflowState;
|
|
|
|
nsBoxLayoutState mBoxState;
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles mStyles;
|
|
|
|
nsMargin mComputedBorder;
|
|
|
|
|
2007-12-04 19:05:57 -08:00
|
|
|
// === Filled in by ReflowScrolledFrame ===
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect mContentsOverflowArea;
|
2007-12-04 19:05:57 -08:00
|
|
|
PRPackedBool mReflowedContentsWithHScrollbar;
|
|
|
|
PRPackedBool mReflowedContentsWithVScrollbar;
|
|
|
|
|
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
|
|
|
|
PRPackedBool mShowHScrollbar;
|
|
|
|
// Whether we decided to show the vertical scrollbar
|
|
|
|
PRPackedBool mShowVScrollbar;
|
|
|
|
|
|
|
|
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 -
|
|
|
|
aState->mReflowState.mComputedPadding.LeftRight();
|
|
|
|
}
|
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 -
|
|
|
|
aState->mReflowState.mComputedPadding.TopBottom();
|
|
|
|
}
|
|
|
|
|
|
|
|
aState->mReflowState.ApplyMinMaxConstraints(&contentWidth, &contentHeight);
|
|
|
|
return nsSize(contentWidth + aState->mReflowState.mComputedPadding.LeftRight(),
|
|
|
|
contentHeight + aState->mReflowState.mComputedPadding.TopBottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetScrollbarMetrics(nsBoxLayoutState& aState, nsIBox* aBox, nsSize* aMin,
|
|
|
|
nsSize* aPref, PRBool aVertical)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aState.GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
|
|
|
|
|
|
|
if (aMin) {
|
|
|
|
*aMin = aBox->GetMinSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(aBox, *aMin);
|
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);
|
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,
|
|
|
|
* compute the resulting layout and return PR_TRUE if the layout is
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @param aForce if PR_TRUE, then we just assume the layout is consistent.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::TryLayout(ScrollReflowState* aState,
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLReflowMetrics* aKidMetrics,
|
|
|
|
PRBool aAssumeHScroll, PRBool aAssumeVScroll,
|
|
|
|
PRBool 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!");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
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,
|
|
|
|
aKidMetrics, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aResult = rv;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize vScrollbarMinSize(0, 0);
|
|
|
|
nsSize vScrollbarPrefSize(0, 0);
|
|
|
|
if (mInner.mVScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mVScrollbarBox,
|
|
|
|
&vScrollbarMinSize,
|
|
|
|
aAssumeVScroll ? &vScrollbarPrefSize : nsnull, PR_TRUE);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
if (mInner.mHScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mHScrollbarBox,
|
|
|
|
&hScrollbarMinSize,
|
|
|
|
aAssumeHScroll ? &hScrollbarPrefSize : nsnull, PR_FALSE);
|
|
|
|
}
|
|
|
|
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 +
|
2009-09-16 08:01:36 -07:00
|
|
|
NS_MAX(aKidMetrics->width, hScrollbarMinWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
desiredInsideBorderSize.height = hScrollbarDesiredHeight +
|
2009-09-16 08:01:36 -07:00
|
|
|
NS_MAX(aKidMetrics->height, vScrollbarMinHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
aState->mInsideBorderSize =
|
|
|
|
ComputeInsideBorderSize(aState, desiredInsideBorderSize);
|
2009-09-16 08:01:36 -07:00
|
|
|
nsSize scrollPortSize = nsSize(NS_MAX(0, aState->mInsideBorderSize.width - vScrollbarDesiredWidth),
|
|
|
|
NS_MAX(0, aState->mInsideBorderSize.height - hScrollbarDesiredHeight));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aForce) {
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect =
|
|
|
|
mInner.GetScrolledRectInternal(aState->mContentsOverflowArea, scrollPortSize);
|
2008-04-24 01:14:06 -07:00
|
|
|
nscoord oneDevPixel = aState->mBoxState.PresContext()->DevPixelsToAppUnits(1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If the style is HIDDEN then we already know that aAssumeHScroll is PR_FALSE
|
|
|
|
if (aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
PRBool wantHScrollbar =
|
|
|
|
aState->mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 01:14:06 -07:00
|
|
|
scrolledRect.XMost() >= scrollPortSize.width + oneDevPixel ||
|
|
|
|
scrolledRect.x <= -oneDevPixel;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aState->mInsideBorderSize.height < hScrollbarMinSize.height ||
|
|
|
|
scrollPortSize.width < hScrollbarMinSize.width)
|
|
|
|
wantHScrollbar = PR_FALSE;
|
|
|
|
if (wantHScrollbar != aAssumeHScroll)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the style is HIDDEN then we already know that aAssumeVScroll is PR_FALSE
|
|
|
|
if (aState->mStyles.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
PRBool wantVScrollbar =
|
|
|
|
aState->mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 01:14:06 -07:00
|
|
|
scrolledRect.YMost() >= scrollPortSize.height + oneDevPixel ||
|
|
|
|
scrolledRect.y <= -oneDevPixel;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aState->mInsideBorderSize.width < vScrollbarMinSize.width ||
|
|
|
|
scrollPortSize.height < vScrollbarMinSize.height)
|
|
|
|
wantVScrollbar = PR_FALSE;
|
|
|
|
if (wantVScrollbar != aAssumeVScroll)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord vScrollbarActualWidth = aState->mInsideBorderSize.width - scrollPortSize.width;
|
|
|
|
|
|
|
|
aState->mShowHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mShowVScrollbar = aAssumeVScroll;
|
|
|
|
nsPoint scrollPortOrigin(aState->mComputedBorder.left,
|
|
|
|
aState->mComputedBorder.top);
|
|
|
|
if (!mInner.IsScrollbarOnRight()) {
|
|
|
|
scrollPortOrigin.x += vScrollbarActualWidth;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
mInner.mScrollPort = nsRect(scrollPortOrigin, scrollPortSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-02-23 02:15:59 -08:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::ScrolledContentDependsOnHeight(ScrollReflowState* aState)
|
|
|
|
{
|
|
|
|
// Return true if ReflowScrolledFrame is going to do something different
|
|
|
|
// based on the presence of a horizontal scrollbar.
|
|
|
|
return (mInner.mScrolledFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT) ||
|
|
|
|
aState->mReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE ||
|
|
|
|
aState->mReflowState.mComputedMinHeight > 0 ||
|
|
|
|
aState->mReflowState.mComputedMaxHeight != NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLScrollFrame::ReflowScrolledFrame(ScrollReflowState* aState,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aAssumeHScroll,
|
|
|
|
PRBool aAssumeVScroll,
|
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
|
|
|
PRBool aFirstPass)
|
|
|
|
{
|
2009-09-16 08:01:36 -07:00
|
|
|
// these could be NS_UNCONSTRAINEDSIZE ... NS_MIN arithmetic should
|
2007-03-22 10:30:00 -07:00
|
|
|
// be OK
|
2007-12-04 19:05:57 -08:00
|
|
|
nscoord paddingLR = aState->mReflowState.mComputedPadding.LeftRight();
|
|
|
|
|
|
|
|
nscoord availWidth = aState->mReflowState.ComputedWidth() + paddingLR;
|
|
|
|
|
|
|
|
nscoord computedHeight = aState->mReflowState.ComputedHeight();
|
|
|
|
nscoord computedMinHeight = aState->mReflowState.mComputedMinHeight;
|
|
|
|
nscoord computedMaxHeight = aState->mReflowState.mComputedMaxHeight;
|
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) {
|
|
|
|
nsSize hScrollbarPrefSize =
|
|
|
|
mInner.mHScrollbarBox->GetPrefSize(const_cast<nsBoxLayoutState&>(aState->mBoxState));
|
|
|
|
if (computedHeight != NS_UNCONSTRAINEDSIZE)
|
2009-09-16 08:01:36 -07:00
|
|
|
computedHeight = NS_MAX(0, computedHeight - hScrollbarPrefSize.height);
|
|
|
|
computedMinHeight = NS_MAX(0, computedMinHeight - hScrollbarPrefSize.height);
|
2007-12-04 19:05:57 -08:00
|
|
|
if (computedMaxHeight != NS_UNCONSTRAINEDSIZE)
|
2009-09-16 08:01:36 -07:00
|
|
|
computedMaxHeight = NS_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) {
|
|
|
|
nsSize vScrollbarPrefSize =
|
2007-12-04 19:05:57 -08:00
|
|
|
mInner.mVScrollbarBox->GetPrefSize(const_cast<nsBoxLayoutState&>(aState->mBoxState));
|
2009-09-16 08:01:36 -07:00
|
|
|
availWidth = NS_MAX(0, availWidth - vScrollbarPrefSize.width);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We're forcing the padding on our scrolled frame, so let it know what that
|
|
|
|
// padding is.
|
2010-03-28 18:46:55 -07:00
|
|
|
presContext->PropertyTable()->
|
|
|
|
Set(mInner.mScrolledFrame, UsedPaddingProperty(),
|
|
|
|
new nsMargin(aState->mReflowState.mComputedPadding));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Pass PR_FALSE for aInit so we can pass in the correct padding
|
2007-12-04 19:05:57 -08:00
|
|
|
nsHTMLReflowState kidReflowState(presContext, aState->mReflowState,
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner.mScrolledFrame,
|
|
|
|
nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
|
|
|
|
-1, -1, PR_FALSE);
|
|
|
|
kidReflowState.Init(presContext, -1, -1, nsnull,
|
2007-12-04 19:05:57 -08:00
|
|
|
&aState->mReflowState.mComputedPadding);
|
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);
|
|
|
|
kidReflowState.mComputedMinHeight = computedMinHeight;
|
|
|
|
kidReflowState.mComputedMaxHeight = 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.
|
2010-02-17 07:43:39 -08:00
|
|
|
PRBool didHaveHorizontalScrollbar = mInner.mHasHorizontalScrollbar;
|
2010-01-14 05:00:00 -08:00
|
|
|
PRBool didHaveVerticalScrollbar = mInner.mHasVerticalScrollbar;
|
|
|
|
mInner.mHasHorizontalScrollbar = aAssumeHScroll;
|
|
|
|
mInner.mHasVerticalScrollbar = aAssumeVScroll;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsReflowStatus status;
|
|
|
|
nsresult rv = ReflowChild(mInner.mScrolledFrame, presContext, *aMetrics,
|
|
|
|
kidReflowState, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW, status);
|
2010-01-14 05:00:00 -08:00
|
|
|
|
2010-02-17 07:43:39 -08:00
|
|
|
mInner.mHasHorizontalScrollbar = didHaveHorizontalScrollbar;
|
2010-01-14 05:00:00 -08:00
|
|
|
mInner.mHasVerticalScrollbar = didHaveVerticalScrollbar;
|
|
|
|
|
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.
|
|
|
|
FinishReflowChild(mInner.mScrolledFrame, presContext,
|
|
|
|
&kidReflowState, *aMetrics, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW | NS_FRAME_NO_SIZE_VIEW);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
aMetrics->mOverflowArea.UnionRect(aMetrics->mOverflowArea,
|
|
|
|
nsRect(0, 0, aMetrics->width, aMetrics->height));
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
aState->mContentsOverflowArea = aMetrics->mOverflowArea;
|
2007-12-04 19:05:57 -08:00
|
|
|
aState->mReflowedContentsWithHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mReflowedContentsWithVScrollbar = aAssumeVScroll;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-02-23 02:15:59 -08:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::GuessHScrollbarNeeded(const ScrollReflowState& aState)
|
|
|
|
{
|
|
|
|
if (aState.mStyles.mHorizontal != NS_STYLE_OVERFLOW_AUTO)
|
|
|
|
// no guessing required
|
|
|
|
return aState.mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL;
|
|
|
|
|
|
|
|
return mInner.mHasHorizontalScrollbar;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool
|
|
|
|
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.
|
|
|
|
if (mInner.mHadNonInitialReflow) {
|
|
|
|
return mInner.mHasVerticalScrollbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the initial reflow, guess PR_FALSE because usually
|
|
|
|
// we have very little content by then.
|
2007-04-25 19:29:21 -07:00
|
|
|
if (InInitialReflow())
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (mInner.mIsRoot) {
|
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).
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-25 19:29:21 -07:00
|
|
|
PRBool
|
|
|
|
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).
|
|
|
|
return !mInner.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)
|
|
|
|
{
|
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mFlags);
|
2008-02-23 02:15:59 -08:00
|
|
|
nsresult rv = ReflowScrolledFrame(aState, GuessHScrollbarNeeded(*aState),
|
2007-12-04 19:05:57 -08:00
|
|
|
GuessVScrollbarNeeded(*aState), &kidDesiredSize, PR_TRUE);
|
|
|
|
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,
|
|
|
|
nsSize(kidDesiredSize.width, kidDesiredSize.height));
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect =
|
|
|
|
mInner.GetScrolledRectInternal(kidDesiredSize.mOverflowArea, 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
|
|
|
|
rv = ReflowScrolledFrame(aState, PR_FALSE, PR_FALSE,
|
2007-03-22 10:30:00 -07:00
|
|
|
&kidDesiredSize, PR_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,
|
2007-12-04 19:05:57 -08:00
|
|
|
aState->mReflowedContentsWithVScrollbar, PR_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,
|
2007-12-04 19:05:57 -08:00
|
|
|
aState->mReflowedContentsWithVScrollbar, PR_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.
|
|
|
|
PRBool newVScrollbarState = !aState->mReflowedContentsWithVScrollbar;
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, PR_FALSE, newVScrollbarState, PR_FALSE, &rv))
|
|
|
|
return NS_OK;
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, PR_TRUE, newVScrollbarState, PR_FALSE, &rv))
|
|
|
|
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,
|
|
|
|
PR_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
|
|
|
{
|
|
|
|
nsIFrame *scrolledFrame = mInner.mScrolledFrame;
|
2009-10-07 20:01:15 -07:00
|
|
|
// Set the x,y of the scrolled frame to the correct value
|
|
|
|
scrolledFrame->SetPosition(mInner.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
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize portSize = mInner.mScrollPort.Size();
|
|
|
|
nsRect scrolledRect = mInner.GetScrolledRectInternal(aState.mContentsOverflowArea, portSize);
|
|
|
|
scrolledArea.UnionRectIncludeEmpty(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.
|
2007-03-22 10:30:00 -07:00
|
|
|
scrolledFrame->FinishAndStoreOverflow(&scrolledArea,
|
|
|
|
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(),
|
2007-03-22 10:30:00 -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
|
|
|
|
nsHTMLScrollFrame::GetIntrinsicVScrollbarWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles ss = GetScrollbarStyles();
|
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_SCROLL || !mInner.mVScrollbarBox)
|
|
|
|
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);
|
|
|
|
GetScrollbarMetrics(bls, mInner.mVScrollbarBox,
|
|
|
|
nsnull, &vScrollbarPrefSize, PR_TRUE);
|
|
|
|
return vScrollbarPrefSize.width;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* virtual */ nscoord
|
|
|
|
nsHTMLScrollFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
2007-12-04 14:03:16 -08:00
|
|
|
nscoord result = mInner.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
|
|
|
|
nsHTMLScrollFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
2008-02-28 12:37:06 -08:00
|
|
|
nscoord result = mInner.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::IsCollapsed(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
// We're never collapsed in the box sense.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ScrollReflowState state(this, aReflowState);
|
|
|
|
// sanity check: ensure that if we have no scrollbar, we treat it
|
|
|
|
// as hidden.
|
|
|
|
if (!mInner.mVScrollbarBox || mInner.mNeverHasVerticalScrollbar)
|
|
|
|
state.mStyles.mVertical = NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
if (!mInner.mHScrollbarBox || mInner.mNeverHasHorizontalScrollbar)
|
|
|
|
state.mStyles.mHorizontal = NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
|
|
|
|
//------------ Handle Incremental Reflow -----------------
|
|
|
|
PRBool reflowContents = PR_TRUE; // XXX Ignored
|
|
|
|
PRBool reflowHScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowVScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowScrollCorner = PR_TRUE;
|
|
|
|
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
|
|
|
|
|
|
|
reflowContents = NEEDS_REFLOW(mInner.mScrolledFrame);
|
|
|
|
reflowHScrollbar = NEEDS_REFLOW(mInner.mHScrollbarBox);
|
|
|
|
reflowVScrollbar = NEEDS_REFLOW(mInner.mVScrollbarBox);
|
|
|
|
reflowScrollCorner = NEEDS_REFLOW(mInner.mScrollCornerBox);
|
|
|
|
|
|
|
|
#undef NEEDS_REFLOW
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect oldScrollAreaBounds = mInner.mScrollPort;
|
|
|
|
nsRect oldScrolledAreaBounds =
|
|
|
|
mInner.mScrolledFrame->GetOverflowRectRelativeToParent();
|
|
|
|
// Adjust to a multiple of device pixels to restore the invariant that
|
|
|
|
// oldScrollPosition is a multiple of device pixels. This could have been
|
|
|
|
// thrown out by a zoom change.
|
|
|
|
nsIntPoint ptDevPx;
|
2010-03-28 18:46:59 -07:00
|
|
|
nsPoint oldScrollPosition = mInner.GetScrollPosition();
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
state.mComputedBorder = aReflowState.mComputedBorderPadding -
|
|
|
|
aReflowState.mComputedPadding;
|
|
|
|
|
|
|
|
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);
|
2009-06-23 18:35:00 -07:00
|
|
|
if (!mInner.mPostedReflowCallback) {
|
|
|
|
// Make sure we'll try scrolling to restored position
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(&mInner);
|
|
|
|
mInner.mPostedReflowCallback = PR_TRUE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool didHaveHScrollbar = mInner.mHasHorizontalScrollbar;
|
|
|
|
PRBool didHaveVScrollbar = mInner.mHasVerticalScrollbar;
|
|
|
|
mInner.mHasHorizontalScrollbar = state.mShowHScrollbar;
|
|
|
|
mInner.mHasVerticalScrollbar = state.mShowVScrollbar;
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect newScrollAreaBounds = mInner.mScrollPort;
|
|
|
|
nsRect newScrolledAreaBounds =
|
|
|
|
mInner.mScrolledFrame->GetOverflowRectRelativeToParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mInner.mSkippedScrollbarLayout ||
|
|
|
|
reflowHScrollbar || reflowVScrollbar || reflowScrollCorner ||
|
|
|
|
(GetStateBits() & NS_FRAME_IS_DIRTY) ||
|
|
|
|
didHaveHScrollbar != state.mShowHScrollbar ||
|
|
|
|
didHaveVScrollbar != state.mShowVScrollbar ||
|
|
|
|
oldScrollAreaBounds != newScrollAreaBounds ||
|
|
|
|
oldScrolledAreaBounds != newScrolledAreaBounds) {
|
|
|
|
if (!mInner.mSupppressScrollbarUpdate) {
|
|
|
|
mInner.mSkippedScrollbarLayout = PR_FALSE;
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, state.mShowHScrollbar);
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, state.mShowVScrollbar);
|
|
|
|
// place and reflow scrollbars
|
|
|
|
nsRect insideBorderArea =
|
|
|
|
nsRect(nsPoint(state.mComputedBorder.left, state.mComputedBorder.top),
|
|
|
|
state.mInsideBorderSize);
|
|
|
|
mInner.LayoutScrollbars(state.mBoxState, insideBorderArea,
|
2009-10-07 20:01:15 -07:00
|
|
|
oldScrollAreaBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
mInner.mSkippedScrollbarLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aDesiredSize.width = state.mInsideBorderSize.width +
|
|
|
|
state.mComputedBorder.LeftRight();
|
|
|
|
aDesiredSize.height = state.mInsideBorderSize.height +
|
|
|
|
state.mComputedBorder.TopBottom();
|
|
|
|
|
|
|
|
aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
2009-12-13 19:40:55 -08:00
|
|
|
|
|
|
|
CheckInvalidateSizeChange(aDesiredSize);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2007-04-25 19:29:21 -07:00
|
|
|
if (!InInitialReflow() && !mInner.mHadNonInitialReflow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner.mHadNonInitialReflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:13:56 -07:00
|
|
|
if (mInner.mIsRoot && oldScrolledAreaBounds != newScrolledAreaBounds) {
|
2010-01-11 13:45:19 -08:00
|
|
|
mInner.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);
|
2007-10-08 01:42:43 -07:00
|
|
|
mInner.PostOverflowEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:13:56 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLScroll"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 05:02:03 -07:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsHTMLScrollFrame::CreateAccessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!IsFocusable()) {
|
2010-06-28 05:02:03 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Focusable via CSS, so needs to be in accessibility hierarchy
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2010-06-28 05:02:03 -07:00
|
|
|
return accService->CreateHyperTextAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 05:02:03 -07:00
|
|
|
return nsnull;
|
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)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------nsXULScrollFrame-------------------------------------------
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsXULScrollFrame(aPresShell, aContext, aIsRoot);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsXULScrollFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
: nsBoxFrame(aShell, aContext, aIsRoot),
|
|
|
|
mInner(this, aIsRoot, PR_TRUE)
|
|
|
|
{
|
|
|
|
SetLayoutManager(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin nsGfxScrollFrameInner::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) {
|
|
|
|
NS_ASSERTION(aState && aState->GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
|
|
|
{
|
|
|
|
return mInner.CreateAnonymousContent(aElements);
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
void
|
2010-02-20 16:52:50 -08:00
|
|
|
nsXULScrollFrame::AppendAnonymousContentTo(nsBaseContentList& aElements)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
2010-02-20 16:52:50 -08:00
|
|
|
mInner.AppendAnonymousContentTo(aElements);
|
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
|
|
|
{
|
|
|
|
mInner.Destroy();
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::SetInitialChildList(aListName, aChildList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::AppendFrames(aListName, aFrameList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::InsertFrames(aListName, aPrevFrame, aFrameList);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::RemoveFrame(aListName, aOldFrame);
|
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSplittableType
|
|
|
|
nsXULScrollFrame::GetSplittableType() const
|
|
|
|
{
|
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::GetPadding(nsMargin& aMargin)
|
|
|
|
{
|
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsXULScrollFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsXULScrollFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::scrollFrame;
|
|
|
|
}
|
|
|
|
|
2008-07-13 15:21:11 -07:00
|
|
|
void
|
|
|
|
nsXULScrollFrame::InvalidateInternal(const nsRect& aDamageRect,
|
|
|
|
nscoord aX, nscoord aY, nsIFrame* aForChild,
|
2008-09-18 02:47:21 -07:00
|
|
|
PRUint32 aFlags)
|
2008-07-13 15:21:11 -07:00
|
|
|
{
|
|
|
|
if (aForChild == mInner.mScrolledFrame) {
|
|
|
|
// restrict aDamageRect to the scrollable view's bounds
|
2010-07-15 14:08:02 -07:00
|
|
|
nsRect damage = aDamageRect + nsPoint(aX, aY) +
|
|
|
|
GetScrollPosition() - mInner.mScrollPosAtLastPaint;
|
2008-07-13 15:21:11 -07:00
|
|
|
nsRect r;
|
2010-07-15 14:08:02 -07:00
|
|
|
if (r.IntersectRect(damage, mInner.mScrollPort)) {
|
2008-09-18 02:47:21 -07:00
|
|
|
nsBoxFrame::InvalidateInternal(r, 0, 0, aForChild, aFlags);
|
2008-07-13 15:21:11 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-18 02:47:21 -07:00
|
|
|
nsBoxFrame::InvalidateInternal(aDamageRect, aX, aY, aForChild, aFlags);
|
2008-07-13 15:21:11 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord
|
|
|
|
nsXULScrollFrame::GetBoxAscent(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
if (!mInner.mScrolledFrame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nscoord ascent = mInner.mScrolledFrame->GetBoxAscent(aState);
|
|
|
|
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
|
|
|
|
|
|
|
|
nsSize pref = mInner.mScrolledFrame->GetPrefSize(aState);
|
|
|
|
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles styles = GetScrollbarStyles();
|
|
|
|
|
|
|
|
// scrolled frames don't have their own margins
|
|
|
|
|
|
|
|
if (mInner.mVScrollbarBox &&
|
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetPrefSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mInner.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
pref.width += vSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInner.mHScrollbarBox &&
|
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetPrefSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mInner.mHScrollbarBox, hSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
pref.height += hSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddBorderAndPadding(pref);
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
nsIBox::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
|
|
|
|
|
|
|
|
nsSize min = mInner.mScrolledFrame->GetMinSizeForScrollArea(aState);
|
|
|
|
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles styles = GetScrollbarStyles();
|
|
|
|
|
|
|
|
if (mInner.mVScrollbarBox &&
|
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetMinSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
AddMargin(mInner.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
min.width += vSize.width;
|
|
|
|
if (min.height < vSize.height)
|
|
|
|
min.height = vSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mInner.mHScrollbarBox &&
|
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetMinSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
AddMargin(mInner.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);
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
nsIBox::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);
|
2010-03-18 12:58:15 -07:00
|
|
|
PRBool widthSet, heightSet;
|
|
|
|
nsIBox::AddCSSMaxSize(this, maxSize, widthSet, heightSet);
|
2008-02-26 17:51:57 -08:00
|
|
|
return maxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("XULScroll"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
PRUint32 flags = aState.LayoutFlags();
|
|
|
|
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)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIScrollableFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------- Inner ----------------------
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
#define SMOOTH_SCROLL_MSECS_PER_FRAME 10
|
|
|
|
#define SMOOTH_SCROLL_FRAMES 10
|
|
|
|
|
|
|
|
#define SMOOTH_SCROLL_PREF_NAME "general.smoothScroll"
|
|
|
|
|
|
|
|
class nsGfxScrollFrameInner::AsyncScroll {
|
|
|
|
public:
|
|
|
|
AsyncScroll() {}
|
|
|
|
~AsyncScroll() {
|
|
|
|
if (mScrollTimer) mScrollTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mScrollTimer;
|
|
|
|
PRInt32 mVelocities[SMOOTH_SCROLL_FRAMES*2];
|
|
|
|
PRInt32 mFrameIndex;
|
|
|
|
PRPackedBool mIsSmoothScroll;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ComputeVelocities(PRInt32 aCurVelocity, nscoord aCurPos, nscoord aDstPos,
|
|
|
|
PRInt32* aVelocities, PRInt32 aP2A)
|
|
|
|
{
|
|
|
|
// scrolling always works in units of whole pixels. So compute velocities
|
|
|
|
// in pixels and then scale them up. This ensures, for example, that
|
|
|
|
// a 1-pixel scroll isn't broken into N frames of 1/N pixels each, each
|
|
|
|
// frame increment being rounded to 0 whole pixels.
|
|
|
|
aCurPos = NSAppUnitsToIntPixels(aCurPos, aP2A);
|
|
|
|
aDstPos = NSAppUnitsToIntPixels(aDstPos, aP2A);
|
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 direction = (aCurPos < aDstPos ? 1 : -1);
|
|
|
|
PRInt32 absDelta = (aDstPos - aCurPos)*direction;
|
|
|
|
PRInt32 baseVelocity = absDelta/SMOOTH_SCROLL_FRAMES;
|
|
|
|
|
|
|
|
for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
|
|
|
|
aVelocities[i*2] = baseVelocity;
|
|
|
|
}
|
|
|
|
nscoord total = baseVelocity*SMOOTH_SCROLL_FRAMES;
|
|
|
|
for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
|
|
|
|
if (total < absDelta) {
|
|
|
|
aVelocities[i*2]++;
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(total == absDelta, "Invalid velocity sum");
|
|
|
|
|
|
|
|
PRInt32 scale = NSIntPixelsToAppUnits(direction, aP2A);
|
|
|
|
for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
|
|
|
|
aVelocities[i*2] *= scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
IsSmoothScrollingEnabled()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs) {
|
|
|
|
PRBool enabled;
|
|
|
|
nsresult rv = prefs->GetBoolPref(SMOOTH_SCROLL_PREF_NAME, &enabled);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
class ScrollFrameActivityTracker : public nsExpirationTracker<nsGfxScrollFrameInner,4> {
|
|
|
|
public:
|
|
|
|
// Wait for 75-100ms between scrolls before we switch the appearance back to
|
|
|
|
// subpixel AA. That's 4 generations of 25ms each.
|
|
|
|
enum { TIMEOUT_MS = 25 };
|
|
|
|
ScrollFrameActivityTracker()
|
|
|
|
: nsExpirationTracker<nsGfxScrollFrameInner,4>(TIMEOUT_MS) {}
|
|
|
|
~ScrollFrameActivityTracker() {
|
|
|
|
AgeAllGenerations();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void NotifyExpired(nsGfxScrollFrameInner *aObject) {
|
|
|
|
RemoveObject(aObject);
|
|
|
|
aObject->mScrollingActive = PR_FALSE;
|
2010-08-30 17:49:12 -07:00
|
|
|
aObject->mOuter->InvalidateFrameSubtree();
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static ScrollFrameActivityTracker *gScrollFrameActivityTracker = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGfxScrollFrameInner::nsGfxScrollFrameInner(nsContainerFrame* aOuter,
|
|
|
|
PRBool aIsRoot,
|
|
|
|
PRBool aIsXUL)
|
2009-10-07 20:01:15 -07:00
|
|
|
: mHScrollbarBox(nsnull),
|
2007-03-22 10:30:00 -07:00
|
|
|
mVScrollbarBox(nsnull),
|
|
|
|
mScrolledFrame(nsnull),
|
|
|
|
mScrollCornerBox(nsnull),
|
|
|
|
mOuter(aOuter),
|
2009-10-07 20:01:15 -07:00
|
|
|
mAsyncScroll(nsnull),
|
|
|
|
mDestination(0, 0),
|
2010-07-15 14:08:02 -07:00
|
|
|
mScrollPosAtLastPaint(0, 0),
|
2009-10-07 20:01:15 -07:00
|
|
|
mRestorePos(-1, -1),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLastPos(-1, -1),
|
|
|
|
mNeverHasVerticalScrollbar(PR_FALSE),
|
|
|
|
mNeverHasHorizontalScrollbar(PR_FALSE),
|
|
|
|
mHasVerticalScrollbar(PR_FALSE),
|
|
|
|
mHasHorizontalScrollbar(PR_FALSE),
|
2009-10-07 20:01:15 -07:00
|
|
|
mFrameIsUpdatingScrollbar(PR_FALSE),
|
2007-03-22 10:30:00 -07:00
|
|
|
mDidHistoryRestore(PR_FALSE),
|
|
|
|
mIsRoot(aIsRoot),
|
|
|
|
mIsXUL(aIsXUL),
|
|
|
|
mSupppressScrollbarUpdate(PR_FALSE),
|
|
|
|
mSkippedScrollbarLayout(PR_FALSE),
|
|
|
|
mHadNonInitialReflow(PR_FALSE),
|
|
|
|
mHorizontalOverflow(PR_FALSE),
|
|
|
|
mVerticalOverflow(PR_FALSE),
|
2007-12-20 15:49:46 -08:00
|
|
|
mPostedReflowCallback(PR_FALSE),
|
2009-06-23 18:35:00 -07:00
|
|
|
mMayHaveDirtyFixedChildren(PR_FALSE),
|
2010-07-15 14:08:02 -07:00
|
|
|
mUpdateScrollbarAttributes(PR_FALSE),
|
|
|
|
mScrollingActive(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxScrollFrameInner::~nsGfxScrollFrameInner()
|
|
|
|
{
|
2010-07-15 14:08:05 -07:00
|
|
|
if (mActivityExpirationState.IsTracked()) {
|
|
|
|
gScrollFrameActivityTracker->RemoveObject(this);
|
|
|
|
}
|
|
|
|
if (gScrollFrameActivityTracker &&
|
|
|
|
gScrollFrameActivityTracker->IsEmpty()) {
|
|
|
|
delete gScrollFrameActivityTracker;
|
|
|
|
gScrollFrameActivityTracker = nsnull;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
delete mAsyncScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
Clamp(nscoord aLower, nscoord aVal, nscoord aUpper)
|
|
|
|
{
|
|
|
|
if (aVal < aLower)
|
|
|
|
return aLower;
|
|
|
|
if (aVal > aUpper)
|
|
|
|
return aUpper;
|
|
|
|
return aVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsGfxScrollFrameInner::ClampScrollPosition(const nsPoint& aPt) const
|
|
|
|
{
|
|
|
|
nsRect range = GetScrollRange();
|
|
|
|
return nsPoint(Clamp(range.x, aPt.x, range.XMost()),
|
|
|
|
Clamp(range.y, aPt.y, range.YMost()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback function from timer used in nsGfxScrollFrameInner::ScrollTo
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::AsyncScrollCallback(nsITimer *aTimer, void* anInstance)
|
|
|
|
{
|
|
|
|
nsGfxScrollFrameInner* self = static_cast<nsGfxScrollFrameInner*>(anInstance);
|
|
|
|
if (!self || !self->mAsyncScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self->mAsyncScroll->mIsSmoothScroll) {
|
|
|
|
// XXX this is crappy, the scroll position needs to be based on the
|
|
|
|
// current time
|
|
|
|
NS_ASSERTION(self->mAsyncScroll->mFrameIndex < SMOOTH_SCROLL_FRAMES,
|
|
|
|
"Past last frame?");
|
|
|
|
nscoord* velocities =
|
|
|
|
&self->mAsyncScroll->mVelocities[self->mAsyncScroll->mFrameIndex*2];
|
|
|
|
nsPoint destination =
|
|
|
|
self->GetScrollPosition() + nsPoint(velocities[0], velocities[1]);
|
|
|
|
|
|
|
|
self->mAsyncScroll->mFrameIndex++;
|
|
|
|
if (self->mAsyncScroll->mFrameIndex >= SMOOTH_SCROLL_FRAMES) {
|
|
|
|
delete self->mAsyncScroll;
|
|
|
|
self->mAsyncScroll = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->ScrollToImpl(destination);
|
|
|
|
} else {
|
|
|
|
delete self->mAsyncScroll;
|
|
|
|
self->mAsyncScroll = nsnull;
|
|
|
|
|
|
|
|
self->ScrollToImpl(self->mDestination);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this method wraps calls to ScrollToImpl(), either in one shot or incrementally,
|
|
|
|
* based on the setting of the smooth scroll pref
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ScrollTo(nsPoint aScrollPosition,
|
|
|
|
nsIScrollableFrame::ScrollMode aMode)
|
|
|
|
{
|
|
|
|
mDestination = ClampScrollPosition(aScrollPosition);
|
|
|
|
|
|
|
|
if (aMode == nsIScrollableFrame::INSTANT) {
|
|
|
|
// Asynchronous scrolling is not allowed, so we'll kill any existing
|
|
|
|
// async-scrolling process and do an instant scroll
|
|
|
|
delete mAsyncScroll;
|
|
|
|
mAsyncScroll = nsnull;
|
|
|
|
ScrollToImpl(mDestination);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 currentVelocityX = 0;
|
|
|
|
PRInt32 currentVelocityY = 0;
|
|
|
|
PRBool isSmoothScroll = IsSmoothScrollingEnabled();
|
|
|
|
|
|
|
|
if (mAsyncScroll) {
|
|
|
|
if (mAsyncScroll->mIsSmoothScroll) {
|
|
|
|
currentVelocityX = mAsyncScroll->mVelocities[mAsyncScroll->mFrameIndex*2];
|
|
|
|
currentVelocityY = mAsyncScroll->mVelocities[mAsyncScroll->mFrameIndex*2 + 1];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mAsyncScroll = new AsyncScroll;
|
|
|
|
if (mAsyncScroll) {
|
|
|
|
mAsyncScroll->mScrollTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mAsyncScroll->mScrollTimer) {
|
|
|
|
delete mAsyncScroll;
|
|
|
|
mAsyncScroll = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mAsyncScroll) {
|
|
|
|
// some allocation failed. Scroll the normal way.
|
|
|
|
ScrollToImpl(mDestination);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isSmoothScroll) {
|
|
|
|
mAsyncScroll->mScrollTimer->InitWithFuncCallback(
|
|
|
|
AsyncScrollCallback, this, SMOOTH_SCROLL_MSECS_PER_FRAME,
|
|
|
|
nsITimer::TYPE_REPEATING_PRECISE);
|
|
|
|
} else {
|
|
|
|
mAsyncScroll->mScrollTimer->InitWithFuncCallback(
|
|
|
|
AsyncScrollCallback, this, 0, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAsyncScroll->mFrameIndex = 0;
|
|
|
|
mAsyncScroll->mIsSmoothScroll = isSmoothScroll;
|
|
|
|
|
|
|
|
if (isSmoothScroll) {
|
|
|
|
PRInt32 p2a = mOuter->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
// compute velocity vectors
|
|
|
|
nsPoint currentPos = GetScrollPosition();
|
|
|
|
ComputeVelocities(currentVelocityX, currentPos.x, mDestination.x,
|
|
|
|
mAsyncScroll->mVelocities, p2a);
|
|
|
|
ComputeVelocities(currentVelocityY, currentPos.y, mDestination.y,
|
|
|
|
mAsyncScroll->mVelocities + 1, p2a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InvalidateWidgets(nsIView* aView)
|
|
|
|
{
|
|
|
|
if (aView->HasWidget()) {
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
|
|
|
nsWindowType type;
|
|
|
|
widget->GetWindowType(type);
|
|
|
|
if (type != eWindowType_popup) {
|
|
|
|
// Force the widget and everything in it to repaint. We can't
|
|
|
|
// just use Invalidate because the widget might have child
|
|
|
|
// widgets and they wouldn't get updated. We can't call
|
|
|
|
// UpdateView(aView) because the area to be repainted might be
|
|
|
|
// outside aView's clipped bounds. This isn't the greatest way
|
|
|
|
// to achieve this, perhaps, but it works.
|
|
|
|
widget->Show(PR_FALSE);
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIView* v = aView->GetFirstChild(); v; v = v->GetNextSibling()) {
|
|
|
|
InvalidateWidgets(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't use nsContainerFrame::PositionChildViews here because
|
|
|
|
// we don't want to invalidate views that have moved.
|
|
|
|
// aInvalidateWidgets is set to true if we should invalidate the area
|
|
|
|
// covered by every widget in the subtree.
|
|
|
|
static void AdjustViewsAndWidgets(nsIFrame* aFrame,
|
|
|
|
PRBool aInvalidateWidgets)
|
|
|
|
{
|
|
|
|
nsIView* view = aFrame->GetView();
|
|
|
|
if (view) {
|
|
|
|
nsPoint pt;
|
|
|
|
aFrame->GetParent()->GetClosestView(&pt);
|
|
|
|
pt += aFrame->GetPosition();
|
|
|
|
view->SetPosition(pt.x, pt.y);
|
|
|
|
|
|
|
|
if (aInvalidateWidgets) {
|
|
|
|
InvalidateWidgets(view);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* childListName = nsnull;
|
|
|
|
PRInt32 childListIndex = 0;
|
|
|
|
do {
|
|
|
|
// Recursively walk aFrame's child frames
|
|
|
|
nsIFrame* childFrame = aFrame->GetFirstChild(childListName);
|
|
|
|
while (childFrame) {
|
|
|
|
AdjustViewsAndWidgets(childFrame, aInvalidateWidgets);
|
|
|
|
|
|
|
|
// Get the next sibling child frame
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// also process the additional child lists, but skip the popup list as the
|
|
|
|
// views for popups are not scrolled.
|
|
|
|
do {
|
|
|
|
childListName = aFrame->GetAdditionalChildListName(childListIndex++);
|
|
|
|
} while (childListName == nsGkAtoms::popupList);
|
|
|
|
} while (childListName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
static PRBool
|
2010-07-15 14:08:02 -07:00
|
|
|
CanScrollWithBlitting(nsIFrame* aFrame, nsIFrame* aDisplayRoot)
|
2009-10-07 20:01:15 -07:00
|
|
|
{
|
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 (f->GetStyleDisplay()->HasTransform()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
if (nsSVGIntegrationUtils::UsingEffectsForFrame(f) ||
|
|
|
|
f->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2010-04-22 19:41:38 -07:00
|
|
|
if (f == aDisplayRoot)
|
|
|
|
break;
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:02 -07:00
|
|
|
static void
|
|
|
|
InvalidateFixedBackgroundFramesFromList(nsDisplayListBuilder* aBuilder,
|
2010-08-13 02:54:37 -07:00
|
|
|
nsIFrame* aMovingFrame,
|
2010-07-15 14:08:02 -07:00
|
|
|
const nsDisplayList& aList)
|
|
|
|
{
|
|
|
|
for (nsDisplayItem* item = aList.GetBottom(); item; item = item->GetAbove()) {
|
|
|
|
nsDisplayList* sublist = item->GetList();
|
|
|
|
if (sublist) {
|
2010-08-13 02:54:37 -07:00
|
|
|
InvalidateFixedBackgroundFramesFromList(aBuilder, aMovingFrame, *sublist);
|
2010-07-15 14:08:12 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsIFrame* f = item->GetUnderlyingFrame();
|
2010-08-13 02:54:37 -07:00
|
|
|
if (f &&
|
|
|
|
item->IsVaryingRelativeToMovingFrame(aBuilder, aMovingFrame)) {
|
2010-07-15 14:08:06 -07:00
|
|
|
if (item->IsFixedAndCoveringViewport(aBuilder)) {
|
|
|
|
// FrameLayerBuilder takes care of scrolling these
|
|
|
|
} else {
|
2010-08-13 03:01:58 -07:00
|
|
|
f->Invalidate(item->GetVisibleRect() - item->ToReferenceFrame());
|
2010-07-15 14:08:06 -07:00
|
|
|
}
|
2010-07-15 14:08:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InvalidateFixedBackgroundFrames(nsIFrame* aRootFrame,
|
|
|
|
nsIFrame* aMovingFrame,
|
|
|
|
const nsRect& aUpdateRect)
|
|
|
|
{
|
|
|
|
if (!aMovingFrame->PresContext()->MayHaveFixedBackgroundFrames())
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ASSERTION(aRootFrame != aMovingFrame,
|
|
|
|
"The root frame shouldn't be the one that's moving, that makes no sense");
|
|
|
|
|
|
|
|
// Build the 'after' display list over the whole area of interest.
|
|
|
|
nsDisplayListBuilder builder(aRootFrame, PR_FALSE, PR_TRUE);
|
|
|
|
builder.EnterPresShell(aRootFrame, aUpdateRect);
|
|
|
|
nsDisplayList list;
|
|
|
|
nsresult rv =
|
|
|
|
aRootFrame->BuildDisplayListForStackingContext(&builder, aUpdateRect, &list);
|
|
|
|
builder.LeavePresShell(aRootFrame, aUpdateRect);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRegion visibleRegion(aUpdateRect);
|
2010-08-27 16:15:08 -07:00
|
|
|
list.ComputeVisibilityForRoot(&builder, &visibleRegion);
|
2010-07-15 14:08:02 -07:00
|
|
|
|
2010-08-13 02:54:37 -07:00
|
|
|
InvalidateFixedBackgroundFramesFromList(&builder, aMovingFrame, list);
|
2010-07-15 14:08:12 -07:00
|
|
|
list.DeleteAll();
|
2010-07-15 14:08:02 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
PRBool nsGfxScrollFrameInner::IsAlwaysActive() const
|
|
|
|
{
|
|
|
|
// The root scrollframe for a non-chrome document which is the direct
|
|
|
|
// child of a chrome document is always treated as "active".
|
2010-07-15 14:08:05 -07:00
|
|
|
// XXX maybe we should extend this so that IFRAMEs which are fill the
|
|
|
|
// entire viewport (like GMail!) are always active
|
|
|
|
return mIsRoot &&
|
|
|
|
!nsContentUtils::IsChildOfSameType(mOuter->GetContent()->GetCurrentDoc());
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsGfxScrollFrameInner::IsScrollingActive() const
|
|
|
|
{
|
|
|
|
return mScrollingActive || IsAlwaysActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsGfxScrollFrameInner::MarkActive()
|
|
|
|
{
|
|
|
|
if (IsAlwaysActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mScrollingActive = PR_TRUE;
|
|
|
|
if (mActivityExpirationState.IsTracked()) {
|
|
|
|
gScrollFrameActivityTracker->MarkUsed(this);
|
|
|
|
} else {
|
|
|
|
if (!gScrollFrameActivityTracker) {
|
|
|
|
gScrollFrameActivityTracker = new ScrollFrameActivityTracker();
|
|
|
|
}
|
|
|
|
gScrollFrameActivityTracker->AddObject(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
void nsGfxScrollFrameInner::ScrollVisual(nsIntPoint aPixDelta)
|
|
|
|
{
|
2010-07-15 14:08:08 -07:00
|
|
|
nsRootPresContext* rootPresContext = mOuter->PresContext()->GetRootPresContext();
|
2010-01-26 05:10:12 -08:00
|
|
|
if (!rootPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2010-07-15 14:08:08 -07:00
|
|
|
rootPresContext->RequestUpdatePluginGeometry(mOuter);
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2010-07-15 14:08:02 -07:00
|
|
|
AdjustViewsAndWidgets(mScrolledFrame, PR_FALSE);
|
|
|
|
// We need to call this after fixing up the widget and view positions
|
|
|
|
// to be consistent with the view and frame hierarchy.
|
|
|
|
PRUint32 flags = nsIFrame::INVALIDATE_REASON_SCROLL_REPAINT;
|
2010-04-22 19:41:38 -07:00
|
|
|
nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(mOuter);
|
2010-07-15 14:08:05 -07:00
|
|
|
if (IsScrollingActive() && CanScrollWithBlitting(mOuter, displayRoot)) {
|
2010-07-15 14:08:02 -07:00
|
|
|
flags |= nsIFrame::INVALIDATE_NO_THEBES_LAYERS;
|
|
|
|
}
|
2010-07-15 14:08:05 -07:00
|
|
|
MarkActive();
|
2010-07-15 14:08:02 -07:00
|
|
|
mOuter->InvalidateWithFlags(mScrollPort, flags);
|
2009-10-07 20:01:15 -07:00
|
|
|
|
2010-07-15 14:08:02 -07:00
|
|
|
if (flags & nsIFrame::INVALIDATE_NO_THEBES_LAYERS) {
|
2010-08-08 11:49:07 -07:00
|
|
|
nsRect update =
|
|
|
|
GetScrollPortRect() + mOuter->GetOffsetToCrossDoc(displayRoot);
|
|
|
|
update = update.ConvertAppUnitsRoundOut(
|
|
|
|
mOuter->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
displayRoot->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
InvalidateFixedBackgroundFrames(displayRoot, mScrolledFrame, update);
|
2009-10-07 20:01:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt32
|
|
|
|
ClampInt(nscoord aLower, nscoord aVal, nscoord aUpper, nscoord aAppUnitsPerPixel)
|
|
|
|
{
|
|
|
|
PRInt32 low = NSToIntCeil(float(aLower)/aAppUnitsPerPixel);
|
|
|
|
PRInt32 high = NSToIntFloor(float(aUpper)/aAppUnitsPerPixel);
|
|
|
|
PRInt32 v = NSToIntRound(float(aVal)/aAppUnitsPerPixel);
|
|
|
|
NS_ASSERTION(low <= high, "No integers in range; 0 is supposed to be in range");
|
|
|
|
if (v < low)
|
|
|
|
return low;
|
|
|
|
if (v > high)
|
|
|
|
return high;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsGfxScrollFrameInner::ClampAndRestrictToDevPixels(const nsPoint& aPt,
|
|
|
|
nsIntPoint* aPtDevPx) const
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
// Convert to device pixels so we scroll to an integer offset of device
|
|
|
|
// pixels. But we also need to make sure that our position remains
|
|
|
|
// inside the allowed region.
|
|
|
|
nsRect scrollRange = GetScrollRange();
|
|
|
|
*aPtDevPx = nsIntPoint(ClampInt(scrollRange.x, aPt.x, scrollRange.XMost(), appUnitsPerDevPixel),
|
|
|
|
ClampInt(scrollRange.y, aPt.y, scrollRange.YMost(), appUnitsPerDevPixel));
|
|
|
|
return nsPoint(NSIntPixelsToAppUnits(aPtDevPx->x, appUnitsPerDevPixel),
|
|
|
|
NSIntPixelsToAppUnits(aPtDevPx->y, appUnitsPerDevPixel));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ScrollToImpl(nsPoint aPt)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
nsIntPoint ptDevPx;
|
|
|
|
nsPoint pt = ClampAndRestrictToDevPixels(aPt, &ptDevPx);
|
|
|
|
|
|
|
|
nsPoint curPos = GetScrollPosition();
|
|
|
|
if (pt == curPos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIntPoint curPosDevPx(NSAppUnitsToIntPixels(curPos.x, appUnitsPerDevPixel),
|
|
|
|
NSAppUnitsToIntPixels(curPos.y, appUnitsPerDevPixel));
|
|
|
|
// We maintain the invariant that the scroll position is a multiple of device
|
|
|
|
// pixels.
|
|
|
|
NS_ASSERTION(curPosDevPx.x*appUnitsPerDevPixel == curPos.x,
|
|
|
|
"curPos.x not a multiple of device pixels");
|
|
|
|
NS_ASSERTION(curPosDevPx.y*appUnitsPerDevPixel == curPos.y,
|
|
|
|
"curPos.y not a multiple of device pixels");
|
|
|
|
|
|
|
|
// notify the listeners.
|
2010-05-02 05:56:00 -07:00
|
|
|
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
2009-10-07 20:01:15 -07:00
|
|
|
mListeners[i]->ScrollPositionWillChange(pt.x, pt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update frame position for scrolling
|
|
|
|
mScrolledFrame->SetPosition(mScrollPort.TopLeft() - pt);
|
|
|
|
|
|
|
|
// We pass in the amount to move visually
|
|
|
|
ScrollVisual(curPosDevPx - ptDevPx);
|
|
|
|
|
|
|
|
presContext->PresShell()->GetViewManager()->SynthesizeMouseMove(PR_TRUE);
|
|
|
|
UpdateScrollbarPosition();
|
|
|
|
PostScrollEvent();
|
|
|
|
|
|
|
|
// notify the listeners.
|
2010-05-02 05:56:00 -07:00
|
|
|
for (PRUint32 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,
|
|
|
|
nsDisplayList* aSource, nsIFrame* aSourceFrame, PRBool aOwnLayer)
|
|
|
|
{
|
|
|
|
if (aOwnLayer) {
|
2010-08-13 03:01:13 -07:00
|
|
|
aDest->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayOwnLayer(aBuilder, aSourceFrame, aSource));
|
2010-07-15 14:08:03 -07:00
|
|
|
} else {
|
|
|
|
aDest->AppendToTop(aSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsresult rv = mOuter->DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-19 04:49:34 -07:00
|
|
|
|
2010-07-15 14:08:02 -07:00
|
|
|
if (aBuilder->IsPaintingToWindow()) {
|
|
|
|
mScrollPosAtLastPaint = GetScrollPosition();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aBuilder->GetIgnoreScrollFrame() == mOuter) {
|
|
|
|
// 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.
|
|
|
|
return mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame,
|
|
|
|
aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-02-25 23:00:36 -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.
|
2010-03-19 04:49:34 -07:00
|
|
|
PRBool hasResizer = HasResizer();
|
2010-06-27 17:28:47 -07:00
|
|
|
nsDisplayListCollection scrollParts;
|
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.
|
|
|
|
PRBool createLayersForScrollbars = mIsRoot &&
|
|
|
|
!nsContentUtils::IsChildOfSameType(mOuter->GetContent()->GetCurrentDoc());
|
2010-03-19 04:49:34 -07:00
|
|
|
for (nsIFrame* kid = mOuter->GetFirstChild(nsnull); kid; kid = kid->GetNextSibling()) {
|
2009-02-25 23:00:36 -08:00
|
|
|
if (kid != mScrolledFrame) {
|
2010-03-19 04:49:34 -07:00
|
|
|
if (kid == mScrollCornerBox && hasResizer) {
|
|
|
|
// skip the resizer as this will be drawn later on top of the scrolled content
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-27 17:28:47 -07:00
|
|
|
rv = mOuter->BuildDisplayListForChild(aBuilder, kid, aDirtyRect, scrollParts,
|
|
|
|
nsIFrame::DISPLAY_CHILD_FORCE_STACKING_CONTEXT);
|
2009-02-25 23:00:36 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-07-15 14:08:03 -07:00
|
|
|
// DISPLAY_CHILD_FORCE_STACKING_CONTEXT put everything into the
|
|
|
|
// PositionedDescendants list.
|
|
|
|
::AppendToTop(aBuilder, aLists.BorderBackground(),
|
|
|
|
scrollParts.PositionedDescendants(), kid,
|
|
|
|
createLayersForScrollbars);
|
2009-02-25 23:00:36 -08:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
|
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.
|
2009-10-07 20:01:15 -07:00
|
|
|
dirtyRect.IntersectRect(aDirtyRect, mScrollPort);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDisplayListCollection set;
|
|
|
|
rv = mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame, dirtyRect, set);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect clip = mScrollPort + aBuilder->ToReferenceFrame(mOuter);
|
2007-03-22 10:30:00 -07:00
|
|
|
// mScrolledFrame may have given us a background, e.g., the scrolled canvas
|
|
|
|
// frame below the viewport. If so, we want it to be clipped. We also want
|
|
|
|
// to end up on our BorderBackground list.
|
|
|
|
// If we are the viewport scrollframe, then clip all our descendants (to ensure
|
|
|
|
// that fixed-pos elements get clipped by us).
|
|
|
|
rv = mOuter->OverflowClip(aBuilder, set, aLists, clip, PR_TRUE, mIsRoot);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-27 17:28:47 -07:00
|
|
|
// Place the resizer in the display list in our Content() list above
|
|
|
|
// scrolled content in the Content() list.
|
|
|
|
// This ensures that the resizer appears above the content and the mouse can
|
2010-03-19 04:49:34 -07:00
|
|
|
// still target the resizer even when scrollbars are hidden.
|
|
|
|
if (hasResizer && mScrollCornerBox) {
|
2010-06-27 17:28:47 -07:00
|
|
|
rv = mOuter->BuildDisplayListForChild(aBuilder, mScrollCornerBox, aDirtyRect, scrollParts,
|
|
|
|
nsIFrame::DISPLAY_CHILD_FORCE_STACKING_CONTEXT);
|
2010-03-19 04:49:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-27 17:28:47 -07:00
|
|
|
// DISPLAY_CHILD_FORCE_STACKING_CONTEXT puts everything into the
|
|
|
|
// PositionedDescendants list.
|
2010-07-15 14:08:03 -07:00
|
|
|
::AppendToTop(aBuilder, aLists.Content(),
|
|
|
|
scrollParts.PositionedDescendants(), mScrollCornerBox,
|
|
|
|
createLayersForScrollbars);
|
2010-03-19 04:49:34 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleScrollPref(nsIScrollable *aScrollable, PRInt32 aOrientation,
|
|
|
|
PRUint8& aValue)
|
|
|
|
{
|
|
|
|
PRInt32 pref;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles
|
|
|
|
nsGfxScrollFrameInner::GetScrollbarStylesFromFrame() const
|
|
|
|
{
|
|
|
|
ScrollbarStyles result;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsRoot) {
|
|
|
|
result = presContext->GetViewportOverflowOverride();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = presContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
|
|
|
|
if (scrollable) {
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
|
|
|
|
result.mHorizontal);
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_Y,
|
|
|
|
result.mVertical);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const nsStyleDisplay *disp = mOuter->GetStyleDisplay();
|
|
|
|
result.mHorizontal = disp->mOverflowX;
|
|
|
|
result.mVertical = disp->mOverflowY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(result.mHorizontal != NS_STYLE_OVERFLOW_VISIBLE &&
|
|
|
|
result.mHorizontal != NS_STYLE_OVERFLOW_CLIP &&
|
|
|
|
result.mVertical != NS_STYLE_OVERFLOW_VISIBLE &&
|
|
|
|
result.mVertical != NS_STYLE_OVERFLOW_CLIP,
|
|
|
|
"scrollbars should not have been created");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
static nscoord
|
|
|
|
AlignToDevPixelRoundingToZero(nscoord aVal, PRInt32 aAppUnitsPerDevPixel)
|
|
|
|
{
|
|
|
|
return (aVal/aAppUnitsPerDevPixel)*aAppUnitsPerDevPixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsGfxScrollFrameInner::GetScrollRange() const
|
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect range = GetScrolledRect();
|
|
|
|
range.width -= mScrollPort.width;
|
|
|
|
range.height -= mScrollPort.height;
|
2009-08-31 21:11:11 -07:00
|
|
|
|
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
|
|
|
PRInt32 appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
range.width =
|
|
|
|
AlignToDevPixelRoundingToZero(range.XMost(), appUnitsPerDevPixel) - range.x;
|
|
|
|
range.height =
|
|
|
|
AlignToDevPixelRoundingToZero(range.YMost(), appUnitsPerDevPixel) - range.y;
|
|
|
|
range.x = AlignToDevPixelRoundingToZero(range.x, appUnitsPerDevPixel);
|
|
|
|
range.y = AlignToDevPixelRoundingToZero(range.y, appUnitsPerDevPixel);
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AdjustForWholeDelta(PRInt32 aDelta, nscoord* aCoord)
|
|
|
|
{
|
|
|
|
if (aDelta < 0) {
|
|
|
|
*aCoord = nscoord_MIN;
|
|
|
|
} else if (aDelta > 0) {
|
|
|
|
*aCoord = nscoord_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ScrollBy(nsIntPoint aDelta,
|
|
|
|
nsIScrollableFrame::ScrollUnit aUnit,
|
|
|
|
nsIScrollableFrame::ScrollMode aMode,
|
|
|
|
nsIntPoint* aOverflow)
|
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize deltaMultiplier;
|
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);
|
2009-08-31 21:11:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIScrollableFrame::LINES: {
|
2009-10-07 20:01:15 -07:00
|
|
|
deltaMultiplier = GetLineScrollAmount();
|
2009-08-31 21:11:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIScrollableFrame::PAGES: {
|
2009-10-07 20:01:15 -07:00
|
|
|
deltaMultiplier = GetPageScrollAmount();
|
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);
|
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);
|
|
|
|
ScrollTo(newPos, aMode);
|
|
|
|
|
2009-08-31 21:11:11 -07:00
|
|
|
if (aOverflow) {
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint clampAmount = mDestination - newPos;
|
|
|
|
float appUnitsPerDevPixel = mOuter->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
*aOverflow = nsIntPoint(
|
|
|
|
NSAppUnitsToIntPixels(PR_ABS(clampAmount.x), appUnitsPerDevPixel),
|
|
|
|
NSAppUnitsToIntPixels(PR_ABS(clampAmount.y), appUnitsPerDevPixel));
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsGfxScrollFrameInner::GetLineScrollAmount() const
|
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
const nsStyleFont* font = mOuter->GetStyleFont();
|
|
|
|
const nsFont& f = font->mFont;
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm = mOuter->PresContext()->GetMetricsFor(f);
|
|
|
|
NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit");
|
|
|
|
nscoord fontHeight = 1;
|
|
|
|
if (fm) {
|
|
|
|
fm->GetHeight(fontHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSize(fontHeight, fontHeight);
|
2009-08-31 21:11:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsGfxScrollFrameInner::GetPageScrollAmount() const
|
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsSize lineScrollAmount = GetLineScrollAmount();
|
|
|
|
// The page increment is the size of the page, minus the smaller of
|
|
|
|
// 10% of the size or 2 lines.
|
|
|
|
return nsSize(
|
|
|
|
mScrollPort.width - NS_MIN(mScrollPort.width/10, 2*lineScrollAmount.width),
|
|
|
|
mScrollPort.height - NS_MIN(mScrollPort.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
|
|
|
|
nsGfxScrollFrameInner::ScrollToRestoredPosition()
|
|
|
|
{
|
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.
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint scrollPos = GetScrollPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if we didn't move, we still need to restore
|
2009-10-07 20:01:15 -07:00
|
|
|
if (scrollPos == mLastPos) {
|
|
|
|
// 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.
|
2009-10-07 20:01:15 -07:00
|
|
|
if (mRestorePos != scrollPos) {
|
|
|
|
ScrollTo(mRestorePos, nsIScrollableFrame::INSTANT);
|
|
|
|
// Re-get the scroll position, it might not be exactly equal to
|
|
|
|
// mRestorePos due to rounding and clamping.
|
|
|
|
mLastPos = GetScrollPosition();
|
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
|
|
|
|
nsGfxScrollFrameInner::FireScrollPortEvent()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
PRBool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
PRBool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
|
|
|
|
|
|
|
PRBool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
PRBool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
|
|
|
|
|
|
|
if (!vertChanged && !horizChanged) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If both either overflowed or underflowed then we dispatch only one
|
|
|
|
// DOM event.
|
|
|
|
PRBool both = vertChanged && horizChanged &&
|
|
|
|
newVerticalOverflow == newHorizontalOverflow;
|
|
|
|
nsScrollPortEvent::orientType orient;
|
|
|
|
if (both) {
|
|
|
|
orient = nsScrollPortEvent::both;
|
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
mVerticalOverflow = newVerticalOverflow;
|
|
|
|
}
|
|
|
|
else if (vertChanged) {
|
|
|
|
orient = nsScrollPortEvent::vertical;
|
|
|
|
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 {
|
|
|
|
orient = nsScrollPortEvent::horizontal;
|
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScrollPortEvent event(PR_TRUE,
|
|
|
|
(orient == nsScrollPortEvent::horizontal ?
|
|
|
|
mHorizontalOverflow : mVerticalOverflow) ?
|
|
|
|
NS_SCROLLPORT_OVERFLOW : NS_SCROLLPORT_UNDERFLOW,
|
|
|
|
nsnull);
|
|
|
|
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
|
|
|
|
nsGfxScrollFrameInner::ReloadChildFrames()
|
|
|
|
{
|
|
|
|
mScrolledFrame = nsnull;
|
|
|
|
mHScrollbarBox = nsnull;
|
|
|
|
mVScrollbarBox = nsnull;
|
|
|
|
mScrollCornerBox = nsnull;
|
|
|
|
|
|
|
|
nsIFrame* frame = mOuter->GetFirstChild(nsnull);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// probably a scrollcorner
|
|
|
|
NS_ASSERTION(!mScrollCornerBox, "Found multiple scrollcorners");
|
|
|
|
mScrollCornerBox = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* parent = mOuter->GetParent();
|
|
|
|
|
|
|
|
// Don't create scrollbars if we're printing/print previewing
|
|
|
|
// Get rid of this code when printing moves to its own presentation
|
|
|
|
if (!presContext->IsDynamic()) {
|
|
|
|
// allow scrollbars if this is the child of the viewport, because
|
|
|
|
// we must be the scrollbars for the print preview window
|
|
|
|
if (!(mIsRoot && presContext->HasPaginatedScrolling())) {
|
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
// Check if the frame is resizable.
|
2010-03-23 10:14:47 -07:00
|
|
|
PRInt8 resizeStyle = mOuter->GetStyleDisplay()->mResize;
|
|
|
|
PRBool 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!).
|
|
|
|
PRBool canHaveHorizontal;
|
|
|
|
PRBool canHaveVertical;
|
|
|
|
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 {
|
|
|
|
canHaveHorizontal = PR_TRUE;
|
|
|
|
canHaveVertical = PR_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) {
|
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNodeInfoManager *nodeInfoManager =
|
|
|
|
presContext->Document()->NodeInfoManager();
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-12 15:32:18 -07:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbar, nsnull,
|
|
|
|
kNameSpaceID_XUL);
|
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,
|
|
|
|
NS_LITERAL_STRING("horizontal"), PR_FALSE);
|
2010-07-16 06:01:39 -07:00
|
|
|
mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
|
|
|
NS_LITERAL_STRING("always"), PR_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,
|
|
|
|
NS_LITERAL_STRING("vertical"), PR_FALSE);
|
2010-07-16 06:01:39 -07:00
|
|
|
mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
|
|
|
NS_LITERAL_STRING("always"), PR_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;
|
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::resizer, nsnull,
|
|
|
|
kNameSpaceID_XUL);
|
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mScrollCornerContent), 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");
|
|
|
|
}
|
|
|
|
mScrollCornerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, dir, PR_FALSE);
|
|
|
|
mScrollCornerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::element,
|
|
|
|
NS_LITERAL_STRING("_parent"), PR_FALSE);
|
2010-07-16 06:01:39 -07:00
|
|
|
mScrollCornerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
|
|
|
NS_LITERAL_STRING("always"), PR_FALSE);
|
2010-03-19 04:49:34 -07:00
|
|
|
|
|
|
|
if (!aElements.AppendElement(mScrollCornerContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else if (canHaveHorizontal && canHaveVertical) {
|
2008-09-12 15:32:18 -07:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollcorner, nsnull,
|
|
|
|
kNameSpaceID_XUL);
|
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
|
2010-02-20 16:52:50 -08:00
|
|
|
nsGfxScrollFrameInner::AppendAnonymousContentTo(nsBaseContentList& aElements)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mHScrollbarContent);
|
|
|
|
aElements.MaybeAppendElement(mVScrollbarContent);
|
|
|
|
aElements.MaybeAppendElement(mScrollCornerContent);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::Destroy()
|
|
|
|
{
|
|
|
|
// Unbind any content created in CreateAnonymousContent from the tree
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mHScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mVScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mScrollCornerContent);
|
|
|
|
|
|
|
|
if (mPostedReflowCallback) {
|
2007-03-30 14:11:41 -07:00
|
|
|
mOuter->PresContext()->PresShell()->CancelReflowCallback(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2009-10-07 20:01:15 -07:00
|
|
|
nsGfxScrollFrameInner::UpdateScrollbarPosition()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
mFrameIsUpdatingScrollbar = PR_TRUE;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
2009-09-29 15:18:20 -07:00
|
|
|
}
|
2008-09-03 14:35:52 -07:00
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
mFrameIsUpdatingScrollbar = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
nscoord x = GetCoordAttribute(mHScrollbarBox, nsGkAtoms::curpos,
|
|
|
|
-scrolledRect.x) +
|
|
|
|
scrolledRect.x;
|
|
|
|
nscoord y = GetCoordAttribute(mVScrollbarBox, nsGkAtoms::curpos,
|
|
|
|
-scrolledRect.y) +
|
|
|
|
scrolledRect.y;
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
PRBool isSmooth = aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::smooth);
|
|
|
|
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.
|
|
|
|
UpdateScrollbarPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
ScrollTo(nsPoint(x, y),
|
|
|
|
isSmooth ? nsIScrollableFrame::SMOOTH : nsIScrollableFrame::INSTANT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ============= Scroll events ========== */
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxScrollFrameInner::ScrollEvent::Run()
|
|
|
|
{
|
|
|
|
if (mInner)
|
|
|
|
mInner->FireScrollEvent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::FireScrollEvent()
|
|
|
|
{
|
|
|
|
mScrollEvent.Forget();
|
|
|
|
|
|
|
|
nsScrollbarEvent event(PR_TRUE, NS_SCROLL_EVENT, nsnull);
|
|
|
|
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) {
|
|
|
|
nsEventDispatcher::Dispatch(doc, prescontext, &event, nsnull, &status);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// scroll events fired at elements don't bubble (although scroll events
|
|
|
|
// fired at documents do, to the window)
|
|
|
|
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
nsEventDispatcher::Dispatch(content, prescontext, &event, nsnull, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::PostScrollEvent()
|
|
|
|
{
|
|
|
|
if (mScrollEvent.IsPending())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRefPtr<ScrollEvent> ev = new ScrollEvent(this);
|
|
|
|
if (NS_FAILED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
NS_WARNING("failed to dispatch ScrollEvent");
|
|
|
|
} else {
|
|
|
|
mScrollEvent = ev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxScrollFrameInner::AsyncScrollPortEvent::Run()
|
|
|
|
{
|
2007-04-13 07:07:40 -07:00
|
|
|
if (mInner) {
|
|
|
|
mInner->mOuter->PresContext()->GetPresShell()->
|
2009-04-21 16:53:52 -07:00
|
|
|
FlushPendingNotifications(Flush_InterruptibleLayout);
|
2007-04-13 07:07:40 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return mInner ? mInner->FireScrollPortEvent() : NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::AddHorizontalScrollbar(nsBoxLayoutState& aState, PRBool aOnTop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mInner.mHScrollbarBox)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
return AddRemoveScrollbar(aState, aOnTop, PR_TRUE, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::AddVerticalScrollbar(nsBoxLayoutState& aState, PRBool aOnRight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mInner.mVScrollbarBox)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
return AddRemoveScrollbar(aState, aOnRight, PR_FALSE, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::RemoveHorizontalScrollbar(nsBoxLayoutState& aState, PRBool aOnTop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// removing a scrollbar should always fit
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool result =
|
|
|
|
#endif
|
2009-10-07 20:01:15 -07:00
|
|
|
AddRemoveScrollbar(aState, aOnTop, PR_TRUE, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(result, "Removing horizontal scrollbar failed to fit??");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::RemoveVerticalScrollbar(nsBoxLayoutState& aState, PRBool aOnRight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// removing a scrollbar should always fit
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool result =
|
|
|
|
#endif
|
2009-10-07 20:01:15 -07:00
|
|
|
AddRemoveScrollbar(aState, aOnRight, PR_FALSE, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(result, "Removing vertical scrollbar failed to fit??");
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(nsBoxLayoutState& aState,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aOnTop, PRBool aHorizontal, PRBool aAdd)
|
|
|
|
{
|
|
|
|
if (aHorizontal) {
|
|
|
|
if (mInner.mNeverHasHorizontalScrollbar || !mInner.mHScrollbarBox)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetPrefSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mInner.mHScrollbarBox, hSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, aAdd);
|
|
|
|
|
|
|
|
PRBool hasHorizontalScrollbar;
|
2009-10-07 20:01:15 -07:00
|
|
|
PRBool fit = AddRemoveScrollbar(hasHorizontalScrollbar,
|
|
|
|
mInner.mScrollPort.y,
|
|
|
|
mInner.mScrollPort.height,
|
|
|
|
hSize.height, aOnTop, aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner.mHasHorizontalScrollbar = hasHorizontalScrollbar; // because mHasHorizontalScrollbar is a PRPackedBool
|
|
|
|
if (!fit)
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, !aAdd);
|
|
|
|
|
|
|
|
return fit;
|
|
|
|
} else {
|
|
|
|
if (mInner.mNeverHasVerticalScrollbar || !mInner.mVScrollbarBox)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetPrefSize(aState);
|
2010-04-02 15:25:40 -07:00
|
|
|
nsBox::AddMargin(mInner.mVScrollbarBox, vSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, aAdd);
|
|
|
|
|
|
|
|
PRBool hasVerticalScrollbar;
|
2009-10-07 20:01:15 -07:00
|
|
|
PRBool fit = AddRemoveScrollbar(hasVerticalScrollbar,
|
|
|
|
mInner.mScrollPort.x,
|
|
|
|
mInner.mScrollPort.width,
|
|
|
|
vSize.width, aOnTop, aAdd);
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner.mHasVerticalScrollbar = hasVerticalScrollbar; // because mHasVerticalScrollbar is a PRPackedBool
|
|
|
|
if (!fit)
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, !aAdd);
|
|
|
|
|
|
|
|
return fit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(PRBool& aHasScrollbar, nscoord& aXY,
|
|
|
|
nscoord& aSize, nscoord aSbSize,
|
|
|
|
PRBool aRightOrBottom, PRBool aAdd)
|
|
|
|
{
|
|
|
|
nscoord size = aSize;
|
|
|
|
nscoord xy = aXY;
|
|
|
|
|
|
|
|
if (size != NS_INTRINSICSIZE) {
|
|
|
|
if (aAdd) {
|
|
|
|
size -= aSbSize;
|
|
|
|
if (!aRightOrBottom && size >= 0)
|
|
|
|
xy += aSbSize;
|
|
|
|
} else {
|
|
|
|
size += aSbSize;
|
|
|
|
if (!aRightOrBottom)
|
|
|
|
xy -= aSbSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not enough room? Yes? Return true.
|
|
|
|
if (size >= 0) {
|
|
|
|
aHasScrollbar = aAdd;
|
|
|
|
aSize = size;
|
|
|
|
aXY = xy;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aHasScrollbar = PR_FALSE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 20:01:15 -07:00
|
|
|
nsXULScrollFrame::LayoutScrollArea(nsBoxLayoutState& aState,
|
|
|
|
const nsPoint& aScrollPosition)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRUint32 oldflags = aState.LayoutFlags();
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect childRect = nsRect(mInner.mScrollPort.TopLeft() - aScrollPosition,
|
|
|
|
mInner.mScrollPort.Size());
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 flags = NS_FRAME_NO_MOVE_VIEW;
|
|
|
|
|
2010-01-27 20:12:42 -08:00
|
|
|
nsRect originalRect = mInner.mScrolledFrame->GetRect();
|
|
|
|
nsRect originalOverflow = mInner.mScrolledFrame->GetOverflowRect();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize minSize = mInner.mScrolledFrame->GetMinSize(aState);
|
|
|
|
|
|
|
|
if (minSize.height > childRect.height)
|
|
|
|
childRect.height = minSize.height;
|
|
|
|
|
|
|
|
if (minSize.width > childRect.width)
|
|
|
|
childRect.width = minSize.width;
|
|
|
|
|
|
|
|
aState.SetLayoutFlags(flags);
|
|
|
|
mInner.mScrolledFrame->SetBounds(aState, childRect);
|
|
|
|
mInner.mScrolledFrame->Layout(aState);
|
|
|
|
|
|
|
|
childRect = mInner.mScrolledFrame->GetRect();
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
if (childRect.width < mInner.mScrollPort.width ||
|
|
|
|
childRect.height < mInner.mScrollPort.height)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
childRect.width = NS_MAX(childRect.width, mInner.mScrollPort.width);
|
|
|
|
childRect.height = NS_MAX(childRect.height, mInner.mScrollPort.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// remove overflow area when we update the bounds,
|
|
|
|
// because we've already accounted for it
|
2007-03-27 23:24:40 -07:00
|
|
|
mInner.mScrolledFrame->SetBounds(aState, childRect);
|
2009-04-05 17:31:50 -07:00
|
|
|
mInner.mScrolledFrame->ClearOverflowRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-01-27 20:12:42 -08:00
|
|
|
nsRect finalRect = mInner.mScrolledFrame->GetRect();
|
|
|
|
nsRect finalOverflow = mInner.mScrolledFrame->GetOverflowRect();
|
|
|
|
// The position of the scrolled frame shouldn't change, but if it does or
|
|
|
|
// the position of the overflow rect changes just invalidate both the old
|
|
|
|
// and new overflow rect.
|
|
|
|
if (originalRect.TopLeft() != finalRect.TopLeft() ||
|
|
|
|
originalOverflow.TopLeft() != finalOverflow.TopLeft())
|
|
|
|
{
|
|
|
|
// The old overflow rect needs to be adjusted if the frame's position
|
|
|
|
// changed.
|
|
|
|
mInner.mScrolledFrame->Invalidate(
|
|
|
|
originalOverflow + originalRect.TopLeft() - finalRect.TopLeft());
|
|
|
|
mInner.mScrolledFrame->Invalidate(finalOverflow);
|
|
|
|
} else if (!originalOverflow.IsExactEqual(finalOverflow)) {
|
|
|
|
// If the overflow rect changed then invalidate the difference between the
|
|
|
|
// old and new overflow rects.
|
|
|
|
mInner.mScrolledFrame->CheckInvalidateSizeChange(
|
|
|
|
originalRect, originalOverflow, finalRect.Size());
|
|
|
|
mInner.mScrolledFrame->InvalidateRectDifference(
|
|
|
|
originalOverflow, finalOverflow);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aState.SetLayoutFlags(oldflags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsGfxScrollFrameInner::PostOverflowEvent()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
PRBool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
PRBool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
|
|
|
|
|
|
|
PRBool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
PRBool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
|
|
|
|
|
|
|
if (!vertChanged && !horizChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<AsyncScrollPortEvent> ev = new AsyncScrollPortEvent(this);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev)))
|
|
|
|
mAsyncScrollPortEvent = ev;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::IsLTR() const
|
|
|
|
{
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame->GetStyleVisibility()->mDirection != NS_STYLE_DIRECTION_RTL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::IsScrollbarOnRight() const
|
|
|
|
{
|
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
|
|
|
|
return PR_TRUE;
|
|
|
|
case 3: // Always left
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
PRBool scrollbarRight = mInner.IsScrollbarOnRight();
|
|
|
|
PRBool scrollbarBottom = PR_TRUE;
|
|
|
|
|
|
|
|
// get the content rect
|
|
|
|
nsRect clientRect(0,0,0,0);
|
|
|
|
GetClientRect(clientRect);
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect oldScrollAreaBounds = mInner.mScrollPort;
|
|
|
|
nsPoint oldScrollPosition = mInner.GetScrollPosition();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// the scroll area size starts off as big as our content area
|
2009-10-07 20:01:15 -07:00
|
|
|
mInner.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)
|
|
|
|
mInner.mHasHorizontalScrollbar = PR_TRUE;
|
|
|
|
if (styles.mVertical == NS_STYLE_OVERFLOW_SCROLL)
|
|
|
|
mInner.mHasVerticalScrollbar = PR_TRUE;
|
|
|
|
|
|
|
|
if (mInner.mHasHorizontalScrollbar)
|
2009-10-07 20:01:15 -07:00
|
|
|
AddHorizontalScrollbar(aState, scrollbarBottom);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mInner.mHasVerticalScrollbar)
|
2009-10-07 20:01:15 -07:00
|
|
|
AddVerticalScrollbar(aState, scrollbarRight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// layout our the scroll area
|
2009-10-07 20:01:15 -07:00
|
|
|
LayoutScrollArea(aState, oldScrollPosition);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// now look at the content area and see if we need scrollbars or not
|
|
|
|
PRBool needsLayout = PR_FALSE;
|
|
|
|
|
|
|
|
// 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.
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize scrolledContentSize(scrolledRect.XMost(), scrolledRect.YMost());
|
|
|
|
|
|
|
|
// There are two cases to consider
|
2009-10-07 20:01:15 -07:00
|
|
|
if (scrolledContentSize.height <= mInner.mScrollPort.height
|
2007-03-22 10:30:00 -07:00
|
|
|
|| styles.mVertical != NS_STYLE_OVERFLOW_AUTO) {
|
|
|
|
if (mInner.mHasVerticalScrollbar) {
|
|
|
|
// 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);
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!mInner.mHasVerticalScrollbar) {
|
|
|
|
// 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))
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok layout at the right 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
|
|
|
needsLayout = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize scrolledContentSize(scrolledRect.XMost(), scrolledRect.YMost());
|
|
|
|
|
|
|
|
// if the child is wider that the scroll area
|
|
|
|
// and we don't have a scrollbar add one.
|
2009-10-07 20:01:15 -07:00
|
|
|
if (scrolledContentSize.width > mInner.mScrollPort.width
|
2007-03-22 10:30:00 -07:00
|
|
|
&& styles.mHorizontal == NS_STYLE_OVERFLOW_AUTO) {
|
|
|
|
|
|
|
|
if (!mInner.mHasHorizontalScrollbar) {
|
|
|
|
// no scrollbar?
|
2009-10-07 20:01:15 -07:00
|
|
|
if (AddHorizontalScrollbar(aState, scrollbarBottom))
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
|
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
|
2007-03-22 10:30:00 -07:00
|
|
|
// suddenly need a vertical scrollbar. Is a special case but its
|
|
|
|
// important.
|
|
|
|
//if (!mHasVerticalScrollbar && scrolledContentSize.height > scrollAreaRect.height - sbSize.height)
|
|
|
|
// printf("****Gfx Scrollbar Special case hit!!*****\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if the area is smaller or equal to and we have a scrollbar then
|
|
|
|
// remove it.
|
|
|
|
if (mInner.mHasHorizontalScrollbar) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveHorizontalScrollbar(aState, scrollbarBottom);
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
needsLayout = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the preferred size of the scrollbars
|
|
|
|
nsSize hMinSize(0, 0);
|
|
|
|
if (mInner.mHScrollbarBox && mInner.mHasHorizontalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mInner.mHScrollbarBox, &hMinSize, nsnull, PR_FALSE);
|
|
|
|
}
|
|
|
|
nsSize vMinSize(0, 0);
|
|
|
|
if (mInner.mVScrollbarBox && mInner.mHasVerticalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mInner.mVScrollbarBox, &vMinSize, nsnull, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (mInner.mHasHorizontalScrollbar &&
|
|
|
|
(hMinSize.width > clientRect.width - vMinSize.width
|
|
|
|
|| hMinSize.height > clientRect.height)) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveHorizontalScrollbar(aState, scrollbarBottom);
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
// Now disable vertical scrollbar if necessary
|
|
|
|
if (mInner.mHasVerticalScrollbar &&
|
|
|
|
(vMinSize.height > clientRect.height - hMinSize.height
|
|
|
|
|| vMinSize.width > clientRect.width)) {
|
2009-10-07 20:01:15 -07:00
|
|
|
RemoveVerticalScrollbar(aState, scrollbarRight);
|
2007-03-22 10:30:00 -07:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
if (!mInner.mSupppressScrollbarUpdate) {
|
2009-10-07 20:01:15 -07:00
|
|
|
mInner.LayoutScrollbars(aState, clientRect, oldScrollAreaBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-06-23 18:35:00 -07:00
|
|
|
if (!mInner.mPostedReflowCallback) {
|
|
|
|
// Make sure we'll try scrolling to restored position
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(&mInner);
|
|
|
|
mInner.mPostedReflowCallback = PR_TRUE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
mInner.mHadNonInitialReflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInner.PostOverflowEvent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::FinishReflowForScrollbar(nsIContent* aContent,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::ReflowFinished()
|
|
|
|
{
|
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
|
2009-06-23 18:35:00 -07:00
|
|
|
ScrollToRestoredPosition();
|
|
|
|
|
2010-03-28 18:46:59 -07:00
|
|
|
// Clamp scroll position
|
|
|
|
ScrollToImpl(GetScrollPosition());
|
|
|
|
|
2009-06-23 18:35:00 -07:00
|
|
|
if (NS_SUBTREE_DIRTY(mOuter) || !mUpdateScrollbarAttributes)
|
2009-06-11 18:46:33 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-06-23 18:35:00 -07:00
|
|
|
mUpdateScrollbarAttributes = PR_FALSE;
|
|
|
|
|
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) {
|
|
|
|
mMayHaveDirtyFixedChildren = PR_FALSE;
|
|
|
|
nsIFrame* parentFrame = mOuter->GetParent();
|
|
|
|
for (nsIFrame* fixedChild =
|
|
|
|
parentFrame->GetFirstChild(nsGkAtoms::fixedList);
|
|
|
|
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");
|
|
|
|
mFrameIsUpdatingScrollbar = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> vScroll =
|
|
|
|
mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull;
|
|
|
|
nsCOMPtr<nsIContent> hScroll =
|
|
|
|
mHScrollbarBox ? mHScrollbarBox->GetContent() : nsnull;
|
|
|
|
|
|
|
|
// Note, in some cases mOuter may get deleted while finishing reflow
|
|
|
|
// for scrollbars.
|
|
|
|
if (vScroll || hScroll) {
|
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint scrollPos = GetScrollPosition();
|
|
|
|
// XXX shouldn't we use GetPageScrollAmount/GetLineScrollAmount here?
|
2007-03-22 10:30:00 -07:00
|
|
|
if (vScroll) {
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord fontHeight = GetLineScrollAmount().height;
|
2008-02-23 23:35:08 -08:00
|
|
|
// We normally use (scrollArea.height - fontHeight) for height
|
|
|
|
// of page scrolling. However, it is too small when
|
|
|
|
// fontHeight is very large. (If fontHeight is larger than
|
|
|
|
// 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)
|
2009-10-07 20:01:15 -07:00
|
|
|
nscoord pageincrement = nscoord(mScrollPort.height - fontHeight);
|
|
|
|
nscoord pageincrementMin = nscoord(float(mScrollPort.height) * 0.8);
|
|
|
|
FinishReflowForScrollbar(vScroll, minY, maxY, scrollPos.y,
|
2009-09-16 08:01:36 -07:00
|
|
|
NS_MAX(pageincrement,pageincrementMin),
|
2007-03-22 10:30:00 -07:00
|
|
|
fontHeight);
|
|
|
|
}
|
|
|
|
if (hScroll) {
|
2009-10-07 20:01:15 -07:00
|
|
|
FinishReflowForScrollbar(hScroll, minX, maxX, scrollPos.x,
|
|
|
|
nscoord(float(mScrollPort.width) * 0.8),
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(10));
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
mFrameIsUpdatingScrollbar = PR_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)
|
|
|
|
return PR_FALSE;
|
|
|
|
CurPosAttributeChanged(mVScrollbarBox ? mVScrollbarBox->GetContent()
|
|
|
|
: mHScrollbarBox->GetContent());
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-30 23:22:44 -08:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-27 23:24:40 -07:00
|
|
|
static void LayoutAndInvalidate(nsBoxLayoutState& aState,
|
2010-07-15 14:08:03 -07:00
|
|
|
nsIFrame* aBox, const nsRect& aRect,
|
|
|
|
PRBool aScrollbarIsBeingHidden)
|
2007-03-27 23:24:40 -07:00
|
|
|
{
|
|
|
|
// When a child box changes shape of position, the parent
|
|
|
|
// is responsible for invalidation; the overflow rect must be invalidated
|
2010-01-13 18:30:06 -08:00
|
|
|
// to make sure to catch any overflow.
|
|
|
|
// We invalidate the parent (i.e. the scrollframe) directly, because
|
|
|
|
// invalidates coming from scrollbars are suppressed by nsHTMLScrollFrame when
|
|
|
|
// mHasVScrollbar/mHasHScrollbar is false, and this is called after those
|
|
|
|
// flags have been set ... if a scrollbar is being hidden, we still need
|
|
|
|
// to invalidate the scrollbar area here.
|
2010-07-15 14:08:03 -07:00
|
|
|
// But we also need to invalidate the scrollbar itself in case it has
|
|
|
|
// its own layer; we need to ensure that layer is updated.
|
2007-03-27 23:24:40 -07:00
|
|
|
PRBool rectChanged = aBox->GetRect() != aRect;
|
2010-01-13 18:30:06 -08:00
|
|
|
if (rectChanged) {
|
2010-07-15 14:08:03 -07:00
|
|
|
if (aScrollbarIsBeingHidden) {
|
|
|
|
aBox->GetParent()->Invalidate(aBox->GetOverflowRect() + aBox->GetPosition());
|
|
|
|
} else {
|
2010-08-30 17:49:12 -07:00
|
|
|
aBox->InvalidateFrameSubtree();
|
2010-07-15 14:08:03 -07:00
|
|
|
}
|
2010-01-13 18:30:06 -08:00
|
|
|
}
|
2007-03-27 23:24:40 -07:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, aBox, aRect);
|
2010-01-13 18:30:06 -08:00
|
|
|
if (rectChanged) {
|
2010-07-15 14:08:03 -07:00
|
|
|
if (aScrollbarIsBeingHidden) {
|
|
|
|
aBox->GetParent()->Invalidate(aBox->GetOverflowRect() + aBox->GetPosition());
|
|
|
|
} else {
|
2010-08-30 17:49:12 -07:00
|
|
|
aBox->InvalidateFrameSubtree();
|
2010-07-15 14:08:03 -07:00
|
|
|
}
|
2010-01-13 18:30:06 -08:00
|
|
|
}
|
2007-03-27 23:24:40 -07:00
|
|
|
}
|
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::AdjustScrollbarRectForResizer(
|
|
|
|
nsIFrame* aFrame, nsPresContext* aPresContext,
|
|
|
|
nsRect& aRect, PRBool aHasResizer, PRBool 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;
|
|
|
|
if (aHasResizer && mScrollCornerBox) {
|
|
|
|
resizerRect = mScrollCornerBox->GetRect();
|
|
|
|
}
|
|
|
|
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)
|
2009-09-16 08:01:36 -07:00
|
|
|
aRect.height = NS_MAX(0, resizerRect.y - aRect.y);
|
2008-08-08 09:11:54 -07:00
|
|
|
else
|
2009-09-16 08:01:36 -07:00
|
|
|
aRect.width = NS_MAX(0, resizerRect.x - aRect.x);
|
2008-08-08 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::LayoutScrollbars(nsBoxLayoutState& aState,
|
|
|
|
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
|
|
|
|
2010-03-19 04:49:34 -07:00
|
|
|
PRBool hasResizer = HasResizer();
|
|
|
|
PRBool scrollbarOnLeft = !IsScrollbarOnRight();
|
|
|
|
|
|
|
|
// place the scrollcorner
|
|
|
|
if (mScrollCornerBox) {
|
|
|
|
NS_PRECONDITION(mScrollCornerBox->IsBoxFrame(), "Must be a box frame!");
|
|
|
|
|
|
|
|
// if a resizer is present, get its size
|
|
|
|
nsSize resizerSize;
|
|
|
|
if (HasResizer()) {
|
|
|
|
// just assume a default size of 15 pixels
|
|
|
|
nscoord defaultSize = nsPresContext::CSSPixelsToAppUnits(15);
|
|
|
|
resizerSize.width =
|
|
|
|
mVScrollbarBox ? mVScrollbarBox->GetMinSize(aState).width : defaultSize;
|
|
|
|
resizerSize.height =
|
|
|
|
mHScrollbarBox ? mHScrollbarBox->GetMinSize(aState).height : defaultSize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resizerSize = nsSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r(0, 0, 0, 0);
|
|
|
|
if (aContentArea.x != mScrollPort.x || scrollbarOnLeft) {
|
|
|
|
// scrollbar (if any) on left
|
|
|
|
r.x = aContentArea.x;
|
|
|
|
r.width = PR_MAX(resizerSize.width, mScrollPort.x - aContentArea.x);
|
|
|
|
NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
|
|
|
|
} else {
|
|
|
|
// scrollbar (if any) on right
|
|
|
|
r.width = PR_MAX(resizerSize.width, aContentArea.XMost() - mScrollPort.XMost());
|
|
|
|
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
|
|
|
|
r.height = PR_MAX(resizerSize.height, aContentArea.YMost() - mScrollPort.YMost());
|
|
|
|
r.y = aContentArea.YMost() - r.height;
|
|
|
|
NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
|
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
LayoutAndInvalidate(aState, mScrollCornerBox, r, PR_FALSE);
|
2010-03-19 04:49:34 -07:00
|
|
|
}
|
|
|
|
|
2008-08-08 09:11:54 -07:00
|
|
|
nsPresContext* presContext = mScrolledFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mVScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect vRect(mScrollPort);
|
|
|
|
vRect.width = aContentArea.width - mScrollPort.width;
|
2010-03-19 04:49:34 -07:00
|
|
|
vRect.x = scrollbarOnLeft ? aContentArea.x : mScrollPort.XMost();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin margin;
|
|
|
|
mVScrollbarBox->GetMargin(margin);
|
2010-04-02 15:25:40 -07:00
|
|
|
vRect.Deflate(margin);
|
2010-03-19 04:49:34 -07:00
|
|
|
AdjustScrollbarRectForResizer(mOuter, presContext, vRect, hasResizer, PR_TRUE);
|
2010-07-15 14:08:03 -07:00
|
|
|
LayoutAndInvalidate(aState, mVScrollbarBox, vRect, !mHasVerticalScrollbar);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mHScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect hRect(mScrollPort);
|
|
|
|
hRect.height = aContentArea.height - mScrollPort.height;
|
|
|
|
hRect.y = PR_TRUE ? mScrollPort.YMost() : aContentArea.y;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin margin;
|
|
|
|
mHScrollbarBox->GetMargin(margin);
|
2010-04-02 15:25:40 -07:00
|
|
|
hRect.Deflate(margin);
|
2010-03-19 04:49:34 -07:00
|
|
|
AdjustScrollbarRectForResizer(mOuter, presContext, hRect, hasResizer, PR_FALSE);
|
2010-07-15 14:08:03 -07:00
|
|
|
LayoutAndInvalidate(aState, mHScrollbarBox, hRect, !mHasHorizontalScrollbar);
|
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)
|
2009-10-07 20:01:15 -07:00
|
|
|
if (aOldScrollArea.Size() != mScrollPort.Size() &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!(mOuter->GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
|
|
|
mIsRoot) {
|
2007-12-20 15:49:46 -08:00
|
|
|
mMayHaveDirtyFixedChildren = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// post reflow callback to modify scrollbar attributes
|
2009-06-23 18:35:00 -07:00
|
|
|
mUpdateScrollbarAttributes = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mPostedReflowCallback) {
|
|
|
|
aState.PresContext()->PresShell()->PostReflowCallback(this);
|
|
|
|
mPostedReflowCallback = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos)
|
|
|
|
{
|
|
|
|
if (aMaxPos) {
|
|
|
|
aContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE);
|
|
|
|
} else {
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
NS_LITERAL_STRING("true"), PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom,
|
|
|
|
nscoord aSize)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, aAtom, newValue, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2009-10-07 20:01:15 -07:00
|
|
|
nsGfxScrollFrameInner::GetScrolledRect() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
nsRect result =
|
|
|
|
GetScrolledRectInternal(mScrolledFrame->GetOverflowRect(),
|
|
|
|
mScrollPort.Size());
|
|
|
|
|
|
|
|
NS_ASSERTION(result.width >= mScrollPort.width,
|
|
|
|
"Scrolled rect smaller than scrollport?");
|
|
|
|
NS_ASSERTION(result.height >= mScrollPort.height,
|
|
|
|
"Scrolled rect smaller than scrollport?");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsGfxScrollFrameInner::GetScrolledRectInternal(const nsRect& aScrolledFrameOverflowArea,
|
|
|
|
const nsSize& aScrollPortSize) const
|
|
|
|
{
|
|
|
|
nscoord x1 = aScrolledFrameOverflowArea.x,
|
|
|
|
x2 = aScrolledFrameOverflowArea.XMost(),
|
|
|
|
y1 = aScrolledFrameOverflowArea.y,
|
|
|
|
y2 = aScrolledFrameOverflowArea.YMost();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (y1 < 0)
|
|
|
|
y1 = 0;
|
|
|
|
if (IsLTR() || mIsXUL) {
|
|
|
|
if (x1 < 0)
|
|
|
|
x1 = 0;
|
|
|
|
} else {
|
|
|
|
if (x2 > aScrollPortSize.width)
|
|
|
|
x2 = aScrollPortSize.width;
|
2008-07-13 14:50:35 -07:00
|
|
|
// When the scrolled frame chooses a size larger than its available width (because
|
|
|
|
// its padding alone is larger than the available width), we need to keep the
|
|
|
|
// start-edge of the scroll frame anchored to the start-edge of the scrollport.
|
|
|
|
// When the scrolled frame is RTL, this means moving it in our left-based
|
|
|
|
// coordinate system, so we need to compensate for its extra width here by
|
|
|
|
// effectively repositioning the frame.
|
2009-09-16 08:01:36 -07:00
|
|
|
nscoord extraWidth = NS_MAX(0, mScrolledFrame->GetSize().width - aScrollPortSize.width);
|
2008-07-13 14:50:35 -07:00
|
|
|
x2 += extraWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return nsRect(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin
|
2010-01-13 04:57:00 -08:00
|
|
|
nsGfxScrollFrameInner::GetActualScrollbarSizes() const
|
|
|
|
{
|
2010-04-02 15:25:40 -07:00
|
|
|
nsRect r = mOuter->GetPaddingRect() - mOuter->GetPosition();
|
|
|
|
|
|
|
|
return nsMargin(mScrollPort.x - r.x, mScrollPort.y - r.y,
|
|
|
|
r.XMost() - mScrollPort.XMost(),
|
|
|
|
r.YMost() - mScrollPort.YMost());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisible)
|
|
|
|
{
|
|
|
|
if (!aScrollbar)
|
|
|
|
return;
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollbarFrame* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsGfxScrollFrameInner::GetCoordAttribute(nsIBox* aBox, nsIAtom* atom, PRInt32 defaultValue)
|
|
|
|
{
|
|
|
|
if (aBox) {
|
|
|
|
nsIContent* content = aBox->GetContent();
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
content->GetAttr(kNameSpaceID_None, atom, value);
|
|
|
|
if (!value.IsEmpty())
|
|
|
|
{
|
|
|
|
PRInt32 error;
|
|
|
|
|
|
|
|
// convert it to an integer
|
|
|
|
defaultValue = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresState*
|
|
|
|
nsGfxScrollFrameInner::SaveState(nsIStatefulFrame::SpecialStateID aStateID)
|
|
|
|
{
|
|
|
|
// Don't save "normal" state for the root scrollframe; that's
|
|
|
|
// handled via the eDocumentScrollState state id
|
|
|
|
if (mIsRoot && aStateID == nsIStatefulFrame::eNoID) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
nsPoint scrollPos = GetScrollPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't save scroll position if we are at (0,0)
|
2009-10-07 20:01:15 -07:00
|
|
|
if (scrollPos == nsPoint(0,0)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-12-12 11:25:22 -08:00
|
|
|
nsPresState* state = new nsPresState();
|
|
|
|
if (!state) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2009-10-07 20:01:15 -07:00
|
|
|
|
|
|
|
state->SetScrollState(scrollPos);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-12 11:25:22 -08:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
|
|
|
|
{
|
2009-10-07 20:01:15 -07:00
|
|
|
mRestorePos = aState->GetScrollState();
|
2007-03-22 10:30:00 -07:00
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
mDidHistoryRestore = PR_TRUE;
|
2009-10-07 20:01:15 -07:00
|
|
|
mLastPos = mScrolledFrame ? GetScrollPosition() : nsPoint(0,0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-25 00:04:18 -07:00
|
|
|
|
|
|
|
void
|
2010-01-11 13:45:19 -08:00
|
|
|
nsGfxScrollFrameInner::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);
|
|
|
|
NS_DispatchToCurrentThread(mScrolledAreaEvent.get());
|
2009-10-25 00:04:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ScrolledArea change event dispatch
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-01-11 13:45:19 -08:00
|
|
|
nsGfxScrollFrameInner::ScrolledAreaEvent::Run()
|
2009-10-25 00:04:18 -07:00
|
|
|
{
|
2010-01-11 13:45:19 -08:00
|
|
|
if (mInner) {
|
|
|
|
mInner->FireScrolledAreaEvent();
|
|
|
|
}
|
2009-10-25 00:04:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-11 13:45:19 -08:00
|
|
|
nsGfxScrollFrameInner::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
|
|
|
|
|
|
|
nsScrollAreaEvent event(PR_TRUE, NS_SCROLLEDAREACHANGED, nsnull);
|
|
|
|
nsPresContext *prescontext = mOuter->PresContext();
|
|
|
|
nsIContent* content = mOuter->GetContent();
|
|
|
|
|
2010-01-11 13:45:19 -08:00
|
|
|
event.mArea = mScrolledFrame->GetOverflowRectRelativeToParent();
|
2009-10-25 00:04:18 -07:00
|
|
|
|
|
|
|
nsIDocument *doc = content->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsEventDispatcher::Dispatch(doc, prescontext, &event, nsnull);
|
|
|
|
}
|
|
|
|
}
|