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 #748 from vingtetun/windowmanager
Browse files Browse the repository at this point in the history
Separe the WindowManager and the TaskManager
  • Loading branch information
vingtetun committed Mar 9, 2012
2 parents b1ade3e + fea200d commit 94bffc2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 87 deletions.
4 changes: 2 additions & 2 deletions apps/homescreen/js/homescreen.js
Expand Up @@ -767,7 +767,7 @@ var MessagesListener = function() {
window.addEventListener('appopen', function onAppOpen(evt) {
// If the sms application is opened, just delete all messages
// notifications
var applicationURL = evt.detail;
var applicationURL = evt.detail.url;
if (!/^\.\.\/sms\/sms\.html/.test(applicationURL))
return;

Expand Down Expand Up @@ -842,7 +842,7 @@ var TelephonyListener = function() {
window.addEventListener('appopen', function onAppOpen(evt) {
// If the dialer application is opened, just delete all messages
// notifications
var applicationURL = evt.detail;
var applicationURL = evt.detail.url;
if (!/^\.\.\/dialer\/dialer\.html/.test(applicationURL))
return;

Expand Down
51 changes: 42 additions & 9 deletions apps/homescreen/js/task_manager.js
Expand Up @@ -21,10 +21,15 @@ var TaskManager = {
this.container = document.getElementById('taskManager');
this.items = this.container.getElementsByTagName('ul')[0];

['keydown', 'keyup', 'locked', 'unlocked'].forEach((function attachKey(type) {
var events = ['locked', 'unlocked', 'appwillopen', 'appfocus',
'appwillclose'];
events.forEach((function attachKey(type) {
window.addEventListener(type, this);
}).bind(this));

window.addEventListener('keydown', this);
window.addEventListener('keyup', this);

// hiding the task manager when a call comes in
var telephony = navigator.mozTelephony;
if (telephony) {
Expand All @@ -36,36 +41,64 @@ var TaskManager = {

_timeout: 0,
handleEvent: function tm_handleEvent(evt) {
var detail = evt.detail;
switch (evt.type) {
case 'keydown':
if (!this.enabled || evt.keyCode !== evt.DOM_VK_HOME || this._timeout)
if (!this.enabled || this._timeout)
return;
this._cancelled = false;

if (this.isActive()) {
this.hide();
if (evt.keyCode !== evt.DOM_VK_HOME || this.isActive())
return;
}

this._timeout = window.setTimeout(function checkKeyPress(self) {
self._cancelled = true;
self.show();
}, 1000, this);
break;

case 'keyup':
if (evt.keyCode !== evt.DOM_VK_HOME)
return;
if (!this._timeout && !evt.defaultPrevented && this.isActive()) {
this.hide();
evt.preventDefault();
}

if (this._cancelled)
evt.preventDefault();

window.clearTimeout(this._timeout);
this._timeout = 0;
break;


case 'locked':
this.enabled = false;
break;

case 'unlocked':
this.enabled = true;
break;

case 'appwillopen':
this.add(detail, detail.id);
break;

case 'appfocus':
this.sendToFront(detail.id);
break;

case 'appclose':
if (!detail.hackKillMe)
return;

// waiting for the closing transition to end before removing
// the iframe from dom
var self = this;
var target = evt.target;
target.addEventListener('transitionend', function waitToKill() {
target.removeEventListener('transitionend', waitToKill);
self.remove(detail, detail.id);
});
break;
}
},

Expand Down Expand Up @@ -107,7 +140,7 @@ var TaskManager = {

WindowManager.kill(app.url);

if (this.items.children.length === 0)
if (this.items.children.length === 0)
this.hide();
},

Expand Down

0 comments on commit 94bffc2

Please sign in to comment.