зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1433883: Remove weak pres context pointer from ContentEventHandler. r=masayuki
Holding a weak pres context pointer across stuff that does flushes is dangerous. Hopefully, we just poke at it when we find a frame (thus a pres context should be around, and it rather be the one that we started poking at). I think it'd be better to just not keep the member around, since frames can reach the pres context easily. MozReview-Commit-ID: HcepvzcSsaH --HG-- extra : rebase_source : 5d0ffb1502e64f8010b7aea714a4caf762c9a95e
This commit is contained in:
Родитель
d9872d9e13
Коммит
18b861e52f
|
@ -243,8 +243,7 @@ ContentEventHandler::RawRange::SelectNodeContents(
|
||||||
// line break caused by the <br> should be included into the flatten text.
|
// line break caused by the <br> should be included into the flatten text.
|
||||||
|
|
||||||
ContentEventHandler::ContentEventHandler(nsPresContext* aPresContext)
|
ContentEventHandler::ContentEventHandler(nsPresContext* aPresContext)
|
||||||
: mPresContext(aPresContext)
|
: mDocument(aPresContext->Document())
|
||||||
, mDocument(aPresContext->Document())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,8 +513,10 @@ ContentEventHandler::QueryContentRect(nsIContent* aContent,
|
||||||
nsresult rv = ConvertToRootRelativeOffset(frame, resultRect);
|
nsresult rv = ConvertToRootRelativeOffset(frame, resultRect);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsPresContext* presContext = frame->PresContext();
|
||||||
|
|
||||||
// account for any additional frames
|
// account for any additional frames
|
||||||
while ((frame = frame->GetNextContinuation()) != nullptr) {
|
while ((frame = frame->GetNextContinuation())) {
|
||||||
nsRect frameRect(nsPoint(0, 0), frame->GetRect().Size());
|
nsRect frameRect(nsPoint(0, 0), frame->GetRect().Size());
|
||||||
rv = ConvertToRootRelativeOffset(frame, frameRect);
|
rv = ConvertToRootRelativeOffset(frame, frameRect);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
@ -523,7 +524,7 @@ ContentEventHandler::QueryContentRect(nsIContent* aContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
||||||
resultRect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
|
resultRect.ToOutsidePixels(presContext->AppUnitsPerDevPixel()));
|
||||||
// Returning empty rect may cause native IME confused, let's make sure to
|
// Returning empty rect may cause native IME confused, let's make sure to
|
||||||
// return non-empty rect.
|
// return non-empty rect.
|
||||||
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
||||||
|
@ -1860,10 +1861,10 @@ ContentEventHandler::GetLineBreakerRectBefore(nsIFrame* aFrame)
|
||||||
// above of top-right corner of aFrame.
|
// above of top-right corner of aFrame.
|
||||||
result.mRect.x = aFrame->GetRect().XMost() - result.mRect.width;
|
result.mRect.x = aFrame->GetRect().XMost() - result.mRect.width;
|
||||||
}
|
}
|
||||||
result.mRect.y = -mPresContext->AppUnitsPerDevPixel();
|
result.mRect.y = -aFrame->PresContext()->AppUnitsPerDevPixel();
|
||||||
} else {
|
} else {
|
||||||
// left of top-left corner of aFrame.
|
// left of top-left corner of aFrame.
|
||||||
result.mRect.x = -mPresContext->AppUnitsPerDevPixel();
|
result.mRect.x = -aFrame->PresContext()->AppUnitsPerDevPixel();
|
||||||
result.mRect.y = 0;
|
result.mRect.y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1908,6 +1909,7 @@ ContentEventHandler::FrameRelativeRect
|
||||||
ContentEventHandler::GuessFirstCaretRectIn(nsIFrame* aFrame)
|
ContentEventHandler::GuessFirstCaretRectIn(nsIFrame* aFrame)
|
||||||
{
|
{
|
||||||
const WritingMode kWritingMode = aFrame->GetWritingMode();
|
const WritingMode kWritingMode = aFrame->GetWritingMode();
|
||||||
|
nsPresContext* presContext = aFrame->PresContext();
|
||||||
|
|
||||||
// Computes the font height, but if it's not available, we should use
|
// Computes the font height, but if it's not available, we should use
|
||||||
// default font size of Firefox. The default font size in default settings
|
// default font size of Firefox. The default font size in default settings
|
||||||
|
@ -1916,7 +1918,7 @@ ContentEventHandler::GuessFirstCaretRectIn(nsIFrame* aFrame)
|
||||||
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame);
|
||||||
const nscoord kMaxHeight =
|
const nscoord kMaxHeight =
|
||||||
fontMetrics ? fontMetrics->MaxHeight() :
|
fontMetrics ? fontMetrics->MaxHeight() :
|
||||||
16 * mPresContext->AppUnitsPerDevPixel();
|
16 * presContext->AppUnitsPerDevPixel();
|
||||||
|
|
||||||
nsRect caretRect;
|
nsRect caretRect;
|
||||||
const nsRect kContentRect = aFrame->GetContentRect() - aFrame->GetPosition();
|
const nsRect kContentRect = aFrame->GetContentRect() - aFrame->GetPosition();
|
||||||
|
@ -1926,7 +1928,7 @@ ContentEventHandler::GuessFirstCaretRectIn(nsIFrame* aFrame)
|
||||||
caretRect.x = kContentRect.x;
|
caretRect.x = kContentRect.x;
|
||||||
} else {
|
} else {
|
||||||
// Move 1px left for the space of caret itself.
|
// Move 1px left for the space of caret itself.
|
||||||
const nscoord kOnePixel = mPresContext->AppUnitsPerDevPixel();
|
const nscoord kOnePixel = presContext->AppUnitsPerDevPixel();
|
||||||
caretRect.x = kContentRect.XMost() - kOnePixel;
|
caretRect.x = kContentRect.XMost() - kOnePixel;
|
||||||
}
|
}
|
||||||
caretRect.height = kMaxHeight;
|
caretRect.height = kMaxHeight;
|
||||||
|
@ -2176,8 +2178,8 @@ ContentEventHandler::OnQueryTextRectArray(WidgetQueryContentEvent* aEvent)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect = LayoutDeviceIntRect::FromUnknownRect(
|
rect = LayoutDeviceIntRect::FromUnknownRect(charRect.ToOutsidePixels(
|
||||||
charRect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
|
baseFrame->PresContext()->AppUnitsPerDevPixel()));
|
||||||
// Returning empty rect may cause native IME confused, let's make sure to
|
// Returning empty rect may cause native IME confused, let's make sure to
|
||||||
// return non-empty rect.
|
// return non-empty rect.
|
||||||
EnsureNonEmptyRect(rect);
|
EnsureNonEmptyRect(rect);
|
||||||
|
@ -2328,7 +2330,9 @@ ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
|
||||||
// If there is at least one frame which can be used for computing a rect
|
// If there is at least one frame which can be used for computing a rect
|
||||||
// for a character or a line breaker, we should use it for guessing the
|
// for a character or a line breaker, we should use it for guessing the
|
||||||
// caret rect at the end of the contents.
|
// caret rect at the end of the contents.
|
||||||
|
nsPresContext* presContext;
|
||||||
if (lastFrame) {
|
if (lastFrame) {
|
||||||
|
presContext = lastFrame->PresContext();
|
||||||
if (NS_WARN_IF(!lastFrame->GetContent())) {
|
if (NS_WARN_IF(!lastFrame->GetContent())) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -2364,6 +2368,7 @@ ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
|
||||||
if (NS_WARN_IF(!rootContentFrame)) {
|
if (NS_WARN_IF(!rootContentFrame)) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
presContext = rootContentFrame->PresContext();
|
||||||
FrameRelativeRect relativeRect = GuessFirstCaretRectIn(rootContentFrame);
|
FrameRelativeRect relativeRect = GuessFirstCaretRectIn(rootContentFrame);
|
||||||
if (NS_WARN_IF(!relativeRect.IsValid())) {
|
if (NS_WARN_IF(!relativeRect.IsValid())) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -2376,7 +2381,7 @@ ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
|
||||||
aEvent->mReply.mWritingMode = rootContentFrame->GetWritingMode();
|
aEvent->mReply.mWritingMode = rootContentFrame->GetWritingMode();
|
||||||
}
|
}
|
||||||
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
||||||
rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
|
rect.ToOutsidePixels(presContext->AppUnitsPerDevPixel()));
|
||||||
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
||||||
aEvent->mSucceeded = true;
|
aEvent->mSucceeded = true;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -2558,7 +2563,7 @@ ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
aEvent->mReply.mRect = LayoutDeviceIntRect::FromUnknownRect(
|
||||||
rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
|
rect.ToOutsidePixels(lastFrame->PresContext()->AppUnitsPerDevPixel()));
|
||||||
// Returning empty rect may cause native IME confused, let's make sure to
|
// Returning empty rect may cause native IME confused, let's make sure to
|
||||||
// return non-empty rect.
|
// return non-empty rect.
|
||||||
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
EnsureNonEmptyRect(aEvent->mReply.mRect);
|
||||||
|
@ -2808,8 +2813,8 @@ ContentEventHandler::OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent)
|
||||||
aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset();
|
aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset();
|
||||||
CSSIntRect docFrameRect = docFrame->GetScreenRect();
|
CSSIntRect docFrameRect = docFrame->GetScreenRect();
|
||||||
CSSIntPoint eventLocCSS(
|
CSSIntPoint eventLocCSS(
|
||||||
mPresContext->DevPixelsToIntCSSPixels(eventLoc.x) - docFrameRect.x,
|
docFrame->PresContext()->DevPixelsToIntCSSPixels(eventLoc.x) - docFrameRect.x,
|
||||||
mPresContext->DevPixelsToIntCSSPixels(eventLoc.y) - docFrameRect.y);
|
docFrame->PresContext()->DevPixelsToIntCSSPixels(eventLoc.y) - docFrameRect.y);
|
||||||
|
|
||||||
Element* contentUnderMouse =
|
Element* contentUnderMouse =
|
||||||
mDocument->ElementFromPointHelper(eventLocCSS.x, eventLocCSS.y, false, false);
|
mDocument->ElementFromPointHelper(eventLocCSS.x, eventLocCSS.y, false, false);
|
||||||
|
|
|
@ -140,7 +140,6 @@ public:
|
||||||
nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
|
nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsPresContext* mPresContext;
|
|
||||||
nsCOMPtr<nsIDocument> mDocument;
|
nsCOMPtr<nsIDocument> mDocument;
|
||||||
// mSelection is typically normal selection but if OnQuerySelectedText()
|
// mSelection is typically normal selection but if OnQuerySelectedText()
|
||||||
// is called, i.e., handling eQuerySelectedText, it's the specified selection
|
// is called, i.e., handling eQuerySelectedText, it's the specified selection
|
||||||
|
|
Загрузка…
Ссылка в новой задаче