Bug 1048752. Part 37: GetGeometryForFrame should return a rect instead of an nsresult. r=tn

--HG--
extra : rebase_source : f49846cc50de2a3a616a991d81b38bf6c1d9a2c5
This commit is contained in:
Robert O'Callahan 2014-08-06 17:19:32 +12:00
Родитель 98d88074ed
Коммит 96711a9de4
2 изменённых файлов: 21 добавлений и 22 удалений

Просмотреть файл

@ -273,16 +273,20 @@ void nsCaret::SetCaretReadOnly(bool inMakeReadonly)
SchedulePaint(); SchedulePaint();
} }
/* static */ nsresult /* static */ nsRect
nsCaret::GetGeometryForFrame(nsIFrame* aFrame, nsCaret::GetGeometryForFrame(nsIFrame* aFrame,
int32_t aFrameOffset, int32_t aFrameOffset,
nsRect* aRect,
nscoord* aBidiIndicatorSize) nscoord* aBidiIndicatorSize)
{ {
nsPoint framePos(0, 0); nsPoint framePos(0, 0);
nsRect rect;
nsresult rv = aFrame->GetPointFromOffset(aFrameOffset, &framePos); nsresult rv = aFrame->GetPointFromOffset(aFrameOffset, &framePos);
if (NS_FAILED(rv)) if (NS_FAILED(rv)) {
return rv; if (aBidiIndicatorSize) {
*aBidiIndicatorSize = 0;
}
return rect;
}
nsIFrame* frame = aFrame->GetContentInsertionFrame(); nsIFrame* frame = aFrame->GetContentInsertionFrame();
if (!frame) { if (!frame) {
@ -303,7 +307,7 @@ nsCaret::GetGeometryForFrame(nsIFrame* aFrame,
nscoord height = ascent + descent; nscoord height = ascent + descent;
framePos.y = baseline - ascent; framePos.y = baseline - ascent;
Metrics caretMetrics = ComputeMetrics(aFrame, aFrameOffset, height); Metrics caretMetrics = ComputeMetrics(aFrame, aFrameOffset, height);
*aRect = nsRect(framePos, nsSize(caretMetrics.mCaretWidth, height)); rect = nsRect(framePos, nsSize(caretMetrics.mCaretWidth, height));
// Clamp the x-position to be within our scroll frame. If we don't, then it // Clamp the x-position to be within our scroll frame. If we don't, then it
// clips us, and we don't appear at all. See bug 335560. // clips us, and we don't appear at all. See bug 335560.
@ -313,20 +317,21 @@ nsCaret::GetGeometryForFrame(nsIFrame* aFrame,
// First, use the scrollFrame to get at the scrollable view that we're in. // First, use the scrollFrame to get at the scrollable view that we're in.
nsIScrollableFrame *sf = do_QueryFrame(scrollFrame); nsIScrollableFrame *sf = do_QueryFrame(scrollFrame);
nsIFrame *scrolled = sf->GetScrolledFrame(); nsIFrame *scrolled = sf->GetScrolledFrame();
nsRect caretInScroll = *aRect + aFrame->GetOffsetTo(scrolled); nsRect caretInScroll = rect + aFrame->GetOffsetTo(scrolled);
// Now see if thet caret extends beyond the view's bounds. If it does, // Now see if thet caret extends beyond the view's bounds. If it does,
// then snap it back, put it as close to the edge as it can. // then snap it back, put it as close to the edge as it can.
nscoord overflow = caretInScroll.XMost() - nscoord overflow = caretInScroll.XMost() -
scrolled->GetVisualOverflowRectRelativeToSelf().width; scrolled->GetVisualOverflowRectRelativeToSelf().width;
if (overflow > 0) if (overflow > 0) {
aRect->x -= overflow; rect.x -= overflow;
}
} }
if (aBidiIndicatorSize) if (aBidiIndicatorSize) {
*aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize; *aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize;
}
return NS_OK; return rect;
} }
static nsIFrame* static nsIFrame*
@ -372,7 +377,7 @@ nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect)
nsIFrame* frame = GetFrameAndOffset( nsIFrame* frame = GetFrameAndOffset(
static_cast<Selection*>(aSelection), nullptr, 0, &frameOffset); static_cast<Selection*>(aSelection), nullptr, 0, &frameOffset);
if (frame) { if (frame) {
GetGeometryForFrame(frame, frameOffset, aRect, nullptr); *aRect = GetGeometryForFrame(frame, frameOffset, nullptr);
} }
return frame; return frame;
} }
@ -818,12 +823,7 @@ nsCaret::ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
NS_ASSERTION(aFrame, "Should have a frame here"); NS_ASSERTION(aFrame, "Should have a frame here");
nscoord bidiIndicatorSize; nscoord bidiIndicatorSize;
nsresult rv = *aCaretRect = GetGeometryForFrame(aFrame, aFrameOffset, &bidiIndicatorSize);
GetGeometryForFrame(aFrame, aFrameOffset, aCaretRect, &bidiIndicatorSize);
if (NS_FAILED(rv)) {
*aCaretRect = *aHookRect = nsRect();
return;
}
// on RTL frames the right edge of mCaretRect must be equal to framePos // on RTL frames the right edge of mCaretRect must be equal to framePos
const nsStyleVisibility* vis = aFrame->StyleVisibility(); const nsStyleVisibility* vis = aFrame->StyleVisibility();

Просмотреть файл

@ -164,10 +164,9 @@ protected:
}; };
static Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset, static Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset,
nscoord aCaretHeight); nscoord aCaretHeight);
static nsresult GetGeometryForFrame(nsIFrame* aFrame, static nsRect GetGeometryForFrame(nsIFrame* aFrame,
int32_t aFrameOffset, int32_t aFrameOffset,
nsRect* aRect, nscoord* aBidiIndicatorSize);
nscoord* aBidiIndicatorSize);
void ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset, void ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
nsRect* aCaretRect, nsRect* aHookRect); nsRect* aCaretRect, nsRect* aHookRect);