1999-01-26 03:05:21 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03: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
|
|
|
*
|
1999-11-06 06:40:37 +03: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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-01-26 03:05:21 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-01-26 03:05:21 +03:00
|
|
|
*/
|
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"
|
1999-02-03 20:01:51 +03:00
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1999-07-24 07:59:47 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-01-26 03:05:21 +03:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
|
1999-02-03 20:01:51 +03:00
|
|
|
static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID);
|
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);
|
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
|
|
|
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_IMETHOD FirstChild(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
|
1999-11-02 01:12:45 +03:00
|
|
|
NS_IMETHOD GetFrameName(nsString& 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-05-12 02:03:29 +04:00
|
|
|
NS_NewViewportFrame(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;
|
|
|
|
}
|
|
|
|
ViewportFrame* it = new ViewportFrame;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, nsIReflowCommand::ReflowDirty);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
reflowCmd->SetChildListName(nsLayoutAtoms::fixedList);
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(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
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this, nsIReflowCommand::ReflowDirty);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
reflowCmd->SetChildListName(nsLayoutAtoms::fixedList);
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(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
|
1999-02-10 05:25:01 +03:00
|
|
|
ViewportFrame::FirstChild(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsContainerFrame::FirstChild(aListName, aFirstChild);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
nsIView* kidView;
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
kidFrame->GetView(aPresContext, &kidView);
|
1999-02-03 20:01:51 +03:00
|
|
|
if (nsnull != kidView) {
|
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(kidView->QueryInterface(kScrollViewIID, (void**)&scrollingView))) {
|
|
|
|
// Get the scrollbar dimensions
|
|
|
|
float sbWidth, sbHeight;
|
1999-02-12 20:45:58 +03:00
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
1999-02-03 20:01:51 +03:00
|
|
|
|
|
|
|
dc->GetScrollBarDimensions(sbWidth, sbHeight);
|
|
|
|
|
|
|
|
// See if the scrollbars are visible
|
|
|
|
PRBool vertSBVisible, horzSBVisible;
|
|
|
|
|
|
|
|
scrollingView->GetScrollbarVisibility(&vertSBVisible, &horzSBVisible);
|
|
|
|
if (vertSBVisible) {
|
|
|
|
aWidth -= NSToCoordRound(sbWidth);
|
|
|
|
}
|
|
|
|
if (horzSBVisible) {
|
|
|
|
aHeight -= NSToCoordRound(sbHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsIView* kidView;
|
1999-11-24 09:03:41 +03:00
|
|
|
aKidFrame->GetView(aPresContext, &kidView);
|
|
|
|
nsContainerFrame::PositionFrameView(aPresContext, aKidFrame, kidView);
|
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);
|
|
|
|
|
|
|
|
// 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
|
1999-11-24 09:03:41 +03:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(aPresContext, aKidFrame, kidView,
|
1999-11-19 18:33:29 +03:00
|
|
|
&kidDesiredSize.mCombinedArea);
|
|
|
|
aKidFrame->DidReflow(aPresContext, 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
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(eReflowReason_Incremental != aReflowState.reason,
|
|
|
|
"unexpected reflow reason");
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nsIReflowCommand::ReflowType type;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
NS_ASSERTION(nsIReflowCommand::ReflowDirty, "unexpected reflow type");
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
1999-01-26 03:05:21 +03:00
|
|
|
// Check for an incremental reflow
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
// 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
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, 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
|
|
|
|
1999-07-24 19:18:24 +04:00
|
|
|
// If this is a resize reflow or the initial reflow, then do a repaint
|
|
|
|
if ((eReflowReason_Initial == aReflowState.reason) ||
|
|
|
|
(eReflowReason_Resize == aReflowState.reason)) {
|
|
|
|
nsRect damageRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
1999-11-24 09:03:41 +03:00
|
|
|
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
|
|
|
|
ViewportFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("Viewport", aResult);
|
|
|
|
}
|
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
|