Bug 1082486 - Part 3 - Refactor UpdatePosition(). r=roc

GetTouchCaretPosition() is needed in a later patch.
This commit is contained in:
Ting-Yu Lin 2014-10-15 03:05:00 +02:00
Родитель d6a6255879
Коммит 4e2fc8bd36
2 изменённых файлов: 31 добавлений и 5 удалений

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

@ -430,14 +430,18 @@ TouchCaret::UpdatePosition()
{
MOZ_ASSERT(mVisible);
nsPoint pos = GetTouchCaretPosition();
pos = ClampPositionToScrollFrame(pos);
SetTouchFramePos(pos);
}
nsPoint
TouchCaret::GetTouchCaretPosition()
{
nsRect focusRect;
nsIFrame* focusFrame = GetCaretFocusFrame(&focusRect);
nsIFrame* canvasFrame = GetCanvasFrame();
if (!focusFrame || !canvasFrame || focusRect.IsEmpty()) {
return;
}
// Position of the touch caret relative to focusFrame.
nsPoint pos = nsPoint(focusRect.x + (focusRect.width / 2),
focusRect.y + focusRect.height);
@ -445,6 +449,16 @@ TouchCaret::UpdatePosition()
// Transform the position to make it relative to canvas frame.
nsLayoutUtils::TransformPoint(focusFrame, canvasFrame, pos);
return pos;
}
nsPoint
TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
{
nsPoint pos = aPosition;
nsIFrame* focusFrame = GetCaretFocusFrame();
nsIFrame* canvasFrame = GetCanvasFrame();
// Clamp the touch caret position to the scrollframe boundary.
nsIFrame* closestScrollFrame =
nsLayoutUtils::GetClosestFrameOfType(focusFrame, nsGkAtoms::scrollFrame);
@ -462,7 +476,7 @@ TouchCaret::UpdatePosition()
nsGkAtoms::scrollFrame);
}
SetTouchFramePos(pos);
return pos;
}
/* static */void

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

@ -111,6 +111,18 @@ private:
*/
nscoord GetCaretYCenterPosition();
/**
* Retrieve the position of the touch caret.
* The returned point is relative to the canvas frame.
*/
nsPoint GetTouchCaretPosition();
/**
* Clamp the position of the touch caret to the scroll frame boundary.
* The returned point is relative to the canvas frame.
*/
nsPoint ClampPositionToScrollFrame(const nsPoint& aPosition);
/**
* Set the position of the touch caret.
* Touch caret is an absolute positioned div.