Bug 1065244 - Part 1 - Add GetRectRelativeToFrame to nsLayoutUtils. f=mtseng, r=roc

This commit is contained in:
Ting-Yu Lin 2014-09-15 17:07:00 +02:00
parent 0a0cfcb515
commit 88ac0a85b6
4 changed files with 34 additions and 37 deletions

View File

@ -791,39 +791,17 @@ SelectionCarets::SetEndFramePos(const nsPoint& aPosition)
nsRect
SelectionCarets::GetStartFrameRect()
{
nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
dom::Element* element = mPresShell->GetSelectionCaretsStartElement();
if (!element) {
return nsRect();
}
nsIFrame* frame = element->GetPrimaryFrame();
if (!frame) {
return nsRect();
}
nsRect frameRect = frame->GetRectRelativeToSelf();
nsLayoutUtils::TransformRect(frame, canvasFrame, frameRect);
return frameRect;
nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
return nsLayoutUtils::GetRectRelativeToFrame(element, canvasFrame);
}
nsRect
SelectionCarets::GetEndFrameRect()
{
nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
dom::Element* element = mPresShell->GetSelectionCaretsEndElement();
if (!element) {
return nsRect();
}
nsIFrame* frame = element->GetPrimaryFrame();
if (!frame) {
return nsRect();
}
nsRect frameRect = frame->GetRectRelativeToSelf();
nsLayoutUtils::TransformRect(frame, canvasFrame, frameRect);
return frameRect;
nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
return nsLayoutUtils::GetRectRelativeToFrame(element, canvasFrame);
}
nsIFrame*

View File

@ -145,18 +145,8 @@ TouchCaret::GetTouchFrameRect()
}
dom::Element* touchCaretElement = presShell->GetTouchCaretElement();
if (!touchCaretElement) {
return nsRect();
}
// Get touch caret position relative to canvas frame.
nsIFrame* touchCaretFrame = touchCaretElement->GetPrimaryFrame();
nsRect tcRect = touchCaretFrame->GetRectRelativeToSelf();
nsIFrame* canvasFrame = GetCanvasFrame();
nsLayoutUtils::TransformResult rv =
nsLayoutUtils::TransformRect(touchCaretFrame, canvasFrame, tcRect);
return rv == nsLayoutUtils::TRANSFORM_SUCCEEDED ? tcRect : nsRect();
return nsLayoutUtils::GetRectRelativeToFrame(touchCaretElement, canvasFrame);
}
nsRect

View File

@ -2389,6 +2389,28 @@ nsLayoutUtils::TransformRect(nsIFrame* aFromFrame, nsIFrame* aToFrame,
return TRANSFORM_SUCCEEDED;
}
nsRect
nsLayoutUtils::GetRectRelativeToFrame(Element* aElement, nsIFrame* aFrame)
{
if (!aElement || !aFrame) {
return nsRect();
}
nsIFrame* frame = aElement->GetPrimaryFrame();
if (!frame) {
return nsRect();
}
nsRect rect = frame->GetRectRelativeToSelf();
nsLayoutUtils::TransformResult rv =
nsLayoutUtils::TransformRect(frame, aFrame, rect);
if (rv != nsLayoutUtils::TRANSFORM_SUCCEEDED) {
return nsRect();
}
return rect;
}
bool
nsLayoutUtils::GetLayerTransformForFrame(nsIFrame* aFrame,
Matrix4x4* aTransform)

View File

@ -754,6 +754,13 @@ public:
static TransformResult TransformRect(nsIFrame* aFromFrame, nsIFrame* aToFrame,
nsRect& aRect);
/**
* Get the border-box of aElement's primary frame, transformed it to be
* relative to aFrame.
*/
static nsRect GetRectRelativeToFrame(mozilla::dom::Element* aElement,
nsIFrame* aFrame);
/**
* Return true if a "layer transform" could be computed for aFrame,
* and optionally return the computed transform. The returned