Bug 500882 part 4. Switch content module to using the new GetPrimaryFrame API. r=smaug, sr=roc

This commit is contained in:
Boris Zbarsky 2009-12-24 16:20:05 -05:00
parent 6733cb0519
commit c58001cbc4
19 changed files with 166 additions and 321 deletions

View File

@ -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);
}

View File

@ -396,8 +396,9 @@ nsINode::GetSelectionRootContent(nsIPresShell* aPresShell)
if (!IsNodeOfType(eCONTENT))
return nsnull;
nsIFrame* frame =
aPresShell->GetPrimaryFrameFor(static_cast<nsIContent*>(this));
NS_ASSERTION(GetCurrentDoc() == aPresShell->GetDocument(),
"Wrong document somewhere");
nsIFrame* frame = static_cast<nsIContent*>(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

View File

@ -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

View File

@ -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);

View File

@ -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<nsTextFrame*>(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<nsIDocument> 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<nsIDOMNode> startContainer = do_QueryInterface(aStartParent);
nsCOMPtr<nsIDOMNode> 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<nsIContent> 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<nsTextFrame*>(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,

View File

@ -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<nsIContent*>(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<nsIContent*>(node));
frame = static_cast<nsIContent*>(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

View File

@ -1444,12 +1444,12 @@ nsEventStateManager::ExecuteAccessKey(nsTArray<PRUint32>& 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 <toolbarbutton> 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 <toolbarbutton> 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<nsIFormControl> formCtrl(do_QueryInterface(mGestureDownContent));
}
else if (mGestureDownContent->IsHTML()) {
nsCOMPtr<nsIFormControl> 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<nsIWidget> 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<nsFrameSelection> 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<nsIWidget> 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<nsFrameSelection> 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<nsIContent> 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.

View File

@ -285,8 +285,7 @@ nsTextStateManager::Init(nsIWidget* aWidget,
// get selection and root content
nsCOMPtr<nsISelectionController> selCon;
if (aNode->IsNodeOfType(nsINode::eCONTENT)) {
nsIFrame* frame = presShell->GetPrimaryFrameFor(
static_cast<nsIContent*>(aNode));
nsIFrame* frame = static_cast<nsIContent*>(aNode)->GetPrimaryFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_UNEXPECTED);
frame->GetSelectionController(aPresContext,

View File

@ -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) {

View File

@ -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().

View File

@ -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

View File

@ -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<nsHTMLMediaElement*>(this),
GetOwnerDoc());
nsIFrame* frame = GetPrimaryFrame();
nsCOMPtr<nsIDOMElement> elem;
if (frame && frame->GetType() == nsGkAtoms::HTMLVideoFrame &&
static_cast<nsVideoFrame*>(frame)->ShouldDisplayPoster()) {

View File

@ -2321,11 +2321,6 @@ nsHTMLDocument::GetBodySize(PRInt32* aWidth,
FlushPendingNotifications(Flush_Layout);
nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
if (!shell)
return NS_OK;
// Find the <body> 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;

View File

@ -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<nsIPluginInstance> pi;
objectFrame->GetPluginInstance(*getter_AddRefs(pi));

View File

@ -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
}
//----------------------------------------------------------------------

View File

@ -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 =

View File

@ -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 =

View File

@ -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<nsIContent*>(this);
nsIFrame* frame = shell->GetPrimaryFrameFor(content);
nsIFrame* frame = GetPrimaryFrame();
nsPresContext *presContext = shell->GetPresContext();

View File

@ -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<nsPresContext> context = shell->GetPresContext();
nsCOMPtr<nsIContent> 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<nsIContent> 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;
}