This commit is contained in:
troy%netscape.com 1998-10-22 18:32:43 +00:00
Родитель 4202cd291f
Коммит d112632a40
1 изменённых файлов: 1 добавлений и 264 удалений

Просмотреть файл

@ -154,272 +154,9 @@ nsScrollViewFrame::ListTag(FILE* out) const
//----------------------------------------------------------------------
/**
* The scrolling view frame creates and manages the scrolling view.
* It creates a nsScrollViewFrame which handles padding and rendering
* of the background.
*/
class nsScrollingViewFrame : public nsHTMLContainerFrame {
public:
nsScrollingViewFrame(nsIContent* aContent, nsIFrame* aParent);
NS_IMETHOD Init(nsIPresContext& aPresContext, nsIFrame* aChildList);
NS_IMETHOD DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus);
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_IMETHOD ListTag(FILE* out = stdout) const;
protected:
virtual PRIntn GetSkipSides() const;
private:
nsresult CreateScrollingView();
};
nsScrollingViewFrame::nsScrollingViewFrame(nsIContent* aContent, nsIFrame* aParent)
: nsHTMLContainerFrame(aContent, aParent)
{
}
NS_IMETHODIMP
nsScrollingViewFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus)
{
nsresult rv = NS_OK;
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
// Send the DidReflow notification to the scrolled view frame
nsIHTMLReflow* htmlReflow;
mFirstChild->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow);
htmlReflow->DidReflow(aPresContext, aStatus);
// Size the scrolled view frame's view. Don't change its position
nsSize size;
nsIViewManager* vm;
nsIView* scrolledView;
mFirstChild->GetSize(size);
mFirstChild->GetView(scrolledView);
scrolledView->GetViewManager(vm);
vm->ResizeView(scrolledView, size.width, size.height);
NS_RELEASE(vm);
// Let the default nsFrame implementation clear the state flags
// and size and position our view
rv = nsFrame::DidReflow(aPresContext, aStatus);
}
return rv;
}
NS_IMETHODIMP
nsScrollingViewFrame::Init(nsIPresContext& aPresContext, nsIFrame* aChildList)
{
// Create a scroll view frame
mFirstChild = new nsScrollViewFrame(mContent, this);
if (nsnull == mFirstChild) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Have it use our style context
mFirstChild->SetStyleContext(&aPresContext, mStyleContext);
// Reset the child frame's geometric and content parent to be
// the scroll view frame
aChildList->SetGeometricParent(mFirstChild);
aChildList->SetContentParent(mFirstChild);
// Init the scroll view frame passing it the child list
return mFirstChild->Init(aPresContext, aChildList);
}
nsresult
nsScrollingViewFrame::CreateScrollingView()
{
nsIView* view;
// Get parent view
nsIFrame* parent;
GetParentWithView(parent);
NS_ASSERTION(parent, "GetParentWithView failed");
nsIView* parentView;
parent->GetView(parentView);
NS_ASSERTION(parentView, "GetParentWithView failed");
// Get the view manager
nsIViewManager* viewManager;
parentView->GetViewManager(viewManager);
// Create the scrolling view
nsresult rv = nsRepository::CreateInstance(kScrollingViewCID,
nsnull,
kIViewIID,
(void **)&view);
if (NS_OK == rv) {
// Get the native widget that should be used as the parent for
// the scrolling view's scrollbar child widgets. Note that we can't
// use the scrolling view's widget as the parent of the scrollbar
// widgets
nsIWidget* window;
nsNativeWidget nativeWidget;
GetWindow(window);
nativeWidget = window->GetNativeData(NS_NATIVE_WINDOW);
NS_RELEASE(window);
// Initialize the scrolling view
view->Init(viewManager, mRect, parentView, &kWidgetCID,
nsnull, nativeWidget);
// Insert the view into the view hierarchy
viewManager->InsertChild(parentView, view, 0);
// If the background is transparent then inform the view manager
const nsStyleColor* color = (const nsStyleColor*)
mStyleContext->GetStyleData(eStyleStruct_Color);
PRBool isTransparent = (NS_STYLE_BG_COLOR_TRANSPARENT & color->mBackgroundFlags);
if (isTransparent) {
viewManager->SetViewContentTransparency(view, PR_TRUE);
}
// Remember our view
SetView(view);
// Create a view for the scroll view frame
nsIView* scrolledView;
rv = nsRepository::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&scrolledView);
if (NS_OK == rv) {
// Bind the view to the frame
mFirstChild->SetView(scrolledView);
// Initialize the view
scrolledView->Init(viewManager, nsRect(0, 0, 0, 0), parentView);
// Set it as the scrolling view's scrolled view
nsIScrollableView* scrollingView;
view->QueryInterface(kScrollViewIID, (void**)&scrollingView);
scrollingView->SetScrolledView(scrolledView);
// If the background is transparent then inform the view manager
if (isTransparent) {
viewManager->SetViewContentTransparency(scrolledView, PR_TRUE);
}
// We need to allow the view's position to be different than the
// frame's position
nsFrameState state;
mFirstChild->GetFrameState(state);
state &= ~NS_FRAME_SYNC_FRAME_AND_VIEW;
mFirstChild->SetFrameState(state);
}
}
NS_RELEASE(viewManager);
return rv;
}
//XXX incremental reflow pass through
NS_IMETHODIMP
nsScrollingViewFrame::Reflow(nsIPresContext& aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
NS_FRAME_TRACE_MSG(NS_FRAME_TRACE_CALLS,
("enter nsScrollingViewFrame::Reflow: maxSize=%d,%d",
aReflowState.maxSize.width,
aReflowState.maxSize.height));
// If it's out initial reflow then create a scrolling view
if (eReflowReason_Initial == aReflowState.reason) {
CreateScrollingView();
}
// Reflow the child and get its desired size. Let the child's height be
// whatever it wants
nsHTMLReflowState kidReflowState(aPresContext, mFirstChild, aReflowState,
nsSize(aReflowState.maxSize.width, NS_UNCONSTRAINEDSIZE));
ReflowChild(mFirstChild, aPresContext, aDesiredSize, kidReflowState, aStatus);
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");
// If our height is constrained then make sure the scroll view is at least as
// high as we're going to be
if (NS_UNCONSTRAINEDSIZE != aReflowState.maxSize.height) {
// Make sure we're at least as tall as the max height we were given
if (aDesiredSize.height < aReflowState.maxSize.height) {
aDesiredSize.height = aReflowState.maxSize.height;
}
}
// Place and size the child
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
mFirstChild->SetRect(rect);
// The scroll view frame either shrink wraps around it's single
// child OR uses the style width/height.
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.width = aReflowState.minWidth;
}
if (aReflowState.HaveConstrainedHeight()) {
aDesiredSize.height = aReflowState.minHeight;
}
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
NS_FRAME_TRACE_MSG(NS_FRAME_TRACE_CALLS,
("exit nsScrollingViewFrame::Reflow: status=%d width=%d height=%d",
aStatus, aDesiredSize.width, aDesiredSize.height));
return NS_OK;
}
NS_IMETHODIMP
nsScrollingViewFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
// Paint our children
return nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
}
PRIntn
nsScrollingViewFrame::GetSkipSides() const
{
return 0;
}
NS_IMETHODIMP
nsScrollingViewFrame::ListTag(FILE* out) const
{
fputs("*scrollingviewframe<", out);
nsIAtom* atom;
mContent->GetTag(atom);
if (nsnull != atom) {
nsAutoString tmp;
atom->ToString(tmp);
fputs(tmp, out);
NS_RELEASE(atom);
}
fprintf(out, ">(%d)@%p", ContentIndexInContainer(this), this);
return NS_OK;
}
//----------------------------------------------------------------------
/**
* The scroll frame creates and manages the scrolling view. It creates
* a nsScrollingViewFrame which handles padding and rendering of the
* a nsScrollViewFrame which handles padding and rendering of the
* background.
*/
class nsScrollFrame : public nsHTMLContainerFrame {