Bug 370642: remove use of views in layout/inspector. r+sr=dbaron.

This commit is contained in:
sharparrow1%yahoo.com 2007-02-18 04:44:21 +00:00
Родитель a9459f49db
Коммит 9544d61b5c
8 изменённых файлов: 29 добавлений и 107 удалений

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

@ -3562,9 +3562,23 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame,
}
nsIWidget* widget = nsnull;
// Never pass a widget to a print rendering context
if (mPresContext->IsScreen())
widget = aFrame->GetWindow();
nsPoint offset(0,0);
if (mPresContext->IsScreen()) {
// Get the widget to create the rendering context for and calculate
// the offset from the frame to it. (Calculating the offset is important
// if the frame isn't the root frame.)
nsPoint viewOffset;
nsIView* view = aFrame->GetClosestView(&viewOffset);
nsPoint widgetOffset;
widget = view->GetNearestWidget(&widgetOffset);
offset = viewOffset + widgetOffset;
} else {
nsIFrame* pageFrame = nsLayoutUtils::GetPageFrame(aFrame);
// This might not always come up with a frame, i.e. during reflow;
// that's fine, because the translation doesn't matter during reflow.
if (pageFrame)
offset = aFrame->GetOffsetTo(pageFrame);
}
nsresult rv;
nsIRenderingContext* result = nsnull;
@ -3577,6 +3591,8 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame,
}
*aResult = result;
result->Translate(offset.x, offset.y);
return rv;
}

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

@ -40,9 +40,6 @@
#include "inLayoutUtils.h"
#include "nsIServiceManager.h"
#include "nsIViewManager.h"
#include "nsIDeviceContext.h"
#include "nsIWidget.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
#include "nsReadableUtils.h"
@ -58,7 +55,6 @@ inFlasher::inFlasher() :
mThickness(0),
mInvert(PR_FALSE)
{
mCSSUtils = do_GetService(kInspectorCSSUtilsCID);
}
inFlasher::~inFlasher()
@ -145,17 +141,7 @@ inFlasher::RepaintElement(nsIDOMElement* aElement)
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
if (!frame) return NS_OK;
nsIFrame* parentWithView = frame->GetAncestorWithViewExternal();
if (parentWithView) {
nsIView* view = parentWithView->GetViewExternal();
if (view) {
nsIViewManager* viewManager = view->GetViewManager();
if (viewManager) {
nsRect rect = parentWithView->GetRect();
viewManager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC);
}
}
}
frame->Invalidate(frame->GetRect());
return NS_OK;
}
@ -168,18 +154,14 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement)
nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
if (!presShell) return NS_OK;
PRBool isFirstFrame = PR_TRUE;
nsCOMPtr<nsIRenderingContext> rcontext;
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
PRBool isFirstFrame = PR_TRUE;
while (frame) {
if (!rcontext) {
presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext));
}
// get view bounds in case this frame is being scrolled
nsRect rect = frame->GetRect();
nsPoint origin = inLayoutUtils::GetClientOrigin(frame);
rect.MoveTo(origin);
mCSSUtils->AdjustRectForMargins(frame, rect);
nsCOMPtr<nsIRenderingContext> rcontext;
presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext));
nsRect rect(nsPoint(0,0), frame->GetSize());
if (mInvert) {
rcontext->InvertRect(rect);

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

@ -69,8 +69,6 @@ protected:
PRBool aDir, PRBool aBounds,
nsIRenderingContext* aRenderContext);
nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
nscolor mColor;
PRUint16 mThickness;

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

