Bug 1248309 - Fix caret size not updated when only zoom level is changed. r=roc

On Fennec, it's possible that after automatically zooming an editable
input, the mImaginaryCaretRect for the caret remains the same. Only the
zoom level is changed. Therefore, the zoom level should also be
considered to determine whether the position is changed or not so that
the caret can get updated.

MozReview-Commit-ID: CrictS4S0Yl

--HG--
extra : rebase_source : f26f89cb72a9ae8a55104054121486a67e841513
This commit is contained in:
Ting-Yu Lin 2016-02-15 18:29:32 +08:00
Родитель 913ed1d7ab
Коммит 19677da566
2 изменённых файлов: 23 добавлений и 15 удалений

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

@ -7,6 +7,7 @@
#include "AccessibleCaret.h"
#include "AccessibleCaretLogger.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/Preferences.h"
#include "mozilla/ToString.h"
#include "nsCanvasFrame.h"
@ -116,6 +117,7 @@ AccessibleCaret::SetAppearance(Appearance aAppearance)
// Need to reset rect since the cached rect will be compared in SetPosition.
if (mAppearance == Appearance::None) {
mImaginaryCaretRect = nsRect();
mZoomLevel = 0.0f;
}
}
@ -255,25 +257,29 @@ AccessibleCaret::SetPosition(nsIFrame* aFrame, int32_t aOffset)
if (imaginaryCaretRectInFrame.IsEmpty()) {
// Don't bother to set the caret position since it's invisible.
mImaginaryCaretRect = nsRect();
mZoomLevel = 0.0f;
return PositionChangedResult::Invisible;
}
nsRect imaginaryCaretRect = imaginaryCaretRectInFrame;
nsLayoutUtils::TransformRect(aFrame, RootFrame(), imaginaryCaretRect);
float zoomLevel = GetZoomLevel();
if (imaginaryCaretRect.IsEqualEdges(mImaginaryCaretRect)) {
if (imaginaryCaretRect.IsEqualEdges(mImaginaryCaretRect) &&
FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel)) {
return PositionChangedResult::NotChanged;
}
mImaginaryCaretRect = imaginaryCaretRect;
mZoomLevel = zoomLevel;
// SetCaretElementStyle() and SetSelectionBarElementStyle() require the
// input rect relative to container frame.
nsRect imaginaryCaretRectInContainerFrame = imaginaryCaretRectInFrame;
nsLayoutUtils::TransformRect(aFrame, CustomContentContainerFrame(),
imaginaryCaretRectInContainerFrame);
SetCaretElementStyle(imaginaryCaretRectInContainerFrame);
SetSelectionBarElementStyle(imaginaryCaretRectInContainerFrame);
SetCaretElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
SetSelectionBarElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
return PositionChangedResult::Changed;
}
@ -288,7 +294,7 @@ AccessibleCaret::CustomContentContainerFrame() const
}
void
AccessibleCaret::SetCaretElementStyle(const nsRect& aRect)
AccessibleCaret::SetCaretElementStyle(const nsRect& aRect, float aZoomLevel)
{
nsPoint position = CaretElementPosition(aRect);
nsAutoString styleStr;
@ -297,11 +303,10 @@ AccessibleCaret::SetCaretElementStyle(const nsRect& aRect)
nsPresContext::AppUnitsToIntCSSPixels(position.y),
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
float zoomLevel = GetZoomLevel();
styleStr.AppendPrintf(" width: %.2fpx; height: %.2fpx; margin-left: %.2fpx",
sWidth / zoomLevel,
sHeight / zoomLevel,
sMarginLeft / zoomLevel);
sWidth / aZoomLevel,
sHeight / aZoomLevel,
sMarginLeft / aZoomLevel);
ErrorResult rv;
CaretElement()->SetAttribute(NS_LITERAL_STRING("style"), styleStr, rv);
@ -311,15 +316,15 @@ AccessibleCaret::SetCaretElementStyle(const nsRect& aRect)
}
void
AccessibleCaret::SetSelectionBarElementStyle(const nsRect& aRect)
AccessibleCaret::SetSelectionBarElementStyle(const nsRect& aRect,
float aZoomLevel)
{
int32_t height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
nsAutoString barStyleStr;
barStyleStr.AppendPrintf("margin-top: -%dpx; height: %dpx;",
height, height);
float zoomLevel = GetZoomLevel();
barStyleStr.AppendPrintf(" width: %.2fpx;", sBarWidth / zoomLevel);
barStyleStr.AppendPrintf(" width: %.2fpx;", sBarWidth / aZoomLevel);
ErrorResult rv;
SelectionBarElement()->SetAttribute(NS_LITERAL_STRING("style"), barStyleStr, rv);
@ -334,7 +339,7 @@ AccessibleCaret::GetZoomLevel()
// Full zoom on desktop.
float fullZoom = mPresShell->GetPresContext()->GetFullZoom();
// Pinch-zoom on B2G.
// Pinch-zoom on B2G or fennec.
float resolution = mPresShell->GetCumulativeResolution();
return fullZoom * resolution;

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

@ -104,7 +104,7 @@ public:
// Position is not changed.
NotChanged,
// Position is changed.
// Position or zoom level is changed.
Changed,
// Position is out of scroll port.
@ -138,8 +138,8 @@ public:
protected:
// Argument aRect should be relative to CustomContentContainerFrame().
void SetCaretElementStyle(const nsRect& aRect);
void SetSelectionBarElementStyle(const nsRect& aRect);
void SetCaretElementStyle(const nsRect& aRect, float aZoomLevel);
void SetSelectionBarElementStyle(const nsRect& aRect, float aZoomLevel);
// Get current zoom level.
float GetZoomLevel();
@ -210,6 +210,9 @@ protected:
// mImaginaryCaretRect is relative to root frame.
nsRect mImaginaryCaretRect;
// Cache current zoom level to determine whether position is changed.
float mZoomLevel = 0.0f;
// A no-op touch-start listener which prevents APZ from panning when dragging
// the caret.
RefPtr<DummyTouchListener> mDummyTouchListener{new DummyTouchListener()};