Open Bug 651019 Opened 13 years ago Updated 2 years ago

Remove nsIDeviceContext wrappers around nsIScreen

Categories

(Core :: Graphics, enhancement)

enhancement

Tracking

()

People

(Reporter: zwol, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The very few users of the nsIDeviceContext screen size and depth methods should be able to get an nsIScreen object directly and use that instead.
Blocks: 651016
Here is a work-in-progress patch.  Although the nsDeviceContext methods in question are gone, the replacement code for the various places that used them may not be right, and it might be appropriate to add helpers that retrieve an appropriate nsIScreen given various things (especially an nsPresContext).
Attachment #596145 - Flags: feedback?(roc)
Attachment #596145 - Flags: feedback?(bzbarsky)
Comment on attachment 596145 [details] [diff] [review]
preliminary patch

I don't actually know much about this stuff, sorry...
Attachment #596145 - Flags: feedback?(bzbarsky)
(In reply to Boris Zbarsky (:bz) from comment #2)
> I don't actually know much about this stuff, sorry...

Do you know who would?
roc is probably a reasonably choice.  Maybe some of the graphics folks?
Try run for b8ac7217b53a is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=b8ac7217b53a
Results (out of 210 total builds):
    exception: 2
    success: 91
    warnings: 103
    failure: 14
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/zackw@panix.com-b8ac7217b53a
Comment on attachment 596145 [details] [diff] [review]
preliminary patch

Review of attachment 596145 [details] [diff] [review]:
-----------------------------------------------------------------

It would be helpful to break this patch down into a bunch of small patches that remove independent usages of the nsIDeviceContext methods, plus another patch that removes unused code.

::: layout/base/nsLayoutUtils.cpp
@@ +4633,5 @@
> +    vArea.height = aPresContext->AppUnitsToDevPixels(vArea.height);
> +    nsCOMPtr<nsIScreen> screen;
> +    nsCOMPtr<nsIScreenManager> screenmgr = services::GetScreenManager();
> +    screenmgr->ScreenForRect(vArea.x, vArea.y, vArea.width, vArea.height,
> +                             getter_AddRefs(screen));

I don't understand this. There's no reference to the window associated with the prescontext, or the position of the prescontext within its window, so this can't possibly be right? I mean, vArea is relative to the prescontext itself, but ScreenForRect requires screen coordinates, so there's a mismatch.
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #6)

> It would be helpful to break this patch down into a bunch of small patches
> that remove independent usages of the nsIDeviceContext methods, plus another
> patch that removes unused code.

Can do.  That'll also make it easier to debug.

> ::: layout/base/nsLayoutUtils.cpp
> @@ +4633,5 @@
> > +    vArea.height = aPresContext->AppUnitsToDevPixels(vArea.height);
> > +    nsCOMPtr<nsIScreen> screen;
> > +    nsCOMPtr<nsIScreenManager> screenmgr = services::GetScreenManager();
> > +    screenmgr->ScreenForRect(vArea.x, vArea.y, vArea.width, vArea.height,
> > +                             getter_AddRefs(screen));
> 
> I don't understand this. There's no reference to the window associated with
> the prescontext, or the position of the prescontext within its window, so
> this can't possibly be right? I mean, vArea is relative to the prescontext
> itself, but ScreenForRect requires screen coordinates, so there's a mismatch.

In fact, it doesn't work.  I was pretty much stabbing in the dark, here.  Do you have any suggestions for how to go about this properly?  The technique formerly used by the device context is to walk up the docshell tree looking for the nearest widget with a native window, but it seems like there has to be a better way.
I think we should add an API to get an nsIScreen from an nsIWidget, to get the "dominant screen" for the widget (this could just get the widget's client rect and ask for the dominant screen for that rect, but it might make sense to allow the API to be platform-specific). Then you can use nsIFrame::GetNearestWidget with that API.
That sounds doable in principle.  I don't know how to get a frame given a prescontext, but probably there's a frame nearby in all these places.
We could add an API to get the enclosing widget for a Prescontext too. Get the RootPresContext, look for its view manager's root view's widget.
Attachment #596145 - Flags: feedback?(roc)
Resetting owner to default per Zack's request.
Assignee: zackw → nobody
Status: ASSIGNED → NEW
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: