Bug 988143 - Enable Gecko Touch in Fennec, SelectionCarets mods, r=ehsan

* * *
Bug 988143 - Enable Gecko Touch in Fennec, Add new Mobile prefs, r=ehsan
This commit is contained in:
Mark Capella 2015-05-14 22:06:13 -04:00
parent e9bbe4196e
commit 20c2759bed
4 changed files with 76 additions and 7 deletions

View File

@ -66,6 +66,8 @@ NS_IMPL_ISUPPORTS(SelectionCarets,
/*static*/ int32_t SelectionCarets::sSelectionCaretsInflateSize = 0;
/*static*/ bool SelectionCarets::sSelectionCaretDetectsLongTap = true;
/*static*/ bool SelectionCarets::sCaretManagesAndroidActionbar = false;
/*static*/ bool SelectionCarets::sSelectionCaretObservesCompositions = false;
SelectionCarets::SelectionCarets(nsIPresShell* aPresShell)
: mPresShell(aPresShell)
@ -78,6 +80,7 @@ SelectionCarets::SelectionCarets(nsIPresShell* aPresShell)
, mStartCaretVisible(false)
, mSelectionVisibleInScrollFrames(true)
, mVisible(false)
, mActionBarViewID(0)
{
MOZ_ASSERT(NS_IsMainThread());
@ -93,6 +96,10 @@ SelectionCarets::SelectionCarets(nsIPresShell* aPresShell)
"selectioncaret.inflatesize.threshold");
Preferences::AddBoolVarCache(&sSelectionCaretDetectsLongTap,
"selectioncaret.detects.longtap", true);
Preferences::AddBoolVarCache(&sCaretManagesAndroidActionbar,
"caret.manages-android-actionbar");
Preferences::AddBoolVarCache(&sSelectionCaretObservesCompositions,
"selectioncaret.observes.compositions");
addedPref = true;
}
}
@ -318,6 +325,11 @@ SelectionCarets::SetVisibility(bool aVisible)
dom::Element* endElement = mPresShell->GetSelectionCaretsEndElement();
SetElementVisibility(endElement, mVisible && mEndCaretVisible);
// Update the Android Actionbar visibility if in use.
if (sCaretManagesAndroidActionbar) {
TouchCaret::UpdateAndroidActionBarVisibility(mVisible, mActionBarViewID);
}
}
void
@ -1125,12 +1137,46 @@ SelectionCarets::NotifySelectionChanged(nsIDOMDocument* aDoc,
return NS_OK;
}
if (!aReason || (aReason & (nsISelectionListener::DRAG_REASON |
nsISelectionListener::KEYPRESS_REASON |
nsISelectionListener::MOUSEDOWN_REASON))) {
SetVisibility(false);
// Update SelectionCaret visibility.
if (sSelectionCaretObservesCompositions) {
// When observing selection change notifications generated for example
// by Android soft-keyboard compositions, we can only obtain visibility
// after mouse-up by long-tap, or final caret-drag.
if (!mVisible) {
if (aReason & nsISelectionListener::MOUSEUP_REASON) {
UpdateSelectionCarets();
}
} else {
// If already visible, we hide immediately for some known
// event-reasons: drag, keypress, or mouse down.
if (aReason & (nsISelectionListener::DRAG_REASON |
nsISelectionListener::KEYPRESS_REASON |
nsISelectionListener::MOUSEDOWN_REASON)) {
SetVisibility(false);
} else {
// Else we look further at the selection status, as currently
// style-composition changes don't provide reason codes.
UpdateSelectionCarets();
}
}
} else {
UpdateSelectionCarets();
// Default logic, mainly employed by b2g, isn't aware of soft-keyboard
// selection change compositions.
if (!aReason || (aReason & (nsISelectionListener::DRAG_REASON |
nsISelectionListener::KEYPRESS_REASON |
nsISelectionListener::MOUSEDOWN_REASON))) {
SetVisibility(false);
} else {
UpdateSelectionCarets();
}
}
// Maybe trigger Android ActionBar updates.
if (mVisible && sCaretManagesAndroidActionbar) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->NotifyObservers(nullptr, "ActionBar:UpdateState", nullptr);
}
}
DispatchSelectionStateChangedEvent(static_cast<Selection*>(aSel),
@ -1162,7 +1208,10 @@ SelectionCarets::AsyncPanZoomStarted()
{
if (mVisible) {
mInAsyncPanZoomGesture = true;
SetVisibility(false);
// Hide selection carets if not using ActionBar.
if (!sCaretManagesAndroidActionbar) {
SetVisibility(false);
}
SELECTIONCARETS_LOG("Dispatch scroll started");
DispatchScrollViewChangeEvent(mPresShell, dom::ScrollState::Started);
@ -1198,7 +1247,11 @@ SelectionCarets::ScrollPositionChanged()
{
if (mVisible) {
if (!mUseAsyncPanZoom) {
SetVisibility(false);
// Hide selection carets if not using ActionBar.
if (!sCaretManagesAndroidActionbar) {
SetVisibility(false);
}
//TODO: handling scrolling for selection bubble when APZ is off
// Dispatch event to notify gaia to hide selection bubble.
// Positions will be updated when scroll is end, so no need to calculate

View File

@ -267,6 +267,11 @@ private:
// Preference
static int32_t sSelectionCaretsInflateSize;
static bool sSelectionCaretDetectsLongTap;
static bool sCaretManagesAndroidActionbar;
static bool sSelectionCaretObservesCompositions;
// Unique ID of current Mobile ActionBar view.
uint32_t mActionBarViewID;
};
} // namespace mozilla

View File

@ -877,12 +877,19 @@ pref("browser.readinglist.enabled", true);
// Whether to use the unified telemetry behavior, requires a restart.
pref("toolkit.telemetry.unified", false);
// Turn off selection caret by default
pref("selectioncaret.enabled", false);
// Selection carets never fall-back to internal LongTap detector.
pref("selectioncaret.detects.longtap", false);
// Selection carets override caret visibility.
pref("selectioncaret.visibility.affectscaret", true);
// Selection caret visibility observes composition
// selections generated by soft keyboard managers.
pref("selectioncaret.observes.compositions", true);
// Turn off touch caret by default.
pref("touchcaret.enabled", false);

View File

@ -4563,6 +4563,10 @@ pref("selectioncaret.detects.longtap", true);
// Selection carets do not affect caret visibility.
pref("selectioncaret.visibility.affectscaret", false);
// Selection caret visibility does not observe composition
// selections generated by soft keyboard managers.
pref("selectioncaret.observes.compositions", false);
// The Touch caret by default observes the b2g visibility rules, and
// not the extended Android visibility rules that allow for touchcaret
// display in empty editable fields, for example.