1998-09-09 02:34:40 +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 "nsHTMLParts.h"
|
|
|
|
#include "nsContainerFrame.h"
|
1998-09-26 03:39:06 +04:00
|
|
|
#include "nsCSSRendering.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIReflowCommand.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsViewsCID.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsPageFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
1998-10-19 04:44:28 +04:00
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
|
|
|
|
// Interface IDs
|
|
|
|
static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-10-30 08:18:59 +03:00
|
|
|
class RootFrame : public nsHTMLContainerFrame {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
|
|
|
RootFrame(nsIContent* aContent);
|
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList);
|
1998-10-02 08:10:00 +04:00
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus);
|
1998-09-26 03:47:59 +04:00
|
|
|
NS_IMETHOD IsPercentageBase(PRBool& aBase) const {
|
|
|
|
aBase = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-30 08:18:59 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual PRIntn GetSkipSides() const;
|
1998-09-09 02:34:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLFrame(nsIContent* aContent, nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aResult)
|
|
|
|
{
|
|
|
|
RootFrame* frame = new RootFrame(aContent);
|
|
|
|
if (nsnull == frame) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aResult = frame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RootFrame::RootFrame(nsIContent* aContent)
|
1998-10-30 08:18:59 +03:00
|
|
|
: nsHTMLContainerFrame(aContent, nsnull)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHODIMP
|
1998-11-10 09:05:32 +03:00
|
|
|
RootFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1998-09-10 23:32:14 +04:00
|
|
|
{
|
1998-10-30 02:25:02 +03:00
|
|
|
mFirstChild = aChildList;
|
|
|
|
return NS_OK;
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-02 08:10:00 +04:00
|
|
|
RootFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
NS_FRAME_TRACE_REFLOW_IN("RootFrame::Reflow");
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
// We don't expect the target of the reflow command to be the root frame
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "no reflow command");
|
|
|
|
|
|
|
|
nsIFrame* target;
|
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
|
|
|
NS_ASSERTION(target != this, "root frame is reflow command target");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Verify that the next frame in the reflow chain is our pseudo frame
|
|
|
|
nsIFrame* next;
|
|
|
|
aReflowState.reflowCommand->GetNext(next);
|
|
|
|
NS_ASSERTION(next == mFirstChild, "unexpected next reflow command frame");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow our pseudo frame. It will choose whetever height its child frame
|
|
|
|
// wants
|
|
|
|
if (nsnull != mFirstChild) {
|
1998-10-30 08:18:59 +03:00
|
|
|
// Compute how much space to reserve for our border and padding
|
|
|
|
const nsStyleSpacing* spacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
|
|
nsMargin borderPadding;
|
|
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
|
|
|
|
nsSize kidMaxSize(aReflowState.maxSize);
|
|
|
|
kidMaxSize.width -= borderPadding.left + borderPadding.right;
|
|
|
|
kidMaxSize.height -= borderPadding.top + borderPadding.bottom;
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
1998-10-12 18:48:02 +04:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, mFirstChild, aReflowState,
|
1998-10-30 08:18:59 +03:00
|
|
|
kidMaxSize);
|
1998-10-30 02:25:02 +03:00
|
|
|
// XXX HACK
|
|
|
|
kidReflowState.widthConstraint = eHTMLFrameConstraint_Fixed;
|
1998-10-30 08:18:59 +03:00
|
|
|
kidReflowState.minWidth = kidMaxSize.width;
|
1998-10-30 02:25:02 +03:00
|
|
|
kidReflowState.heightConstraint = eHTMLFrameConstraint_Fixed;
|
1998-10-30 08:18:59 +03:00
|
|
|
kidReflowState.minHeight = kidMaxSize.height;
|
1998-10-12 18:48:02 +04:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
1998-10-01 08:46:11 +04:00
|
|
|
|
|
|
|
if (NS_OK == mFirstChild->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
1998-10-06 04:27:22 +04:00
|
|
|
ReflowChild(mFirstChild, aPresContext, desiredSize, kidReflowState, aStatus);
|
1998-10-01 08:46:11 +04:00
|
|
|
|
|
|
|
// Place and size the child
|
1998-10-30 08:18:59 +03:00
|
|
|
nsRect rect(borderPadding.left, borderPadding.top, desiredSize.width, desiredSize.height);
|
1998-10-01 08:46:11 +04:00
|
|
|
mFirstChild->SetRect(rect);
|
1998-10-06 04:27:22 +04:00
|
|
|
|
|
|
|
// XXX We should resolve the details of who/when DidReflow() notifications
|
|
|
|
// are sent...
|
1998-10-01 08:46:11 +04:00
|
|
|
htmlReflow->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
|
|
|
}
|
1998-10-31 07:40:01 +03:00
|
|
|
|
|
|
|
// If this is a resize reflow and we have non-zero border or padding
|
|
|
|
// then do a repaint to make sure we repaint correctly.
|
|
|
|
// XXX We could be smarter about only damaging the border/padding area
|
|
|
|
// that was affected by the resize...
|
|
|
|
if ((eReflowReason_Resize == aReflowState.reason) &&
|
|
|
|
((borderPadding.left != 0) || (borderPadding.top != 0) ||
|
|
|
|
(borderPadding.right != 0) || (borderPadding.bottom) != 0)) {
|
|
|
|
nsRect damageRect(0, 0, aReflowState.maxSize.width, aReflowState.maxSize.height);
|
|
|
|
Invalidate(damageRect, PR_FALSE);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the max size as our desired size
|
|
|
|
aDesiredSize.width = aReflowState.maxSize.width;
|
|
|
|
aDesiredSize.height = aReflowState.maxSize.height;
|
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
|
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("RootFrame::Reflow", aStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-30 08:18:59 +03:00
|
|
|
PRIntn
|
|
|
|
RootFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RootFrame::HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
|
|
|
mContent->HandleDOMEvent(aPresContext, (nsEvent*)aEvent, nsnull, DOM_EVENT_INIT, aEventStatus);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (aEventStatus != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
{
|
|
|
|
nsIFrame* target = this;
|
|
|
|
PRInt32 cursor;
|
|
|
|
|
|
|
|
GetCursorAndContentAt(aPresContext, aEvent->point, &target, &mContent, cursor);
|
|
|
|
if (cursor == NS_STYLE_CURSOR_INHERIT) {
|
|
|
|
cursor = NS_STYLE_CURSOR_DEFAULT;
|
|
|
|
}
|
|
|
|
nsCursor c;
|
|
|
|
switch (cursor) {
|
|
|
|
default:
|
|
|
|
case NS_STYLE_CURSOR_DEFAULT:
|
|
|
|
c = eCursor_standard;
|
|
|
|
break;
|
1998-10-27 02:14:17 +03:00
|
|
|
case NS_STYLE_CURSOR_POINTER:
|
1998-09-09 02:34:40 +04:00
|
|
|
c = eCursor_hyperlink;
|
|
|
|
break;
|
1998-10-27 02:14:17 +03:00
|
|
|
case NS_STYLE_CURSOR_TEXT:
|
1998-09-09 02:34:40 +04:00
|
|
|
c = eCursor_select;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIWidget* window;
|
|
|
|
target->GetWindow(window);
|
|
|
|
window->SetCursor(c);
|
|
|
|
NS_RELEASE(window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|