2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-26 03:05:21 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-01-26 03:05:21 +03: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-01-26 03:05:21 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-26 03:05:21 +03:00
|
|
|
#include "nsContainerFrame.h"
|
1999-01-28 20:14:13 +03:00
|
|
|
#include "nsHTMLParts.h"
|
1999-01-26 03:05:21 +03:00
|
|
|
#include "nsHTMLIIDs.h"
|
1999-01-28 20:14:13 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsIViewManager.h"
|
2001-04-17 05:45:38 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
1999-02-03 20:01:51 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
2001-12-18 01:39:59 +03:00
|
|
|
#include "nsHTMLReflowCommand.h"
|
1999-07-24 07:59:47 +04:00
|
|
|
#include "nsIPresShell.h"
|
1999-01-26 03:05:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Viewport frame class.
|
|
|
|
*
|
|
|
|
* The viewport frame is the parent frame for the document element's frame.
|
|
|
|
* It only supports having a single child frame which must be one of the
|
|
|
|
* following:
|
|
|
|
* - scroll frame
|
|
|
|
* - root frame
|
|
|
|
*
|
1999-02-14 06:47:33 +03:00
|
|
|
* The viewport frame has an additional named child list:
|
1999-01-26 03:05:21 +03:00
|
|
|
* - "Fixed-list" which contains the fixed positioned frames
|
1999-02-14 06:47:33 +03:00
|
|
|
*
|
|
|
|
* @see nsLayoutAtoms::fixedList
|
1999-01-26 03:05:21 +03:00
|
|
|
*/
|
|
|
|
class ViewportFrame : public nsContainerFrame {
|
|
|
|
public:
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD Destroy(nsIPresContext* aPresContext);
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD SetInitialChildList(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList);
|
2000-03-22 05:43:08 +03:00
|
|
|
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
nsIFrame** aFrame);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD AppendFrames(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD InsertFrames(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList);
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD RemoveFrame(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame);
|
1999-01-28 20:14:13 +03:00
|
|
|
|
|
|
|
NS_IMETHOD GetAdditionalChildListName(PRInt32 aIndex,
|
1999-02-10 05:25:01 +03:00
|
|
|
nsIAtom** aListName) const;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
NS_IMETHOD FirstChild(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
|
1999-01-26 03:05:21 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
1999-02-14 06:47:33 +03:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsLayoutAtoms::viewportFrame
|
|
|
|
*/
|
|
|
|
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
|
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
2001-11-14 04:33:42 +03:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const;
|
1999-08-31 07:09:40 +04:00
|
|
|
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|
1999-01-28 20:14:13 +03:00
|
|
|
|
|
|
|
protected:
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult IncrementalReflow(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState);
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsresult ReflowFixedFrame(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
PRBool aInitialReflow,
|
|
|
|
nsReflowStatus& aStatus) const;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void ReflowFixedFrames(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState) const;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void CalculateFixedContainingBlockSize(nsIPresContext* aPresContext,
|
1999-02-03 20:01:51 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord& aWidth,
|
|
|
|
nscoord& aHeight) const;
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
private:
|
|
|
|
nsFrameList mFixedFrames; // additional named child list
|
1999-01-26 03:05:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewViewportFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-01-26 03:05:21 +03:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
ViewportFrame* it = new (aPresShell) ViewportFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
if (nsnull == it) {
|
1999-01-26 03:05:21 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1999-01-26 03:05:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::Destroy(nsIPresContext* aPresContext)
|
1999-01-28 20:14:13 +03:00
|
|
|
{
|
1999-07-22 08:00:57 +04:00
|
|
|
mFixedFrames.DestroyFrames(aPresContext);
|
1999-07-22 06:24:52 +04:00
|
|
|
return nsContainerFrame::Destroy(aPresContext);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
1999-07-27 18:15:42 +04:00
|
|
|
nsresult rv;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
// See which child list to add the frames to
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsFrame::VerifyDirtyBitSet(aChildList);
|
|
|
|
#endif
|
1999-01-28 20:14:13 +03:00
|
|
|
if (nsLayoutAtoms::fixedList == aListName) {
|
|
|
|
mFixedFrames.SetFrames(aChildList);
|
1999-07-27 18:15:42 +04:00
|
|
|
rv = NS_OK;
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
} else {
|
|
|
|
rv = nsContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-22 05:43:08 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ViewportFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
// this should act like a block, so we need to override
|
|
|
|
return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame);
|
|
|
|
}
|
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::AppendFrames(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-07-27 18:15:42 +04:00
|
|
|
nsresult rv;
|
1999-07-24 07:59:47 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(nsLayoutAtoms::fixedList == aListName, "unexpected child list");
|
1999-07-27 18:15:42 +04:00
|
|
|
if (aListName != nsLayoutAtoms::fixedList) {
|
|
|
|
// We only expect incremental changes for our fixed frames
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Add the frames to our list of fixed position frames
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsFrame::VerifyDirtyBitSet(aFrameList);
|
|
|
|
#endif
|
|
|
|
mFixedFrames.AppendFrames(nsnull, aFrameList);
|
|
|
|
|
|
|
|
// Generate a reflow command to reflow the dirty frames
|
2001-12-18 01:39:59 +03:00
|
|
|
nsHTMLReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, eReflowType_ReflowDirty);
|
1999-07-27 18:15:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
reflowCmd->SetChildListName(nsLayoutAtoms::fixedList);
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
}
|
1999-07-24 07:59:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::InsertFrames(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-07-27 18:15:42 +04:00
|
|
|
nsresult rv;
|
1999-07-24 07:59:47 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(nsLayoutAtoms::fixedList == aListName, "unexpected child list");
|
1999-07-27 18:15:42 +04:00
|
|
|
if (aListName != nsLayoutAtoms::fixedList) {
|
|
|
|
// We only expect incremental changes for our fixed frames
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Insert the new frames
|
1999-07-24 07:59:47 +04:00
|
|
|
#ifdef NS_DEBUG
|
1999-07-27 18:15:42 +04:00
|
|
|
nsFrame::VerifyDirtyBitSet(aFrameList);
|
1999-07-24 07:59:47 +04:00
|
|
|
#endif
|
1999-07-27 18:15:42 +04:00
|
|
|
mFixedFrames.InsertFrames(nsnull, aPrevFrame, aFrameList);
|
|
|
|
|
|
|
|
// Generate a reflow command to reflow the dirty frames
|
2001-12-18 01:39:59 +03:00
|
|
|
nsHTMLReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, eReflowType_ReflowDirty);
|
1999-07-27 18:15:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
reflowCmd->SetChildListName(nsLayoutAtoms::fixedList);
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
}
|
1999-07-24 07:59:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::RemoveFrame(nsIPresContext* aPresContext,
|
1999-07-24 07:59:47 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
1999-07-27 18:15:42 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
NS_PRECONDITION(nsLayoutAtoms::fixedList == aListName, "unexpected child list");
|
1999-07-27 18:15:42 +04:00
|
|
|
if (aListName != nsLayoutAtoms::fixedList) {
|
|
|
|
// We only expect incremental changes for our fixed frames
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PRBool result = mFixedFrames.DestroyFrame(aPresContext, aOldFrame);
|
|
|
|
NS_ASSERTION(result, "didn't find frame to delete");
|
|
|
|
// Because fixed frames aren't part of a flow, there's no additional
|
|
|
|
// work to do, e.g. reflowing sibling frames. And because fixed frames
|
|
|
|
// have a view, we don't need to repaint
|
|
|
|
rv = result ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1999-07-24 07:59:47 +04:00
|
|
|
}
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ViewportFrame::GetAdditionalChildListName(PRInt32 aIndex,
|
1999-02-10 05:25:01 +03:00
|
|
|
nsIAtom** aListName) const
|
1999-01-28 20:14:13 +03:00
|
|
|
{
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
|
|
|
|
*aListName = nsnull;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else if (0 == aIndex) {
|
1999-02-10 05:25:01 +03:00
|
|
|
*aListName = nsLayoutAtoms::fixedList;
|
|
|
|
NS_ADDREF(*aListName);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-22 04:16:50 +03:00
|
|
|
ViewportFrame::FirstChild(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const
|
1999-01-28 20:14:13 +03:00
|
|
|
{
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_PRECONDITION(nsnull != aFirstChild, "null OUT parameter pointer");
|
1999-01-28 20:14:13 +03:00
|
|
|
if (aListName == nsLayoutAtoms::fixedList) {
|
1999-02-10 05:25:01 +03:00
|
|
|
*aFirstChild = mFixedFrames.FirstChild();
|
1999-01-28 20:14:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
return nsContainerFrame::FirstChild(aPresContext, aListName, aFirstChild);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
|
1999-02-03 20:01:51 +03:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::CalculateFixedContainingBlockSize(nsIPresContext* aPresContext,
|
1999-02-03 20:01:51 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord& aWidth,
|
|
|
|
nscoord& aHeight) const
|
|
|
|
{
|
|
|
|
// Initialize the values to the computed width/height in our reflow
|
|
|
|
// state struct
|
1999-07-20 07:41:03 +04:00
|
|
|
aWidth = aReflowState.mComputedWidth;
|
|
|
|
aHeight = aReflowState.mComputedHeight;
|
1999-02-03 20:01:51 +03:00
|
|
|
|
|
|
|
// Get our prinicpal child frame and see if we're scrollable
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
2001-04-17 05:45:38 +04:00
|
|
|
nsCOMPtr<nsIScrollableFrame> scrollingFrame(do_QueryInterface(kidFrame));
|
|
|
|
|
|
|
|
if (scrollingFrame) {
|
|
|
|
nscoord sbWidth = 0, sbHeight = 0;
|
|
|
|
PRBool sbHVisible = PR_FALSE, sbVVisible = PR_FALSE;
|
|
|
|
scrollingFrame->GetScrollbarSizes(aPresContext, &sbWidth, &sbHeight);
|
|
|
|
scrollingFrame->GetScrollbarVisibility(aPresContext, &sbVVisible, &sbHVisible);
|
|
|
|
if (sbVVisible) {
|
|
|
|
aWidth -= sbWidth;
|
|
|
|
}
|
|
|
|
if (sbHVisible) {
|
|
|
|
aHeight -= sbHeight;
|
1999-02-03 20:01:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-18 03:55:58 +04:00
|
|
|
/**
|
|
|
|
* NOTE: nsAbsoluteContainingBlock::ReflowAbsoluteFrame is rather
|
|
|
|
* similar to this function, so changes made here may also need to be
|
|
|
|
* made there.
|
|
|
|
*/
|
1999-01-28 20:14:13 +03:00
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::ReflowFixedFrame(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aKidFrame,
|
|
|
|
PRBool aInitialReflow,
|
|
|
|
nsReflowStatus& aStatus) const
|
|
|
|
{
|
|
|
|
// Reflow the frame
|
1999-10-30 06:52:11 +04:00
|
|
|
nsresult rv;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
nsHTMLReflowMetrics kidDesiredSize(nsnull);
|
|
|
|
nsSize availSize(aReflowState.availableWidth, NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, aKidFrame,
|
|
|
|
availSize);
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// If it's the initial reflow, then override the reflow reason. This is
|
|
|
|
// used when frames are inserted incrementally
|
|
|
|
if (aInitialReflow) {
|
|
|
|
kidReflowState.reason = eReflowReason_Initial;
|
|
|
|
}
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Send the WillReflow() notification and position the frame
|
|
|
|
aKidFrame->WillReflow(aPresContext);
|
1999-11-24 09:03:41 +03:00
|
|
|
aKidFrame->MoveTo(aPresContext,
|
1999-11-19 18:33:29 +03:00
|
|
|
kidReflowState.mComputedOffsets.left + kidReflowState.mComputedMargin.left,
|
|
|
|
kidReflowState.mComputedOffsets.top + kidReflowState.mComputedMargin.top);
|
|
|
|
|
|
|
|
// Position its view
|
2001-09-06 00:27:19 +04:00
|
|
|
nsContainerFrame::PositionFrameView(aPresContext, aKidFrame);
|
1999-11-19 18:33:29 +03:00
|
|
|
|
|
|
|
// Do the reflow
|
1999-10-30 06:52:11 +04:00
|
|
|
rv = aKidFrame->Reflow(aPresContext, kidDesiredSize, kidReflowState, aStatus);
|
|
|
|
|
2001-09-18 03:55:58 +04:00
|
|
|
if (NS_AUTOOFFSET == kidReflowState.mComputedOffsets.left)
|
|
|
|
kidReflowState.mComputedOffsets.left = aReflowState.mComputedWidth -
|
|
|
|
kidReflowState.mComputedOffsets.right -
|
|
|
|
kidReflowState.mComputedMargin.right -
|
|
|
|
kidReflowState.mComputedBorderPadding.right -
|
|
|
|
kidDesiredSize.width -
|
|
|
|
kidReflowState.mComputedBorderPadding.left -
|
|
|
|
kidReflowState.mComputedMargin.left;
|
|
|
|
if (NS_AUTOOFFSET == kidReflowState.mComputedOffsets.top)
|
|
|
|
kidReflowState.mComputedOffsets.top = aReflowState.mComputedHeight -
|
|
|
|
kidReflowState.mComputedOffsets.bottom -
|
|
|
|
kidReflowState.mComputedMargin.bottom -
|
|
|
|
kidReflowState.mComputedBorderPadding.bottom -
|
|
|
|
kidDesiredSize.height -
|
|
|
|
kidReflowState.mComputedBorderPadding.top -
|
|
|
|
kidReflowState.mComputedMargin.top;
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// XXX If the child had a fixed height, then make sure it respected it...
|
|
|
|
if (NS_AUTOHEIGHT != kidReflowState.mComputedHeight) {
|
|
|
|
if (kidDesiredSize.height < kidReflowState.mComputedHeight) {
|
|
|
|
kidDesiredSize.height = kidReflowState.mComputedHeight;
|
|
|
|
kidDesiredSize.height += kidReflowState.mComputedBorderPadding.top +
|
|
|
|
kidReflowState.mComputedBorderPadding.bottom;
|
1999-01-30 20:39:29 +03:00
|
|
|
}
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Position the child
|
|
|
|
nsRect rect(kidReflowState.mComputedOffsets.left + kidReflowState.mComputedMargin.left,
|
|
|
|
kidReflowState.mComputedOffsets.top + kidReflowState.mComputedMargin.top,
|
|
|
|
kidDesiredSize.width, kidDesiredSize.height);
|
1999-11-24 09:03:41 +03:00
|
|
|
aKidFrame->SetRect(aPresContext, rect);
|
1999-10-30 06:52:11 +04:00
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Size and position the view and set its opacity, visibility, content
|
|
|
|
// transparency, and clip
|
2001-09-06 00:27:19 +04:00
|
|
|
nsIView* kidView;
|
|
|
|
aKidFrame->GetView(aPresContext, &kidView);
|
1999-11-24 09:03:41 +03:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(aPresContext, aKidFrame, kidView,
|
1999-12-06 18:49:53 +03:00
|
|
|
&kidDesiredSize.mOverflowArea);
|
2001-12-07 17:51:12 +03:00
|
|
|
aKidFrame->DidReflow(aPresContext, nsnull, NS_FRAME_REFLOW_FINISHED);
|
1999-01-28 20:14:13 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by Reflow() to reflow all of the fixed positioned child frames.
|
|
|
|
// This is only done for 'initial', 'resize', and 'style change' reflow commands
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::ReflowFixedFrames(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState) const
|
|
|
|
{
|
1999-02-03 20:01:51 +03:00
|
|
|
// Calculate how much room is available for the fixed items. That means
|
|
|
|
// determining if the viewport is scrollable and whether the vertical and/or
|
|
|
|
// horizontal scrollbars are visible
|
|
|
|
nscoord width, height;
|
|
|
|
CalculateFixedContainingBlockSize(aPresContext, aReflowState, width, height);
|
|
|
|
|
|
|
|
// Make a copy of the reflow state and change the computed width and height
|
|
|
|
// to reflect the available space for the fixed items
|
|
|
|
// XXX Find a cleaner way to do this...
|
|
|
|
nsHTMLReflowState reflowState(aReflowState);
|
1999-07-20 07:41:03 +04:00
|
|
|
reflowState.mComputedWidth = width;
|
|
|
|
reflowState.mComputedHeight = height;
|
1999-02-03 20:01:51 +03:00
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
nsIFrame* kidFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
for (kidFrame = mFixedFrames.FirstChild(); nsnull != kidFrame; kidFrame->GetNextSibling(&kidFrame)) {
|
1999-01-28 20:14:13 +03:00
|
|
|
// Reflow the frame using our reflow reason
|
|
|
|
nsReflowStatus kidStatus;
|
1999-02-03 20:01:51 +03:00
|
|
|
ReflowFixedFrame(aPresContext, reflowState, kidFrame, PR_FALSE, kidStatus);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by Reflow() to handle the case where it's an incremental reflow
|
|
|
|
* of a fixed child frame
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::IncrementalReflow(nsIPresContext* aPresContext,
|
1999-01-28 20:14:13 +03:00
|
|
|
const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
2001-12-18 01:39:59 +03:00
|
|
|
nsReflowType type;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
|
|
|
// Get the type of reflow command
|
|
|
|
aReflowState.reflowCommand->GetType(type);
|
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
// The only type of reflow command we expect is that we have dirty
|
|
|
|
// child frames to reflow
|
2001-12-18 01:39:59 +03:00
|
|
|
NS_ASSERTION(eReflowType_ReflowDirty, "unexpected reflow type");
|
1999-07-24 07:59:47 +04:00
|
|
|
|
|
|
|
// Calculate how much room is available for the fixed items. That means
|
|
|
|
// determining if the viewport is scrollable and whether the vertical and/or
|
|
|
|
// horizontal scrollbars are visible
|
|
|
|
nscoord width, height;
|
|
|
|
CalculateFixedContainingBlockSize(aPresContext, aReflowState, width, height);
|
|
|
|
|
|
|
|
// Make a copy of the reflow state and change the computed width and height
|
|
|
|
// to reflect the available space for the fixed items
|
|
|
|
// XXX Find a cleaner way to do this...
|
|
|
|
nsHTMLReflowState reflowState(aReflowState);
|
|
|
|
reflowState.mComputedWidth = width;
|
|
|
|
reflowState.mComputedHeight = height;
|
|
|
|
|
|
|
|
// Walk the fixed child frames and reflow the dirty frames
|
|
|
|
for (nsIFrame* f = mFixedFrames.FirstChild(); f; f->GetNextSibling(&f)) {
|
|
|
|
nsFrameState frameState;
|
1999-01-28 20:14:13 +03:00
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
f->GetFrameState(&frameState);
|
|
|
|
if (frameState & NS_FRAME_IS_DIRTY) {
|
1999-02-03 20:01:51 +03:00
|
|
|
nsReflowStatus status;
|
1999-07-27 18:15:42 +04:00
|
|
|
|
|
|
|
// Note: the only reason the frame would be dirty would be if it had
|
|
|
|
// just been inserted or appended
|
|
|
|
NS_ASSERTION(frameState & NS_FRAME_FIRST_REFLOW, "unexpected frame state");
|
1999-07-24 07:59:47 +04:00
|
|
|
ReflowFixedFrame(aPresContext, reflowState, f, PR_TRUE, status);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
ViewportFrame::Reflow(nsIPresContext* aPresContext,
|
1999-01-26 03:05:21 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("ViewportFrame", aReflowState.reason);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_IN("ViewportFrame::Reflow");
|
|
|
|
NS_PRECONDITION(nsnull == aDesiredSize.maxElementSize, "unexpected request");
|
|
|
|
|
|
|
|
// Initialize OUT parameter
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
nsIFrame* nextFrame = nsnull;
|
|
|
|
PRBool isHandled = PR_FALSE;
|
|
|
|
|
2001-12-18 01:39:59 +03:00
|
|
|
nsReflowType reflowType = eReflowType_ContentChanged;
|
2001-04-17 05:45:38 +04:00
|
|
|
if (aReflowState.reflowCommand) {
|
|
|
|
aReflowState.reflowCommand->GetType(reflowType);
|
|
|
|
}
|
2001-12-18 01:39:59 +03:00
|
|
|
if (reflowType == eReflowType_UserDefined) {
|
2001-04-17 05:45:38 +04:00
|
|
|
// Reflow the fixed frames to account for changed scrolled area size
|
|
|
|
ReflowFixedFrames(aPresContext, aReflowState);
|
|
|
|
isHandled = PR_TRUE;
|
|
|
|
|
|
|
|
// Otherwise check for an incremental reflow
|
|
|
|
} else if (eReflowReason_Incremental == aReflowState.reason) {
|
1999-01-26 03:05:21 +03:00
|
|
|
// See if we're the target frame
|
|
|
|
nsIFrame* targetFrame;
|
|
|
|
aReflowState.reflowCommand->GetTarget(targetFrame);
|
|
|
|
if (this == targetFrame) {
|
1999-01-28 20:14:13 +03:00
|
|
|
nsIAtom* listName;
|
|
|
|
PRBool isFixedChild;
|
|
|
|
|
1999-07-24 07:59:47 +04:00
|
|
|
// It's targeted at us. It better be for the fixed child list
|
1999-01-28 20:14:13 +03:00
|
|
|
aReflowState.reflowCommand->GetChildListName(listName);
|
|
|
|
isFixedChild = nsLayoutAtoms::fixedList == listName;
|
|
|
|
NS_IF_RELEASE(listName);
|
|
|
|
NS_ASSERTION(isFixedChild, "unexpected child list");
|
|
|
|
|
|
|
|
if (isFixedChild) {
|
1999-07-24 07:59:47 +04:00
|
|
|
// Handle the incremental reflow command
|
1999-01-28 20:14:13 +03:00
|
|
|
IncrementalReflow(aPresContext, aReflowState);
|
|
|
|
isHandled = PR_TRUE;
|
|
|
|
}
|
1999-01-26 03:05:21 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Get the next frame in the reflow chain
|
|
|
|
aReflowState.reflowCommand->GetNext(nextFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-04 08:09:54 +04:00
|
|
|
nsRect kidRect(0,0,aReflowState.availableWidth,aReflowState.availableHeight);
|
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
if (!isHandled) {
|
|
|
|
if ((eReflowReason_Incremental == aReflowState.reason) &&
|
|
|
|
(mFixedFrames.ContainsFrame(nextFrame))) {
|
|
|
|
// Reflow the 'fixed' frame that's the next frame in the reflow path
|
|
|
|
nsReflowStatus kidStatus;
|
|
|
|
ReflowFixedFrame(aPresContext, aReflowState, nextFrame, PR_FALSE,
|
|
|
|
kidStatus);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Reflow our one and only principal child frame
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
|
|
|
nsHTMLReflowMetrics kidDesiredSize(nsnull);
|
|
|
|
nsSize availableSpace(aReflowState.availableWidth,
|
|
|
|
aReflowState.availableHeight);
|
1999-03-05 07:29:11 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
kidFrame, availableSpace);
|
1999-01-28 20:14:13 +03:00
|
|
|
|
|
|
|
// Reflow the frame
|
1999-10-30 06:52:11 +04:00
|
|
|
kidReflowState.mComputedHeight = aReflowState.availableHeight;
|
|
|
|
ReflowChild(kidFrame, aPresContext, kidDesiredSize, kidReflowState,
|
1999-11-19 18:33:29 +03:00
|
|
|
0, 0, 0, aStatus);
|
1999-11-20 01:04:01 +03:00
|
|
|
kidRect.width = kidDesiredSize.width;
|
|
|
|
kidRect.height = kidDesiredSize.height;
|
1999-10-30 06:52:11 +04:00
|
|
|
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, nsnull, kidDesiredSize, 0, 0, 0);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
1999-01-26 03:05:21 +03:00
|
|
|
|
1999-01-28 20:14:13 +03:00
|
|
|
// If it's a 'initial', 'resize', or 'style change' reflow command (anything
|
|
|
|
// but incremental), then reflow all the fixed positioned child frames
|
|
|
|
if (eReflowReason_Incremental != aReflowState.reason) {
|
|
|
|
ReflowFixedFrames(aPresContext, aReflowState);
|
|
|
|
}
|
1999-01-26 03:05:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-04 08:09:54 +04:00
|
|
|
// If we were flowed initially at both an unconstrained width and height,
|
|
|
|
// this is a hint that we should return our child's intrinsic size.
|
1999-09-04 02:41:56 +04:00
|
|
|
if ((eReflowReason_Initial == aReflowState.reason ||
|
|
|
|
eReflowReason_Resize == aReflowState.reason) &&
|
1999-07-04 08:09:54 +04:00
|
|
|
aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE &&
|
|
|
|
aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.width = kidRect.width;
|
|
|
|
aDesiredSize.height = kidRect.height;
|
|
|
|
aDesiredSize.ascent = kidRect.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Return the max size as our desired size
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
aDesiredSize.ascent = aReflowState.availableHeight;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
}
|
1999-01-26 03:05:21 +03:00
|
|
|
|
2000-03-15 18:16:03 +03:00
|
|
|
// If this is an initial reflow, resize reflow, or style change reflow
|
|
|
|
// then do a repaint
|
1999-07-24 19:18:24 +04:00
|
|
|
if ((eReflowReason_Initial == aReflowState.reason) ||
|
2000-03-15 18:16:03 +03:00
|
|
|
(eReflowReason_Resize == aReflowState.reason) ||
|
|
|
|
(eReflowReason_StyleChange == aReflowState.reason)) {
|
1999-07-24 19:18:24 +04:00
|
|
|
nsRect damageRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
2001-11-06 04:44:20 +03:00
|
|
|
if (!damageRect.IsEmpty()) {
|
|
|
|
Invalidate(aPresContext, damageRect, PR_FALSE);
|
|
|
|
}
|
1999-07-24 19:18:24 +04:00
|
|
|
}
|
|
|
|
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-14 06:47:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ViewportFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::viewportFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
ViewportFrame::GetFrameName(nsAString& aResult) const
|
1999-01-26 03:05:21 +03:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Viewport"), aResult);
|
1999-01-26 03:05:21 +03:00
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ViewportFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|