This commit is contained in:
hyatt%netscape.com 2000-03-15 03:16:43 +00:00
Родитель 804ec67bf8
Коммит 1c02f1ca09
6 изменённых файлов: 49 добавлений и 361 удалений

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

@ -89,7 +89,7 @@ XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
XUL_ATOM(observes, "observes") // The observes element
XUL_ATOM(templateAtom, "template") // A XUL template
XUL_ATOM(progressmeter, "progressmeter")
XUL_ATOM(progressbar, "progressbar")
XUL_ATOM(titledbutton, "titledbutton")
XUL_ATOM(crop, "crop")

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

@ -2093,7 +2093,7 @@ nsCSSFrameConstructor::TableIsValidCellContent(nsIPresContext* aPresContext,
(nsXULAtoms::tabbox == tag.get()) ||
(nsXULAtoms::tabpanel == tag.get()) ||
(nsXULAtoms::tabpage == tag.get()) ||
(nsXULAtoms::progressmeter == tag.get()) ||
(nsXULAtoms::progressbar == tag.get()) ||
(nsXULAtoms::checkbox == tag.get()) ||
(nsXULAtoms::radio == tag.get()) ||
(nsXULAtoms::menulist == tag.get()) ||
@ -4588,7 +4588,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell,
// End of TOOLBAR CONSTRUCTION logic
// PROGRESS METER CONSTRUCTION
else if (aTag == nsXULAtoms::progressmeter) {
else if (aTag == nsXULAtoms::progressbar) {
processChildren = PR_TRUE;
isReplaced = PR_TRUE;
rv = NS_NewProgressMeterFrame(aPresShell, &newFrame);

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

@ -2093,7 +2093,7 @@ nsCSSFrameConstructor::TableIsValidCellContent(nsIPresContext* aPresContext,
(nsXULAtoms::tabbox == tag.get()) ||
(nsXULAtoms::tabpanel == tag.get()) ||
(nsXULAtoms::tabpage == tag.get()) ||
(nsXULAtoms::progressmeter == tag.get()) ||
(nsXULAtoms::progressbar == tag.get()) ||
(nsXULAtoms::checkbox == tag.get()) ||
(nsXULAtoms::radio == tag.get()) ||
(nsXULAtoms::menulist == tag.get()) ||
@ -4588,7 +4588,7 @@ nsCSSFrameConstructor::ConstructXULFrame(nsIPresShell* aPresShell,
// End of TOOLBAR CONSTRUCTION logic
// PROGRESS METER CONSTRUCTION
else if (aTag == nsXULAtoms::progressmeter) {
else if (aTag == nsXULAtoms::progressbar) {
processChildren = PR_TRUE;
isReplaced = PR_TRUE;
rv = NS_NewProgressMeterFrame(aPresShell, &newFrame);

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

@ -21,7 +21,7 @@
*/
//
// Eric Vaughan
// David Hyatt & Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
@ -47,7 +47,7 @@ NS_NewProgressMeterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsProgressMeterFrame* it = new (aPresShell) nsProgressMeterFrame;
nsProgressMeterFrame* it = new (aPresShell) nsProgressMeterFrame(aPresShell);
if (nsnull == it)
return NS_ERROR_OUT_OF_MEMORY;
@ -61,11 +61,9 @@ NS_NewProgressMeterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
//
// Init, if necessary
//
nsProgressMeterFrame :: nsProgressMeterFrame ( )
nsProgressMeterFrame :: nsProgressMeterFrame (nsIPresShell* aPresShell)
:nsBoxFrame(aPresShell)
{
mProgress = float(0.0);
mHorizontal = PR_TRUE;
mUndetermined = PR_FALSE;
}
//
@ -78,231 +76,16 @@ nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
}
NS_IMETHODIMP
nsProgressMeterFrame::Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsLeafFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
// get the value
nsAutoString value;
if ((NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value)) &&
(value.Length() > 0)) {
setProgress(value);
}
// get the alignment
nsAutoString align;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, align);
setAlignment(align);
// get the mode
nsAutoString mode;
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, mode);
setMode(mode);
nsProgressMeterFrame::SetInitialChildList(nsIPresContext* aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList)
{
// Set up our initial flexes.
nsresult rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
AttributeChanged(aPresContext, mContent, kNameSpaceID_None, nsHTMLAtoms::value, 0);
return rv;
}
void
nsProgressMeterFrame::setProgress(nsAutoString progress)
{
// convert to and integer
PRInt32 error;
PRInt32 v = progress.ToInteger(&error);
// adjust to 0 and 100
if (v < 0)
v = 0;
else if (v > 100)
v = 100;
// printf("ProgressMeter value=%d\n", v);
mProgress = float(v)/float(100);
}
void
nsProgressMeterFrame::setAlignment(nsAutoString progress)
{
if (progress.EqualsIgnoreCase("vertical"))
mHorizontal = PR_FALSE;
else
mHorizontal = PR_TRUE;
}
void
nsProgressMeterFrame::setMode(nsAutoString mode)
{
if (mode.EqualsIgnoreCase("undetermined"))
mUndetermined = PR_TRUE;
else
mUndetermined = PR_FALSE;
}
//
// Paint
//
// Paint our background and border like normal frames, but before we draw the
// children, draw our grippies for each toolbar.
//
NS_IMETHODIMP
nsProgressMeterFrame :: Paint ( nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
{
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
// if we aren't visible then we are done.
if (!disp->mVisible)
return NS_OK;
// if we are visible then tell our superclass to paint
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,
aWhichLayer);
if (aWhichLayer == NS_FRAME_PAINT_LAYER_FOREGROUND)
{
if (!mUndetermined) {
// get our border
const nsStyleSpacing* spacing =
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsMargin border(0,0,0,0);
spacing->CalcBorderFor(this, border);
const nsStyleColor* colorStyle =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
nscolor color = colorStyle->mColor;
// figure out our rectangle
nsRect rect(0,0,mRect.width, mRect.height);
//CalcSize(aPresContext,rect.width,rect.height);
rect.x = border.left;
rect.y = border.top;
rect.width -= border.left + border.right;
rect.height -= border.top + border.bottom;
// paint the current progress in blue
PaintBar(aPresContext, aRenderingContext, rect, mProgress, color);
}
}
return NS_OK;
} // Paint
void
nsProgressMeterFrame :: PaintBar ( nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& rect,
float progress,
nscolor color) {
nsRect bar(rect);
if (mHorizontal)
bar.width = (nscoord)(bar.width*progress);
else
bar.height = (nscoord)(bar.height*progress);
aRenderingContext.SetColor(color);
aRenderingContext.FillRect(bar);
}
//
// Reflow
//
// Handle moving children around.
//
NS_IMETHODIMP
nsProgressMeterFrame :: Reflow ( nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
// handle dirty and incremental reflow
if (eReflowReason_Incremental == aReflowState.reason) {
nsIFrame* targetFrame;
// See if it's targeted at us
aReflowState.reflowCommand->GetTarget(targetFrame);
if (this == targetFrame) {
Invalidate(aPresContext, nsRect(0,0,mRect.width,mRect.height), PR_FALSE);
}
} else if (eReflowReason_Dirty == aReflowState.reason) {
Invalidate(aPresContext, nsRect(0,0,mRect.width,mRect.height), PR_FALSE);
}
return nsLeafFrame::Reflow ( aPresContext, aDesiredSize, aReflowState, aStatus );
} // Reflow
void
nsProgressMeterFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
CalcSize(aPresContext,aDesiredSize.width,aDesiredSize.height);
// if the width is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedWidth)
aDesiredSize.width = aReflowState.mComputedWidth;
// if the height is set use it
if (NS_INTRINSICSIZE != aReflowState.mComputedHeight)
aDesiredSize.height = aReflowState.mComputedHeight;
}
void
nsProgressMeterFrame::CalcSize(nsIPresContext* aPresContext, int& width, int& height)
{
// set up a default size for the progress meter.
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
if (mHorizontal) {
width = (int)(100 * p2t);
height = (int)(16 * p2t);
} else {
height = (int)(100 * p2t);
width = (int)(16 * p2t);
}
}
NS_IMETHODIMP
nsProgressMeterFrame::GetBoxInfo(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize)
{
CalcSize(aPresContext, aSize.prefSize.width, aSize.prefSize.height);
aSize.minSize = aSize.prefSize;
return NS_OK;
}
NS_INTERFACE_MAP_BEGIN(nsProgressMeterFrame)
NS_INTERFACE_MAP_ENTRY(nsIBox)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIBox)
NS_INTERFACE_MAP_END_INHERITING(nsLeafFrame)
NS_IMETHODIMP
nsProgressMeterFrame::InvalidateCache(nsIFrame* aChild)
{
// we don't have any cached children
return NS_OK;
}
NS_IMETHODIMP
nsProgressMeterFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
@ -310,69 +93,40 @@ nsProgressMeterFrame::AttributeChanged(nsIPresContext* aPresContext,
nsIAtom* aAttribute,
PRInt32 aHint)
{
nsresult rv = nsLeafFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aHint);
nsresult rv = nsBoxFrame::AttributeChanged(aPresContext, aChild,
aNameSpaceID, aAttribute, aHint);
if (NS_OK != rv) {
return rv;
}
// did the progress change?
if (nsHTMLAtoms::value == aAttribute) {
nsAutoString newValue;
PRInt32 childCount;
mContent->ChildCount(childCount);
// get attribute and set it
aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, newValue);
setProgress(newValue);
if (childCount >= 2) {
nsCOMPtr<nsIContent> progressBar;
nsCOMPtr<nsIContent> progressRemainder;
Redraw(aPresContext);
mContent->ChildAt(0, *getter_AddRefs(progressBar));
mContent->ChildAt(1, *getter_AddRefs(progressRemainder));
} else if (nsXULAtoms::mode == aAttribute) {
nsAutoString newValue;
nsAutoString value;
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value);
aChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::mode, newValue);
setMode(newValue);
PRInt32 error;
PRInt32 flex = value.ToInteger(&error);
if (flex < 0) flex = 0;
if (flex > 100) flex = 100;
// needs to reflow so we start the timer.
/// if (aHint != NS_STYLE_HINT_REFLOW)
// Reflow(aPresContext);
aPresContext->StopAllLoadImagesFor(this);
PRInt32 remainder = 100 - flex;
} else if (nsHTMLAtoms::align == aAttribute) {
nsAutoString newValue;
// get attribute and set it
aChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::align, newValue);
setAlignment(newValue);
if (aHint != NS_STYLE_HINT_REFLOW)
Reflow(aPresContext);
nsAutoString leftFlex, rightFlex;
leftFlex.Append(flex);
rightFlex.Append(remainder);
progressBar->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, leftFlex, PR_TRUE);
progressRemainder->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, rightFlex, PR_TRUE);
}
}
return NS_OK;
}
void
nsProgressMeterFrame::Reflow(nsIPresContext* aPresContext)
{
nsCOMPtr<nsIPresShell> shell;
aPresContext->GetShell(getter_AddRefs(shell));
// reflow
mState |= NS_FRAME_IS_DIRTY;
mParent->ReflowDirtyChild(shell, this);
}
void
nsProgressMeterFrame::Redraw(nsIPresContext* aPresContext)
{
nsRect frameRect;
GetRect(frameRect);
nsRect rect(0, 0, frameRect.width, frameRect.height);
Invalidate(aPresContext, rect, PR_TRUE);
}

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

