Bug 1094072 - Update selection carets after reflow. r=roc

Let SelectionCarets inherits from nsIReflowObserver so it could refresh
its position after reflow. This fixes the incorrect position of
selection carets after we rotate the device to change the screen from
portrait mode to landscape mode and vice versa.
This commit is contained in:
Ting-Yu Lin 2014-11-05 21:18:00 +01:00
Родитель ab5bc2240d
Коммит 189652787e
3 изменённых файлов: 53 добавлений и 5 удалений

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

@ -71,6 +71,7 @@ static const int32_t kScrollEndTimerDelay = 300;
static bool kSupportNonEditableFields = false;
NS_IMPL_ISUPPORTS(SelectionCarets,
nsIReflowObserver,
nsISelectionListener,
nsIScrollObserver,
nsISupportsWeakReference)
@ -107,6 +108,20 @@ SelectionCarets::SelectionCarets(nsIPresShell* aPresShell)
}
}
void
SelectionCarets::Init()
{
nsPresContext* presContext = mPresShell->GetPresContext();
MOZ_ASSERT(presContext, "PresContext should be given in PresShell::Init()");
nsIDocShell* docShell = presContext->GetDocShell();
if (!docShell) {
return;
}
docShell->AddWeakReflowObserver(this);
}
SelectionCarets::~SelectionCarets()
{
SELECTIONCARETS_LOG("Destructor");
@ -125,6 +140,20 @@ SelectionCarets::~SelectionCarets()
mPresShell = nullptr;
}
void
SelectionCarets::Terminate()
{
nsPresContext* presContext = mPresShell->GetPresContext();
MOZ_ASSERT(presContext, "PresContext should be given in PresShell::Init()");
nsIDocShell* docShell = presContext->GetDocShell();
if (docShell) {
docShell->RemoveWeakReflowObserver(this);
}
mPresShell = nullptr;
}
nsEventStatus
SelectionCarets::HandleEvent(WidgetEvent* aEvent)
{
@ -1090,3 +1119,20 @@ SelectionCarets::FireScrollEnd(nsITimer* aTimer, void* aSelectionCarets)
self->SetVisibility(true);
self->UpdateSelectionCarets();
}
NS_IMETHODIMP
SelectionCarets::Reflow(DOMHighResTimeStamp aStart, DOMHighResTimeStamp aEnd)
{
if (mVisible) {
SELECTIONCARETS_LOG("Update selection carets after reflow!");
UpdateSelectionCarets();
}
return NS_OK;
}
NS_IMETHODIMP
SelectionCarets::ReflowInterruptible(DOMHighResTimeStamp aStart,
DOMHighResTimeStamp aEnd)
{
return Reflow(aStart, aEnd);
}

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

@ -7,6 +7,7 @@
#ifndef SelectionCarets_h__
#define SelectionCarets_h__
#include "nsIReflowObserver.h"
#include "nsIScrollObserver.h"
#include "nsISelectionListener.h"
#include "nsWeakPtr.h"
@ -48,7 +49,8 @@ class Selection;
* UX spec, when selection contains only one characters, the image of
* caret becomes tilt.
*/
class SelectionCarets MOZ_FINAL : public nsISelectionListener,
class SelectionCarets MOZ_FINAL : public nsIReflowObserver,
public nsISelectionListener,
public nsIScrollObserver,
public nsSupportsWeakReference
{
@ -65,6 +67,7 @@ public:
explicit SelectionCarets(nsIPresShell *aPresShell);
NS_DECL_ISUPPORTS
NS_DECL_NSIREFLOWOBSERVER
NS_DECL_NSISELECTIONLISTENER
// nsIScrollObserver
@ -74,10 +77,8 @@ public:
virtual void AsyncPanZoomStarted(const mozilla::CSSIntPoint aScrollPos) MOZ_OVERRIDE;
virtual void AsyncPanZoomStopped(const mozilla::CSSIntPoint aScrollPos) MOZ_OVERRIDE;
void Terminate()
{
mPresShell = nullptr;
}
void Init();
void Terminate();
nsEventStatus HandleEvent(WidgetEvent* aEvent);

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

@ -903,6 +903,7 @@ PresShell::Init(nsIDocument* aDocument,
if (SelectionCaretPrefEnabled()) {
// Create selection caret handle
mSelectionCarets = new SelectionCarets(this);
mSelectionCarets->Init();
}