added content quality indicator.

This commit is contained in:
michaelp 1998-06-21 01:23:44 +00:00
parent d5b0774f7c
commit 6ad59f6a19
10 changed files with 374 additions and 23 deletions

View File

@ -21,6 +21,7 @@
#include "nsISupports.h"
#include "nsCoord.h"
#include "nsIViewManager.h"
class nsIView;
// IID for the nsIView interface
@ -64,6 +65,24 @@ public:
* @result child view
*/
virtual nsIView * GetScrolledView(void) = 0;
/**
* Select whether quality level should be displayed in view frame
* @param aShow if PR_TRUE, quality level will be displayed, else hidden
*/
virtual void ShowQuality(PRBool aShow) = 0;
/**
* Query whether quality level should be displayed in view frame
* @return if PR_TRUE, quality level will be displayed, else hidden
*/
virtual PRBool GetShowQuality(void) = 0;
/**
* Select whether quality level should be displayed in view frame
* @param aShow if PR_TRUE, quality level will be displayed, else hidden
*/
virtual void SetQuality(nsContentQuality aQuality) = 0;
};
#endif

View File

@ -31,6 +31,13 @@ class nsIView;
class nsIWidget;
struct nsRect;
typedef enum
{
nsContentQuality_kGood = 0,
nsContentQuality_kFair,
nsContentQuality_kPoor
} nsContentQuality;
#define NS_IVIEWMANAGER_IID \
{ 0x3a8863d0, 0xa7f3, 0x11d1, \
{ 0xa8, 0x24, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
@ -359,6 +366,24 @@ public:
* to an empty state
*/
virtual void ClearDirtyRegion() = 0;
/**
* Select whether quality level should be displayed in root view
* @param aShow if PR_TRUE, quality level will be displayed, else hidden
*/
virtual void ShowQuality(PRBool aShow) = 0;
/**
* Query whether quality level should be displayed in view frame
* @return if PR_TRUE, quality level will be displayed, else hidden
*/
virtual PRBool GetShowQuality(void) = 0;
/**
* Select whether quality level should be displayed in root view
* @param aShow if PR_TRUE, quality level will be displayed, else hidden
*/
virtual void SetQuality(nsContentQuality aQuality) = 0;
};
//when the refresh happens, should it be double buffered?

View File

@ -82,6 +82,153 @@ void ScrollBarView :: SetDimensions(nscoord width, nscoord height)
}
}
class CornerView : public nsView
{
public:
CornerView();
~CornerView();
void ShowQuality(PRBool aShow);
void SetQuality(nsContentQuality aQuality);
void Show(PRBool aShow);
PRBool Paint(nsIRenderingContext& rc, const nsRect& rect,
PRUint32 aPaintFlags, nsIView *aBackstop = nsnull);
PRBool mShowQuality;
nsContentQuality mQuality;
PRBool mShow;
};
CornerView :: CornerView()
{
mShowQuality = PR_FALSE;
mQuality = nsContentQuality_kGood;
mShow = PR_FALSE;
}
CornerView :: ~CornerView()
{
}
void CornerView :: ShowQuality(PRBool aShow)
{
if (mShowQuality != aShow)
{
mShowQuality = aShow;
if (mShow == PR_FALSE)
{
if (mVis == nsViewVisibility_kShow)
mViewManager->SetViewVisibility(this, nsViewVisibility_kHide);
else
mViewManager->SetViewVisibility(this, nsViewVisibility_kShow);
nscoord dimx, dimy;
//this will force the scrolling view to recalc the scrollbar sizes... MMP
mParent->GetDimensions(&dimx, &dimy);
mParent->SetDimensions(dimx, dimy);
}
mViewManager->UpdateView(this, nsnull, NS_VMREFRESH_IMMEDIATE);
}
}
void CornerView :: SetQuality(nsContentQuality aQuality)
{
if (mQuality != aQuality)
{
mQuality = aQuality;
if (mVis == nsViewVisibility_kShow)
mViewManager->UpdateView(this, nsnull, NS_VMREFRESH_IMMEDIATE);
}
}
void CornerView :: Show(PRBool aShow)
{
if (mShow != aShow)
{
mShow = aShow;
if (mShow == PR_TRUE)
mViewManager->SetViewVisibility(this, nsViewVisibility_kShow);
else if (mShowQuality == PR_FALSE)
mViewManager->SetViewVisibility(this, nsViewVisibility_kHide);
nscoord dimx, dimy;
//this will force the scrolling view to recalc the scrollbar sizes... MMP
mParent->GetDimensions(&dimx, &dimy);
mParent->SetDimensions(dimx, dimy);
}
}
PRBool CornerView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
PRUint32 aPaintFlags, nsIView *aBackstop)
{
PRBool clipres = PR_FALSE;
if (mVis == nsViewVisibility_kShow)
{
nscoord xoff, yoff;
rc.PushState();
GetScrollOffset(&xoff, &yoff);
rc.Translate(xoff, yoff);
clipres = rc.SetClipRect(mBounds, nsClipCombine_kIntersect);
if (clipres == PR_FALSE)
{
rc.SetColor(NS_RGB(192, 192, 192));
rc.FillRect(mBounds);
if (PR_TRUE == mShowQuality)
{
//display quality indicator
rc.Translate(mBounds.x, mBounds.y);
rc.SetColor(NS_RGB(0, 0, 0));
rc.FillEllipse(nscoord(mBounds.width * 0.15f),
nscoord(mBounds.height * 0.15f),
NS_TO_INT_ROUND(mBounds.width * 0.7f),
NS_TO_INT_ROUND(mBounds.height * 0.7f));
if (mQuality == nsContentQuality_kGood)
rc.SetColor(NS_RGB(0, 255, 0));
else if (mQuality == nsContentQuality_kFair)
rc.SetColor(NS_RGB(255, 176, 0));
else
rc.SetColor(NS_RGB(255, 0, 0));
rc.FillEllipse(NS_TO_INT_ROUND(mBounds.width * 0.23f),
NS_TO_INT_ROUND(mBounds.height * 0.23f),
nscoord(mBounds.width * 0.46f),
nscoord(mBounds.height * 0.46f));
}
}
clipres = rc.PopState();
if (clipres == PR_FALSE)
{
nsRect xrect = mBounds;
xrect.x += xoff;
xrect.y += yoff;
clipres = rc.SetClipRect(xrect, nsClipCombine_kSubtract);
}
}
return clipres;
}
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
nsScrollingView :: nsScrollingView()
@ -90,6 +237,7 @@ nsScrollingView :: nsScrollingView()
mOffsetX = mOffsetY = 0;
mVScrollBarView = nsnull;
mHScrollBarView = nsnull;
mCornerView = nsnull;
}
nsScrollingView :: ~nsScrollingView()
@ -105,6 +253,12 @@ nsScrollingView :: ~nsScrollingView()
NS_RELEASE(mHScrollBarView);
mHScrollBarView = nsnull;
}
if (nsnull != mCornerView)
{
NS_RELEASE(mCornerView);
mCornerView = nsnull;
}
}
nsresult nsScrollingView :: QueryInterface(const nsIID& aIID, void** aInstancePtr)
@ -154,7 +308,27 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
nsIPresContext *cx = mViewManager->GetPresContext();
nsIDeviceContext *dx = cx->GetDeviceContext();
// Create a view
// Create a view for a corner cover
mCornerView = new CornerView();
if (nsnull != mCornerView)
{
NS_ADDREF(mCornerView);
nsRect trect;
trect.width = NS_TO_INT_ROUND(dx->GetScrollBarWidth());
trect.x = aBounds.XMost() - trect.width;
trect.height = NS_TO_INT_ROUND(dx->GetScrollBarHeight());
trect.y = aBounds.YMost() - trect.height;
rv = mCornerView->Init(mViewManager, trect, this, nsnull, nsnull, nsnull, -1, nsnull, 1.0f, nsViewVisibility_kHide);
mViewManager->InsertChild(this, mCornerView, -1);
}
// Create a view for a vertical scrollbar
mVScrollBarView = new ScrollBarView();
@ -170,12 +344,12 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
static NS_DEFINE_IID(kCScrollbarIID, NS_VERTSCROLLBAR_CID);
rv = mVScrollBarView->Init(mViewManager, trect, this, &kCScrollbarIID);
rv = mVScrollBarView->Init(mViewManager, trect, this, &kCScrollbarIID, nsnull, nsnull, -2);
mViewManager->InsertChild(this, mVScrollBarView, 0);
mViewManager->InsertChild(this, mVScrollBarView, -2);
}
// Create a view
// Create a view for a horizontal scrollbar
mHScrollBarView = new ScrollBarView();
@ -191,9 +365,9 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
static NS_DEFINE_IID(kCHScrollbarIID, NS_HORZSCROLLBAR_CID);
rv = mHScrollBarView->Init(mViewManager, trect, this, &kCHScrollbarIID);
rv = mHScrollBarView->Init(mViewManager, trect, this, &kCHScrollbarIID, nsnull, nsnull, -2);
mViewManager->InsertChild(this, mHScrollBarView, 0);
mViewManager->InsertChild(this, mHScrollBarView, -2);
}
NS_RELEASE(dx);
@ -209,6 +383,16 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height)
nsIPresContext *cx = mViewManager->GetPresContext();
nsIDeviceContext *dx = cx->GetDeviceContext();
if (nsnull != mCornerView)
{
mCornerView->GetDimensions(&trect.width, &trect.height);
trect.y = height - NS_TO_INT_ROUND(dx->GetScrollBarHeight());
trect.x = width - NS_TO_INT_ROUND(dx->GetScrollBarWidth());
mCornerView->SetBounds(trect);
}
nsView :: SetDimensions(width, height);
if (nsnull != mVScrollBarView)
@ -217,7 +401,8 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height)
trect.height = height;
if (mHScrollBarView && (mHScrollBarView->GetVisibility() == nsViewVisibility_kShow))
if ((mHScrollBarView && (mHScrollBarView->GetVisibility() == nsViewVisibility_kShow)) ||
(mCornerView && (mCornerView->GetVisibility() == nsViewVisibility_kShow)))
trect.height -= NS_TO_INT_ROUND(dx->GetScrollBarHeight());
trect.x = width - NS_TO_INT_ROUND(dx->GetScrollBarWidth());
@ -232,10 +417,11 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height)
trect.width = width;
if (mVScrollBarView && (mVScrollBarView->GetVisibility() == nsViewVisibility_kShow))
trect.width -= NS_TO_INT_ROUND(dx->GetScrollBarHeight());
if ((mVScrollBarView && (mVScrollBarView->GetVisibility() == nsViewVisibility_kShow)) ||
(mCornerView && (mCornerView->GetVisibility() == nsViewVisibility_kShow)))
trect.width -= NS_TO_INT_ROUND(dx->GetScrollBarWidth());
trect.y = height - NS_TO_INT_ROUND(dx->GetScrollBarWidth());
trect.y = height - NS_TO_INT_ROUND(dx->GetScrollBarHeight());
trect.x = 0;
mHScrollBarView->SetBounds(trect);
@ -485,7 +671,7 @@ void nsScrollingView :: ComputeContainerSize()
{
nscoord dx = 0, dy = 0;
nsIPresContext *px = mViewManager->GetPresContext();
nscoord width, height;
nscoord hwidth, hheight;
nscoord vwidth, vheight;
PRUint32 oldsizey = mSizeY, oldsizex = mSizeX;
nsRect area(0, 0, 0, 0);
@ -497,6 +683,22 @@ void nsScrollingView :: ComputeContainerSize()
mSizeY = area.YMost();
mSizeX = area.XMost();
if (nsnull != mHScrollBarView)
{
mHScrollBarView->GetDimensions(&hwidth, &hheight);
win = mHScrollBarView->GetWidget();
if (NS_OK == win->QueryInterface(kscroller, (void **)&scrollh))
{
if (mSizeX > mBounds.width)
scrollh->Release(); //DO NOT USE NS_RELEASE()! MMP
else
NS_RELEASE(scrollh); //MUST USE NS_RELEASE()! MMP
}
NS_RELEASE(win);
}
if (nsnull != mVScrollBarView)
{
mVScrollBarView->GetDimensions(&vwidth, &vheight);
@ -520,17 +722,20 @@ void nsScrollingView :: ComputeContainerSize()
dy = NS_TO_INT_ROUND(scale * (offy - mOffsetY));
scrollv->SetParameters(mSizeY, mBounds.height, mOffsetY, NS_POINTS_TO_TWIPS_INT(12));
scrollv->SetParameters(mSizeY, mBounds.height - ((nsnull != scrollh) ? hheight : 0),
mOffsetY, NS_POINTS_TO_TWIPS_INT(12));
}
else
{
mOffsetY = 0;
dy = NS_TO_INT_ROUND(scale * offy);
mVScrollBarView->SetVisibility(nsViewVisibility_kHide);
NS_RELEASE(scrollv);
}
//don't release the vertical scroller here because if we need to
//create a horizontal one, it will need to tweak the vertical one
//create a horizontal one, it will need to know that there is a vertical one
// //create a horizontal one, it will need to tweak the vertical one
}
NS_RELEASE(win);
@ -538,7 +743,6 @@ void nsScrollingView :: ComputeContainerSize()
if (nsnull != mHScrollBarView)
{
mHScrollBarView->GetDimensions(&width, &height);
offx = mOffsetX;
win = mHScrollBarView->GetWidget();
@ -562,10 +766,10 @@ void nsScrollingView :: ComputeContainerSize()
scrollh->SetParameters(mSizeX, mBounds.width - ((nsnull != scrollv) ? vwidth : 0),
mOffsetX, NS_POINTS_TO_TWIPS_INT(12));
//now make the vertical scroll region account for this scrollbar
if (nsnull != scrollv)
scrollv->SetParameters(mSizeY, mBounds.height - height, mOffsetY, NS_POINTS_TO_TWIPS_INT(12));
// //now make the vertical scroll region account for this scrollbar
//
// if (nsnull != scrollv)
// scrollv->SetParameters(mSizeY, mBounds.height - hheight, mOffsetY, NS_POINTS_TO_TWIPS_INT(12));
}
else
{
@ -580,7 +784,16 @@ void nsScrollingView :: ComputeContainerSize()
NS_RELEASE(win);
}
// now we can release the vertical srcoller if there was one...
if (mCornerView)
{
if ((mHScrollBarView && (mHScrollBarView->GetVisibility() == nsViewVisibility_kShow)) &&
(mVScrollBarView && (mVScrollBarView->GetVisibility() == nsViewVisibility_kShow)))
((CornerView *)mCornerView)->Show(PR_TRUE);
else
((CornerView *)mCornerView)->Show(PR_FALSE);
}
// now we can release the vertical scroller if there was one...
NS_IF_RELEASE(scrollv);
@ -622,6 +835,9 @@ void nsScrollingView :: ComputeContainerSize()
NS_RELEASE(win);
}
if (nsnull != mCornerView)
((CornerView *)mCornerView)->Show(PR_FALSE);
mOffsetX = mOffsetY = 0;
mSizeX = mSizeY = 0;
}
@ -645,6 +861,21 @@ void nsScrollingView :: GetVisibleOffset(nscoord *aOffsetX, nscoord *aOffsetY)
*aOffsetY = mOffsetY;
}
void nsScrollingView :: ShowQuality(PRBool aShow)
{
((CornerView *)mCornerView)->ShowQuality(aShow);
}
PRBool nsScrollingView :: GetShowQuality(void)
{
return ((CornerView *)mCornerView)->mShowQuality;
}
void nsScrollingView :: SetQuality(nsContentQuality aQuality)
{
((CornerView *)mCornerView)->SetQuality(aQuality);
}
void nsScrollingView :: AdjustChildWidgets(nsScrollingView *aScrolling, nsIView *aView, nscoord aDx, nscoord aDy, float scale)
{
PRInt32 numkids = aView->GetChildCount();
@ -746,7 +977,9 @@ nsIView * nsScrollingView :: GetScrolledView(void)
{
retview = GetChild(cnt);
if ((retview != mVScrollBarView) && (retview != mHScrollBarView))
if ((retview != mVScrollBarView) &&
(retview != mHScrollBarView) &&
(retview != mCornerView))
break;
else
retview = nsnull;

View File

@ -62,6 +62,10 @@ public:
virtual void GetVisibleOffset(nscoord *aOffsetX, nscoord *aOffsetY);
virtual nsIView * GetScrolledView(void);
virtual void ShowQuality(PRBool aShow);
virtual PRBool GetShowQuality(void);
virtual void SetQuality(nsContentQuality aQuality);
//private
void ComputeScrollArea(nsIView *aView, nsRect &aRect, nscoord aOffX, nscoord aOffY);
@ -70,6 +74,7 @@ protected:
nscoord mOffsetX, mOffsetY;
nsIView *mVScrollBarView;
nsIView *mHScrollBarView;
nsIView *mCornerView;
};
#endif

View File

@ -767,6 +767,8 @@ void nsViewManager :: SetViewClip(nsIView *aView, nsRect *rect)
void nsViewManager :: SetViewVisibility(nsIView *aView, nsViewVisibility visible)
{
aView->SetVisibility(visible);
UpdateView(aView, nsnull, 0);
}
void nsViewManager :: SetViewZindex(nsIView *aView, PRInt32 zindex)
@ -885,6 +887,48 @@ void nsViewManager :: ClearDirtyRegion()
#endif
}
void nsViewManager :: ShowQuality(PRBool aShow)
{
nsIScrollableView *scroller;
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
{
scroller->ShowQuality(aShow);
NS_RELEASE(scroller);
}
}
PRBool nsViewManager :: GetShowQuality(void)
{
nsIScrollableView *scroller;
PRBool retval = PR_FALSE;
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
{
retval = scroller->GetShowQuality();
NS_RELEASE(scroller);
}
return retval;
}
void nsViewManager :: SetQuality(nsContentQuality aQuality)
{
nsIScrollableView *scroller;
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
if (NS_OK == mRootView->QueryInterface(kscroller, (void **)&scroller))
{
scroller->SetQuality(aQuality);
NS_RELEASE(scroller);
}
}
nsIRenderingContext * nsViewManager :: CreateRenderingContext(nsIView &aView)
{
nsIView *par = &aView;

View File

@ -113,6 +113,10 @@ public:
nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext, nsRect& aBounds);
virtual void ShowQuality(PRBool aShow);
virtual PRBool GetShowQuality(void);
virtual void SetQuality(nsContentQuality aQuality);
private:
~nsViewManager();
nsIRenderingContext *CreateRenderingContext(nsIView &aView);

