From c58001cbc4e8a551c5f696e6a7247fa2f47b6ded Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 24 Dec 2009 16:20:05 -0500 Subject: [PATCH] Bug 500882 part 4. Switch content module to using the new GetPrimaryFrame API. r=smaug, sr=roc --- content/base/src/nsFrameLoader.cpp | 8 +- content/base/src/nsGenericElement.cpp | 32 +-- content/base/src/nsGenericElement.h | 23 +- content/base/src/nsObjectLoadingContent.cpp | 14 +- content/base/src/nsRange.cpp | 50 ++--- content/events/src/nsContentEventHandler.cpp | 15 +- content/events/src/nsEventStateManager.cpp | 196 ++++++++---------- content/events/src/nsIMEStateManager.cpp | 3 +- .../html/content/src/nsGenericHTMLElement.cpp | 11 +- .../html/content/src/nsGenericHTMLElement.h | 31 +-- .../html/content/src/nsHTMLCanvasElement.cpp | 14 +- .../html/content/src/nsHTMLMediaElement.cpp | 16 +- content/html/document/src/nsHTMLDocument.cpp | 7 +- .../html/document/src/nsPluginDocument.cpp | 13 +- content/svg/content/src/nsSVGSVGElement.cpp | 30 +-- content/xbl/src/nsXBLResourceLoader.cpp | 2 +- content/xbl/src/nsXBLService.cpp | 2 +- content/xul/content/src/nsXULElement.cpp | 13 +- .../xul/content/src/nsXULPopupListener.cpp | 7 +- 19 files changed, 166 insertions(+), 321 deletions(-) diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index 653d96c8abeb..405123c9282f 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -747,8 +747,8 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther, FirePageHideEvent(ourTreeItem, ourChromeEventHandler); FirePageHideEvent(otherTreeItem, otherChromeEventHandler); - nsIFrame* ourFrame = ourShell->GetPrimaryFrameFor(ourContent); - nsIFrame* otherFrame = otherShell->GetPrimaryFrameFor(otherContent); + nsIFrame* ourFrame = ourContent->GetPrimaryFrame(); + nsIFrame* otherFrame = otherContent->GetPrimaryFrame(); if (!ourFrame || !otherFrame) { mInSwap = aOther->mInSwap = PR_FALSE; FirePageShowEvent(ourTreeItem, ourChromeEventHandler, PR_TRUE); @@ -826,8 +826,8 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther, } // We shouldn't have changed frames, but be really careful about it - if (ourFrame == ourShell->GetPrimaryFrameFor(ourContent) && - otherFrame == otherShell->GetPrimaryFrameFor(otherContent)) { + if (ourFrame == ourContent->GetPrimaryFrame() && + otherFrame == otherContent->GetPrimaryFrame()) { ourFrameFrame->EndSwapDocShells(otherFrame); } diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index d1d03a3b66e8..527f480cf520 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -396,8 +396,9 @@ nsINode::GetSelectionRootContent(nsIPresShell* aPresShell) if (!IsNodeOfType(eCONTENT)) return nsnull; - nsIFrame* frame = - aPresShell->GetPrimaryFrameFor(static_cast(this)); + NS_ASSERTION(GetCurrentDoc() == aPresShell->GetDocument(), + "Wrong document somewhere"); + nsIFrame* frame = static_cast(this)->GetPrimaryFrame(); if (frame && frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION) { // This node should be a descendant of input/textarea editor. nsIContent* content = GetTextEditorRootContent(); @@ -3488,17 +3489,6 @@ nsGenericElement::DispatchClickEvent(nsPresContext* aPresContext, return DispatchEvent(aPresContext, &event, aTarget, aFullDispatch, aStatus); } -nsIFrame* -nsGenericElement::GetPrimaryFrame() -{ - nsIDocument* doc = GetCurrentDoc(); - if (!doc) { - return nsnull; - } - - return GetPrimaryFrameFor(this, doc); -} - nsIFrame* nsGenericElement::GetPrimaryFrame(mozFlushType aType) { @@ -3511,21 +3501,7 @@ nsGenericElement::GetPrimaryFrame(mozFlushType aType) // information doc->FlushPendingNotifications(aType); - return GetPrimaryFrameFor(this, doc); -} - -/* static */ -nsIFrame* -nsGenericElement::GetPrimaryFrameFor(nsIContent* aContent, - nsIDocument* aDocument) -{ - // Get presentation shell 0 - nsIPresShell *presShell = aDocument->GetPrimaryShell(); - if (!presShell) { - return nsnull; - } - - return presShell->GetPrimaryFrameFor(aContent); + return GetPrimaryFrame(); } void diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 3075012761b9..2a090a64d170 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -705,32 +705,15 @@ public: nsEventStatus* aStatus); /** - * Get the primary frame for this content without flushing (see - * GetPrimaryFrameFor) - * - * @return the primary frame - */ - nsIFrame* GetPrimaryFrame(); - - /** - * Get the primary frame for this content with flushing (see - * GetPrimaryFrameFor). + * Get the primary frame for this content with flushing * * @param aType the kind of flush to do, typically Flush_Frames or * Flush_Layout * @return the primary frame */ nsIFrame* GetPrimaryFrame(mozFlushType aType); - - /** - * Get the primary frame for a piece of content without flushing. - * - * @param aContent the content to get the primary frame for - * @param aDocument the document for this content - * @return the primary frame - */ - static nsIFrame* GetPrimaryFrameFor(nsIContent* aContent, - nsIDocument* aDocument); + // Work around silly C++ name hiding stuff + nsIFrame* GetPrimaryFrame() const { return nsIContent::GetPrimaryFrame(); } /** * Struct that stores info on an attribute. The name and value must diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 8ea7663d4a06..6b9f6165606c 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -1665,17 +1665,7 @@ nsObjectLoadingContent::GetExistingFrame(FlushType aFlushType) nsIFrame* frame; do { - nsIDocument* doc = thisContent->GetCurrentDoc(); - if (!doc) { - return nsnull; // No current doc -> no frame - } - - nsIPresShell* shell = doc->GetPrimaryShell(); - if (!shell) { - return nsnull; // No presentation -> no frame - } - - frame = shell->GetPrimaryFrameFor(thisContent); + frame = thisContent->GetPrimaryFrame(); if (!frame) { return nsnull; } @@ -1686,6 +1676,8 @@ nsObjectLoadingContent::GetExistingFrame(FlushType aFlushType) // OK, let's flush out and try again. Note that we want to reget // the document, etc, since flushing might run script. + nsIDocument* doc = thisContent->GetCurrentDoc(); + NS_ASSERTION(doc, "Frame but no document?"); mozFlushType flushType = aFlushType == eFlushLayout ? Flush_Layout : Flush_ContentAndNotify; doc->FlushPendingNotifications(flushType); diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index 1968ffc27062..171f552521a0 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -2061,10 +2061,10 @@ static void ExtractRectFromOffset(nsIFrame* aFrame, } } -static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback, nsIPresShell* aPresShell, +static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback, nsIContent* aContent, PRInt32 aStartOffset, PRInt32 aEndOffset) { - nsIFrame* frame = aPresShell->GetPrimaryFrameFor(aContent); + nsIFrame* frame = aContent->GetPrimaryFrame(); if (frame && frame->GetType() == nsGkAtoms::textFrame) { nsTextFrame* textFrame = static_cast(frame); nsIFrame* relativeTo = nsLayoutUtils::GetContainingBlockForClientRect(textFrame); @@ -2090,30 +2090,24 @@ static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback, nsIPr return NS_OK; } -static nsIPresShell* GetPresShell(nsINode* aNode, PRBool aFlush) -{ - nsCOMPtr document = aNode->GetCurrentDoc(); - if (!document) - return nsnull; - - if (aFlush) { - document->FlushPendingNotifications(Flush_Layout); - } - - return document->GetPrimaryShell(); -} - static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector, nsRange* aRange, nsINode* aStartParent, PRInt32 aStartOffset, nsINode* aEndParent, PRInt32 aEndOffset) { + // Hold strong pointers across the flush nsCOMPtr startContainer = do_QueryInterface(aStartParent); nsCOMPtr endContainer = do_QueryInterface(aEndParent); - nsIPresShell* presShell = GetPresShell(aStartParent, PR_TRUE); - if (!presShell) { - //not in the document + // Flush out layout so our frames are up to date. + if (!aStartParent->IsInDoc()) { + return; + } + + aStartParent->GetCurrentDoc()->FlushPendingNotifications(Flush_Layout); + + // Recheck whether we're still in the document + if (!aStartParent->IsInDoc()) { return; } @@ -2126,7 +2120,7 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector, // the range is collapsed, only continue if the cursor is in a text node nsCOMPtr content = do_QueryInterface(aStartParent); if (content->IsNodeOfType(nsINode::eTEXT)) { - nsIFrame* frame = presShell->GetPrimaryFrameFor(content); + nsIFrame* frame = content->GetPrimaryFrame(); if (frame && frame->GetType() == nsGkAtoms::textFrame) { nsTextFrame* textFrame = static_cast(frame); PRInt32 outOffset; @@ -2154,17 +2148,15 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector, if (node == startContainer) { PRInt32 offset = startContainer == endContainer ? aEndOffset : content->GetText()->GetLength(); - GetPartialTextRect(aCollector, presShell, content, - aStartOffset, offset); + GetPartialTextRect(aCollector, content, aStartOffset, offset); continue; } else if (node == endContainer) { - GetPartialTextRect(aCollector, presShell, content, - 0, aEndOffset); + GetPartialTextRect(aCollector, content, 0, aEndOffset); continue; } } - nsIFrame* frame = presShell->GetPrimaryFrameFor(content); + nsIFrame* frame = content->GetPrimaryFrame(); if (frame) { nsLayoutUtils::GetAllInFlowRects(frame, nsLayoutUtils::GetContainingBlockForClientRect(frame), aCollector); @@ -2182,10 +2174,6 @@ nsRange::GetBoundingClientRect(nsIDOMClientRect** aResult) NS_ADDREF(*aResult = rect); - nsIPresShell* presShell = GetPresShell(mStartParent, PR_FALSE); - if (!presShell) - return NS_OK; - nsLayoutUtils::RectAccumulator accumulator; CollectClientRects(&accumulator, this, mStartParent, mStartOffset, @@ -2206,12 +2194,6 @@ nsRange::GetClientRects(nsIDOMClientRectList** aResult) if (!rectList) return NS_ERROR_OUT_OF_MEMORY; - nsIPresShell* presShell = GetPresShell(mStartParent, PR_FALSE); - if (!presShell) { - rectList.forget(aResult); - return NS_OK; - } - nsLayoutUtils::RectListBuilder builder(rectList); CollectClientRects(&builder, this, mStartParent, mStartOffset, diff --git a/content/events/src/nsContentEventHandler.cpp b/content/events/src/nsContentEventHandler.cpp index 783ee0a02b8f..1841e3379db0 100644 --- a/content/events/src/nsContentEventHandler.cpp +++ b/content/events/src/nsContentEventHandler.cpp @@ -494,8 +494,7 @@ static nsINode* AdjustTextRectNode(nsINode* aNode, // Similar to nsFrameSelection::GetFrameForNodeOffset, // but this is more flexible for OnQueryTextRect to use -static nsresult GetFrameForTextRect(nsIPresShell* aPresShell, - nsINode* aNode, +static nsresult GetFrameForTextRect(nsINode* aNode, PRInt32 aOffset, PRBool aHint, nsIFrame** aReturnFrame) @@ -503,7 +502,7 @@ static nsresult GetFrameForTextRect(nsIPresShell* aPresShell, NS_ENSURE_TRUE(aNode && aNode->IsNodeOfType(nsINode::eCONTENT), NS_ERROR_UNEXPECTED); nsIContent* content = static_cast(aNode); - nsIFrame* frame = aPresShell->GetPrimaryFrameFor(content); + nsIFrame* frame = content->GetPrimaryFrame(); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); PRInt32 childOffset = 0; return frame->GetChildFrameContainingOffset(aOffset, aHint, &childOffset, @@ -539,8 +538,7 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent) node = AdjustTextRectNode(range->GetStartParent(), offset); } nsIFrame* firstFrame = nsnull; - rv = GetFrameForTextRect(mPresShell, node, offset, - PR_TRUE, &firstFrame); + rv = GetFrameForTextRect(node, offset, PR_TRUE, &firstFrame); NS_ENSURE_SUCCESS(rv, rv); // get the starting frame rect @@ -558,8 +556,7 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent) offset = range->EndOffset(); node = AdjustTextRectNode(range->GetEndParent(), offset); nsIFrame* lastFrame = nsnull; - rv = GetFrameForTextRect(mPresShell, node, offset, - range->Collapsed(), &lastFrame); + rv = GetFrameForTextRect(node, offset, range->Collapsed(), &lastFrame); NS_ENSURE_SUCCESS(rv, rv); // iterate over all covered frames @@ -571,7 +568,7 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent) node = iter->GetCurrentNode(); if (!node || !node->IsNodeOfType(nsINode::eCONTENT)) continue; - frame = mPresShell->GetPrimaryFrameFor(static_cast(node)); + frame = static_cast(node)->GetPrimaryFrame(); } while (!frame && !iter->IsDone()); if (!frame) { // this can happen when the end offset of the range is 0. @@ -610,7 +607,7 @@ nsContentEventHandler::OnQueryEditorRect(nsQueryContentEvent* aEvent) if (NS_FAILED(rv)) return rv; - nsIFrame* frame = mPresShell->GetPrimaryFrameFor(mRootContent); + nsIFrame* frame = mRootContent->GetPrimaryFrame(); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); // get rect for first frame diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index f6f22bb28d5c..ebcfb30d727c 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1444,12 +1444,12 @@ nsEventStateManager::ExecuteAccessKey(nsTArray& aAccessCharCodes, AppendUCS4ToUTF16(ch, accessKey); for (count = 1; count <= length; ++count) { content = mAccessKeys[(start + count) % length]; - frame = mPresContext->PresShell()->GetPrimaryFrameFor(content); + frame = content->GetPrimaryFrame(); if (IsAccessKeyTarget(content, frame, accessKey)) { PRBool shouldActivate = sKeyCausesActivation; while (shouldActivate && ++count <= length) { nsIContent *oc = mAccessKeys[(start + count) % length]; - nsIFrame *of = mPresContext->PresShell()->GetPrimaryFrameFor(oc); + nsIFrame *of = oc->GetPrimaryFrame(); if (IsAccessKeyTarget(oc, of, accessKey)) shouldActivate = PR_FALSE; } @@ -1683,93 +1683,88 @@ nsEventStateManager::FireContextClick() // the same. (Note: saari and I have decided that we don't have to reset |mCurrentTarget| // when we're through because no one else is doing anything more with this // event and it will get reset on the very next event to the correct frame). - mCurrentTarget = nsnull; - nsIPresShell *shell = mPresContext->GetPresShell(); - if ( shell ) { - mCurrentTarget = shell->GetPrimaryFrameFor(mGestureDownFrameOwner); + mCurrentTarget = mPresContext->GetPrimaryFrameFor(mGestureDownContent); + if (mCurrentTarget) { + NS_ASSERTION(mPresContext == mCurrentTarget->PresContext(), + "a prescontext returned a primary frame that didn't belong to it?"); - if ( mCurrentTarget ) { - NS_ASSERTION(mPresContext == mCurrentTarget->PresContext(), - "a prescontext returned a primary frame that didn't belong to it?"); + // before dispatching, check that we're not on something that + // doesn't get a context menu + nsIAtom *tag = mGestureDownContent->Tag(); + PRBool allowedToDispatch = PR_TRUE; - // before dispatching, check that we're not on something that - // doesn't get a context menu - nsIAtom *tag = mGestureDownContent->Tag(); - PRBool allowedToDispatch = PR_TRUE; - - if (mGestureDownContent->IsXUL()) { - if (tag == nsGkAtoms::scrollbar || - tag == nsGkAtoms::scrollbarbutton || - tag == nsGkAtoms::button) + if (mGestureDownContent->IsXUL()) { + if (tag == nsGkAtoms::scrollbar || + tag == nsGkAtoms::scrollbarbutton || + tag == nsGkAtoms::button) + allowedToDispatch = PR_FALSE; + else if (tag == nsGkAtoms::toolbarbutton) { + // a that has the container attribute set + // will already have its own dropdown. + if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent, + kNameSpaceID_None, nsGkAtoms::container)) { allowedToDispatch = PR_FALSE; - else if (tag == nsGkAtoms::toolbarbutton) { - // a that has the container attribute set - // will already have its own dropdown. - if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent, - kNameSpaceID_None, nsGkAtoms::container)) { - allowedToDispatch = PR_FALSE; - } else { - // If the toolbar button has an open menu, don't attempt to open + } else { + // If the toolbar button has an open menu, don't attempt to open // a second menu - if (mGestureDownContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open, - nsGkAtoms::_true, eCaseMatters)) { - allowedToDispatch = PR_FALSE; - } + if (mGestureDownContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open, + nsGkAtoms::_true, eCaseMatters)) { + allowedToDispatch = PR_FALSE; } } } - else if (mGestureDownContent->IsHTML()) { - nsCOMPtr formCtrl(do_QueryInterface(mGestureDownContent)); + } + else if (mGestureDownContent->IsHTML()) { + nsCOMPtr formCtrl(do_QueryInterface(mGestureDownContent)); - if (formCtrl) { - // of all form controls, only ones dealing with text are - // allowed to have context menus - PRInt32 type = formCtrl->GetType(); + if (formCtrl) { + // of all form controls, only ones dealing with text are + // allowed to have context menus + PRInt32 type = formCtrl->GetType(); - allowedToDispatch = (type == NS_FORM_INPUT_TEXT || - type == NS_FORM_INPUT_PASSWORD || - type == NS_FORM_INPUT_FILE || - type == NS_FORM_TEXTAREA); - } - else if (tag == nsGkAtoms::applet || - tag == nsGkAtoms::embed || - tag == nsGkAtoms::object) { - allowedToDispatch = PR_FALSE; + allowedToDispatch = (type == NS_FORM_INPUT_TEXT || + type == NS_FORM_INPUT_PASSWORD || + type == NS_FORM_INPUT_FILE || + type == NS_FORM_TEXTAREA); + } + else if (tag == nsGkAtoms::applet || + tag == nsGkAtoms::embed || + tag == nsGkAtoms::object) { + allowedToDispatch = PR_FALSE; + } + } + + if (allowedToDispatch) { + // make sure the widget sticks around + nsCOMPtr targetWidget(mCurrentTarget->GetWindow()); + // init the event while mCurrentTarget is still good + nsMouseEvent event(PR_TRUE, NS_CONTEXTMENU, + targetWidget, + nsMouseEvent::eReal); + event.clickCount = 1; + FillInEventFromGestureDown(&event); + + // stop selection tracking, we're in control now + if (mCurrentTarget) + { + nsCOMPtr frameSel = + mCurrentTarget->GetFrameSelection(); + + if (frameSel && frameSel->GetMouseDownState()) { + // note that this can cause selection changed events to fire if we're in + // a text field, which will null out mCurrentTarget + frameSel->SetMouseDownState(PR_FALSE); } } - if (allowedToDispatch) { - // make sure the widget sticks around - nsCOMPtr targetWidget(mCurrentTarget->GetWindow()); - // init the event while mCurrentTarget is still good - nsMouseEvent event(PR_TRUE, NS_CONTEXTMENU, - targetWidget, - nsMouseEvent::eReal); - event.clickCount = 1; - FillInEventFromGestureDown(&event); - - // stop selection tracking, we're in control now - if (mCurrentTarget) - { - nsCOMPtr frameSel = - mCurrentTarget->GetFrameSelection(); - - if (frameSel && frameSel->GetMouseDownState()) { - // note that this can cause selection changed events to fire if we're in - // a text field, which will null out mCurrentTarget - frameSel->SetMouseDownState(PR_FALSE); - } - } + // dispatch to DOM + nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event, + nsnull, &status); - // dispatch to DOM - nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event, - nsnull, &status); - - // We don't need to dispatch to frame handling because no frames - // watch NS_CONTEXTMENU except for nsMenuFrame and that's only for - // dismissal. That's just as well since we don't really know - // which frame to send it to. - } + // We don't need to dispatch to frame handling because no frames + // watch NS_CONTEXTMENU except for nsMenuFrame and that's only for + // dismissal. That's just as well since we don't really know + // which frame to send it to. } } @@ -1874,7 +1869,7 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext, { NS_ASSERTION(aPresContext, "This shouldn't happen."); if ( IsTrackingDragGesture() ) { - mCurrentTarget = aPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownFrameOwner); + mCurrentTarget = mGestureDownFrameOwner->GetPrimaryFrame(); if (!mCurrentTarget) { StopTrackingDragGesture(); @@ -2216,16 +2211,9 @@ nsEventStateManager::DoDefaultDragStart(nsPresContext* aPresContext, nsCOMPtr content = do_QueryInterface(dragTarget); if (content->NodeInfo()->Equals(nsGkAtoms::treechildren, kNameSpaceID_XUL)) { - nsIDocument* doc = content->GetCurrentDoc(); - if (doc) { - nsIPresShell* presShell = doc->GetPrimaryShell(); - if (presShell) { - nsIFrame* frame = presShell->GetPrimaryFrameFor(content); - if (frame) { - nsTreeBodyFrame* treeBody = do_QueryFrame(frame); - treeBody->GetSelectionRegion(getter_AddRefs(region)); - } - } + nsTreeBodyFrame* treeBody = do_QueryFrame(content->GetPrimaryFrame()); + if (treeBody) { + treeBody->GetSelectionRegion(getter_AddRefs(region)); } } } @@ -2788,7 +2776,7 @@ nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent, because they are not used by DoScrollText(). */ - nsIFrame* frameFrame = pPresShell->GetPrimaryFrameFor(frameContent); + nsIFrame* frameFrame = frameContent->GetPrimaryFrame(); if (!frameFrame) return NS_ERROR_FAILURE; NS_IF_ADDREF(presCtxOuter = pPresShell->GetPresContext()); @@ -3577,14 +3565,11 @@ public: virtual void HandleEvent(nsEventChainPostVisitor& aVisitor) { if (aVisitor.mPresContext) { - nsIPresShell* shell = aVisitor.mPresContext->GetPresShell(); - if (shell) { - nsIFrame* frame = shell->GetPrimaryFrameFor(mTarget); - if (frame) { - frame->HandleEvent(aVisitor.mPresContext, - (nsGUIEvent*) aVisitor.mEvent, - &aVisitor.mEventStatus); - } + nsIFrame* frame = aVisitor.mPresContext->GetPrimaryFrameFor(mTarget); + if (frame) { + frame->HandleEvent(aVisitor.mPresContext, + (nsGUIEvent*) aVisitor.mEvent, + &aVisitor.mEventStatus); } } } @@ -3616,12 +3601,11 @@ nsEventStateManager::DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage, nsEventDispatcher::Dispatch(aTargetContent, mPresContext, &event, nsnull, &status, &callback); - nsIPresShell *shell = mPresContext ? mPresContext->GetPresShell() : nsnull; - if (shell) { - // Although the primary frame was checked in event callback, - // it may not be the same object after event dispatching and handling. - // So we need to refetch it. - targetFrame = shell->GetPrimaryFrameFor(aTargetContent); + // Although the primary frame was checked in event callback, + // it may not be the same object after event dispatching and handling. + // So we need to refetch it. + if (mPresContext) { + targetFrame = mPresContext->GetPrimaryFrameFor(aTargetContent); } } @@ -4059,7 +4043,7 @@ nsEventStateManager::GetEventTarget(nsIFrame **aFrame) } if (mCurrentTargetContent) { - mCurrentTarget = shell->GetPrimaryFrameFor(mCurrentTargetContent); + mCurrentTarget = mPresContext->GetPrimaryFrameFor(mCurrentTargetContent); if (mCurrentTarget) { *aFrame = mCurrentTarget; return NS_OK; @@ -4232,8 +4216,10 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) if (!mPresContext || mPresContext->IsDynamic()) { newHover = aContent; } else { - nsIFrame *frame = aContent ? - mPresContext->PresShell()->GetPrimaryFrameFor(aContent) : nsnull; + NS_ASSERTION(!aContent || + aContent->GetCurrentDoc() == mPresContext->PresShell()->GetDocument(), + "Unexpected document"); + nsIFrame *frame = aContent ? aContent->GetPrimaryFrame() : nsnull; if (frame && nsLayoutUtils::IsViewportScrollbarFrame(frame)) { // The scrollbars of viewport should not ignore the hover state. // Because they are *not* the content of the web page. diff --git a/content/events/src/nsIMEStateManager.cpp b/content/events/src/nsIMEStateManager.cpp index a740ac5feb37..39a4f36db1b7 100644 --- a/content/events/src/nsIMEStateManager.cpp +++ b/content/events/src/nsIMEStateManager.cpp @@ -285,8 +285,7 @@ nsTextStateManager::Init(nsIWidget* aWidget, // get selection and root content nsCOMPtr selCon; if (aNode->IsNodeOfType(nsINode::eCONTENT)) { - nsIFrame* frame = presShell->GetPrimaryFrameFor( - static_cast(aNode)); + nsIFrame* frame = static_cast(aNode)->GetPrimaryFrame(); NS_ENSURE_TRUE(frame, NS_ERROR_UNEXPECTED); frame->GetSelectionController(aPresContext, diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 1408a0870d6b..a66e8cc48f4d 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1245,17 +1245,14 @@ nsGenericHTMLElement::GetAttributeMappingFunction() const return &MapCommonAttributesInto; } -// static nsIFormControlFrame* -nsGenericHTMLElement::GetFormControlFrameFor(nsIContent* aContent, - nsIDocument* aDocument, - PRBool aFlushContent) +nsGenericHTMLElement::GetFormControlFrame(PRBool aFlushFrames) { - if (aFlushContent) { + if (aFlushFrames && IsInDoc()) { // Cause a flush of the frames, so we get up-to-date frame information - aDocument->FlushPendingNotifications(Flush_Frames); + GetCurrentDoc()->FlushPendingNotifications(Flush_Frames); } - nsIFrame* frame = GetPrimaryFrameFor(aContent, aDocument); + nsIFrame* frame = GetPrimaryFrame(); if (frame) { nsIFormControlFrame* form_frame = do_QueryFrame(frame); if (form_frame) { diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 588367e03e1f..d89eb3fd7c94 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -232,21 +232,13 @@ public: void GetBaseTarget(nsAString& aBaseTarget) const; /** - * Get the primary form control frame for this content (see - * GetFormControlFrameFor) + * Get the primary form control frame for this element. Same as + * GetPrimaryFrame(), except it QI's to nsIFormControlFrame. * - * @param aFlushContent whether to flush the content sink - * @return the primary form control frame (or null) + * @param aFlush whether to flush out frames so that they're up to date. + * @return the primary frame as nsIFormControlFrame */ - nsIFormControlFrame* GetFormControlFrame(PRBool aFlushContent) - { - nsIDocument* doc = GetCurrentDoc(); - if (!doc) { - return nsnull; - } - - return GetFormControlFrameFor(this, doc, aFlushContent); - } + nsIFormControlFrame* GetFormControlFrame(PRBool aFlushFrames); //---------------------------------------- @@ -444,19 +436,6 @@ public: */ static void MapScrollingAttributeInto(const nsMappedAttributes* aAttributes, nsRuleData* aData); - /** - * Get the primary form control frame for a piece of content. Same as - * GetPrimaryFrameFor, except it QI's to nsIFormControlFrame. - * - * @param aContent the content to get the primary frame for - * @param aDocument the document for this content - * @param aFlushContent whether to flush the content sink, which creates - * frames for content that do not already have it. EXPENSIVE. - * @return the primary frame as nsIFormControlFrame - */ - static nsIFormControlFrame* GetFormControlFrameFor(nsIContent* aContent, - nsIDocument* aDocument, - PRBool aFlushContent); /** * Get the presentation state for a piece of content, or create it if it does * not exist. Generally used by SaveState(). diff --git a/content/html/content/src/nsHTMLCanvasElement.cpp b/content/html/content/src/nsHTMLCanvasElement.cpp index d9a6e8e564cb..cdc5e4e4eb1d 100644 --- a/content/html/content/src/nsHTMLCanvasElement.cpp +++ b/content/html/content/src/nsHTMLCanvasElement.cpp @@ -521,14 +521,9 @@ nsHTMLCanvasElement::SetWriteOnly() NS_IMETHODIMP nsHTMLCanvasElement::InvalidateFrame() { - nsIDocument* doc = GetCurrentDoc(); - if (!doc) { - return NS_OK; - } - // We don't need to flush anything here; if there's no frame or if // we plan to reframe we don't need to invalidate it anyway. - nsIFrame *frame = GetPrimaryFrameFor(this, doc); + nsIFrame *frame = GetPrimaryFrame(); if (frame) { nsRect r = frame->GetRect(); r.x = r.y = 0; @@ -541,14 +536,9 @@ nsHTMLCanvasElement::InvalidateFrame() NS_IMETHODIMP nsHTMLCanvasElement::InvalidateFrameSubrect(const gfxRect& damageRect) { - nsIDocument* doc = GetCurrentDoc(); - if (!doc) { - return NS_OK; - } - // We don't need to flush anything here; if there's no frame or if // we plan to reframe we don't need to invalidate it anyway. - nsIFrame *frame = GetPrimaryFrameFor(this, doc); + nsIFrame *frame = GetPrimaryFrame(); if (frame) { // Frame might be dirty, but we don't care about that; if the geometry // changes the right invalidates will happen anyway. Don't assert on our diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 83566be0d1f0..d37cfb608a8a 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -952,15 +952,11 @@ void nsHTMLMediaElement::SetPlayedOrSeeked(PRBool aValue) mHasPlayedOrSeeked = aValue; // Force a reflow so that the poster frame hides or shows immediately. - nsIDocument *doc = GetDocument(); - if (!doc) return; - nsIPresShell *presShell = doc->GetPrimaryShell(); - if (!presShell) return; - nsIFrame* frame = presShell->GetPrimaryFrameFor(this); + nsIFrame* frame = GetPrimaryFrame(); if (!frame) return; - presShell->FrameNeedsReflow(frame, - nsIPresShell::eTreeChange, - NS_FRAME_IS_DIRTY); + frame->PresContext()->PresShell()->FrameNeedsReflow(frame, + nsIPresShell::eTreeChange, + NS_FRAME_IS_DIRTY); } NS_IMETHODIMP nsHTMLMediaElement::Play() @@ -2027,9 +2023,7 @@ nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest) const dest->mPrintSurface = mPrintSurface; dest->mMediaSize = mMediaSize; } else { - nsIFrame* frame = - GetPrimaryFrameFor(const_cast(this), - GetOwnerDoc()); + nsIFrame* frame = GetPrimaryFrame(); nsCOMPtr elem; if (frame && frame->GetType() == nsGkAtoms::HTMLVideoFrame && static_cast(frame)->ShouldDisplayPoster()) { diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 0e0b0a7b609c..509ce5c1e3bd 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2321,11 +2321,6 @@ nsHTMLDocument::GetBodySize(PRInt32* aWidth, FlushPendingNotifications(Flush_Layout); - nsCOMPtr shell = GetPrimaryShell(); - - if (!shell) - return NS_OK; - // Find the element: this is what we'll want to use for the // document's width and height values. nsIContent* body = GetBodyContent(); @@ -2334,7 +2329,7 @@ nsHTMLDocument::GetBodySize(PRInt32* aWidth, } // Now grab its frame - nsIFrame* frame = shell->GetPrimaryFrameFor(body); + nsIFrame* frame = body->GetPrimaryFrame(); if (!frame) return NS_OK; diff --git a/content/html/document/src/nsPluginDocument.cpp b/content/html/document/src/nsPluginDocument.cpp index 59331ca1d2ab..cecb168d95d0 100644 --- a/content/html/document/src/nsPluginDocument.cpp +++ b/content/html/document/src/nsPluginDocument.cpp @@ -138,7 +138,7 @@ nsPluginStreamListener::SetupPlugin() // nsObjectFrame does that at the end of reflow. shell->FlushPendingNotifications(Flush_Layout); - nsIFrame* frame = shell->GetPrimaryFrameFor(embed); + nsIFrame* frame = embed->GetPrimaryFrame(); if (!frame) { mPluginDoc->AllowNormalInstantiation(); return NS_OK; @@ -341,15 +341,8 @@ nsPluginDocument::Print() { NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE); - nsIPresShell *shell = GetPrimaryShell(); - if (!shell) { - return NS_OK; - } - - nsIFrame* frame = shell->GetPrimaryFrameFor(mPluginContent); - NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); - - nsIObjectFrame* objectFrame = do_QueryFrame(frame); + nsIObjectFrame* objectFrame = + do_QueryFrame(mPluginContent->GetPrimaryFrame()); if (objectFrame) { nsCOMPtr pi; objectFrame->GetPluginInstance(*getter_AddRefs(pi)); diff --git a/content/svg/content/src/nsSVGSVGElement.cpp b/content/svg/content/src/nsSVGSVGElement.cpp index 975c30fda12e..c7fe8c6ce331 100644 --- a/content/svg/content/src/nsSVGSVGElement.cpp +++ b/content/svg/content/src/nsSVGSVGElement.cpp @@ -1091,26 +1091,18 @@ nsSVGSVGElement::WillBeOutermostSVG(nsIContent* aParent, void nsSVGSVGElement::InvalidateTransformNotifyFrame() { - nsIDocument* doc = GetCurrentDoc(); - if (!doc) return; - nsIPresShell* presShell = doc->GetPrimaryShell(); - if (!presShell) return; - - nsIFrame* frame = presShell->GetPrimaryFrameFor(this); - if (frame) { - nsISVGSVGFrame* svgframe = do_QueryFrame(frame); - if (svgframe) { - svgframe->NotifyViewportChange(); - } -#ifdef DEBUG - else { - // XXX we get here during nsSVGOuterSVGFrame::Init() since that - // function is called before the presshell association between us - // and our frame is established. - NS_WARNING("wrong frame type"); - } -#endif + nsISVGSVGFrame* svgframe = do_QueryFrame(GetPrimaryFrame()); + if (svgframe) { + svgframe->NotifyViewportChange(); } +#ifdef DEBUG + else { + // XXX we get here during nsSVGOuterSVGFrame::Init() since that + // function is called before the presshell association between us + // and our frame is established. + NS_WARNING("wrong frame type"); + } +#endif } //---------------------------------------------------------------------- diff --git a/content/xbl/src/nsXBLResourceLoader.cpp b/content/xbl/src/nsXBLResourceLoader.cpp index dca235db25d0..95edb3391ff9 100644 --- a/content/xbl/src/nsXBLResourceLoader.cpp +++ b/content/xbl/src/nsXBLResourceLoader.cpp @@ -265,7 +265,7 @@ nsXBLResourceLoader::NotifyBoundElements() // will happen. nsIPresShell *shell = doc->GetPrimaryShell(); if (shell) { - nsIFrame* childFrame = shell->GetPrimaryFrameFor(content); + nsIFrame* childFrame = content->GetPrimaryFrame(); if (!childFrame) { // Check to see if it's in the undisplayed content map. nsStyleContext* sc = diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index fb2b8a06db0d..c1e39926d8ec 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -215,7 +215,7 @@ public: // will happen. nsIPresShell *shell = doc->GetPrimaryShell(); if (shell) { - nsIFrame* childFrame = shell->GetPrimaryFrameFor(mBoundElement); + nsIFrame* childFrame = mBoundElement->GetPrimaryFrame(); if (!childFrame) { // Check to see if it's in the undisplayed content map. nsStyleContext* sc = diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 01bd0573a033..158cfc376ae6 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -632,15 +632,7 @@ nsXULElement::PerformAccesskey(PRBool aKeyCausesActivation, return; } - nsIDocument* doc = GetCurrentDoc(); - if (!doc) - return; - - nsIPresShell *shell = doc->GetPrimaryShell(); - if (!shell) - return; - - nsIFrame* frame = shell->GetPrimaryFrameFor(content); + nsIFrame* frame = content->GetPrimaryFrame(); if (!frame) return; @@ -2385,8 +2377,7 @@ nsXULElement::HideWindowChrome(PRBool aShouldHide) nsIPresShell *shell = doc->GetPrimaryShell(); if (shell) { - nsIContent* content = static_cast(this); - nsIFrame* frame = shell->GetPrimaryFrameFor(content); + nsIFrame* frame = GetPrimaryFrame(); nsPresContext *presContext = shell->GetPresContext(); diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index cd9a9ece3c2c..af02ba85dad5 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -274,10 +274,11 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode) return NS_ERROR_FAILURE; // strong reference to keep this from going away between events + // XXXbz between what events? We don't use this local at all! nsCOMPtr context = shell->GetPresContext(); nsCOMPtr content = do_QueryInterface(aTargetNode); - nsIFrame* targetFrame = shell->GetPrimaryFrameFor(content); + nsIFrame* targetFrame = content->GetPrimaryFrame(); if (!targetFrame) return NS_ERROR_FAILURE; const nsStyleUserInterface* ui = targetFrame->GetStyleUserInterface(); @@ -451,9 +452,7 @@ nsXULPopupListener::LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent) nsCOMPtr popup = do_QueryInterface(popupElement); nsIContent* parent = popup->GetParent(); if (parent) { - nsIDocument* doc = parent->GetCurrentDoc(); - nsIPresShell* presShell = doc ? doc->GetPrimaryShell() : nsnull; - nsIFrame* frame = presShell ? presShell->GetPrimaryFrameFor(parent) : nsnull; + nsIFrame* frame = parent->GetPrimaryFrame(); if (frame && frame->GetType() == nsGkAtoms::menuFrame) return NS_OK; }