зеркало из https://github.com/mozilla/pjs.git
changes to support viewobserver and troy's spankage of the device context.
This commit is contained in:
Родитель
8190f7951c
Коммит
f1fba56cbb
|
@ -6,3 +6,4 @@ nsIView.h
|
|||
nsIViewManager.h
|
||||
nsIScrollableView.h
|
||||
nsViewsCID.h
|
||||
nsIViewObserver.h
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
|
||||
DEFINES = -D_IMPL_NS_UI
|
||||
|
||||
EXPORTS = \
|
||||
nsIView.h \
|
||||
nsIViewManager.h \
|
||||
nsIScrollableView.h \
|
||||
nsViewsCID.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
|
@ -19,7 +19,7 @@ DEPTH=..\..
|
|||
IGNORE_MANIFEST=1
|
||||
|
||||
DEFINES=-D_IMPL_NS_UI
|
||||
EXPORTS=nsIView.h nsIViewManager.h nsIScrollableView.h nsViewsCID.h
|
||||
EXPORTS=nsIView.h nsIViewManager.h nsIScrollableView.h nsViewsCID.h nsIViewObserver.h
|
||||
MODULE=raptor
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -30,6 +30,7 @@ class nsIRegion;
|
|||
class nsIRenderingContext;
|
||||
class nsTransform2D;
|
||||
class nsIFrame;
|
||||
class nsIViewObserver;
|
||||
struct nsRect;
|
||||
|
||||
//this is used by the view clipping APIs since the description of
|
||||
|
@ -365,16 +366,16 @@ public:
|
|||
virtual void SetContentTransparency(PRBool aTransparent) = 0;
|
||||
|
||||
/**
|
||||
* Set the view's link to the nsIFrame part of the universe.
|
||||
* @param aFrame frame to associate with view. nsnull to disassociate
|
||||
* Set the view's link to client owned data.
|
||||
* @param aData - data to associate with view. nsnull to disassociate
|
||||
*/
|
||||
virtual void SetFrame(nsIFrame *aFrame) = 0;
|
||||
virtual void SetClientData(void *aData) = 0;
|
||||
|
||||
/**
|
||||
* Query the view for it's link to the nsIFrame part of the universe.
|
||||
* @result frame associated with view or nsnull if there is none.
|
||||
* Query the view for it's link to client owned data.
|
||||
* @result data associated with view or nsnull if there is none.
|
||||
*/
|
||||
virtual nsIFrame * GetFrame() = 0;
|
||||
virtual void * GetClientData() = 0;
|
||||
|
||||
/**
|
||||
* Get the nearest widget in this view or a parent of this view and
|
||||
|
|
|
@ -47,12 +47,12 @@ class nsIViewManager : public nsISupports
|
|||
public:
|
||||
/**
|
||||
* Initialize the ViewManager
|
||||
* Note: this instance does not hold a reference to the presentation
|
||||
* context because it holds a reference to this instance.
|
||||
* @param aPresContext the presentation context to use.
|
||||
* Note: this instance does not hold a reference to the viewobserver
|
||||
* because it holds a reference to this instance.
|
||||
* @param aContext the device context to use.
|
||||
* @result The result of the initialization, NS_OK if no errors
|
||||
*/
|
||||
virtual nsresult Init(nsIPresContext* aPresContext) = 0;
|
||||
virtual nsresult Init(nsIDeviceContext* aContext) = 0;
|
||||
|
||||
/**
|
||||
* Get the root of the view tree.
|
||||
|
@ -323,10 +323,24 @@ public:
|
|||
virtual void SetViewOpacity(nsIView *aView, float aOpacity) = 0;
|
||||
|
||||
/**
|
||||
* Get the presentation context associated with this manager
|
||||
* @result presentation context
|
||||
* Set the view observer associated with this manager
|
||||
* @param aObserver - new observer
|
||||
* @result error status
|
||||
*/
|
||||
virtual nsIPresContext* GetPresContext() = 0;
|
||||
NS_IMETHOD SetViewObserver(nsIViewObserver *aObserver) = 0;
|
||||
|
||||
/**
|
||||
* Get the view observer associated with this manager
|
||||
* @param aObserver - out parameter for observer
|
||||
* @result error status
|
||||
*/
|
||||
NS_IMETHOD GetViewObserver(nsIViewObserver *&aObserver) = 0;
|
||||
|
||||
/**
|
||||
* Get the device context associated with this manager
|
||||
* @result device context
|
||||
*/
|
||||
virtual nsIDeviceContext* GetDeviceContext() = 0;
|
||||
|
||||
/**
|
||||
* Set the area that the view manager considers to be "dirty"
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIViewObserver_h___
|
||||
#define nsIViewObserver_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsGUIEvent.h"
|
||||
|
||||
class nsIRenderingContext;
|
||||
struct nsRect;
|
||||
|
||||
#define NS_IVIEWOBSERVER_IID \
|
||||
{ 0x6a1529e0, 0x3d2c, 0x11d2, \
|
||||
{ 0xa8, 0x32, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
|
||||
|
||||
class nsIViewObserver : public nsISupports
|
||||
{
|
||||
public:
|
||||
|
||||
/* called when the observer needs to paint
|
||||
* @param aRenderingContext - rendering context to paint to
|
||||
* @param aDirtyRect - rectangle of dirty area
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD Paint(nsIView * aView,
|
||||
nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect) = 0;
|
||||
|
||||
/* called when the observer needs to handle an event
|
||||
* @param aEvent - event notification
|
||||
* @param aEventStatus - out parameter for event handling
|
||||
* status
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD HandleEvent(nsIView * aView,
|
||||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus) = 0;
|
||||
|
||||
/* called when the view has been repositioned due to scrolling
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD Scrolled(nsIView * aView) = 0;
|
||||
|
||||
/* called when the view has been resized and the
|
||||
* content within the view needs to be reflowed.
|
||||
* @param aWidth - new width of view
|
||||
* @param aHeight - new height of view
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD ResizeReflow(nsIView * aView, nscoord aWidth, nscoord aHeight) = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -85,18 +85,20 @@ void ScrollBarView :: SetPosition(nscoord x, nscoord y)
|
|||
|
||||
if (nsnull != mWindow)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
float twipToPix = px->GetTwipsToPixels();
|
||||
nscoord parx = 0, pary = 0;
|
||||
nsIWidget *pwidget = nsnull;
|
||||
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
float twipToPix;
|
||||
nscoord parx = 0, pary = 0;
|
||||
nsIWidget *pwidget = nsnull;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(twipToPix);
|
||||
|
||||
pwidget = GetOffsetFromWidget(&parx, &pary);
|
||||
NS_IF_RELEASE(pwidget);
|
||||
|
||||
mWindow->Move(NSTwipsToIntPixels((x + parx), twipToPix),
|
||||
NSTwipsToIntPixels((y + pary), twipToPix));
|
||||
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(dx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,13 +108,15 @@ void ScrollBarView :: SetDimensions(nscoord width, nscoord height, PRBool aPaint
|
|||
|
||||
if (nsnull != mWindow)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
float t2p = px->GetTwipsToPixels();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
float t2p;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
mWindow->Resize(NSTwipsToIntPixels(width, t2p), NSTwipsToIntPixels(height, t2p),
|
||||
aPaint);
|
||||
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(dx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,8 +400,7 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
|
|||
|
||||
if (rv == NS_OK)
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nsIDeviceContext *dx = cx->GetDeviceContext();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
|
||||
// Create a view for a corner cover
|
||||
|
||||
|
@ -462,7 +465,6 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
|
|||
}
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(cx);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -471,8 +473,7 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
|
|||
void nsScrollingView :: SetDimensions(nscoord width, nscoord height, PRBool aPaint)
|
||||
{
|
||||
nsRect trect;
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nsIDeviceContext *dx = cx->GetDeviceContext();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
nscoord showHorz = 0, showVert = 0;
|
||||
float scrollWidthFloat, scrollHeightFloat;
|
||||
dx->GetScrollBarDimensions(scrollWidthFloat, scrollHeightFloat);
|
||||
|
@ -501,7 +502,9 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height, PRBool aPai
|
|||
|
||||
if (nsnull != mWindow)
|
||||
{
|
||||
float t2p = cx->GetTwipsToPixels();
|
||||
float t2p;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
mClipX = width - showVert;
|
||||
mClipY = height - showHorz;
|
||||
|
@ -553,13 +556,13 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height, PRBool aPai
|
|||
// ComputeContainerSize();
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(cx);
|
||||
}
|
||||
|
||||
void nsScrollingView :: SetPosition(nscoord aX, nscoord aY)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
nsIWidget *thiswin = GetWidget();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
nsIWidget *thiswin = GetWidget();
|
||||
float t2p;
|
||||
|
||||
if (nsnull == thiswin)
|
||||
thiswin = GetOffsetFromWidget(nsnull, nsnull);
|
||||
|
@ -569,7 +572,9 @@ void nsScrollingView :: SetPosition(nscoord aX, nscoord aY)
|
|||
|
||||
nsView::SetPosition(aX, aY);
|
||||
|
||||
AdjustChildWidgets(this, this, 0, 0, px->GetTwipsToPixels());
|
||||
dx->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
AdjustChildWidgets(this, this, 0, 0, t2p);
|
||||
|
||||
if (nsnull != thiswin)
|
||||
{
|
||||
|
@ -577,7 +582,7 @@ void nsScrollingView :: SetPosition(nscoord aX, nscoord aY)
|
|||
NS_RELEASE(thiswin);
|
||||
}
|
||||
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(dx);
|
||||
}
|
||||
|
||||
PRBool nsScrollingView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
|
||||
|
@ -609,11 +614,13 @@ PRBool nsScrollingView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
|
|||
|
||||
void nsScrollingView :: HandleScrollEvent(nsGUIEvent *aEvent, PRUint32 aEventFlags)
|
||||
{
|
||||
nsIView *scview = nsView::GetViewFor(aEvent->widget);
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
float scale = px->GetTwipsToPixels();
|
||||
nscoord dx = 0, dy = 0;
|
||||
nsRect bounds;
|
||||
nsIView *scview = nsView::GetViewFor(aEvent->widget);
|
||||
nsIDeviceContext *px = mViewManager->GetDeviceContext();
|
||||
float scale;
|
||||
nscoord dx = 0, dy = 0;
|
||||
nsRect bounds;
|
||||
|
||||
px->GetAppUnitsToDevUnits(scale);
|
||||
|
||||
GetBounds(bounds);
|
||||
|
||||
|
@ -621,6 +628,9 @@ void nsScrollingView :: HandleScrollEvent(nsGUIEvent *aEvent, PRUint32 aEventFla
|
|||
{
|
||||
nscoord oy = mOffsetY;
|
||||
nscoord newpos;
|
||||
float p2t;
|
||||
|
||||
px->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
//now, this horrible thing makes sure that as we scroll
|
||||
//the document a pixel at a time, we keep the logical position of
|
||||
|
@ -632,7 +642,7 @@ void nsScrollingView :: HandleScrollEvent(nsGUIEvent *aEvent, PRUint32 aEventFla
|
|||
if ((newpos + bounds.height) > mSizeY)
|
||||
newpos = mSizeY - bounds.height;
|
||||
|
||||
mOffsetY = NSIntPixelsToTwips(NSTwipsToIntPixels(newpos, scale), px->GetPixelsToTwips());
|
||||
mOffsetY = NSIntPixelsToTwips(NSTwipsToIntPixels(newpos, scale), p2t);
|
||||
|
||||
dy = NSTwipsToIntPixels((oy - mOffsetY), scale);
|
||||
|
||||
|
@ -683,6 +693,9 @@ void nsScrollingView :: HandleScrollEvent(nsGUIEvent *aEvent, PRUint32 aEventFla
|
|||
{
|
||||
nscoord ox = mOffsetX;
|
||||
nscoord newpos;
|
||||
float p2t;
|
||||
|
||||
px->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
//now, this horrible thing makes sure that as we scroll
|
||||
//the document a pixel at a time, we keep the logical position of
|
||||
|
@ -694,7 +707,7 @@ void nsScrollingView :: HandleScrollEvent(nsGUIEvent *aEvent, PRUint32 aEventFla
|
|||
if ((newpos + bounds.width) > mSizeX)
|
||||
newpos = mSizeX - bounds.width;
|
||||
|
||||
mOffsetX = NSIntPixelsToTwips(NSTwipsToIntPixels(newpos, scale), px->GetPixelsToTwips());
|
||||
mOffsetX = NSIntPixelsToTwips(NSTwipsToIntPixels(newpos, scale), p2t);
|
||||
|
||||
dx = NSTwipsToIntPixels((ox - mOffsetX), scale);
|
||||
|
||||
|
@ -769,8 +782,6 @@ void nsScrollingView :: Notify(nsITimer * aTimer)
|
|||
|
||||
event.message = NS_MOUSE_MOVE;
|
||||
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
|
||||
GetBounds(rect);
|
||||
|
||||
event.point.x = rect.x;
|
||||
|
@ -778,9 +789,14 @@ void nsScrollingView :: Notify(nsITimer * aTimer)
|
|||
|
||||
//printf("timer %d %d\n", event.point.x, event.point.y);
|
||||
|
||||
mFrame->HandleEvent(*cx, &event, retval);
|
||||
nsIViewObserver *obs;
|
||||
|
||||
NS_RELEASE(cx);
|
||||
if (NS_OK == mViewManager->GetViewObserver(obs))
|
||||
{
|
||||
obs->HandleEvent((nsIView *)this, &event, retval);
|
||||
NS_RELEASE(obs);
|
||||
}
|
||||
|
||||
NS_RELEASE(mScrollingTimer);
|
||||
|
||||
if (NS_OK == NS_NewTimer(&mScrollingTimer))
|
||||
|
@ -878,7 +894,7 @@ nsEventStatus nsScrollingView :: HandleEvent(nsGUIEvent *aEvent, PRUint32 aEvent
|
|||
{
|
||||
if (mScrollingTimer == nsnull)
|
||||
{
|
||||
if (nsnull != mFrame)
|
||||
if (nsnull != mClientData)
|
||||
{
|
||||
if (ly < 0 || ly > trect.y)
|
||||
{
|
||||
|
@ -920,22 +936,26 @@ nsEventStatus nsScrollingView :: HandleEvent(nsGUIEvent *aEvent, PRUint32 aEvent
|
|||
{
|
||||
nsEventStatus retval;
|
||||
|
||||
if (nsnull != mFrame)
|
||||
if (nsnull != mClientData)
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nscoord xoff, yoff;
|
||||
nsIViewObserver *obs;
|
||||
|
||||
GetScrollOffset(&xoff, &yoff);
|
||||
if (NS_OK == mViewManager->GetViewObserver(obs))
|
||||
{
|
||||
nscoord xoff, yoff;
|
||||
|
||||
aEvent->point.x += xoff;
|
||||
aEvent->point.y += yoff;
|
||||
GetScrollOffset(&xoff, &yoff);
|
||||
|
||||
mFrame->HandleEvent(*cx, aEvent, retval);
|
||||
aEvent->point.x += xoff;
|
||||
aEvent->point.y += yoff;
|
||||
|
||||
aEvent->point.x -= xoff;
|
||||
aEvent->point.y -= yoff;
|
||||
obs->HandleEvent((nsIView *)this, aEvent, retval);
|
||||
|
||||
NS_RELEASE(cx);
|
||||
aEvent->point.x -= xoff;
|
||||
aEvent->point.y -= yoff;
|
||||
|
||||
NS_RELEASE(obs);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -956,14 +976,16 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
|
||||
if (nsnull != scrollview)
|
||||
{
|
||||
nscoord dx = 0, dy = 0;
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
nscoord hwidth, hheight;
|
||||
nscoord vwidth, vheight;
|
||||
PRUint32 oldsizey = mSizeY, oldsizex = mSizeX;
|
||||
nsRect area(0, 0, 0, 0);
|
||||
nscoord offx, offy;
|
||||
float scale = px->GetTwipsToPixels();
|
||||
nscoord dx = 0, dy = 0;
|
||||
nsIDeviceContext *px = mViewManager->GetDeviceContext();
|
||||
nscoord hwidth, hheight;
|
||||
nscoord vwidth, vheight;
|
||||
PRUint32 oldsizey = mSizeY, oldsizex = mSizeX;
|
||||
nsRect area(0, 0, 0, 0);
|
||||
nscoord offx, offy;
|
||||
float scale;
|
||||
|
||||
px->GetAppUnitsToDevUnits(scale);
|
||||
|
||||
ComputeScrollArea(scrollview, area, 0, 0);
|
||||
|
||||
|
@ -1007,8 +1029,11 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
//now update the scroller position for the new size
|
||||
|
||||
PRUint32 oldpos = scrollv->GetPosition();
|
||||
float p2t;
|
||||
|
||||
mOffsetY = NSIntPixelsToTwips(NSTwipsToIntPixels(nscoord(((float)oldpos * mSizeY) / oldsizey), scale), px->GetPixelsToTwips());
|
||||
px->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
mOffsetY = NSIntPixelsToTwips(NSTwipsToIntPixels(nscoord(((float)oldpos * mSizeY) / oldsizey), scale), p2t);
|
||||
|
||||
dy = NSTwipsToIntPixels((offy - mOffsetY), scale);
|
||||
|
||||
|
@ -1059,8 +1084,11 @@ void nsScrollingView :: ComputeContainerSize()
|
|||
//now update the scroller position for the new size
|
||||
|
||||
PRUint32 oldpos = scrollh->GetPosition();
|
||||
float p2t;
|
||||
|
||||
mOffsetX = NSIntPixelsToTwips(NSTwipsToIntPixels(nscoord(((float)oldpos * mSizeX) / oldsizex), scale), px->GetPixelsToTwips());
|
||||
px->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
mOffsetX = NSIntPixelsToTwips(NSTwipsToIntPixels(nscoord(((float)oldpos * mSizeX) / oldsizex), scale), p2t);
|
||||
|
||||
dx = NSTwipsToIntPixels((offx - mOffsetX), scale);
|
||||
|
||||
|
@ -1207,10 +1235,14 @@ nsScrollPreference nsScrollingView :: GetScrollPreference(void)
|
|||
NS_IMETHODIMP
|
||||
nsScrollingView :: ScrollTo(nscoord aX, nscoord aY, PRUint32 aUpdateFlags)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
float t2p = px->GetTwipsToPixels();
|
||||
float p2t = px->GetPixelsToTwips();
|
||||
NS_RELEASE(px);
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
float t2p;
|
||||
float p2t;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(t2p);
|
||||
dx->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
|
||||
nsIWidget* win;
|
||||
win = mVScrollBarView->GetWidget();
|
||||
|
|
|
@ -215,11 +215,13 @@ nsresult nsView :: Init(nsIViewManager* aManager,
|
|||
// check if a real window has to be created
|
||||
if (aWindowCIID)
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nsIDeviceContext *dx = cx->GetDeviceContext();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
nsRect trect = aBounds;
|
||||
float scale;
|
||||
|
||||
trect *= cx->GetTwipsToPixels();
|
||||
dx->GetAppUnitsToDevUnits(scale);
|
||||
|
||||
trect *= scale;
|
||||
|
||||
if (NS_OK == LoadWidget(*aWindowCIID))
|
||||
{
|
||||
|
@ -234,7 +236,6 @@ nsresult nsView :: Init(nsIViewManager* aManager,
|
|||
}
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(cx);
|
||||
}
|
||||
|
||||
SetVisibility(aVisibilityFlag);
|
||||
|
@ -395,11 +396,15 @@ PRBool nsView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
|
|||
}
|
||||
}
|
||||
|
||||
if (nsnull != mFrame)
|
||||
if (nsnull != mClientData)
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
mFrame->Paint(*cx, rc, rect);
|
||||
NS_RELEASE(cx);
|
||||
nsIViewObserver *obs;
|
||||
|
||||
if (NS_OK == mViewManager->GetViewObserver(obs))
|
||||
{
|
||||
obs->Paint((nsIView *)this, rc, rect);
|
||||
NS_RELEASE(obs);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SHOW_VIEW_BORDERS
|
||||
|
@ -475,8 +480,16 @@ PRBool nsView :: Paint(nsIRenderingContext& rc, const nsIRegion& region, PRUint3
|
|||
{
|
||||
// XXX apply region to rc
|
||||
// XXX get bounding rect from region
|
||||
//if (nsnull != mFrame)
|
||||
// mFrame->Paint(rc, rect, aPaintFlags);
|
||||
//if (nsnull != mClientData)
|
||||
//{
|
||||
// nsIViewObserver *obs;
|
||||
//
|
||||
// if (NS_OK == mViewManager->GetViewObserver(obs))
|
||||
// {
|
||||
// obs->Paint((nsIView *)this, rc, rect, aPaintFlags);
|
||||
// NS_RELEASE(obs);
|
||||
// }
|
||||
//}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -526,22 +539,26 @@ nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
|||
}
|
||||
|
||||
//if the view's children didn't take the event, check the view itself.
|
||||
if (retval == nsEventStatus_eIgnore && nsnull != mFrame)
|
||||
if ((retval == nsEventStatus_eIgnore) && (nsnull != mClientData))
|
||||
{
|
||||
nsIPresContext *cx = mViewManager->GetPresContext();
|
||||
nscoord xoff, yoff;
|
||||
nsIViewObserver *obs;
|
||||
|
||||
GetScrollOffset(&xoff, &yoff);
|
||||
if (NS_OK == mViewManager->GetViewObserver(obs))
|
||||
{
|
||||
nscoord xoff, yoff;
|
||||
|
||||
event->point.x += xoff;
|
||||
event->point.y += yoff;
|
||||
GetScrollOffset(&xoff, &yoff);
|
||||
|
||||
mFrame->HandleEvent(*cx, event, retval);
|
||||
event->point.x += xoff;
|
||||
event->point.y += yoff;
|
||||
|
||||
event->point.x -= xoff;
|
||||
event->point.y -= yoff;
|
||||
obs->HandleEvent((nsIView *)this, event, retval);
|
||||
|
||||
NS_RELEASE(cx);
|
||||
event->point.x -= xoff;
|
||||
event->point.y -= yoff;
|
||||
|
||||
NS_RELEASE(obs);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -553,11 +570,13 @@ void nsView :: SetPosition(nscoord x, nscoord y)
|
|||
|
||||
if (nsnull != mWindow)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
nscoord offx, offy, parx = 0, pary = 0;
|
||||
float scale = px->GetTwipsToPixels();
|
||||
nsIWidget *pwidget = nsnull;
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
nscoord offx, offy, parx = 0, pary = 0;
|
||||
float scale;
|
||||
nsIWidget *pwidget = nsnull;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(scale);
|
||||
|
||||
GetScrollOffset(&offx, &offy);
|
||||
|
||||
pwidget = GetOffsetFromWidget(&parx, &pary);
|
||||
|
@ -566,7 +585,7 @@ void nsView :: SetPosition(nscoord x, nscoord y)
|
|||
mWindow->Move(NSTwipsToIntPixels((x + parx - offx), scale),
|
||||
NSTwipsToIntPixels((y + pary - offy), scale));
|
||||
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(dx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,13 +620,15 @@ void nsView :: SetDimensions(nscoord width, nscoord height, PRBool aPaint)
|
|||
|
||||
if (nsnull != mWindow)
|
||||
{
|
||||
nsIPresContext *px = mViewManager->GetPresContext();
|
||||
float t2p = px->GetTwipsToPixels();
|
||||
nsIDeviceContext *dx = mViewManager->GetDeviceContext();
|
||||
float t2p;
|
||||
|
||||
dx->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
mWindow->Resize(NSTwipsToIntPixels(width, t2p), NSTwipsToIntPixels(height, t2p),
|
||||
aPaint);
|
||||
|
||||
NS_RELEASE(px);
|
||||
NS_RELEASE(dx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -821,15 +842,14 @@ void nsView :: SetContentTransparency(PRBool aTransparent)
|
|||
mVFlags &= ~VIEW_FLAG_TRANSPARENT;
|
||||
}
|
||||
|
||||
// Frames have a pointer to the view, so don't AddRef the frame.
|
||||
void nsView :: SetFrame(nsIFrame *aFrame)
|
||||
void nsView :: SetClientData(void *aData)
|
||||
{
|
||||
mFrame = aFrame;
|
||||
mClientData = aData;
|
||||
}
|
||||
|
||||
nsIFrame * nsView :: GetFrame()
|
||||
void * nsView :: GetClientData(void)
|
||||
{
|
||||
return mFrame;
|
||||
return mClientData;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIViewObserver.h"
|
||||
|
||||
class nsIPresContext;
|
||||
|
||||
|
@ -90,8 +91,8 @@ public:
|
|||
virtual PRBool HasTransparency();
|
||||
virtual void SetContentTransparency(PRBool aTransparent);
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
virtual void SetFrame(nsIFrame *aFrame);
|
||||
virtual nsIFrame * GetFrame();
|
||||
virtual void SetClientData(void *aData);
|
||||
virtual void * GetClientData();
|
||||
virtual nsIWidget * GetOffsetFromWidget(nscoord *aDx, nscoord *aDy);
|
||||
virtual void GetScrollOffset(nscoord *aDx, nscoord *aDy);
|
||||
|
||||
|
@ -111,7 +112,7 @@ protected:
|
|||
//XXX should there be pointers to last child so backward walking is fast?
|
||||
nsIView *mNextSibling;
|
||||
nsIView *mFirstChild;
|
||||
nsIFrame *mFrame;
|
||||
void *mClientData;
|
||||
PRInt32 mZindex;
|
||||
nsViewVisibility mVis;
|
||||
PRInt32 mNumKids;
|
||||
|
|
|
@ -95,6 +95,9 @@ nsViewManager :: ~nsViewManager()
|
|||
|
||||
mDrawingSurface = nsnull;
|
||||
}
|
||||
|
||||
mObserver = nsnull;
|
||||
mContext = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsViewManager, knsViewManagerIID)
|
||||
|
@ -123,18 +126,19 @@ nsrefcnt nsViewManager::Release(void)
|
|||
|
||||
// We don't hold a reference to the presentation context because it
|
||||
// holds a reference to us.
|
||||
nsresult nsViewManager::Init(nsIPresContext* aPresContext)
|
||||
nsresult nsViewManager :: Init(nsIDeviceContext* aContext)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_PRECONDITION(nsnull != aPresContext, "null ptr");
|
||||
if (nsnull == aPresContext) {
|
||||
NS_PRECONDITION(nsnull != aContext, "null ptr");
|
||||
|
||||
if (nsnull == aContext) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (nsnull != mContext) {
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
}
|
||||
mContext = aPresContext;
|
||||
mContext = aContext;
|
||||
|
||||
mDSBounds.Empty();
|
||||
mDrawingSurface = nsnull;
|
||||
|
@ -217,19 +221,14 @@ void nsViewManager :: GetWindowDimensions(nscoord *width, nscoord *height)
|
|||
|
||||
void nsViewManager :: SetWindowDimensions(nscoord width, nscoord height)
|
||||
{
|
||||
nsIPresShell* presShell = mContext->GetShell();
|
||||
|
||||
// Resize the root view
|
||||
if (nsnull != mRootView)
|
||||
mRootView->SetDimensions(width, height);
|
||||
|
||||
//printf("new dims: %4.2f %4.2f...\n", width / 20.0f, height / 20.0f);
|
||||
// Inform the presentation shell that we've been resized
|
||||
if (nsnull != presShell)
|
||||
{
|
||||
presShell->ResizeReflow(width, height);
|
||||
NS_RELEASE(presShell);
|
||||
}
|
||||
if (nsnull != mObserver)
|
||||
mObserver->ResizeReflow(mRootView, width, height);
|
||||
}
|
||||
|
||||
void nsViewManager :: GetWindowOffsets(nscoord *xoffset, nscoord *yoffset)
|
||||
|
@ -313,7 +312,7 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsI
|
|||
localcx->SelectOffScreenDrawingSurface(ds);
|
||||
}
|
||||
|
||||
scale = mContext->GetTwipsToPixels();
|
||||
mContext->GetAppUnitsToDevUnits(scale);
|
||||
|
||||
GetWindowOffsets(&xoff, &yoff);
|
||||
|
||||
|
@ -322,10 +321,13 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsI
|
|||
localcx->SetClipRegion(*region, nsClipCombine_kReplace);
|
||||
region->Offset(NSTwipsToIntPixels(xoff, scale), NSTwipsToIntPixels(yoff, scale));
|
||||
|
||||
nsRect trect;
|
||||
nsRect trect;
|
||||
float p2t;
|
||||
|
||||
mContext->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
region->GetBoundingBox(&trect.x, &trect.y, &trect.width, &trect.height);
|
||||
trect.ScaleRoundOut(mContext->GetPixelsToTwips());
|
||||
trect.ScaleRoundOut(p2t);
|
||||
|
||||
aView->Paint(*localcx, trect, 0);
|
||||
|
||||
|
@ -436,9 +438,12 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsR
|
|||
|
||||
if ((nsnull != mDirtyRegion) && !mDirtyRegion->IsEmpty())
|
||||
{
|
||||
nsRect pixrect = trect;
|
||||
nsRect pixrect = trect;
|
||||
float t2p;
|
||||
|
||||
pixrect.ScaleRoundIn(mContext->GetTwipsToPixels());
|
||||
mContext->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
pixrect.ScaleRoundIn(t2p);
|
||||
mDirtyRegion->Subtract(pixrect.x, pixrect.y, pixrect.width, pixrect.height);
|
||||
}
|
||||
|
||||
|
@ -554,7 +559,9 @@ void nsViewManager :: UpdateView(nsIView *aView, const nsRect &aRect, PRUint32 a
|
|||
rrect = mDirtyRect;
|
||||
#else
|
||||
mDirtyRegion->GetBoundingBox(&rrect.x, &rrect.y, &rrect.width, &rrect.height);
|
||||
rrect.ScaleRoundOut(mContext->GetPixelsToTwips());
|
||||
float p2t;
|
||||
mContext->GetDevUnitsToAppUnits(p2t);
|
||||
rrect.ScaleRoundOut(p2t);
|
||||
#endif
|
||||
rrect.IntersectRect(rrect, vrect);
|
||||
|
||||
|
@ -611,9 +618,11 @@ nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
|||
if (view == mRootView)
|
||||
{
|
||||
// Convert from pixels to twips
|
||||
float p2t = mContext->GetPixelsToTwips();
|
||||
float p2t;
|
||||
nsIScrollableView *scrollView;
|
||||
|
||||
mContext->GetDevUnitsToAppUnits(p2t);
|
||||
|
||||
//XXX hey look, a hack! :) i'm not proud of it, but it does
|
||||
//work. the purpose is to prevent resizes of the view if the
|
||||
//clip size (assumed to be the size of this window) is the same
|
||||
|
@ -622,7 +631,9 @@ nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
|||
if (NS_OK == mRootView->QueryInterface(kIScrollableViewIID, (void **)&scrollView))
|
||||
{
|
||||
nscoord sizex, sizey;
|
||||
float t2p = mContext->GetTwipsToPixels();
|
||||
float t2p;
|
||||
|
||||
mContext->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
scrollView->GetClipSize(&sizex, &sizey);
|
||||
|
||||
|
@ -647,9 +658,10 @@ nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
|||
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
||||
if (nsnull != view) {
|
||||
|
||||
float convert = mContext->GetPixelsToTwips();
|
||||
float convert;
|
||||
nsRect trect = *((nsPaintEvent*)aEvent)->rect;
|
||||
nsIDeviceContext *dx = mContext->GetDeviceContext();
|
||||
|
||||
mContext->GetDevUnitsToAppUnits(convert);
|
||||
|
||||
trect *= convert;
|
||||
|
||||
|
@ -660,8 +672,6 @@ nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
|||
NS_VMREFRESH_IMMEDIATE |
|
||||
NS_VMREFRESH_AUTO_DOUBLE_BUFFER);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
|
||||
result = nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
break;
|
||||
|
@ -685,25 +695,25 @@ nsEventStatus nsViewManager :: DispatchEvent(nsGUIEvent *aEvent)
|
|||
view = nsView::GetViewFor(aEvent->widget);
|
||||
}
|
||||
|
||||
if (nsnull != view) {
|
||||
nsIViewManager *vm = view->GetViewManager();
|
||||
nsIPresContext *cx = vm->GetPresContext();
|
||||
if (nsnull != view)
|
||||
{
|
||||
float p2t, t2p;
|
||||
|
||||
// pass on to view somewhere else to deal with
|
||||
|
||||
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, cx->GetPixelsToTwips());
|
||||
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, cx->GetPixelsToTwips());
|
||||
mContext->GetDevUnitsToAppUnits(p2t);
|
||||
mContext->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, p2t);
|
||||
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, p2t);
|
||||
|
||||
|
||||
result = view->HandleEvent(aEvent, NS_VIEW_FLAG_CHECK_CHILDREN |
|
||||
NS_VIEW_FLAG_CHECK_PARENT |
|
||||
NS_VIEW_FLAG_CHECK_SIBLINGS);
|
||||
|
||||
aEvent->point.x = NSTwipsToIntPixels(aEvent->point.x, cx->GetTwipsToPixels());
|
||||
aEvent->point.y = NSTwipsToIntPixels(aEvent->point.y, cx->GetTwipsToPixels());
|
||||
|
||||
NS_RELEASE(cx);
|
||||
NS_RELEASE(vm);
|
||||
aEvent->point.x = NSTwipsToIntPixels(aEvent->point.x, t2p);
|
||||
aEvent->point.y = NSTwipsToIntPixels(aEvent->point.y, t2p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1011,7 +1021,25 @@ void nsViewManager :: SetViewOpacity(nsIView *aView, float aOpacity)
|
|||
aView->SetOpacity(aOpacity);
|
||||
}
|
||||
|
||||
nsIPresContext * nsViewManager :: GetPresContext()
|
||||
NS_IMETHODIMP nsViewManager :: SetViewObserver(nsIViewObserver *aObserver)
|
||||
{
|
||||
mObserver = aObserver;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsViewManager :: GetViewObserver(nsIViewObserver *&aObserver)
|
||||
{
|
||||
if (nsnull != mObserver)
|
||||
{
|
||||
aObserver = mObserver;
|
||||
NS_ADDREF(mObserver);
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
nsIDeviceContext * nsViewManager :: GetDeviceContext()
|
||||
{
|
||||
NS_IF_ADDREF(mContext);
|
||||
return mContext;
|
||||
|
@ -1086,7 +1114,6 @@ nsIRenderingContext * nsViewManager :: CreateRenderingContext(nsIView &aView)
|
|||
nsIView *par = &aView;
|
||||
nsIWidget *win;
|
||||
nsIRenderingContext *cx = nsnull;
|
||||
nsIDeviceContext *dx;
|
||||
nscoord x, y, ax = 0, ay = 0;
|
||||
|
||||
do
|
||||
|
@ -1114,13 +1141,11 @@ nsIRenderingContext * nsViewManager :: CreateRenderingContext(nsIView &aView)
|
|||
|
||||
if (nsnull != win)
|
||||
{
|
||||
dx = mContext->GetDeviceContext();
|
||||
dx->CreateRenderingContext(&aView, cx);
|
||||
mContext->CreateRenderingContext(&aView, cx);
|
||||
|
||||
if (nsnull != cx)
|
||||
cx->Translate(ax, ay);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(win);
|
||||
}
|
||||
|
||||
|
@ -1146,8 +1171,11 @@ void nsViewManager :: AddRectToDirtyRegion(nsRect &aRect)
|
|||
}
|
||||
|
||||
nsRect trect = aRect;
|
||||
float t2p;
|
||||
|
||||
trect.ScaleRoundOut(mContext->GetTwipsToPixels());
|
||||
mContext->GetAppUnitsToDevUnits(t2p);
|
||||
|
||||
trect.ScaleRoundOut(t2p);
|
||||
mDirtyRegion->Union(trect.x, trect.y, trect.width, trect.height);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsIPresContext* aPresContext);
|
||||
virtual nsresult Init(nsIDeviceContext* aContext);
|
||||
|
||||
virtual nsIView *GetRootView();
|
||||
virtual void SetRootView(nsIView *aView);
|
||||
|
@ -99,7 +99,10 @@ public:
|
|||
virtual void SetViewContentTransparency(nsIView *aView, PRBool aTransparent);
|
||||
virtual void SetViewOpacity(nsIView *aView, float aOpacity);
|
||||
|
||||
virtual nsIPresContext* GetPresContext();
|
||||
NS_IMETHOD SetViewObserver(nsIViewObserver *aObserver);
|
||||
NS_IMETHOD GetViewObserver(nsIViewObserver *&aObserver);
|
||||
|
||||
virtual nsIDeviceContext* GetDeviceContext();
|
||||
|
||||
virtual void ClearDirtyRegion();
|
||||
|
||||
|
@ -123,7 +126,8 @@ private:
|
|||
void Refresh(nsIView* aView, nsIRenderingContext *aContext,
|
||||
nsRect *rect, PRUint32 aUpdateFlags);
|
||||
|
||||
nsIPresContext *mContext;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIViewObserver *mObserver;
|
||||
nsIWidget *mRootWindow;
|
||||
PRTime mLastRefresh;
|
||||
nsIRegion *mDirtyRegion;
|
||||
|
|
Загрузка…
Ссылка в новой задаче