Bug 1110039 - Part 4 - Hook new classes into the system. r=roc

The necessary modifications are the same as SelectionCarets. For
convenience, Touch/SelectionCarets will be disabled whenever
AccessibleCaret preference is enabled.
This commit is contained in:
Ting-Yu Lin 2015-04-24 02:08:00 +02:00
Родитель f7bd43c314
Коммит da5ef9e181
6 изменённых файлов: 99 добавлений и 2 удалений

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

@ -8,6 +8,7 @@
#include "nsFocusManager.h" #include "nsFocusManager.h"
#include "AccessibleCaretEventHub.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
@ -1694,6 +1695,11 @@ nsFocusManager::Blur(nsPIDOMWindow* aWindowToClear,
selectionCarets->NotifyBlur(aIsLeavingDocument || !mActiveWindow); selectionCarets->NotifyBlur(aIsLeavingDocument || !mActiveWindow);
} }
nsRefPtr<AccessibleCaretEventHub> eventHub = presShell->GetAccessibleCaretEventHub();
if (eventHub) {
eventHub->NotifyBlur(aIsLeavingDocument || !mActiveWindow);
}
// at this point, it is expected that this window will be still be // at this point, it is expected that this window will be still be
// focused, but the focused content will be null, as it was cleared before // focused, but the focused content will be null, as it was cleared before
// the event. If this isn't the case, then something else was focused during // the event. If this isn't the case, then something else was focused during

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

