Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25989 from alivedise/bugzilla/1096133/home-event-…
Browse files Browse the repository at this point in the history
…dispatcher

Bug 1096133 - Get rid of stopImmediatePropagation, r=etienne
  • Loading branch information
alivedise committed Nov 26, 2014
2 parents 99d24c8 + 9b6e751 commit eca5c04
Show file tree
Hide file tree
Showing 30 changed files with 871 additions and 392 deletions.
2 changes: 1 addition & 1 deletion apps/system/js/app_window_factory.js
Expand Up @@ -170,7 +170,7 @@
return;
}
if (config.isActivity && config.inline) {
this.publish('launchactivity', config, document.body);
this.publish('launchactivity', config);
return;
}

Expand Down
124 changes: 74 additions & 50 deletions apps/system/js/app_window_manager.js
@@ -1,5 +1,6 @@
/* global SettingsListener, homescreenWindowManager, inputWindowManager,
layoutManager, Service, NfcHandler, rocketbar, ShrinkingUI */
layoutManager, Service, NfcHandler, rocketbar, ShrinkingUI,
FtuLauncher */
'use strict';

(function(exports) {
Expand Down Expand Up @@ -33,7 +34,7 @@
screen: document.getElementById('screen'),

isActive: function() {
return !!this._activeApp;
return (!!this._activeApp && this._activeApp.isActive());
},

setHierarchy: function(active) {
Expand Down Expand Up @@ -299,15 +300,14 @@
* @memberOf module:AppWindowManager
*/
start: function awm_start() {
this.activated = false;
if (this.slowTransition) {
this.element.classList.add('slow-transition');
} else {
this.element.classList.remove('slow-transition');
}
window.addEventListener('cardviewbeforeshow', this);
window.addEventListener('launchapp', this);
document.body.addEventListener('launchactivity', this, true);
window.addEventListener('home', this);
window.addEventListener('appcreated', this);
window.addEventListener('appterminated', this);
window.addEventListener('ftuskip', this);
Expand Down Expand Up @@ -335,7 +335,6 @@
window.addEventListener('attentionopened', this);
window.addEventListener('homegesture-enabled', this);
window.addEventListener('homegesture-disabled', this);
window.addEventListener('system-resize', this);
window.addEventListener('orientationchange', this);
window.addEventListener('sheets-gesture-begin', this);
window.addEventListener('sheets-gesture-end', this);
Expand All @@ -344,8 +343,7 @@
window.addEventListener('permissiondialoghide', this);
window.addEventListener('appopening', this);
window.addEventListener('localized', this);

window.addEventListener('mozChromeEvent', this);
window.addEventListener('taskmanager-activated', this);

this._settingsObserveHandler = {
// continuous transition controlling
Expand Down Expand Up @@ -402,7 +400,6 @@
*/
stop: function awm_stop() {
window.removeEventListener('launchapp', this);
window.removeEventListener('home', this);
window.removeEventListener('appcreated', this);
window.removeEventListener('appterminated', this);
window.removeEventListener('ftuskip', this);
Expand All @@ -423,16 +420,15 @@
window.removeEventListener('attentionopened', this);
window.removeEventListener('homegesture-enabled', this);
window.removeEventListener('homegesture-disabled', this);
window.removeEventListener('system-resize', this);
window.removeEventListener('orientationchange', this);
window.removeEventListener('sheets-gesture-begin', this);
window.removeEventListener('sheets-gesture-end', this);
window.removeEventListener('permissiondialoghide', this);
window.removeEventListener('appopening', this);
window.removeEventListener('localized', this);
window.removeEventListener('mozChromeEvent', this);
window.removeEventListener('shrinking-start', this);
window.removeEventListener('shrinking-stop', this);
window.removeEventListener('taskmanager-activated', this);

for (var name in this._settingsObserveHandler) {
SettingsListener.unobserve(
Expand All @@ -445,6 +441,44 @@
Service.request('unregisterHierarchy', this);
},

'_handle_system-resize': function() {
if (this._activeApp) {
this.debug(' Resizing ' + this._activeApp.name);
if (!this._activeApp.isTransitioning()) {
this._activeApp.resize();
return false;
}
}
return true;
},

_handle_home: function(evt) {
// XXX: FtuLauncher should become submodule of AppWindowManager.
if (FtuLauncher.respondToHierarchyEvent(evt)) {
if (!homescreenWindowManager.ready ||
(window.taskManager && window.taskManager.isActive())) {
return true;
}
this.display(null, null, null, 'home');
return false;
} else {
return false;
}
},

_handle_holdhome: function(evt) {
// XXX: FtuLauncher should become submodule of AppWindowManager.
var ret = FtuLauncher.respondToHierarchyEvent(evt);
return ret;
},

respondToHierarchyEvent: function(evt) {
if (this['_handle_' + evt.type]) {
return this['_handle_' + evt.type](evt);
}
return true;
},

handleEvent: function awm_handleEvent(evt) {
this.debug('handling ' + evt.type);
var activeApp = this._activeApp;
Expand Down Expand Up @@ -475,15 +509,6 @@
case 'orientationchange':
this.broadcastMessage(evt.type);
break;
case 'system-resize':
this.debug(' Resizing...');
if (activeApp) {
this.debug(' Resizing ' + activeApp.name);
if (!activeApp.isTransitioning()) {
activeApp.resize();
}
}
break;

// Dispatch internal events for navigation usage.
// The active app's navigation needs to know homes gesture is
Expand Down Expand Up @@ -595,32 +620,12 @@
}
break;

// If the lockscreen is active, it will stop propagation on this event
// and we'll never see it here. Similarly, other overlays may use this
// event to hide themselves and may prevent the event from getting here.
// Note that for this to work, the lockscreen and other overlays must
// be included in index.html before this one, so they can register their
// event handlers before we do.
case 'home':
if (!homescreenWindowManager.ready ||
(window.taskManager && window.taskManager.isActive())) {
return;
}
this.display(null, null, null, 'home');
break;

case 'launchapp':
var config = evt.detail;
this.debug('launching' + config.origin);
this.launch(config);
break;

case 'launchactivity':
if (evt.detail.isActivity && evt.detail.inline) {
this.launchActivity(evt);
}
break;

case 'cardviewbeforeshow':
if (this._activeApp) {
this._activeApp.getTopMostWindow().blur();
Expand Down Expand Up @@ -651,23 +656,32 @@
this.broadcastMessage('localized');
break;

case 'mozChromeEvent':
if (!activeApp || !evt.detail ||
evt.detail.type !== 'inputmethod-contextchange') {
return;
}
activeApp.getTopMostWindow().broadcast('inputmethod-contextchange',
evt.detail);
case 'taskmanager-activated':
this.activated = false;
this.publish(this.EVENT_PREFIX + '-deactivated');
break;
}
},

launchActivity: function(evt) {
// We don't know who is the opener,
// delegate the request to the active window.
if (this._activeApp) {
_handle_launchactivity: function(evt) {
if (evt.detail.isActivity && evt.detail.inline && this._activeApp) {
this._activeApp.broadcast('launchactivity', evt.detail);
return false;
}
return true;
},

'_handle_mozChromeEvent': function(evt) {
if (!evt.detail || evt.detail.type !== 'inputmethod-contextchange') {
return true;
}
if (this._activeApp) {
this._activeApp.getTopMostWindow()
.broadcast('inputmethod-contextchange',
evt.detail);
return false;
}
return true;
},

_dumpAllWindows: function() {
Expand Down Expand Up @@ -794,6 +808,13 @@

_updateActiveApp: function awm__changeActiveApp(instanceID) {
var appHasChanged = (this._activeApp !== this._apps[instanceID]);
this.debug(appHasChanged, this.activated, this._activeApp);
var activated = false;
if (!this.activated && appHasChanged && !this._activeApp) {
activated = true;
} else if (!appHasChanged && this._activeApp && !this.activated) {
activated = true;
}

this._activeApp = this._apps[instanceID];
if (!this._activeApp) {
Expand All @@ -819,6 +840,9 @@

this.debug('=== Active app now is: ',
(this._activeApp.name || this._activeApp.origin), '===');
if (activated) {
this.publish(this.EVENT_PREFIX + '-activated');
}
},

/**
Expand Down
69 changes: 40 additions & 29 deletions apps/system/js/attention_window_manager.js
Expand Up @@ -44,6 +44,46 @@
return this._topMostWindow;
},

respondToHierarchyEvent: function(evt) {
if (this['_handle_' + evt.type]) {
return this['_handle_' + evt.type](evt);
} else {
return true;
}
},

_handle_home: function(evt) {
if (!this.hasActiveWindow()) {
return true;
}
this._topMostWindow = null;
var nextApp = homescreenLauncher.getHomescreen();
if (Service.locked) {
this.closeAllAttentionWindows();
} else if (nextApp && !nextApp.isDead()) {
nextApp.ready(this.closeAllAttentionWindows.bind(this));
} else {
this.closeAllAttentionWindows();
}
return true;
},

'_handle_system-resize': function() {
if (this._topMostWindow) {
this._topMostWindow.resize();
return false;
}
return true;
},

_handle_holdhome: function() {
if (this.isActive()) {
this._topMostWindow = null;
this.closeAllAttentionWindows();
}
return true;
},

/**
* Return current alive attention window instances in a map.
* @return {Map} The attention window map
Expand All @@ -66,11 +106,8 @@
window.addEventListener('attentionclosing', this);
window.addEventListener('attentionrequestopen', this);
window.addEventListener('attentionrequestclose', this);
window.addEventListener('home', this);
window.addEventListener('holdhome', this);
window.addEventListener('emergencyalert', this);
window.addEventListener('launchapp', this);
window.addEventListener('system-resize', this);
window.addEventListener('lockscreen-appclosed', this);
window.addEventListener('lockscreen-appopened', this);
window.addEventListener('rocketbar-overlayopened', this);
Expand All @@ -89,11 +126,8 @@
window.removeEventListener('attentionclosing', this);
window.removeEventListener('attentionrequestopen', this);
window.removeEventListener('attentionrequestclose', this);
window.removeEventListener('home', this);
window.removeEventListener('holdhome', this);
window.removeEventListener('emergencyalert', this);
window.removeEventListener('launchapp', this);
window.removeEventListener('system-resize', this);
window.removeEventListener('lockscreen-appclosed', this);
window.removeEventListener('lockscreen-appopened', this);
window.removeEventListener('rocketbar-overlayopened', this);
Expand Down Expand Up @@ -210,39 +244,16 @@
this.updateClassState();
break;

case 'home':
if (!this.hasActiveWindow()) {
return;
}
this._topMostWindow = null;
var nextApp = homescreenLauncher.getHomescreen();
if (Service.locked) {
this.closeAllAttentionWindows();
} else if (nextApp && !nextApp.isDead()) {
nextApp.ready(this.closeAllAttentionWindows.bind(this));
} else {
this.closeAllAttentionWindows();
}
break;

case 'launchapp':
if (evt.detail && evt.detail.stayBackground) {
break;
} // jshint ignore:line
case 'holdhome':
case 'emergencyalert':
case 'rocketbar-overlayopened':
this._topMostWindow = null;
this.closeAllAttentionWindows();
break;

case 'system-resize':
if (this._topMostWindow) {
this._topMostWindow.resize();
evt.stopImmediatePropagation();
}
break;

case 'lockscreen-appclosed':
case 'lockscreen-appopened':
this._instances.forEach(function(instance) {
Expand Down
2 changes: 0 additions & 2 deletions apps/system/js/bootstrap.js
Expand Up @@ -75,8 +75,6 @@ window.addEventListener('load', function startup() {
window.lockScreenWindowManager = new window.LockScreenWindowManager();
window.lockScreenWindowManager.start();

// Let systemDialogManager handle inputmethod-contextchange event before
// starting appWindowManager. See bug 1082741.
window.appWindowManager.start();

/** @global */
Expand Down

0 comments on commit eca5c04

Please sign in to comment.