Architecture, Development, Patterns
Window Manager
A core module in an operating system, which is responsible to display and maintain the window based UI.
Window Mgmt. at FxOS
Things inside..
Window Manager (v1.3-)
ModalDialog
TrusteUI
AuthDialog
transition control
create mozbrowser iframe
maintain app life cycle
gen screenshots
redirect mozbrowser events
orientation control
layout control
error handling
visibility control
web activities management
web app management
manage homescreen
manage ftu
It’s sad to have a such giant module to control everything :(
The secret to build a large app ?
The secret to build a large app ?
Never build a large app
Solutions
Instances +
Manager +
Scalable Patterns
INSTANCES
Minimal operable unit
AppWindow
Extra chrome UI
Real web content
AppWindow States
App Visibility
App Orientation
App has no knowledge about (x, y),
but (w, h) is affecting app by window.innerHeight, window.innerWidth, and reflow/resize if that changed.
Layout = (x, y, w, h)
Use small piece of codes doing limited tasks
AppWindow: Submodule
To avoid a giant AppWindow class..
AppWindow Submodules
AppWindow
Each submodule is responsible to handle a specific request from the appWindow. Their only dependency is the appWindow who launches/instantiates them.
M
M
M
M
M
M
HW
M
M
M
M
M
M
AtW
M
M
M
M
M
M
submodule
Current
Submodules
AppWindow
ModalDialog
AuthenticationDialog
TransitionController
Chrome
ContextMenu
childWindowFactory
window.alert
window.open
HTTP Auth
chrome property
<contextmenu>
Transition State Machine
<iframe mozBrowser>
Developing Submodules
var MyModule = function(app) {
this.app = app;
this.app.element.addEventListener(‘_opened’, this);
};
MyModule.prototype = {
handleEvent: function() {
// ...
}
};
AppWindow.SUB_MODULES = {
‘myModule’: window.MyModule
};
var a = new AppWindow();
typeof(a.myModule) // === MyModule
Transition Finite State Machine
opened
closed
opening
closing
AppWindow
AppWindow does not care the state maintainence, but only ask the finite state machine to process events
opened
closed
opening
closing
AppWindow
Whenever state is changed, transition FSM will publish events for the app.
Interactions between AppWindows..
We are living in a world of multiple apps. An appWindow should not do anything it wants to do.
Request before permitted!
MANAGERS
Managing multiple standalone instances
If all the subordinates are standalone
The job of a manager is easy!
Manager
LifeCycle Management
Life cycle - launch
AppWindowManager
#AppWindow
Gecko
webapps-launch
open-app
Factory
Factory
mozbrowseropenwindow
launchactivity
#AppWindow
Factory
#AppWindow
Factory
#AppWindow
Factory
#AppWindow
Factory
#PopupWindow
Factory
#ActivityWindow
Factory
#AttentionWindow
appopenwindow
Life cycle - kill
appWindow
SuspendingWindowManager
suspended
appWindow
suspended
appWindow
suspended
mozbrowsererror
mozbrowsererror
mozbrowsererror
appWindow
timestamp: 1
SuspendingWindowManager
appWindow
timestamp: 0
appWindow
timestamp: 2
resumed
launch
appWindow
timestamp: 1
SuspendingWindowManager
appWindow
timestamp: 0
appWindow
timestamp: 9
appWindow
timestamp: 10
suspended
kill the oldest
*WindowManager
*Window
*Window (active)
Modules affecting transition
*Window
Transition
FSM
*Window
request to open
close the active instance
Basically only the same type window will be taken into account.
WindowManager
*Window
*Window
Modules affecting transition
*DialogManager
Transition
FSM
*Window
admit the request or ignore by
*Window.open();
MultiTasking - Nested Windows
Dialer App
Gallery App
Homescreen App
Contact App
Contact Activity
Gallery Activity
Camera Activity
Camera App
MultiTasking - Nested Windows
AppWindow
AppWindow
AppWindow
AppWindow
ActivityWindow
Activity
Window
ActivityWindow
AppWindow
FrontWindow is rendered inside BottomWindow’s container.
Nested Window
AppWindow#1
Activity
Window#A
Activity
Window#B
We are having a principal pattern now.
AppWindowManager
AppWindow
AppWindow
Application Core
AppWindow
AppWindow
AppWindow
One Manager + Instances Pattern fits usual webapp management requirements.
Hierarchy
In an operation system, there would be some system level user interface which are not usual applications but has certain interaction with applications.
Lockscreen, Attention, SystemDialog, Rocketbar...
We are having a principal pattern now.
Scale this design.
One App =>
Multiple App =>
Multiple Tasking =>
Multiple Hierachy
AppWindowManager
AppWindow
AppWindow
Application Core
LockscreenWindow
Manager
LockscreenWindow
Ability to extend the manager
AppWindowManager
AppWindow
AppWindow
Application Core
LockscreenWindow
Manager
LockscreenWindow
Keep the interactions between new windows
AttentionWindow
Manager
Attention
Window
Attention
Window
Manager of Managers
Hierarchy management
Hierarchy Management
Lowlevel Windows
Highlevel Windows
Manager
1. Request
2. Detect
3.Perform/ Ignore
Operations across windows is controlled by specfic manager.
Hierarchy events
Hierarchy Management
LayoutManager
*Window
KeyboardManager
SoftwareHomeButton
*WindowManager
*Window
*Window
*Window
*WindowManager
*WindowManager
dispatch resize command to highest priority manager
Modules affecting layout
execute resize to active window
resize
VisibilityManager
*Window
*Window
*Window
*WindowManager
*WindowManager
*WindowManager
dispatch background command to lower priority manager
Modules affecting visibility
execute setVisible to active window
*DialogManager
*Window
VisibilityManager
*Window
*Window
Modules affecting visibility
*DialogManager
Transition
FSM
request to foreground
*Window
Check no higher priority module is active
VisibilityManager
*Window
*Window
Modules affecting visibility
*DialogManager
Transition
FSM
*Window
admit the request or ignore
by *Window.setVisible(true)
OrientationManager
*Window
*Window
Modules affecting orientation
*DialogManager
Transition
FSM
*Window
request lock orientation
Check no higher priority module is active
OrientationManager
*Window
*Window
Modules affecting orientation
*DialogManager
Transition
FSM
*Window
admit the request or ignore
This is not real now.
screen.requestLockOrientation() is open to web content.
System app should have the ability to manage orientation request from mozbrowser iframe.
Look at the Transition FSM closely
Develop a window manager
Best Practice: Rocketbar
PATTERNS USED
Patterns
Manager(Mediator) Pattern
InstanceA
Manager
InstanceB
InstanceC
Instances should issue a request which needs cross instance knowledge to manager.
request an operation across instances
InstanceA
Manager
InstanceB
InstanceC
InstanceA has no knowledge about instanceB.
check states
InstanceA
Manager
InstanceB
InstanceC
permit the request after checking
other instances
Patterns
Event Publisher/Broadcaster
Inner Subscriber
Inner Subscriber
Inner Subscriber
Outer Subscriber
Outer Subscriber
Outer Subscriber
Inside a module
The world
Event Publisher/Broadcaster
Inner Subscriber
Inner Subscriber
Inner Subscriber
Outer Subscriber
Outer Subscriber
Outer Subscriber
Inside a module
The world
Patterns
Finite State Machine
Events
FSM.processEvent(‘a’);
FSM.processEvent(‘a’);
FSM.processEvent(‘b’);
FSM.processEvent(‘c’);
statechange