Last Comment Bug 654989 - Add a method to specify the style context of a frame to nsIAnonymousContentCreator so we don't have to use CreateFrameFor
: Add a method to specify the style context of a frame to nsIAnonymousContentCr...
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Layout (show other bugs)
: Trunk
: All All
: P1 normal (vote)
: mozilla6
Assigned To: Boris Zbarsky [:bz]
:
Mentors:
Depends on:
Blocks: 654990
  Show dependency treegraph
 
Reported: 2011-05-05 06:24 PDT by Mounir Lamouri (:mounir)
Modified: 2011-05-06 21:25 PDT (History)
3 users (show)
bzbarsky: in‑testsuite-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
part 1. Allow handing out both an nsIContent and an nsStyleContext from CreateAnonymousContent. (26.65 KB, patch)
2011-05-05 13:13 PDT, Boris Zbarsky [:bz]
roc: review+
Details | Diff | Review
part 2. Use the nsStyleContext handed back from CreateAnonymousContent. asserts the parts of AddFrameConstructionItems that should never matter for anonymous content and then just copies the one-line style context get if it's needed. (3.37 KB, patch)
2011-05-05 13:25 PDT, Boris Zbarsky [:bz]
roc: review+
Details | Diff | Review

Description Mounir Lamouri (:mounir) 2011-05-05 06:24:25 PDT
See bug 633209 comment 13.
Comment 1 Boris Zbarsky [:bz] 2011-05-05 13:13:35 PDT
Created attachment 530407 [details] [diff] [review]
part 1.  Allow handing out both an nsIContent and an nsStyleContext from CreateAnonymousContent.
Comment 2 Boris Zbarsky [:bz] 2011-05-05 13:25:33 PDT
Created attachment 530409 [details] [diff] [review]
part 2.  Use the nsStyleContext handed back from CreateAnonymousContent.   asserts the parts of AddFrameConstructionItems that should never matter for anonymous content and then just copies the one-line style context get if it's needed.
Comment 3 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2011-05-05 15:13:22 PDT
Comment on attachment 530407 [details] [diff] [review]
part 1.  Allow handing out both an nsIContent and an nsStyleContext from CreateAnonymousContent.

Review of attachment 530407 [details] [diff] [review]:

r+ with that.

::: layout/generic/nsIAnonymousContentCreator.h
@@ +102,5 @@
    */
   virtual nsIFrame* CreateFrameFor(nsIContent* aContent) { return nsnull; }
 };
 
+typedef nsTArray<nsIAnonymousContentCreator::ContentInfo> nsAnonymousContentArray;

Personally I wouldn't bother with this typedef, I think it just obscures things. Instead I would have "typedef nsIAnonymousContentCreator::ContentInfo ContentInfo;" so that you can write nsTArray<ContentInfo> everywhere you currently have nsAnonymousContentArray (which is actually longer!).
Comment 4 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2011-05-05 15:18:45 PDT
Comment on attachment 530409 [details] [diff] [review]
part 2.  Use the nsStyleContext handed back from CreateAnonymousContent.   asserts the parts of AddFrameConstructionItems that should never matter for anonymous content and then just copies the one-line style context get if it's needed.

Review of attachment 530409 [details] [diff] [review]:

::: layout/base/nsCSSFrameConstructor.cpp
@@ +9548,5 @@
 #endif
+    // Assert some things about this content
+    NS_ABORT_IF_FALSE(!(content->GetFlags() &
+                        (NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME)),
+                      "Should not be marked as needing frames");

This is not likely to cause instability so should just be an NS_ASSERTION IMHO.

@@ +9551,5 @@
+                        (NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME)),
+                      "Should not be marked as needing frames");
+    NS_ABORT_IF_FALSE(!content->IsElement() ||
+                      !(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS),
+                      "Should have no pending restyle flags");

Ditto.

@@ +9553,5 @@
+    NS_ABORT_IF_FALSE(!content->IsElement() ||
+                      !(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS),
+                      "Should have no pending restyle flags");
+    NS_ABORT_IF_FALSE(!content->GetPrimaryFrame(),
+                      "Should have no existing frame");

This could cause strange crashes so should stay an NS_ABORT_IF_FALSE.

@@ +9556,5 @@
+    NS_ABORT_IF_FALSE(!content->GetPrimaryFrame(),
+                      "Should have no existing frame");
+    NS_ABORT_IF_FALSE(!content->IsNodeOfType(nsINode::eCOMMENT) &&
+                      !content->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION),
+                      "Why is someone creating garbage anonymous content");

I think AddFrameConstructionItemsInternal will just not create frames for these without breaking stuff, so again this can just be an NS_ASSERTION.

@@ +9560,5 @@
+                      "Why is someone creating garbage anonymous content");
+
+    nsRefPtr<nsStyleContext> styleContext;
+    if (anonymousItems[i].mStyleContext) {
+      anonymousItems[i].mStyleContext.swap(styleContext);

Clearer to write
  styleContext = anonymousItems[i].mStyleContext.forget();
Comment 5 Boris Zbarsky [:bz] 2011-05-05 15:43:50 PDT
> Instead I would have "typedef nsIAnonymousContentCreator::ContentInfo
> ContentInfo;

Should I just move ContentInfo outside nsIAnonymousContentCreator?
Comment 6 Boris Zbarsky [:bz] 2011-05-05 18:03:07 PDT
> This is not likely to cause instability 

It is, actually; if those flags are set and don't get unset then we'll end up trying to double-construct frames, no?  I guess if we go through AddFrameConstructionItems for that we'll just NS_ERROR and bail out... but that's a thin thread to hang on.

> I think AddFrameConstructionItemsInternal will just not create frames for
> these without breaking stuff

It'll create nsTextFrames for them.  Not sure what you mean by "Breaking stuff", but that doesn't sound like a happy situation.

> styleContext = anonymousItems[i].mStyleContext.forget();

Will do.
Comment 7 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2011-05-05 18:06:55 PDT
(In reply to comment #6)
> > This is not likely to cause instability 
> 
> It is, actually; if those flags are set and don't get unset then we'll end up
> trying to double-construct frames, no?  I guess if we go through
> AddFrameConstructionItems for that we'll just NS_ERROR and bail out... but
> that's a thin thread to hang on.
> 
> > I think AddFrameConstructionItemsInternal will just not create frames for
> > these without breaking stuff
> 
> It'll create nsTextFrames for them.  Not sure what you mean by "Breaking
> stuff", but that doesn't sound like a happy situation.

OK, never mind!
Comment 8 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2011-05-05 18:40:59 PDT
(In reply to comment #5)
> > Instead I would have "typedef nsIAnonymousContentCreator::ContentInfo
> > ContentInfo;
> 
> Should I just move ContentInfo outside nsIAnonymousContentCreator?

Actually, just remove this typedef. It looks like most places that use it inherit from nsIAnonymousContentCreator anyway.
Comment 9 Boris Zbarsky [:bz] 2011-05-05 19:03:32 PDT
Indeed.  OK, will do.

Note You need to log in before you can comment on or make changes to this bug.