1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00: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/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00: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.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-13 20:24:54 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-13 20:24:54 +00:00
|
|
|
*/
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-05-03 03:51:48 +00:00
|
|
|
#include "nsIPresShell.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIContent.h"
|
1999-08-08 01:15:30 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1998-05-05 04:47:53 +00:00
|
|
|
#include "nsIPtr.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
1998-05-29 02:13:25 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLParts.h"
|
1998-06-04 17:50:19 +00:00
|
|
|
#include "nsIView.h"
|
1998-09-23 02:29:31 +00:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsViewsCID.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-10-06 21:01:41 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsDOMEvent.h"
|
1998-12-18 05:25:36 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-01-28 17:14:13 +00:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-02-24 04:03:50 +00:00
|
|
|
#include "nsIStyleSet.h"
|
1999-08-24 19:26:03 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-12-18 05:25:36 +00:00
|
|
|
static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID);
|
1999-01-28 17:14:13 +00:00
|
|
|
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-10-06 21:01:41 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLContainerFrame::Paint(nsIPresContext* aPresContext,
|
1998-10-06 21:01:41 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-08-27 21:48:21 +00:00
|
|
|
if (NS_FRAME_IS_UNFLOWABLE & mState) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-26 00:39:35 +00:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (disp->mVisible && mRect.width && mRect.height) {
|
|
|
|
// Paint our background and border
|
|
|
|
PRIntn skipSides = GetSkipSides();
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-10-06 21:01:41 +00:00
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
1999-01-15 18:25:58 +00:00
|
|
|
aDirtyRect, rect, *color, *spacing, 0, 0);
|
1998-12-18 15:54:23 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
1999-01-22 22:25:58 +00:00
|
|
|
aDirtyRect, rect, *spacing, mStyleContext, skipSides);
|
1999-08-19 14:35:48 +00:00
|
|
|
nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, rect, *spacing, mStyleContext, 0);
|
1998-10-06 21:01:41 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-11-19 03:52:29 +00:00
|
|
|
|
|
|
|
// Now paint the kids. Note that child elements have the opportunity to
|
|
|
|
// override the visibility property and display even if their parent is
|
|
|
|
// hidden
|
1998-12-18 15:54:23 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1998-04-17 01:41:24 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-09-23 02:29:31 +00:00
|
|
|
/**
|
|
|
|
* Create a next-in-flow for aFrame. Will return the newly created
|
|
|
|
* frame in aNextInFlowResult <b>if and only if</b> a new frame is
|
|
|
|
* created; otherwise nsnull is returned in aNextInFlowResult.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLContainerFrame::CreateNextInFlow(nsIPresContext* aPresContext,
|
1998-09-23 02:29:31 +00:00
|
|
|
nsIFrame* aOuterFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame*& aNextInFlowResult)
|
|
|
|
{
|
|
|
|
aNextInFlowResult = nsnull;
|
|
|
|
|
|
|
|
nsIFrame* nextInFlow;
|
1999-02-24 04:48:08 +00:00
|
|
|
aFrame->GetNextInFlow(&nextInFlow);
|
1998-09-23 02:29:31 +00:00
|
|
|
if (nsnull == nextInFlow) {
|
|
|
|
// Create a continuation frame for the child frame and insert it
|
|
|
|
// into our lines child list.
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aFrame->GetNextSibling(&nextFrame);
|
1999-02-24 04:03:50 +00:00
|
|
|
|
|
|
|
nsIPresShell* presShell;
|
|
|
|
nsIStyleSet* styleSet;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetShell(&presShell);
|
1999-02-24 04:03:50 +00:00
|
|
|
presShell->GetStyleSet(&styleSet);
|
|
|
|
NS_RELEASE(presShell);
|
1999-11-24 06:03:41 +00:00
|
|
|
styleSet->CreateContinuingFrame(aPresContext, aFrame, aOuterFrame, &nextInFlow);
|
1999-02-24 04:03:50 +00:00
|
|
|
NS_RELEASE(styleSet);
|
|
|
|
|
1998-09-23 02:29:31 +00:00
|
|
|
if (nsnull == nextInFlow) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aFrame->SetNextSibling(nextInFlow);
|
|
|
|
nextInFlow->SetNextSibling(nextFrame);
|
|
|
|
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_NEW_FRAMES,
|
1999-03-18 21:03:25 +00:00
|
|
|
("nsHTMLContainerFrame::MaybeCreateNextInFlow: frame=%p nextInFlow=%p",
|
1998-09-23 02:29:31 +00:00
|
|
|
aFrame, nextInFlow));
|
|
|
|
|
|
|
|
aNextInFlowResult = nextInFlow;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-11 04:22:00 +00:00
|
|
|
static nsresult
|
1999-10-26 04:44:41 +00:00
|
|
|
ReparentFrameViewTo(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
1999-08-24 19:26:03 +00:00
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIView* aNewParentView,
|
|
|
|
nsIView* aOldParentView)
|
1999-04-11 04:22:00 +00:00
|
|
|
{
|
|
|
|
nsIView* view;
|
|
|
|
|
|
|
|
// Does aFrame have a view?
|
1999-10-26 04:44:41 +00:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
1999-04-11 04:22:00 +00:00
|
|
|
if (view) {
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Verify that the current parent view is what we think it is
|
|
|
|
nsIView* parentView;
|
|
|
|
|
|
|
|
view->GetParent(parentView);
|
|
|
|
NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Change the parent view.
|
|
|
|
PRInt32 zIndex;
|
|
|
|
view->GetZIndex(zIndex);
|
1999-08-24 19:26:03 +00:00
|
|
|
aViewManager->RemoveChild(aOldParentView, view);
|
1999-04-11 04:22:00 +00:00
|
|
|
|
|
|
|
// XXX We need to insert this view in the correct place within its z-order...
|
1999-08-24 19:26:03 +00:00
|
|
|
aViewManager->InsertChild(aNewParentView, view, zIndex);
|
1999-04-11 04:22:00 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Iterate the child frames, and check each child frame to see if it has
|
|
|
|
// a view
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
|
|
|
|
aFrame->FirstChild(nsnull, &childFrame);
|
|
|
|
while (childFrame) {
|
1999-10-26 04:44:41 +00:00
|
|
|
ReparentFrameViewTo(aPresContext, childFrame, aViewManager, aNewParentView, aOldParentView);
|
1999-04-11 04:22:00 +00:00
|
|
|
childFrame->GetNextSibling(&childFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-24 19:26:03 +00:00
|
|
|
// Helper function that returns the nearest view to this frame. Checks
|
|
|
|
// this frame, its parent frame, its parent frame, ...
|
1999-04-11 04:22:00 +00:00
|
|
|
static nsIView*
|
1999-10-26 04:44:41 +00:00
|
|
|
GetClosestViewFor(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
1999-04-11 04:22:00 +00:00
|
|
|
{
|
1999-08-24 19:26:03 +00:00
|
|
|
NS_PRECONDITION(aFrame, "null frame pointer");
|
1999-04-11 04:22:00 +00:00
|
|
|
nsIView* view;
|
|
|
|
|
1999-08-24 19:26:03 +00:00
|
|
|
do {
|
1999-10-26 04:44:41 +00:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
1999-08-24 19:26:03 +00:00
|
|
|
if (view) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aFrame->GetParent(&aFrame);
|
|
|
|
} while (aFrame);
|
1999-04-11 04:22:00 +00:00
|
|
|
|
|
|
|
NS_POSTCONDITION(view, "no containing view");
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-10-26 04:44:41 +00:00
|
|
|
nsHTMLContainerFrame::ReparentFrameView(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIFrame* aOldParentFrame,
|
|
|
|
nsIFrame* aNewParentFrame)
|
1999-04-11 04:22:00 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aChildFrame, "null child frame pointer");
|
|
|
|
NS_PRECONDITION(aOldParentFrame, "null old parent frame pointer");
|
|
|
|
NS_PRECONDITION(aNewParentFrame, "null new parent frame pointer");
|
|
|
|
NS_PRECONDITION(aOldParentFrame != aNewParentFrame, "same old and new parent frame");
|
|
|
|
|
1999-08-24 19:26:03 +00:00
|
|
|
nsIView* childView;
|
|
|
|
nsIView* oldParentView;
|
|
|
|
nsIView* newParentView;
|
|
|
|
|
|
|
|
// This code is called often and we need it to be as fast as possible, so
|
|
|
|
// see if we can trivially detect that no work needs to be done
|
1999-10-26 04:44:41 +00:00
|
|
|
aChildFrame->GetView(aPresContext, &childView);
|
1999-08-24 19:26:03 +00:00
|
|
|
if (!childView) {
|
|
|
|
// Child frame doesn't have a view. See if it has any child frames
|
|
|
|
nsIFrame* firstChild;
|
|
|
|
aChildFrame->FirstChild(nsnull, &firstChild);
|
|
|
|
if (!firstChild) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if either the old parent frame or the new parent frame have a view
|
1999-10-26 04:44:41 +00:00
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
1999-08-24 19:26:03 +00:00
|
|
|
|
|
|
|
if (!oldParentView && !newParentView) {
|
|
|
|
// Walk up both the old parent frame and the new parent frame nodes
|
|
|
|
// stopping when we either find a common parent or views for one
|
|
|
|
// or both of the frames.
|
|
|
|
//
|
|
|
|
// This works well in the common case where we push/pull and the old parent
|
|
|
|
// frame and the new parent frame are part of the same flow. They will
|
|
|
|
// typically be the same distance (height wise) from the
|
|
|
|
do {
|
|
|
|
aOldParentFrame->GetParent(&aOldParentFrame);
|
|
|
|
aNewParentFrame->GetParent(&aNewParentFrame);
|
|
|
|
|
|
|
|
// We should never walk all the way to the root frame without finding
|
|
|
|
// a view
|
|
|
|
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
|
1999-04-11 04:22:00 +00:00
|
|
|
|
1999-08-24 19:26:03 +00:00
|
|
|
// See if we reached a common parent
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the views
|
1999-10-26 04:44:41 +00:00
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
1999-08-24 19:26:03 +00:00
|
|
|
} while (!(oldParentView || newParentView));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See if we found a common parent frame
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
// We found a common parent and there are no views between the old parent
|
|
|
|
// and the common parent or the new parent frame and the common parent.
|
|
|
|
// Because neither the old parent frame nor the new parent frame have views,
|
|
|
|
// then any child views don't need reparenting
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found views for one or both of the parent frames before we found a
|
|
|
|
// common parent
|
|
|
|
NS_ASSERTION(oldParentView || newParentView, "internal error");
|
|
|
|
if (!oldParentView) {
|
1999-10-26 04:44:41 +00:00
|
|
|
oldParentView = GetClosestViewFor(aPresContext, aOldParentFrame);
|
1999-08-24 19:26:03 +00:00
|
|
|
}
|
|
|
|
if (!newParentView) {
|
1999-10-26 04:44:41 +00:00
|
|
|
newParentView = GetClosestViewFor(aPresContext, aNewParentFrame);
|
1999-08-24 19:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if the old parent frame and the new parent frame are in the
|
|
|
|
// same view sub-hierarchy. If they are then we don't have to do
|
|
|
|
// anything
|
1999-04-11 04:22:00 +00:00
|
|
|
if (oldParentView != newParentView) {
|
1999-08-24 19:26:03 +00:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
oldParentView->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
|
|
|
|
// They're not so we need to reparent any child views
|
1999-10-26 04:44:41 +00:00
|
|
|
return ReparentFrameViewTo(aPresContext, aChildFrame, viewManager, newParentView,
|
1999-08-24 19:26:03 +00:00
|
|
|
oldParentView);
|
1999-04-11 04:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 02:29:31 +00:00
|
|
|
nsresult
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(nsIPresContext* aPresContext,
|
1998-09-23 02:29:31 +00:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
PRBool aForce)
|
|
|
|
{
|
|
|
|
nsIView* view;
|
1999-11-24 06:03:41 +00:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
1998-12-04 19:03:44 +00:00
|
|
|
// If we don't yet have a view, see if we need a view
|
1998-09-23 02:29:31 +00:00
|
|
|
if (nsnull == view) {
|
1998-12-04 19:03:44 +00:00
|
|
|
PRInt32 zIndex = 0;
|
1999-12-08 04:49:20 +00:00
|
|
|
PRBool autoZIndex = PR_FALSE;
|
1999-04-21 21:27:50 +00:00
|
|
|
PRBool fixedBackgroundAttachment = PR_FALSE;
|
1998-10-23 17:54:23 +00:00
|
|
|
|
1998-12-04 19:03:44 +00:00
|
|
|
// Get nsStyleColor and nsStyleDisplay
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*)
|
1998-10-14 21:31:41 +00:00
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Color);
|
1998-12-04 19:03:44 +00:00
|
|
|
const nsStyleDisplay* display = (const nsStyleDisplay*)
|
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Display);
|
1998-09-23 02:29:31 +00:00
|
|
|
|
1998-12-04 19:03:44 +00:00
|
|
|
if (color->mOpacity != 1.0f) {
|
1998-10-23 17:54:23 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: frame=%p opacity=%g",
|
1998-12-04 19:03:44 +00:00
|
|
|
aFrame, color->mOpacity));
|
1998-10-23 17:54:23 +00:00
|
|
|
aForce = PR_TRUE;
|
1998-09-23 02:29:31 +00:00
|
|
|
}
|
|
|
|
|
1999-04-21 22:08:01 +00:00
|
|
|
// See if the frame has a fixed background attachment
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == color->mBackgroundAttachment) {
|
|
|
|
aForce = PR_TRUE;
|
|
|
|
fixedBackgroundAttachment = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-12-04 19:03:44 +00:00
|
|
|
// See if the frame is being relatively positioned or absolutely
|
|
|
|
// positioned
|
1998-09-23 02:29:31 +00:00
|
|
|
if (!aForce) {
|
|
|
|
const nsStylePosition* position = (const nsStylePosition*)
|
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Position);
|
1998-12-04 19:03:44 +00:00
|
|
|
|
1998-09-23 02:29:31 +00:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == position->mPosition) {
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: frame=%p relatively positioned",
|
|
|
|
aFrame));
|
|
|
|
aForce = PR_TRUE;
|
1999-09-01 01:10:24 +00:00
|
|
|
|
|
|
|
// Get the z-index to use
|
|
|
|
if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
|
|
|
|
zIndex = position->mZIndex.GetIntValue();
|
1999-12-08 04:49:20 +00:00
|
|
|
|
|
|
|
} else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
|
|
|
|
autoZIndex = PR_TRUE;
|
1999-09-01 01:10:24 +00:00
|
|
|
}
|
1998-12-04 19:03:44 +00:00
|
|
|
|
1999-01-28 17:14:13 +00:00
|
|
|
} else if (position->IsAbsolutelyPositioned()) {
|
1998-12-04 19:03:44 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: frame=%p relatively positioned",
|
|
|
|
aFrame));
|
|
|
|
aForce = PR_TRUE;
|
|
|
|
|
1999-09-01 01:10:24 +00:00
|
|
|
// Get the z-index to use
|
1998-12-04 19:03:44 +00:00
|
|
|
if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
|
|
|
|
zIndex = position->mZIndex.GetIntValue();
|
1999-12-08 04:49:20 +00:00
|
|
|
|
|
|
|
} else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
|
|
|
|
autoZIndex = PR_TRUE;
|
1998-12-04 19:03:44 +00:00
|
|
|
}
|
1998-09-23 02:29:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-04 05:56:06 +00:00
|
|
|
// See if the frame is a scrolled frame
|
|
|
|
if (!aForce) {
|
|
|
|
nsIAtom* pseudoTag;
|
|
|
|
aStyleContext->GetPseudoType(pseudoTag);
|
1999-08-08 01:15:30 +00:00
|
|
|
if (pseudoTag == nsLayoutAtoms::scrolledContentPseudo) {
|
1998-12-04 19:03:44 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: scrolled frame=%p", aFrame));
|
1998-12-04 05:56:06 +00:00
|
|
|
aForce = PR_TRUE;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(pseudoTag);
|
|
|
|
}
|
|
|
|
|
1998-09-23 02:29:31 +00:00
|
|
|
if (aForce) {
|
|
|
|
// Create a view
|
|
|
|
nsIFrame* parent;
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
aFrame->GetParentWithView(aPresContext, &parent);
|
1998-09-23 02:29:31 +00:00
|
|
|
NS_ASSERTION(parent, "GetParentWithView failed");
|
1998-12-18 05:25:36 +00:00
|
|
|
nsIView* parentView;
|
1998-09-23 02:29:31 +00:00
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
parent->GetView(aPresContext, &parentView);
|
1998-12-18 05:25:36 +00:00
|
|
|
NS_ASSERTION(parentView, "no parent with view");
|
1998-09-23 02:29:31 +00:00
|
|
|
|
|
|
|
// Create a view
|
|
|
|
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
|
|
|
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
nsresult result = nsComponentManager::CreateInstance(kViewCID,
|
1998-09-23 02:29:31 +00:00
|
|
|
nsnull,
|
|
|
|
kIViewIID,
|
|
|
|
(void **)&view);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsIViewManager* viewManager;
|
1998-12-18 05:25:36 +00:00
|
|
|
parentView->GetViewManager(viewManager);
|
1998-09-23 02:29:31 +00:00
|
|
|
NS_ASSERTION(nsnull != viewManager, "null view manager");
|
|
|
|
|
1998-12-18 05:25:36 +00:00
|
|
|
// Initialize the view
|
1998-09-23 02:29:31 +00:00
|
|
|
nsRect bounds;
|
|
|
|
aFrame->GetRect(bounds);
|
1998-12-18 05:25:36 +00:00
|
|
|
view->Init(viewManager, bounds, parentView);
|
|
|
|
|
1999-04-21 22:08:01 +00:00
|
|
|
// If the frame has a fixed background attachment, then indicate that the
|
1999-09-26 20:40:29 +00:00
|
|
|
// view's contents should be repainted and not bitblt'd
|
1999-04-24 04:53:42 +00:00
|
|
|
if (fixedBackgroundAttachment) {
|
|
|
|
PRUint32 viewFlags;
|
|
|
|
view->GetViewFlags(&viewFlags);
|
|
|
|
view->SetViewFlags(viewFlags | NS_VIEW_PUBLIC_FLAG_DONT_BITBLT);
|
|
|
|
}
|
1999-04-21 22:08:01 +00:00
|
|
|
|
1998-12-18 05:25:36 +00:00
|
|
|
// Insert the view into the view hierarchy. If the parent view is a
|
|
|
|
// scrolling view we need to do this differently
|
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
if (NS_SUCCEEDED(parentView->QueryInterface(kScrollViewIID, (void**)&scrollingView))) {
|
|
|
|
scrollingView->SetScrolledView(view);
|
|
|
|
} else {
|
|
|
|
viewManager->InsertChild(parentView, view, zIndex);
|
1999-12-08 04:49:20 +00:00
|
|
|
|
|
|
|
if (autoZIndex) {
|
|
|
|
viewManager->SetViewAutoZIndex(view, PR_TRUE);
|
|
|
|
}
|
1998-12-18 05:25:36 +00:00
|
|
|
}
|
|
|
|
|
1999-09-26 20:40:29 +00:00
|
|
|
// See if the view should be hidden
|
|
|
|
PRBool viewIsVisible = PR_TRUE;
|
|
|
|
PRBool viewHasTransparentContent = (color->mBackgroundFlags &
|
|
|
|
NS_STYLE_BG_COLOR_TRANSPARENT) == NS_STYLE_BG_COLOR_TRANSPARENT;
|
|
|
|
|
1999-09-29 03:37:02 +00:00
|
|
|
if (NS_STYLE_VISIBILITY_COLLAPSE == display->mVisible) {
|
|
|
|
viewIsVisible = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_VISIBILITY_HIDDEN == display->mVisible) {
|
|
|
|
// If it has a widget, hide the view because the widget can't deal with it
|
|
|
|
nsIWidget* widget = nsnull;
|
|
|
|
view->GetWidget(widget);
|
|
|
|
if (widget) {
|
|
|
|
viewIsVisible = PR_FALSE;
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If it's a container element, then leave the view visible, but
|
|
|
|
// mark it as having transparent content. The reason we need to
|
|
|
|
// do this is that child elements can override their parent's
|
|
|
|
// hidden visibility and be visible anyway
|
|
|
|
nsIContent* content;
|
|
|
|
|
|
|
|
// Because this function is called before processing the content
|
|
|
|
// object's child elements, we can't tell if it's a leaf by looking
|
|
|
|
// at whether the frame has any child frames
|
|
|
|
aFrame->GetContent(&content);
|
|
|
|
if (content) {
|
|
|
|
PRBool isContainer;
|
|
|
|
|
|
|
|
content->CanContainChildren(isContainer);
|
|
|
|
if (isContainer) {
|
|
|
|
// The view needs to be visible, but marked as having transparent
|
|
|
|
// content
|
|
|
|
viewHasTransparentContent = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// Go ahead and hide the view
|
|
|
|
viewIsVisible = PR_FALSE;
|
|
|
|
}
|
|
|
|
NS_RELEASE(content);
|
1999-09-26 20:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewIsVisible) {
|
|
|
|
if (viewHasTransparentContent) {
|
|
|
|
viewManager->SetViewContentTransparency(view, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
view->SetVisibility(nsViewVisibility_kHide);
|
1998-10-14 21:31:41 +00:00
|
|
|
}
|
1999-05-19 22:14:11 +00:00
|
|
|
|
1999-09-15 04:16:31 +00:00
|
|
|
// XXX If it's fixed positioned, then create a widget so it floats
|
|
|
|
// above the scrolling area
|
1999-01-23 05:47:55 +00:00
|
|
|
const nsStylePosition* position = (const nsStylePosition*)
|
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Position);
|
|
|
|
|
1999-01-28 17:14:13 +00:00
|
|
|
if (NS_STYLE_POSITION_FIXED == position->mPosition) {
|
1999-12-01 05:10:50 +00:00
|
|
|
view->CreateWidget(kCChildCID);
|
1999-01-28 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
1998-12-04 19:03:44 +00:00
|
|
|
viewManager->SetViewOpacity(view, color->mOpacity);
|
1998-09-23 02:29:31 +00:00
|
|
|
NS_RELEASE(viewManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember our view
|
1999-11-24 06:03:41 +00:00
|
|
|
aFrame->SetView(aPresContext, view);
|
1998-09-23 02:29:31 +00:00
|
|
|
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: frame=%p view=%p",
|
|
|
|
aFrame));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|