Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe-screen.js

Issue 599273004: Polished UI for the host side of pairing flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_point
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 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.
4
dzhioev (left Google) 2014/09/25 19:28:22 This file is mostly a copy of ui/login/screen.js.
5 Polymer('oobe-screen', (function() {
6 /** @const */ var CALLBACK_USER_ACTED = 'userActed';
7
8 function doNothing() {};
9
10 return {
11 /**
12 * The login.Screen which is hosting |this|.
13 */
14 screen_: null,
15
16 /**
17 * Dictionary of context observers that are methods of |this| bound to
18 * |this|.
19 */
20 contextObservers_: null,
21
22 context: null,
23
24 C: null,
25
26 /**
27 * Called when the screen is beeing registered.
28 */
29 initialize: doNothing,
30
31 ready: function() {
32 if (this.decorate_) {
33 this.initialize();
34 } else {
35 this.ready_ = true;
36 }
37 },
38
39 i18n: function(args) {
40 if (!(args instanceof Array))
41 args = [args];
42 args[0] = 'login_' + this.name + '_' + args[0];
43 return loadTimeData.getStringF.apply(loadTimeData, args);
44 },
45
46 /**
47 * Called by login.Screen when the screen is beeing registered.
48 */
49 decorate: function(screen) {
50 this.screen_ = screen;
51 screen.initialize();
52 this.context = screen.screenContext_;
53 this.C = this.context.storage_;
54 this.contextObservers_ = {};
55 var self = this;
56 this.querySelectorAllImpl_('button[action]').forEach(function(button) {
57 button.addEventListener('click', function(e) {
58 var action = this.getAttribute('action');
59 self.send(CALLBACK_USER_ACTED, action);
60 e.stopPropagation();
61 });
62 });
63 if (this.ready_) {
64 this.initialize();
65 } else {
66 this.decorate_ = true;
67 }
68 },
69
70 /**
71 * @final
72 */
73 send: function() {
74 return this.sendImpl_.apply(this, arguments);
75 },
76
77 /**
78 * @final
79 */
80 addContextObserver: function() {
81 return this.addContextObserverImpl_.apply(this, arguments);
82 },
83
84 /**
85 * @final
86 */
87 removeContextObserver: function() {
88 return this.removeContextObserverImpl_.apply(this, arguments);
89 },
90
91 /**
92 * @final
93 */
94 commitContextChanges: function() {
95 return this.commitContextChangesImpl_.apply(this, arguments);
96 },
97
98 /**
99 * @override
100 * @final
101 */
102 querySelector: function() {
103 return this.querySelectorImpl_.apply(this, arguments);
104 },
105
106 /**
107 * @override
108 * @final
109 */
110 querySelectorAll: function() {
111 return this.querySelectorAllImpl_.apply(this, arguments);
112 },
113
114 /**
115 * See login.Screen.send.
116 * @private
117 */
118 sendImpl_: function() {
119 return this.screen_.send.apply(this.screen_, arguments);
120 },
121
122 /**
123 * Does the following things:
124 * * Looks for buttons having "action" properties and adds click handlers
125 * to them. These handlers send |CALLBACK_USER_ACTED| messages to
126 * C++ with "action" property's value as a payload.
127 * @private
128 */
129 initializeImpl_: function() {
130 },
131
132 /**
133 * Starts observation of property with |key| of the context attached to
134 * current screen. This method differs from "login.ScreenContext" in that
135 * it automatically detects if observer is method of |this| and make
136 * all needed actions to make it work correctly. So it's no need for client
137 * to bind methods to |this| and keep resulting callback for
138 * |removeObserver| call:
139 *
140 * this.addContextObserver('key', this.onKeyChanged_);
141 * ...
142 * this.removeContextObserver('key', this.onKeyChanged_);
143 * @private
144 */
145 addContextObserverImpl_: function(key, observer) {
146 var realObserver = observer;
147 var propertyName = this.getPropertyNameOf_(observer);
148 if (propertyName) {
149 if (!this.contextObservers_.hasOwnProperty(propertyName))
150 this.contextObservers_[propertyName] = observer.bind(this);
151 realObserver = this.contextObservers_[propertyName];
152 }
153 this.context.addObserver(key, realObserver);
154 },
155
156 /**
157 * Removes |observer| from the list of context observers. Supports not only
158 * regular functions but also screen methods (see comment to
159 * |addContextObserver|).
160 * @private
161 */
162 removeContextObserverImpl_: function(observer) {
163 var realObserver = observer;
164 var propertyName = this.getPropertyNameOf_(observer);
165 if (propertyName) {
166 if (!this.contextObservers_.hasOwnProperty(propertyName))
167 return;
168 realObserver = this.contextObservers_[propertyName];
169 delete this.contextObservers_[propertyName];
170 }
171 this.context.removeObserver(realObserver);
172 },
173
174 /**
175 * See login.Screen.commitContextChanges.
176 * @private
177 */
178 commitContextChangesImpl_: function() {
179 return this.screen_.commitContextChanges.apply(this.screen_, arguments);
180 },
181
182 /**
183 * Calls |querySelector| method of the shadow dom and returns the result.
184 * @private
185 */
186 querySelectorImpl_: function(selector) {
187 return this.shadowRoot.querySelector(selector);
188 },
189
190
191 /**
192 * Calls standart |querySelectorAll| method of the shadow dom and returns
193 * the result converted to Array.
194 * @private
195 */
196 querySelectorAllImpl_: function(selector) {
197 var list = this.shadowRoot.querySelectorAll(selector);
198 return Array.prototype.slice.call(list);
199 },
200
201 /**
202 * If |value| is the value of some property of |this| returns property's
203 * name. Otherwise returns empty string.
204 * @private
205 */
206 getPropertyNameOf_: function(value) {
207 for (var key in this)
208 if (this[key] === value)
209 return key;
210 return '';
211 }
212 };
213 })());
214
215
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698