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

Side by Side Diff: sky/sdk/lib/widgets/widget.dart

Issue 1217473007: Remove all the caching of Theme data, since perf data suggests it wasn't helping. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'dart:sky' as sky; 8 import 'dart:sky' as sky;
9 9
10 import '../base/hit_test.dart'; 10 import '../base/hit_test.dart';
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 215 }
216 216
217 } 217 }
218 218
219 class ParentDataNode extends TagNode { 219 class ParentDataNode extends TagNode {
220 ParentDataNode(Widget child, this.parentData, { String key }) 220 ParentDataNode(Widget child, this.parentData, { String key })
221 : super(child, key: key); 221 : super(child, key: key);
222 final ParentData parentData; 222 final ParentData parentData;
223 } 223 }
224 224
225 abstract class _Heir implements Widget { 225 abstract class Inherited extends TagNode {
226 Map<Type, Inherited> _traits; 226 Inherited({ String key, Widget child }) : super._withKey(child, key);
227 Inherited inheritedOfType(Type type) => _traits == null ? null : _traits[type] ;
228
229 static _Heir _getHeirAncestor(Widget widget) {
230 Widget ancestor = widget;
231 while (ancestor != null && !(ancestor is _Heir)) {
232 ancestor = ancestor.parent;
233 }
234 return ancestor as _Heir;
235 }
236
237 void _updateTraitsFromParent(Widget parent) {
238 _Heir ancestor = _getHeirAncestor(parent);
239 if (ancestor == null || ancestor._traits == null) return;
240 _updateTraits(ancestor._traits);
241 }
242
243 void _updateTraitsRecursively(Widget widget) {
244 if (widget is _Heir)
245 widget._updateTraits(_traits);
246 else
247 widget.walkChildren(_updateTraitsRecursively);
248 }
249
250 void _updateTraits(Map<Type, Inherited> newTraits) {
251 if (newTraits != _traits) {
252 _traits = newTraits;
253 walkChildren(_updateTraitsRecursively);
254 }
255 }
256 }
257
258 abstract class Inherited extends TagNode with _Heir {
259 Inherited({ String key, Widget child }) : super._withKey(child, key) {
260 _traits = new Map<Type, Inherited>();
261 }
262
263 void set _traits(Map<Type, Inherited> value) {
264 super._traits = new Map<Type, Inherited>.from(value)
265 ..[runtimeType] = this;
266 }
267
268 // TODO(jackson): When Dart supports super in mixins we can move to _Heir
269 void setParent(Widget parent) {
270 _updateTraitsFromParent(parent);
271 super.setParent(parent);
272 }
273 } 227 }
274 228
275 typedef void GestureEventListener(sky.GestureEvent e); 229 typedef void GestureEventListener(sky.GestureEvent e);
276 typedef void PointerEventListener(sky.PointerEvent e); 230 typedef void PointerEventListener(sky.PointerEvent e);
277 typedef void EventListener(sky.Event e); 231 typedef void EventListener(sky.Event e);
278 232
279 class Listener extends TagNode { 233 class Listener extends TagNode {
280 234
281 Listener({ 235 Listener({
282 Widget child, 236 Widget child,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 310
357 void _handleEvent(sky.Event e) { 311 void _handleEvent(sky.Event e) {
358 sky.EventListener listener = listeners[e.type]; 312 sky.EventListener listener = listeners[e.type];
359 if (listener != null) { 313 if (listener != null) {
360 listener(e); 314 listener(e);
361 } 315 }
362 } 316 }
363 317
364 } 318 }
365 319
366 abstract class Component extends Widget with _Heir { 320 abstract class Component extends Widget {
367 321
368 Component({ String key, bool stateful }) 322 Component({ String key, bool stateful })
369 : _stateful = stateful != null ? stateful : false, 323 : _stateful = stateful != null ? stateful : false,
370 _order = _currentOrder + 1, 324 _order = _currentOrder + 1,
371 super._withKey(key); 325 super._withKey(key);
372 326
373 static Component _currentlyBuilding; 327 static Component _currentlyBuilding;
374 bool get _isBuilding => _currentlyBuilding == this; 328 bool get _isBuilding => _currentlyBuilding == this;
375 329
376 bool _stateful; 330 bool _stateful;
377 bool _dirty = true; 331 bool _dirty = true;
378 bool _disqualifiedFromEverAppearingAgain = false; 332 bool _disqualifiedFromEverAppearingAgain = false;
379 333
380 Widget _built; 334 Widget _built;
381 dynamic _slot; // cached slot from the last time we were synced 335 dynamic _slot; // cached slot from the last time we were synced
382 336
383 void didMount() { 337 void didMount() {
384 assert(!_disqualifiedFromEverAppearingAgain); 338 assert(!_disqualifiedFromEverAppearingAgain);
385 super.didMount(); 339 super.didMount();
386 } 340 }
387 341
388 // TODO(jackson): When Dart supports super in mixins we can move to _Heir
389 void setParent(Widget parent) {
390 _updateTraitsFromParent(parent);
391 super.setParent(parent);
392 }
393
394 void remove() { 342 void remove() {
395 assert(_built != null); 343 assert(_built != null);
396 assert(root != null); 344 assert(root != null);
397 removeChild(_built); 345 removeChild(_built);
398 _built = null; 346 _built = null;
399 super.remove(); 347 super.remove();
400 } 348 }
401 349
402 void detachRoot() { 350 void detachRoot() {
403 assert(_built != null); 351 assert(_built != null);
404 assert(root != null); 352 assert(root != null);
405 _built.detachRoot(); 353 _built.detachRoot();
406 } 354 }
407 355
356 Inherited inheritedOfType(Type targetType) {
357 Widget ancestor = parent;
358 while (ancestor != null && ancestor.runtimeType != targetType)
359 ancestor = ancestor.parent;
360 return ancestor;
361 }
362
408 bool _retainStatefulNodeIfPossible(Widget old) { 363 bool _retainStatefulNodeIfPossible(Widget old) {
409 assert(!_disqualifiedFromEverAppearingAgain); 364 assert(!_disqualifiedFromEverAppearingAgain);
410 365
411 Component oldComponent = old as Component; 366 Component oldComponent = old as Component;
412 if (oldComponent == null || !oldComponent._stateful) 367 if (oldComponent == null || !oldComponent._stateful)
413 return false; 368 return false;
414 369
415 assert(runtimeType == oldComponent.runtimeType); 370 assert(runtimeType == oldComponent.runtimeType);
416 assert(key == oldComponent.key); 371 assert(key == oldComponent.key);
417 372
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 if (root.parent == null) { 968 if (root.parent == null) {
1014 // we haven't attached it yet 969 // we haven't attached it yet
1015 assert(_container.child == null); 970 assert(_container.child == null);
1016 _container.child = root; 971 _container.child = root;
1017 } 972 }
1018 assert(root.parent == _container); 973 assert(root.parent == _container);
1019 } 974 }
1020 975
1021 Widget build() => builder(); 976 Widget build() => builder();
1022 } 977 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698