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>
|
2006-12-20 04:17:00 +03:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
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 ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* rendering object to wrap rendering objects that should be scrollable */
|
|
|
|
|
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"
|
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 "nsGfxScrollFrame.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-08-20 02:16:23 +04:00
|
|
|
#include "nsINameSpaceManager.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"
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsPresState.h"
|
2006-03-03 06:34:48 +03:00
|
|
|
#include "nsIGlobalHistory3.h"
|
2005-08-25 04:10:37 +04:00
|
|
|
#include "nsDocShellCID.h"
|
2008-02-19 21:47:34 +03:00
|
|
|
#include "nsIHTMLDocument.h"
|
2006-03-07 20:08:51 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
2007-02-18 20:34:09 +03:00
|
|
|
#include "nsContentUtils.h"
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2004-09-01 18:58:34 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2006-03-26 04:48:03 +04:00
|
|
|
#include "nsBidiUtils.h"
|
2005-08-22 03:37:13 +04:00
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
//----------nsHTMLScrollFrame-------------------------------------------
|
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsHTMLScrollFrame(aPresShell, aContext, aIsRoot);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
: nsHTMLContainerFrame(aContext),
|
2006-03-15 19:55:19 +03:00
|
|
|
mInner(this, aIsRoot, PR_FALSE)
|
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
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2007-02-18 20:34:09 +03:00
|
|
|
return mInner.CreateAnonymousContent(aElements);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::Destroy()
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2007-02-18 20:34:09 +03:00
|
|
|
mInner.Destroy();
|
2006-04-10 04:16:29 +04:00
|
|
|
nsHTMLContainerFrame::Destroy();
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-04-04 01:00:41 +04:00
|
|
|
nsHTMLScrollFrame::
|
2006-04-10 04:16:29 +04:00
|
|
|
SetInitialChildList(nsIAtom* aListName,
|
2005-08-25 04:10:37 +04:00
|
|
|
nsIFrame* aChildList)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2006-04-10 04:16:29 +04:00
|
|
|
nsresult rv = nsHTMLContainerFrame::SetInitialChildList(aListName, 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");
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
2005-04-29 01:57:22 +04:00
|
|
|
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");
|
2007-11-19 01:24:21 +03:00
|
|
|
mFrames.DestroyFrame(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
|
|
|
}
|
|
|
|
|
2006-12-20 06:52:34 +03:00
|
|
|
nsSplittableType
|
|
|
|
nsHTMLScrollFrame::GetSplittableType() const
|
2006-08-24 09:22:16 +04:00
|
|
|
{
|
2006-12-20 06:52:34 +03:00
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
2006-08-24 09:22:16 +04:00
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsHTMLScrollFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLScrollFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::scrollFrame;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
2008-07-14 02:21:11 +04:00
|
|
|
void
|
|
|
|
nsHTMLScrollFrame::InvalidateInternal(const nsRect& aDamageRect,
|
|
|
|
nscoord aX, nscoord aY, nsIFrame* aForChild,
|
2008-09-18 13:47:21 +04:00
|
|
|
PRUint32 aFlags)
|
2008-07-14 02:21:11 +04:00
|
|
|
{
|
2008-09-18 13:47:21 +04:00
|
|
|
if (aForChild == mInner.mScrolledFrame && !(aFlags & INVALIDATE_NOTIFY_ONLY)) {
|
2008-07-14 02:21:11 +04:00
|
|
|
// restrict aDamageRect to the scrollable view's bounds
|
2008-09-18 13:47:21 +04:00
|
|
|
nsRect damage = aDamageRect + nsPoint(aX, aY);
|
2008-07-14 02:21:11 +04:00
|
|
|
nsRect r;
|
2008-09-18 13:47:21 +04:00
|
|
|
if (r.IntersectRect(damage, mInner.mScrollableView->View()->GetBounds())) {
|
|
|
|
nsHTMLContainerFrame::InvalidateInternal(r, 0, 0, aForChild, aFlags);
|
|
|
|
}
|
|
|
|
if (mInner.mIsRoot && r != damage) {
|
|
|
|
// Make sure we notify our prescontext about invalidations outside
|
|
|
|
// viewport clipping.
|
|
|
|
// This is important for things that are snapshotting the viewport,
|
|
|
|
// possibly outside the scrolled bounds.
|
|
|
|
// We don't need to propagate this any further up, though. Anyone who
|
|
|
|
// cares about scrolled-out-of-view invalidates had better be listening
|
|
|
|
// to our window directly.
|
|
|
|
PresContext()->NotifyInvalidation(damage,
|
|
|
|
(aFlags & INVALIDATE_CROSS_DOC) != 0);
|
2008-07-14 02:21:11 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
nsHTMLContainerFrame::InvalidateInternal(aDamageRect, aX, aY, aForChild, aFlags);
|
2008-07-14 02:21:11 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
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;
|
2005-05-03 02:49:44 +04:00
|
|
|
nsMargin mComputedBorder;
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2007-12-05 06:05:57 +03:00
|
|
|
// === Filled in by ReflowScrolledFrame ===
|
|
|
|
PRPackedBool mReflowedContentsWithHScrollbar;
|
|
|
|
PRPackedBool mReflowedContentsWithVScrollbar;
|
|
|
|
|
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;
|
|
|
|
// Whether we decided to show the horizontal scrollbar
|
|
|
|
PRPackedBool mShowHScrollbar;
|
|
|
|
// Whether we decided to show the vertical scrollbar
|
|
|
|
PRPackedBool mShowVScrollbar;
|
|
|
|
|
|
|
|
ScrollReflowState(nsIScrollableFrame* aFrame,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
const nsHTMLReflowState& aState) :
|
2005-04-29 01:57:22 +04:00
|
|
|
mReflowState(aState),
|
2008-04-10 08:39:41 +04:00
|
|
|
// mBoxState is just used for scrollbars so we don't need to
|
|
|
|
// worry about the reflow depth here
|
|
|
|
mBoxState(aState.frame->PresContext(), aState.rendContext, 0),
|
2005-04-29 01:57:22 +04:00
|
|
|
mStyles(aFrame->GetScrollbarStyles()) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb Can this go away?
|
2005-04-29 01:57:22 +04:00
|
|
|
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.
|
2007-01-26 03:05:12 +03:00
|
|
|
nscoord contentWidth = aState->mReflowState.ComputedWidth();
|
2005-05-03 02:49:44 +04:00
|
|
|
if (contentWidth == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
contentWidth = aDesiredInsideBorderSize.width -
|
|
|
|
aState->mReflowState.mComputedPadding.LeftRight();
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2007-08-02 22:08:05 +04:00
|
|
|
nscoord contentHeight = aState->mReflowState.ComputedHeight();
|
2005-05-03 02:49:44 +04:00
|
|
|
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
|
2005-05-09 02:33:40 +04:00
|
|
|
GetScrollbarMetrics(nsBoxLayoutState& aState, nsIBox* aBox, nsSize* aMin,
|
|
|
|
nsSize* aPref, PRBool aVertical)
|
2005-04-29 01:57:22 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ASSERTION(aState.GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
|
|
|
|
2005-05-09 02:33:40 +04:00
|
|
|
if (aMin) {
|
2007-01-08 05:57:59 +03:00
|
|
|
*aMin = aBox->GetMinSize(aState);
|
2005-05-09 02:33:40 +04:00
|
|
|
nsBox::AddMargin(aBox, *aMin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPref) {
|
2007-01-08 05:57:59 +03:00
|
|
|
*aPref = aBox->GetPrefSize(aState);
|
2005-05-09 02:33:40 +04:00
|
|
|
nsBox::AddMargin(aBox, *aPref);
|
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,
|
2007-12-05 06:05:57 +03:00
|
|
|
nsHTMLReflowMetrics* aKidMetrics,
|
|
|
|
PRBool aAssumeHScroll, PRBool aAssumeVScroll,
|
|
|
|
PRBool aForce, nsresult* aResult)
|
2005-04-29 01:57:22 +04:00
|
|
|
{
|
2007-12-05 06:05:57 +03:00
|
|
|
*aResult = NS_OK;
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if ((aState->mStyles.mVertical == NS_STYLE_OVERFLOW_HIDDEN && aAssumeVScroll) ||
|
|
|
|
(aState->mStyles.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN && aAssumeHScroll)) {
|
|
|
|
NS_ASSERTION(!aForce, "Shouldn't be forcing a hidden scrollbar to show!");
|
|
|
|
return PR_FALSE;
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2007-12-05 06:05:57 +03:00
|
|
|
|
|
|
|
if (aAssumeVScroll != aState->mReflowedContentsWithVScrollbar ||
|
2008-02-23 13:15:59 +03:00
|
|
|
(aAssumeHScroll != aState->mReflowedContentsWithHScrollbar &&
|
|
|
|
ScrolledContentDependsOnHeight(aState))) {
|
2007-12-05 06:05:57 +03:00
|
|
|
nsresult rv = ReflowScrolledFrame(aState, aAssumeHScroll, aAssumeVScroll,
|
|
|
|
aKidMetrics, PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aResult = rv;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize vScrollbarMinSize(0, 0);
|
2005-05-09 02:33:40 +04:00
|
|
|
nsSize vScrollbarPrefSize(0, 0);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mVScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mVScrollbarBox,
|
2005-05-09 02:33:40 +04:00
|
|
|
&vScrollbarMinSize,
|
|
|
|
aAssumeVScroll ? &vScrollbarPrefSize : nsnull, PR_TRUE);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-05-09 02:33:40 +04:00
|
|
|
nscoord vScrollbarDesiredWidth = aAssumeVScroll ? vScrollbarPrefSize.width : 0;
|
2008-02-25 04:21:08 +03:00
|
|
|
nscoord vScrollbarMinHeight = aAssumeVScroll ? vScrollbarMinSize.height : 0;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize hScrollbarMinSize(0, 0);
|
2005-05-09 02:33:40 +04:00
|
|
|
nsSize hScrollbarPrefSize(0, 0);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (mInner.mHScrollbarBox) {
|
|
|
|
GetScrollbarMetrics(aState->mBoxState, mInner.mHScrollbarBox,
|
2005-05-09 02:33:40 +04:00
|
|
|
&hScrollbarMinSize,
|
|
|
|
aAssumeHScroll ? &hScrollbarPrefSize : nsnull, PR_FALSE);
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2005-05-09 02:33:40 +04:00
|
|
|
nscoord hScrollbarDesiredHeight = aAssumeHScroll ? hScrollbarPrefSize.height : 0;
|
2008-02-25 04:21:08 +03:00
|
|
|
nscoord hScrollbarMinWidth = aAssumeHScroll ? hScrollbarMinSize.width : 0;
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
// First, compute our inside-border size and scrollport size
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb Can we depend more on ComputeSize here?
|
2005-04-29 01:57:22 +04:00
|
|
|
nsSize desiredInsideBorderSize;
|
2005-05-09 02:33:40 +04:00
|
|
|
desiredInsideBorderSize.width = vScrollbarDesiredWidth +
|
2008-02-25 04:21:08 +03:00
|
|
|
PR_MAX(aKidMetrics->width, hScrollbarMinWidth);
|
2005-05-09 02:33:40 +04:00
|
|
|
desiredInsideBorderSize.height = hScrollbarDesiredHeight +
|
2008-02-25 04:21:08 +03:00
|
|
|
PR_MAX(aKidMetrics->height, vScrollbarMinHeight);
|
2005-04-29 01:57:22 +04:00
|
|
|
aState->mInsideBorderSize =
|
2005-05-03 02:49:44 +04:00
|
|
|
ComputeInsideBorderSize(aState, desiredInsideBorderSize);
|
2005-05-09 02:33:40 +04:00
|
|
|
nsSize scrollPortSize = nsSize(PR_MAX(0, aState->mInsideBorderSize.width - vScrollbarDesiredWidth),
|
|
|
|
PR_MAX(0, aState->mInsideBorderSize.height - hScrollbarDesiredHeight));
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
if (!aForce) {
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect(scrollPortSize);
|
2008-04-24 12:14:06 +04:00
|
|
|
nscoord oneDevPixel = aState->mBoxState.PresContext()->DevPixelsToAppUnits(1);
|
2006-03-15 19:55:19 +03:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
// If the style is HIDDEN then we already know that aAssumeHScroll is PR_FALSE
|
|
|
|
if (aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
2006-03-15 19:55:19 +03:00
|
|
|
PRBool wantHScrollbar =
|
|
|
|
aState->mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 12:14:06 +04:00
|
|
|
scrolledRect.XMost() >= scrollPortSize.width + oneDevPixel ||
|
|
|
|
scrolledRect.x <= -oneDevPixel;
|
2005-04-29 01:57:22 +04:00
|
|
|
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) {
|
2006-03-15 19:55:19 +03:00
|
|
|
PRBool wantVScrollbar =
|
|
|
|
aState->mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL ||
|
2008-04-24 12:14:06 +04:00
|
|
|
scrolledRect.YMost() >= scrollPortSize.height + oneDevPixel ||
|
|
|
|
scrolledRect.y <= -oneDevPixel;
|
2005-04-29 01:57:22 +04:00
|
|
|
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-05-09 02:33:40 +04:00
|
|
|
nscoord vScrollbarActualWidth = aState->mInsideBorderSize.width - scrollPortSize.width;
|
|
|
|
|
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);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2008-02-23 13:15:59 +03:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::ScrolledContentDependsOnHeight(ScrollReflowState* aState)
|
|
|
|
{
|
|
|
|
// Return true if ReflowScrolledFrame is going to do something different
|
|
|
|
// based on the presence of a horizontal scrollbar.
|
|
|
|
return (mInner.mScrolledFrame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT) ||
|
|
|
|
aState->mReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE ||
|
|
|
|
aState->mReflowState.mComputedMinHeight > 0 ||
|
|
|
|
aState->mReflowState.mComputedMaxHeight != NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsresult
|
2007-12-05 06:05:57 +03:00
|
|
|
nsHTMLScrollFrame::ReflowScrolledFrame(ScrollReflowState* aState,
|
2005-10-18 09:00:24 +04:00
|
|
|
PRBool aAssumeHScroll,
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool aAssumeVScroll,
|
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
|
|
|
PRBool aFirstPass)
|
|
|
|
{
|
|
|
|
// these could be NS_UNCONSTRAINEDSIZE ... PR_MIN arithmetic should
|
|
|
|
// be OK
|
2007-12-05 06:05:57 +03:00
|
|
|
nscoord paddingLR = aState->mReflowState.mComputedPadding.LeftRight();
|
|
|
|
|
|
|
|
nscoord availWidth = aState->mReflowState.ComputedWidth() + paddingLR;
|
|
|
|
|
|
|
|
nscoord computedHeight = aState->mReflowState.ComputedHeight();
|
|
|
|
nscoord computedMinHeight = aState->mReflowState.mComputedMinHeight;
|
|
|
|
nscoord computedMaxHeight = aState->mReflowState.mComputedMaxHeight;
|
2007-12-07 03:10:31 +03:00
|
|
|
if (!ShouldPropagateComputedHeightToScrolledContent()) {
|
|
|
|
computedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
computedMinHeight = 0;
|
|
|
|
computedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
2007-12-05 06:05:57 +03:00
|
|
|
if (aAssumeHScroll) {
|
|
|
|
nsSize hScrollbarPrefSize =
|
|
|
|
mInner.mHScrollbarBox->GetPrefSize(const_cast<nsBoxLayoutState&>(aState->mBoxState));
|
|
|
|
if (computedHeight != NS_UNCONSTRAINEDSIZE)
|
|
|
|
computedHeight = PR_MAX(0, computedHeight - hScrollbarPrefSize.height);
|
|
|
|
computedMinHeight = PR_MAX(0, computedMinHeight - hScrollbarPrefSize.height);
|
|
|
|
if (computedMaxHeight != NS_UNCONSTRAINEDSIZE)
|
|
|
|
computedMaxHeight = PR_MAX(0, computedMaxHeight - hScrollbarPrefSize.height);
|
|
|
|
}
|
2007-12-07 03:10:31 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (aAssumeVScroll) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize vScrollbarPrefSize =
|
2007-12-05 06:05:57 +03:00
|
|
|
mInner.mVScrollbarBox->GetPrefSize(const_cast<nsBoxLayoutState&>(aState->mBoxState));
|
2005-05-09 02:33:40 +04:00
|
|
|
availWidth = PR_MAX(0, availWidth - vScrollbarPrefSize.width);
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2007-02-20 21:54:16 +03:00
|
|
|
// We're forcing the padding on our scrolled frame, so let it know what that
|
|
|
|
// padding is.
|
|
|
|
mInner.mScrolledFrame->
|
|
|
|
SetProperty(nsGkAtoms::usedPaddingProperty,
|
2007-12-05 06:05:57 +03:00
|
|
|
new nsMargin(aState->mReflowState.mComputedPadding),
|
2007-02-20 21:54:16 +03:00
|
|
|
nsCSSOffsetState::DestroyMarginFunc);
|
|
|
|
|
2007-09-18 06:54:48 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
2006-12-12 18:18:40 +03:00
|
|
|
// Pass PR_FALSE for aInit so we can pass in the correct padding
|
2007-12-05 06:05:57 +03:00
|
|
|
nsHTMLReflowState kidReflowState(presContext, aState->mReflowState,
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.mScrolledFrame,
|
2006-12-12 18:18:40 +03:00
|
|
|
nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
|
|
|
|
-1, -1, PR_FALSE);
|
|
|
|
kidReflowState.Init(presContext, -1, -1, nsnull,
|
2007-12-05 06:05:57 +03:00
|
|
|
&aState->mReflowState.mComputedPadding);
|
2005-10-18 09:00:24 +04:00
|
|
|
kidReflowState.mFlags.mAssumingHScrollbar = aAssumeHScroll;
|
|
|
|
kidReflowState.mFlags.mAssumingVScrollbar = aAssumeVScroll;
|
2007-12-05 06:05:57 +03:00
|
|
|
kidReflowState.SetComputedHeight(computedHeight);
|
|
|
|
kidReflowState.mComputedMinHeight = computedMinHeight;
|
|
|
|
kidReflowState.mComputedMaxHeight = computedMaxHeight;
|
2005-05-03 02:49:44 +04:00
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
nsReflowStatus status;
|
2006-12-12 18:18:40 +03:00
|
|
|
nsresult rv = ReflowChild(mInner.mScrolledFrame, presContext, *aMetrics,
|
2005-04-29 01:57:22 +04:00
|
|
|
kidReflowState, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW, status);
|
2005-05-09 02:17:03 +04:00
|
|
|
// Don't resize or position the view because we're going to resize
|
|
|
|
// it to the correct size anyway in PlaceScrollArea. Allowing it to
|
|
|
|
// resize here would size it to the natural height of the frame,
|
|
|
|
// which will usually be different from the scrollport height;
|
|
|
|
// invalidating the difference will cause unnecessary repainting.
|
2006-12-12 18:18:40 +03:00
|
|
|
FinishReflowChild(mInner.mScrolledFrame, presContext,
|
2005-04-29 01:57:22 +04:00
|
|
|
&kidReflowState, *aMetrics, 0, 0,
|
2005-05-09 02:17:03 +04:00
|
|
|
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW | NS_FRAME_NO_SIZE_VIEW);
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
// XXX Some frames (e.g., nsObjectFrame, nsFrameFrame, nsTextFrame) don't bother
|
|
|
|
// setting their mOverflowArea. This is wrong because every frame should
|
|
|
|
// always set mOverflowArea. In fact nsObjectFrame and nsFrameFrame don't
|
|
|
|
// support the 'outline' property because of this. Rather than fix the world
|
2005-06-16 06:57:23 +04:00
|
|
|
// right now, just fix up the overflow area if necessary. Note that we don't
|
|
|
|
// check NS_FRAME_OUTSIDE_CHILDREN because it could be set even though the
|
|
|
|
// overflow area doesn't include the frame bounds.
|
|
|
|
aMetrics->mOverflowArea.UnionRect(aMetrics->mOverflowArea,
|
|
|
|
nsRect(0, 0, aMetrics->width, aMetrics->height));
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2007-12-05 06:05:57 +03:00
|
|
|
aState->mReflowedContentsWithHScrollbar = aAssumeHScroll;
|
|
|
|
aState->mReflowedContentsWithVScrollbar = aAssumeVScroll;
|
|
|
|
|
2004-06-18 06:08:19 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-02-23 13:15:59 +03:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::GuessHScrollbarNeeded(const ScrollReflowState& aState)
|
|
|
|
{
|
|
|
|
if (aState.mStyles.mHorizontal != NS_STYLE_OVERFLOW_AUTO)
|
|
|
|
// no guessing required
|
|
|
|
return aState.mStyles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL;
|
|
|
|
|
|
|
|
return mInner.mHasHorizontalScrollbar;
|
|
|
|
}
|
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::GuessVScrollbarNeeded(const ScrollReflowState& aState)
|
2004-06-18 06:08:19 +04:00
|
|
|
{
|
2005-08-25 04:10:37 +04:00
|
|
|
if (aState.mStyles.mVertical != NS_STYLE_OVERFLOW_AUTO)
|
|
|
|
// no guessing required
|
|
|
|
return aState.mStyles.mVertical == NS_STYLE_OVERFLOW_SCROLL;
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
// If we've had at least one non-initial reflow, then just assume
|
|
|
|
// the state of the vertical scrollbar will be what we determined
|
|
|
|
// last time.
|
|
|
|
if (mInner.mHadNonInitialReflow) {
|
|
|
|
return mInner.mHasVerticalScrollbar;
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
// If this is the initial reflow, guess PR_FALSE because usually
|
|
|
|
// we have very little content by then.
|
2007-04-26 06:29:21 +04:00
|
|
|
if (InInitialReflow())
|
2005-08-25 04:10:37 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (mInner.mIsRoot) {
|
|
|
|
// For viewports, try getting a hint from global history
|
|
|
|
// as to whether we had a vertical scrollbar last time.
|
|
|
|
PRBool hint;
|
|
|
|
nsresult rv = mInner.GetVScrollbarHintFromGlobalHistory(&hint);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return hint;
|
|
|
|
// No hint. Assume that there will be a scrollbar; it seems to me
|
|
|
|
// that 'most pages' do have a scrollbar, and anyway, it's cheaper
|
|
|
|
// to do an extra reflow for the pages that *don't* need a
|
|
|
|
// scrollbar (because on average they will have less content).
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
// For non-viewports, just guess that we don't need a scrollbar.
|
|
|
|
// XXX I wonder if statistically this is the right idea; I'm
|
|
|
|
// basically guessing that there are a lot of overflow:auto DIVs
|
|
|
|
// that get their intrinsic size and don't overflow
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-26 06:29:21 +04:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::InInitialReflow() const
|
|
|
|
{
|
|
|
|
// We're in an initial reflow if NS_FRAME_FIRST_REFLOW is set, unless we're a
|
2007-05-01 21:15:08 +04:00
|
|
|
// root scrollframe. In that case we want to skip this clause altogether.
|
|
|
|
// The guess here is that there are lots of overflow:auto divs out there that
|
|
|
|
// end up auto-sizing so they don't overflow, and that the root basically
|
|
|
|
// always needs a scrollbar if it did last time we loaded this page (good
|
|
|
|
// assumption, because our initial reflow is no longer synchronous).
|
|
|
|
return !mInner.mIsRoot && (GetStateBits() & NS_FRAME_FIRST_REFLOW);
|
2007-04-26 06:29:21 +04:00
|
|
|
}
|
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
|
|
|
const nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mFlags);
|
2008-02-23 13:15:59 +03:00
|
|
|
nsresult rv = ReflowScrolledFrame(aState, GuessHScrollbarNeeded(*aState),
|
2007-12-05 06:05:57 +03:00
|
|
|
GuessVScrollbarNeeded(*aState), &kidDesiredSize, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
// There's an important special case ... if the child appears to fit
|
|
|
|
// in the inside-border rect (but overflows the scrollport), we
|
|
|
|
// should try laying it out without a vertical scrollbar. It will
|
|
|
|
// usually fit because making the available-width wider will not
|
|
|
|
// normally make the child taller. (The only situation I can think
|
|
|
|
// of is when you have a line containing %-width inline replaced
|
|
|
|
// elements whose percentages sum to more than 100%, so increasing
|
|
|
|
// the available width makes the line break where it was fitting
|
|
|
|
// before.) If we don't treat this case specially, then we will
|
|
|
|
// decide that showing scrollbars is OK because the content
|
|
|
|
// overflows when we're showing scrollbars and we won't try to
|
|
|
|
// remove the vertical scrollbar.
|
|
|
|
|
|
|
|
// Detecting when we enter this special case is important for when
|
|
|
|
// people design layouts that exactly fit the container "most of the
|
|
|
|
// time".
|
2007-12-05 06:05:57 +03:00
|
|
|
|
|
|
|
// XXX Is this check really sufficient to catch all the incremental cases
|
|
|
|
// where the ideal case doesn't have a scrollbar?
|
|
|
|
if ((aState->mReflowedContentsWithHScrollbar || aState->mReflowedContentsWithVScrollbar) &&
|
2005-04-29 01:57:22 +04:00
|
|
|
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));
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect(insideBorderSize);
|
|
|
|
if (nsRect(nsPoint(0, 0), insideBorderSize).Contains(scrolledRect)) {
|
2007-12-05 06:05:57 +03:00
|
|
|
// Let's pretend we had no scrollbars coming in here
|
|
|
|
rv = ReflowScrolledFrame(aState, PR_FALSE, PR_FALSE,
|
2005-05-03 02:49:44 +04:00
|
|
|
&kidDesiredSize, PR_FALSE);
|
2007-12-05 06:05:57 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2007-12-05 06:05:57 +03:00
|
|
|
// Try vertical scrollbar settings that leave the vertical scrollbar unchanged.
|
|
|
|
// Do this first because changing the vertical scrollbar setting is expensive,
|
|
|
|
// forcing a reflow always.
|
|
|
|
|
2008-02-23 13:15:59 +03:00
|
|
|
// Try leaving the horizontal scrollbar unchanged first. This will be more
|
|
|
|
// efficient.
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, aState->mReflowedContentsWithHScrollbar,
|
2007-12-05 06:05:57 +03:00
|
|
|
aState->mReflowedContentsWithVScrollbar, PR_FALSE, &rv))
|
2007-12-01 14:49:13 +03:00
|
|
|
return NS_OK;
|
2008-02-23 13:15:59 +03:00
|
|
|
if (TryLayout(aState, &kidDesiredSize, !aState->mReflowedContentsWithHScrollbar,
|
2007-12-05 06:05:57 +03:00
|
|
|
aState->mReflowedContentsWithVScrollbar, PR_FALSE, &rv))
|
2007-12-01 14:49:13 +03:00
|
|
|
return NS_OK;
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2007-12-05 06:05:57 +03:00
|
|
|
// OK, now try toggling the vertical scrollbar. The performance advantage
|
2008-02-23 13:15:59 +03:00
|
|
|
// of trying the status-quo horizontal scrollbar state
|
2007-12-05 06:05:57 +03:00
|
|
|
// does not exist here (we'll have to reflow due to the vertical scrollbar
|
|
|
|
// change), so always try no horizontal scrollbar first.
|
|
|
|
PRBool newVScrollbarState = !aState->mReflowedContentsWithVScrollbar;
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, PR_FALSE, newVScrollbarState, PR_FALSE, &rv))
|
|
|
|
return NS_OK;
|
|
|
|
if (TryLayout(aState, &kidDesiredSize, PR_TRUE, newVScrollbarState, PR_FALSE, &rv))
|
|
|
|
return NS_OK;
|
2007-12-01 13:38:09 +03:00
|
|
|
|
2007-12-12 05:28:50 +03:00
|
|
|
// OK, we're out of ideas. Try again enabling whatever scrollbars we can
|
|
|
|
// enable and force the layout to stick even if it's inconsistent.
|
|
|
|
// This just happens sometimes.
|
|
|
|
TryLayout(aState, &kidDesiredSize,
|
|
|
|
aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
PR_TRUE, &rv);
|
2007-12-05 06:05:57 +03:00
|
|
|
return rv;
|
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
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
nsIFrame *scrolledFrame = mInner.mScrolledFrame;
|
|
|
|
nsIView *scrolledView = scrolledFrame->GetView();
|
2006-03-09 21:46:14 +03:00
|
|
|
// Set the x,y of the scrolled frame to the correct value: the displacement
|
|
|
|
// from its origin to the origin of this frame
|
2006-03-15 19:55:19 +03:00
|
|
|
scrolledFrame->SetPosition(scrolledView->GetOffsetTo(GetView()));
|
|
|
|
|
|
|
|
nsRect scrolledArea;
|
2008-02-27 12:46:22 +03:00
|
|
|
// Preserve the width or height of empty rects
|
|
|
|
scrolledArea.UnionRectIncludeEmpty(mInner.GetScrolledRect(aState.mScrollPortRect.Size()),
|
|
|
|
nsRect(nsPoint(0,0), aState.mScrollPortRect.Size()));
|
2006-03-15 19:55:19 +03:00
|
|
|
|
2005-12-19 04:07:41 +03:00
|
|
|
// Store the new overflow area. Note that this changes where an outline
|
|
|
|
// of the scrolled frame would be painted, but scrolled frames can't have
|
|
|
|
// outlines (the outline would go on this scrollframe instead).
|
2006-03-27 02:12:54 +04:00
|
|
|
// Using FinishAndStoreOverflow is needed so NS_FRAME_OUTSIDE_CHILDREN
|
|
|
|
// gets set correctly. It also messes with the overflow rect in the
|
|
|
|
// -moz-hidden-unscrollable case, but scrolled frames can't have
|
|
|
|
// 'overflow' either.
|
2006-03-30 08:26:36 +04:00
|
|
|
// This needs to happen before SyncFrameViewAfterReflow so
|
|
|
|
// NS_FRAME_OUTSIDE_CHILDREN is set.
|
2006-03-27 02:12:54 +04:00
|
|
|
scrolledFrame->FinishAndStoreOverflow(&scrolledArea,
|
|
|
|
scrolledFrame->GetSize());
|
2005-12-19 04:07:41 +03:00
|
|
|
|
2006-03-30 08:26:36 +04:00
|
|
|
// Note that making the view *exactly* the size of the scrolled area
|
|
|
|
// is critical, since the view scrolling code uses the size of the
|
|
|
|
// scrolled view to clamp scroll requests.
|
2007-03-31 01:11:41 +04:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(scrolledFrame->PresContext(),
|
2006-03-30 08:26:36 +04:00
|
|
|
scrolledFrame,
|
|
|
|
scrolledView,
|
|
|
|
&scrolledArea,
|
|
|
|
NS_FRAME_NO_MOVE_VIEW);
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
2008-02-28 23:37:06 +03:00
|
|
|
nscoord
|
|
|
|
nsHTMLScrollFrame::GetIntrinsicVScrollbarWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles ss = GetScrollbarStyles();
|
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_SCROLL || !mInner.mVScrollbarBox)
|
|
|
|
return 0;
|
|
|
|
|
2008-04-10 08:39:41 +04:00
|
|
|
// Don't need to worry about reflow depth here since it's
|
|
|
|
// just for scrollbars
|
|
|
|
nsBoxLayoutState bls(PresContext(), aRenderingContext, 0);
|
2008-02-28 23:37:06 +03:00
|
|
|
nsSize vScrollbarPrefSize(0, 0);
|
|
|
|
GetScrollbarMetrics(bls, mInner.mVScrollbarBox,
|
|
|
|
nsnull, &vScrollbarPrefSize, PR_TRUE);
|
|
|
|
return vScrollbarPrefSize.width;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ nscoord
|
|
|
|
nsHTMLScrollFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
2007-12-05 01:03:16 +03:00
|
|
|
nscoord result = mInner.mScrolledFrame->GetMinWidth(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2008-02-28 23:37:06 +03:00
|
|
|
return result + GetIntrinsicVScrollbarWidth(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsHTMLScrollFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
2008-02-28 23:37:06 +03:00
|
|
|
nscoord result = mInner.mScrolledFrame->GetPrefWidth(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
2008-02-28 23:37:06 +03:00
|
|
|
return NSCoordSaturatingAdd(result, GetIntrinsicVScrollbarWidth(aRenderingContext));
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLScrollFrame::GetPadding(nsMargin& aMargin)
|
|
|
|
{
|
|
|
|
// Our padding hangs out on the inside of the scrollframe, but XUL doesn't
|
|
|
|
// reaize that. If we're stuck inside a XUL box, we need to claim no
|
|
|
|
// padding.
|
|
|
|
// @see also nsXULScrollFrame::GetPadding.
|
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-03 03:08:19 +03:00
|
|
|
PRBool
|
|
|
|
nsHTMLScrollFrame::IsCollapsed(nsBoxLayoutState& aBoxLayoutState)
|
2007-01-22 07:27:31 +03:00
|
|
|
{
|
|
|
|
// We're never collapsed in the box sense.
|
2007-02-03 03:08:19 +03:00
|
|
|
return PR_FALSE;
|
2007-01-22 07:27:31 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLScrollFrame");
|
2004-06-18 06:08:19 +04:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
ScrollReflowState state(this, aReflowState);
|
2005-04-29 01:57:22 +04:00
|
|
|
// 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 -----------------
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
PRBool reflowContents = PR_TRUE; // XXX Ignored
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool reflowHScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowVScrollbar = PR_TRUE;
|
|
|
|
PRBool reflowScrollCorner = PR_TRUE;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (!aReflowState.ShouldReflowAllKids()) {
|
|
|
|
#define NEEDS_REFLOW(frame_) \
|
2007-05-06 23:16:51 +04:00
|
|
|
((frame_) && NS_SUBTREE_DIRTY(frame_))
|
2005-04-29 01:57:22 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
reflowContents = NEEDS_REFLOW(mInner.mScrolledFrame);
|
|
|
|
reflowHScrollbar = NEEDS_REFLOW(mInner.mHScrollbarBox);
|
|
|
|
reflowVScrollbar = NEEDS_REFLOW(mInner.mVScrollbarBox);
|
|
|
|
reflowScrollCorner = NEEDS_REFLOW(mInner.mScrollCornerBox);
|
|
|
|
|
|
|
|
#undef NEEDS_REFLOW
|
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;
|
|
|
|
|
|
|
|
PlaceScrollArea(state);
|
2006-04-07 23:51:46 +04:00
|
|
|
mInner.ScrollToRestoredPosition();
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2007-01-19 21:01:10 +03:00
|
|
|
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 (mInner.mSkippedScrollbarLayout ||
|
|
|
|
reflowHScrollbar || reflowVScrollbar || reflowScrollCorner ||
|
|
|
|
(GetStateBits() & NS_FRAME_IS_DIRTY) ||
|
|
|
|
didHaveHScrollbar != state.mShowHScrollbar ||
|
|
|
|
didHaveVScrollbar != state.mShowVScrollbar ||
|
|
|
|
oldScrollAreaBounds != newScrollAreaBounds ||
|
|
|
|
oldScrolledAreaBounds != newScrolledAreaBounds) {
|
|
|
|
if (!mInner.mSupppressScrollbarUpdate) {
|
|
|
|
mInner.mSkippedScrollbarLayout = PR_FALSE;
|
2005-07-26 03:23:53 +04:00
|
|
|
mInner.SetScrollbarVisibility(mInner.mHScrollbarBox, state.mShowHScrollbar);
|
|
|
|
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, state.mShowVScrollbar);
|
|
|
|
// place and reflow scrollbars
|
|
|
|
nsRect insideBorderArea =
|
|
|
|
nsRect(nsPoint(state.mComputedBorder.left, state.mComputedBorder.top),
|
|
|
|
state.mInsideBorderSize);
|
|
|
|
mInner.LayoutScrollbars(state.mBoxState, insideBorderArea,
|
|
|
|
oldScrollAreaBounds, state.mScrollPortRect);
|
2007-01-19 21:01:10 +03:00
|
|
|
} else {
|
|
|
|
mInner.mSkippedScrollbarLayout = PR_TRUE;
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2005-04-29 01:57:22 +04:00
|
|
|
|
|
|
|
aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2007-04-26 06:29:21 +04:00
|
|
|
if (!InInitialReflow() && !mInner.mHadNonInitialReflow) {
|
2005-08-25 04:10:37 +04:00
|
|
|
mInner.mHadNonInitialReflow = PR_TRUE;
|
|
|
|
if (mInner.mIsRoot) {
|
|
|
|
// For viewports, record whether we needed a vertical scrollbar
|
|
|
|
// after the first non-initial reflow.
|
|
|
|
mInner.SaveVScrollbarStateToGlobalHistory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2004-06-18 06:08:19 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2007-10-08 12:42:43 +04:00
|
|
|
mInner.PostOverflowEvent();
|
2004-06-18 06:08:19 +04:00
|
|
|
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) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return accService->CreateHTMLGenericAccessible(static_cast<nsIFrame*>(this), aAccessible);
|
2004-09-01 18:58:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2006-03-15 19:55:19 +03:00
|
|
|
mInner.CurPosAttributeChanged(aChild);
|
2004-06-18 06:08:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-------------------------------------------
|
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsXULScrollFrame(aPresShell, aContext, aIsRoot);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsXULScrollFrame::nsXULScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, PRBool aIsRoot)
|
|
|
|
: nsBoxFrame(aShell, aContext, aIsRoot),
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
mInner(this, aIsRoot, PR_TRUE)
|
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) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ASSERTION(aState && aState->GetRenderingContext(),
|
|
|
|
"Must have rendering context in layout state for size "
|
|
|
|
"computations");
|
|
|
|
|
2004-01-09 22:21:20 +03:00
|
|
|
nsMargin result(0, 0, 0, 0);
|
2003-04-22 05:33:14 +04:00
|
|
|
|
2005-10-18 09:00:24 +04:00
|
|
|
if (mVScrollbarBox) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size = mVScrollbarBox->GetPrefSize(*aState);
|
2005-10-18 09:00:24 +04:00
|
|
|
nsBox::AddMargin(mVScrollbarBox, size);
|
2005-04-29 01:57:22 +04:00
|
|
|
if (IsScrollbarOnRight())
|
2004-01-09 22:21:20 +03:00
|
|
|
result.left = size.width;
|
|
|
|
else
|
|
|
|
result.right = size.width;
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2005-10-18 09:00:24 +04:00
|
|
|
if (mHScrollbarBox) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size = mHScrollbarBox->GetPrefSize(*aState);
|
2005-10-18 09:00:24 +04:00
|
|
|
nsBox::AddMargin(mHScrollbarBox, 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
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult
|
|
|
|
nsXULScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2007-02-18 20:34:09 +03:00
|
|
|
return mInner.CreateAnonymousContent(aElements);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
|
|
|
nsXULScrollFrame::Destroy()
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2007-02-18 20:34:09 +03:00
|
|
|
mInner.Destroy();
|
2006-04-10 04:16:29 +04:00
|
|
|
nsBoxFrame::Destroy();
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-10 04:16:29 +04:00
|
|
|
nsXULScrollFrame::SetInitialChildList(nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2006-04-10 04:16:29 +04:00
|
|
|
nsresult rv = nsBoxFrame::SetInitialChildList(aListName, aChildList);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-12-20 06:52:34 +03:00
|
|
|
nsSplittableType
|
|
|
|
nsXULScrollFrame::GetSplittableType() const
|
2006-08-24 09:22:16 +04:00
|
|
|
{
|
2006-12-20 06:52:34 +03:00
|
|
|
return NS_FRAME_NOT_SPLITTABLE;
|
2006-08-24 09:22:16 +04:00
|
|
|
}
|
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
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::scrollFrame;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2008-07-14 02:21:11 +04:00
|
|
|
void
|
|
|
|
nsXULScrollFrame::InvalidateInternal(const nsRect& aDamageRect,
|
|
|
|
nscoord aX, nscoord aY, nsIFrame* aForChild,
|
2008-09-18 13:47:21 +04:00
|
|
|
PRUint32 aFlags)
|
2008-07-14 02:21:11 +04:00
|
|
|
{
|
|
|
|
if (aForChild == mInner.mScrolledFrame) {
|
|
|
|
// restrict aDamageRect to the scrollable view's bounds
|
|
|
|
nsRect r;
|
|
|
|
if (r.IntersectRect(aDamageRect + nsPoint(aX, aY),
|
|
|
|
mInner.mScrollableView->View()->GetBounds())) {
|
2008-09-18 13:47:21 +04:00
|
|
|
nsBoxFrame::InvalidateInternal(r, 0, 0, aForChild, aFlags);
|
2008-07-14 02:21:11 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-18 13:47:21 +04:00
|
|
|
nsBoxFrame::InvalidateInternal(aDamageRect, aX, aY, aForChild, aFlags);
|
2008-07-14 02:21:11 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
nscoord
|
|
|
|
nsXULScrollFrame::GetBoxAscent(nsBoxLayoutState& aState)
|
2000-05-15 08:12:31 +04:00
|
|
|
{
|
2005-04-04 01:00:41 +04:00
|
|
|
if (!mInner.mScrolledFrame)
|
2007-01-31 19:02:42 +03:00
|
|
|
return 0;
|
2005-04-04 01:00:41 +04:00
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
nscoord ascent = mInner.mScrolledFrame->GetBoxAscent(aState);
|
2000-05-15 08:12:31 +04:00
|
|
|
nsMargin m(0,0,0,0);
|
|
|
|
GetBorderAndPadding(m);
|
2007-01-31 19:02:42 +03:00
|
|
|
ascent += m.top;
|
2000-05-15 08:12:31 +04:00
|
|
|
GetMargin(m);
|
2007-01-31 19:02:42 +03:00
|
|
|
ascent += m.top;
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
return ascent;
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetPrefSize(nsBoxLayoutState& aState)
|
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
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize pref = mInner.mScrolledFrame->GetPrefSize(aState);
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
nsGfxScrollFrameInner::ScrollbarStyles styles = GetScrollbarStyles();
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
// scrolled frames don't have their own margins
|
|
|
|
|
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) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mInner.mVScrollbarBox, vSize);
|
|
|
|
pref.width += vSize.width;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetPrefSize(aState);
|
|
|
|
nsBox::AddMargin(mInner.mHScrollbarBox, hSize);
|
|
|
|
pref.height += hSize.height;
|
2002-10-01 05:23:47 +04:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
AddBorderAndPadding(pref);
|
|
|
|
nsIBox::AddCSSPrefSize(aState, this, pref);
|
|
|
|
return pref;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetMinSize(nsBoxLayoutState& aState)
|
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
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize min = 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) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetMinSize(aState);
|
2004-05-05 06:32:27 +04:00
|
|
|
AddMargin(mInner.mVScrollbarBox, vSize);
|
2007-01-08 05:57:59 +03:00
|
|
|
min.width += vSize.width;
|
|
|
|
if (min.height < vSize.height)
|
|
|
|
min.height = vSize.height;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetMinSize(aState);
|
2004-05-05 06:32:27 +04:00
|
|
|
AddMargin(mInner.mHScrollbarBox, hSize);
|
2007-01-08 05:57:59 +03:00
|
|
|
min.height += hSize.height;
|
|
|
|
if (min.width < hSize.width)
|
|
|
|
min.width = hSize.width;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
AddBorderAndPadding(min);
|
|
|
|
nsIBox::AddCSSMinSize(aState, this, min);
|
|
|
|
return min;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
|
|
|
nsXULScrollFrame::GetMaxSize(nsBoxLayoutState& aState)
|
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
|
|
|
|
2008-02-27 04:51:57 +03:00
|
|
|
nsSize maxSize(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
1999-11-18 22:40:52 +03:00
|
|
|
|
2008-02-27 04:51:57 +03:00
|
|
|
AddBorderAndPadding(maxSize);
|
|
|
|
nsIBox::AddCSSMaxSize(aState, this, maxSize);
|
|
|
|
return maxSize;
|
1999-11-18 22:40:52 +03:00
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#if 0 // XXXldb I don't think this is even needed
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsXULScrollFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
2000-04-05 04:19:00 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsStyleUnit widthUnit = GetStylePosition()->mWidth.GetUnit();
|
|
|
|
if (widthUnit == eStyleUnit_Percent || widthUnit == eStyleUnit_Auto) {
|
|
|
|
nsMargin border = aReflowState.mComputedBorderPadding;
|
|
|
|
aDesiredSize.mMaxElementWidth = border.right + border.left;
|
|
|
|
mMaxElementWidth = aDesiredSize.mMaxElementWidth;
|
|
|
|
} else {
|
|
|
|
NS_NOTYETIMPLEMENTED("Use the info from the scrolled frame");
|
|
|
|
#if 0
|
|
|
|
// if not set then use the cached size. If set then set it.
|
|
|
|
if (aDesiredSize.mMaxElementWidth == -1)
|
|
|
|
aDesiredSize.mMaxElementWidth = mMaxElementWidth;
|
|
|
|
else
|
2005-04-29 01:57:22 +04:00
|
|
|
mMaxElementWidth = aDesiredSize.mMaxElementWidth;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#endif
|
2000-05-02 06:28:41 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return 0;
|
2000-04-05 04:19:00 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#endif
|
2000-04-05 04:19:00 +04:00
|
|
|
|
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
|
|
|
{
|
2006-03-15 19:55:19 +03:00
|
|
|
mInner.CurPosAttributeChanged(aChild);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 ----------------------
|
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
nsGfxScrollFrameInner::nsGfxScrollFrameInner(nsContainerFrame* aOuter,
|
|
|
|
PRBool aIsRoot,
|
|
|
|
PRBool aIsXUL)
|
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),
|
2004-09-13 06:10:29 +04:00
|
|
|
mRestoreRect(-1, -1, -1, -1),
|
|
|
|
mLastPos(-1, -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-07-26 03:23:53 +04:00
|
|
|
mIsRoot(aIsRoot),
|
2006-03-15 19:55:19 +03:00
|
|
|
mIsXUL(aIsXUL),
|
2005-08-25 04:10:37 +04:00
|
|
|
mSupppressScrollbarUpdate(PR_FALSE),
|
2007-01-19 21:01:10 +03:00
|
|
|
mSkippedScrollbarLayout(PR_FALSE),
|
2005-08-25 04:10:37 +04:00
|
|
|
mDidLoadHistoryVScrollbarHint(PR_FALSE),
|
|
|
|
mHistoryVScrollbarHint(PR_FALSE),
|
2005-08-31 04:57:27 +04:00
|
|
|
mHadNonInitialReflow(PR_FALSE),
|
|
|
|
mHorizontalOverflow(PR_FALSE),
|
2007-03-05 04:39:53 +03:00
|
|
|
mVerticalOverflow(PR_FALSE),
|
2007-12-21 02:49:46 +03:00
|
|
|
mPostedReflowCallback(PR_FALSE),
|
|
|
|
mMayHaveDirtyFixedChildren(PR_FALSE)
|
2004-05-05 06:32:27 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-22 03:37:13 +04:00
|
|
|
nsGfxScrollFrameInner::~nsGfxScrollFrameInner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsGfxScrollFrameInner::AddRef(void)
|
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
return 2;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsresult rv = mOuter->DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aBuilder->GetIgnoreScrollFrame() == mOuter) {
|
|
|
|
// Don't clip the scrolled child, and don't paint scrollbars/scrollcorner.
|
|
|
|
// The scrolled frame shouldn't have its own background/border, so we
|
|
|
|
// can just pass aLists directly. We do need to replace aDirtyRect with
|
|
|
|
// the scrolled area though, since callers may have restricted aDirtyRect
|
|
|
|
// to our bounds.
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect newDirty = GetScrolledRect(GetScrollPortSize()) +
|
2006-01-26 05:29:17 +03:00
|
|
|
aBuilder->ToReferenceFrame(mScrolledFrame);
|
|
|
|
return mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame, newDirty, aLists);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overflow clipping can never clip frames outside our subtree, so there
|
|
|
|
// is no need to worry about whether we are a moving frame that might clip
|
|
|
|
// non-moving frames.
|
|
|
|
nsRect frameClip = mScrollableView->View()->GetBounds();
|
|
|
|
nsRect dirtyRect;
|
|
|
|
// Not all our descendants will be clipped by overflow clipping, but all
|
|
|
|
// the ones that aren't clipped will be out of flow frames that have already
|
|
|
|
// had dirty rects saved for them by their parent frames calling
|
|
|
|
// MarkOutOfFlowChildrenForDisplayList, so it's safe to restrict our
|
|
|
|
// dirty rect here.
|
|
|
|
dirtyRect.IntersectRect(aDirtyRect, frameClip);
|
|
|
|
|
|
|
|
nsDisplayListCollection set;
|
|
|
|
rv = mOuter->BuildDisplayListForChild(aBuilder, mScrolledFrame, dirtyRect, set);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsRect clip = frameClip + aBuilder->ToReferenceFrame(mOuter);
|
|
|
|
// mScrolledFrame may have given us a background, e.g., the scrolled canvas
|
2006-02-05 23:52:13 +03:00
|
|
|
// frame below the viewport. If so, we want it to be clipped. We also want
|
|
|
|
// to end up on our BorderBackground list.
|
2006-01-26 05:29:17 +03:00
|
|
|
// If we are the viewport scrollframe, then clip all our descendants (to ensure
|
|
|
|
// that fixed-pos elements get clipped by us).
|
|
|
|
rv = mOuter->OverflowClip(aBuilder, set, aLists, clip, PR_TRUE, mIsRoot);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now display the scrollbars and scrollcorner
|
|
|
|
nsIFrame* kid = mOuter->GetFirstChild(nsnull);
|
|
|
|
// Put each child's background directly onto the content list
|
|
|
|
nsDisplayListSet scrollbarSet(aLists, aLists.Content());
|
|
|
|
while (kid) {
|
2008-03-13 12:14:16 +03:00
|
|
|
if (kid != mScrolledFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
rv = mOuter->BuildDisplayListForChild(aBuilder, kid, aDirtyRect, scrollbarSet,
|
|
|
|
nsIFrame::DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-04 01:00:41 +04:00
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::NeedsClipWidget() const
|
|
|
|
{
|
|
|
|
// Scrollports contained in form controls (e.g., listboxes) don't get
|
2008-09-13 13:42:11 +04:00
|
|
|
// widgets. Also, transformed elements don't need clip widgets since they
|
|
|
|
// result in graphical glitches.
|
2005-04-08 03:54:28 +04:00
|
|
|
for (nsIFrame* parentFrame = mOuter; parentFrame;
|
2008-09-13 13:42:11 +04:00
|
|
|
parentFrame = nsLayoutUtils::GetCrossDocParentFrame(parentFrame)) {
|
|
|
|
|
|
|
|
/* See if we have a transform... we should have no widget if that's the case. */
|
|
|
|
if (parentFrame->GetStyleDisplay()->HasTransform())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
/* If we're a form element, we don't need a widget. */
|
2005-04-04 01:00:41 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2006-04-11 05:48:48 +04:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
2006-04-12 05:55:25 +04:00
|
|
|
if (!presContext->IsDynamic() &&
|
|
|
|
!(mIsRoot && presContext->HasPaginatedScrolling())) {
|
2006-04-11 05:48:48 +04:00
|
|
|
return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
|
2005-04-04 02:40:25 +04:00
|
|
|
if (mIsRoot) {
|
2004-09-05 04:04:04 +04:00
|
|
|
result = presContext->GetViewportOverflowOverride();
|
2004-09-05 03:03:04 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = presContext->GetContainer();
|
2007-02-24 03:23:42 +03:00
|
|
|
nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
|
|
|
|
if (scrollable) {
|
2004-09-29 05:46:55 +04:00
|
|
|
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
|
2005-11-21 01:05:24 +03:00
|
|
|
* saved position. if the user has not moved the scroll position manually
|
|
|
|
* we keep scrolling down until we get to our original position. keep in
|
2004-09-13 06:10:29 +04:00
|
|
|
* 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);
|
|
|
|
|
2005-09-18 18:50:26 +04:00
|
|
|
x = (int)mRestoreRect.x;
|
|
|
|
y = (int)mRestoreRect.y;
|
2004-09-13 06:10:29 +04:00
|
|
|
|
|
|
|
// 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.
|
2006-04-07 23:51:46 +04:00
|
|
|
if (y != cy || x != cx) {
|
2004-09-13 06:10:29 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::FireScrollPortEvent()
|
2006-12-15 03:23:39 +03:00
|
|
|
{
|
2007-01-28 01:50:18 +03:00
|
|
|
mAsyncScrollPortEvent.Forget();
|
2007-10-08 12:42:43 +04:00
|
|
|
|
|
|
|
// Keep this in sync with PostOverflowEvent().
|
2007-01-28 01:50:18 +03:00
|
|
|
nsSize scrollportSize = GetScrollPortSize();
|
|
|
|
nsSize childSize = GetScrolledRect(scrollportSize).Size();
|
|
|
|
|
|
|
|
PRBool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
PRBool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
|
|
|
|
|
|
|
PRBool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
PRBool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
2006-12-15 03:23:39 +03:00
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
if (!vertChanged && !horizChanged) {
|
2006-12-15 03:23:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
// If both either overflowed or underflowed then we dispatch only one
|
|
|
|
// DOM event.
|
|
|
|
PRBool both = vertChanged && horizChanged &&
|
|
|
|
newVerticalOverflow == newHorizontalOverflow;
|
|
|
|
nsScrollPortEvent::orientType orient;
|
|
|
|
if (both) {
|
|
|
|
orient = nsScrollPortEvent::both;
|
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
mVerticalOverflow = newVerticalOverflow;
|
|
|
|
}
|
|
|
|
else if (vertChanged) {
|
|
|
|
orient = nsScrollPortEvent::vertical;
|
|
|
|
mVerticalOverflow = newVerticalOverflow;
|
|
|
|
if (horizChanged) {
|
|
|
|
// We need to dispatch a separate horizontal DOM event. Do that the next
|
|
|
|
// time around since dispatching the vertical DOM event might destroy
|
|
|
|
// the frame.
|
|
|
|
PostOverflowEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
orient = nsScrollPortEvent::horizontal;
|
|
|
|
mHorizontalOverflow = newHorizontalOverflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScrollPortEvent event(PR_TRUE,
|
|
|
|
(orient == nsScrollPortEvent::horizontal ?
|
|
|
|
mHorizontalOverflow : mVerticalOverflow) ?
|
|
|
|
NS_SCROLLPORT_OVERFLOW : NS_SCROLLPORT_UNDERFLOW,
|
|
|
|
nsnull);
|
|
|
|
event.orient = orient;
|
|
|
|
return nsEventDispatcher::Dispatch(mOuter->GetContent(),
|
2007-03-31 01:11:41 +04:00
|
|
|
mOuter->PresContext(), &event);
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
|
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;
|
2006-12-26 20:47:52 +03:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::orient, value);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (!value.IsEmpty()) {
|
2005-04-04 01:00:41 +04:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
2004-05-05 06:32:27 +04:00
|
|
|
{
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
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
|
2006-04-11 05:48:48 +04:00
|
|
|
if (!presContext->IsDynamic()) {
|
2004-05-05 06:32:27 +04:00
|
|
|
// allow scrollbars if this is the child of the viewport, because
|
|
|
|
// we must be the scrollbars for the print preview window
|
2006-04-11 05:48:48 +04:00
|
|
|
if (!(mIsRoot && presContext->HasPaginatedScrolling())) {
|
2004-09-04 07:17:18 +04:00
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_OK;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!canHaveHorizontal && !canHaveVertical) {
|
2004-09-04 03:57:42 +04:00
|
|
|
// Nothing to do.
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
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.
|
2007-05-23 00:34:00 +04:00
|
|
|
nsITextControlFrame* textFrame = nsnull;
|
|
|
|
CallQueryInterface(parent, &textFrame);
|
2004-09-04 07:17:18 +04:00
|
|
|
if (textFrame) {
|
|
|
|
// Make sure we are not a text area.
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> textAreaElement(do_QueryInterface(parent->GetContent()));
|
|
|
|
if (!textAreaElement) {
|
|
|
|
mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_OK;
|
2004-09-04 07:17:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2004-09-04 03:57:42 +04:00
|
|
|
nsNodeInfoManager *nodeInfoManager =
|
2006-05-19 14:26:44 +04:00
|
|
|
presContext->Document()->NodeInfoManager();
|
2004-05-05 06:32:27 +04:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-13 02:32:18 +04:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbar, nsnull,
|
|
|
|
kNameSpaceID_XUL);
|
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
|
2004-06-25 16:26:02 +04:00
|
|
|
|
2004-05-05 06:32:27 +04:00
|
|
|
if (canHaveHorizontal) {
|
2007-02-18 20:34:09 +03:00
|
|
|
rv = NS_NewElement(getter_AddRefs(mHScrollbarContent),
|
2008-04-18 02:30:51 +04:00
|
|
|
kNameSpaceID_XUL, nodeInfo, PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
NS_LITERAL_STRING("horizontal"), PR_FALSE);
|
|
|
|
if (!aElements.AppendElement(mHScrollbarContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (canHaveVertical) {
|
2007-02-18 20:34:09 +03:00
|
|
|
rv = NS_NewElement(getter_AddRefs(mVScrollbarContent),
|
2008-04-18 02:30:51 +04:00
|
|
|
kNameSpaceID_XUL, nodeInfo, PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
NS_LITERAL_STRING("vertical"), PR_FALSE);
|
|
|
|
if (!aElements.AppendElement(mVScrollbarContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (canHaveHorizontal && canHaveVertical) {
|
2008-09-13 02:32:18 +04:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollcorner, nsnull,
|
|
|
|
kNameSpaceID_XUL);
|
2007-02-18 20:34:09 +03:00
|
|
|
rv = NS_NewElement(getter_AddRefs(mScrollCornerContent),
|
2008-04-18 02:30:51 +04:00
|
|
|
kNameSpaceID_XUL, nodeInfo, PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!aElements.AppendElement(mScrollCornerContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-05-05 06:32:27 +04:00
|
|
|
}
|
2007-02-18 20:34:09 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::Destroy()
|
|
|
|
{
|
|
|
|
// Unbind any content created in CreateAnonymousContent from the tree
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mHScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mVScrollbarContent);
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mScrollCornerContent);
|
2007-03-05 04:39:53 +03:00
|
|
|
|
|
|
|
mScrollEvent.Revoke();
|
|
|
|
mAsyncScrollPortEvent.Revoke();
|
|
|
|
if (mPostedReflowCallback) {
|
2007-03-31 01:11:41 +04:00
|
|
|
mOuter->PresContext()->PresShell()->CancelReflowCallback(this);
|
2007-03-05 04:39:53 +03:00
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
}
|
|
|
|
nsIScrollableView *view = GetScrollableView();
|
|
|
|
NS_ASSERTION(view, "unexpected null pointer");
|
|
|
|
if (view)
|
|
|
|
view->RemoveScrollPositionListener(this);
|
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
|
|
|
/**
|
2005-08-22 08:16:38 +04:00
|
|
|
* Called when we want to update the scrollbar position, either because scrolling happened
|
|
|
|
* or the user moved the scrollbar position and we need to undo that (e.g., when the user
|
|
|
|
* clicks to scroll and we're using smooth scrolling, so we need to put the thumb back
|
|
|
|
* to its initial position for the start of the smooth sequence).
|
2003-04-05 15:41:19 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::InternalScrollPositionDidChange(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
if (mVScrollbarBox)
|
2007-03-14 01:11:14 +03:00
|
|
|
SetCoordAttribute(mVScrollbarBox->GetContent(), nsGkAtoms::curpos,
|
2006-03-23 06:45:41 +03:00
|
|
|
aY - GetScrolledRect(GetScrollPortSize()).y);
|
2003-04-05 15:41:19 +04:00
|
|
|
|
|
|
|
if (mHScrollbarBox)
|
2007-03-14 01:11:14 +03:00
|
|
|
SetCoordAttribute(mHScrollbarBox->GetContent(), nsGkAtoms::curpos,
|
2006-03-23 06:45:41 +03:00
|
|
|
aX - GetScrolledRect(GetScrollPortSize()).x);
|
2003-04-05 15:41:19 +04:00
|
|
|
}
|
|
|
|
|
2008-09-04 01:35:52 +04:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ViewPositionDidChange(nsIScrollableView* aScrollable)
|
|
|
|
{
|
|
|
|
// Update frame position to match view offsets
|
|
|
|
nsPoint childOffset = mScrolledFrame->GetView()->GetOffsetTo(mOuter->GetView());
|
|
|
|
mScrolledFrame->SetPosition(childOffset);
|
|
|
|
}
|
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
/**
|
2005-08-22 08:16:38 +04:00
|
|
|
* Called whenever actual scrolling happens for any reason.
|
1999-10-12 04:16:06 +04:00
|
|
|
*/
|
|
|
|
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;
|
2008-09-18 13:47:21 +04:00
|
|
|
|
2005-08-22 03:37:13 +04:00
|
|
|
PostScrollEvent();
|
2008-09-18 13:47:21 +04:00
|
|
|
|
|
|
|
// Notify that the display has changed
|
|
|
|
mOuter->InvalidateWithFlags(nsRect(nsPoint(0, 0), mOuter->GetSize()),
|
|
|
|
nsIFrame::INVALIDATE_NOTIFY_ONLY);
|
2003-04-05 15:41:19 +04:00
|
|
|
return NS_OK;
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2003-05-22 05:46:13 +04:00
|
|
|
NS_ASSERTION(aContent, "aContent must not be null");
|
2006-03-15 19:55:19 +03:00
|
|
|
NS_ASSERTION((mHScrollbarBox && mHScrollbarBox->GetContent() == aContent) ||
|
|
|
|
(mVScrollbarBox && mVScrollbarBox->GetContent() == aContent),
|
|
|
|
"unexpected child");
|
2003-05-22 05:46:13 +04:00
|
|
|
|
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.
|
2005-08-22 08:16:38 +04:00
|
|
|
//
|
|
|
|
// Cases 1) and 3) do not indicate that actual scrolling has happened. Only
|
|
|
|
// case 2) indicates actual scrolling. Therefore we do not fire onscroll
|
|
|
|
// here, but in ScrollPositionDidChange.
|
2003-04-05 15:41:19 +04:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect scrolledRect = GetScrolledRect(GetScrollPortSize());
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
nscoord x = GetCoordAttribute(mHScrollbarBox, nsGkAtoms::curpos,
|
2006-03-23 06:45:41 +03:00
|
|
|
-scrolledRect.x) +
|
2006-03-15 19:55:19 +03:00
|
|
|
scrolledRect.x;
|
2006-12-26 20:47:52 +03:00
|
|
|
nscoord y = GetCoordAttribute(mVScrollbarBox, nsGkAtoms::curpos,
|
2006-03-23 06:45:41 +03:00
|
|
|
-scrolledRect.y) +
|
2006-03-15 19:55:19 +03:00
|
|
|
scrolledRect.y;
|
|
|
|
|
|
|
|
// 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 == curPosX && y == curPosY)
|
|
|
|
return;
|
1999-10-12 04:16:06 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
PRBool isSmooth = aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::smooth);
|
2002-09-26 01:29:33 +04:00
|
|
|
|
2006-03-15 19:55:19 +03: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.
|
|
|
|
|
|
|
|
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;
|
2004-09-06 06:44:43 +04:00
|
|
|
}
|
2007-03-31 01:11:41 +04:00
|
|
|
ScrollbarChanged(mOuter->PresContext(), x, y, isSmooth ? NS_VMREFRESH_SMOOTHSCROLL : 0);
|
2004-09-06 06:44:43 +04:00
|
|
|
}
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2005-08-22 03:37:13 +04:00
|
|
|
/* ============= Scroll events ========== */
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxScrollFrameInner::ScrollEvent::Run()
|
2005-08-22 03:37:13 +04:00
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
if (mInner)
|
|
|
|
mInner->FireScrollEvent();
|
|
|
|
return NS_OK;
|
2005-08-22 03:37:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::FireScrollEvent()
|
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
mScrollEvent.Forget();
|
2005-10-07 05:28:27 +04:00
|
|
|
|
2005-08-22 03:37:13 +04:00
|
|
|
nsScrollbarEvent event(PR_TRUE, NS_SCROLL_EVENT, nsnull);
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-10-07 05:28:27 +04:00
|
|
|
nsIContent* content = mOuter->GetContent();
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* prescontext = mOuter->PresContext();
|
2005-10-07 05:28:27 +04:00
|
|
|
// Fire viewport scroll events at the document (where they
|
|
|
|
// will bubble to the window)
|
|
|
|
if (mIsRoot) {
|
|
|
|
nsIDocument* doc = content->GetCurrentDoc();
|
|
|
|
if (doc) {
|
2006-03-07 20:08:51 +03:00
|
|
|
nsEventDispatcher::Dispatch(doc, prescontext, &event, nsnull, &status);
|
2005-10-07 05:28:27 +04:00
|
|
|
}
|
|
|
|
} else {
|
2006-03-07 20:08:51 +03:00
|
|
|
// scroll events fired at elements don't bubble (although scroll events
|
|
|
|
// fired at documents do, to the window)
|
|
|
|
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
|
|
|
|
nsEventDispatcher::Dispatch(content, prescontext, &event, nsnull, &status);
|
2005-10-07 05:28:27 +04:00
|
|
|
}
|
2005-08-22 03:37:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::PostScrollEvent()
|
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
if (mScrollEvent.IsPending())
|
2005-08-22 03:37:13 +04:00
|
|
|
return;
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsRefPtr<ScrollEvent> ev = new ScrollEvent(this);
|
|
|
|
if (NS_FAILED(NS_DispatchToCurrentThread(ev))) {
|
|
|
|
NS_WARNING("failed to dispatch ScrollEvent");
|
|
|
|
} else {
|
|
|
|
mScrollEvent = ev;
|
2005-08-22 03:37:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxScrollFrameInner::AsyncScrollPortEvent::Run()
|
|
|
|
{
|
2007-04-13 18:07:40 +04:00
|
|
|
if (mInner) {
|
|
|
|
mInner->mOuter->PresContext()->GetPresShell()->
|
2007-08-22 06:57:06 +04:00
|
|
|
FlushPendingNotifications(Flush_Layout);
|
2007-04-13 18:07:40 +04:00
|
|
|
}
|
2007-01-28 01:50:18 +03:00
|
|
|
return mInner ? mInner->FireScrollPortEvent() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool
|
|
|
|
nsXULScrollFrame::AddHorizontalScrollbar(nsBoxLayoutState& aState,
|
|
|
|
nsRect& aScrollAreaSize, PRBool aOnTop)
|
|
|
|
{
|
|
|
|
if (!mInner.mHScrollbarBox)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
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;
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize hSize = mInner.mHScrollbarBox->GetPrefSize(aState);
|
2005-04-29 01:57:22 +04:00
|
|
|
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;
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize vSize = mInner.mVScrollbarBox->GetPrefSize(aState);
|
2005-04-29 01:57:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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();
|
2006-03-09 21:46:14 +03:00
|
|
|
nsPoint childOffset =
|
|
|
|
mInner.mScrolledFrame->GetView()->GetOffsetTo(GetView());
|
|
|
|
nsRect childRect = nsRect(childOffset, aRect.Size());
|
2005-04-04 01:00:41 +04:00
|
|
|
|
|
|
|
PRInt32 flags = NS_FRAME_NO_MOVE_VIEW;
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize minSize = mInner.mScrolledFrame->GetMinSize(aState);
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2005-08-22 04:22:41 +04:00
|
|
|
if (minSize.height > childRect.height)
|
|
|
|
childRect.height = minSize.height;
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2005-08-22 04:22:41 +04:00
|
|
|
if (minSize.width > childRect.width)
|
|
|
|
childRect.width = minSize.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
|
2007-03-28 10:24:40 +04:00
|
|
|
mInner.mScrolledFrame->SetBounds(aState, childRect);
|
2007-03-31 01:11:41 +04:00
|
|
|
PresContext()->PropertyTable()->
|
2007-03-28 10:24:40 +04:00
|
|
|
DeleteProperty(mInner.mScrolledFrame, nsGkAtoms::overflowAreaProperty);
|
|
|
|
mInner.mScrolledFrame->RemoveStateBits(NS_FRAME_OUTSIDE_CHILDREN);
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aState.SetLayoutFlags(oldflags);
|
|
|
|
|
2005-08-31 04:57:27 +04:00
|
|
|
}
|
2005-04-04 01:00:41 +04:00
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
void nsGfxScrollFrameInner::PostOverflowEvent()
|
2005-08-31 04:57:27 +04:00
|
|
|
{
|
2007-01-28 01:50:18 +03:00
|
|
|
if (mAsyncScrollPortEvent.IsPending())
|
|
|
|
return;
|
2005-04-04 01:00:41 +04:00
|
|
|
|
2007-10-08 12:42:43 +04:00
|
|
|
// Keep this in sync with FireScrollPortEvent().
|
|
|
|
nsSize scrollportSize = GetScrollPortSize();
|
|
|
|
nsSize childSize = GetScrolledRect(scrollportSize).Size();
|
|
|
|
|
|
|
|
PRBool newVerticalOverflow = childSize.height > scrollportSize.height;
|
|
|
|
PRBool vertChanged = mVerticalOverflow != newVerticalOverflow;
|
|
|
|
|
|
|
|
PRBool newHorizontalOverflow = childSize.width > scrollportSize.width;
|
|
|
|
PRBool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
|
|
|
|
|
|
|
|
if (!vertChanged && !horizChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
nsRefPtr<AsyncScrollPortEvent> ev = new AsyncScrollPortEvent(this);
|
|
|
|
if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev)))
|
|
|
|
mAsyncScrollPortEvent = ev;
|
2005-04-04 01:00:41 +04:00
|
|
|
}
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
PRBool
|
2006-03-15 19:55:19 +03:00
|
|
|
nsGfxScrollFrameInner::IsLTR() const
|
2005-04-29 01:57:22 +04:00
|
|
|
{
|
|
|
|
//TODO make bidi code set these from preferences
|
2006-03-15 19:55:19 +03:00
|
|
|
|
|
|
|
nsIFrame *frame = mOuter;
|
|
|
|
// XXX This is a bit on the slow side.
|
|
|
|
if (mIsRoot) {
|
|
|
|
// If we're the root scrollframe, we need the root element's style data.
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = mOuter->PresContext();
|
2006-05-19 14:26:44 +04:00
|
|
|
nsIDocument *document = presContext->Document();
|
2006-03-15 19:55:19 +03:00
|
|
|
nsIContent *root = document->GetRootContent();
|
|
|
|
|
|
|
|
// But for HTML we want the body element.
|
2008-02-19 21:47:34 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
|
2008-02-19 21:46:21 +03:00
|
|
|
if (htmlDoc) {
|
2008-02-19 21:47:34 +03:00
|
|
|
nsIContent *bodyContent = htmlDoc->GetBodyContentExternal();
|
2006-03-15 19:55:19 +03:00
|
|
|
if (bodyContent)
|
|
|
|
root = bodyContent; // we can trust the document to hold on to it
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root) {
|
|
|
|
nsIFrame *rootsFrame =
|
|
|
|
presContext->PresShell()->GetPrimaryFrameFor(root);
|
|
|
|
if (rootsFrame)
|
|
|
|
frame = rootsFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame->GetStyleVisibility()->mDirection != NS_STYLE_DIRECTION_RTL;
|
2005-04-29 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
2006-03-26 04:48:03 +04:00
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::IsScrollbarOnRight() const
|
|
|
|
{
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = mOuter->PresContext();
|
2006-03-26 04:48:03 +04:00
|
|
|
switch (presContext->GetCachedIntPref(kPresContext_ScrollbarSide)) {
|
|
|
|
default:
|
|
|
|
case 0: // UI directionality
|
|
|
|
return presContext->GetCachedIntPref(kPresContext_BidiDirection)
|
|
|
|
== IBMBIDI_TEXTDIRECTION_LTR;
|
|
|
|
case 1: // Document / content directionality
|
|
|
|
return IsLTR();
|
|
|
|
case 2: // Always right
|
|
|
|
return PR_TRUE;
|
|
|
|
case 3: // Always left
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2006-03-15 19:55:19 +03:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// 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) {
|
2007-01-04 07:44:42 +03:00
|
|
|
// These are only good until the call to LayoutScrollArea.
|
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect(scrollAreaRect.Size());
|
|
|
|
nsSize scrolledContentSize(scrolledRect.XMost(), scrolledRect.YMost());
|
|
|
|
|
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);
|
2005-04-04 01:00:41 +04:00
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
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
|
|
|
{
|
2007-01-04 07:44:42 +03:00
|
|
|
// These are only good until the call to LayoutScrollArea.
|
|
|
|
nsRect scrolledRect = mInner.GetScrolledRect(scrollAreaRect.Size());
|
|
|
|
nsSize scrolledContentSize(scrolledRect.XMost(), scrolledRect.YMost());
|
|
|
|
|
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
|
|
|
|
2008-07-19 09:32:50 +04:00
|
|
|
// if we added a horizontal scrollbar and we did not have a vertical
|
|
|
|
// there is a chance that by adding the horizontal scrollbar we will
|
2000-03-31 11:02:06 +04:00
|
|
|
// 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);
|
2005-04-04 01:00:41 +04:00
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
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) {
|
2005-05-09 02:33:40 +04:00
|
|
|
GetScrollbarMetrics(aState, mInner.mHScrollbarBox, &hMinSize, nsnull, 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) {
|
2005-05-09 02:33:40 +04:00
|
|
|
GetScrollbarMetrics(aState, mInner.mVScrollbarBox, &vMinSize, nsnull, 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);
|
|
|
|
LayoutScrollArea(resizeState, scrollAreaRect);
|
|
|
|
}
|
|
|
|
|
2005-07-26 03:23:53 +04:00
|
|
|
if (!mInner.mSupppressScrollbarUpdate) {
|
|
|
|
mInner.LayoutScrollbars(aState, clientRect, oldScrollAreaBounds, scrollAreaRect);
|
|
|
|
}
|
2005-04-29 01:57:22 +04:00
|
|
|
mInner.ScrollToRestoredPosition();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2005-08-25 04:10:37 +04:00
|
|
|
mInner.mHadNonInitialReflow = PR_TRUE;
|
|
|
|
}
|
2007-01-28 01:50:18 +03:00
|
|
|
|
|
|
|
mInner.PostOverflowEvent();
|
2005-04-29 01:57:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-14 01:11:14 +03:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::FinishReflowForScrollbar(nsIContent* aContent,
|
|
|
|
nscoord aMinXY, nscoord aMaxXY,
|
|
|
|
nscoord aCurPosXY,
|
|
|
|
nscoord aPageIncrement,
|
|
|
|
nscoord aIncrement)
|
|
|
|
{
|
|
|
|
// Scrollbars assume zero is the minimum position, so translate for them.
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::curpos, aCurPosXY - aMinXY);
|
|
|
|
SetScrollbarEnabled(aContent, aMaxXY - aMinXY);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::maxpos, aMaxXY - aMinXY);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::pageincrement, aPageIncrement);
|
|
|
|
SetCoordAttribute(aContent, nsGkAtoms::increment, aIncrement);
|
|
|
|
}
|
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
PRBool
|
|
|
|
nsGfxScrollFrameInner::ReflowFinished()
|
2005-04-29 01:57:22 +04:00
|
|
|
{
|
2007-03-05 04:39:53 +03:00
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
|
2007-12-21 02:49:46 +03:00
|
|
|
if (mMayHaveDirtyFixedChildren) {
|
|
|
|
mMayHaveDirtyFixedChildren = PR_FALSE;
|
|
|
|
nsIFrame* parentFrame = mOuter->GetParent();
|
|
|
|
for (nsIFrame* fixedChild =
|
|
|
|
parentFrame->GetFirstChild(nsGkAtoms::fixedList);
|
|
|
|
fixedChild; fixedChild = fixedChild->GetNextSibling()) {
|
|
|
|
// force a reflow of the fixed child
|
|
|
|
mOuter->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(fixedChild, nsIPresShell::eResize,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
// Update scrollbar attributes.
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = mOuter->PresContext();
|
2007-03-05 04:39:53 +03:00
|
|
|
|
|
|
|
nsIScrollableView* scrollable = GetScrollableView();
|
|
|
|
nsRect scrollArea = scrollable->View()->GetBounds();
|
|
|
|
|
2005-04-29 01:57:22 +04:00
|
|
|
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);
|
2007-03-05 04:39:53 +03:00
|
|
|
scrollable->SetLineHeight(fontHeight);
|
2005-04-29 01:57:22 +04:00
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
nsRect scrolledContentRect = GetScrolledRect(scrollArea.Size());
|
2006-03-15 19:55:19 +03:00
|
|
|
nscoord minX = scrolledContentRect.x;
|
2007-03-05 04:39:53 +03:00
|
|
|
nscoord maxX = scrolledContentRect.XMost() - scrollArea.width;
|
2006-03-15 19:55:19 +03:00
|
|
|
nscoord minY = scrolledContentRect.y;
|
2007-03-05 04:39:53 +03:00
|
|
|
nscoord maxY = scrolledContentRect.YMost() - scrollArea.height;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
// Suppress handling of the curpos attribute changes we make here.
|
2007-03-05 04:39:53 +03:00
|
|
|
NS_ASSERTION(!mFrameInitiatedScroll, "We shouldn't be reentering here");
|
2006-03-15 19:55:19 +03:00
|
|
|
mFrameInitiatedScroll = PR_TRUE;
|
|
|
|
|
2007-03-14 01:11:14 +03:00
|
|
|
nsCOMPtr<nsIContent> vScroll =
|
|
|
|
mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull;
|
|
|
|
nsCOMPtr<nsIContent> hScroll =
|
|
|
|
mHScrollbarBox ? mHScrollbarBox->GetContent() : nsnull;
|
2007-03-05 04:39:53 +03:00
|
|
|
|
2007-03-14 01:11:14 +03:00
|
|
|
// Note, in some cases mOuter may get deleted while finishing reflow
|
|
|
|
// for scrollbars.
|
|
|
|
if (vScroll || hScroll) {
|
|
|
|
nsWeakFrame weakFrame(mOuter);
|
2006-03-15 19:55:19 +03:00
|
|
|
nscoord curPosX, curPosY;
|
|
|
|
scrollable->GetScrollPosition(curPosX, curPosY);
|
2007-03-14 01:11:14 +03:00
|
|
|
if (vScroll) {
|
2008-02-24 10:35:08 +03:00
|
|
|
// We normally use (scrollArea.height - fontHeight) for height
|
|
|
|
// of page scrolling. However, it is too small when
|
|
|
|
// fontHeight is very large. (If fontHeight is larger than
|
|
|
|
// scrollArea.height, direction of scrolling will be opposite).
|
|
|
|
// To avoid it, we use (float(scrollArea.height) * 0.8) as
|
|
|
|
// lower bound value of height of page scrolling. (bug 383267)
|
|
|
|
nscoord pageincrement = nscoord(scrollArea.height - fontHeight);
|
|
|
|
nscoord pageincrementMin = nscoord(float(scrollArea.height) * 0.8);
|
2007-03-14 01:11:14 +03:00
|
|
|
FinishReflowForScrollbar(vScroll, minY, maxY, curPosY,
|
2008-02-24 10:35:08 +03:00
|
|
|
PR_MAX(pageincrement,pageincrementMin),
|
2007-03-14 01:11:14 +03:00
|
|
|
fontHeight);
|
|
|
|
}
|
|
|
|
if (hScroll) {
|
|
|
|
FinishReflowForScrollbar(hScroll, minX, maxX, curPosX,
|
|
|
|
nscoord(float(scrollArea.width) * 0.8),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(10));
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), PR_FALSE);
|
2000-05-15 08:12:31 +04:00
|
|
|
}
|
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
mFrameInitiatedScroll = PR_FALSE;
|
2006-03-15 19:55:19 +03:00
|
|
|
// We used to rely on the curpos attribute changes above to scroll the
|
|
|
|
// view. However, for scrolling to the left of the viewport, we
|
|
|
|
// rescale the curpos attribute, which means that operations like
|
|
|
|
// resizing the window while it is scrolled all the way to the left
|
|
|
|
// hold the curpos attribute constant at 0 while still requiring
|
|
|
|
// scrolling. So we suppress the effect of the changes above with
|
|
|
|
// mFrameInitiatedScroll and call CurPosAttributeChanged here.
|
|
|
|
// (It actually even works some of the time without this, thanks to
|
|
|
|
// nsSliderFrame::AttributeChanged's handling of maxpos, but not when
|
|
|
|
// we hide the scrollbar on a large size change, such as
|
|
|
|
// maximization.)
|
2007-03-05 04:39:53 +03:00
|
|
|
if (!mHScrollbarBox && !mVScrollbarBox)
|
|
|
|
return PR_FALSE;
|
|
|
|
CurPosAttributeChanged(mVScrollbarBox ? mVScrollbarBox->GetContent()
|
|
|
|
: mHScrollbarBox->GetContent());
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-01 10:22:44 +03:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mPostedReflowCallback = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-28 10:24:40 +04:00
|
|
|
static void LayoutAndInvalidate(nsBoxLayoutState& aState,
|
|
|
|
nsIFrame* aBox, const nsRect& aRect)
|
|
|
|
{
|
|
|
|
// When a child box changes shape of position, the parent
|
|
|
|
// is responsible for invalidation; the overflow rect must be invalidated
|
|
|
|
// to make sure to catch any overflow
|
|
|
|
PRBool rectChanged = aBox->GetRect() != aRect;
|
|
|
|
if (rectChanged)
|
|
|
|
aBox->Invalidate(aBox->GetOverflowRect());
|
|
|
|
nsBoxFrame::LayoutChildAt(aState, aBox, aRect);
|
|
|
|
if (rectChanged)
|
|
|
|
aBox->Invalidate(aBox->GetOverflowRect());
|
|
|
|
}
|
|
|
|
|
2008-08-08 20:11:54 +04:00
|
|
|
static void AdjustScrollbarRect(nsIView* aView, nsPresContext* aPresContext,
|
|
|
|
nsRect& aRect, PRBool aVertical)
|
|
|
|
{
|
|
|
|
if ((aVertical ? aRect.width : aRect.height) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsPoint offset;
|
|
|
|
nsIWidget* widget = aView->GetNearestWidget(&offset);
|
|
|
|
|
|
|
|
nsIntRect widgetRect;
|
|
|
|
if (!widget->ShowsResizeIndicator(&widgetRect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRect resizerRect =
|
|
|
|
nsRect(aPresContext->DevPixelsToAppUnits(widgetRect.x) - offset.x,
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.y) - offset.y,
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.width),
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetRect.height));
|
|
|
|
|
|
|
|
if (!aRect.Intersects(resizerRect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aVertical)
|
|
|
|
aRect.height = PR_MAX(0, resizerRect.y - aRect.y);
|
|
|
|
else
|
|
|
|
aRect.width = PR_MAX(0, resizerRect.x - aRect.x);
|
|
|
|
}
|
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::LayoutScrollbars(nsBoxLayoutState& aState,
|
|
|
|
const nsRect& aContentArea,
|
|
|
|
const nsRect& aOldScrollArea,
|
|
|
|
const nsRect& aScrollArea)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mSupppressScrollbarUpdate,
|
|
|
|
"This should have been suppressed");
|
2008-03-13 12:14:16 +03:00
|
|
|
|
2008-08-08 20:11:54 +04:00
|
|
|
nsIView* view = mOuter->GetView();
|
|
|
|
nsPresContext* presContext = mScrolledFrame->PresContext();
|
2007-03-05 04:39:53 +03:00
|
|
|
if (mVScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
|
|
|
nsRect vRect(aScrollArea);
|
|
|
|
vRect.width = aContentArea.width - aScrollArea.width;
|
|
|
|
vRect.x = IsScrollbarOnRight() ? aScrollArea.XMost() : aContentArea.x;
|
|
|
|
nsMargin margin;
|
|
|
|
mVScrollbarBox->GetMargin(margin);
|
|
|
|
vRect.Deflate(margin);
|
2008-08-08 20:11:54 +04:00
|
|
|
AdjustScrollbarRect(view, presContext, vRect, PR_TRUE);
|
2007-03-28 10:24:40 +04:00
|
|
|
LayoutAndInvalidate(aState, mVScrollbarBox, vRect);
|
2007-03-05 04:39:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mHScrollbarBox) {
|
|
|
|
NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!");
|
|
|
|
nsRect hRect(aScrollArea);
|
|
|
|
hRect.height = aContentArea.height - aScrollArea.height;
|
|
|
|
hRect.y = PR_TRUE ? aScrollArea.YMost() : aContentArea.y;
|
|
|
|
nsMargin margin;
|
|
|
|
mHScrollbarBox->GetMargin(margin);
|
|
|
|
hRect.Deflate(margin);
|
2008-08-08 20:11:54 +04:00
|
|
|
AdjustScrollbarRect(view, presContext, hRect, PR_FALSE);
|
2007-03-28 10:24:40 +04:00
|
|
|
LayoutAndInvalidate(aState, mHScrollbarBox, hRect);
|
2007-03-05 04:39:53 +03:00
|
|
|
}
|
2006-03-15 19:55:19 +03:00
|
|
|
|
2003-11-21 13:45:24 +03:00
|
|
|
// place the scrollcorner
|
|
|
|
if (mScrollCornerBox) {
|
2005-10-05 03:49:39 +04:00
|
|
|
NS_PRECONDITION(mScrollCornerBox->IsBoxFrame(), "Must be a box frame!");
|
2003-11-21 13:45:24 +03:00
|
|
|
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");
|
|
|
|
}
|
2007-03-28 10:24:40 +04:00
|
|
|
LayoutAndInvalidate(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,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// if the client area changed size because of an incremental
|
|
|
|
// reflow of a descendant. (If the outer frame is dirty, the fixed
|
|
|
|
// children will be re-laid out anyway)
|
|
|
|
if (aOldScrollArea.Size() != aScrollArea.Size() &&
|
|
|
|
!(mOuter->GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
2005-06-16 06:57:23 +04:00
|
|
|
mIsRoot) {
|
2007-12-21 02:49:46 +03:00
|
|
|
mMayHaveDirtyFixedChildren = PR_TRUE;
|
2001-04-17 05:45:38 +04:00
|
|
|
}
|
2007-03-05 04:39:53 +03:00
|
|
|
|
|
|
|
// post reflow callback to modify scrollbar attributes
|
|
|
|
if (!mPostedReflowCallback) {
|
|
|
|
aState.PresContext()->PresShell()->PostReflowCallback(this);
|
|
|
|
mPostedReflowCallback = PR_TRUE;
|
|
|
|
}
|
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
|
2007-03-14 01:11:14 +03:00
|
|
|
nsGfxScrollFrameInner::SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos)
|
2004-09-22 10:33:36 +04:00
|
|
|
{
|
2007-03-05 04:39:53 +03:00
|
|
|
if (aMaxPos) {
|
2007-03-14 01:11:14 +03:00
|
|
|
aContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE);
|
2007-03-05 04:39:53 +03:00
|
|
|
} else {
|
2007-03-14 01:11:14 +03:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
NS_LITERAL_STRING("true"), PR_TRUE);
|
2007-03-05 04:39:53 +03:00
|
|
|
}
|
2004-09-22 10:33:36 +04:00
|
|
|
}
|
|
|
|
|
2007-03-05 04:39:53 +03:00
|
|
|
void
|
2007-03-14 01:11:14 +03:00
|
|
|
nsGfxScrollFrameInner::SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom,
|
2007-03-05 04:39:53 +03:00
|
|
|
nscoord aSize)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
// convert to pixels
|
2007-02-07 10:46:44 +03:00
|
|
|
aSize = nsPresContext::AppUnitsToIntCSSPixels(aSize);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-10-12 04:16:06 +04:00
|
|
|
// only set the attribute if it changed.
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2006-03-22 10:10:31 +03:00
|
|
|
nsAutoString newValue;
|
|
|
|
newValue.AppendInt(aSize);
|
|
|
|
|
2007-03-14 01:11:14 +03:00
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, aAtom, newValue, eCaseMatters))
|
2007-03-05 04:39:53 +03:00
|
|
|
return;
|
2006-03-22 10:10:31 +03:00
|
|
|
|
2007-03-14 01:11:14 +03:00
|
|
|
aContent->SetAttr(kNameSpaceID_None, aAtom, newValue, PR_TRUE);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect
|
|
|
|
nsGfxScrollFrameInner::GetScrolledRect(const nsSize& aScrollPortSize) const
|
2000-07-08 02:24:06 +04:00
|
|
|
{
|
2006-03-15 19:55:19 +03:00
|
|
|
nsRect result = mScrolledFrame->GetOverflowRect();
|
|
|
|
nscoord x1 = result.x, x2 = result.XMost(),
|
|
|
|
y1 = result.y, y2 = result.YMost();
|
|
|
|
if (y1 < 0)
|
|
|
|
y1 = 0;
|
|
|
|
if (IsLTR() || mIsXUL) {
|
|
|
|
if (x1 < 0)
|
|
|
|
x1 = 0;
|
|
|
|
} else {
|
|
|
|
if (x2 > aScrollPortSize.width)
|
|
|
|
x2 = aScrollPortSize.width;
|
2008-07-14 01:50:35 +04:00
|
|
|
// When the scrolled frame chooses a size larger than its available width (because
|
|
|
|
// its padding alone is larger than the available width), we need to keep the
|
|
|
|
// start-edge of the scroll frame anchored to the start-edge of the scrollport.
|
|
|
|
// When the scrolled frame is RTL, this means moving it in our left-based
|
|
|
|
// coordinate system, so we need to compensate for its extra width here by
|
|
|
|
// effectively repositioning the frame.
|
|
|
|
nscoord extraWidth = PR_MAX(0, mScrolledFrame->GetSize().width - aScrollPortSize.width);
|
|
|
|
x2 += extraWidth;
|
2006-03-15 19:55:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsRect(x1, y1, x2 - x1, y2 - y1);
|
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 {
|
2005-08-03 00:19:34 +04:00
|
|
|
nsMargin border;
|
|
|
|
mOuter->GetBorder(border);
|
2005-08-24 00:41:08 +04:00
|
|
|
nsRect r(nsPoint(0,0), mOuter->GetSize());
|
2005-08-03 00:19:34 +04:00
|
|
|
r.Deflate(border);
|
2005-04-04 01:00:41 +04:00
|
|
|
nsRect scrollArea = mScrollableView->View()->GetBounds();
|
2004-09-29 06:08:51 +04:00
|
|
|
|
2005-08-03 00:19:34 +04:00
|
|
|
return nsMargin(scrollArea.x - r.x, scrollArea.y - r.y,
|
|
|
|
r.XMost() - scrollArea.XMost(),
|
|
|
|
r.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;
|
|
|
|
|
2006-12-07 22:53:41 +03:00
|
|
|
nsIScrollbarFrame* scrollbar;
|
|
|
|
CallQueryInterface(aScrollbar, &scrollbar);
|
2000-07-14 03:00:59 +04:00
|
|
|
if (scrollbar) {
|
|
|
|
// See if we have a mediator.
|
2006-12-07 22:53:41 +03:00
|
|
|
nsIScrollbarMediator* mediator = scrollbar->GetScrollbarMediator();
|
2000-07-14 03:00:59 +04:00
|
|
|
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
|
2006-03-23 06:45:41 +03:00
|
|
|
nsGfxScrollFrameInner::GetCoordAttribute(nsIBox* aBox, nsIAtom* atom, PRInt32 defaultValue)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2006-03-15 19:55:19 +03:00
|
|
|
if (aBox) {
|
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;
|
2005-10-28 15:25:24 +04:00
|
|
|
content->GetAttr(kNameSpaceID_None, atom, value);
|
|
|
|
if (!value.IsEmpty())
|
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
|
2007-02-07 10:46:44 +03:00
|
|
|
defaultValue = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
2006-03-15 19:55:19 +03:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2006-03-15 19:55:19 +03:00
|
|
|
return defaultValue;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
2004-09-13 06:10:29 +04:00
|
|
|
|
2005-08-25 04:10:37 +04:00
|
|
|
static nsIURI* GetDocURI(nsIFrame* aFrame)
|
|
|
|
{
|
2007-03-31 01:11:41 +04:00
|
|
|
nsIPresShell* shell = aFrame->PresContext()->GetPresShell();
|
2005-08-25 04:10:37 +04:00
|
|
|
if (!shell)
|
|
|
|
return nsnull;
|
|
|
|
nsIDocument* doc = shell->GetDocument();
|
|
|
|
if (!doc)
|
|
|
|
return nsnull;
|
|
|
|
return doc->GetDocumentURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxScrollFrameInner::SaveVScrollbarStateToGlobalHistory()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsRoot, "Only use this on viewports");
|
|
|
|
|
|
|
|
// If the hint is the same as the one we loaded, don't bother
|
|
|
|
// saving it
|
|
|
|
if (mDidLoadHistoryVScrollbarHint &&
|
|
|
|
(mHistoryVScrollbarHint == mHasVerticalScrollbar))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIURI* uri = GetDocURI(mOuter);
|
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
2006-03-03 06:34:48 +03:00
|
|
|
nsCOMPtr<nsIGlobalHistory3> history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID));
|
2005-08-25 04:10:37 +04:00
|
|
|
if (!history)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRUint32 flags = 0;
|
|
|
|
if (mHasVerticalScrollbar) {
|
|
|
|
flags |= NS_GECKO_FLAG_NEEDS_VERTICAL_SCROLLBAR;
|
|
|
|
}
|
|
|
|
history->SetURIGeckoFlags(uri, flags);
|
|
|
|
// if it fails, we don't care
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGfxScrollFrameInner::GetVScrollbarHintFromGlobalHistory(PRBool* aVScrollbarNeeded)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsRoot, "Only use this on viewports");
|
|
|
|
NS_ASSERTION(!mDidLoadHistoryVScrollbarHint,
|
|
|
|
"Should only load a hint once, it can be expensive");
|
|
|
|
|
|
|
|
nsIURI* uri = GetDocURI(mOuter);
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-03-03 06:34:48 +03:00
|
|
|
nsCOMPtr<nsIGlobalHistory3> history(do_GetService(NS_GLOBALHISTORY2_CONTRACTID));
|
2005-08-25 04:10:37 +04:00
|
|
|
if (!history)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint32 flags;
|
|
|
|
nsresult rv = history->GetURIGeckoFlags(uri, &flags);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*aVScrollbarNeeded = (flags & NS_GECKO_FLAG_NEEDS_VERTICAL_SCROLLBAR) != 0;
|
|
|
|
mDidLoadHistoryVScrollbarHint = PR_TRUE;
|
|
|
|
mHistoryVScrollbarHint = *aVScrollbarNeeded;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-28 01:52:53 +03:00
|
|
|
nsPresState*
|
2005-12-07 02:56:17 +03:00
|
|
|
nsGfxScrollFrameInner::SaveState(nsIStatefulFrame::SpecialStateID aStateID)
|
2004-09-13 06:10:29 +04:00
|
|
|
{
|
2005-12-07 02:56:17 +03:00
|
|
|
// Don't save "normal" state for the root scrollframe; that's
|
|
|
|
// handled via the eDocumentScrollState state id
|
|
|
|
if (mIsRoot && aStateID == nsIStatefulFrame::eNoID) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2006-12-07 22:53:41 +03:00
|
|
|
|
2006-12-19 23:11:27 +03:00
|
|
|
nsIScrollbarMediator* mediator;
|
|
|
|
CallQueryInterface(GetScrolledFrame(), &mediator);
|
2004-09-13 06:10:29 +04:00
|
|
|
if (mediator) {
|
2006-12-19 23:11:27 +03:00
|
|
|
// child handles its own scroll state, so don't bother saving state here
|
2004-09-13 06:10:29 +04:00
|
|
|
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();
|
2006-11-06 19:08:20 +03:00
|
|
|
childRect.x = x;
|
|
|
|
childRect.y = y;
|
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);
|
|
|
|
|
2006-11-06 19:08:20 +03:00
|
|
|
state->SetScrollState(childRect);
|
2004-09-13 06:10:29 +04:00
|
|
|
|
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
|
|
|
{
|
2006-11-06 19:08:20 +03:00
|
|
|
mRestoreRect = aState->GetScrollState();
|
|
|
|
mLastPos.x = -1;
|
|
|
|
mLastPos.y = -1;
|
|
|
|
mDidHistoryRestore = PR_TRUE;
|
|
|
|
nsIScrollableView* scrollingView = GetScrollableView();
|
|
|
|
if (scrollingView) {
|
|
|
|
scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
|
|
|
|
} else {
|
|
|
|
mLastPos = nsPoint(0, 0);
|
2004-09-13 06:10:29 +04:00
|
|
|
}
|
|
|
|
}
|