OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2012 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 */ |
| 5 'use strict'; |
| 6 |
| 7 base.require('ui'); |
| 8 base.require('ui.list_view'); |
| 9 base.require('quad_view_viewport'); |
| 10 base.require('tree_quad_view'); |
| 11 base.requireStylesheet('lthi_view'); |
| 12 |
| 13 base.exportTo('ccfv', function() { |
| 14 |
| 15 var TreeQuadView = ccfv.TreeQuadView; |
| 16 |
| 17 var LTHIView = ui.define('x-lthi-view'); |
| 18 |
| 19 LTHIView.prototype = { |
| 20 __proto__: HTMLUnknownElement.prototype, |
| 21 |
| 22 decorate: function() { |
| 23 this.lthi_ = undefined; |
| 24 this.trees_ = document.createElement('x-trees'); |
| 25 |
| 26 this.viewport_ = undefined; |
| 27 |
| 28 var optionsEl = document.createElement('x-frame-view-options'); |
| 29 |
| 30 this.colorMapSelector_ = document.createElement('select'); |
| 31 this.colorMapSelector_.addEventListener( |
| 32 'change', this.onColorMapChanged_.bind(this)); |
| 33 ccfv.ALL_TILE_COLOR_MAPS.forEach(function(colorMap) { |
| 34 var mapOption = document.createElement('option'); |
| 35 mapOption.textContent = colorMap.title; |
| 36 mapOption.colorMap = colorMap; |
| 37 this.colorMapSelector_.appendChild(mapOption); |
| 38 }.bind(this)); |
| 39 optionsEl.appendChild(ui.createSpan('Color map:')); |
| 40 optionsEl.appendChild(this.colorMapSelector_); |
| 41 |
| 42 this.scaleSelector_ = document.createElement('select'); |
| 43 this.scaleSelector_.addEventListener( |
| 44 'change', this.onScaleChanged_.bind(this)); |
| 45 [1/32., 1/16., 1/8., 1/4, 1/2, 1].forEach(function(scale) { |
| 46 var mapOption = document.createElement('option'); |
| 47 mapOption.textContent = Math.floor(scale * 100) + '%'; |
| 48 mapOption.scale = scale; |
| 49 this.scaleSelector_.appendChild(mapOption); |
| 50 }.bind(this)); |
| 51 this.scaleSelector_.selectedIndex = 3; |
| 52 optionsEl.appendChild(ui.createSpan('Scale:')); |
| 53 optionsEl.appendChild(this.scaleSelector_); |
| 54 |
| 55 this.activeTreeQuadView_ = new TreeQuadView(); |
| 56 this.pendingTreeQuadView_ = new TreeQuadView(); |
| 57 this.inactiveTileView_ = new InactiveTileView(); |
| 58 |
| 59 this.onSelectionChanged_ = this.onSelectionChanged_.bind(this); |
| 60 this.activeTreeQuadView_.addEventListener('selection-changed', |
| 61 this.onSelectionChanged_); |
| 62 this.pendingTreeQuadView_.addEventListener('selection-changed', |
| 63 this.onSelectionChanged_); |
| 64 this.inactiveTileView_.addEventListener('selection-changed', |
| 65 this.onSelectionChanged_); |
| 66 |
| 67 this.trees_.appendChild(this.activeTreeQuadView_); |
| 68 this.trees_.appendChild(this.pendingTreeQuadView_); |
| 69 this.appendChild(optionsEl); |
| 70 this.appendChild(this.trees_); |
| 71 this.appendChild(this.inactiveTileView_); |
| 72 }, |
| 73 |
| 74 get lthi() { |
| 75 return this.lthi_; |
| 76 }, |
| 77 |
| 78 set lthi(lthi) { |
| 79 this.lthi_ = lthi; |
| 80 this.updateChildren_(); |
| 81 }, |
| 82 |
| 83 onColorMapChanged_: function() { |
| 84 this.activeTreeQuadView_.colorMap = |
| 85 this.colorMapSelector_.selectedOptions[0].colorMap; |
| 86 this.pendingTreeQuadView_.colorMap = |
| 87 this.colorMapSelector_.selectedOptions[0].colorMap; |
| 88 }, |
| 89 |
| 90 onScaleChanged_: function() { |
| 91 if (this.viewport_.scale) |
| 92 this.viewport_.scale = this.scaleSelector_.selectedOptions[0].scale; |
| 93 }, |
| 94 |
| 95 updateChildren_: function() { |
| 96 var lthi = this.lthi_; |
| 97 if (!lthi) { |
| 98 this.activeTreeQuadView_.tree = undefined; |
| 99 this.pendingTreeQuadView_.tree = undefined; |
| 100 this.viewport_ = undefined; |
| 101 return; |
| 102 } |
| 103 |
| 104 var bbox = new base.BBox2(); |
| 105 bbox.addBBox2(lthi.pendingTree.tileBBox); |
| 106 bbox.addBBox2(lthi.activeTree.tileBBox); |
| 107 |
| 108 if (!this.viewport_) { |
| 109 if (!bbox.isEmpty) { |
| 110 this.viewport_ = new ccfv.QuadViewViewport( |
| 111 lthi.history.allTilesBBox); |
| 112 this.viewport_.scale = this.scaleSelector_.selectedOptions[0].scale; |
| 113 this.activeTreeQuadView_.viewport = this.viewport_; |
| 114 this.pendingTreeQuadView_.viewport = this.viewport_; |
| 115 } else { |
| 116 return; |
| 117 } |
| 118 } |
| 119 |
| 120 this.activeTreeQuadView_.viewport.setWorldBBox(bbox); |
| 121 this.pendingTreeQuadView_.viewport.setWorldBBox(bbox); |
| 122 |
| 123 this.activeTreeQuadView_.which_tree = lthi.activeTree.which_tree; |
| 124 this.activeTreeQuadView_.tiles = lthi.activeTree.tiles; |
| 125 this.activeTreeQuadView_.headerText = |
| 126 'Active Tree: ' + lthi.activeTree.tiles.length + ' live tiles'; |
| 127 this.activeTreeQuadView_.deviceViewportSizeForFrame = |
| 128 lthi.deviceViewportSize; |
| 129 |
| 130 this.pendingTreeQuadView_.which_tree = lthi.pendingTree.which_tree; |
| 131 this.pendingTreeQuadView_.tiles = lthi.pendingTree.tiles; |
| 132 this.pendingTreeQuadView_.headerText = |
| 133 'Pending Tree: ' + lthi.pendingTree.tiles.length + ' live tiles'; |
| 134 this.pendingTreeQuadView_.deviceViewportSizeForFrame = |
| 135 lthi.deviceViewportSize; |
| 136 |
| 137 this.inactiveTileView_.tiles = lthi.inactiveTiles; |
| 138 }, |
| 139 |
| 140 onSelectionChanged_: function(e) { |
| 141 var e2 = new base.Event('selection-changed'); |
| 142 e2.selection = e.selection; |
| 143 this.dispatchEvent(e2); |
| 144 return true; |
| 145 } |
| 146 }; |
| 147 |
| 148 function InactiveTileViewSelection(view, tiles) { |
| 149 this.view = view; |
| 150 this.tiles = tiles; |
| 151 } |
| 152 |
| 153 InactiveTileViewSelection.prototype = { |
| 154 activate: function() { |
| 155 this.tiles.forEach(function(tile) { |
| 156 tile.selected = true; |
| 157 }); |
| 158 this.quad_view.viewport.didTileSelectednessChange(); |
| 159 try { |
| 160 this.view.ignoreChangeEvents_ = true; |
| 161 this.view.selectedTile = this.tiles[0]; |
| 162 } finally { |
| 163 this.view.ignoreChangeEvents_ = false; |
| 164 } |
| 165 }, |
| 166 |
| 167 deactivate: function() { |
| 168 this.tiles.forEach(function(tile) { |
| 169 tile.selected = false; |
| 170 }); |
| 171 this.quad_view.viewport.didTileSelectednessChange(); |
| 172 try { |
| 173 this.view.ignoreChangeEvents_ = true; |
| 174 this.view.selectedElement = undefined; |
| 175 } finally { |
| 176 this.view.ignoreChangeEvents_ = false; |
| 177 } |
| 178 } |
| 179 } |
| 180 |
| 181 var InactiveTileView = ui.define('x-inactive-tile-view'); |
| 182 |
| 183 InactiveTileView.prototype = { |
| 184 __proto__: HTMLUnknownElement.prototype, |
| 185 |
| 186 decorate: function() { |
| 187 this.viewport_ = undefined; |
| 188 this.tiles_ = undefined; |
| 189 this.header_ = document.createElement('div'); |
| 190 this.tileList_ = new ui.ListView(); |
| 191 this.ignoreChangeEvents_ = false; |
| 192 this.tileList_.addEventListener( |
| 193 'selection-changed', |
| 194 this.onSelectionChanged_.bind(this)); |
| 195 this.appendChild(this.header_); |
| 196 this.appendChild(this.tileList_); |
| 197 }, |
| 198 |
| 199 set viewport(viewport) { |
| 200 this.viewport_ = viewport; |
| 201 this.updateChildren_(); |
| 202 }, |
| 203 |
| 204 get viewport() { |
| 205 return this.viewport_; |
| 206 }, |
| 207 |
| 208 set tiles(tiles) { |
| 209 this.tiles_ = tiles; |
| 210 this.updateChildren_(); |
| 211 }, |
| 212 |
| 213 get tiles() { |
| 214 return this.tiles_; |
| 215 }, |
| 216 |
| 217 set selectedTile(tile) { |
| 218 for (var i = 0; i < this.tileList.children.length; i++) { |
| 219 if(this.tileList.children[i].tile == tile) { |
| 220 this.tileList.children[i].selected = true; |
| 221 return; |
| 222 } |
| 223 } |
| 224 throw new Error('Tile not found'); |
| 225 }, |
| 226 |
| 227 updateChildren_: function() { |
| 228 this.header_.textContent = ''; |
| 229 this.tileList_.textContent = ''; |
| 230 if (!this.tiles_) |
| 231 return; |
| 232 this.header_.textContent = this.tiles_.length + ' inactive tiles'; |
| 233 this.tileList_.textContent = ''; |
| 234 this.tiles_.forEach(function(tile) { |
| 235 var tileEl = document.createElement('div'); |
| 236 tileEl.tile = tile; |
| 237 tileEl.textContent = tile.id; |
| 238 tileEl.className = 'tile'; |
| 239 this.tileList_.appendChild(tileEl); |
| 240 }.bind(this)); |
| 241 }, |
| 242 |
| 243 onSelectionChanged_: function() { |
| 244 if (this.ignoreChangeEvents_) |
| 245 return; |
| 246 var tiles = []; |
| 247 if (this.tileList_.selectedElement) |
| 248 tiles.push(this.tileList_.selectedElement.tile); |
| 249 var selection = new InactiveTileViewSelection(this, tiles); |
| 250 var e = new base.Event('inactive-tile-selection-changed', true); |
| 251 e.selection = selection; |
| 252 this.dispatchEvent(e); |
| 253 } |
| 254 } |
| 255 |
| 256 return { |
| 257 LTHIView: LTHIView, |
| 258 InactiveTileView: InactiveTileView, |
| 259 } |
| 260 }); |
| 261 |
OLD | NEW |