@ -95,14 +95,6 @@ inLayoutUtils::GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell)
return aShell->GetPrimaryFrameFor(content);
}
already_AddRefed<nsIRenderingContext>
inLayoutUtils::GetRenderingContextFor(nsIPresShell* aShell)
{
nsCOMPtr<nsIWidget> widget;
aShell->GetViewManager()->GetWidget(getter_AddRefs(widget));
return widget->GetRenderingContext(); // AddRefs
}
nsIEventStateManager*
inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
{
@ -123,28 +115,6 @@ inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
return shell->GetPresContext()->EventStateManager();
}
nsPoint
inLayoutUtils::GetClientOrigin(nsIFrame* aFrame)
{
nsPoint result(0,0);
nsIView* view;
aFrame->GetOffsetFromView(result, &view);
nsIView* rootView = nsnull;
if (view) {
nsIViewManager* viewManager = view->GetViewManager();
NS_ASSERTION(viewManager, "View must have a viewmanager");
viewManager->GetRootView(rootView);
}
while (view) {
result += view->GetPosition();
if (view == rootView) {
break;
}
view = view->GetParent();
}
return result;
}
nsBindingManager*
inLayoutUtils::GetBindingManagerFor(nsIDOMNode* aNode)
{

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

@ -55,22 +55,10 @@ public:
static nsIDOMWindowInternal* GetWindowFor(nsIDOMDocument* aDoc);
static nsIPresShell* GetPresShellFor(nsISupports* aThing);
static nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell);
static already_AddRefed<nsIRenderingContext> GetRenderingContextFor(nsIPresShell* aShell);
static nsIEventStateManager* GetEventStateManagerFor(nsIDOMElement *aElement);
static nsBindingManager* GetBindingManagerFor(nsIDOMNode* aNode);
static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode);
static nsIDOMNode* GetContainerFor(nsIDOMDocument* aDoc);
/**
* This function returns the offset of a frame with respect to the
* root view of the aPresContext's viewmanager (for use by
* inFlasher::DrawElementOutline and the like)
*
* @param aFrame the frame whose offset we want
* @param aPresContext the presentation context
* @return the offset
*/
static nsPoint GetClientOrigin(nsIFrame* aFrame);
};
#endif // __inLayoutUtils_h__

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

@ -52,9 +52,10 @@ class nsIContent;
class nsIDOMElement;
class nsIArray;
// 35dfc2a6-b069-4014-ad4b-01927e77d828
#define NS_IINSPECTORCSSUTILS_IID \
{ 0xdf2072d2, 0x57f0, 0x4c62, \
{0xa7, 0x3f, 0xa5, 0x2f, 0xf2, 0xf0, 0x99, 0xa6 } }
{ 0x35dfc2a6, 0xb069, 0x4014, \
{0xad, 0x4b, 0x01, 0x92, 0x7e, 0x77, 0xd8, 0x28 } }
// 7ef2f07f-6e34-410b-8336-88acd1cd16b7
#define NS_INSPECTORCSSUTILS_CID \
@ -76,9 +77,6 @@ public:
NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule) = 0;
NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot) = 0;
// Hooks to avoid having to use nsStyleCoord.
NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) = 0;
// Hooks to methods that need nsStyleContext
NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent,
nsRuleNode** aParent) = 0;

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

@ -96,35 +96,6 @@ nsInspectorCSSUtils::IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot)
return NS_OK;
}
NS_IMETHODIMP
nsInspectorCSSUtils::AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect)
{
const nsStyleMargin* margins = aFrame->GetStyleMargin();
// adjust coordinates for margins
nsStyleCoord coord;
if (margins->mMargin.GetTopUnit() == eStyleUnit_Coord) {
margins->mMargin.GetTop(coord);
aRect.y -= coord.GetCoordValue();
aRect.height += coord.GetCoordValue();
}
if (margins->mMargin.GetLeftUnit() == eStyleUnit_Coord) {
margins->mMargin.GetLeft(coord);
aRect.x -= coord.GetCoordValue();
aRect.width += coord.GetCoordValue();
}
if (margins->mMargin.GetRightUnit() == eStyleUnit_Coord) {
margins->mMargin.GetRight(coord);
aRect.width += coord.GetCoordValue();
}
if (margins->mMargin.GetBottomUnit() == eStyleUnit_Coord) {
margins->mMargin.GetBottom(coord);
aRect.height += coord.GetCoordValue();
}
return NS_OK;
}
/* static */
nsStyleContext*
nsInspectorCSSUtils::GetStyleContextForFrame(nsIFrame* aFrame)

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

@ -62,7 +62,6 @@ public:
NS_IMETHOD GetRuleNodeParent(nsRuleNode *aNode, nsRuleNode **aParent);
NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule);
NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot);
NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect);
NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent,
nsRuleNode** aRuleNode);
NS_IMETHOD GetBindingURLs(nsIDOMElement *aElement, nsIArray **aResult);