Closed Bug 1065646 Opened 6 years ago Closed 6 years ago

Replace "GetContentRect() - GetPosition()" with GetContentRectRelativeToSelf()

Categories

(Core :: Layout, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: dholbert, Assigned: dholbert)

Details

Attachments

(1 file)

We have several places in layout where we do arithmetic with:
 GetContentRect() - GetPosition()

GetContentRect() gives us nsRect(x,y,width,height); GetPosition() gives us (x,y); so this expression produces nsRect(0,0,width,height).

This is silly, though, because GetContentRect() itself is implemented as follows:
> 1155 nsRect
> 1156 nsIFrame::GetContentRect() const
> 1157 {
> 1158   return GetContentRectRelativeToSelf() + GetPosition();
> 1159 }

So, anyone calling "GetContentRect() - GetPosition()" should really just be calling GetContentRectRelativeToSelf().
(actually, the "0,0" in "0,0,width,height" isn't quite right in my hand-wavy overview at the start of comment 0, because borderpadding impacts things a bit, as shown by the GetContentRectRelativeToSelf() implementation. That's tangential to the main point here, though, which is that GetContentRect() - GetPosition() is silly & wasteful.)
Attached patch fix v1Splinter Review
(As noted in the patch, this makes nsImageFrame's helper-method "GetInnerArea()" a bit silly, albeit a bit conciser than GetContentRectRelativeToSelf(). Similar for nsHTMLCanvasFrame::GetInnerArea, which is documented as having been copied from nsImageFrame at some point in the past.)
Attachment #8487508 - Flags: review?(tnikkel)
Attachment #8487508 - Flags: review?(tnikkel) → review+
https://hg.mozilla.org/mozilla-central/rev/3a582ed49923
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
You need to log in before you can comment on or make changes to this bug.