Bug 1450208: Change nsRange::ExtractRectFromOffset to use simpler, hopefully safer logic to determine whether text is vertical.
Instead of checking nsIFrame::IsTextFrame() and then casting to nsTextFrame,
the new code just checks the writing mode of the frame. Less casts; less
chance of pointer errors.
MozReview-Commit-ID: LrtthZjwYq6
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -2906,26 +2906,25 @@ nsRange::CreateContextualFragment(const
return nsContentUtils::CreateContextualFragment(mStart.Container(), aFragment,
false, aRv);
}
static void ExtractRectFromOffset(nsIFrame* aFrame,
const int32_t aOffset, nsRect* aR,
bool aFlushToOriginEdge, bool aClampToEdge)
{
+ MOZ_ASSERT(aFrame);
+ MOZ_ASSERT(aR);
+
nsPoint point;
aFrame->GetPointFromOffset(aOffset, &point);
- // Determine if point was generated from a vertical text run, which will change
- // our math on the output rect.
- bool isVertical = false;
- if (aFrame->IsTextFrame()) {
- nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
- isVertical = textFrame->GetTextRun(nsTextFrame::eInflated)->IsVertical();
- }
+ // Determine if aFrame has a vertical writing mode, which will change our math
+ // on the output rect.
+ bool isVertical = aFrame->GetWritingMode().IsVertical();
if (!aClampToEdge && !aR->Contains(point)) {
// If point is outside aR, and we aren't clamping, output an empty rect
// with origin at the point.
if (isVertical) {
aR->SetHeight(0);
aR->y = point.y;
} else {