@ -59,6 +59,7 @@ class nsCanvasFrame;
class nsAString; class nsAString;
class nsCaret; class nsCaret;
namespace mozilla { namespace mozilla {
class AccessibleCaretEventHub;
class TouchCaret; class TouchCaret;
class SelectionCarets; class SelectionCarets;
} // namespace mozilla } // namespace mozilla
@ -808,6 +809,11 @@ public:
*/ */
virtual mozilla::dom::Element* GetSelectionCaretsEndElement() const = 0; virtual mozilla::dom::Element* GetSelectionCaretsEndElement() const = 0;
/**
* Get the AccessibleCaretEventHub, if it exists. AddRefs it.
*/
virtual already_AddRefed<mozilla::AccessibleCaretEventHub> GetAccessibleCaretEventHub() const = 0;
/** /**
* Get the caret, if it exists. AddRefs it. * Get the caret, if it exists. AddRefs it.
*/ */

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

@ -76,6 +76,7 @@
#include "nsIPermissionManager.h" #include "nsIPermissionManager.h"
#include "nsIMozBrowserFrame.h" #include "nsIMozBrowserFrame.h"
#include "nsCaret.h" #include "nsCaret.h"
#include "AccessibleCaretEventHub.h"
#include "TouchCaret.h" #include "TouchCaret.h"
#include "SelectionCarets.h" #include "SelectionCarets.h"
#include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLDocument.h"
@ -706,6 +707,7 @@ static uint32_t sNextPresShellId;
static bool sPointerEventEnabled = true; static bool sPointerEventEnabled = true;
static bool sTouchCaretEnabled = false; static bool sTouchCaretEnabled = false;
static bool sSelectionCaretEnabled = false; static bool sSelectionCaretEnabled = false;
static bool sAccessibleCaretEnabled = false;
static bool sBeforeAfterKeyboardEventEnabled = false; static bool sBeforeAfterKeyboardEventEnabled = false;
/* static */ bool /* static */ bool
@ -730,6 +732,17 @@ PresShell::SelectionCaretPrefEnabled()
return sSelectionCaretEnabled; return sSelectionCaretEnabled;
} }
/* static */ bool
PresShell::AccessibleCaretEnabled()
{
static bool initialized = false;
if (!initialized) {
Preferences::AddBoolVarCache(&sAccessibleCaretEnabled, "layout.accessiblecaret.enabled");
initialized = true;
}
return sAccessibleCaretEnabled;
}
/* static */ bool /* static */ bool
PresShell::BeforeAfterKeyboardEventEnabled() PresShell::BeforeAfterKeyboardEventEnabled()
{ {
@ -883,17 +896,21 @@ PresShell::Init(nsIDocument* aDocument,
// before creating any frames. // before creating any frames.
SetPreferenceStyleRules(false); SetPreferenceStyleRules(false);
if (TouchCaretPrefEnabled()) { if (TouchCaretPrefEnabled() && !AccessibleCaretEnabled()) {
// Create touch caret handle // Create touch caret handle
mTouchCaret = new TouchCaret(this); mTouchCaret = new TouchCaret(this);
} }
if (SelectionCaretPrefEnabled()) { if (SelectionCaretPrefEnabled() && !AccessibleCaretEnabled()) {
// Create selection caret handle // Create selection caret handle
mSelectionCarets = new SelectionCarets(this); mSelectionCarets = new SelectionCarets(this);
mSelectionCarets->Init(); mSelectionCarets->Init();
} }
if (AccessibleCaretEnabled()) {
// Need to happen before nsFrameSelection has been set up.
mAccessibleCaretEventHub = new AccessibleCaretEventHub();
}
mSelection = new nsFrameSelection(); mSelection = new nsFrameSelection();
@ -1163,6 +1180,11 @@ PresShell::Destroy()
mSelectionCarets = nullptr; mSelectionCarets = nullptr;
} }
if (mAccessibleCaretEventHub) {
mAccessibleCaretEventHub->Terminate();
mAccessibleCaretEventHub = nullptr;
}
// release our pref style sheet, if we have one still // release our pref style sheet, if we have one still
ClearPreferenceStyleRules(); ClearPreferenceStyleRules();
@ -1907,6 +1929,11 @@ PresShell::Initialize(nscoord aWidth, nscoord aHeight)
mFrameConstructor->EndUpdate(); mFrameConstructor->EndUpdate();
} }
// Initialize after nsCanvasFrame is created.
if (mAccessibleCaretEventHub) {
mAccessibleCaretEventHub->Init(this);
}
// nsAutoScriptBlocker going out of scope may have killed us too // nsAutoScriptBlocker going out of scope may have killed us too
NS_ENSURE_STATE(!mHaveShutDown); NS_ENSURE_STATE(!mHaveShutDown);
@ -2214,6 +2241,12 @@ already_AddRefed<SelectionCarets> PresShell::GetSelectionCarets() const
return selectionCaret.forget(); return selectionCaret.forget();
} }
already_AddRefed<AccessibleCaretEventHub> PresShell::GetAccessibleCaretEventHub() const
{
nsRefPtr<AccessibleCaretEventHub> eventHub = mAccessibleCaretEventHub;
return eventHub.forget();
}
void PresShell::SetCaret(nsCaret *aNewCaret) void PresShell::SetCaret(nsCaret *aNewCaret)
{ {
mCaret = aNewCaret; mCaret = aNewCaret;
@ -7253,6 +7286,28 @@ PresShell::HandleEvent(nsIFrame* aFrame,
} }
} }
if (AccessibleCaretEnabled()) {
// We have to target the focus window because regardless of where the
// touch goes, we want to access the copy paste manager.
nsCOMPtr<nsPIDOMWindow> window = GetFocusedDOMWindowInOurWindow();
nsCOMPtr<nsIDocument> retargetEventDoc =
window ? window->GetExtantDoc() : nullptr;
nsCOMPtr<nsIPresShell> presShell =
retargetEventDoc ? retargetEventDoc->GetShell() : nullptr;
nsRefPtr<AccessibleCaretEventHub> eventHub =
presShell ? presShell->GetAccessibleCaretEventHub() : nullptr;
if (eventHub) {
*aEventStatus = eventHub->HandleEvent(aEvent);
if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
// If the event is consumed, cancel APZC panning by setting
// mMultipleActionsPrevented.
aEvent->mFlags.mMultipleActionsPrevented = true;
return NS_OK;
}
}
}
if (sPointerEventEnabled) { if (sPointerEventEnabled) {
UpdateActivePointerState(aEvent); UpdateActivePointerState(aEvent);
} }

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

