[Webkit-unassigned] [Bug 26278] Patch that make WebCore have a RenderTheme per page

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jun 16 08:42:52 PDT 2009


aroben at apple.com changed:

           What    |Removed                     |Added
                 CC|                            |aroben at apple.com

------- Comment #12 from aroben at apple.com  2009-06-16 08:42 PDT -------
(In reply to comment #10)
> As classes are inheriting from RenderTheme, I cannot make the ctor and dtor
> private in RenderTheme.h, but I can do it in the implementations such as
> RenderThemeQt.h.

In that case, you should make them protected in RenderTheme and private in the
derived classes (like RenderThemeQt).

The point is to avoid errors like this one (in your new code);

 114     static RefPtr<RenderTheme> fallback = new RenderThemeQt();
 115     return fallback; // keep the reference of one.

"fallback" will actually have a reference count of 2 here: it is created with a
reference count of 1, then assigned into a RefPtr which increments the refcount
to 2. Obviously this is OK in this case, since we want to keep this RenderTheme
around forever, but this illustrates the reason why we use the create()
functions and keep the constructors private/protected.

> Another question:
> Is this right? or do I need to do a releaseRef or so here.
> +    static inline PassRefPtr<RenderTheme> defaultTheme()
> +    {
> +        return RenderTheme::themeForPage(0);
> +    };

This is correct as written.

> Also is this change right?
>  PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page)
>  {
>      if (page)
> -        return adoptRef(new RenderThemeQt(page));
> +        return RenderThemeQt::create(page);

This is a good change.

> -    static RefPtr<RenderTheme> fallback = new RenderThemeQt(0);
> -    return fallback; // keep the reference of one.
> +    static RefPtr<RenderTheme> fallback =
> RenderThemeQt::create(0).releaseRef();
> +    return fallback;
>  }

This is not correct.

> Could you explain me why the code causes a destructor to be run when the
> process exits? I would really like to understand how to use the RefPtr's
> correctly.

Static variables and global variables on the stack have their destructors run
when the process exits. This is part of the way the C++ language works. We
avoid having the destructor run by not keeping a RefPtr on the stack. That's
why the code I wrote in comment 9 stores the RenderTheme as a bare pointer.

Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

More information about the webkit-unassigned mailing list