added auto collapse.
This commit is contained in:
evaughan%netscape.com 1999-09-14 22:17:19 +00:00
Родитель bec9503c6c
Коммит cc94b6273b
12 изменённых файлов: 230 добавлений и 78 удалений

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

@ -33,6 +33,18 @@ nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext)
ReResolveStyles(aPresContext, 0, nsnull, nsnull);
}
nsIFrame*
nsButtonFrameRenderer::GetFrame()
{
return mFrame;
}
PRInt32
nsButtonFrameRenderer::GetNameSpace()
{
return mNameSpace;
}
void
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
{

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

@ -92,6 +92,9 @@ public:
virtual void Redraw();
virtual nsIFrame* GetFrame();
virtual PRInt32 GetNameSpace();
protected:
private:

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

@ -35,8 +35,8 @@ class nsISupportsArray;
* or remove the scrolled frame
*/
class nsGfxScrollFrame : public nsHTMLContainerFrame,
nsIAnonymousContentCreator,
nsIDocumentObserver {
public nsIAnonymousContentCreator,
public nsIDocumentObserver {
public:
friend nsresult NS_NewGfxScrollFrame(nsIFrame** aNewFrame);

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

@ -35,8 +35,8 @@ class nsISupportsArray;
* or remove the scrolled frame
*/
class nsGfxScrollFrame : public nsHTMLContainerFrame,
nsIAnonymousContentCreator,
nsIDocumentObserver {
public nsIAnonymousContentCreator,
public nsIDocumentObserver {
public:
friend nsresult NS_NewGfxScrollFrame(nsIFrame** aNewFrame);

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

@ -33,6 +33,18 @@ nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsIPresContext& aPresContext)
ReResolveStyles(aPresContext, 0, nsnull, nsnull);
}
nsIFrame*
nsButtonFrameRenderer::GetFrame()
{
return mFrame;
}
PRInt32
nsButtonFrameRenderer::GetNameSpace()
{
return mNameSpace;
}
void
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
{

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

@ -92,6 +92,9 @@ public:
virtual void Redraw();
virtual nsIFrame* GetFrame();
virtual PRInt32 GetNameSpace();
protected:
private:

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

@ -1672,6 +1672,11 @@ nsBoxDebugInner::PaintSprings(nsIPresContext& aPresContext, nsIRenderingContext&
const nsStyleColor* debugColor =
(const nsStyleColor*)debugStyle->GetStyleData(eStyleStruct_Color);
nsMargin margin(0,0,0,0);
debugSpacing->GetMargin(margin);
border += margin;
nsRect inner(0,0,mOuter->mRect.width, mOuter->mRect.height);
inner.Deflate(border);
@ -1696,12 +1701,12 @@ nsBoxDebugInner::PaintSprings(nsIPresContext& aPresContext, nsIRenderingContext&
x = inner.x;
y = inner.y + onePixel;
x += debugBorder.left;
springSize = debugBorder.top - onePixel*2;
springSize = debugBorder.top - onePixel*4;
} else {
x = inner.y;
y = inner.x + onePixel;
x += debugBorder.top;
springSize = debugBorder.left - onePixel*2;
springSize = debugBorder.left - onePixel*4;
}
for (int i=0; i < mOuter->mSpringCount; i++) {
@ -1830,6 +1835,9 @@ nsBoxFrameInner::GetDebugInset(nsMargin& inset)
(const nsStyleSpacing*)style->GetStyleData(eStyleStruct_Spacing);
debugSpacing->GetBorderPadding(inset);
nsMargin margin(0,0,0,0);
debugSpacing->GetMargin(margin);
inset += margin;
}
}

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

@ -44,6 +44,8 @@
#include "nsFrameNavigator.h"
#include "nsHTMLParts.h"
#include "nsIPresShell.h"
#include "nsIStyleContext.h"
#include "nsWidgetsCID.h"
const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32
@ -114,6 +116,7 @@ public:
enum ResizeType { Closest, Farthest, Grow };
enum State { Open, Collapsed, Dragging };
enum CollapseDirection { Before, After, None };
ResizeType GetResizeBefore();
ResizeType GetResizeAfter();
@ -122,6 +125,7 @@ public:
nsresult CaptureMouse(PRBool aGrabMouseEvents);
PRBool IsMouseCaptured();
void Reverse(nsSplitterInfo*& aIndexes, PRInt32 aCount);
CollapseDirection GetCollapseDirection();
nsSplitterFrame* mSplitter;
PRBool mDidDrag;
@ -242,12 +246,11 @@ nsSplitterFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
mContent->ChildCount(count);
// create a grippy if we have no children and teh collapse attribute is before or after.
if (count == 0) {
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::collapse, value))
if (count == 0)
{
nsSplitterFrameImpl::CollapseDirection d = mImpl->GetCollapseDirection();
if (d != nsSplitterFrameImpl::None)
{
if (value.EqualsIgnoreCase("after") || value.EqualsIgnoreCase("before"))
{
// create a spring
nsCOMPtr<nsIContent> content;
NS_CreateAnonymousNode(mContent, nsXULAtoms::spring, nsXULAtoms::nameSpaceID, content);
@ -263,12 +266,24 @@ nsSplitterFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100%", PR_FALSE);
aAnonymousChildren.AppendElement(content);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSplitterFrame::GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor)
{
if (IsHorizontal())
aCursor = NS_STYLE_CURSOR_N_RESIZE;
else
aCursor = NS_STYLE_CURSOR_W_RESIZE;
return NS_OK;
}
NS_IMETHODIMP
nsSplitterFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
@ -330,6 +345,13 @@ nsSplitterFrame::Init(nsIPresContext& aPresContext,
GetView(&view);
view->SetContentTransparency(PR_TRUE);
view->SetZIndex(kMaxZ);
nsWidgetInitData widgetData;
widgetData.mWindowType = eWindowType_child;
widgetData.mBorderStyle = eBorderStyle_default;
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
view->CreateWidget(kCChildCID,
&widgetData,
nsnull);
mImpl->AddListener();
@ -487,17 +509,43 @@ nsSplitterFrameImpl::MouseDrag(nsIPresContext& aPresContext, nsGUIEvent* aEvent)
else
bounded = PR_TRUE;
// nscoord diff = pos - mCurrentPos;
int i;
int i;
for (i=0; i < mChildInfosBeforeCount; i++)
mChildInfosBefore[i].changed = mChildInfosBefore[i].current;
for (i=0; i < mChildInfosAfterCount; i++)
mChildInfosAfter[i].changed = mChildInfosAfter[i].current;
nscoord oldPos = pos;
ResizeChildTo(pos, mChildInfosBefore, mChildInfosAfter, mChildInfosBeforeCount, mChildInfosAfterCount, bounded);
//mCurrentPos = diff + mCurrentPos;
if (oldPos > 0 && oldPos > pos)
{
printf("Collapse right\n");
if (GetCollapseDirection() == After) {
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "collapsed", PR_TRUE);
AdjustChildren(aPresContext);
AddListener();
CaptureMouse(PR_FALSE);
mPressed = PR_FALSE;
return;
}
}
if (oldPos < 0 && oldPos < pos)
{
printf("Collapse left\n");
if (GetCollapseDirection() == Before) {
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "collapsed", PR_TRUE);
AdjustChildren(aPresContext);
AddListener();
CaptureMouse(PR_FALSE);
mPressed = PR_FALSE;
return;
}
}
// printf("----- resize ----- ");
/*
@ -554,15 +602,18 @@ nsSplitterFrameImpl :: CaptureMouse(PRBool aGrabMouseEvents)
mSplitter->GetView(&view);
nsCOMPtr<nsIViewManager> viewMan;
PRBool result;
nsCOMPtr<nsIWidget> widget;
if (view) {
view->GetViewManager(*getter_AddRefs(viewMan));
view->GetWidget(*getter_AddRefs(widget));
if (viewMan) {
if (aGrabMouseEvents) {
viewMan->GrabMouseEvents(view,result);
widget->CaptureMouse(PR_TRUE);
} else {
viewMan->GrabMouseEvents(nsnull,result);
widget->CaptureMouse(PR_FALSE);
}
}
}
@ -740,8 +791,8 @@ nsSplitterFrameImpl::MouseMove(nsIDOMEvent* aMouseEvent)
if (IsMouseCaptured())
return NS_OK;
if (mState == Collapsed)
return NS_OK;
// if (mState == Collapsed)
// return NS_OK;
mSplitter->mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::state, "dragging", PR_TRUE);
@ -764,19 +815,52 @@ nsSplitterFrameImpl::Reverse(nsSplitterInfo*& aChildInfos, PRInt32 aCount)
aChildInfos = infos;
}
nsSplitterFrameImpl::CollapseDirection
nsSplitterFrameImpl::GetCollapseDirection()
{
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mSplitter->mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::collapse, value))
{
if (value.EqualsIgnoreCase("before"))
return Before;
else if (value.EqualsIgnoreCase("after"))
return After;
else
return None;
} else {
return None;
}
}
void
nsSplitterFrameImpl::UpdateState()
{
// states
//
// Open -> Dragging
// Open -> Collapsed
// Collapsed -> Open
// Collapsed -> Dragging
// Dragging -> Open
// Dragging -> Collapsed (auto collapse)
State newState = GetState();
// if the state are the same we are done
if (newState == mState)
return;
nsString style;
nsString style;
if (mState == Collapsed) {
// Collapsed -> Open
// Collapsed -> Dragging
// set the old style back
style = mCollapsedChildStyle;
} else {
} else if ((mState == Open || mState == Dragging) && newState == Collapsed) {
// when clicked see if we are in a splitter.
nsIFrame* splitter = mSplitter;
@ -784,34 +868,29 @@ nsSplitterFrameImpl::UpdateState()
nsCOMPtr<nsIContent> content;
splitter->GetContent(getter_AddRefs(content));
// get the collapse attribute. If the attribute is not set collapse
// the child before otherwise collapse the child after
PRBool before = PR_TRUE;
nsString value;
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsXULAtoms::collapse, value))
{
if (value.EqualsIgnoreCase("before"))
before = PR_TRUE;
else if (value.EqualsIgnoreCase("after"))
before = PR_FALSE;
else
return;
CollapseDirection d = GetCollapseDirection();
if (d != None) {
// find the child just in the box just before the splitter. If we are not currently collapsed then
// then get the childs style attribute and store it. Then set the child style attribute to be display none.
// if we are already collapsed then set the child's style back to our stored value.
nsIFrame* child = nsFrameNavigator::GetChildBeforeAfter(splitter,(d == Before));
if (child == nsnull)
return;
child->GetContent(getter_AddRefs(mCollapsedChild));
style = "visibility: collapse";
mCollapsedChildStyle = "";
mCollapsedChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
} else {
mState = newState;
return;
}
// find the child just in the box just before the splitter. If we are not currently collapsed then
// then get the childs style attribute and store it. Then set the child style attribute to be display none.
// if we are already collapsed then set the child's style back to our stored value.
nsIFrame* child = nsFrameNavigator::GetChildBeforeAfter(splitter,before);
if (child == nsnull)
} else {
mState = newState;
return;
child->GetContent(getter_AddRefs(mCollapsedChild));
style = "visibility: collapse";
mCollapsedChildStyle = "";
mCollapsedChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
}
mCollapsedChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::style, style, PR_TRUE);
@ -960,17 +1039,15 @@ nsSplitterFrameImpl::ResizeChildTo(nscoord& aDiff,
mSplitter->GetView(&v);
v->GetViewManager(*getter_AddRefs(vm));
v->GetBounds(vr);
nsRect invalid(0,0,0,0);
nsRect invalid;
if (mParentBox->IsHorizontal()) {
mSplitter->MoveTo(mSplitterPos + aDiff, r.y);
vm->MoveViewTo(v, mSplitterViewPos + aDiff, vr.y);
invalid.width = r.width + PR_ABS(aDiff);
invalid.x = PR_MAX(mSplitterPos,mSplitterPos + aDiff);
invalid.UnionRect(r,mSplitter->mRect);
} else {
mSplitter->MoveTo(r.x, mSplitterPos + aDiff);
vm->MoveViewTo(v, vr.x, mSplitterViewPos + aDiff);
invalid.height = r.height + PR_ABS(aDiff);
invalid.y = PR_MAX(mSplitterPos, mSplitterPos + aDiff);
invalid.UnionRect(r,mSplitter->mRect);
}
// redraw immediately only what changed. This is animation so

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

@ -55,6 +55,11 @@ public:
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD GetCursor(nsIPresContext& aPresContext,
nsPoint& aPoint,
PRInt32& aCursor);
// nsIAnonymousContentCreator
NS_IMETHOD CreateAnonymousContent(nsISupportsArray& aAnonymousItems);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);

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

@ -24,6 +24,7 @@
// See documentation in associated header file
//
#include "nsButtonFrameRenderer.h"
#include "nsTitledButtonFrame.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
@ -100,6 +101,26 @@ static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
#define CROP_RIGHT "right"
#define CROP_CENTER "center"
class nsTitledButtonRenderer : public nsButtonFrameRenderer
{
public:
// change this to do the XML thing. An boolean attribute is only true if it is set to true
// it is false otherwise
virtual PRBool isDisabled()
{
nsCOMPtr<nsIContent> content;
GetFrame()->GetContent(getter_AddRefs(content));
nsAutoString value;
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(GetNameSpace(), nsHTMLAtoms::disabled, value))
{
if (value.EqualsIgnoreCase("true"))
return PR_TRUE;
}
return PR_FALSE;
}
};
nsresult
nsTitledButtonFrame::UpdateImageFrame(nsIPresContext* aPresContext,
nsHTMLImageLoader* aLoader,
@ -174,7 +195,7 @@ nsTitledButtonFrame::AttributeChanged(nsIPresContext* aPresContext,
nsFrame::Invalidate(nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);
// redraw
mRenderer.Redraw();
mRenderer->Redraw();
#if !ONLOAD_CALLED_TOO_EARLY
// onload handlers are called to early, so we have to do this code
@ -199,7 +220,13 @@ nsTitledButtonFrame::nsTitledButtonFrame()
mCropType = CropRight;
mNeedsLayout = PR_TRUE;
mHasImage = PR_FALSE;
mHasOnceBeenInMixedState = PR_FALSE;
mHasOnceBeenInMixedState = PR_FALSE;
mRenderer = new nsTitledButtonRenderer();
}
nsTitledButtonFrame::~nsTitledButtonFrame()
{
delete mRenderer;
}
NS_METHOD
@ -221,8 +248,8 @@ nsTitledButtonFrame::Init(nsIPresContext& aPresContext,
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
mRenderer.SetNameSpace(kNameSpaceID_None);
mRenderer.SetFrame(this,aPresContext);
mRenderer->SetNameSpace(kNameSpaceID_None);
mRenderer->SetFrame(this,aPresContext);
// place 4 pixels of spacing
float p2t;
@ -267,9 +294,9 @@ void
nsTitledButtonFrame::SetDisabled(nsAutoString aDisabled)
{
if (aDisabled.EqualsIgnoreCase("true"))
mRenderer.SetDisabled(PR_TRUE, PR_TRUE);
mRenderer->SetDisabled(PR_TRUE, PR_TRUE);
else
mRenderer.SetDisabled(PR_FALSE, PR_TRUE);
mRenderer->SetDisabled(PR_FALSE, PR_TRUE);
}
void
@ -393,12 +420,12 @@ nsTitledButtonFrame::Paint(nsIPresContext& aPresContext,
nsRect rect (0,0, mRect.width, mRect.height);
mRenderer->PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
aRenderingContext.PushState();
PRBool clipState;
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect, clipState);
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
LayoutTitleAndImage(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
PaintTitle(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
@ -432,7 +459,7 @@ nsTitledButtonFrame::LayoutTitleAndImage(nsIPresContext& aPresContext,
// if they don't fit then crop the text, the image can't be squeezed.
nsRect rect;
mRenderer.GetButtonContentRect(nsRect(0,0,mRect.width,mRect.height), rect);
mRenderer->GetButtonContentRect(nsRect(0,0,mRect.width,mRect.height), rect);
// set up some variables we will use a lot.
nscoord bottom_y = rect.y + rect.height;
@ -756,7 +783,7 @@ nsTitledButtonFrame::PaintTitle(nsIPresContext& aPresContext,
}
// if disabled paint
if (PR_TRUE == mRenderer.isDisabled())
if (PR_TRUE == mRenderer->isDisabled())
{
aRenderingContext.SetColor(NS_RGB(255,255,255));
aRenderingContext.DrawString(mCroppedTitle, disabledRect.x,
@ -1082,7 +1109,7 @@ nsTitledButtonFrame::HandleEvent(nsIPresContext& aPresContext,
{
// if disabled do nothing
if (PR_TRUE == mRenderer.isDisabled()) {
if (PR_TRUE == mRenderer->isDisabled()) {
return NS_OK;
}
@ -1229,14 +1256,14 @@ NS_IMETHODIMP
nsTitledButtonFrame::GetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext** aStyleContext) const
{
return mRenderer.GetStyleContext(aIndex, aStyleContext);
return mRenderer->GetStyleContext(aIndex, aStyleContext);
}
NS_IMETHODIMP
nsTitledButtonFrame::SetAdditionalStyleContext(PRInt32 aIndex,
nsIStyleContext* aStyleContext)
{
return mRenderer.SetStyleContext(aIndex, aStyleContext);
return mRenderer->SetStyleContext(aIndex, aStyleContext);
}
//
@ -1261,7 +1288,7 @@ nsTitledButtonFrame :: ReResolveStyleContext ( nsIPresContext* aPresContext, nsI
aParentChange = *aLocalChange; // tell children about or change
}
}
mRenderer.ReResolveStyles(*aPresContext, aParentChange, aChangeList, aLocalChange);
mRenderer->ReResolveStyles(*aPresContext, aParentChange, aChangeList, aLocalChange);
// if list-style-image change we want to change the image
UpdateImage(*aPresContext);
@ -1375,7 +1402,7 @@ nsTitledButtonFrame::GetBoxInfo(nsIPresContext& aPresContext, const nsHTMLReflow
break;
}
nsMargin focusBorder = mRenderer.GetAddedButtonBorderAndPadding();
nsMargin focusBorder = mRenderer->GetAddedButtonBorderAndPadding();
aSize.prefSize.width += focusBorder.left + focusBorder.right;
aSize.prefSize.height += focusBorder.top + focusBorder.bottom;

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

@ -21,10 +21,10 @@
#include "nsHTMLImageLoader.h"
#include "nsLeafFrame.h"
#include "nsButtonFrameRenderer.h"
#include "nsIBox.h"
class nsIPopUpMenu;
class nsTitledButtonRenderer;
class nsTitledButtonFrame : public nsLeafFrame, public nsIBox
{
@ -84,6 +84,7 @@ public:
nsEventStatus& aEventStatus);
~nsTitledButtonFrame();
protected:
enum CheckState { eUnset, eOff, eOn, eMixed } ;
@ -166,12 +167,8 @@ private:
nsRect mTitleRect;
PRBool mNeedsLayout;
nscoord mSpacing;
//nsSize mMinSize;
nsButtonFrameRenderer mRenderer;
nsTitledButtonRenderer* mRenderer;
PRBool mHasImage;
// nsIPopUpMenu * mPopUpMenu;
// PRBool mMenuIsPoppedUp;
}; // class nsTitledButtonFrame

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

@ -855,14 +855,14 @@ tabcontrol {
*:-moz-horizontal-box-debug {
border: 2px solid blue;
border-top-width: 10px;
padding: 1px;
padding: 2px;
color: white;
}
*:-moz-vertical-box-debug {
border: 2px solid red;
border-left-width: 10px;
padding: 1px;
padding: 2px;
color: white;
}
*/
@ -874,24 +874,32 @@ tabcontrol {
border: 2px solid blue;
border-top-width: 10px;
color: white;
padding: 2px;
margin: 2px;
}
*[debug="true"]:-moz-vertical-box-debug {
border: 2px solid blue;
border-top-width: 10px;
color: white;
}
*[debug="true"] *:-moz-horizontal-box-debug {
border: 2px solid red;
border-left-width: 10px;
color: white;
padding: 2px;
margin: 2px;
}
*[debug="true"] *:-moz-horizontal-box-debug {
border: 2px solid blue;
border-top-width: 10px;
color: white;
padding: 2px;
margin: 2px;
}
*[debug="true"] *:-moz-vertical-box-debug {
border: 2px solid red;
border-left-width: 10px;
color: white;
padding: 2px;
margin: 2px;
}