Bug 334416: Misc view usage cleanups. r+sr=roc.

This commit is contained in:
sharparrow1%yahoo.com 2006-04-18 06:05:24 +00:00
Родитель 637a3c6242
Коммит 67d4723e36
11 изменённых файлов: 18 добавлений и 214 удалений

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

@ -848,37 +848,6 @@ NS_IMETHODIMP nsAccessible::GetChildAtPoint(PRInt32 tx, PRInt32 ty, nsIAccessibl
return NS_ERROR_FAILURE;
}
void nsAccessible::GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame, nsRect *aRect)
{
aRect->x = aRect->y = 0;
if (!aPresContext) {
return;
}
nsPoint origin(0,0);
nsIView *view = aFrame->GetViewExternal();
if (!view) {
aFrame->GetOffsetFromView(origin, &view);
NS_ASSERTION(view, "Frame has no view");
}
nsPoint viewOrigin(0,0);
nsIWidget *widget = view->GetNearestWidget(&viewOrigin);
origin += viewOrigin;
// Get the scale from that Presentation Context
float t2p = aPresContext->TwipsToPixels();
// Convert to pixels using that scale
origin.x = NSTwipsToIntPixels(origin.x, t2p);
origin.y = NSTwipsToIntPixels(origin.y, t2p);
// Add the widget's screen coordinates to the offset we've counted
NS_ASSERTION(widget, "No widget for top view");
widget->WidgetToScreen(nsRect(origin.x, origin.y, 1, 1), *aRect);
}
void nsAccessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
{
/*
@ -998,8 +967,7 @@ NS_IMETHODIMP nsAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PR
// We have the union of the rectangle, now we need to put it in absolute screen coords
nsRect orgRectPixels, pageRectPixels;
GetScreenOrigin(presContext, aBoundingFrame, &orgRectPixels);
nsRect orgRectPixels = aBoundingFrame->GetScreenRectExternal();
*x += orgRectPixels.x;
*y += orgRectPixels.y;

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

@ -174,7 +174,6 @@ protected:
// helper method to verify frames
static nsresult GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut);
static nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
void GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame, nsRect *aRect);
nsresult AppendFlatStringFromSubtreeRecurse(nsIContent *aContent, nsAString *aFlatString);
virtual void CacheChildren(PRBool aWalkAnonContent);

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

@ -142,7 +142,7 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *w
imageFrame->GetImageMap(presContext, getter_AddRefs(map));
NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
nsRect rect, orgRectPixels, pageRectPixels;
nsRect rect, orgRectPixels;
rv = map->GetBoundsForAreaContent(ourContent, presContext, rect);
NS_ENSURE_SUCCESS(rv, rv);
@ -152,13 +152,13 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *w
*x = NSTwipsToIntPixels(rect.x, t2p);
*y = NSTwipsToIntPixels(rect.y, t2p);
// XXX aaronl not sure why we have to subtract the x,y from the width, height
// -- but it works perfectly!
// XXX Areas are screwy; they return their rects as a pair of points, one pair
// stored into the width and height.
*width = NSTwipsToIntPixels(rect.width, t2p) - *x;
*height = NSTwipsToIntPixels(rect.height, t2p) - *y;
// Put coords in absolute screen coords
GetScreenOrigin(presContext, frame, &orgRectPixels);
orgRectPixels = frame->GetScreenRectExternal();
*x += orgRectPixels.x;
*y += orgRectPixels.y;

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

@ -68,7 +68,6 @@
#include "nsITransactionManager.h"
#include "nsIAbsorbingTransaction.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIViewManager.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
@ -2142,23 +2141,6 @@ GetEditorContentWindow(nsIPresShell *aPresShell, nsIDOMElement *aRoot, nsIWidget
if (!frame)
return NS_ERROR_FAILURE;
// Check first to see if this frame contains a view with a native widget.
nsIView *view = frame->GetViewExternal();
if (view)
{
*aResult = view->GetWidget();
if (*aResult) {
NS_ADDREF(*aResult);
return NS_OK;
}
}
// frame doesn't have a view with a widget, so call GetWindow()
// which will traverse it's parent hierarchy till it finds a
// view with a widget.
*aResult = frame->GetWindow();
if (!*aResult)
return NS_ERROR_FAILURE;

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

@ -56,12 +56,6 @@
#include "nsIPrefService.h"
#include "nsILookAndFeel.h"
#include "nsPresContext.h"
#ifdef USE_HACK_REPAINT
// for repainting hack only
#include "nsIView.h"
#include "nsIViewManager.h"
// end repainting hack only
#endif
// Drag & Drop, Clipboard
#include "nsIServiceManager.h"
@ -1058,20 +1052,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent)
selCon->SetCaretReadOnly(kIsReadonly);
selCon->SetCaretEnabled(PR_TRUE);
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
#ifdef USE_HACK_REPAINT
// begin hack repaint
nsIViewManager* viewmgr = ps->GetViewManager();
if (viewmgr) {
nsIView* view;
viewmgr->GetRootView(view); // views are not refCounted
if (view) {
viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE);
}
}
// end hack repaint
#else
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
#endif
}
}
}
@ -1123,21 +1104,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent)
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
}
#ifdef USE_HACK_REPAINT
// begin hack repaint
nsIViewManager* viewmgr = ps->GetViewManager();
if (viewmgr)
{
nsIView* view;
viewmgr->GetRootView(view); // views are not refCounted
if (view) {
viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE);
}
}
// end hack repaint
#else
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
#endif
}
}
}

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

@ -147,72 +147,6 @@ inLayoutUtils::GetClientOrigin(nsIFrame* aFrame)
return result;
}
nsRect&
inLayoutUtils::GetScreenOrigin(nsIDOMElement* aElement)
{
nsRect* rect = new nsRect(0,0,0,0);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
nsCOMPtr<nsIDocument> doc = content->GetDocument();
if (doc) {
// Get Presentation shell 0
nsIPresShell *presShell = doc->GetShellAt(0);
if (presShell) {
// Flush all pending notifications so that our frames are uptodate
doc->FlushPendingNotifications(Flush_Layout);
nsPresContext *presContext = presShell->GetPresContext();
if (presContext) {
nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
PRInt32 offsetX = 0;
PRInt32 offsetY = 0;
nsIWidget* widget = nsnull;
while (frame) {
// Look for a widget so we can get screen coordinates
nsIView* view = frame->GetViewExternal();
if (view) {
widget = view->GetWidget();
if (widget)
break;
}
// No widget yet, so count up the coordinates of the frame
nsPoint origin = frame->GetPosition();
offsetX += origin.x;
offsetY += origin.y;
frame = frame->GetParent();
}
if (widget) {
// Get the widget's screen coordinates
nsRect oldBox(0,0,0,0);
widget->WidgetToScreen(oldBox, *rect);
// Get the scale from that Presentation Context
float p2t;
p2t = presContext->PixelsToTwips();
// Convert screen rect to twips
rect->x = NSIntPixelsToTwips(rect->x, p2t);
rect->y = NSIntPixelsToTwips(rect->y, p2t);
// Add the offset we've counted
rect->x += offsetX;
rect->y += offsetY;
}
}
}
}
return *rect;
}
nsIBindingManager*
inLayoutUtils::GetBindingManagerFor(nsIDOMNode* aNode)
{

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

@ -70,8 +70,7 @@ public:
* @return the offset
*/
static nsPoint GetClientOrigin(nsIFrame* aFrame);
static nsRect& GetScreenOrigin(nsIDOMElement* aElement);
};
#endif // __inLayoutUtils_h__

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

