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 #21444 from alivedise/bugzilla/1027401_v2.1/reset-…
Browse files Browse the repository at this point in the history
…orientation-on-popupclose

Bug 1027401 - Change child event mechanism, r=etienne
  • Loading branch information
alivedise committed Jul 9, 2014
2 parents ba9da60 + f7c94db commit d8f5af3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 163 deletions.
2 changes: 1 addition & 1 deletion apps/system/js/activity_window.js
Expand Up @@ -181,7 +181,7 @@
ActivityWindow.REGISTERED_EVENTS =
['mozbrowserclose', 'mozbrowsererror', 'mozbrowservisibilitychange',
'mozbrowserloadend', 'mozbrowseractivitydone', 'mozbrowserloadstart',
'_localized', '_opened', '_closing', 'acitivityclosing', 'popupclosing'];
'_localized'];

ActivityWindow.prototype._handle_mozbrowseractivitydone =
function aw__handle_mozbrowseractivitydone() {
Expand Down
73 changes: 14 additions & 59 deletions apps/system/js/app_window.js
@@ -1,5 +1,4 @@
/* global SettingsListener, AttentionScreen,
OrientationManager, StatusBar */
/* global SettingsListener, OrientationManager, StatusBar */
'use strict';

(function(exports) {
Expand Down Expand Up @@ -433,17 +432,6 @@
this.destroy();
}

// Remove previous -> next reference.
if (this.previousWindow) {
this.previousWindow.unsetNextWindow();
this.previousWindow = null;
}

// Remove rear -> front reference.
if (this.rearWindow) {
this.rearWindow.unsetFrontWindow();
this.rearWindow = null;
}
/**
* Fired when the instance is terminated.
* @event AppWindow#appterminated
Expand All @@ -469,6 +457,17 @@
* Fired before the instance id destroyed.
* @event AppWindow#appwilldestroy
*/
// Remove previous -> next reference.
if (this.previousWindow) {
this.previousWindow.unsetNextWindow();
this.previousWindow = null;
}

// Remove rear -> front reference.
if (this.rearWindow) {
this.rearWindow.unsetFrontWindow();
this.rearWindow = null;
}
this.publish('willdestroy');
this.uninstallSubComponents();
if (this.element) {
Expand Down Expand Up @@ -645,8 +644,7 @@
'mozbrowsertitlechange', 'mozbrowserlocationchange',
'mozbrowsericonchange', 'mozbrowserasyncscroll',
'_localized', '_swipein', '_swipeout', '_kill_suspended',
'popupterminated', 'activityterminated', 'activityclosing',
'popupclosing', 'activityopened', '_orientationchange', '_focus'];
'_orientationchange', '_focus'];

AppWindow.SUB_COMPONENTS = {
'transitionController': window.AppTransitionController,
Expand Down Expand Up @@ -926,10 +924,9 @@

// WebAPI testing is using mozbrowserloadend event to know
// the first app is loaded so we cannot stop the propagation here.
// When an activity is killed we remove the rearWindow reference first
// but we don't want subsequent mozbrowser events to bubble to the
// used-to-be-rear-window
if (this.rearWindow || this._killed) {
if (this.rearWindow && evt.type.startsWith('mozbrowser')) {
evt.stopPropagation();
}
this.debug(' Handling ' + evt.type + ' event...');
Expand Down Expand Up @@ -1787,48 +1784,6 @@
return top.browser ? top.browser.element : null;
};

AppWindow.prototype._handle_activityterminated = function() {
this.frontWindow = null;
};

AppWindow.prototype._handle_popupterminated = function() {
this.frontWindow = null;
};

/**
* Restore visibility and orientation when the embedded window
* is closing.
*/
AppWindow.prototype._handle_activityclosing = function() {
// Do nothing if we are not active or we are being killing.
if (!this.isVisible() || this._killed) {
return;
}

this.lockOrientation();
// XXX: Refine this in attention-window refactor.
if (!AttentionScreen.isFullyVisible()) {
this.setVisible(true);
}
};

/**
* Restore visibility and orientation when the embedded window
* is closing.
*/
AppWindow.prototype._handle_popupclosing = function() {
// Do nothing if we are not active or we are being killing.
if (!this.isVisible() || this._killed) {
return;
}

this.lockOrientation();
// XXX: Refine this in attention-window refactor.
if (!AttentionScreen.isFullyVisible()) {
this.setVisible(true);
}
};

/**
* Indicate we are in viewport or not.
* @return {Boolean} We are in viewport or outside viewport.
Expand Down
27 changes: 26 additions & 1 deletion apps/system/js/child_window_factory.js
@@ -1,5 +1,6 @@
'use strict';
/* global AppWindow, PopupWindow, ActivityWindow, SettingsListener */
/* global AppWindow, PopupWindow, ActivityWindow, SettingsListener,
AttentionScreen */

(function(exports) {
var ENABLE_IN_APP_SHEET = false;
Expand Down Expand Up @@ -39,6 +40,14 @@

ChildWindowFactory.prototype.handleEvent =
function cwf_handleEvent(evt) {
// Handle event from child window.
if (evt.detail && evt.detail.instanceID &&
evt.detail.instanceID !== this.app.instanceID) {
if (this['_handle_child_' + evt.type]) {
this['_handle_child_' + evt.type](evt);
}
return;
}
// Skip to wrapperWindowFactory.
if (this.isHomescreen) {
// XXX: Launch wrapper window here.
Expand Down Expand Up @@ -88,6 +97,7 @@
rearWindow: this.app
};
var childWindow = new PopupWindow(configObject);
childWindow.element.addEventListener('_closing', this);
childWindow.open();
return true;
};
Expand Down Expand Up @@ -126,6 +136,20 @@
return false;
};

ChildWindowFactory.prototype._handle_child__closing = function(evt) {
// Do nothing if we are not active or we are being killing.
if (!this.app.isVisible() || this.app._killed) {
return;
}
// XXX: Refine this in attention-window refactor.
if (AttentionScreen.isFullyVisible()) {
return;
}

this.app.lockOrientation();
this.app.setVisible(true);
};

ChildWindowFactory.prototype.createActivityWindow = function(evt) {
var configuration = evt.detail;
var top = this.app.getTopMostWindow();
Expand All @@ -136,6 +160,7 @@
return;
}
var activity = new ActivityWindow(configuration, top);
activity.element.addEventListener('_closing', this);
activity.open();
};

Expand Down
116 changes: 17 additions & 99 deletions apps/system/test/unit/app_window_test.js
@@ -1,6 +1,6 @@
/* global AppWindow, ScreenLayout, MockOrientationManager,
LayoutManager, MocksHelper, MockAttentionScreen, MockContextMenu,
AppChrome, ActivityWindow, PopupWindow, layoutManager */
LayoutManager, MocksHelper, MockContextMenu,
AppChrome, layoutManager */
'use strict';

requireApp('system/test/unit/mock_orientation_manager.js');
Expand All @@ -13,15 +13,13 @@ requireApp('system/test/unit/mock_layout_manager.js');
requireApp('system/test/unit/mock_app_chrome.js');
requireApp('system/test/unit/mock_screen_layout.js');
requireApp('system/test/unit/mock_popup_window.js');
requireApp('system/test/unit/mock_attention_screen.js');
requireApp('system/test/unit/mock_activity_window.js');
requireApp('system/test/unit/mock_statusbar.js');

var mocksForAppWindow = new MocksHelper([
'OrientationManager', 'Applications', 'SettingsListener',
'ManifestHelper', 'LayoutManager', 'ActivityWindow',
'ScreenLayout', 'AppChrome', 'PopupWindow', 'AttentionScreen',
'StatusBar'
'ScreenLayout', 'AppChrome', 'PopupWindow', 'StatusBar'
]).init();

suite('system/AppWindow', function() {
Expand Down Expand Up @@ -1221,6 +1219,20 @@ suite('system/AppWindow', function() {
assert.isTrue(spyClose.calledWith('out-to-right'));
});

test('Destroy should clear rearWindow.', function() {
var popups = openPopups(2);
popups[1].destroy();
assert.isNull(popups[0].frontWindow);
assert.isNull(popups[1].rearWindow);
});

test('Destroy should clear previousWindow.', function() {
var sheets = openSheets(2);
sheets[1].destroy();
assert.isNull(sheets[0].nextWindow);
assert.isNull(sheets[1].previousWindow);
});

test('Error event', function() {
var app1 = new AppWindow(fakeAppConfig1);
var stubKill = this.sinon.stub(app1, 'kill');
Expand Down Expand Up @@ -1304,8 +1316,6 @@ suite('system/AppWindow', function() {
assert.isTrue(stubOpenParent.calledWith('in-from-left'));
assert.isTrue(stubCloseSelf.calledWith('out-to-right'));
assert.isTrue(stubKillChild.called);
assert.isNull(app1.previousWindow);
assert.isNull(app1parent.nextWindow);
assert.isNull(app1.nextWindow);

var stubDestroy = this.sinon.stub(app1, 'destroy');
Expand Down Expand Up @@ -1348,28 +1358,6 @@ suite('system/AppWindow', function() {
app1.config.url = url;
});

suite('kill behavior with events', function() {
var app, evt, spyStopPropagation;

setup(function() {
app = new AppWindow(fakeAppConfig1);
evt = new CustomEvent('mozbrowserlocationchange',
{ detail: 'http://fakeURL.changed' });
spyStopPropagation = this.sinon.spy(evt, 'stopPropagation');
});

test('no kill', function() {
app.handleEvent(evt);
assert.isTrue(spyStopPropagation.notCalled);
});

test('under kill', function() {
app.kill();
app.handleEvent(evt);
assert.isTrue(spyStopPropagation.called);
});
});

test('Scroll event', function() {
var app4 = new AppWindow(fakeAppConfig4);
app4.manifest = null;
Expand Down Expand Up @@ -1530,76 +1518,6 @@ suite('system/AppWindow', function() {

assert.isTrue(switchTransitionState.calledWith('closed'));
});

test('popupclosing event', function() {
var app1 = new AppWindow(fakeAppConfig1);
var spyLockOrientation = this.sinon.spy(app1, 'lockOrientation');
var spySetVisible = this.sinon.spy(app1, 'setVisible');
var stubIsActive = this.sinon.stub(app1, 'isActive');
stubIsActive.returns(true);
MockAttentionScreen.mFullyVisible = false;

app1.handleEvent({
type: 'popupclosing'
});

assert.isTrue(spyLockOrientation.called);
assert.isTrue(spySetVisible.called);
});

test('activityclosing event', function() {
var app1 = new AppWindow(fakeAppConfig1);
var spyLockOrientation = this.sinon.spy(app1, 'lockOrientation');
var spySetVisible = this.sinon.spy(app1, 'setVisible');
var stubIsActive = this.sinon.stub(app1, 'isActive');
stubIsActive.returns(true);
MockAttentionScreen.mFullyVisible = false;

app1.handleEvent({
type: 'activityclosing'
});

assert.isTrue(spyLockOrientation.called);
assert.isTrue(spySetVisible.called);
});

test('activityclosing event when attention screen is shown', function() {
var app1 = new AppWindow(fakeAppConfig1);
var spyLockOrientation = this.sinon.spy(app1, 'lockOrientation');
var spySetVisible = this.sinon.spy(app1, 'setVisible');
var stubIsActive = this.sinon.stub(app1, 'isActive');
stubIsActive.returns(true);
MockAttentionScreen.mFullyVisible = true;

app1.handleEvent({
type: 'activityclosing'
});

assert.isTrue(spyLockOrientation.called);
assert.isFalse(spySetVisible.called);
});

test('activityterminated event', function() {
var app1 = new AppWindow(fakeAppConfig1);
var activity = new ActivityWindow({});
app1.frontWindow = activity;
app1.handleEvent({
type: 'activityterminated'
});

assert.isNull(app1.frontWindow);
});

test('popupterminated event', function() {
var app1 = new AppWindow(fakeAppConfig1);
var popup = new PopupWindow({});
app1.frontWindow = popup;
app1.handleEvent({
type: 'popupterminated'
});

assert.isNull(app1.frontWindow);
});
});

test('Change URL at run time', function() {
Expand Down

0 comments on commit d8f5af3

Please sign in to comment.