mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1215959
- (GeckoCaret2) Upgrade mobile-side for new AccessibleCaret front-end, r=snorp
This commit is contained in:
parent
2ef78c023e
commit
09b32da6ac
@ -4,14 +4,6 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
// Notifications we observe.
|
||||
const NOTIFICATIONS = [
|
||||
"ActionBar:UpdateState",
|
||||
"TextSelection:Action",
|
||||
"TextSelection:End",
|
||||
];
|
||||
|
||||
const DEFER_INIT_DELAY_MS = 50; // Delay period before _init() begins.
|
||||
const PHONE_REGEX = /^\+?[0-9\s,-.\(\)*#pw]{1,30}$/; // Are we a phone #?
|
||||
|
||||
|
||||
@ -26,39 +18,52 @@ var ActionBarHandler = {
|
||||
NONE: "",
|
||||
},
|
||||
|
||||
_nextSelectionID: 1, // Next available.
|
||||
_selectionID: null, // Unique Selection ID, assigned each time we _init().
|
||||
_actionBarActions: null, // Most-recent set of actions sent to ActionBar.
|
||||
|
||||
/**
|
||||
* Receive and act on AccessibleCarets caret state-change
|
||||
* (mozcaretstatechanged) events.
|
||||
*/
|
||||
caretStateChangedHandler: function(e) {
|
||||
// Close an open ActionBar, if carets no longer logically visible.
|
||||
if (this._selectionID && !e.caretVisible) {
|
||||
this._uninit(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Open a closed ActionBar if carets actually visible.
|
||||
if (!this._selectionID && e.caretVisuallyVisible) {
|
||||
this._init();
|
||||
return;
|
||||
}
|
||||
|
||||
// Else, update an open ActionBar.
|
||||
if (this._selectionID) {
|
||||
if ([this._targetElement, this._contentWindow] ===
|
||||
[Services.focus.focusedElement, Services.focus.focusedWindow]) {
|
||||
// We have the same focused window/element as before. Trigger "TextSelection:ActionbarStatus"
|
||||
// message only if available actions differ from when last we checked.
|
||||
this._sendActionBarActions();
|
||||
} else {
|
||||
// We have a new focused window/element pair.
|
||||
this._uninit(false);
|
||||
this._init();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* ActionBarHandler notification observers.
|
||||
*/
|
||||
observe: function(subject, topic, data) {
|
||||
switch (topic) {
|
||||
|
||||
// Gecko opens the ActionBarHandler.
|
||||
case "ActionBar:OpenNew": {
|
||||
// Always close, then re-open.
|
||||
this._uninit(false);
|
||||
this._init(data);
|
||||
break;
|
||||
}
|
||||
|
||||
// Gecko closes the ActionBarHandler.
|
||||
case "ActionBar:Close": {
|
||||
if (this._selectionID === data) {
|
||||
this._uninit(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Update ActionBar when text selection changes.
|
||||
case "ActionBar:UpdateState": {
|
||||
this._sendActionBarActions();
|
||||
break;
|
||||
}
|
||||
|
||||
// User click an ActionBar button.
|
||||
case "TextSelection:Action": {
|
||||
if (!this._selectionID) {
|
||||
break;
|
||||
}
|
||||
for (let type in this.actions) {
|
||||
let action = this.actions[type];
|
||||
if (action.id == data) {
|
||||
@ -76,13 +81,15 @@ var ActionBarHandler = {
|
||||
requestId: data,
|
||||
text: this._getSelectedText(),
|
||||
});
|
||||
|
||||
this._uninit();
|
||||
break;
|
||||
}
|
||||
|
||||
// User closed ActionBar by clicking "checkmark" button.
|
||||
case "TextSelection:End": {
|
||||
// End the requested selection only.
|
||||
if (this._selectionID === JSON.parse(data).selectionID) {
|
||||
if (this._selectionID == JSON.parse(data).selectionID) {
|
||||
this._uninit();
|
||||
}
|
||||
break;
|
||||
@ -93,22 +100,17 @@ var ActionBarHandler = {
|
||||
/**
|
||||
* Called when Gecko TouchCaret or SelectionCarets become visible.
|
||||
*/
|
||||
_init: function(actionBarID) {
|
||||
_init: function() {
|
||||
let [element, win] = this._getSelectionTargets();
|
||||
if (!win) {
|
||||
return this.START_TOUCH_ERROR.NO_CONTENT_WINDOW;
|
||||
}
|
||||
|
||||
// Hold the ActionBar ID provided by Gecko.
|
||||
this._selectionID = actionBarID;
|
||||
this._selectionID = this._nextSelectionID++;
|
||||
[this._targetElement, this._contentWindow] = [element, win];
|
||||
|
||||
// Add notification observers.
|
||||
NOTIFICATIONS.forEach(notification => {
|
||||
Services.obs.addObserver(this, notification, false);
|
||||
});
|
||||
|
||||
// Open the ActionBar, send it's initial actions list.
|
||||
// Open the ActionBar, send it's actions list.
|
||||
Messaging.sendRequest({
|
||||
type: "TextSelection:ActionbarInit",
|
||||
selectionID: this._selectionID,
|
||||
@ -151,11 +153,6 @@ var ActionBarHandler = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove notification observers.
|
||||
NOTIFICATIONS.forEach(notification => {
|
||||
Services.obs.removeObserver(this, notification);
|
||||
});
|
||||
|
||||
// Close the ActionBar.
|
||||
Messaging.sendRequest({
|
||||
type: "TextSelection:ActionbarUninit",
|
||||
@ -291,9 +288,6 @@ var ActionBarHandler = {
|
||||
|
||||
// Close ActionBarHandler, then selectAll, and display handles.
|
||||
ActionBarHandler._getSelectAllController(element, win).selectAll();
|
||||
ActionBarHandler._getSelectionController(element, win).
|
||||
selectionCaretsVisibility = true;
|
||||
|
||||
UITelemetry.addEvent("action.1", "actionbar", null, "select_all");
|
||||
},
|
||||
},
|
||||
|
@ -8,9 +8,8 @@
|
||||
const PHONE_NUMBER_CONTAINERS = "td,div";
|
||||
const DEFER_CLOSE_TRIGGER_MS = 125; // Grace period delay before deferred _closeSelection()
|
||||
|
||||
// Gecko TouchCaret/SelectionCaret pref names.
|
||||
const PREF_GECKO_TOUCHCARET_ENABLED = "touchcaret.enabled";
|
||||
const PREF_GECKO_SELECTIONCARETS_ENABLED = "selectioncaret.enabled";
|
||||
// Gecko AccessibleCaret pref names.
|
||||
const PREF_GECKO_ACCESSIBLECARET_ENABLED = "layout.accessiblecaret.enabled";
|
||||
|
||||
var SelectionHandler = {
|
||||
|
||||
@ -43,7 +42,7 @@ var SelectionHandler = {
|
||||
SELECT_AT_POINT: 1,
|
||||
|
||||
// Gecko TouchCaret/SelectionCaret pref values.
|
||||
_touchCaretEnabledValue: null,
|
||||
_accessibleCaretEnabledValue: null,
|
||||
_selectionCaretEnabledValue: null,
|
||||
|
||||
// Keeps track of data about the dimensions of the selection. Coordinates
|
||||
@ -101,28 +100,18 @@ var SelectionHandler = {
|
||||
getService(Ci.nsIUUIDGenerator);
|
||||
},
|
||||
|
||||
// Are we supporting Gecko or Native touchCarets?
|
||||
get _touchCaretEnabled() {
|
||||
if (this._touchCaretEnabledValue == null) {
|
||||
this._touchCaretEnabledValue = Services.prefs.getBoolPref(PREF_GECKO_TOUCHCARET_ENABLED);
|
||||
Services.prefs.addObserver(PREF_GECKO_TOUCHCARET_ENABLED, function() {
|
||||
SelectionHandler._touchCaretEnabledValue =
|
||||
Services.prefs.getBoolPref(PREF_GECKO_TOUCHCARET_ENABLED);
|
||||
// Are we supporting Accessible-core or native-Java carets?
|
||||
get _accessibleCaretEnabled() {
|
||||
if (this._accessibleCaretEnabledValue == null) {
|
||||
try {
|
||||
this._accessibleCaretEnabledValue = Services.prefs.getBoolPref(PREF_GECKO_ACCESSIBLECARET_ENABLED);
|
||||
} catch (unused) { }
|
||||
Services.prefs.addObserver(PREF_GECKO_ACCESSIBLECARET_ENABLED, function() {
|
||||
SelectionHandler._accessibleCaretEnabledValue =
|
||||
Services.prefs.getBoolPref(PREF_GECKO_ACCESSIBLECARET_ENABLED);
|
||||
}, false);
|
||||
}
|
||||
return this._touchCaretEnabledValue;
|
||||
},
|
||||
|
||||
// Are we supporting Gecko or Native selectionCarets?
|
||||
get _selectionCaretEnabled() {
|
||||
if (this._selectionCaretEnabledValue == null) {
|
||||
this._selectionCaretEnabledValue = Services.prefs.getBoolPref(PREF_GECKO_SELECTIONCARETS_ENABLED);
|
||||
Services.prefs.addObserver(PREF_GECKO_SELECTIONCARETS_ENABLED, function() {
|
||||
SelectionHandler._selectionCaretEnabledValue =
|
||||
Services.prefs.getBoolPref(PREF_GECKO_SELECTIONCARETS_ENABLED);
|
||||
}, false);
|
||||
}
|
||||
return this._selectionCaretEnabledValue;
|
||||
return this._accessibleCaretEnabledValue;
|
||||
},
|
||||
|
||||
_addObservers: function sh_addObservers() {
|
||||
@ -412,8 +401,8 @@ var SelectionHandler = {
|
||||
* y - The y-coordinate for SELECT_AT_POINT.
|
||||
*/
|
||||
startSelection: function sh_startSelection(aElement, aOptions = { mode: SelectionHandler.SELECT_ALL }) {
|
||||
// Disable Native touchCarets if Gecko enabled.
|
||||
if (this._selectionCaretEnabled) {
|
||||
// Disable Native touchCarets if Gecko AccessibleCaret enabled.
|
||||
if (this._accessibleCaretEnabled) {
|
||||
return this.START_ERROR_SELECTIONCARETS_ENABLED;
|
||||
}
|
||||
|
||||
@ -876,8 +865,8 @@ var SelectionHandler = {
|
||||
* @param aX, aY tap location in client coordinates.
|
||||
*/
|
||||
attachCaret: function sh_attachCaret(aElement) {
|
||||
// Disable Native attachCaret() if Gecko touchCarets are enabled.
|
||||
if (this._touchCaretEnabled) {
|
||||
// Disable Native touchCarets if Gecko AccessibleCaret enabled.
|
||||
if (this._accessibleCaretEnabled) {
|
||||
return this.ATTACH_ERROR_TOUCHCARET_ENABLED;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ var lazilyLoadedObserverScripts = [
|
||||
];
|
||||
if (AppConstants.NIGHTLY_BUILD) {
|
||||
lazilyLoadedObserverScripts.push(
|
||||
["ActionBarHandler", ["ActionBar:OpenNew", "ActionBar:Close", "TextSelection:Get"],
|
||||
["ActionBarHandler", ["TextSelection:Get", "TextSelection:Action", "TextSelection:End"],
|
||||
"chrome://browser/content/ActionBarHandler.js"]
|
||||
);
|
||||
}
|
||||
@ -615,6 +615,13 @@ var BrowserApp = {
|
||||
InitLater(() => LoginManagerParent.init(), window, "LoginManagerParent");
|
||||
|
||||
}, false);
|
||||
|
||||
// Pass caret StateChanged events to ActionBarHandler.
|
||||
if (AppConstants.NIGHTLY_BUILD) {
|
||||
window.addEventListener("mozcaretstatechanged", e => {
|
||||
ActionBarHandler.caretStateChangedHandler(e);
|
||||
}, /* useCapture = */ true, /* wantsUntrusted = */ false);
|
||||
}
|
||||
},
|
||||
|
||||
get _startupStatus() {
|
||||
|
Loading…
Reference in New Issue
Block a user