Bug 1255555 - When a frame reconstruction triggers caret elements to be cloned, ensure the dummy touch listeners are re-registered on the clones. r=tylin

MozReview-Commit-ID: 8txWmd64LC9
This commit is contained in:
Kartikaya Gupta 2016-07-11 08:16:39 -04:00
parent 6968f9a027
commit e0f363fe61
5 changed files with 32 additions and 2 deletions

View File

@ -187,6 +187,18 @@ AccessibleCaret::Contains(const nsPoint& aPoint) const
return rect.Contains(aPoint);
}
void
AccessibleCaret::EnsureApzAware()
{
// If the caret element was cloned, the listener might have been lost. So
// if that's the case we register a dummy listener if there isn't one on
// the element already.
if (!CaretElement()->IsApzAware()) {
CaretElement()->AddEventListener(NS_LITERAL_STRING("touchstart"),
mDummyTouchListener, false);
}
}
void
AccessibleCaret::InjectCaretElement(nsIDocument* aDocument)
{
@ -200,8 +212,7 @@ AccessibleCaret::InjectCaretElement(nsIDocument* aDocument)
// InsertAnonymousContent will clone the element to make an AnonymousContent.
// Since event listeners are not being cloned when cloning a node, we need to
// add the listener here.
CaretElement()->AddEventListener(NS_LITERAL_STRING("touchstart"),
mDummyTouchListener, false);
EnsureApzAware();
}
already_AddRefed<Element>

View File

@ -136,6 +136,10 @@ public:
return mCaretElementHolder->GetContentNode();
}
// Ensures that the caret element is made "APZ aware" so that the APZ code
// doesn't scroll the page when the user is trying to drag the caret.
void EnsureApzAware();
protected:
// Argument aRect should be relative to CustomContentContainerFrame().
void SetCaretElementStyle(const nsRect& aRect, float aZoomLevel);

View File

@ -401,6 +401,10 @@ AccessibleCaretEventHub::~AccessibleCaretEventHub()
void
AccessibleCaretEventHub::Init()
{
if (mInitialized && mManager) {
mManager->OnFrameReconstruction();
}
if (mInitialized || !mPresShell || !mPresShell->GetCanvasFrame() ||
!mPresShell->GetCanvasFrame()->GetCustomContentContainer()) {
return;

View File

@ -697,6 +697,13 @@ AccessibleCaretManager::OnKeyboardEvent()
}
}
void
AccessibleCaretManager::OnFrameReconstruction()
{
mFirstCaret->EnsureApzAware();
mSecondCaret->EnsureApzAware();
}
Selection*
AccessibleCaretManager::GetSelection() const
{

View File

@ -98,6 +98,10 @@ public:
// Handle key event.
virtual void OnKeyboardEvent();
// The canvas frame holding the accessible caret anonymous content elements
// was reconstructed, resulting in the content elements getting cloned.
virtual void OnFrameReconstruction();
protected:
// This enum representing the number of AccessibleCarets on the screen.
enum class CaretMode : uint8_t {