DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (74cd81b8ce)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Servo Layout Debugger</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet" />

    <!-- Treeview -->
    <link href="css/bootstrap-treeview.min.css" rel="stylesheet" />

    <!-- JSDiffPatch -->
    <link href="css/formatters/html.css" rel="stylesheet" />

    <!-- Custom -->
    <link href="css/main.css" rel="stylesheet" />

    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container" role="main">
      <div class="row">
        <div class="col-sm-12">
          <h1>Servo Layout Viewer</h1>
          <p>
            Check the
            <a
              href="https://github.com/servo/servo/blob/master/etc/layout_viewer/README.md"
              >README</a
            >
            for instructions.
          </p>
        </div>
      </div>
      <div class="row">
        <div class="col-sm-4">
          <div class="row">
            <div class="col-sm-12">
              <div class="well">
                <input type="file" />
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12">
              <div id="trace-tree"></div>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12">
              <ul id="trace-list" class="list-group"></ul>
            </div>
          </div>
        </div>
        <div class="col-sm-8">
          <div class="row">
            <div class="col-sm-12">
              <div class="panel panel-default">
                <div class="panel-heading">
                  Box Tree
                  <a
                    id="box-tree-collapse"
                    class="tree-collapse"
                    data-collapsed="0"
                  ></a>
                </div>
                <div class="panel-body" id="box-tree"></div>
              </div>
            </div>
            <div class="col-sm-12">
              <div id="box-diffs"></div>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12">
              <div class="panel panel-default">
                <div class="panel-heading">
                  Fragment Tree
                  <a
                    id="fragment-tree-collapse"
                    class="tree-collapse"
                    data-collapsed="0"
                  ></a>
                </div>
                <div class="panel-body" id="fragment-tree"></div>
              </div>
            </div>
            <div class="col-sm-12">
              <div id="fragment-diffs"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- Treeview -->
    <script src="js/bootstrap-treeview.min.js"></script>
    <!-- JSDiffPatch -->
    <script src="js/bundle.min.js"></script>
    <script src="js/formatters.min.js"></script>

    <script>
      function get_inner_boxes(box) {
        const box_type = Object.keys(box)[0];
        switch (box_type) {
          case "BlockLevelBoxes":
            return box.BlockLevelBoxes;
          case "InlineFormattingContext":
            return box.InlineFormattingContext.inline_level_boxes;
          case "InlineBox":
            return box.InlineBox.children;
          case "SameFormattingContextBlock":
          case "Independent":
          case "Flow":
          case "OutOfFlowAbsolutelyPositionedBox":
          case "OutOfFlowFloatBox":
          case "Atomic":
            return box[box_type].contents;
        }
        return null;
      }

      function box_tree_from_container(container) {
        const box_type = Object.keys(container)[0];
        let inner_boxes = get_inner_boxes(container);
        let nodes = [];
        let text = box_type;
        if (Array.isArray(inner_boxes)) {
          if (!inner_boxes.length) {
            nodes = null;
          } else {
            for (let box in inner_boxes) {
              nodes.push(box_tree_from_container(inner_boxes[box]));
            }
          }
        } else if (inner_boxes != null) {
          nodes.push(box_tree_from_container(inner_boxes));
        } else {
          if (box_type == "TextRun") {
            text += ` (${container.TextRun.text})`;
          }
          nodes = null;
        }

        let info;
        if (
          box_type != "BlockLevelBoxes" &&
          box_type != "InlineFormattingContext"
        ) {
          info = Object.assign({}, Object.values(container)[0]);
          delete info.children;
          delete info.contents;
          delete info.tag;
        }

        return {
          text,
          nodes,
          info
        };
      }

      function box_tree_from_bfc(bfc) {
        const { contains_floats, contents } = bfc;
        let block_container = Object.values(contents)[0];
        return {
          text: "BlockFormattingContext",
          info: {
            contains_floats
          },
          nodes: [box_tree_from_container(contents)]
        };
      }

      function create_fragment_tree(root) {
        let fragment = Object.values(root)[0];
        let node = {
          text: Object.keys(root)[0],
          id: fragment.debug_id,
          href: "#diff-" + fragment.debug_id
        };

        if (fragment.children) {
          let children = [];
          for (let i = 0; i < fragment.children.length; ++i) {
            children.push(create_fragment_tree(fragment.children[i]));
          }

          if (children.length > 0) {
            node.nodes = children;
          }
        }

        node.info = Object.assign({}, fragment);
        delete node.info.children;
        delete node.info.debug_id;

        return node;
      }

      function flatten_trace(trace_node) {
        const fragment_tree_root = Object.values(
          trace_node.fragment_tree.children
        )[0];
        return {
          fragment_tree: create_fragment_tree(fragment_tree_root),
          box_tree: box_tree_from_bfc(trace_node.box_tree)
        };
      }

      function create_trace_tree_node(trace_node) {
        const trace = flatten_trace(trace_node.pre);

        let tree_node = {
          text: trace_node.name,
          icon: "dummy",
          box_tree: trace.box_tree,
          fragment_tree: trace.fragment_tree
        };

        let node = Object.values(trace_node)[0];
        if (node.children) {
          let children = [];
          for (let i = 0; i < node.children.length; ++i) {
            children.push(create_trace_tree_node(node.children[i]));
          }

          if (children.length > 0) {
            tree_node.nodes = children;
          }
        }

        return tree_node;
      }

      function new_data_loaded(data) {
        jsondiffpatch.formatters.html.hideUnchanged();

        let node_color_hash = {};
        let tree = [create_trace_tree_node(data)];
        $("#trace-tree").treeview({ data: tree, levels: 3 });
        $("#trace-tree").on("nodeSelected", function(event, node) {
          $("#fragment-diffs").empty();
          $("#trace-tree")
            .treeview(true)
            .revealNode(node);

          const on_tree_node_selected = tree => (event, data) => {
            $(`#${tree}-diffs`).empty();
            if (!data.info) return;
            // XXX(ferjm) no diff for now.
            const delta = jsondiffpatch
              .create({
                objectHash: function(obj) {
                  return JSON.stringify(obj);
                }
              })
              .diff({}, data.info);

            const json = jsondiffpatch.formatters.html.format(delta, data.info);

            $(`#${tree}-diffs`).append(
              "<div class='panel panel-default'><div class='panel-heading'>" +
                data.text +
                "</div><div class='panel-body'>" +
                json +
                "</div></div>"
            );
          };

          const on_fragment_tree_node_selected = on_tree_node_selected(
            "fragment"
          );
          const on_box_tree_node_selected = on_tree_node_selected("box");

          $("#fragment-tree").treeview({
            data: [node.fragment_tree],
            levels: 100,
            enableLinks: false,
            emptyIcon: "glyphicon glyphicon-unchecked hidden-glyphicon",
            onNodeSelected: on_fragment_tree_node_selected
          });

          $("#box-tree").treeview({
            data: [node.box_tree],
            levels: 100,
            enableLinks: false,
            emptyIcon: "glyphicon glyphicon-unchecked hidden-glyphicon",
            onNodeSelected: on_box_tree_node_selected
          });

          ["fragment", "box"].forEach(key => {
            const collapsable = $(`#${key}-tree-collapse`);
            collapsable.html("Collapse all").on("click", () => {
              const collapsed = collapsable.data("collapsed");
              if (collapsed == 0) {
                $(`#${key}-tree`).treeview("collapseAll");
              } else {
                $(`#${key}-tree`).treeview("expandAll");
              }
              collapsable.html(collapsed == 0 ? "Expand all" : "Collapse all");
              collapsable.data("collapsed", collapsed == 0 ? 1 : 0);
            });
          });
        });

        $("#trace-tree")
          .treeview(true)
          .selectNode(0);
      }

      $(document).ready(function() {
        let upload = document.getElementsByTagName("input")[0];
        upload.onchange = function(e) {
          e.preventDefault();

          let file = upload.files[0],
            reader = new FileReader();
          reader.onload = function(event) {
            new_data_loaded(JSON.parse(event.target.result));
          };

          reader.readAsText(file);
          return false;
        };
      });
    </script>
  </body>
</html>