| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/base/base.html"> |
| |
| <script> |
| 'use strict'; |
| |
| /** |
| * @fileoverview Provides the LayoutObject class. |
| */ |
| tr.exportTo('tr.e.chrome', function() { |
| var KNOWN_PROPERTIES = { |
| children: 1, |
| name: 1, |
| address: 1 |
| }; |
| |
| /** |
| * @constructor |
| */ |
| function LayoutObject(snapshot, args) { |
| this.snapshot_ = snapshot; |
| this.id_ = args.address; |
| this.name_ = args.name; |
| this.childLayoutObjects_ = []; |
| this.otherProperties_ = {}; |
| |
| if (args.children) { |
| args.children.forEach(function(child) { |
| this.childLayoutObjects_.push(new LayoutObject(snapshot, child)); |
| }.bind(this)); |
| } |
| |
| for (var property in args) { |
| if (!KNOWN_PROPERTIES[property]) |
| this.otherProperties_[property] = args[property]; |
| } |
| } |
| |
| LayoutObject.prototype = { |
| get snapshot() { |
| return this.snapshot_; |
| }, |
| |
| get id() { |
| return this.id_; |
| }, |
| |
| get name() { |
| return this.name_; |
| }, |
| |
| get hasChildLayoutObjects() { |
| return this.childLayoutObjects_.length > 0; |
| }, |
| |
| get childLayoutObjects() { |
| return this.childLayoutObjects_; |
| }, |
| |
| traverseTree: function(cb, opt_this) { |
| cb.call(opt_this, this); |
| if (!this.hasChildLayoutObjects) |
| return; |
| this.childLayoutObjects.forEach(function(child) { |
| child.traverseTree(cb, opt_this); |
| }); |
| }, |
| |
| get otherPropertyNames() { |
| var names = []; |
| for (var name in this.otherProperties_) { |
| names.push(name); |
| } |
| return names; |
| }, |
| |
| getProperty: function(name) { |
| return this.otherProperties_[name]; |
| }, |
| |
| get previousSnapshotLayoutObject() { |
| if (!this.snapshot.previousSnapshot) |
| return undefined; |
| return this.snapshot.previousSnapshot.getLayoutObjectById(this.id); |
| }, |
| |
| get nextSnapshotLayoutObject() { |
| if (!this.snapshot.nextSnapshot) |
| return undefined; |
| return this.snapshot.nextSnapshot.getLayoutObjectById(this.id); |
| } |
| }; |
| |
| return { |
| LayoutObject: LayoutObject |
| }; |
| }); |
| </script> |