1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-05-03 07:51:48 +04:00
|
|
|
#include "nsIPresShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1998-05-05 08:47:53 +04:00
|
|
|
#include "nsIPtr.h"
|
|
|
|
#include "nsAbsoluteFrame.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsIContentDelegate.h"
|
1998-05-29 06:13:25 +04:00
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLParts.h"
|
1998-06-11 20:46:33 +04:00
|
|
|
#include "nsHTMLBase.h"
|
1998-06-04 21:50:19 +04:00
|
|
|
#include "nsScrollFrame.h"
|
|
|
|
#include "nsIView.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-05 08:47:53 +04:00
|
|
|
NS_DEF_PTR(nsIStyleContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-06 03:56:50 +04:00
|
|
|
nsHTMLContainerFrame::nsHTMLContainerFrame(nsIContent* aContent, nsIFrame* aParent)
|
|
|
|
: nsContainerFrame(aContent, aParent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLContainerFrame::~nsHTMLContainerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsHTMLContainerFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-28 08:38:28 +04:00
|
|
|
// Paint our background and border
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
1998-05-27 03:15:47 +04:00
|
|
|
|
1998-06-04 21:50:19 +04:00
|
|
|
if (disp->mVisible && mRect.width && mRect.height) {
|
1998-05-28 08:38:28 +04:00
|
|
|
PRIntn skipSides = GetSkipSides();
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleColor* color =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-28 08:38:28 +04:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, mRect, *color);
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, mRect, *spacing, skipSides);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect);
|
|
|
|
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
1998-06-04 21:50:19 +04:00
|
|
|
nsIView* view;
|
|
|
|
GetView(view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
|
|
|
NS_RELEASE(view);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsHTMLContainerFrame::HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-08 04:57:15 +04:00
|
|
|
return nsContainerFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsHTMLContainerFrame::GetCursorAt(nsIPresContext& aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsIFrame** aFrame,
|
|
|
|
PRInt32& aCursor)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-04-25 22:40:01 +04:00
|
|
|
// Get my cursor
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleColor* styleColor = (const nsStyleColor*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Color);
|
1998-04-25 22:40:01 +04:00
|
|
|
PRInt32 myCursor = styleColor->mCursor;
|
|
|
|
|
|
|
|
// Get child's cursor, if any
|
|
|
|
nsresult rv = nsContainerFrame::GetCursorAt(aPresContext, aPoint, aFrame,
|
|
|
|
aCursor);
|
|
|
|
if (NS_OK != rv) return rv;
|
|
|
|
if (aCursor != NS_STYLE_CURSOR_INHERIT) {
|
|
|
|
nsIAtom* tag = mContent->GetTag();
|
|
|
|
if (nsHTMLAtoms::a == tag) {
|
|
|
|
// Anchor tags override their child cursors in some cases.
|
|
|
|
if ((NS_STYLE_CURSOR_IBEAM == aCursor) &&
|
|
|
|
(NS_STYLE_CURSOR_INHERIT != myCursor)) {
|
|
|
|
aCursor = myCursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_STYLE_CURSOR_INHERIT != myCursor) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// If this container has a particular cursor, use it, otherwise
|
|
|
|
// let the child decide.
|
|
|
|
*aFrame = this;
|
1998-04-25 22:40:01 +04:00
|
|
|
aCursor = myCursor;
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-04-25 22:40:01 +04:00
|
|
|
|
|
|
|
// No specific cursor for us
|
|
|
|
aCursor = NS_STYLE_CURSOR_INHERIT;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-03 07:51:48 +04:00
|
|
|
NS_METHOD nsHTMLContainerFrame::ContentAppended(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer)
|
|
|
|
{
|
|
|
|
// Get the last-in-flow
|
|
|
|
nsHTMLContainerFrame* lastInFlow = (nsHTMLContainerFrame*)GetLastInFlow();
|
|
|
|
|
|
|
|
// Generate a reflow command for the frame
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIReflowCommand* cmd;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
result = NS_NewHTMLReflowCommand(&cmd, lastInFlow, nsIReflowCommand::FrameAppended);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
aShell->AppendReflowCommand(cmd);
|
|
|
|
NS_RELEASE(cmd);
|
|
|
|
}
|
|
|
|
|
1998-05-03 07:51:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-04 21:54:45 +04:00
|
|
|
static PRBool
|
|
|
|
HasSameMapping(nsIFrame* aFrame, nsIContent* aContent)
|
1998-05-03 07:51:48 +04:00
|
|
|
{
|
1998-05-04 21:54:45 +04:00
|
|
|
nsIContent* content;
|
|
|
|
PRBool result;
|
|
|
|
|
|
|
|
aFrame->GetContent(content);
|
|
|
|
result = content == aContent;
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-07-03 21:46:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLContainerFrame::ContentInserted(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInParent)
|
1998-05-04 21:54:45 +04:00
|
|
|
{
|
1998-07-03 21:46:44 +04:00
|
|
|
NS_ASSERTION(!IsPseudoFrame(), "pseudos not supported here");
|
1998-05-03 07:51:48 +04:00
|
|
|
|
1998-07-03 21:46:44 +04:00
|
|
|
// Find the frame that precedes the insertion point
|
1998-05-05 08:47:53 +04:00
|
|
|
nsIFrame* prevSibling = nsnull;
|
|
|
|
if (aIndexInParent > 0) {
|
|
|
|
nsIContent* precedingContent = aContainer->ChildAt(aIndexInParent - 1);
|
|
|
|
prevSibling = aShell->FindFrameWithContent(precedingContent);
|
|
|
|
NS_RELEASE(precedingContent);
|
|
|
|
|
|
|
|
// The frame may have a next-in-flow. Get the last-in-flow
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
do {
|
|
|
|
prevSibling->GetNextInFlow(nextInFlow);
|
|
|
|
if (nsnull != nextInFlow) {
|
|
|
|
prevSibling = nextInFlow;
|
|
|
|
}
|
|
|
|
} while (nsnull != nextInFlow);
|
|
|
|
}
|
|
|
|
|
1998-07-03 21:46:44 +04:00
|
|
|
// Get the geometric parent for the prevSibling. We expect it to be
|
|
|
|
// this frame or one of its next-in-flow(s).
|
|
|
|
nsHTMLContainerFrame* flow = this;
|
1998-05-05 08:47:53 +04:00
|
|
|
if (nsnull != prevSibling) {
|
1998-07-03 21:46:44 +04:00
|
|
|
prevSibling->GetGeometricParent((nsIFrame*&)flow);
|
1998-05-05 08:47:53 +04:00
|
|
|
}
|
|
|
|
|
1998-07-03 21:46:44 +04:00
|
|
|
// Create the new frame as a child of the same parent as prevSibling
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIFrame* newFrame;
|
1998-07-03 21:46:44 +04:00
|
|
|
nsresult rv = nsHTMLBase::CreateFrame(aPresContext, flow, aChild, nsnull,
|
1998-06-26 19:07:09 +04:00
|
|
|
newFrame);
|
1998-05-07 04:08:20 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-03 21:46:44 +04:00
|
|
|
flow->mChildCount++;
|
1998-05-05 08:47:53 +04:00
|
|
|
|
1998-07-03 21:46:44 +04:00
|
|
|
// Place the new frame into the parents sibling list
|
1998-05-05 08:47:53 +04:00
|
|
|
if (nsnull == prevSibling) {
|
1998-07-03 21:46:44 +04:00
|
|
|
newFrame->SetNextSibling(flow->mFirstChild);
|
|
|
|
flow->mFirstChild = newFrame;
|
|
|
|
}
|
|
|
|
else {
|
1998-05-05 08:47:53 +04:00
|
|
|
nsIFrame* nextSibling;
|
|
|
|
prevSibling->GetNextSibling(nextSibling);
|
|
|
|
newFrame->SetNextSibling(nextSibling);
|
|
|
|
prevSibling->SetNextSibling(newFrame);
|
|
|
|
if (nsnull == nextSibling) {
|
1998-07-03 21:46:44 +04:00
|
|
|
// newFrame ended up being flow's last child
|
|
|
|
flow->mLastContentIsComplete = PR_TRUE;
|
1998-05-05 08:47:53 +04:00
|
|
|
}
|
|
|
|
}
|
1998-07-03 21:46:44 +04:00
|
|
|
flow->mLastContentOffset++;
|
1998-05-05 08:47:53 +04:00
|
|
|
|
|
|
|
// Generate a reflow command
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIReflowCommand* cmd;
|
1998-07-03 21:46:44 +04:00
|
|
|
rv = NS_NewHTMLReflowCommand(&cmd, flow,
|
|
|
|
nsIReflowCommand::FrameInserted,
|
1998-06-09 08:51:44 +04:00
|
|
|
newFrame);
|
1998-07-03 21:46:44 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aShell->AppendReflowCommand(cmd);
|
|
|
|
NS_RELEASE(cmd);
|
|
|
|
|
|
|
|
// Fix up the next-in-flows of parent now that it has a new child
|
|
|
|
flow = (nsHTMLContainerFrame*) flow->mNextInFlow;
|
|
|
|
while (nsnull != flow) {
|
|
|
|
flow->mFirstContentOffset++;
|
|
|
|
flow->mLastContentOffset++;
|
1998-06-09 08:51:44 +04:00
|
|
|
}
|
|
|
|
return rv;
|
1998-05-03 07:51:48 +04:00
|
|
|
}
|
|
|
|
|
1998-05-29 06:13:25 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLContainerFrame::ProcessInitialReflow(nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-25 20:33:10 +04:00
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
const nsStyleDisplay* display = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::ProcessInitialReflow: display=%d",
|
|
|
|
display->mDisplay));
|
|
|
|
if (NS_STYLE_DISPLAY_LIST_ITEM == display->mDisplay) {
|
|
|
|
// This container is a list-item container. Therefore it needs a
|
|
|
|
// bullet content object.
|
|
|
|
nsIHTMLContent* bullet;
|
|
|
|
nsresult rv = NS_NewHTMLBullet(&bullet);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-25 20:33:10 +04:00
|
|
|
// Insert the bullet. Do not allow an incremental reflow operation
|
|
|
|
// to occur.
|
|
|
|
mContent->InsertChildAt(bullet, 0, PR_FALSE);
|
|
|
|
}
|
1998-05-29 06:13:25 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-29 06:13:25 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|