From 6febafd1058d710bdd01059f95a64ea7ba1e989c Mon Sep 17 00:00:00 2001 From: "sharparrow1%yahoo.com" Date: Tue, 18 Apr 2006 06:05:24 +0000 Subject: [PATCH] Bug 334416: Misc view usage cleanups. r+sr=roc. git-svn-id: svn://10.0.0.236/trunk@194582 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/accessible/src/base/nsAccessible.cpp | 34 +--------- mozilla/accessible/src/base/nsAccessible.h | 1 - .../src/html/nsHTMLAreaAccessible.cpp | 8 +-- mozilla/editor/libeditor/base/nsEditor.cpp | 18 ----- .../libeditor/text/nsEditorEventListeners.cpp | 33 ---------- .../inspector/base/src/inLayoutUtils.cpp | 66 ------------------- .../inspector/base/src/inLayoutUtils.h | 3 +- mozilla/layout/base/nsDocumentViewer.cpp | 5 -- .../layout/xul/base/src/nsSplitterFrame.cpp | 7 -- .../src/nsAutoCompleteController.cpp | 18 ++--- .../satchel/src/nsFormFillController.cpp | 39 ++--------- 11 files changed, 18 insertions(+), 214 deletions(-) diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index edd4e32b9ae..482dfbcbb53 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -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; diff --git a/mozilla/accessible/src/base/nsAccessible.h b/mozilla/accessible/src/base/nsAccessible.h index 6e8d4f76289..93cbf6baed2 100644 --- a/mozilla/accessible/src/base/nsAccessible.h +++ b/mozilla/accessible/src/base/nsAccessible.h @@ -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); diff --git a/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp b/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp index a9de6866b1c..e1823c91aa8 100644 --- a/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp +++ b/mozilla/accessible/src/html/nsHTMLAreaAccessible.cpp @@ -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; diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index bed70003df0..d98c943c8d2 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -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; diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index 38705f1d79d..7a1481cc654 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -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 } } } diff --git a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp index 11414d5bd73..7191b05e0e4 100644 --- a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp @@ -147,72 +147,6 @@ inLayoutUtils::GetClientOrigin(nsIFrame* aFrame) return result; } -nsRect& -inLayoutUtils::GetScreenOrigin(nsIDOMElement* aElement) -{ - nsRect* rect = new nsRect(0,0,0,0); - - nsCOMPtr content = do_QueryInterface(aElement); - nsCOMPtr 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) { diff --git a/mozilla/extensions/inspector/base/src/inLayoutUtils.h b/mozilla/extensions/inspector/base/src/inLayoutUtils.h index b5b202b4d58..891fd5d58bf 100644 --- a/mozilla/extensions/inspector/base/src/inLayoutUtils.h +++ b/mozilla/extensions/inspector/base/src/inLayoutUtils.h @@ -70,8 +70,7 @@ public: * @return the offset */ static nsPoint GetClientOrigin(nsIFrame* aFrame); - static nsRect& GetScreenOrigin(nsIDOMElement* aElement); - + }; #endif // __inLayoutUtils_h__ diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 81f09f340cc..35037a771d4 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -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))) { diff --git a/mozilla/layout/xul/base/src/nsSplitterFrame.cpp b/mozilla/layout/xul/base/src/nsSplitterFrame.cpp index 1a594f31c17..d6892831a84 100644 --- a/mozilla/layout/xul/base/src/nsSplitterFrame.cpp +++ b/mozilla/layout/xul/base/src/nsSplitterFrame.cpp @@ -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 { diff --git a/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp b/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp index d2e3f8fc747..273ee8e2119 100644 --- a/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp +++ b/mozilla/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp @@ -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 domDoc; popup->GetOwnerDocument(getter_AddRefs(domDoc)); + NS_ENSURE_TRUE(domDoc, nsnull); nsCOMPtr doc = do_QueryInterface(domDoc); + NS_ENSURE_TRUE(doc, nsnull); + nsIPresShell* presShell = doc->GetShellAt(0); + NS_ENSURE_TRUE(presShell, nsnull); + nsCOMPtr 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) diff --git a/mozilla/toolkit/components/satchel/src/nsFormFillController.cpp b/mozilla/toolkit/components/satchel/src/nsFormFillController.cpp index 30de53a9cda..a7228e62771 100644 --- a/mozilla/toolkit/components/satchel/src/nsFormFillController.cpp +++ b/mozilla/toolkit/components/satchel/src/nsFormFillController.cpp @@ -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(); } }