Home | History | Annotate | Download | only in chrome
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/tracing/base/base.html">
      9 
     10 <script>
     11 'use strict';
     12 
     13 tr.exportTo('tr.e.chrome', function() {
     14   var KNOWN_PROPERTIES = {
     15     absX: 1,
     16     absY: 1,
     17     address: 1,
     18     anonymous: 1,
     19     childNeeds: 1,
     20     children: 1,
     21     classNames: 1,
     22     col: 1,
     23     colSpan: 1,
     24     float: 1,
     25     height: 1,
     26     htmlId: 1,
     27     name: 1,
     28     posChildNeeds: 1,
     29     positioned: 1,
     30     positionedMovement: 1,
     31     relX: 1,
     32     relY: 1,
     33     relativePositioned: 1,
     34     row: 1,
     35     rowSpan: 1,
     36     selfNeeds: 1,
     37     stickyPositioned: 1,
     38     tag: 1,
     39     width: 1
     40   };
     41 
     42   function LayoutObject(snapshot, args) {
     43     this.snapshot_ = snapshot;
     44     this.id_ = args.address;
     45     this.name_ = args.name;
     46     this.childLayoutObjects_ = [];
     47     this.otherProperties_ = {};
     48     this.tag_ = args.tag;
     49     this.relativeRect_ = tr.b.Rect.fromXYWH(
     50         args.relX, args.relY, args.width, args.height);
     51     this.absoluteRect_ = tr.b.Rect.fromXYWH(
     52         args.absX, args.absY, args.width, args.height);
     53     this.isFloat_ = args.float;
     54     this.isStickyPositioned_ = args.stickyPositioned;
     55     this.isPositioned_ = args.positioned;
     56     this.isRelativePositioned_ = args.relativePositioned;
     57     this.isAnonymous_ = args.anonymous;
     58     this.htmlId_ = args.htmlId;
     59     this.classNames_ = args.classNames;
     60     this.needsLayoutReasons_ = [];
     61     if (args.selfNeeds)
     62       this.needsLayoutReasons_.push('self');
     63     if (args.childNeeds)
     64       this.needsLayoutReasons_.push('child');
     65     if (args.posChildNeeds)
     66       this.needsLayoutReasons_.push('positionedChild');
     67     if (args.positionedMovement)
     68       this.needsLayoutReasons_.push('positionedMovement');
     69     this.tableRow_ = args.row;
     70     this.tableCol_ = args.col;
     71     this.tableRowSpan_ = args.rowSpan;
     72     this.tableColSpan_ = args.colSpan;
     73 
     74     if (args.children) {
     75       args.children.forEach(function(child) {
     76         this.childLayoutObjects_.push(new LayoutObject(snapshot, child));
     77       }.bind(this));
     78     }
     79 
     80     for (var property in args) {
     81       if (!KNOWN_PROPERTIES[property])
     82         this.otherProperties_[property] = args[property];
     83     }
     84   }
     85 
     86   LayoutObject.prototype = {
     87     get snapshot() {
     88       return this.snapshot_;
     89     },
     90 
     91     get id() {
     92       return this.id_;
     93     },
     94 
     95     get name() {
     96       return this.name_;
     97     },
     98 
     99     get tag() {
    100       return this.tag_;
    101     },
    102 
    103     get relativeRect() {
    104       return this.relativeRect_;
    105     },
    106 
    107     get absoluteRect() {
    108       return this.absoluteRect_;
    109     },
    110 
    111     get isPositioned() {
    112       return this.isPositioned_;
    113     },
    114 
    115     get isFloat() {
    116       return this.isFloat_;
    117     },
    118 
    119     get isStickyPositioned() {
    120       return this.isStickyPositioned_;
    121     },
    122 
    123     get isRelativePositioned() {
    124       return this.isRelativePositioned_;
    125     },
    126 
    127     get isAnonymous() {
    128       return this.isAnonymous_;
    129     },
    130 
    131     get tableRow() {
    132       return this.tableRow_;
    133     },
    134 
    135     get tableCol() {
    136       return this.tableCol_;
    137     },
    138 
    139     get tableRowSpan() {
    140       return this.tableRowSpan_;
    141     },
    142 
    143     get tableColSpan() {
    144       return this.tableColSpan_;
    145     },
    146 
    147     get htmlId() {
    148       return this.htmlId_;
    149     },
    150 
    151     get classNames() {
    152       return this.classNames_;
    153     },
    154 
    155     get needsLayoutReasons() {
    156       return this.needsLayoutReasons_;
    157     },
    158 
    159     get hasChildLayoutObjects() {
    160       return this.childLayoutObjects_.length > 0;
    161     },
    162 
    163     get childLayoutObjects() {
    164       return this.childLayoutObjects_;
    165     },
    166 
    167     traverseTree: function(cb, opt_this) {
    168       cb.call(opt_this, this);
    169       if (!this.hasChildLayoutObjects)
    170         return;
    171       this.childLayoutObjects.forEach(function(child) {
    172         child.traverseTree(cb, opt_this);
    173       });
    174     },
    175 
    176     get otherPropertyNames() {
    177       var names = [];
    178       for (var name in this.otherProperties_) {
    179         names.push(name);
    180       }
    181       return names;
    182     },
    183 
    184     getProperty: function(name) {
    185       return this.otherProperties_[name];
    186     },
    187 
    188     get previousSnapshotLayoutObject() {
    189       if (!this.snapshot.previousSnapshot)
    190         return undefined;
    191       return this.snapshot.previousSnapshot.getLayoutObjectById(this.id);
    192     },
    193 
    194     get nextSnapshotLayoutObject() {
    195       if (!this.snapshot.nextSnapshot)
    196         return undefined;
    197       return this.snapshot.nextSnapshot.getLayoutObjectById(this.id);
    198     }
    199   };
    200 
    201   return {
    202     LayoutObject: LayoutObject
    203   };
    204 });
    205 </script>
    206