Bug 1082486 - Part 4 - Check whether nsCaret shows in the scroll frame. r=roc

This patch check whether nsCaret shows in scroll frame. If yes, touch
caret will show, and its position will be clamp to scroll frame as
before. Otherwise, we hide it since the nsCaret will not be seen in this
case.
This commit is contained in:
Ting-Yu Lin 2014-10-16 22:03:00 +02:00
parent 7cd6cb94a0
commit 142b3b8d13
2 changed files with 43 additions and 1 deletions

View File

@ -371,7 +371,6 @@ TouchCaret::UpdatePositionIfNeeded()
if (!IsDisplayable()) {
SetVisibility(false);
return;
}
if (mVisible) {
@ -427,6 +426,11 @@ TouchCaret::IsDisplayable()
return false;
}
if (!IsCaretShowingInScrollFrame()) {
TOUCHCARET_LOG("Caret does not show in the scrollable frame!");
return false;
}
return true;
}
@ -457,6 +461,37 @@ TouchCaret::GetTouchCaretPosition()
return pos;
}
bool
TouchCaret::IsCaretShowingInScrollFrame()
{
nsRect caretRect;
nsIFrame* caretFrame = GetCaretFocusFrame(&caretRect);
nsIFrame* closestScrollFrame =
nsLayoutUtils::GetClosestFrameOfType(caretFrame, nsGkAtoms::scrollFrame);
while (closestScrollFrame) {
nsIScrollableFrame* sf = do_QueryFrame(closestScrollFrame);
nsRect scrollPortRect = sf->GetScrollPortRect();
nsRect caretRectRelativeToScrollFrame = caretRect;
nsLayoutUtils::TransformRect(caretFrame, closestScrollFrame,
caretRectRelativeToScrollFrame);
// Check whether nsCaret appears in the scroll frame or not.
if (!scrollPortRect.Intersects(caretRectRelativeToScrollFrame)) {
return false;
}
// Get next ancestor scroll frame.
closestScrollFrame =
nsLayoutUtils::GetClosestFrameOfType(closestScrollFrame->GetParent(),
nsGkAtoms::scrollFrame);
}
return true;
}
nsPoint
TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
{
@ -467,6 +502,7 @@ TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
// Clamp the touch caret position to the scrollframe boundary.
nsIFrame* closestScrollFrame =
nsLayoutUtils::GetClosestFrameOfType(focusFrame, nsGkAtoms::scrollFrame);
while (closestScrollFrame) {
nsIScrollableFrame* sf = do_QueryFrame(closestScrollFrame);
nsRect visualRect = sf->GetScrollPortRect();

View File

@ -117,6 +117,12 @@ private:
*/
nsPoint GetTouchCaretPosition();
/**
* Check whether nsCaret shows in the scroll frame boundary, i.e. its rect
* intersects scroll frame's rect.
*/
bool IsCaretShowingInScrollFrame();
/**
* Clamp the position of the touch caret to the scroll frame boundary.
* The returned point is relative to the canvas frame.