2001-09-28 20:14:13 +00: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
|
2000-03-31 07:02:06 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +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/
|
2000-03-31 07:02:06 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +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.
|
2000-03-31 07:02:06 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00: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.
|
2000-03-31 07:02:06 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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 ***** */
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsContainerFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsPageFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsStackLayout.h"
|
2001-08-18 01:04:47 +00:00
|
|
|
#include "nsIRootBox.h"
|
2001-12-04 22:32:49 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsXULTooltipListener.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// Interface IDs
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
//#define DEBUG_REFLOW
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
|
2000-03-31 07:02:06 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
friend nsresult NS_NewBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
|
|
|
|
|
|
|
|
nsRootBoxFrame(nsIPresShell* aShell);
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
NS_IMETHOD GetPopupSetFrame(nsIFrame** aResult);
|
|
|
|
NS_IMETHOD SetPopupSetFrame(nsIFrame* aPopupSet);
|
2001-12-04 22:32:49 +00:00
|
|
|
NS_IMETHOD GetDefaultTooltip(nsIContent** aResult);
|
|
|
|
NS_IMETHOD SetDefaultTooltip(nsIContent* aTooltip);
|
|
|
|
NS_IMETHOD AddTooltipSupport(nsIContent* aNode);
|
|
|
|
NS_IMETHOD RemoveTooltipSupport(nsIContent* aNode);
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHOD AppendFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList);
|
|
|
|
NS_IMETHOD InsertFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList);
|
|
|
|
NS_IMETHOD RemoveFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame);
|
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus);
|
|
|
|
NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
nsIFrame** aFrame);
|
2001-05-25 15:00:51 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsLayoutAtoms::rootFrame
|
|
|
|
*/
|
|
|
|
NS_IMETHOD GetFrameType(nsIAtom** aType) const;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
|
|
|
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
|
|
|
#endif
|
2001-08-18 01:04:47 +00:00
|
|
|
|
|
|
|
nsIFrame* mPopupSetFrame;
|
2001-12-04 22:32:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIContent* mDefaultTooltip;
|
2000-03-31 07:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsRootBoxFrame* it = new (aPresShell) nsRootBoxFrame (aPresShell);
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewFrame = it;
|
2000-04-05 00:19:00 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell, PR_TRUE)
|
|
|
|
{
|
2001-08-18 01:04:47 +00:00
|
|
|
mPopupSetFrame = nsnull;
|
|
|
|
|
2000-04-05 00:19:00 +00:00
|
|
|
nsCOMPtr<nsIBoxLayout> layout;
|
|
|
|
NS_NewStackLayout(aShell, layout);
|
|
|
|
SetLayoutManager(layout);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::AppendFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!aListName, "unexpected child list name");
|
|
|
|
NS_PRECONDITION(mFrames.IsEmpty(), "already have a child frame");
|
|
|
|
if (aListName) {
|
|
|
|
// We only support unnamed principal child list
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else if (!mFrames.IsEmpty()) {
|
|
|
|
// We only allow a single child frame
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
rv = nsBoxFrame::AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::InsertFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Because we only support a single child frame inserting is the same
|
|
|
|
// as appending
|
|
|
|
NS_PRECONDITION(!aPrevFrame, "unexpected previous sibling frame");
|
|
|
|
if (aPrevFrame) {
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
} else {
|
|
|
|
rv = AppendFrames(aPresContext, aPresShell, aListName, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::RemoveFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!aListName, "unexpected child list name");
|
|
|
|
if (aListName) {
|
|
|
|
// We only support the unnamed principal child list
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
} else if (aOldFrame == mFrames.FirstChild()) {
|
|
|
|
rv = nsBoxFrame::RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
#ifdef DEBUG_REFLOW
|
|
|
|
PRInt32 gReflows = 0;
|
|
|
|
#endif
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::Reflow(nsIPresContext* aPresContext,
|
2002-05-28 22:50:43 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2000-04-21 14:59:47 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame", aReflowState.reason);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_REFLOW
|
|
|
|
gReflows++;
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("----Reflow %d----\n", gReflows);
|
2000-05-15 04:12:31 +00:00
|
|
|
#endif
|
2000-03-31 07:02:06 +00:00
|
|
|
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::HandleEvent(nsIPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP ||
|
|
|
|
aEvent->message == NS_MOUSE_MIDDLE_BUTTON_UP ||
|
|
|
|
aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP) {
|
|
|
|
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
// this should act like a block, so we need to override
|
|
|
|
return nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aWhichLayer, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::rootFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::GetPopupSetFrame(nsIFrame** aResult)
|
|
|
|
{
|
|
|
|
*aResult = mPopupSetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::SetPopupSetFrame(nsIFrame* aPopupSet)
|
|
|
|
{
|
2002-07-19 21:58:09 +00:00
|
|
|
NS_ASSERTION(!mPopupSetFrame, "Popup set is already defined! Only 1 allowed.");
|
|
|
|
if (!mPopupSetFrame)
|
|
|
|
mPopupSetFrame = aPopupSet;
|
2001-08-18 01:04:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-04 22:32:49 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::GetDefaultTooltip(nsIContent** aTooltip)
|
|
|
|
{
|
|
|
|
*aTooltip = mDefaultTooltip;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
|
|
|
|
{
|
|
|
|
mDefaultTooltip = aTooltip;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
// listener will be refcounted by dom event targets that
|
|
|
|
// it will add itself to, and destroyed when those targets
|
|
|
|
// are destroyed
|
|
|
|
nsXULTooltipListener* listener = new nsXULTooltipListener();
|
|
|
|
listener->Init(aNode, this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
|
|
|
|
{
|
|
|
|
// XXjh yuck, I'll have to implement a way to get at
|
|
|
|
// the tooltip listener for a given node to make
|
|
|
|
// this work. Not crucial, we aren't removing
|
|
|
|
// tooltips from any nodes in the app just yet.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsRootBoxFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsRootBoxFrame::Release(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsRootBoxFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRootBox)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
2001-11-14 01:33:42 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsRootBoxFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = sizeof(*this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|