@ -77,6 +77,8 @@ public:
// Selection caret preference // Selection caret preference
static bool SelectionCaretPrefEnabled(); static bool SelectionCaretPrefEnabled();
static bool AccessibleCaretEnabled();
// BeforeAfterKeyboardEvent preference // BeforeAfterKeyboardEvent preference
static bool BeforeAfterKeyboardEventEnabled(); static bool BeforeAfterKeyboardEventEnabled();
@ -240,6 +242,9 @@ public:
virtual already_AddRefed<mozilla::SelectionCarets> GetSelectionCarets() const override; virtual already_AddRefed<mozilla::SelectionCarets> GetSelectionCarets() const override;
virtual mozilla::dom::Element* GetSelectionCaretsStartElement() const override; virtual mozilla::dom::Element* GetSelectionCaretsStartElement() const override;
virtual mozilla::dom::Element* GetSelectionCaretsEndElement() const override; virtual mozilla::dom::Element* GetSelectionCaretsEndElement() const override;
virtual already_AddRefed<mozilla::AccessibleCaretEventHub> GetAccessibleCaretEventHub() const override;
// caret handling // caret handling
virtual already_AddRefed<nsCaret> GetCaret() const override; virtual already_AddRefed<nsCaret> GetCaret() const override;
NS_IMETHOD SetCaretEnabled(bool aInEnable) override; NS_IMETHOD SetCaretEnabled(bool aInEnable) override;
@ -811,6 +816,7 @@ protected:
// TouchCaret // TouchCaret
nsRefPtr<mozilla::TouchCaret> mTouchCaret; nsRefPtr<mozilla::TouchCaret> mTouchCaret;
nsRefPtr<mozilla::SelectionCarets> mSelectionCarets; nsRefPtr<mozilla::SelectionCarets> mSelectionCarets;
nsRefPtr<mozilla::AccessibleCaretEventHub> mAccessibleCaretEventHub;
// This timer controls painting suppression. Until it fires // This timer controls painting suppression. Until it fires
// or all frames are constructed, we won't paint anything but // or all frames are constructed, we won't paint anything but

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

@ -54,6 +54,9 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
#include "TouchCaret.h" #include "TouchCaret.h"
#include "SelectionCarets.h" #include "SelectionCarets.h"
#include "AccessibleCaretEventHub.h"
#include "AccessibleCaretManager.h"
#include "mozilla/MouseEvents.h" #include "mozilla/MouseEvents.h"
#include "mozilla/TextEvents.h" #include "mozilla/TextEvents.h"
@ -819,6 +822,14 @@ nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
mDomSelections[index]->AddSelectionListener(selectionCarets); mDomSelections[index]->AddSelectionListener(selectionCarets);
} }
} }
nsRefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
if (eventHub) {
int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
if (mDomSelections[index]) {
mDomSelections[index]->AddSelectionListener(eventHub);
}
}
} }
nsresult nsresult
@ -3225,6 +3236,12 @@ nsFrameSelection::DisconnectFromPresShell()
mDomSelections[index]->RemoveSelectionListener(selectionCarets); mDomSelections[index]->RemoveSelectionListener(selectionCarets);
} }
nsRefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
if (eventHub) {
int8_t index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
mDomSelections[index]->RemoveSelectionListener(eventHub);
}
StopAutoScrollTimer(); StopAutoScrollTimer();
for (int32_t i = 0; i < nsISelectionController::NUM_SELECTIONTYPES; i++) { for (int32_t i = 0; i < nsISelectionController::NUM_SELECTIONTYPES; i++) {
mDomSelections[i]->Clear(nullptr); mDomSelections[i]->Clear(nullptr);

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

@ -4553,6 +4553,13 @@ pref("selectioncaret.inflatesize.threshold", 40);
// Selection carets will fall-back to internal LongTap detector. // Selection carets will fall-back to internal LongTap detector.
pref("selectioncaret.detects.longtap", true); pref("selectioncaret.detects.longtap", true);
// New implementation to unify touch-caret and selection-carets.
pref("layout.accessiblecaret.enabled", false);
// Timeout in milliseconds to hide the accessiblecaret under cursor mode while
// no one touches it. Set the value to 0 to disable this feature.
pref("layout.accessiblecaret.timeout_ms", 3000);
// Wakelock is disabled by default. // Wakelock is disabled by default.
pref("dom.wakelock.enabled", false); pref("dom.wakelock.enabled", false);