@ -22,66 +22,31 @@
/**
Eric D Vaughan.
David Hyatt & Eric D Vaughan.
A simple progress meter.
An XBL-based progress meter.
Attributes:
value: A number between 0% adn 100%
align: horizontal, or vertical
value: A number between 0% and 100%
align: horizontal or vertical
mode: determined, undetermined (one shows progress other shows animated candy cane)
Style:
Bar gets its color from the color style
Alternating stripes can be set with the seudo style:
:PROGRESSMETER-STRIPE {
color: gray
}
**/
#include "nsLeafFrame.h"
#include "nsColor.h"
#include "prtypes.h"
#include "nsIBox.h"
#include "nsBoxFrame.h"
class nsIPresContext;
class nsIStyleContext;
class nsProgressMeterFrame : public nsLeafFrame, nsIBox
class nsProgressMeterFrame : public nsBoxFrame
{
public:
friend nsresult NS_NewProgressMeterFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
NS_IMETHOD Init(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
NS_IMETHOD_(nsrefcnt) AddRef(void) { return NS_OK; }
NS_IMETHOD_(nsrefcnt) Release(void) { return NS_OK; }
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD GetBoxInfo(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize);
NS_IMETHOD InvalidateCache(nsIFrame* aChild);
NS_IMETHOD SetDebug(nsIPresContext* aPresContext, PRBool aDebug) { return NS_OK; }
// nsIHTMLReflow overrides
NS_IMETHOD Reflow(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD Paint(nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer);
NS_IMETHOD SetInitialChildList(nsIPresContext* aPresContext,
nsIAtom* aListName,
nsIFrame* aChildList);
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
nsIContent* aChild,
@ -89,40 +54,9 @@ public:
nsIAtom* aAttribute,
PRInt32 aHint);
virtual void Reflow(nsIPresContext* aPresContext);
virtual void Redraw(nsIPresContext* aPresContext);
protected:
nsProgressMeterFrame();
nsProgressMeterFrame(nsIPresShell* aPresShell);
virtual ~nsProgressMeterFrame();
virtual void GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize);
virtual void CalcSize(nsIPresContext* aPresContext, int& width, int& height);
virtual void PaintBar ( nsIPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& rect,
float progress,
nscolor color);
// pass-by-value not allowed for a coordinator because it corresponds 1-to-1
// with an element in the UI.
nsProgressMeterFrame ( const nsProgressMeterFrame& aFrame ) ; // DO NOT IMPLEMENT
nsProgressMeterFrame& operator= ( const nsProgressMeterFrame& aFrame ) ; // DO NOT IMPLEMENT
private:
void setProgress(nsAutoString progress);
void setAlignment(nsAutoString alignment);
void setMode(nsAutoString mode);
float mProgress;
PRBool mHorizontal;
PRBool mUndetermined;
}; // class nsProgressMeterFrame

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

@ -89,7 +89,7 @@ XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
XUL_ATOM(observes, "observes") // The observes element
XUL_ATOM(templateAtom, "template") // A XUL template
XUL_ATOM(progressmeter, "progressmeter")
XUL_ATOM(progressbar, "progressbar")
XUL_ATOM(titledbutton, "titledbutton")
XUL_ATOM(crop, "crop")