2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-20 02:16:23 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
1999-08-20 02:16:23 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1999-08-20 02:16:23 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2004-04-18 18:30:37 +04:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-20 02:16:23 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2005-02-08 03:59:52 +03:00
|
|
|
#include "nsReflowType.h"
|
1999-08-20 02:16:23 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsPageFrame.h"
|
|
|
|
#include "nsViewsCID.h"
|
2000-01-25 09:35:27 +03:00
|
|
|
#include "nsIServiceManager.h"
|
1999-08-20 02:16:23 +04:00
|
|
|
#include "nsIView.h"
|
2004-05-05 06:32:27 +04:00
|
|
|
#include "nsIScrollableView.h"
|
2004-09-05 03:03:04 +04:00
|
|
|
#include "nsIScrollable.h"
|
1999-08-20 02:16:23 +04:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGfxScrollFrame.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsXULAtoms.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
1999-10-12 04:16:06 +04:00
|
|
|
#include "nsIDocumentObserver.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-05-10 17:13:39 +04:00
|
|
|
#include "nsINodeInfo.h"
|
2000-07-14 03:00:59 +04:00
|
|
|
#include "nsIScrollbarFrame.h"
|
|
|
|
#include "nsIScrollbarMediator.h"
|
2002-07-27 00:57:24 +04:00
|
|
|
#include "nsITextControlFrame.h"
|
2004-09-04 07:17:18 +04:00
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
2002-01-23 05:53:02 +03:00
|
|
|
#include "nsIURI.h"
|
2002-06-21 01:47:59 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-09-13 06:10:29 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2004-09-22 10:33:36 +04:00
|
|
|
#include "nsIPresShell.h"
|
2005-04-29 01:57:22 +04:00
|
|
|
#include "nsReflowPath.h"
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsPresState.h"
|
2004-09-01 18:58:34 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
1999-08-20 02:16:23 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
//----------nsHTMLScrollFrame-------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsHTMLScrollFrame* it = new (aPresShell) nsHTMLScrollFrame(aPresShell, aIsRoot);
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, PRBool aIsRoot)
|
2005-04-29 01:57:22 +04:00
|
|
|
: nsHTMLContainerFrame(),
|
2005-04-04 02:40:25 +04:00
|
|
|
mInner(this, aIsRoot)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the view that we are scrolling within the scrolling view.
|
|
|
|
* @result child view
|
|
|
|
*/
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIFrame* nsHTMLScrollFrame::GetScrolledFrame() const
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return mInner.GetScrolledFrame();
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIScrollableView* nsHTMLScrollFrame::GetScrollableView()
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return mInner.GetScrollableView();
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsPoint nsHTMLScrollFrame::GetScrollPosition() const
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
|
|
|
nsIScrollableView* s = mInner.GetScrollableView();
|
2004-09-06 06:44:43 +04:00
|
|
|
nsPoint scrollPosition;
|
|
|
|
s->GetScrollPosition(scrollPosition.x, scrollPosition.y);
|
|
|
|
return scrollPosition;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsHTMLScrollFrame::ScrollTo(nsPoint aScrollPosition, PRUint32 aFlags)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
|
|
|
nsIScrollableView* s = mInner.GetScrollableView();
|
2004-09-06 06:44:43 +04:00
|
|
|
s->ScrollTo(aScrollPosition.x, aScrollPosition.y, aFlags);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles
|
|
|
|
nsHTMLScrollFrame::GetScrollbarStyles() const {
|
|
|
|
return mInner.GetScrollbarStylesFromFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin nsHTMLScrollFrame::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) {
|
2005-04-29 01:57:22 +04:00
|
|
|
return mInner.GetDesiredScrollbarSizes(aState);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsHTMLScrollFrame::SetScrollbarVisibility(PRBool aVerticalVisible, PRBool aHorizontalVisible)
|
2004-09-04 07:49:25 +04:00
|
|
|
{
|
|
|
|
mInner.mNeverHasVerticalScrollbar = !aVerticalVisible;
|
|
|
|
mInner.mNeverHasHorizontalScrollbar = !aHorizontalVisible;
|
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIBox* nsHTMLScrollFrame::GetScrollbarBox(PRBool aVertical)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return aVertical ? mInner.mVScrollbarBox : mInner.mHScrollbarBox;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLScrollFrame::CreateAnonymousContent(nsPresContext* aPresContext,
|
2004-06-18 06:08:19 +04:00
|
|
|
nsISupportsArray& aAnonymousChildren)
|
|
|
|
{
|
|
|
|
mInner.CreateAnonymousContent(aAnonymousChildren);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLScrollFrame::Destroy(nsPresContext* aPresContext)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
|
|
|
nsIScrollableView *view = mInner.GetScrollableView();
|
|
|
|
NS_ASSERTION(view, "unexpected null pointer");
|
|
|
|
if (view)
|
|
|
|
view->RemoveScrollPositionListener(&mInner);
|
2005-04-29 01:57:22 +04:00
|
|
|
return nsHTMLContainerFrame::Destroy(aPresContext);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-04 01:00:41 +04:00
|
|
|
nsHTMLScrollFrame::
|
|
|
|
SetInitialChildList(nsPresContext* aPresContext,
|
2004-06-18 06:08:19 +04:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult rv = nsHTMLContainerFrame::SetInitialChildList(aPresContext, aListName,
|
2004-06-18 06:08:19 +04:00
|
|
|
aChildList);
|
2005-04-04 01:00:41 +04:00
|
|
|
mInner.CreateScrollableView();
|
2004-06-18 06:08:19 +04:00
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
|
|
|
|
// listen for scroll events.
|
|
|
|
mInner.GetScrollableView()->AddScrollPositionListener(&mInner);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLScrollFrame::AppendFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
2005-02-07 04:58:25 +03:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
mFrames.AppendFrames(nsnull, aFrameList);
|
2004-06-18 06:08:19 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLScrollFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
2005-02-07 04:58:25 +03:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
mFrames.InsertFrames(nsnull, aPrevFrame, aFrameList);
|
2004-06-18 06:08:19 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLScrollFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
2005-02-07 04:58:25 +03:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
mFrames.RemoveFrame(aOldFrame);
|
2004-06-18 06:08:19 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLScrollFrame::ReplaceFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
2005-02-07 04:58:25 +03:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
NS_ASSERTION(!aListName, "Only main list supported");
|
|
|
|
nsresult rv = nsHTMLContainerFrame::ReplaceFrame(aListName, aOldFrame, aNewFrame);
|
2004-06-18 06:08:19 +04:00
|
|
|
mInner.ReloadChildFrames();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsHTMLScrollFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLScrollFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsLayoutAtoms::scrollFrame;
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
/**
|
|
|
|
HTML scrolling implementation
|
2005-04-04 01:00:41 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
We rely on the fact that if height is 'auto', changing the height of
|
|
|
|
the element does not require reflowing the contents.
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
All other things being equal, we prefer layouts with fewer scrollbars showing.
|
|
|
|
*/
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
struct ScrollReflowState {
|
|
|
|
const nsHTMLReflowState& mReflowState;
|
|
|
|
nsBoxLayoutState mBoxState;
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles mStyles;
|
|
|
|
nsReflowReason mNewReason;
|
2005-05-03 02:49:44 +04:00
|
|
|
nsMargin mComputedBorder;
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
// === Filled in when TryLayout succeeds ===
|
|
|
|
// The area of the scrollport, in coordinates relative to the scrollframe
|
|
|
|
nsRect mScrollPortRect;
|
|
|
|
// The size of the inside-border area
|
|
|
|
nsSize mInsideBorderSize;
|
|
|
|
// Taken from kid metrics; ascent from the inner-border top edge
|
|
|
|
nscoord mAscent;
|
|
|
|
// Taken from kid metrics; does not include our border widths,
|
|
|
|
// does include vertical scrollbar if present
|
|
|
|
nscoord mMaxElementWidth;
|
|
|
|
// Taken from kid metrics; does not include our border widths,
|
|
|
|
// does include vertical scrollbar if present
|
|
|
|
nscoord mMaximumWidth;
|
|
|
|
// 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, nsHTMLReflowMetrics& aMetrics) :
|
|
|
|
mReflowState(aState),
|
|
|
|
mBoxState(aState.frame->GetPresContext(), aState, aMetrics),
|
|
|
|
mStyles(aFrame->GetScrollbarStyles()) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsSize ComputeInsideBorderSize(ScrollReflowState* aState,
|
2005-05-03 02:49:44 +04:00
|
|
|
const nsSize& aDesiredInsideBorderSize)
|
2005-04-29 01:57:22 +04:00
|
|
|
{
|
2005-05-03 02:49:44 +04:00
|
|
|
// 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.mComputedWidth;
|
|
|
|
if (contentWidth == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
contentWidth = aDesiredInsideBorderSize.width -
|
|
|
|
aState->mReflowState.mComputedPadding.LeftRight();
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2005-05-03 02:49:44 +04:00
|
|
|
nscoord contentHeight = aState->mReflowState.mComputedHeight;
|
|
|
|
if (contentHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
contentHeight = aDesiredInsideBorderSize.height -
|
|
|
|
aState->mReflowState.mComputedPadding.TopBottom();
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2005-05-03 02:49:44 +04:00
|
|
|
|
|
|
|
aState->mReflowState.ApplyMinMaxConstraints(&contentWidth, &contentHeight);
|
|
|
|
return nsSize(contentWidth + aState->mReflowState.mComputedPadding.LeftRight(),
|
|
|
|
contentHeight + aState->mReflowState.mComputedPadding.TopBottom());
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetScrollbarMetrics(nsBoxLayoutState& aState, nsIBox* aBox, nsSize* aMin, PRBool aVertical)
|
|
|
|
{
|
|
|
|
aBox->GetMinSize(aState, *aMin);
|
|
|
|
nsBox::AddMargin(aBox, *aMin);
|
|
|
|
|
|
|
|
// The scrollbar preferred size is rather useless. For example, for
|
|
|
|
// a horizontal scrollbar the preferred width will always be
|
|
|
|
// ignored, and the preferred height will invariably be the same as
|
|
|
|
// the minimum height (even if it isn't, it's easiest for us to just
|
|
|
|
// use the min-height so that's what we'll do).
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsSize pref;
|
|
|
|
aBox->GetPrefSize(aState, pref);
|
|
|
|
nsBox::AddMargin(aBox, pref);
|
|
|
|
if (aVertical) {
|
|
|
|
NS_ASSERTION(aMin->width == pref.width,
|
|
|
|
"We assume that the vertical scrollbar width is fixed");
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aMin->height == pref.height,
|
|
|
|
"We assume that the horizontal scrollbar height is fixed");
|
|
|
|
}
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04: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,
|
|
|
|
const nsHTMLReflowMetrics& aKidMetrics,
|
|
|
|
PRBool aAssumeVScroll, PRBool aAssumeHScroll,
|
|
|
|
PRBool aForce)
|
|
|
|
{
|
|
|
|
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;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
nsSize vScrollbarMinSize(0, 0);
|
|
|
|
if (mInner.mVScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mVScrollbarBox,
|
|
|
|
&vScrollbarMinSize, PR_TRUE);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
nscoord vScrollbarActualWidth = aAssumeVScroll ? vScrollbarMinSize.width : 0;
|
|
|
|
nscoord vScrollbarRequiredHeight = aAssumeVScroll ? vScrollbarMinSize.height : 0;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize hScrollbarMinSize(0, 0);
|
|
|
|
if (mInner.mHScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mHScrollbarBox,
|
|
|
|
&hScrollbarMinSize, PR_FALSE);
|
|
|
|
}
|
|
|
|
nscoord hScrollbarActualHeight = aAssumeHScroll ? hScrollbarMinSize.height : 0;
|
|
|
|
nscoord hScrollbarRequiredWidth = aAssumeHScroll ? hScrollbarMinSize.width : 0;
|
|
|
|
|
|
|
|
// First, compute our inside-border size and scrollport size
|
|
|
|
nsSize desiredInsideBorderSize;
|
|
|
|
desiredInsideBorderSize.width = vScrollbarActualWidth +
|
|
|
|
PR_MAX(aKidMetrics.width, hScrollbarRequiredWidth);
|
|
|
|
desiredInsideBorderSize.height = hScrollbarActualHeight +
|
|
|
|
PR_MAX(aKidMetrics.height, vScrollbarRequiredHeight);
|
|
|
|
aState->mInsideBorderSize =
|
2005-05-03 02:49:44 +04:00
|
|
|
ComputeInsideBorderSize(aState, desiredInsideBorderSize);
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize scrollPortSize = nsSize(aState->mInsideBorderSize.width - vScrollbarActualWidth,
|
|
|
|
aState->mInsideBorderSize.height - hScrollbarActualHeight);
|
|
|
|
|
|
|
|
if (!aForce) {
|
|
|
|
// 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_AUTO
|
|
|
|
? aKidMetrics.mOverflowArea.XMost() > scrollPortSize.width : PR_TRUE;
|
|
|
|
if (aState->mInsideBorderSize.height < hScrollbarMinSize.height ||
|
|
|
|
scrollPortSize.width < hScrollbarMinSize.width)
|
|
|
|
wantHScrollbar = PR_FALSE;
|
|
|
|
if (wantHScrollbar != aAssumeHScroll)
|
|
|
|
return PR_FALSE;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// 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_AUTO
|
|
|
|
? aKidMetrics.mOverflowArea.YMost() > scrollPortSize.height : PR_TRUE;
|
|
|
|
if (aState->mInsideBorderSize.width < vScrollbarMinSize.width ||
|
|
|
|
scrollPortSize.height < vScrollbarMinSize.height)
|
|
|
|
wantVScrollbar = PR_FALSE;
|
|
|
|
if (wantVScrollbar != aAssumeVScroll)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
aState->mShowHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mShowVScrollbar = aAssumeVScroll;
|
2005-05-03 02:49:44 +04:00
|
|
|
nsPoint scrollPortOrigin(aState->mComputedBorder.left,
|
|
|
|
aState->mComputedBorder.top);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mInner.IsScrollbarOnRight()) {
|
|
|
|
scrollPortOrigin.x += vScrollbarActualWidth;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
aState->mScrollPortRect = nsRect(scrollPortOrigin, scrollPortSize);
|
|
|
|
aState->mAscent = aKidMetrics.ascent;
|
|
|
|
if (aKidMetrics.mComputeMEW) {
|
2005-05-02 08:48:59 +04:00
|
|
|
aState->mMaxElementWidth = aKidMetrics.mMaxElementWidth + vScrollbarActualWidth;
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
if (aKidMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
2005-05-02 08:48:59 +04:00
|
|
|
aState->mMaximumWidth = aKidMetrics.mMaximumWidth;
|
|
|
|
if (aState->mMaximumWidth != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aState->mMaximumWidth += vScrollbarActualWidth;
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::ReflowScrolledFrame(const ScrollReflowState& aState,
|
|
|
|
PRBool aAssumeVScroll,
|
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
|
|
|
PRBool aFirstPass)
|
|
|
|
{
|
|
|
|
// these could be NS_UNCONSTRAINEDSIZE ... PR_MIN arithmetic should
|
|
|
|
// be OK
|
2005-05-03 02:49:44 +04:00
|
|
|
nscoord paddingLR = aState.mReflowState.mComputedPadding.LeftRight();
|
|
|
|
|
|
|
|
nscoord availWidth = aState.mReflowState.availableWidth;
|
|
|
|
if (aState.mReflowState.mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
availWidth = aState.mReflowState.mComputedWidth + paddingLR;
|
|
|
|
} else {
|
|
|
|
if (aState.mReflowState.mComputedMaxWidth != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
availWidth = PR_MIN(availWidth,
|
|
|
|
aState.mReflowState.mComputedMaxWidth + paddingLR);
|
|
|
|
}
|
|
|
|
if (aState.mReflowState.mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
availWidth = PR_MIN(availWidth,
|
|
|
|
aState.mReflowState.mComputedWidth + paddingLR);
|
|
|
|
}
|
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
if (availWidth != NS_UNCONSTRAINEDSIZE && aAssumeVScroll) {
|
|
|
|
nsSize vScrollbarMinSize;
|
|
|
|
mInner.mVScrollbarBox->GetMinSize(NS_CONST_CAST(nsBoxLayoutState&, aState.mBoxState),
|
|
|
|
vScrollbarMinSize);
|
|
|
|
availWidth = PR_MAX(0, availWidth - vScrollbarMinSize.width);
|
|
|
|
}
|
2005-05-03 02:49:44 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLReflowState kidReflowState(GetPresContext(), aState.mReflowState,
|
|
|
|
mInner.mScrolledFrame,
|
|
|
|
nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
|
|
|
|
aFirstPass ? aState.mNewReason : eReflowReason_Resize);
|
2005-05-03 02:49:44 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (IsRTLTextControl()) {
|
|
|
|
kidReflowState.mRightEdge = mInner.GetScrolledSize().width;
|
|
|
|
}
|
|
|
|
nsReflowStatus status;
|
|
|
|
nsresult rv = ReflowChild(mInner.mScrolledFrame, GetPresContext(), *aMetrics,
|
|
|
|
kidReflowState, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW, status);
|
|
|
|
FinishReflowChild(mInner.mScrolledFrame, GetPresContext(),
|
|
|
|
&kidReflowState, *aMetrics, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_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.
|
|
|
|
if (!(mInner.mScrolledFrame->GetStateBits() & NS_FRAME_OUTSIDE_CHILDREN)) {
|
|
|
|
aMetrics->mOverflowArea.SetRect(0, 0, aMetrics->width, aMetrics->height);
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
|
|
|
const nsHTMLReflowMetrics& aDesiredSize)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
// Try layouts that keep the vertical scrollbar setting the same,
|
|
|
|
// first. That will minimize the work we have to do.
|
|
|
|
PRBool currentlyUsingVScrollbar = mInner.mHasVerticalScrollbar;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (aState->mReflowState.reason == eReflowReason_Initial) {
|
|
|
|
// Set initial vertical scrollbar assumption.
|
|
|
|
if (aState->mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
currentlyUsingVScrollbar = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// If we're the viewport scrollframe, then let's start out assuming that
|
|
|
|
// there *is* a vertical scrollbar.
|
|
|
|
// XXX disable this for now so we can see what the Tp impact of the
|
|
|
|
// big changes is.
|
|
|
|
// if (mInner.mIsRoot) {
|
|
|
|
// currentlyUsingVScrollbar = PR_TRUE;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// Don't assume a vertical scrollbar if we're not allowed to have
|
|
|
|
// one
|
|
|
|
PRBool canHaveVerticalScrollbar =
|
|
|
|
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
if (!canHaveVerticalScrollbar)
|
|
|
|
currentlyUsingVScrollbar = PR_FALSE;
|
|
|
|
|
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
|
|
|
nsresult rv = ReflowScrolledFrame(*aState, currentlyUsingVScrollbar,
|
2005-05-03 02:49:44 +04:00
|
|
|
&kidDesiredSize, PR_TRUE);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
PRBool didUseScrollbar = currentlyUsingVScrollbar;
|
|
|
|
|
|
|
|
// 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".
|
|
|
|
if (currentlyUsingVScrollbar &&
|
|
|
|
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_SCROLL &&
|
|
|
|
aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL) {
|
|
|
|
nsSize insideBorderSize =
|
2005-05-03 02:49:44 +04:00
|
|
|
ComputeInsideBorderSize(aState,
|
|
|
|
nsSize(kidDesiredSize.width, kidDesiredSize.height));
|
2005-04-29 01:57:22 +04:00
|
|
|
if (kidDesiredSize.mOverflowArea.XMost() <= insideBorderSize.width &&
|
|
|
|
kidDesiredSize.mOverflowArea.YMost() <= insideBorderSize.height) {
|
|
|
|
// Let's pretend we had no vertical scrollbar coming in here
|
|
|
|
currentlyUsingVScrollbar = PR_FALSE;
|
|
|
|
rv = ReflowScrolledFrame(*aState, currentlyUsingVScrollbar,
|
2005-05-03 02:49:44 +04:00
|
|
|
&kidDesiredSize, PR_FALSE);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
didUseScrollbar = PR_FALSE;
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
// First try a layout without a horizontal scrollbar, then with.
|
2005-05-03 02:49:44 +04:00
|
|
|
if (TryLayout(aState, kidDesiredSize, didUseScrollbar, PR_FALSE, PR_FALSE))
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
2005-05-03 02:49:44 +04:00
|
|
|
if (TryLayout(aState, kidDesiredSize, didUseScrollbar, PR_TRUE, PR_FALSE))
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// That didn't work. Try the other setting for the vertical scrollbar.
|
|
|
|
// But don't try to show a scrollbar if we know there can't be one.
|
|
|
|
if (currentlyUsingVScrollbar || canHaveVerticalScrollbar) {
|
|
|
|
nsHTMLReflowMetrics kidRetrySize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
|
|
|
rv = ReflowScrolledFrame(*aState, !currentlyUsingVScrollbar,
|
2005-05-03 02:49:44 +04:00
|
|
|
&kidRetrySize, PR_FALSE);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
didUseScrollbar = !currentlyUsingVScrollbar;
|
2005-05-03 02:49:44 +04:00
|
|
|
if (TryLayout(aState, kidRetrySize, didUseScrollbar, PR_FALSE, PR_FALSE))
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
2005-05-03 02:49:44 +04:00
|
|
|
if (TryLayout(aState, kidRetrySize, didUseScrollbar, PR_TRUE, PR_FALSE))
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_WARNING("Strange content ... we can't find logically consistent scrollbar settings");
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Strange content ... we can't find logically consistent scrollbar settings");
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// Fall back to no scrollbars --- even if NS_STYLE_OVERFLOW_SCROLL is
|
|
|
|
// in effect. They might not fit anyway.
|
|
|
|
if (didUseScrollbar) {
|
2005-05-03 02:49:44 +04:00
|
|
|
rv = ReflowScrolledFrame(*aState, PR_FALSE, &kidDesiredSize, PR_FALSE);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
2005-05-03 02:49:44 +04:00
|
|
|
TryLayout(aState, kidDesiredSize, PR_FALSE, PR_FALSE, PR_TRUE);
|
2005-04-04 01:00:41 +04:00
|
|
|
return NS_OK;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::PlaceScrollArea(const ScrollReflowState& aState)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
nsIView* scrollView = mInner.mScrollableView->View();
|
|
|
|
nsIViewManager* vm = scrollView->GetViewManager();
|
|
|
|
vm->MoveViewTo(scrollView, aState.mScrollPortRect.x, aState.mScrollPortRect.y);
|
|
|
|
vm->ResizeView(scrollView, nsRect(nsPoint(0, 0), aState.mScrollPortRect.Size()),
|
|
|
|
PR_TRUE);
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// set the origin of childRect to (0,0) even though we might have borders or
|
|
|
|
// a left-hand-side scrollbar. We've accounted for that by positioning the
|
|
|
|
// anonymous mScrollableView.
|
|
|
|
nsRect childOverflow = mInner.mScrolledFrame->GetOverflowRect();
|
|
|
|
nsRect childRect = nsRect(0, 0,
|
|
|
|
PR_MAX(childOverflow.XMost(), aState.mScrollPortRect.width),
|
|
|
|
PR_MAX(childOverflow.YMost(), aState.mScrollPortRect.height));
|
|
|
|
mInner.mScrolledFrame->SetRect(childRect);
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(mInner.mScrolledFrame->GetPresContext(),
|
|
|
|
mInner.mScrolledFrame,
|
|
|
|
mInner.mScrolledFrame->GetView(),
|
|
|
|
&childRect,
|
|
|
|
NS_FRAME_NO_MOVE_VIEW);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::IsRTLTextControl()
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
const nsStyleVisibility* ourVis = GetStyleVisibility();
|
|
|
|
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == ourVis->mDirection) {
|
|
|
|
nsCOMPtr<nsITextControlFrame> textControl = do_QueryInterface(GetParent());
|
|
|
|
if (textControl) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
return PR_FALSE;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-29 01:57:22 +04:00
|
|
|
nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLScrollFrame", aReflowState.reason);
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
ScrollReflowState state(this, aReflowState, aDesiredSize);
|
|
|
|
// 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;
|
|
|
|
PRBool reflowHScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowVScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowScrollCorner = PR_TRUE;
|
|
|
|
nsReflowReason reason = aReflowState.reason;
|
|
|
|
|
|
|
|
if (reason == eReflowReason_Incremental) {
|
|
|
|
nsHTMLReflowCommand *command = aReflowState.path->mReflowCommand;
|
|
|
|
// See if it's targeted at us
|
|
|
|
if (command) {
|
|
|
|
nsReflowType reflowType;
|
|
|
|
command->GetType(reflowType);
|
|
|
|
|
|
|
|
switch (reflowType) {
|
|
|
|
case eReflowType_StyleChanged:
|
|
|
|
reason = eReflowReason_StyleChange;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eReflowType_ReflowDirty:
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unexpected Reflow Type");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reflowContents = PR_FALSE;
|
|
|
|
reflowHScrollbar = PR_FALSE;
|
|
|
|
reflowVScrollbar = PR_FALSE;
|
|
|
|
reflowScrollCorner = PR_FALSE;
|
|
|
|
|
|
|
|
nsReflowPath::iterator iter = aReflowState.path->FirstChild();
|
|
|
|
nsReflowPath::iterator end = aReflowState.path->EndChildren();
|
|
|
|
|
|
|
|
for ( ; iter != end; ++iter) {
|
|
|
|
if (*iter == mInner.mScrolledFrame)
|
|
|
|
reflowContents = PR_TRUE;
|
|
|
|
else if (*iter == mInner.mHScrollbarBox)
|
|
|
|
reflowHScrollbar = PR_TRUE;
|
|
|
|
else if (*iter == mInner.mVScrollbarBox)
|
|
|
|
reflowVScrollbar = PR_TRUE;
|
|
|
|
else if (*iter == mInner.mScrollCornerBox)
|
|
|
|
reflowScrollCorner = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
state.mNewReason = reason;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsRect oldScrollAreaBounds = mInner.mScrollableView->View()->GetBounds();
|
|
|
|
nsRect oldScrolledAreaBounds = mInner.mScrolledFrame->GetView()->GetBounds();
|
2005-05-03 02:49:44 +04:00
|
|
|
state.mComputedBorder = aReflowState.mComputedBorderPadding -
|
|
|
|
aReflowState.mComputedPadding;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult rv = ReflowContents(&state, aDesiredSize);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (IsRTLTextControl()) {
|
|
|
|
nscoord newScrolledWidth =
|
|
|
|
PR_MAX(mInner.mScrolledFrame->GetOverflowRect().XMost(),
|
|
|
|
state.mScrollPortRect.width);
|
|
|
|
if (newScrolledWidth != oldScrolledAreaBounds.width) {
|
|
|
|
// RTL text controls keep their lines flush right, so we need to reflow
|
|
|
|
// again with the correct right edge
|
|
|
|
// XXX I'm not sure why this can't be done in a more general way
|
|
|
|
// XXX the way this works, we can never get narrower even when content
|
|
|
|
// is deleted, because the XMost of the frame's overflow area is always
|
|
|
|
// at least the right edge. But it looks like it has always worked this way.
|
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
|
|
|
rv = ReflowScrolledFrame(state, state.mShowVScrollbar,
|
2005-05-03 02:49:44 +04:00
|
|
|
&kidDesiredSize, PR_FALSE);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-10-29 21:36:58 +04:00
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PlaceScrollArea(state);
|
|
|
|
|
|
|
|
PRBool didHaveHScrollbar = mInner.mHasHorizontalScrollbar;
|
|
|
|
PRBool didHaveVScrollbar = mInner.mHasVerticalScrollbar;
|
|
|
|
mInner.mHasHorizontalScrollbar = state.mShowHScrollbar;
|
|
|
|
mInner.mHasVerticalScrollbar = state.mShowVScrollbar;
|
|
|
|
nsRect newScrollAreaBounds = mInner.mScrollableView->View()->GetBounds();
|
|
|
|
nsRect newScrolledAreaBounds = mInner.mScrolledFrame->GetView()->GetBounds();
|
|
|
|
if (reflowHScrollbar || reflowVScrollbar || reflowScrollCorner ||
|
|
|
|
reason != eReflowReason_Incremental ||
|
|
|
|
didHaveHScrollbar != state.mShowHScrollbar ||
|
|
|
|
didHaveVScrollbar != state.mShowVScrollbar ||
|
|
|
|
oldScrollAreaBounds != newScrollAreaBounds ||
|
|
|
|
oldScrolledAreaBounds != newScrolledAreaBounds) {
|
|
|
|
if (mInner.mHasHorizontalScrollbar && !didHaveHScrollbar) {
|
|
|
|
mInner.AdjustHorizontalScrollbar();
|
|
|
|
}
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, state.mShowHScrollbar);
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, state.mShowVScrollbar);
|
|
|
|
// place and reflow scrollbars
|
|
|
|
nsRect insideBorderArea =
|
2005-05-03 02:49:44 +04:00
|
|
|
nsRect(nsPoint(state.mComputedBorder.left, state.mComputedBorder.top),
|
|
|
|
state.mInsideBorderSize);
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.LayoutScrollbars(state.mBoxState, insideBorderArea,
|
|
|
|
oldScrollAreaBounds, state.mScrollPortRect);
|
|
|
|
}
|
|
|
|
ScrollToRestoredPosition();
|
|
|
|
|
|
|
|
aDesiredSize.width = state.mInsideBorderSize.width +
|
2005-05-03 02:49:44 +04:00
|
|
|
state.mComputedBorder.LeftRight();
|
2005-04-29 01:57:22 +04:00
|
|
|
aDesiredSize.height = state.mInsideBorderSize.height +
|
2005-05-03 02:49:44 +04:00
|
|
|
state.mComputedBorder.TopBottom();
|
|
|
|
aDesiredSize.ascent = state.mAscent + state.mComputedBorder.top;
|
2005-04-29 01:57:22 +04:00
|
|
|
if (aDesiredSize.mComputeMEW) {
|
|
|
|
aDesiredSize.mMaxElementWidth = state.mMaxElementWidth +
|
2005-05-03 02:49:44 +04:00
|
|
|
state.mComputedBorder.LeftRight();
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
aDesiredSize.mMaximumWidth = state.mMaximumWidth;
|
|
|
|
if (aDesiredSize.mMaximumWidth != NS_UNCONSTRAINEDSIZE) {
|
2005-05-03 02:49:44 +04:00
|
|
|
aDesiredSize.mMaximumWidth += state.mComputedBorder.LeftRight();
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aDesiredSize.descent = aDesiredSize.height - aDesiredSize.ascent;
|
|
|
|
aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2004-06-18 06:08:19 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsHTMLScrollFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsHTMLScrollFrame::Release(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLScroll"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-01 18:58:34 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
NS_IMETHODIMP nsHTMLScrollFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
if (!IsFocusable()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Focusable via CSS, so needs to be in accessibility hierarchy
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
|
|
|
return accService->CreateHTMLGenericAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::CurPosAttributeChanged(nsIContent* aChild,
|
2004-06-18 06:08:19 +04:00
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
mInner.CurPosAttributeChanged(aChild, aModType);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::GetContentOf(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
*aContent = GetContent();
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsHTMLScrollFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameDebug)
|
|
|
|
#endif
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollableFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollableViewProvider)
|
2004-09-13 06:10:29 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStatefulFrame)
|
2005-04-29 01:57:22 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsHTMLContainerFrame)
|
2004-06-18 06:08:19 +04:00
|
|
|
|
|
|
|
//----------nsXULScrollFrame-------------------------------------------
|
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
nsresult
|
2004-06-18 06:08:19 +04:00
|
|
|
NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame* it = new (aPresShell) nsXULScrollFrame(aPresShell, aIsRoot);
|
1999-08-20 02:16:23 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, PRBool aIsRoot)
|
2004-05-05 06:32:27 +04:00
|
|
|
: nsBoxFrame(aShell, aIsRoot),
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner(this, aIsRoot),
|
|
|
|
mMaxElementWidth(0),
|
|
|
|
mHorizontalOverflow(PR_FALSE),
|
|
|
|
mVerticalOverflow(PR_FALSE)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
SetLayoutManager(nsnull);
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
1999-12-07 06:36:05 +03:00
|
|
|
/**
|
|
|
|
* Get the view that we are scrolling within the scrolling view.
|
|
|
|
* @result child view
|
|
|
|
*/
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIFrame* nsXULScrollFrame::GetScrolledFrame() const
|
1999-12-07 06:36:05 +03:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return mInner.GetScrolledFrame();
|
1999-12-07 06:36:05 +03:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIScrollableView* nsXULScrollFrame::GetScrollableView()
|
2000-07-27 10:57:32 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return mInner.GetScrollableView();
|
2000-07-27 10:57:32 +04:00
|
|
|
}
|
2000-05-14 03:00:53 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsPoint nsXULScrollFrame::GetScrollPosition() const
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIScrollableView* s = mInner.GetScrollableView();
|
|
|
|
nsPoint scrollPosition;
|
|
|
|
s->GetScrollPosition(scrollPosition.x, scrollPosition.y);
|
|
|
|
return scrollPosition;
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsXULScrollFrame::ScrollTo(nsPoint aScrollPosition, PRUint32 aFlags)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIScrollableView* s = mInner.GetScrollableView();
|
|
|
|
s->ScrollTo(aScrollPosition.x, aScrollPosition.y, aFlags);
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetScrollbarStyles() const {
|
2004-05-05 06:32:27 +04:00
|
|
|
return mInner.GetScrollbarStylesFromFrame();
|
|
|
|
}
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
nsMargin nsXULScrollFrame::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) {
|
2005-04-29 01:57:22 +04:00
|
|
|
return mInner.GetDesiredScrollbarSizes(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMargin nsGfxScrollFrameInner::GetDesiredScrollbarSizes(nsBoxLayoutState* aState) {
|
2004-01-09 22:21:20 +03:00
|
|
|
nsMargin result(0, 0, 0, 0);
|
2003-04-22 05:33:14 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mHScrollbarBox) {
|
2004-01-09 22:21:20 +03:00
|
|
|
nsSize size;
|
2005-04-29 01:57:22 +04:00
|
|
|
mHScrollbarBox->GetMinSize(*aState, size);
|
|
|
|
nsBox::AddMargin(mHScrollbarBox, size);
|
2004-01-09 22:21:20 +03:00
|
|
|
#ifdef IBMBIDI
|
2005-04-29 01:57:22 +04:00
|
|
|
if (IsScrollbarOnRight())
|
2004-01-09 22:21:20 +03:00
|
|
|
result.left = size.width;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
result.right = size.width;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mVScrollbarBox) {
|
2004-01-09 22:21:20 +03:00
|
|
|
nsSize size;
|
2005-04-29 01:57:22 +04:00
|
|
|
mVScrollbarBox->GetMinSize(*aState, size);
|
|
|
|
nsBox::AddMargin(mVScrollbarBox, size);
|
2004-01-09 22:21:20 +03:00
|
|
|
// We don't currently support any scripts that would require a scrollbar
|
|
|
|
// at the top. (Are there any?)
|
|
|
|
result.bottom = size.height;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2004-01-09 22:21:20 +03:00
|
|
|
return result;
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsXULScrollFrame::SetScrollbarVisibility(PRBool aVerticalVisible, PRBool aHorizontalVisible)
|
2004-09-04 07:49:25 +04:00
|
|
|
{
|
|
|
|
mInner.mNeverHasVerticalScrollbar = !aVerticalVisible;
|
|
|
|
mInner.mNeverHasHorizontalScrollbar = !aHorizontalVisible;
|
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsIBox* nsXULScrollFrame::GetScrollbarBox(PRBool aVertical)
|
2000-06-07 03:14:11 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
return aVertical ? mInner.mVScrollbarBox : mInner.mHScrollbarBox;
|
2000-06-07 03:14:11 +04:00
|
|
|
}
|
2000-05-14 03:00:53 +04:00
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsXULScrollFrame::CreateAnonymousContent(nsPresContext* aPresContext,
|
2000-01-22 04:16:50 +03:00
|
|
|
nsISupportsArray& aAnonymousChildren)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.CreateAnonymousContent(aAnonymousChildren);
|
1999-08-20 02:16:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsXULScrollFrame::Destroy(nsPresContext* aPresContext)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2004-05-05 06:32:27 +04:00
|
|
|
nsIScrollableView *view = mInner.GetScrollableView();
|
2002-07-09 08:30:28 +04:00
|
|
|
NS_ASSERTION(view, "unexpected null pointer");
|
|
|
|
if (view)
|
2004-05-05 06:32:27 +04:00
|
|
|
view->RemoveScrollPositionListener(&mInner);
|
2000-03-31 11:02:06 +04:00
|
|
|
return nsBoxFrame::Destroy(aPresContext);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsXULScrollFrame::SetInitialChildList(nsPresContext* aPresContext,
|
1999-08-20 02:16:23 +04:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
nsresult rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName,
|
1999-08-20 02:16:23 +04:00
|
|
|
aChildList);
|
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
mInner.CreateScrollableView();
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.ReloadChildFrames();
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
// listen for scroll events.
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.GetScrollableView()->AddScrollPositionListener(&mInner);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
return rv;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:58:25 +03:00
|
|
|
nsXULScrollFrame::AppendFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::AppendFrames(aListName, aFrameList);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2003-04-09 00:50:57 +04:00
|
|
|
return rv;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:58:25 +03:00
|
|
|
nsXULScrollFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::InsertFrames(aListName, aPrevFrame, aFrameList);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2003-04-09 00:50:57 +04:00
|
|
|
return rv;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:58:25 +03:00
|
|
|
nsXULScrollFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::RemoveFrame(aListName, aOldFrame);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2003-04-09 00:50:57 +04:00
|
|
|
return rv;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:58:25 +03:00
|
|
|
nsXULScrollFrame::ReplaceFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::ReplaceFrame(aListName, aOldFrame, aNewFrame);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.ReloadChildFrames();
|
2003-04-09 00:50:57 +04:00
|
|
|
return rv;
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetPadding(nsMargin& aMargin)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
PRIntn
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetSkipSides() const
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetType() const
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
return nsLayoutAtoms::scrollFrame;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetAscent(nsBoxLayoutState& aState, nscoord& aAscent)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
|
|
|
aAscent = 0;
|
2005-04-04 01:00:41 +04:00
|
|
|
if (!mInner.mScrolledFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = mInner.mScrolledFrame->GetAscent(aState, aAscent);
|
2000-05-15 08:12:31 +04:00
|
|
|
nsMargin m(0,0,0,0);
|
|
|
|
GetBorderAndPadding(m);
|
|
|
|
aAscent += m.top;
|
|
|
|
GetMargin(m);
|
|
|
|
aAscent += m.top;
|
|
|
|
GetInset(m);
|
|
|
|
aAscent += m.top;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-31 11:02:06 +04:00
|
|
|
PropagateDebug(aState);
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles styles = GetScrollbarStyles();
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2002-10-01 05:23:47 +04:00
|
|
|
nsSize vSize(0,0);
|
2004-05-05 06:32:27 +04:00
|
|
|
if (mInner.mVScrollbarBox &&
|
2003-05-22 05:46:13 +04:00
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mVScrollbarBox->GetMinSize(aState, vSize);
|
2004-05-05 06:32:27 +04:00
|
|
|
nsBox::AddMargin(mInner.mVScrollbarBox, vSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2002-10-01 05:23:47 +04:00
|
|
|
nsSize hSize(0,0);
|
2004-05-05 06:32:27 +04:00
|
|
|
if (mInner.mHScrollbarBox &&
|
2003-05-22 05:46:13 +04:00
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHScrollbarBox->GetMinSize(aState, hSize);
|
2004-05-05 06:32:27 +04:00
|
|
|
nsBox::AddMargin(mInner.mHScrollbarBox, hSize);
|
2002-10-01 05:23:47 +04:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
nsresult rv = mInner.mScrolledFrame->GetPrefSize(aState, aSize);
|
2004-03-13 05:51:16 +03:00
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
// scrolled frames don't have their own margins
|
2002-10-01 05:23:47 +04:00
|
|
|
|
|
|
|
aSize.width += vSize.width;
|
|
|
|
aSize.height += hSize.height;
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
AddBorderAndPadding(aSize);
|
|
|
|
AddInset(aSize);
|
|
|
|
nsIBox::AddCSSPrefSize(aState, this, aSize);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState, nsSize& aSize)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-31 11:02:06 +04:00
|
|
|
PropagateDebug(aState);
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
aSize = mInner.mScrolledFrame->GetMinSizeForScrollArea(aState);
|
2003-05-22 05:46:13 +04:00
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles styles = GetScrollbarStyles();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
if (mInner.mVScrollbarBox &&
|
2003-05-22 05:46:13 +04:00
|
|
|
styles.mVertical == NS_STYLE_OVERFLOW_SCROLL) {
|
2000-03-31 11:02:06 +04:00
|
|
|
nsSize vSize(0,0);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.mVScrollbarBox->GetMinSize(aState, vSize);
|
|
|
|
AddMargin(mInner.mVScrollbarBox, vSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
aSize.width += vSize.width;
|
|
|
|
if (aSize.height < vSize.height)
|
|
|
|
aSize.height = vSize.height;
|
|
|
|
}
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
if (mInner.mHScrollbarBox &&
|
2003-05-22 05:46:13 +04:00
|
|
|
styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL) {
|
2000-03-31 11:02:06 +04:00
|
|
|
nsSize hSize(0,0);
|
2004-05-05 06:32:27 +04:00
|
|
|
mInner.mHScrollbarBox->GetMinSize(aState, hSize);
|
|
|
|
AddMargin(mInner.mHScrollbarBox, hSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
aSize.height += hSize.height;
|
|
|
|
if (aSize.width < hSize.width)
|
|
|
|
aSize.width = hSize.width;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
AddBorderAndPadding(aSize);
|
|
|
|
AddInset(aSize);
|
|
|
|
nsIBox::AddCSSMinSize(aState, this, aSize);
|
2005-04-04 01:00:41 +04:00
|
|
|
return NS_OK;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
1999-11-18 22:40:52 +03:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetMaxSize(nsBoxLayoutState& aState, nsSize& aSize)
|
1999-11-18 22:40:52 +03:00
|
|
|
{
|
2004-06-19 13:07:47 +04:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-31 11:02:06 +04:00
|
|
|
PropagateDebug(aState);
|
2004-06-19 13:07:47 +04:00
|
|
|
#endif
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
aSize.width = NS_INTRINSICSIZE;
|
|
|
|
aSize.height = NS_INTRINSICSIZE;
|
1999-11-18 22:40:52 +03:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
AddBorderAndPadding(aSize);
|
|
|
|
AddInset(aSize);
|
|
|
|
nsIBox::AddCSSMaxSize(aState, this, aSize);
|
|
|
|
return NS_OK;
|
1999-11-18 22:40:52 +03:00
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2000-04-05 04:19:00 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsXULScrollFrame::Reflow(nsPresContext* aPresContext,
|
2000-04-05 04:19:00 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2004-06-18 06:08:19 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsXULScrollFrame", aReflowState.reason);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2000-05-02 06:28:41 +04:00
|
|
|
|
|
|
|
// if there is a max element request then set it to -1 so we can see if it gets set
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aDesiredSize.mComputeMEW)
|
2000-05-02 06:28:41 +04:00
|
|
|
{
|
2003-01-09 17:26:32 +03:00
|
|
|
aDesiredSize.mMaxElementWidth = -1;
|
2000-05-02 06:28:41 +04:00
|
|
|
}
|
|
|
|
|
2000-04-05 04:19:00 +04:00
|
|
|
nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aDesiredSize.mComputeMEW)
|
2000-04-05 04:19:00 +04:00
|
|
|
{
|
2004-10-29 21:36:58 +04:00
|
|
|
nsStyleUnit widthUnit = GetStylePosition()->mWidth.GetUnit();
|
|
|
|
if (widthUnit == eStyleUnit_Percent || widthUnit == eStyleUnit_Auto) {
|
|
|
|
nsMargin border = aReflowState.mComputedBorderPadding;
|
|
|
|
aDesiredSize.mMaxElementWidth = border.right + border.left;
|
2005-04-29 01:57:22 +04:00
|
|
|
mMaxElementWidth = aDesiredSize.mMaxElementWidth;
|
2004-10-29 21:36:58 +04:00
|
|
|
} else {
|
|
|
|
// if not set then use the cached size. If set then set it.
|
|
|
|
if (aDesiredSize.mMaxElementWidth == -1)
|
2005-04-29 01:57:22 +04:00
|
|
|
aDesiredSize.mMaxElementWidth = mMaxElementWidth;
|
|
|
|
else
|
|
|
|
mMaxElementWidth = aDesiredSize.mMaxElementWidth;
|
2004-10-29 21:36:58 +04:00
|
|
|
}
|
2000-05-02 06:28:41 +04:00
|
|
|
}
|
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2000-04-05 04:19:00 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::AddRef(void)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
return NS_OK;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::Release(void)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
return NS_OK;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-10-12 04:16:06 +04:00
|
|
|
NS_IMETHODIMP
|
2004-06-18 06:08:19 +04:00
|
|
|
nsXULScrollFrame::GetFrameName(nsAString& aResult) const
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2004-06-18 06:08:19 +04:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("XULScroll"), aResult);
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsXULScrollFrame::CurPosAttributeChanged(nsIContent* aChild, PRInt32 aModType)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2004-09-06 06:44:43 +04:00
|
|
|
mInner.CurPosAttributeChanged(aChild, aModType);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULScrollFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
2004-06-22 06:55:04 +04:00
|
|
|
PRUint32 flags = aState.LayoutFlags();
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult rv = Layout(aState);
|
2004-06-22 06:55:04 +04:00
|
|
|
aState.SetLayoutFlags(flags);
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2004-06-22 06:55:04 +04:00
|
|
|
nsBox::DoLayout(aState);
|
|
|
|
return rv;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULScrollFrame::GetContentOf(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
*aContent = GetContent();
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULScrollFrame)
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameDebug)
|
|
|
|
#endif
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollableFrame)
|
2003-04-09 00:50:57 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollableViewProvider)
|
2004-09-13 06:10:29 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStatefulFrame)
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------- Inner ----------------------
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsGfxScrollFrameInner::nsGfxScrollFrameInner(nsContainerFrame* aOuter, PRBool aIsRoot)
|
2005-04-04 01:00:41 +04:00
|
|
|
: mScrollableView(nsnull),
|
|
|
|
mHScrollbarBox(nsnull),
|
2003-11-21 13:45:24 +03:00
|
|
|
mVScrollbarBox(nsnull),
|
2005-04-04 01:00:41 +04:00
|
|
|
mScrolledFrame(nsnull),
|
2003-11-21 13:45:24 +03:00
|
|
|
mScrollCornerBox(nsnull),
|
2004-01-06 02:56:00 +03:00
|
|
|
mOuter(aOuter),
|
2005-04-29 01:57:22 +04:00
|
|
|
mOnePixel(20),
|
2004-09-13 06:10:29 +04:00
|
|
|
mRestoreRect(-1, -1, -1, -1),
|
|
|
|
mLastPos(-1, -1),
|
2004-01-06 02:56:00 +03:00
|
|
|
mLastDir(-1),
|
2004-09-04 07:17:18 +04:00
|
|
|
mNeverHasVerticalScrollbar(PR_FALSE),
|
|
|
|
mNeverHasHorizontalScrollbar(PR_FALSE),
|
2003-11-21 13:45:24 +03:00
|
|
|
mHasVerticalScrollbar(PR_FALSE),
|
2004-01-06 02:56:00 +03:00
|
|
|
mHasHorizontalScrollbar(PR_FALSE),
|
2004-05-05 06:32:27 +04:00
|
|
|
mViewInitiatedScroll(PR_FALSE),
|
2004-09-13 06:10:29 +04:00
|
|
|
mFrameInitiatedScroll(PR_FALSE),
|
2005-04-04 01:00:41 +04:00
|
|
|
mDidHistoryRestore(PR_FALSE),
|
2005-04-04 02:40:25 +04:00
|
|
|
mIsRoot(aIsRoot)
|
2004-05-05 06:32:27 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrameInner::AddRef(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrameInner::Release(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-05-05 08:38:12 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsGfxScrollFrameInner, nsIScrollPositionListener)
|
2004-05-05 06:32:27 +04:00
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::NeedsClipWidget() const
|
|
|
|
{
|
|
|
|
// Scrollports contained in form controls (e.g., listboxes) don't get
|
|
|
|
// widgets.
|
2005-04-08 03:54:28 +04:00
|
|
|
for (nsIFrame* parentFrame = mOuter; parentFrame;
|
2005-04-04 01:00:41 +04:00
|
|
|
parentFrame = parentFrame->GetParent()) {
|
|
|
|
nsIFormControlFrame* fcFrame;
|
|
|
|
if ((NS_SUCCEEDED(parentFrame->QueryInterface(NS_GET_IID(nsIFormControlFrame), (void**)&fcFrame)))) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scrollports that don't ever show associated scrollbars don't get
|
|
|
|
// widgets, because they will seldom actually be scrolled.
|
|
|
|
nsIScrollableFrame *scrollableFrame;
|
|
|
|
CallQueryInterface(mOuter, &scrollableFrame);
|
|
|
|
ScrollbarStyles scrollbars = scrollableFrame->GetScrollbarStyles();
|
|
|
|
if ((scrollbars.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN
|
|
|
|
|| scrollbars.mHorizontal == NS_STYLE_OVERFLOW_VISIBLE)
|
|
|
|
&& (scrollbars.mVertical == NS_STYLE_OVERFLOW_HIDDEN
|
|
|
|
|| scrollbars.mVertical == NS_STYLE_OVERFLOW_VISIBLE)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::GetChildContentAndOffsetsFromPoint(nsPresContext* aCX,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsIContent ** aNewContent,
|
|
|
|
PRInt32& aContentOffset,
|
|
|
|
PRInt32& aContentOffsetEnd,
|
|
|
|
PRBool& aBeginFrameContent)
|
|
|
|
{
|
|
|
|
// We need to overrride this to ensure that scrollbars are ignored
|
|
|
|
|
|
|
|
// Since we definitely have a view, aPoint is relative to this frame's view. We
|
|
|
|
// need to make it relative to the scrolled frame.
|
|
|
|
nsPoint point = aPoint - mScrollableView->View()->GetOffsetTo(mOuter->GetView());
|
|
|
|
|
|
|
|
return mScrolledFrame->GetContentAndOffsetsFromPoint(aCX, point, aNewContent,
|
|
|
|
aContentOffset, aContentOffsetEnd,
|
|
|
|
aBeginFrameContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::CreateScrollableView()
|
|
|
|
{
|
|
|
|
nsIView* outerView = mOuter->GetView();
|
|
|
|
NS_ASSERTION(outerView, "scrollframes must have views");
|
|
|
|
nsIViewManager* viewManager = outerView->GetViewManager();
|
|
|
|
mScrollableView = viewManager->CreateScrollableView(mOuter->GetRect(), outerView);
|
|
|
|
if (!mScrollableView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIView* view = mScrollableView->View();
|
|
|
|
|
|
|
|
// Insert the view into the view hierarchy
|
|
|
|
viewManager->InsertChild(outerView, view, nsnull, PR_TRUE);
|
|
|
|
|
|
|
|
// Have the scrolling view create its internal widgets
|
|
|
|
if (NeedsClipWidget()) {
|
|
|
|
mScrollableView->CreateScrollControls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-05 03:03:04 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-08 03:54:28 +04:00
|
|
|
nsIView*
|
|
|
|
nsGfxScrollFrameInner::GetParentViewForChildFrame(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
if (aFrame->GetContent() == mOuter->GetContent()) {
|
|
|
|
NS_ASSERTION(mScrollableView, "Scrollable view should have been created by now");
|
|
|
|
// scrolled frame, put it under our anonymous view
|
|
|
|
return mScrollableView->View();
|
|
|
|
}
|
|
|
|
// scrollbars and stuff; put them under our regular view
|
|
|
|
return mOuter->GetView();
|
|
|
|
}
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles
|
|
|
|
nsGfxScrollFrameInner::GetScrollbarStylesFromFrame() const
|
|
|
|
{
|
2004-09-05 03:03:04 +04:00
|
|
|
ScrollbarStyles result;
|
2005-04-04 02:40:25 +04:00
|
|
|
if (mIsRoot) {
|
2004-09-05 03:03:04 +04:00
|
|
|
nsPresContext *presContext = mOuter->GetPresContext();
|
2004-09-05 04:04:04 +04:00
|
|
|
result = presContext->GetViewportOverflowOverride();
|
2004-09-05 03:03:04 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = presContext->GetContainer();
|
2004-09-29 05:46:55 +04:00
|
|
|
if (container) {
|
|
|
|
nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
|
|
|
|
result.mHorizontal);
|
|
|
|
HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_Y,
|
|
|
|
result.mVertical);
|
|
|
|
}
|
2004-05-05 06:32:27 +04:00
|
|
|
} else {
|
2004-09-05 04:04:04 +04:00
|
|
|
const nsStyleDisplay *disp = mOuter->GetStyleDisplay();
|
|
|
|
result.mHorizontal = disp->mOverflowX;
|
|
|
|
result.mVertical = disp->mOverflowY;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
|
2004-09-05 03:03:04 +04:00
|
|
|
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;
|
2004-08-27 05:26:55 +04:00
|
|
|
}
|
|
|
|
|
2004-09-13 06:10:29 +04:00
|
|
|
/**
|
|
|
|
* this code is resposible for restoring the scroll position back to some
|
|
|
|
* saved positon. if the user has not moved the scroll position manually
|
|
|
|
* we keep scrolling down until we get to our orignally position. keep in
|
|
|
|
* mind that content could incrementally be coming in. we only want to stop
|
|
|
|
* when we reach our new position.
|
|
|
|
*/
|
2004-07-24 01:39:47 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ScrollToRestoredPosition()
|
|
|
|
{
|
2004-09-13 06:10:29 +04:00
|
|
|
nsIScrollableView* scrollingView = GetScrollableView();
|
|
|
|
if (!scrollingView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mRestoreRect.y == -1 || mLastPos.x == -1 || mLastPos.y == -1) {
|
|
|
|
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.
|
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = 0;
|
|
|
|
scrollingView->GetScrollPosition(x, y);
|
|
|
|
|
|
|
|
// if we didn't move, we still need to restore
|
|
|
|
if (x == mLastPos.x && y == mLastPos.y) {
|
|
|
|
nsRect childRect(0, 0, 0, 0);
|
|
|
|
nsIView* child = nsnull;
|
|
|
|
nsresult rv = scrollingView->GetScrolledView(child);
|
|
|
|
if (NS_SUCCEEDED(rv) && child)
|
|
|
|
childRect = child->GetBounds();
|
|
|
|
|
|
|
|
PRInt32 cx, cy, x, y;
|
|
|
|
scrollingView->GetScrollPosition(cx,cy);
|
|
|
|
|
|
|
|
x = (int)
|
|
|
|
(((float)childRect.width / mRestoreRect.width) * mRestoreRect.x);
|
|
|
|
y = (int)
|
|
|
|
(((float)childRect.height / mRestoreRect.height) * mRestoreRect.y);
|
|
|
|
|
|
|
|
// if our position is greater than the scroll position, scroll.
|
|
|
|
// remember that we could be incrementally loading so we may enter
|
|
|
|
// and scroll many times.
|
|
|
|
if (y > cy || x > cx) {
|
|
|
|
scrollingView->ScrollTo(x, y, 0);
|
|
|
|
// scrollpostion goes from twips to pixels. this fixes any roundoff
|
|
|
|
// problems.
|
|
|
|
scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
|
|
|
|
} else {
|
|
|
|
// if we reached the position then stop
|
|
|
|
mRestoreRect.y = -1;
|
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// user moved the position, so we won't need to restore
|
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
}
|
2004-07-24 01:39:47 +04:00
|
|
|
}
|
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::PostScrollPortEvent(PRBool aOverflow, nsScrollPortEvent::orientType aType)
|
|
|
|
{
|
2005-04-29 03:48:28 +04:00
|
|
|
nsScrollPortEvent* event = new nsScrollPortEvent(PR_TRUE, aOverflow ?
|
2005-04-04 01:00:41 +04:00
|
|
|
NS_SCROLLPORT_OVERFLOW :
|
2005-04-29 03:48:28 +04:00
|
|
|
NS_SCROLLPORT_UNDERFLOW,
|
|
|
|
nsnull);
|
2005-04-04 01:00:41 +04:00
|
|
|
event->orient = aType;
|
|
|
|
mOuter->GetPresContext()->PresShell()->PostDOMEvent(mOuter->GetContent(), event);
|
|
|
|
}
|
|
|
|
|
2004-07-24 01:39:47 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ReloadChildFrames()
|
2004-05-05 06:32:27 +04:00
|
|
|
{
|
2005-04-04 01:00:41 +04:00
|
|
|
mScrolledFrame = nsnull;
|
2004-05-05 06:32:27 +04:00
|
|
|
mHScrollbarBox = nsnull;
|
|
|
|
mVScrollbarBox = nsnull;
|
|
|
|
mScrollCornerBox = nsnull;
|
|
|
|
|
|
|
|
nsIFrame* frame = mOuter->GetFirstChild(nsnull);
|
|
|
|
while (frame) {
|
2005-04-04 01:00:41 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (content == mOuter->GetContent()) {
|
|
|
|
NS_ASSERTION(!mScrolledFrame, "Already found the scrolled frame");
|
|
|
|
mScrolledFrame = frame;
|
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None,
|
|
|
|
nsXULAtoms::orient, value)) {
|
|
|
|
// 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;
|
2005-03-31 22:04:50 +04:00
|
|
|
}
|
2005-04-04 01:00:41 +04:00
|
|
|
} else {
|
|
|
|
// probably a scrollcorner
|
|
|
|
NS_ASSERTION(!mScrollCornerBox, "Found multiple scrollcorners");
|
|
|
|
mScrollCornerBox = frame;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = frame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
|
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* presContext = mOuter->GetPresContext();
|
2004-05-05 06:32:27 +04: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->IsPaginated()) {
|
|
|
|
// allow scrollbars if this is the child of the viewport, because
|
|
|
|
// we must be the scrollbars for the print preview window
|
|
|
|
if (!parent || parent->GetType() != nsLayoutAtoms::viewportFrame) {
|
2004-09-04 07:17:18 +04:00
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
2004-05-05 06:32:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-04 03:57:42 +04:00
|
|
|
nsIScrollableFrame *scrollable;
|
|
|
|
CallQueryInterface(mOuter, &scrollable);
|
2004-08-27 05:26:55 +04:00
|
|
|
|
2005-04-04 02:40:25 +04:00
|
|
|
// At this stage in frame construction, the document element and/or
|
|
|
|
// BODY overflow styles have not yet been propagated to the
|
|
|
|
// viewport. So GetScrollbarStylesFromFrame called here will only
|
|
|
|
// take into account the scrollbar preferences set on the docshell.
|
|
|
|
// Thus if no scrollbar preferences are set on the docshell, we will
|
|
|
|
// always create scrollbars, which means later dynamic changes to
|
|
|
|
// propagated overflow styles will show or hide scrollbars on the
|
|
|
|
// viewport without requiring frame reconstruction of the viewport
|
|
|
|
// (good!).
|
|
|
|
|
|
|
|
// XXX On the other hand, if scrolling="no" is set on the container
|
|
|
|
// we won't create scrollbars here so no scrollbars will ever be
|
|
|
|
// created even if the container's scrolling attribute is later
|
|
|
|
// changed. However, this has never been supported.
|
2004-09-04 03:57:42 +04:00
|
|
|
ScrollbarStyles styles = scrollable->GetScrollbarStyles();
|
|
|
|
PRBool canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
PRBool canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
|
|
|
|
if (!canHaveHorizontal && !canHaveVertical)
|
|
|
|
// Nothing to do.
|
2004-05-05 06:32:27 +04:00
|
|
|
return;
|
2004-06-25 16:26:02 +04:00
|
|
|
|
2004-09-04 07:17:18 +04:00
|
|
|
// The anonymous <div> used by <inputs> never gets scrollbars.
|
|
|
|
nsCOMPtr<nsITextControlFrame> textFrame(do_QueryInterface(parent));
|
|
|
|
if (textFrame) {
|
|
|
|
// Make sure we are not a text area.
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> textAreaElement(do_QueryInterface(parent->GetContent()));
|
|
|
|
if (!textAreaElement) {
|
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-04 03:57:42 +04:00
|
|
|
nsNodeInfoManager *nodeInfoManager =
|
|
|
|
presContext->GetDocument()->NodeInfoManager();
|
2004-05-05 06:32:27 +04:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
nodeInfoManager->GetNodeInfo(nsXULAtoms::scrollbar, nsnull,
|
|
|
|
kNameSpaceID_XUL, getter_AddRefs(nodeInfo));
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
if (canHaveHorizontal) {
|
2004-06-25 20:38:43 +04:00
|
|
|
NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
|
2004-05-05 06:32:27 +04:00
|
|
|
content->SetAttr(kNameSpaceID_None, nsXULAtoms::orient,
|
|
|
|
NS_LITERAL_STRING("horizontal"), PR_FALSE);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canHaveVertical) {
|
2004-06-25 20:38:43 +04:00
|
|
|
NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
|
2004-05-05 06:32:27 +04:00
|
|
|
content->SetAttr(kNameSpaceID_None, nsXULAtoms::orient,
|
|
|
|
NS_LITERAL_STRING("vertical"), PR_FALSE);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canHaveHorizontal && canHaveVertical) {
|
|
|
|
nodeInfoManager->GetNodeInfo(nsXULAtoms::scrollcorner, nsnull,
|
|
|
|
kNameSpaceID_XUL, getter_AddRefs(nodeInfo));
|
2004-06-25 20:38:43 +04:00
|
|
|
NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
|
2004-05-05 06:32:27 +04:00
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
1999-10-15 08:29:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxScrollFrameInner::ScrollPositionWillChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
// Do nothing.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-05 15:41:19 +04:00
|
|
|
/**
|
|
|
|
* Called when someone (external or this frame) moves the scroll area.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::InternalScrollPositionDidChange(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
if (mVScrollbarBox)
|
|
|
|
SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, aY);
|
|
|
|
|
|
|
|
if (mHScrollbarBox)
|
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, aX);
|
|
|
|
}
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
/**
|
|
|
|
* Called if something externally moves the scroll area
|
|
|
|
* This can happen if the user pages up down or uses arrow keys
|
|
|
|
* So what we need to do up adjust the scrollbars to match.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
1999-10-15 08:29:30 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollPositionDidChange(nsIScrollableView* aScrollable, nscoord aX, nscoord aY)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2003-04-05 15:41:19 +04:00
|
|
|
NS_ASSERTION(!mViewInitiatedScroll, "Cannot reenter ScrollPositionDidChange");
|
|
|
|
|
|
|
|
mViewInitiatedScroll = PR_TRUE;
|
|
|
|
|
|
|
|
InternalScrollPositionDidChange(aX, aY);
|
|
|
|
|
|
|
|
mViewInitiatedScroll = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent, PRInt32 aModType)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2003-05-22 05:46:13 +04:00
|
|
|
NS_ASSERTION(aContent, "aContent must not be null");
|
|
|
|
|
2003-04-05 15:41:19 +04:00
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// In case 2), we don't need to scroll the view because the scrolling
|
|
|
|
// has already happened. In case 3) we don't need to scroll because
|
|
|
|
// we're just adjusting the scrollbars back to the correct setting
|
|
|
|
// for the view.
|
|
|
|
//
|
|
|
|
// We used to detect this case implicitly because we'd compare the
|
|
|
|
// scrollbar attributes with the view's current scroll position and
|
|
|
|
// bail out if they were equal. But that approach is fragile; it can
|
|
|
|
// fail when, for example, the view scrolls horizontally and
|
|
|
|
// vertically simultaneously; we'll get here when only the vertical
|
|
|
|
// attribute has been set, so the attributes and the view scroll
|
|
|
|
// position don't yet agree, and we'd tell the view to scroll to the
|
|
|
|
// new vertical position and the old horizontal position! Even worse
|
|
|
|
// things could happen when smooth scrolling got involved ... crashes
|
|
|
|
// and other terrors.
|
2004-09-06 06:44:43 +04:00
|
|
|
if (mViewInitiatedScroll || mFrameInitiatedScroll) return;
|
2003-04-05 15:41:19 +04:00
|
|
|
|
2004-09-28 22:37:50 +04:00
|
|
|
nsIContent* vcontent = mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull;
|
|
|
|
nsIContent* hcontent = mHScrollbarBox ? mHScrollbarBox->GetContent() : nsnull;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
if (hcontent == aContent || vcontent == aContent)
|
|
|
|
{
|
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = 0;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
nsAutoString value;
|
|
|
|
if (hcontent && NS_CONTENT_ATTR_HAS_VALUE == hcontent->GetAttr(kNameSpaceID_None, nsXULAtoms::curpos, value))
|
|
|
|
{
|
|
|
|
PRInt32 error;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
// convert it to an integer
|
|
|
|
x = value.ToInteger(&error);
|
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
if (vcontent && NS_CONTENT_ATTR_HAS_VALUE == vcontent->GetAttr(kNameSpaceID_None, nsXULAtoms::curpos, value))
|
|
|
|
{
|
|
|
|
PRInt32 error;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
// convert it to an integer
|
|
|
|
y = value.ToInteger(&error);
|
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
// Make sure the scrollbars indeed moved before firing the event.
|
|
|
|
// I think it is OK to prevent the call to ScrollbarChanged()
|
|
|
|
// if we didn't actually move. The following check is the first
|
|
|
|
// thing ScrollbarChanged() does anyway, before deciding to move
|
|
|
|
// the scrollbars.
|
|
|
|
nscoord curPosX=0, curPosY=0;
|
|
|
|
nsIScrollableView* s = GetScrollableView();
|
|
|
|
if (s) {
|
|
|
|
s->GetScrollPosition(curPosX, curPosY);
|
|
|
|
if ((x*mOnePixel) == curPosX && (y*mOnePixel) == curPosY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRBool isSmooth = aContent->HasAttr(kNameSpaceID_None, nsXULAtoms::smooth);
|
2002-09-26 01:29:33 +04:00
|
|
|
|
2004-09-06 06:44:43 +04:00
|
|
|
if (isSmooth) {
|
|
|
|
// Make sure an attribute-setting callback occurs even if the view didn't actually move yet
|
|
|
|
// We need to make sure other listeners see that the scroll position is not (yet)
|
|
|
|
// what they thought it was.
|
|
|
|
s->GetScrollPosition(curPosX, curPosY);
|
|
|
|
|
|
|
|
NS_ASSERTION(!mFrameInitiatedScroll, "Unexpected reentry");
|
|
|
|
// Make sure we don't do anything in when the view calls us back for this
|
|
|
|
// scroll operation.
|
|
|
|
mFrameInitiatedScroll = PR_TRUE;
|
|
|
|
InternalScrollPositionDidChange(curPosX, curPosY);
|
|
|
|
mFrameInitiatedScroll = PR_FALSE;
|
|
|
|
}
|
|
|
|
ScrollbarChanged(mOuter->GetPresContext(), x*mOnePixel, y*mOnePixel, isSmooth ? NS_VMREFRESH_SMOOTHSCROLL : 0);
|
|
|
|
|
|
|
|
// Fire the onScroll event now that we have scrolled
|
|
|
|
nsIPresShell *presShell = mOuter->GetPresContext()->GetPresShell();
|
|
|
|
if (presShell) {
|
2005-04-29 03:48:28 +04:00
|
|
|
nsScrollbarEvent event(PR_TRUE, NS_SCROLL_EVENT, nsnull);
|
2004-09-06 06:44:43 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
// note if hcontent is non-null then hframe must be non-null.
|
|
|
|
// likewise for vcontent and vframe. Thus targetFrame will always
|
|
|
|
// be non-null in here.
|
|
|
|
nsIFrame* targetFrame =
|
2004-09-28 22:37:50 +04:00
|
|
|
hcontent == aContent ? mHScrollbarBox : mVScrollbarBox;
|
2004-09-06 06:44:43 +04:00
|
|
|
presShell->HandleEventWithTarget(&event, targetFrame,
|
|
|
|
aContent,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::AdjustHorizontalScrollbar()
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2001-04-12 03:04:11 +04:00
|
|
|
#ifdef IBMBIDI
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* vis = mOuter->GetStyleVisibility();
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2004-01-06 02:56:00 +03:00
|
|
|
// Scroll the view horizontally if:
|
|
|
|
// 1) We are creating the scrollbar for the first time and the
|
|
|
|
// horizontal scroll position of the view is 0 or
|
|
|
|
// 2) The display direction is changed
|
|
|
|
PRBool needScroll;
|
|
|
|
if (mLastDir == -1) {
|
|
|
|
// Creating the scrollbar the first time
|
2005-04-29 01:57:22 +04:00
|
|
|
nscoord curPosX = 0, curPosY = 0;
|
2004-05-05 06:32:27 +04:00
|
|
|
nsIScrollableView* s = GetScrollableView();
|
2004-01-06 02:56:00 +03:00
|
|
|
if (s) {
|
|
|
|
s->GetScrollPosition(curPosX, curPosY);
|
|
|
|
}
|
|
|
|
needScroll = (curPosX == 0);
|
|
|
|
} else {
|
|
|
|
needScroll = (mLastDir != vis->mDirection);
|
|
|
|
}
|
|
|
|
if (needScroll) {
|
2001-12-18 01:51:39 +03:00
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::curpos,
|
|
|
|
(NS_STYLE_DIRECTION_LTR == vis->mDirection) ? 0 : 0x7FFFFFFF);
|
2001-04-12 03:04:11 +04:00
|
|
|
}
|
2004-01-06 02:56:00 +03:00
|
|
|
mLastDir = vis->mDirection;
|
2001-04-12 03:04:11 +04:00
|
|
|
#endif // IBMBIDI
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsXULScrollFrame::AddHorizontalScrollbar(nsBoxLayoutState& aState,
|
|
|
|
nsRect& aScrollAreaSize, PRBool aOnTop)
|
|
|
|
{
|
|
|
|
if (!mInner.mHScrollbarBox)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
mInner.AdjustHorizontalScrollbar();
|
2001-12-18 01:51:39 +03:00
|
|
|
return AddRemoveScrollbar(aState, aScrollAreaSize, aOnTop, PR_TRUE, PR_TRUE);
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::AddVerticalScrollbar(nsBoxLayoutState& aState,
|
|
|
|
nsRect& aScrollAreaSize, PRBool aOnRight)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mInner.mVScrollbarBox)
|
2001-12-18 01:51:39 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return AddRemoveScrollbar(aState, aScrollAreaSize, aOnRight, PR_FALSE, PR_TRUE);
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2004-03-11 02:52:01 +03:00
|
|
|
void
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::RemoveHorizontalScrollbar(nsBoxLayoutState& aState,
|
|
|
|
nsRect& aScrollAreaSize, PRBool aOnTop)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2004-03-11 02:52:01 +03:00
|
|
|
// removing a scrollbar should always fit
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool result =
|
|
|
|
#endif
|
|
|
|
AddRemoveScrollbar(aState, aScrollAreaSize, aOnTop, PR_TRUE, PR_FALSE);
|
|
|
|
NS_ASSERTION(result, "Removing horizontal scrollbar failed to fit??");
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2004-03-11 02:52:01 +03:00
|
|
|
void
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::RemoveVerticalScrollbar(nsBoxLayoutState& aState,
|
|
|
|
nsRect& aScrollAreaSize, PRBool aOnRight)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2004-03-11 02:52:01 +03:00
|
|
|
// removing a scrollbar should always fit
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool result =
|
|
|
|
#endif
|
|
|
|
AddRemoveScrollbar(aState, aScrollAreaSize, aOnRight, PR_FALSE, PR_FALSE);
|
|
|
|
NS_ASSERTION(result, "Removing vertical scrollbar failed to fit??");
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(nsBoxLayoutState& aState, nsRect& aScrollAreaSize,
|
|
|
|
PRBool aOnTop, PRBool aHorizontal, PRBool aAdd)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
|
|
|
if (aHorizontal) {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mNeverHasHorizontalScrollbar || !mInner.mHScrollbarBox)
|
2000-05-15 08:12:31 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsSize hSize;
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHScrollbarBox->GetMinSize(aState, hSize);
|
|
|
|
nsBox::AddMargin(mInner.mHScrollbarBox, hSize);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, aAdd);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2001-12-15 02:13:08 +03:00
|
|
|
PRBool hasHorizontalScrollbar;
|
|
|
|
PRBool fit = AddRemoveScrollbar(hasHorizontalScrollbar, aScrollAreaSize.y, aScrollAreaSize.height, hSize.height, aOnTop, aAdd);
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHasHorizontalScrollbar = hasHorizontalScrollbar; // because mHasHorizontalScrollbar is a PRPackedBool
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!fit)
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, !aAdd);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
|
|
|
return fit;
|
|
|
|
} else {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mNeverHasVerticalScrollbar || !mInner.mVScrollbarBox)
|
2000-05-15 08:12:31 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsSize vSize;
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mVScrollbarBox->GetMinSize(aState, vSize);
|
|
|
|
nsBox::AddMargin(mInner.mVScrollbarBox, vSize);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, aAdd);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2001-12-15 02:13:08 +03:00
|
|
|
PRBool hasVerticalScrollbar;
|
|
|
|
PRBool fit = AddRemoveScrollbar(hasVerticalScrollbar, aScrollAreaSize.x, aScrollAreaSize.width, vSize.width, aOnTop, aAdd);
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHasVerticalScrollbar = hasVerticalScrollbar; // because mHasVerticalScrollbar is a PRPackedBool
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!fit)
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, !aAdd);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
|
|
|
return fit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::AddRemoveScrollbar(PRBool& aHasScrollbar, nscoord& aXY,
|
|
|
|
nscoord& aSize, nscoord aSbSize,
|
|
|
|
PRBool aRightOrBottom, PRBool aAdd)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
1999-10-12 04:16:06 +04:00
|
|
|
nscoord size = aSize;
|
2004-09-27 23:21:41 +04:00
|
|
|
nscoord xy = aXY;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
|
|
|
if (size != NS_INTRINSICSIZE) {
|
2000-04-03 10:26:38 +04:00
|
|
|
if (aAdd) {
|
1999-10-12 04:16:06 +04:00
|
|
|
size -= aSbSize;
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!aRightOrBottom && size >= 0)
|
2004-09-27 23:21:41 +04:00
|
|
|
xy += aSbSize;
|
2000-04-03 10:26:38 +04:00
|
|
|
} else {
|
1999-10-12 04:16:06 +04:00
|
|
|
size += aSbSize;
|
2000-04-03 10:26:38 +04:00
|
|
|
if (!aRightOrBottom)
|
2004-09-27 23:21:41 +04:00
|
|
|
xy -= aSbSize;
|
2000-04-03 10:26:38 +04:00
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
// not enough room? Yes? Return true.
|
2004-09-27 23:21:41 +04:00
|
|
|
if (size >= 0) {
|
1999-10-12 04:16:06 +04:00
|
|
|
aHasScrollbar = aAdd;
|
|
|
|
aSize = size;
|
2004-09-27 23:21:41 +04:00
|
|
|
aXY = xy;
|
2000-05-15 08:12:31 +04:00
|
|
|
return PR_TRUE;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2002-08-21 12:56:58 +04:00
|
|
|
aHasScrollbar = PR_FALSE;
|
2000-05-15 08:12:31 +04:00
|
|
|
return PR_FALSE;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2002-01-23 05:53:02 +03:00
|
|
|
/**
|
|
|
|
* When reflowing a HTML document where the content model is being created
|
|
|
|
* The nsGfxScrollFrame will get an Initial reflow when the body is opened by the content sink.
|
|
|
|
* But there isn't enough content to really reflow very much of the document
|
|
|
|
* so it never needs to do layout for the scrollbars
|
|
|
|
*
|
|
|
|
* So later other reflows happen and these are Incremental reflows, and then the scrollbars
|
|
|
|
* get reflowed. The important point here is that when they reflowed the ReflowState inside the
|
|
|
|
* BoxLayoutState contains an "Incremental" reason and never a "Initial" reason.
|
|
|
|
*
|
|
|
|
* When it reflows for Print Preview, the content model is already full constructed and it lays
|
|
|
|
* out the entire document at that time. When it returns back here it discovers it needs scrollbars
|
|
|
|
* and this is a problem because the ReflowState inside the BoxLayoutState still has a "Initial"
|
|
|
|
* reason and if it does a Layout it is essentially asking everything to reflow yet again with
|
|
|
|
* an "Initial" reason. This causes a lot of problems especially for tables.
|
|
|
|
*
|
|
|
|
* The solution for this is to change the ReflowState's reason from Initial to Resize and let
|
|
|
|
* all the frames do what is necessary for a resize refow. Now, we only need to do this when
|
|
|
|
* it is doing PrintPreview and we need only do it for HTML documents and NOT chrome.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::AdjustReflowStateForPrintPreview(nsBoxLayoutState& aState, PRBool& aSetBack)
|
2002-01-23 05:53:02 +03:00
|
|
|
{
|
|
|
|
aSetBack = PR_FALSE;
|
|
|
|
PRBool isChrome;
|
|
|
|
PRBool isInitialPP = nsBoxFrame::IsInitialReflowForPrintPreview(aState, isChrome);
|
|
|
|
if (isInitialPP && !isChrome) {
|
|
|
|
// I know you shouldn't, but we cast away the "const" here
|
|
|
|
nsHTMLReflowState* reflowState = (nsHTMLReflowState*)aState.GetReflowState();
|
|
|
|
reflowState->reason = eReflowReason_Resize;
|
|
|
|
aSetBack = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets reflow state back to Initial when we are done.
|
|
|
|
*/
|
|
|
|
void
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::AdjustReflowStateBack(nsBoxLayoutState& aState, PRBool aSetBack)
|
2002-01-23 05:53:02 +03:00
|
|
|
{
|
|
|
|
// I know you shouldn't, but we cast away the "const" here
|
|
|
|
nsHTMLReflowState* reflowState = (nsHTMLReflowState*)aState.GetReflowState();
|
|
|
|
if (aSetBack && reflowState->reason == eReflowReason_Resize) {
|
|
|
|
reflowState->reason = eReflowReason_Initial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
void
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::LayoutScrollArea(nsBoxLayoutState& aState, const nsRect& aRect)
|
2005-04-04 01:00:41 +04:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
nsIView* scrollView = mInner.mScrollableView->View();
|
2005-04-04 01:00:41 +04:00
|
|
|
nsIViewManager* vm = scrollView->GetViewManager();
|
|
|
|
vm->MoveViewTo(scrollView, aRect.x, aRect.y);
|
|
|
|
vm->ResizeView(scrollView, nsRect(nsPoint(0, 0), aRect.Size()), PR_TRUE);
|
|
|
|
|
|
|
|
PRUint32 oldflags = aState.LayoutFlags();
|
2005-04-29 01:57:22 +04:00
|
|
|
// set the origin of childRect to (0,0) even though we might have
|
|
|
|
// borders or a left-hand-side scrollbar. We've accounted for that
|
|
|
|
// by positioning the anonymous mScrollableView.
|
2005-04-04 01:00:41 +04:00
|
|
|
nsRect childRect = nsRect(nsPoint(0, 0), aRect.Size());
|
|
|
|
|
|
|
|
PRInt32 flags = NS_FRAME_NO_MOVE_VIEW;
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize min(0,0);
|
|
|
|
mInner.mScrolledFrame->GetMinSize(aState, min);
|
|
|
|
|
|
|
|
if (min.height > childRect.height)
|
|
|
|
childRect.height = min.height;
|
|
|
|
|
|
|
|
if (min.width > childRect.width)
|
|
|
|
childRect.width = min.width;
|
2005-04-04 01:00:41 +04:00
|
|
|
|
|
|
|
aState.SetLayoutFlags(flags);
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mScrolledFrame->SetBounds(aState, childRect);
|
|
|
|
mInner.mScrolledFrame->Layout(aState);
|
2005-04-04 01:00:41 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
childRect = mInner.mScrolledFrame->GetRect();
|
2005-04-04 01:00:41 +04:00
|
|
|
|
|
|
|
if (childRect.width < aRect.width || childRect.height < aRect.height)
|
|
|
|
{
|
|
|
|
childRect.width = PR_MAX(childRect.width, aRect.width);
|
|
|
|
childRect.height = PR_MAX(childRect.height, aRect.height);
|
|
|
|
|
|
|
|
// remove overflow area when we update the bounds,
|
|
|
|
// because we've already accounted for it
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mScrolledFrame->SetBounds(aState, childRect, PR_TRUE);
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aState.SetLayoutFlags(oldflags);
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
childRect = mInner.mScrolledFrame->GetRect();
|
2005-04-04 01:00:41 +04:00
|
|
|
|
|
|
|
// first see what changed
|
|
|
|
PRBool vertChanged = PR_FALSE;
|
|
|
|
PRBool horizChanged = PR_FALSE;
|
|
|
|
|
|
|
|
if (mVerticalOverflow && childRect.height <= aRect.height) {
|
|
|
|
mVerticalOverflow = PR_FALSE;
|
|
|
|
vertChanged = PR_TRUE;
|
|
|
|
} else if (childRect.height > aRect.height) {
|
|
|
|
// XXX we fire an event every time we reflow with overflowing height. Do
|
|
|
|
// we really need to?
|
|
|
|
if (!mVerticalOverflow) {
|
|
|
|
mVerticalOverflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
vertChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHorizontalOverflow && childRect.width <= aRect.width) {
|
|
|
|
mHorizontalOverflow = PR_FALSE;
|
|
|
|
horizChanged = PR_TRUE;
|
|
|
|
} else if (childRect.width > aRect.width) {
|
|
|
|
// XXX we fire an event every time we reflow with overflowing width. Do
|
|
|
|
// we really need to?
|
|
|
|
if (!mHorizontalOverflow) {
|
|
|
|
mHorizontalOverflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
horizChanged = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if either changed
|
|
|
|
if (vertChanged || horizChanged)
|
|
|
|
{
|
|
|
|
// are there 2 events or 1?
|
|
|
|
if (vertChanged && horizChanged) {
|
|
|
|
if (mVerticalOverflow == mHorizontalOverflow)
|
|
|
|
{
|
|
|
|
// both either overflowed or underflowed. 1 event
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::both);
|
2005-04-04 01:00:41 +04:00
|
|
|
} else {
|
|
|
|
// one overflowed and one underflowed
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::vertical);
|
|
|
|
mInner.PostScrollPortEvent(mHorizontalOverflow, nsScrollPortEvent::horizontal);
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
} else if (vertChanged) // only one changed either vert or horiz
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::vertical);
|
2005-04-04 01:00:41 +04:00
|
|
|
else
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.PostScrollPortEvent(mHorizontalOverflow, nsScrollPortEvent::horizontal);
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::IsScrollbarOnRight()
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
//TODO make bidi code set these from preferences
|
|
|
|
const nsStyleVisibility* vis = mOuter->GetStyleVisibility();
|
|
|
|
return vis->mDirection != NS_STYLE_DIRECTION_RTL;
|
|
|
|
#else
|
|
|
|
return PR_TRUE;
|
|
|
|
#endif // IBMBIDI
|
|
|
|
}
|
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
/**
|
|
|
|
* Reflow the scroll area if it needs it and return its size. Also determine if the reflow will
|
|
|
|
* cause any of the scrollbars to need to be reflowed.
|
|
|
|
*/
|
2000-03-31 11:02:06 +04:00
|
|
|
nsresult
|
2005-04-29 01:57:22 +04:00
|
|
|
nsXULScrollFrame::Layout(nsBoxLayoutState& aState)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool scrollbarRight = mInner.IsScrollbarOnRight();
|
|
|
|
PRBool scrollbarBottom = PR_TRUE;
|
2001-04-12 03:04:11 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// get the content rect
|
|
|
|
nsRect clientRect(0,0,0,0);
|
2005-04-29 01:57:22 +04:00
|
|
|
GetClientRect(clientRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// the scroll area size starts off as big as our content area
|
|
|
|
nsRect scrollAreaRect(clientRect);
|
|
|
|
|
2004-03-11 02:52:01 +03: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).
|
|
|
|
**************/
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
ScrollbarStyles styles = GetScrollbarStyles();
|
2003-05-22 05:46:13 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// Look at our style do we always have vertical or horizontal scrollbars?
|
2003-05-22 05:46:13 +04:00
|
|
|
if (styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL)
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHasHorizontalScrollbar = PR_TRUE;
|
2003-05-22 05:46:13 +04:00
|
|
|
if (styles.mVertical == NS_STYLE_OVERFLOW_SCROLL)
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mHasVerticalScrollbar = PR_TRUE;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasHorizontalScrollbar)
|
|
|
|
AddHorizontalScrollbar(aState, scrollAreaRect, scrollbarBottom);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasVerticalScrollbar)
|
|
|
|
AddVerticalScrollbar(aState, scrollAreaRect, scrollbarRight);
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsRect oldScrollAreaBounds = mInner.mScrollableView->View()->GetBounds();
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// layout our the scroll area
|
2005-04-04 01:00:41 +04:00
|
|
|
LayoutScrollArea(aState, scrollAreaRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// now look at the content area and see if we need scrollbars or not
|
|
|
|
PRBool needsLayout = PR_FALSE;
|
|
|
|
nsSize scrolledContentSize(0,0);
|
|
|
|
|
|
|
|
// if we have 'auto' scrollbars look at the vertical case
|
2003-05-22 05:46:13 +04:00
|
|
|
if (styles.mVertical != NS_STYLE_OVERFLOW_SCROLL) {
|
2000-03-31 11:02:06 +04:00
|
|
|
// get the area frame is the scrollarea
|
2005-04-29 01:57:22 +04:00
|
|
|
scrolledContentSize = mInner.GetScrolledSize();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// There are two cases to consider
|
|
|
|
if (scrolledContentSize.height <= scrollAreaRect.height
|
2003-05-22 05:46:13 +04:00
|
|
|
|| styles.mVertical != NS_STYLE_OVERFLOW_AUTO) {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasVerticalScrollbar) {
|
2000-03-31 11:02:06 +04:00
|
|
|
// We left room for the vertical scrollbar, but it's not needed;
|
|
|
|
// remove it.
|
2005-04-29 01:57:22 +04:00
|
|
|
RemoveVerticalScrollbar(aState, scrollAreaRect, scrollbarRight);
|
2004-03-11 02:52:01 +03:00
|
|
|
needsLayout = PR_TRUE;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mInner.mHasVerticalScrollbar) {
|
2000-03-31 11:02:06 +04:00
|
|
|
// We didn't leave room for the vertical scrollbar, but it turns
|
|
|
|
// out we needed it
|
2005-04-29 01:57:22 +04:00
|
|
|
if (AddVerticalScrollbar(aState, scrollAreaRect, scrollbarRight))
|
2000-03-31 11:02:06 +04:00
|
|
|
needsLayout = PR_TRUE;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// ok layout at the right size
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
|
|
|
resizeState.SetLayoutReason(nsBoxLayoutState::Resize);
|
2002-01-23 05:53:02 +03:00
|
|
|
PRBool setBack;
|
|
|
|
AdjustReflowStateForPrintPreview(aState, setBack);
|
2005-04-04 01:00:41 +04:00
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
2002-01-23 05:53:02 +03:00
|
|
|
AdjustReflowStateBack(aState, setBack);
|
2000-05-15 08:12:31 +04:00
|
|
|
needsLayout = PR_FALSE;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// if scrollbars are auto look at the horizontal case
|
2003-05-22 05:46:13 +04:00
|
|
|
if (styles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
// get the area frame is the scrollarea
|
2005-04-29 01:57:22 +04:00
|
|
|
scrolledContentSize = mInner.GetScrolledSize();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// if the child is wider that the scroll area
|
|
|
|
// and we don't have a scrollbar add one.
|
|
|
|
if (scrolledContentSize.width > scrollAreaRect.width
|
2003-05-22 05:46:13 +04:00
|
|
|
&& styles.mHorizontal == NS_STYLE_OVERFLOW_AUTO) {
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mInner.mHasHorizontalScrollbar) {
|
2000-05-15 08:12:31 +04:00
|
|
|
// no scrollbar?
|
2005-04-29 01:57:22 +04:00
|
|
|
if (AddHorizontalScrollbar(aState, scrollAreaRect, scrollbarBottom))
|
2000-03-31 11:02:06 +04:00
|
|
|
needsLayout = PR_TRUE;
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// if we added a horizonal scrollbar and we did not have a vertical
|
|
|
|
// there is a chance that by adding the horizonal scrollbar we will
|
|
|
|
// suddenly need a vertical scrollbar. Is a special case but its
|
|
|
|
// important.
|
2000-04-27 01:01:57 +04:00
|
|
|
//if (!mHasVerticalScrollbar && scrolledContentSize.height > scrollAreaRect.height - sbSize.height)
|
2000-10-29 02:17:53 +04:00
|
|
|
// printf("****Gfx Scrollbar Special case hit!!*****\n");
|
2000-04-03 10:26:38 +04:00
|
|
|
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
|
|
|
// if the area is smaller or equal to and we have a scrollbar then
|
|
|
|
// remove it.
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasHorizontalScrollbar) {
|
|
|
|
RemoveHorizontalScrollbar(aState, scrollAreaRect, scrollbarBottom);
|
2004-03-11 02:52:01 +03:00
|
|
|
needsLayout = PR_TRUE;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// we only need to set the rect. The inner child stays the same size.
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
|
|
|
resizeState.SetLayoutReason(nsBoxLayoutState::Resize);
|
2002-01-23 05:53:02 +03:00
|
|
|
PRBool setBack;
|
|
|
|
AdjustReflowStateForPrintPreview(aState, setBack);
|
2005-04-04 01:00:41 +04:00
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
2002-01-23 05:53:02 +03:00
|
|
|
AdjustReflowStateBack(aState, setBack);
|
2000-05-15 08:12:31 +04:00
|
|
|
needsLayout = PR_FALSE;
|
1999-11-19 18:33:29 +03:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2004-03-11 02:52:01 +03:00
|
|
|
// get the preferred size of the scrollbars
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize hMinSize(0, 0);
|
|
|
|
if (mInner.mHScrollbarBox && mInner.mHasHorizontalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mInner.mHScrollbarBox, &hMinSize, PR_FALSE);
|
2004-03-11 02:52:01 +03:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize vMinSize(0, 0);
|
|
|
|
if (mInner.mVScrollbarBox && mInner.mHasVerticalScrollbar) {
|
|
|
|
GetScrollbarMetrics(aState, mInner.mVScrollbarBox, &vMinSize, PR_TRUE);
|
2004-03-11 02:52:01 +03:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2004-03-11 02:52:01 +03:00
|
|
|
// Disable scrollbars that are too small
|
|
|
|
// Disable horizontal scrollbar first. If we have to disable only one
|
|
|
|
// scrollbar, we'd rather keep the vertical scrollbar.
|
2004-03-12 06:35:53 +03:00
|
|
|
// Note that we always give horizontal scrollbars their preferred height,
|
|
|
|
// never their min-height. So check that there's room for the preferred height.
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasHorizontalScrollbar &&
|
|
|
|
(hMinSize.width > clientRect.width - vMinSize.width
|
|
|
|
|| hMinSize.height > clientRect.height)) {
|
|
|
|
RemoveHorizontalScrollbar(aState, scrollAreaRect, scrollbarBottom);
|
2004-03-11 02:52:01 +03:00
|
|
|
needsLayout = PR_TRUE;
|
|
|
|
}
|
|
|
|
// Now disable vertical scrollbar if necessary
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHasVerticalScrollbar &&
|
|
|
|
(vMinSize.height > clientRect.height - hMinSize.height
|
|
|
|
|| vMinSize.width > clientRect.width)) {
|
|
|
|
RemoveVerticalScrollbar(aState, scrollAreaRect, scrollbarRight);
|
2004-03-11 02:52:01 +03:00
|
|
|
needsLayout = PR_TRUE;
|
2000-04-25 11:10:48 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// we only need to set the rect. The inner child stays the same size.
|
|
|
|
if (needsLayout) {
|
|
|
|
nsBoxLayoutState resizeState(aState);
|
|
|
|
resizeState.SetLayoutReason(nsBoxLayoutState::Resize);
|
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInner.LayoutScrollbars(aState, clientRect, oldScrollAreaBounds, scrollAreaRect);
|
|
|
|
mInner.ScrollToRestoredPosition();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::LayoutScrollbars(nsBoxLayoutState& aState,
|
|
|
|
const nsRect& aContentArea,
|
|
|
|
const nsRect& aOldScrollArea,
|
|
|
|
const nsRect& aScrollArea)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = aState.PresContext();
|
|
|
|
mOnePixel = presContext->IntScaledPixelsToTwips(1);
|
|
|
|
const nsStyleFont* font = mOuter->GetStyleFont();
|
|
|
|
const nsFont& f = font->mFont;
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm = presContext->GetMetricsFor(f);
|
|
|
|
nscoord fontHeight = 1;
|
|
|
|
NS_ASSERTION(fm,"FontMetrics is null assuming fontHeight == 1");
|
|
|
|
if (fm)
|
|
|
|
fm->GetHeight(fontHeight);
|
|
|
|
|
|
|
|
nsSize scrolledContentSize = GetScrolledSize();
|
|
|
|
|
|
|
|
nscoord maxX = scrolledContentSize.width - aScrollArea.width;
|
|
|
|
nscoord maxY = scrolledContentSize.height - aScrollArea.height;
|
2000-04-03 10:26:38 +04:00
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsIScrollableView* scrollable = GetScrollableView();
|
2004-03-11 02:52:01 +03:00
|
|
|
scrollable->SetLineHeight(fontHeight);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2004-03-11 02:52:01 +03:00
|
|
|
if (mVScrollbarBox) {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mHasVerticalScrollbar) {
|
|
|
|
SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, 0);
|
|
|
|
}
|
2004-09-22 10:33:36 +04:00
|
|
|
SetScrollbarEnabled(mVScrollbarBox, maxY);
|
2000-04-25 11:10:48 +04:00
|
|
|
SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY);
|
2005-04-29 01:57:22 +04:00
|
|
|
SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(aScrollArea.height - fontHeight));
|
2002-09-19 02:38:23 +04:00
|
|
|
SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsRect vRect(aScrollArea);
|
|
|
|
vRect.width = aContentArea.width - aScrollArea.width;
|
|
|
|
vRect.x = IsScrollbarOnRight() ? aScrollArea.XMost() : aContentArea.x;
|
2004-03-11 02:52:01 +03:00
|
|
|
nsMargin margin;
|
|
|
|
mVScrollbarBox->GetMargin(margin);
|
|
|
|
vRect.Deflate(margin);
|
2005-04-29 01:57:22 +04:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mVScrollbarBox, vRect);
|
2000-08-04 02:42:36 +04:00
|
|
|
}
|
2004-03-11 02:52:01 +03:00
|
|
|
|
|
|
|
if (mHScrollbarBox) {
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!mHasHorizontalScrollbar) {
|
2005-05-02 06:16:25 +04:00
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, 0);
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2004-09-22 10:33:36 +04:00
|
|
|
SetScrollbarEnabled(mHScrollbarBox, maxX);
|
2000-04-25 11:10:48 +04:00
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::maxpos, maxX);
|
2005-04-29 01:57:22 +04:00
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::pageincrement, nscoord(float(aScrollArea.width)*0.8));
|
2002-09-20 18:50:43 +04:00
|
|
|
SetAttribute(mHScrollbarBox, nsXULAtoms::increment, 10*mOnePixel);
|
2000-04-25 11:10:48 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsRect hRect(aScrollArea);
|
|
|
|
hRect.height = aContentArea.height - aScrollArea.height;
|
|
|
|
hRect.y = PR_TRUE ? aScrollArea.YMost() : aContentArea.y;
|
2004-03-11 02:52:01 +03:00
|
|
|
nsMargin margin;
|
|
|
|
mHScrollbarBox->GetMargin(margin);
|
|
|
|
hRect.Deflate(margin);
|
2005-04-29 01:57:22 +04:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mHScrollbarBox, hRect);
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2003-11-21 13:45:24 +03:00
|
|
|
// place the scrollcorner
|
|
|
|
if (mScrollCornerBox) {
|
|
|
|
nsRect r(0, 0, 0, 0);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (aContentArea.x != aScrollArea.x) {
|
2003-11-21 13:45:24 +03:00
|
|
|
// scrollbar (if any) on left
|
2005-04-29 01:57:22 +04:00
|
|
|
r.x = aContentArea.x;
|
|
|
|
r.width = aScrollArea.x - aContentArea.x;
|
2003-11-21 13:45:24 +03:00
|
|
|
NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
|
|
|
|
} else {
|
|
|
|
// scrollbar (if any) on right
|
2005-04-29 01:57:22 +04:00
|
|
|
r.x = aScrollArea.XMost();
|
|
|
|
r.width = aContentArea.XMost() - aScrollArea.XMost();
|
2003-11-21 13:45:24 +03:00
|
|
|
NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
|
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
if (aContentArea.y != aScrollArea.y) {
|
2003-11-21 13:45:24 +03:00
|
|
|
// scrollbar (if any) on top
|
2005-04-29 01:57:22 +04:00
|
|
|
r.y = aContentArea.y;
|
|
|
|
r.height = aScrollArea.y - aContentArea.y;
|
2003-11-21 13:45:24 +03:00
|
|
|
NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
|
|
|
|
} else {
|
|
|
|
// scrollbar (if any) on bottom
|
2005-04-29 01:57:22 +04:00
|
|
|
r.y = aScrollArea.YMost();
|
|
|
|
r.height = aContentArea.YMost() - aScrollArea.YMost();
|
2003-11-21 13:45:24 +03:00
|
|
|
NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
|
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, mScrollCornerBox, r);
|
2003-11-21 13:45:24 +03:00
|
|
|
}
|
|
|
|
|
2001-04-17 05:45:38 +04:00
|
|
|
// may need to update fixed position children of the viewport,
|
|
|
|
// if the client area changed size because of some dirty reflow
|
|
|
|
// (if the reflow is initial or resize, the fixed children will
|
|
|
|
// be re-laid out anyway)
|
2005-04-29 01:57:22 +04:00
|
|
|
if (aOldScrollArea.Size() != aScrollArea.Size()
|
2004-06-22 06:55:04 +04:00
|
|
|
&& nsBoxLayoutState::Dirty == aState.LayoutReason()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIFrame* parentFrame = mOuter->GetParent();
|
2001-04-17 05:45:38 +04:00
|
|
|
if (parentFrame) {
|
2003-10-31 23:19:18 +03:00
|
|
|
if (parentFrame->GetType() == nsLayoutAtoms::viewportFrame) {
|
2001-04-17 05:45:38 +04:00
|
|
|
// Usually there are no fixed children, so don't do anything unless there's
|
|
|
|
// at least one fixed child
|
2004-01-09 17:20:53 +03:00
|
|
|
if (parentFrame->GetFirstChild(nsLayoutAtoms::fixedList)) {
|
2001-04-17 05:45:38 +04:00
|
|
|
// force a reflow of the fixed children
|
2005-02-08 03:59:52 +03:00
|
|
|
mOuter->GetPresContext()->PresShell()->
|
|
|
|
AppendReflowCommand(parentFrame, eReflowType_UserDefined,
|
|
|
|
nsLayoutAtoms::fixedList);
|
2001-04-17 05:45:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarChanged(nsPresContext* aPresContext, nscoord aX, nscoord aY, PRUint32 aFlags)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2004-05-05 06:32:27 +04:00
|
|
|
nsIScrollableView* scrollable = GetScrollableView();
|
2003-03-24 08:29:45 +03:00
|
|
|
scrollable->ScrollTo(aX, aY, aFlags);
|
2000-10-29 02:17:53 +04:00
|
|
|
// printf("scrolling to: %d, %d\n", aX, aY);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2004-09-22 10:33:36 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SetScrollbarEnabled(nsIBox* aBox, nscoord aMaxPos, PRBool aReflow)
|
|
|
|
{
|
|
|
|
mOuter->GetPresContext()->PresShell()->PostAttributeChange(
|
2004-09-28 22:37:50 +04:00
|
|
|
aBox->GetContent(),
|
2004-09-22 10:33:36 +04:00
|
|
|
kNameSpaceID_None,
|
|
|
|
nsHTMLAtoms::disabled,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
aReflow,
|
|
|
|
aMaxPos ? eChangeType_Remove : eChangeType_Set);
|
|
|
|
}
|
|
|
|
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
/**
|
|
|
|
* Returns whether it actually needed to change the attribute
|
|
|
|
*/
|
|
|
|
PRBool
|
2000-03-31 11:02:06 +04:00
|
|
|
nsGfxScrollFrameInner::SetAttribute(nsIBox* aBox, nsIAtom* aAtom, nscoord aSize, PRBool aReflow)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
// convert to pixels
|
|
|
|
aSize /= mOnePixel;
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
// only set the attribute if it changed.
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
PRInt32 current = GetIntegerAttribute(aBox, aAtom, -1);
|
1999-10-12 04:16:06 +04:00
|
|
|
if (current != aSize)
|
|
|
|
{
|
2001-08-02 16:12:53 +04:00
|
|
|
nsAutoString newValue;
|
|
|
|
newValue.AppendInt(aSize);
|
2004-09-28 22:37:50 +04:00
|
|
|
aBox->GetContent()->SetAttr(kNameSpaceID_None, aAtom, newValue, aReflow);
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
return PR_TRUE;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-10 01:02:40 +03:00
|
|
|
|
|
|
|
return PR_FALSE;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2004-09-29 06:08:51 +04:00
|
|
|
nsSize
|
|
|
|
nsGfxScrollFrameInner::GetScrolledSize() const
|
2000-07-08 02:24:06 +04:00
|
|
|
{
|
2005-04-04 01:00:41 +04:00
|
|
|
nsRect r = mScrolledFrame->GetOverflowRect();
|
|
|
|
return nsSize(r.XMost(), r.YMost());
|
2004-09-29 06:08:51 +04:00
|
|
|
}
|
2000-07-08 02:24:06 +04:00
|
|
|
|
2004-09-29 06:08:51 +04:00
|
|
|
nsMargin
|
|
|
|
nsGfxScrollFrameInner::GetActualScrollbarSizes() const {
|
|
|
|
nsRect contentRect;
|
|
|
|
mOuter->GetClientRect(contentRect);
|
2005-04-04 01:00:41 +04:00
|
|
|
nsRect scrollArea = mScrollableView->View()->GetBounds();
|
2004-09-29 06:08:51 +04:00
|
|
|
|
|
|
|
return nsMargin(scrollArea.x - contentRect.x, scrollArea.y - contentRect.y,
|
|
|
|
contentRect.XMost() - scrollArea.XMost(),
|
|
|
|
contentRect.YMost() - scrollArea.YMost());
|
2000-07-08 02:24:06 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SetScrollbarVisibility(nsIBox* aScrollbar, PRBool aVisible)
|
|
|
|
{
|
2002-10-24 07:11:53 +04:00
|
|
|
if (!aScrollbar)
|
|
|
|
return;
|
|
|
|
|
2000-07-14 03:00:59 +04:00
|
|
|
nsCOMPtr<nsIScrollbarFrame> scrollbar(do_QueryInterface(aScrollbar));
|
|
|
|
if (scrollbar) {
|
|
|
|
// See if we have a mediator.
|
|
|
|
nsCOMPtr<nsIScrollbarMediator> mediator;
|
|
|
|
scrollbar->GetScrollbarMediator(getter_AddRefs(mediator));
|
|
|
|
if (mediator) {
|
|
|
|
// Inform the mediator of the visibility change.
|
2004-05-29 04:09:05 +04:00
|
|
|
mediator->VisibilityChanged(scrollbar, aVisible);
|
2000-07-14 03:00:59 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
PRInt32
|
2000-03-31 11:02:06 +04:00
|
|
|
nsGfxScrollFrameInner::GetIntegerAttribute(nsIBox* aBox, nsIAtom* atom, PRInt32 defaultValue)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2004-09-28 22:37:50 +04:00
|
|
|
nsIContent* content = aBox->GetContent();
|
1999-08-20 02:16:23 +04:00
|
|
|
|
Landing changes Vidur made while the tree was closed for beta1 work, here's a list of the changes. r=me
[1] Cutting down the size of content. Made nsIJSScriptObject inherit from nsIScriptObjectOwner
[2] Cutting down the size of content. Made nsITextContent inherit from nsIContent.
[3] Cutting down the size of content. Moved implementation of nsIDOMReceiver to nsListenerManager. This is not true aggregation since it isn't transitive, but it's OK for now. It will be necessary for nsListenerManager to have a reference to its content in the future anyway, so the transitivity could be done.
dom/public/nsDOMPropEnums.h,v - bug 12559
dom/public/nsIJSScriptObject.h,v - [1]
dom/public/html/MANIFEST,v - bug 12559
dom/public/html/Makefile.in,v - bug 12559
dom/public/html/makefile.win,v - bug 12559
dom/public/html/nsIDOMHTMLInputElement.h,v - bug 17544
dom/public/idl/html/HTMLAnchorElement.idl,v - bug 12559
dom/public/idl/html/HTMLAreaElement.idl,v - bug 12559
dom/public/idl/html/HTMLInputElement.idl,v - bug 17544
dom/src/base/nsGlobalWindow.cpp,v - bug 30700
dom/src/base/nsGlobalWindow.h,v - [1]
dom/src/base/nsLocation.cpp,v - [1]
dom/src/html/nsJSHTMLAnchorElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLAreaElement.cpp,v - bug 12559
dom/src/html/nsJSHTMLInputElement.cpp,v - bug 17544
layout/base/public/nsIDocument.h,v - bug 27953
layout/base/public/nsITextContent.h,v - [2]
layout/base/src/nsCommentNode.cpp,v - [2]
layout/base/src/nsDocument.cpp,v - bug 27953
layout/base/src/nsDocument.h,v - bug 27953
layout/base/src/nsDocumentViewer.cpp,v - bug 27953
layout/base/src/nsGenericDOMDataNode.cpp,v - [3]
layout/base/src/nsGenericDOMDataNode.h,v - [3]
layout/base/src/nsGenericElement.cpp,v - [3]
layout/base/src/nsGenericElement.h,v - [3]
layout/base/src/nsNameSpaceManager.cpp,v - bug 7834
layout/base/src/nsStyleContext.cpp,v - outline property shouldn't reflow
layout/base/src/nsTextNode.cpp,v - [2]
layout/events/src/nsEventListenerManager.cpp,v - [3]
layout/events/src/nsEventListenerManager.h,v - [3]
layout/html/base/src/nsGfxScrollFrame.cpp,v - nsString->nsAutoString
layout/html/content/src/nsAttributeContent.cpp,v - [2]
layout/html/content/src/nsHTMLAnchorElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAppletElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBaseFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLBodyElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLButtonElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDirectoryElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLDivElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLEmbedElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFieldSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFontElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFormElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLFrameSetElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHRElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHeadingElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLHtmlElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIFrameElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLImageElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInputElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLInsElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLIsIndexElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLIElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLabelElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLayerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLegendElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLLinkElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMapElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMenuElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLMetaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLModElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLObjectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLOptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParagraphElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLParamElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLPreElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLQuoteElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLScriptElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSelectElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpacerElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLSpanElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLStyleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCaptionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableCellElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableColGroupElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableRowElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTableSectionElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTextAreaElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLTitleElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLUListElement.cpp,v - [1][3]
layout/html/content/src/nsHTMLWBRElement.cpp,v - [1][3]
layout/html/document/src/nsHTMLDocument.cpp,v - bug 27953
layout/html/document/src/nsHTMLDocument.h,v - bug 27953
layout/xml/content/src/nsXMLCDATASection.cpp,v - [1][2]
layout/xml/content/src/nsXMLDocumentType.cpp,v - [1][2]
layout/xml/content/src/nsXMLElement.h,v - [1][2]
layout/xml/content/src/nsXMLEntity.cpp,v - [1][2]
layout/xml/content/src/nsXMLNotation.cpp,v - [1][2]
layout/xml/content/src/nsXMLProcessingInstruction.cpp,v - [1][2]
layout/xul/base/src/nsBoxFrame.cpp,v - nsString->nsAutoString
layout/xul/base/src/nsSliderFrame.cpp,v - nsString->nsAutoString
netwerk/protocol/http/src/nsHTTPRequest.cpp,v - nsString->nsAutoString
rdf/content/src/nsXULDocument.cpp,v - bug 27953
rdf/content/src/nsXULDocument.h,v - bug 27953
rdf/content/src/nsXULElement.h,v - [1]
xpcom/base/IIDS.h,v - bug 12559
2000-03-17 16:27:00 +03:00
|
|
|
nsAutoString value;
|
2001-08-17 12:14:14 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, atom, value))
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
|
|
|
PRInt32 error;
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
// convert it to an integer
|
|
|
|
defaultValue = value.ToInteger(&error);
|
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
return defaultValue;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
2004-09-13 06:10:29 +04:00
|
|
|
|
2005-01-28 01:52:53 +03:00
|
|
|
nsPresState*
|
2004-09-13 06:10:29 +04:00
|
|
|
nsGfxScrollFrameInner::SaveState()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScrollbarMediator> mediator;
|
|
|
|
nsIFrame* first = GetScrolledFrame();
|
|
|
|
mediator = do_QueryInterface(first);
|
|
|
|
if (mediator) {
|
|
|
|
// Child manages its own scrolling. Bail.
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScrollableView* scrollingView = GetScrollableView();
|
|
|
|
PRInt32 x,y;
|
|
|
|
scrollingView->GetScrollPosition(x,y);
|
|
|
|
// Don't save scroll position if we are at (0,0)
|
|
|
|
if (!x && !y) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* child = nsnull;
|
|
|
|
scrollingView->GetScrolledView(child);
|
|
|
|
if (!child) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect childRect = child->GetBounds();
|
2005-01-28 01:52:53 +03:00
|
|
|
nsAutoPtr<nsPresState> state;
|
|
|
|
nsresult rv = NS_NewPresState(getter_Transfers(state));
|
2004-09-13 06:10:29 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCOMPtr<nsISupportsPRInt32> xoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
|
2004-09-13 06:10:29 +04:00
|
|
|
if (xoffset) {
|
|
|
|
rv = xoffset->SetData(x);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), xoffset);
|
|
|
|
}
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCOMPtr<nsISupportsPRInt32> yoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
|
2004-09-13 06:10:29 +04:00
|
|
|
if (yoffset) {
|
|
|
|
rv = yoffset->SetData(y);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), yoffset);
|
|
|
|
}
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCOMPtr<nsISupportsPRInt32> width = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
|
2004-09-13 06:10:29 +04:00
|
|
|
if (width) {
|
|
|
|
rv = width->SetData(childRect.width);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("width"), width);
|
|
|
|
}
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsCOMPtr<nsISupportsPRInt32> height = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
|
2004-09-13 06:10:29 +04:00
|
|
|
if (height) {
|
|
|
|
rv = height->SetData(childRect.height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("height"), height);
|
|
|
|
}
|
2005-01-28 01:52:53 +03:00
|
|
|
return state.forget();
|
2004-09-13 06:10:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-28 01:52:53 +03:00
|
|
|
nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
|
2004-09-13 06:10:29 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupportsPRInt32> xoffset;
|
|
|
|
nsCOMPtr<nsISupportsPRInt32> yoffset;
|
|
|
|
nsCOMPtr<nsISupportsPRInt32> width;
|
|
|
|
nsCOMPtr<nsISupportsPRInt32> height;
|
|
|
|
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), getter_AddRefs(xoffset));
|
|
|
|
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), getter_AddRefs(yoffset));
|
|
|
|
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("width"), getter_AddRefs(width));
|
|
|
|
aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("height"), getter_AddRefs(height));
|
|
|
|
|
|
|
|
if (xoffset && yoffset) {
|
|
|
|
PRInt32 x,y,w,h;
|
|
|
|
nsresult rv = xoffset->GetData(&x);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = yoffset->GetData(&y);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = width->GetData(&w);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = height->GetData(&h);
|
|
|
|
|
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
mRestoreRect.SetRect(-1, -1, -1, -1);
|
|
|
|
|
|
|
|
// don't do it now, store it later and do it in layout.
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRestoreRect.SetRect(x, y, w, h);
|
2004-09-22 01:41:01 +04:00
|
|
|
mDidHistoryRestore = PR_TRUE;
|
2004-09-13 06:10:29 +04:00
|
|
|
nsIScrollableView* scrollingView = GetScrollableView();
|
|
|
|
if (scrollingView) {
|
|
|
|
scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
|
2004-09-22 01:41:01 +04:00
|
|
|
} else {
|
|
|
|
mLastPos = nsPoint(0, 0);
|
2004-09-13 06:10:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|