@ -3661,11 +3661,6 @@ DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum)
}
if (fndPageFrame && scrollableView) {
// find offset from view
nsPoint pnt;
nsIView * view;
fndPageFrame->GetOffsetFromView(pnt, &view);
nscoord deadSpaceGap = 0;
nsIPageSequenceFrame * sqf;
if (NS_SUCCEEDED(CallQueryInterface(seqFrame, &sqf))) {

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

@ -965,13 +965,6 @@ nsSplitterFrameInner::AdjustChildren(nsPresContext* aPresContext)
if (realTimeDrag) {
nsIView* view = mParentBox->GetView();
if (!view) {
nsPoint offset;
mParentBox->GetOffsetFromView(offset, &view);
NS_ASSERTION(nsnull != view, "no view");
}
aPresContext->PresShell()->FlushPendingNotifications(Flush_Display);
}
else {

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

@ -48,12 +48,10 @@
#include "nsToolkitCompsCID.h"
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIView.h"
#include "nsIPresShell.h"
#include "nsIAtomService.h"
#include "nsReadableUtils.h"
@ -1344,21 +1342,19 @@ nsAutoCompleteController::GetPopupWidget()
nsCOMPtr<nsIDOMDocument> domDoc;
popup->GetOwnerDocument(getter_AddRefs(domDoc));
NS_ENSURE_TRUE(domDoc, nsnull);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
NS_ENSURE_TRUE(doc, nsnull);
nsIPresShell* presShell = doc->GetShellAt(0);
NS_ENSURE_TRUE(presShell, nsnull);
nsCOMPtr<nsIContent> content = do_QueryInterface(popup);
nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
while (frame) {
nsIView* view = frame->GetViewExternal();
if (view && view->HasWidget())
return view->GetWidget();
frame = frame->GetParent();
}
NS_ENSURE_TRUE(frame, nsnull);
NS_ERROR("widget wasn't found!");
return nsnull;
return frame->GetWindow();
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteController)

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

@ -66,10 +66,7 @@
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIView.h"
#include "nsIFrame.h"
#include "nsIWidget.h"
#include "nsRect.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOMHTMLFormElement.h"
@ -139,38 +136,12 @@ GetScreenOrigin(nsIDOMElement* aElement)
if (doc) {
// Get Presentation shell 0
nsIPresShell* presShell = doc->GetShellAt(0);
if (presShell) {
nsPresContext* presContext = presShell->GetPresContext();
if (presContext) {
// Get the scale from that Presentation Context
float scale;
scale = presContext->TwipsToPixels();
nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
if (!frame)
return rect;
nsIView* view;
nsPoint offset;
frame->GetOffsetFromView(offset, &view);
if (view) {
nsPoint widgetOffset(0, 0);
nsIWidget* widget = view->GetNearestWidget(&widgetOffset);
if (widget) {
nsRect oldBox(0,0,0,0);
widget->WidgetToScreen(oldBox, rect);
}
rect.x += NSTwipsToIntPixels(offset.x+widgetOffset.x, scale);
rect.y += NSTwipsToIntPixels(offset.y+widgetOffset.y, scale);
}
size = frame->GetSize();
rect.width = NSTwipsToIntPixels(size.width, scale);
rect.height = NSTwipsToIntPixels(size.height, scale);
}
nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
if (!frame)
return rect;
rect = frame->GetScreenRectExternal();
}
}