1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * Functions related to controlling the modal UI state of the app. UI states
8 * are expressed as HTML attributes with a dotted hierarchy. For example, the
9 * string 'host.shared' will match any elements with an associated attribute
10 * of 'host' or 'host.shared', showing those elements and hiding all others.
11 * Elements with no associated attribute are ignored.
16 /** @suppress {duplicate} */
17 var remoting
= remoting
|| {};
22 UNAUTHENTICATED
: 'auth',
24 CLIENT_UNCONNECTED
: 'client.unconnected',
25 CLIENT_PIN_PROMPT
: 'client.pin-prompt',
26 CLIENT_CONNECTING
: 'client.connecting',
27 CLIENT_CONNECT_FAILED_IT2ME
: 'client.connect-failed.it2me',
28 CLIENT_CONNECT_FAILED_ME2ME
: 'client.connect-failed.me2me',
29 CLIENT_SESSION_FINISHED_IT2ME
: 'client.session-finished.it2me',
30 CLIENT_SESSION_FINISHED_ME2ME
: 'client.session-finished.me2me',
32 HOST_WAITING_FOR_CODE
: 'host.waiting-for-code',
33 HOST_WAITING_FOR_CONNECTION
: 'host.waiting-for-connection',
34 HOST_SHARED
: 'host.shared',
35 HOST_SHARE_FAILED
: 'host.share-failed',
36 HOST_SHARE_FINISHED
: 'host.share-finished',
37 IN_SESSION
: 'in-session'
41 * Update the DOM by showing or hiding elements based on whether or not they
42 * have an attribute matching the specified name.
43 * @param {string} mode The value against which to match the attribute.
44 * @param {string} attr The attribute name to match.
45 * @return {void} Nothing.
47 remoting
.updateModalUi = function(mode
, attr
) {
48 var modes
= mode
.split('.');
49 for (var i
= 1; i
< modes
.length
; ++i
)
50 modes
[i
] = modes
[i
- 1] + '.' + modes
[i
];
51 var elements
= document
.querySelectorAll('[' + attr
+ ']');
52 for (var i
= 0; i
< elements
.length
; ++i
) {
53 var element
= /** @type {Element} */ elements
[i
];
55 for (var m
= 0; m
< modes
.length
; ++m
) {
56 if (hasClass(element
.getAttribute(attr
), modes
[m
])) {
61 element
.hidden
= hidden
;
66 * @type {remoting.AppMode} The current app mode
68 remoting
.currentMode
= remoting
.AppMode
.HOME
;
71 * Change the app's modal state to |mode|, determined by the data-ui-mode
74 * @param {remoting.AppMode} mode The new modal state.
76 remoting
.setMode = function(mode
) {
77 remoting
.updateModalUi(mode
, 'data-ui-mode');
78 remoting
.debug
.log('App mode: ' + mode
);
79 remoting
.currentMode
= mode
;
80 if (mode
== remoting
.AppMode
.IN_SESSION
) {
81 document
.removeEventListener('keydown', remoting
.DebugLog
.onKeydown
, false);
83 document
.addEventListener('keydown', remoting
.DebugLog
.onKeydown
, false);
85 if (mode
== remoting
.AppMode
.HOME
) {
86 var display = function() { remoting
.hostList
.display(); };
87 remoting
.hostList
.refresh(display
);
92 * Get the major mode that the app is running in.
93 * @return {string} The app's current major mode.
95 remoting
.getMajorMode = function() {
96 return remoting
.currentMode
.split('.')[0];