зеркало из https://github.com/mozilla/gecko-dev.git
Starting to pay attention to CSS positioning properties
This commit is contained in:
Родитель
42943b6cf9
Коммит
4366741d31
|
@ -15,12 +15,21 @@
|
|||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#include "nsAbsoluteFrame.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentDelegate.h"
|
||||
#include "nsViewsCID.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsAbsoluteFrame.h"
|
||||
#include "nsBodyFrame.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsViewsCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kStylePositionSID, NS_STYLEPOSITION_SID);
|
||||
|
||||
NS_DEF_PTR(nsIStyleContext);
|
||||
|
||||
nsresult
|
||||
AbsoluteFrame::NewFrame(nsIFrame** aInstancePtrResult,
|
||||
|
@ -52,6 +61,39 @@ AbsoluteFrame::~AbsoluteFrame()
|
|||
{
|
||||
}
|
||||
|
||||
nsIView* AbsoluteFrame::CreateView(const nsRect& aRect)
|
||||
{
|
||||
nsIFrame* parent;
|
||||
nsIView* parentView;
|
||||
nsIView* view;
|
||||
|
||||
// Create a view for the frame and position it
|
||||
// XXX This isn't correct. We should look for a containing frame that is absolutely
|
||||
// positioned and use its local coordinate system, or the root content frame
|
||||
GetParentWithView(parent);
|
||||
parent->GetView(parentView);
|
||||
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
||||
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
||||
|
||||
nsresult result = NSRepository::CreateInstance(kViewCID,
|
||||
nsnull,
|
||||
kIViewIID,
|
||||
(void **)&view);
|
||||
if (NS_OK == result) {
|
||||
nsIViewManager* viewManager = parentView->GetViewManager();
|
||||
|
||||
// Initialize the view
|
||||
NS_ASSERTION(nsnull != viewManager, "null view manager");
|
||||
|
||||
view->Init(viewManager, aRect, parentView);
|
||||
viewManager->InsertChild(parentView, view, 0);
|
||||
|
||||
NS_RELEASE(viewManager);
|
||||
}
|
||||
NS_RELEASE(parentView);
|
||||
return view;
|
||||
}
|
||||
|
||||
NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext,
|
||||
nsReflowMetrics& aDesiredSize,
|
||||
const nsSize& aMaxSize,
|
||||
|
@ -60,60 +102,87 @@ NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext,
|
|||
{
|
||||
// Have we created the absolutely positioned item yet?
|
||||
if (nsnull == mFrame) {
|
||||
// Create the absolutely positioned item as a pseudo-frame child. We'll
|
||||
// also create a view
|
||||
nsIContentDelegate* delegate = mContent->GetDelegate(aPresContext);
|
||||
// If the content object is a container then wrap it in a body pseudo-frame
|
||||
if (mContent->CanContainChildren()) {
|
||||
nsBodyFrame::NewFrame(&mFrame, mContent, mIndexInParent, this);
|
||||
|
||||
mFrame= delegate->CreateFrame(aPresContext, mContent, mIndexInParent, this);
|
||||
NS_RELEASE(delegate);
|
||||
// Resolve style for the pseudo-frame. We can't use our style context
|
||||
nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, this);
|
||||
mFrame->SetStyleContext(styleContext);
|
||||
|
||||
// Set the style context for the frame
|
||||
mFrame->SetStyleContext(mStyleContext);
|
||||
} else {
|
||||
// Create the absolutely positioned item as a pseudo-frame child. We'll
|
||||
// also create a view
|
||||
nsIContentDelegate* delegate = mContent->GetDelegate(aPresContext);
|
||||
|
||||
mFrame= delegate->CreateFrame(aPresContext, mContent, mIndexInParent, this);
|
||||
NS_RELEASE(delegate);
|
||||
|
||||
// Set the style context for the frame
|
||||
mFrame->SetStyleContext(mStyleContext);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Get the containing block
|
||||
nsIFrame* containingBlock = GetContainingBlock();
|
||||
|
||||
// Determine the view's rect
|
||||
nsRect rect;
|
||||
|
||||
ComputeViews
|
||||
#endif
|
||||
|
||||
// Compute the offset and size for the view based on the position properties
|
||||
nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID);
|
||||
nsRect rect;
|
||||
|
||||
if (NS_STYLE_POSITION_VALUE_AUTO == position->mLeftOffsetFlags) {
|
||||
rect.x = 0;
|
||||
|
||||
// Left offset should be automatically computed
|
||||
if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) {
|
||||
// When all three properties are 'auto' the width is the same as the
|
||||
// width of the containing block
|
||||
rect.width = 3500; // XXX Fix me
|
||||
} else {
|
||||
rect.width = position->mWidth;
|
||||
// rect.x = containingRect->width - rect.width;
|
||||
}
|
||||
} else {
|
||||
rect.x = position->mLeftOffset;
|
||||
// rect.width = containingRect->width - rect.x;
|
||||
}
|
||||
|
||||
// Create a view for the frame
|
||||
nsIView* view = CreateView(rect);
|
||||
mFrame->SetView(view);
|
||||
NS_RELEASE(view);
|
||||
|
||||
// Resize reflow the anchored item into the available space
|
||||
mFrame->ResizeReflow(aPresContext, aDesiredSize, aMaxSize, nsnull, aStatus);
|
||||
mFrame->SizeTo(aDesiredSize.width, aDesiredSize.height);
|
||||
|
||||
// Create a view for the frame and position it
|
||||
// XXX This isn't correct. We should look for a containing frame that is absolutely
|
||||
// positioned and use its local coordinate system, or the root content frame
|
||||
nsIFrame* parent;
|
||||
nsIView* parentView;
|
||||
nsIView* view;
|
||||
|
||||
GetParentWithView(parent);
|
||||
parent->GetView(parentView);
|
||||
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
||||
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
||||
|
||||
nsresult result = NSRepository::CreateInstance(kViewCID,
|
||||
nsnull,
|
||||
kIViewIID,
|
||||
(void **)&view);
|
||||
if (NS_OK == result) {
|
||||
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
||||
nsIViewManager* viewManager = parentView->GetViewManager();
|
||||
|
||||
// Initialize the view
|
||||
NS_ASSERTION(nsnull != viewManager, "null view manager");
|
||||
|
||||
view->Init(viewManager, rect, parentView);
|
||||
viewManager->InsertChild(parentView, view, 0);
|
||||
|
||||
NS_RELEASE(viewManager);
|
||||
mFrame->SetView(view);
|
||||
NS_RELEASE(view);
|
||||
}
|
||||
NS_RELEASE(parentView);
|
||||
}
|
||||
|
||||
// Return our desired size as (0, 0)
|
||||
return nsFrame::ResizeReflow(aPresContext, aDesiredSize, aMaxSize, aMaxElementSize, aStatus);
|
||||
}
|
||||
|
||||
NS_METHOD AbsoluteFrame::ListTag(FILE* out) const
|
||||
NS_METHOD AbsoluteFrame::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
// Indent
|
||||
for (PRInt32 i = aIndent; --i >= 0; ) fputs(" ", out);
|
||||
|
||||
// Output the tag
|
||||
fputs("*absolute", out);
|
||||
fprintf(out, "(%d)@%p", mIndexInParent, this);
|
||||
fprintf(out, "(%d)@%p ", mIndexInParent, this);
|
||||
|
||||
// Output the rect
|
||||
out << mRect;
|
||||
|
||||
// List the absolutely positioned frame
|
||||
fputs("<\n", out);
|
||||
mFrame->List(out, aIndent + 1);
|
||||
fputs(">\n", out);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
const nsSize& aMaxSize,
|
||||
nsSize* aMaxElementSize,
|
||||
ReflowStatus& aStatus);
|
||||
NS_IMETHOD ListTag(FILE* out = stdout) const;
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
protected:
|
||||
nsIFrame* mFrame; // the actual absolutely positioned frame
|
||||
|
@ -51,6 +52,8 @@ protected:
|
|||
nsIFrame* aParent);
|
||||
|
||||
virtual ~AbsoluteFrame();
|
||||
|
||||
nsIView* CreateView(const nsRect& aRect);
|
||||
};
|
||||
|
||||
#endif /* nsAbsoluteFrame_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче