Bug 1021499 - Enlarge touch/selection carets touch area. r=roc

This commit is contained in:
Morris Tseng 2015-04-15 19:15:00 +02:00
Родитель f3bad20a10
Коммит 6176571161
6 изменённых файлов: 58 добавлений и 48 удалений

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

@ -537,8 +537,8 @@ SelectionCarets::UpdateSelectionCarets()
SetStartFrameVisibility(startFrameVisible);
SetEndFrameVisibility(endFrameVisible);
SetStartFramePos(firstRectInRootFrame.BottomLeft());
SetEndFramePos(lastRectInRootFrame.BottomRight());
SetStartFramePos(firstRectInRootFrame);
SetEndFramePos(lastRectInRootFrame);
SetVisibility(true);
// Use half of the first(last) rect as the dragup(dragdown) boundary
@ -885,7 +885,7 @@ SelectionCarets::SetSelectionDirection(nsDirection aDir)
}
static void
SetFramePos(dom::Element* aElement, const nsPoint& aPosition)
SetFramePos(dom::Element* aElement, const nsRect& aCaretRect)
{
if (!aElement) {
return;
@ -893,9 +893,11 @@ SetFramePos(dom::Element* aElement, const nsPoint& aPosition)
nsAutoString styleStr;
styleStr.AppendLiteral("left: ");
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aPosition.x));
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.Center().x));
styleStr.AppendLiteral("px; top: ");
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aPosition.y));
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.y));
styleStr.AppendLiteral("px; padding-top: ");
styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.height));
styleStr.AppendLiteral("px;");
SELECTIONCARETS_LOG_STATIC("Set style: %s",
@ -905,17 +907,19 @@ SetFramePos(dom::Element* aElement, const nsPoint& aPosition)
}
void
SelectionCarets::SetStartFramePos(const nsPoint& aPosition)
SelectionCarets::SetStartFramePos(const nsRect& aCaretRect)
{
SELECTIONCARETS_LOG("x=%d, y=%d", aPosition.x, aPosition.y);
SetFramePos(mPresShell->GetSelectionCaretsStartElement(), aPosition);
SELECTIONCARETS_LOG("x=%d, y=%d, w=%d, h=%d",
aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height);
SetFramePos(mPresShell->GetSelectionCaretsStartElement(), aCaretRect);
}
void
SelectionCarets::SetEndFramePos(const nsPoint& aPosition)
SelectionCarets::SetEndFramePos(const nsRect& aCaretRect)
{
SELECTIONCARETS_LOG("x=%d, y=%d", aPosition.y, aPosition.y);
SetFramePos(mPresShell->GetSelectionCaretsEndElement(), aPosition);
SELECTIONCARETS_LOG("x=%d, y=%d, w=%d, h=%d",
aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height);
SetFramePos(mPresShell->GetSelectionCaretsEndElement(), aCaretRect);
}
bool

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

@ -147,16 +147,16 @@ private:
void SetSelectionDirection(nsDirection aDir);
/**
* Move start frame of selection caret to given position.
* Move start frame of selection caret based on current caret pos.
* In app units.
*/
void SetStartFramePos(const nsPoint& aPosition);
void SetStartFramePos(const nsRect& aCaretRect);
/**
* Move end frame of selection caret to given position.
* Move end frame of selection caret based on current caret pos.
* In app units.
*/
void SetEndFramePos(const nsPoint& aPosition);
void SetEndFramePos(const nsRect& aCaretRect);
/**
* Check if aPosition is on the start or end frame of the

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

@ -249,7 +249,7 @@ TouchCaret::GetCaretYCenterPosition()
}
void
TouchCaret::SetTouchFramePos(const nsPoint& aOrigin)
TouchCaret::SetTouchFramePos(const nsRect& aCaretRect)
{
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
if (!presShell) {
@ -263,14 +263,17 @@ TouchCaret::SetTouchFramePos(const nsPoint& aOrigin)
// Convert aOrigin to CSS pixels.
nsRefPtr<nsPresContext> presContext = presShell->GetPresContext();
int32_t x = presContext->AppUnitsToIntCSSPixels(aOrigin.x);
int32_t y = presContext->AppUnitsToIntCSSPixels(aOrigin.y);
int32_t x = presContext->AppUnitsToIntCSSPixels(aCaretRect.Center().x);
int32_t y = presContext->AppUnitsToIntCSSPixels(aCaretRect.y);
int32_t padding = presContext->AppUnitsToIntCSSPixels(aCaretRect.height);
nsAutoString styleStr;
styleStr.AppendLiteral("left: ");
styleStr.AppendInt(x);
styleStr.AppendLiteral("px; top: ");
styleStr.AppendInt(y);
styleStr.AppendLiteral("px; padding-top: ");
styleStr.AppendInt(padding);
styleStr.AppendLiteral("px;");
TOUCHCARET_LOG("Set style: %s", NS_ConvertUTF16toUTF8(styleStr).get());
@ -483,32 +486,27 @@ TouchCaret::UpdatePosition()
{
MOZ_ASSERT(mVisible);
nsPoint pos = GetTouchCaretPosition();
pos = ClampPositionToScrollFrame(pos);
SetTouchFramePos(pos);
nsRect rect = GetTouchCaretRect();
rect = ClampRectToScrollFrame(rect);
SetTouchFramePos(rect);
}
nsPoint
TouchCaret::GetTouchCaretPosition()
nsRect
TouchCaret::GetTouchCaretRect()
{
nsRect focusRect;
nsIFrame* focusFrame = GetCaretFocusFrame(&focusRect);
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 root frame.
nsLayoutUtils::TransformPoint(focusFrame, rootFrame, pos);
nsLayoutUtils::TransformRect(focusFrame, rootFrame, focusRect);
return pos;
return focusRect;
}
nsPoint
TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
nsRect
TouchCaret::ClampRectToScrollFrame(const nsRect& aRect)
{
nsPoint pos = aPosition;
nsRect rect = aRect;
nsIFrame* focusFrame = GetCaretFocusFrame();
nsIFrame* rootFrame = GetRootFrame();
@ -522,7 +520,7 @@ TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
// Clamp the touch caret in the scroll port.
nsLayoutUtils::TransformRect(closestScrollFrame, rootFrame, visualRect);
pos = visualRect.ClampPoint(pos);
rect = rect.Intersect(visualRect);
// Get next ancestor scroll frame.
closestScrollFrame =
@ -530,7 +528,7 @@ TouchCaret::ClampPositionToScrollFrame(const nsPoint& aPosition)
nsGkAtoms::scrollFrame);
}
return pos;
return rect;
}
/* static */void

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

@ -117,22 +117,22 @@ private:
nscoord GetCaretYCenterPosition();
/**
* Retrieve the position of the touch caret.
* The returned point is relative to the canvas frame.
* Retrieve the rect of the touch caret.
* The returned rect is relative to the canvas frame.
*/
nsPoint GetTouchCaretPosition();
nsRect GetTouchCaretRect();
/**
* Clamp the position of the touch caret to the scroll frame boundary.
* The returned point is relative to the canvas frame.
* The returned rect is relative to the canvas frame.
*/
nsPoint ClampPositionToScrollFrame(const nsPoint& aPosition);
nsRect ClampRectToScrollFrame(const nsRect& aRect);
/**
* Set the position of the touch caret.
* Touch caret is an absolute positioned div.
*/
void SetTouchFramePos(const nsPoint& aOrigin);
void SetTouchFramePos(const nsRect& aRect);
void LaunchExpirationTimer();
void CancelExpirationTimer();

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

@ -510,9 +510,13 @@ nsCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
nsIFrame* kid;
for (kid = GetFirstPrincipalChild(); kid; kid = kid->GetNextSibling()) {
// Skip touch caret frame if we do not build caret.
if (!aBuilder->IsBuildingCaret() && kid->GetContent() == mTouchCaretElement) {
continue;
// Skip touch/selection caret frame if we do not build caret.
if (!aBuilder->IsBuildingCaret()) {
if(kid->GetContent() == mTouchCaretElement ||
kid->GetContent() == mSelectionCaretsStartElement||
kid->GetContent() == mSelectionCaretsEndElement) {
continue;
}
}
// Put our child into its own pseudo-stack.

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

@ -318,11 +318,16 @@ div:-moz-native-anonymous.moz-touchcaret,
div:-moz-native-anonymous.moz-selectioncaret-left,
div:-moz-native-anonymous.moz-selectioncaret-right {
position: fixed;
width: 44px;
height: 47px;
}
div:-moz-native-anonymous.moz-selectioncaret-left > div,
div:-moz-native-anonymous.moz-selectioncaret-right > div {
position: absolute;
width: 100%;
height: 100%;
bottom: 0;
}
div:-moz-native-anonymous.moz-touchcaret,
@ -330,10 +335,9 @@ 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: 44px;
height: 47px;
background-position: center center;
background-size: 100% 100%;
background-position: center bottom;
background-size: 100%;
background-repeat: no-repeat;
z-index: 2147483647;
}