View File

@ -151,6 +151,8 @@ void CreateViewerMenus(Widget aParent, MenuCallbackProc aCallback)
{"Show Style Size", "y", VIEWER_SHOW_STYLE_SIZE},
{"separator", NULL, 0},
{"Debug Robot", "R", VIEWER_DEBUGROBOT},
{"separator", NULL, 0},
{"Show Content Quality", ".", VIEWER_SHOW_CONTENT_QUALITY},
{NULL, NULL, 0}
};
@ -174,6 +176,7 @@ void CreateViewerMenus(Widget aParent, MenuCallbackProc aCallback)
CreateMenuItem(menu, "demo #6", VIEWER_DEMO6, aCallback);
CreateMenuItem(menu, "demo #7", VIEWER_DEMO7, aCallback);
CreateMenuItem(menu, "demo #8", VIEWER_DEMO8, aCallback);
CreateMenuItem(menu, "demo #9", VIEWER_DEMO9, aCallback);
menu = CreatePulldownMenu(fileMenu, "Print Preview", 'P');
CreateMenuItem(menu, "One Column", VIEWER_ONE_COLUMN, aCallback);

View File

@ -52,6 +52,7 @@
#include "nsIFrame.h"
#include "nsIPresShell.h"
#include "nsISizeOfHandler.h"
#include "nsIViewManager.h"
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
@ -1012,6 +1013,20 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd)
}
break;
case VIEWER_SHOW_CONTENT_QUALITY:
if ((nsnull != wd) && (nsnull != wd->ww)) {
nsIPresContext *px = wd->ww->GetPresContext();
nsIPresShell *ps = px->GetShell();
nsIViewManager *vm = ps->GetViewManager();
vm->ShowQuality(!vm->GetShowQuality());
NS_RELEASE(vm);
NS_RELEASE(ps);
NS_RELEASE(px);
}
break;
case VIEWER_ONE_COLUMN:
case VIEWER_TWO_COLUMN:
case VIEWER_THREE_COLUMN:

View File

@ -48,11 +48,12 @@
#define VIEWER_SHOW_CONTENT_SIZE 40029
#define VIEWER_SHOW_FRAME_SIZE 40030
#define VIEWER_SHOW_STYLE_SIZE 40031
#define VIEWER_SHOW_CONTENT_QUALITY 40032
// Note: must be in ascending sequential order
#define VIEWER_ONE_COLUMN 40032
#define VIEWER_TWO_COLUMN 40033
#define VIEWER_THREE_COLUMN 40034
#define VIEWER_ONE_COLUMN 40033
#define VIEWER_TWO_COLUMN 40034
#define VIEWER_THREE_COLUMN 40035
#define JS_CONSOLE 40100

View File

@ -74,6 +74,8 @@ VIEWER MENU DISCARDABLE
MENUITEM "Show Style Size", VIEWER_SHOW_STYLE_SIZE
MENUITEM SEPARATOR
MENUITEM "Debu&g Robot", VIEWER_DEBUGROBOT
MENUITEM SEPARATOR
MENUITEM "Show Content Quality", VIEWER_SHOW_CONTENT_QUALITY
}
POPUP "&Tools"
{