mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1122805 - v3 Update carets' positions based on coordinates of the root frame. r=roc
This commit is contained in:
parent
9a06424267
commit
b81f2619bf
@ -461,10 +461,9 @@ SelectionCarets::UpdateSelectionCarets()
|
||||
nsRefPtr<nsRange> firstRange = selection->GetRangeAt(0);
|
||||
nsRefPtr<nsRange> lastRange = selection->GetRangeAt(rangeCount - 1);
|
||||
|
||||
nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
|
||||
nsIFrame* rootFrame = mPresShell->GetRootFrame();
|
||||
|
||||
if (!canvasFrame || !rootFrame) {
|
||||
if (!rootFrame) {
|
||||
SetVisibility(false);
|
||||
return;
|
||||
}
|
||||
@ -523,23 +522,18 @@ SelectionCarets::UpdateSelectionCarets()
|
||||
bool endFrameVisible =
|
||||
nsLayoutUtils::IsRectVisibleInScrollFrames(endFrame, lastRectInEndFrame);
|
||||
|
||||
nsRect firstRectInCanvasFrame = firstRectInStartFrame;
|
||||
nsRect lastRectInCanvasFrame = lastRectInEndFrame;
|
||||
nsLayoutUtils::TransformRect(startFrame, canvasFrame, firstRectInCanvasFrame);
|
||||
nsLayoutUtils::TransformRect(endFrame, canvasFrame, lastRectInCanvasFrame);
|
||||
|
||||
SetStartFrameVisibility(startFrameVisible);
|
||||
SetEndFrameVisibility(endFrameVisible);
|
||||
|
||||
SetStartFramePos(firstRectInCanvasFrame.BottomLeft());
|
||||
SetEndFramePos(lastRectInCanvasFrame.BottomRight());
|
||||
SetVisibility(true);
|
||||
|
||||
nsRect firstRectInRootFrame = firstRectInStartFrame;
|
||||
nsRect lastRectInRootFrame = lastRectInEndFrame;
|
||||
nsLayoutUtils::TransformRect(startFrame, rootFrame, firstRectInRootFrame);
|
||||
nsLayoutUtils::TransformRect(endFrame, rootFrame, lastRectInRootFrame);
|
||||
|
||||
SetStartFrameVisibility(startFrameVisible);
|
||||
SetEndFrameVisibility(endFrameVisible);
|
||||
|
||||
SetStartFramePos(firstRectInRootFrame.BottomLeft());
|
||||
SetEndFramePos(lastRectInRootFrame.BottomRight());
|
||||
SetVisibility(true);
|
||||
|
||||
// Use half of the first(last) rect as the dragup(dragdown) boundary
|
||||
mDragUpYBoundary =
|
||||
(firstRectInRootFrame.BottomLeft().y + firstRectInRootFrame.TopLeft().y) / 2;
|
||||
|
@ -140,6 +140,16 @@ TouchCaret::GetCanvasFrame()
|
||||
return presShell->GetCanvasFrame();
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
TouchCaret::GetRootFrame()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
if (!presShell) {
|
||||
return nullptr;
|
||||
}
|
||||
return presShell->GetRootFrame();
|
||||
}
|
||||
|
||||
void
|
||||
TouchCaret::SetVisibility(bool aVisible)
|
||||
{
|
||||
@ -282,7 +292,6 @@ TouchCaret::MoveCaret(const nsPoint& movePoint)
|
||||
if (!focusFrame && !canvasFrame) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsIFrame* scrollable =
|
||||
nsLayoutUtils::GetClosestFrameOfType(focusFrame, nsGkAtoms::scrollFrame);
|
||||
|
||||
@ -419,6 +428,12 @@ TouchCaret::IsDisplayable()
|
||||
return false;
|
||||
}
|
||||
|
||||
nsIFrame* rootFrame = GetRootFrame();
|
||||
if (!rootFrame) {
|
||||
TOUCHCARET_LOG("No root frame!");
|
||||
return false;
|
||||
}
|
||||
|
||||
dom::Element* touchCaretElement = presShell->GetTouchCaretElement();
|
||||
if (!touchCaretElement) {
|
||||
TOUCHCARET_LOG("No touch caret frame element!");
|
||||
@ -483,14 +498,14 @@ TouchCaret::GetTouchCaretPosition()
|
||||
{
|
||||
nsRect focusRect;
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame(&focusRect);
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
nsIFrame* rootFrame = GetRootFrame();
|
||||
|
||||
// Position of the touch caret relative to focusFrame.
|
||||
nsPoint pos = nsPoint(focusRect.x + (focusRect.width / 2),
|
||||
focusRect.y + focusRect.height);
|
||||
|
||||
// Transform the position to make it relative to canvas frame.
|
||||
nsLayoutUtils::TransformPoint(focusFrame, canvasFrame, pos);
|
||||
// Transform the position to make it relative to root frame.
|
||||
nsLayoutUtils::TransformPoint(focusFrame, rootFrame, pos);
|
||||
|
||||
return pos;
|
||||
}
|
||||
@ -500,7 +515,7 @@ TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
|
||||
{
|
||||
nsPoint pos = aPosition;
|
||||
nsIFrame* focusFrame = GetCaretFocusFrame();
|
||||
nsIFrame* canvasFrame = GetCanvasFrame();
|
||||
nsIFrame* rootFrame = GetRootFrame();
|
||||
|
||||
// Clamp the touch caret position to the scrollframe boundary.
|
||||
nsIFrame* closestScrollFrame =
|
||||
@ -511,7 +526,7 @@ TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
|
||||
nsRect visualRect = sf->GetScrollPortRect();
|
||||
|
||||
// Clamp the touch caret in the scroll port.
|
||||
nsLayoutUtils::TransformRect(closestScrollFrame, canvasFrame, visualRect);
|
||||
nsLayoutUtils::TransformRect(closestScrollFrame, rootFrame, visualRect);
|
||||
pos = visualRect.ClampPoint(pos);
|
||||
|
||||
// Get next ancestor scroll frame.
|
||||
|
@ -87,6 +87,11 @@ private:
|
||||
*/
|
||||
nsCanvasFrame* GetCanvasFrame();
|
||||
|
||||
/**
|
||||
* Find the root frame to update the touch caret's position.
|
||||
*/
|
||||
nsIFrame* GetRootFrame();
|
||||
|
||||
/**
|
||||
* Retrieve the bounding rectangle of the touch caret.
|
||||
*
|
||||
|
@ -311,10 +311,20 @@ parsererror|sourcetext {
|
||||
|
||||
div:-moz-native-anonymous.moz-touchcaret,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-left,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-right,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-right {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
div:-moz-native-anonymous.moz-selectioncaret-left > div,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-right > div {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
div:-moz-native-anonymous.moz-touchcaret,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-left,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-right,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-left > div,
|
||||
div:-moz-native-anonymous.moz-selectioncaret-right > div {
|
||||
width: 29px;
|
||||
height: 31px;
|
||||
background-position: center center;
|
||||
|
Loading…
Reference in New Issue
Block a user