mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1078991 - Add TouchCaret::GetCaretFocusFrame(). r=roc
This commit is contained in:
parent
bec88b0686
commit
22279846ae
@ -88,6 +88,29 @@ TouchCaret::~TouchCaret()
|
||||
}
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
TouchCaret::GetCaretFocusFrame(nsRect* aOutRect)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (!caret) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRect rect;
|
||||
nsIFrame* frame = caret->GetGeometry(&rect);
|
||||
|
||||
if (aOutRect) {
|
||||
*aOutRect = rect;
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
TouchCaret::GetCanvasFrame()
|
||||
{
|
||||
@ -152,16 +175,12 @@ TouchCaret::GetTouchFrameRect()
|
||||
nsRect
|
||||
TouchCaret::GetContentBoundary()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame();
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
if (!focusFrame || !canvasFrame) {
|
||||
return nsRect();
|
||||
}
|
||||
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
nsRect focusRect;
|
||||
nsIFrame* focusFrame = caret->GetGeometry(&focusRect);
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
|
||||
// Get the editing host to determine the touch caret dragable boundary.
|
||||
dom::Element* editingHost = focusFrame->GetContent()->GetEditingHost();
|
||||
if (!editingHost) {
|
||||
@ -196,16 +215,10 @@ TouchCaret::GetContentBoundary()
|
||||
nscoord
|
||||
TouchCaret::GetCaretYCenterPosition()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
return 0;
|
||||
}
|
||||
nsRect caretRect;
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame(&caretRect);
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
nsRect focusRect;
|
||||
nsIFrame* focusFrame = caret->GetGeometry(&focusRect);
|
||||
nsRect caretRect = focusFrame->GetRectRelativeToSelf();
|
||||
nsIFrame *canvasFrame = GetCanvasFrame();
|
||||
nsLayoutUtils::TransformRect(focusFrame, canvasFrame, caretRect);
|
||||
|
||||
return (caretRect.y + caretRect.height / 2);
|
||||
@ -245,23 +258,16 @@ TouchCaret::SetTouchFramePos(const nsPoint& aOrigin)
|
||||
void
|
||||
TouchCaret::MoveCaret(const nsPoint& movePoint)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame();
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
if (!focusFrame && !canvasFrame) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get scrollable frame.
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
nsRect focusRect;
|
||||
nsIFrame* focusFrame = caret->GetGeometry(&focusRect);
|
||||
nsIFrame* scrollable =
|
||||
nsLayoutUtils::GetClosestFrameOfType(focusFrame, nsGkAtoms::scrollFrame);
|
||||
|
||||
// Convert touch/mouse position to frame coordinates.
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
if (!canvasFrame) {
|
||||
return;
|
||||
}
|
||||
nsPoint offsetToCanvasFrame = nsPoint(0,0);
|
||||
nsLayoutUtils::TransformPoint(scrollable, canvasFrame, offsetToCanvasFrame);
|
||||
nsPoint pt = movePoint - offsetToCanvasFrame;
|
||||
@ -415,16 +421,11 @@ TouchCaret::UpdatePosition()
|
||||
{
|
||||
MOZ_ASSERT(mVisible);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
return;
|
||||
}
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
|
||||
// Caret is visible and shown, update touch caret.
|
||||
nsRect focusRect;
|
||||
nsIFrame* focusFrame = caret->GetGeometry(&focusRect);
|
||||
if (!focusFrame || focusRect.IsEmpty()) {
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame(&focusRect);
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
|
||||
if (!focusFrame || !canvasFrame || focusRect.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -433,10 +434,6 @@ TouchCaret::UpdatePosition()
|
||||
focusRect.y + focusRect.height);
|
||||
|
||||
// Transform the position to make it relative to canvas frame.
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
if (!canvasFrame) {
|
||||
return;
|
||||
}
|
||||
nsLayoutUtils::TransformPoint(focusFrame, canvasFrame, pos);
|
||||
|
||||
// Clamp the touch caret position to the scrollframe boundary.
|
||||
@ -498,14 +495,11 @@ TouchCaret::CancelExpirationTimer()
|
||||
void
|
||||
TouchCaret::SetSelectionDragState(bool aState)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
nsIFrame* caretFocusFrame = GetCaretFocusFrame();
|
||||
if (!caretFocusFrame) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
nsRect focusRect;
|
||||
nsIFrame* caretFocusFrame = caret->GetGeometry(&focusRect);
|
||||
nsRefPtr<nsFrameSelection> fs = caretFocusFrame->GetFrameSelection();
|
||||
fs->SetDragState(aState);
|
||||
}
|
||||
|
@ -76,6 +76,11 @@ private:
|
||||
*/
|
||||
void SetVisibility(bool aVisible);
|
||||
|
||||
/**
|
||||
* Helper function to get caret's focus frame and caret's bounding rect.
|
||||
*/
|
||||
nsIFrame* GetCaretFocusFrame(nsRect* aOutRect = nullptr);
|
||||
|
||||
/**
|
||||
* Find the nsCanvasFrame which holds the touch caret.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user