Commit 15e803c1 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Refactor View/PhaseView interfaces

Notry: true
Bug: v8:7327
Change-Id: I9cdea29db2b409d773a16e3d6c29ef4325257162
Reviewed-on: https://chromium-review.googlesource.com/c/1409437
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58815}
parent 78bd811e
...@@ -100,9 +100,6 @@ export class CodeView extends View { ...@@ -100,9 +100,6 @@ export class CodeView extends View {
mkVisible.apply(scrollIntoView); mkVisible.apply(scrollIntoView);
} }
initializeContent(data, rememberedSelection) {
}
getCodeHtmlElementName() { getCodeHtmlElementName() {
return `source-pre-${this.source.sourceId}`; return `source-pre-${this.source.sourceId}`;
} }
...@@ -126,7 +123,7 @@ export class CodeView extends View { ...@@ -126,7 +123,7 @@ export class CodeView extends View {
} }
} }
onSelectSourcePosition(sourcePosition, doClear) { onSelectSourcePosition(sourcePosition, doClear: boolean) {
if (doClear) { if (doClear) {
this.selectionHandler.clear(); this.selectionHandler.clear();
} }
...@@ -274,6 +271,4 @@ export class CodeView extends View { ...@@ -274,6 +271,4 @@ export class CodeView extends View {
} }
} }
deleteContent() { }
detachSelection() { return null; }
} }
...@@ -280,9 +280,9 @@ export class DisassemblyView extends TextView { ...@@ -280,9 +280,9 @@ export class DisassemblyView extends TextView {
} }
} }
initializeContent(data, rememberedSelection) { showContent(data): void {
console.time("disassembly-view"); console.time("disassembly-view");
super.initializeContent(data, rememberedSelection); super.initializeContent(data, null);
this.showInstructionAddressHandler(); this.showInstructionAddressHandler();
this.showInstructionBinaryHandler(); this.showInstructionBinaryHandler();
console.timeEnd("disassembly-view"); console.timeEnd("disassembly-view");
...@@ -347,4 +347,8 @@ export class DisassemblyView extends TextView { ...@@ -347,4 +347,8 @@ export class DisassemblyView extends TextView {
} }
detachSelection() { return null; } detachSelection() { return null; }
public searchInputAction(searchInput: HTMLInputElement, e: Event, onlyVisible: boolean): void {
throw new Error("Method not implemented.");
}
} }
...@@ -8,7 +8,7 @@ import { GNode, nodeToStr } from "../src/node"; ...@@ -8,7 +8,7 @@ import { GNode, nodeToStr } from "../src/node";
import { NODE_INPUT_WIDTH } from "../src/node"; import { NODE_INPUT_WIDTH } from "../src/node";
import { DEFAULT_NODE_BUBBLE_RADIUS } from "../src/node"; import { DEFAULT_NODE_BUBBLE_RADIUS } from "../src/node";
import { Edge, edgeToStr } from "../src/edge"; import { Edge, edgeToStr } from "../src/edge";
import { View, PhaseView } from "../src/view"; import { PhaseView } from "../src/view";
import { MySelection } from "../src/selection"; import { MySelection } from "../src/selection";
import { partial } from "../src/util"; import { partial } from "../src/util";
import { NodeSelectionHandler, ClearableHandler } from "./selection-handler"; import { NodeSelectionHandler, ClearableHandler } from "./selection-handler";
...@@ -28,7 +28,7 @@ interface GraphState { ...@@ -28,7 +28,7 @@ interface GraphState {
hideDead: boolean; hideDead: boolean;
} }
export class GraphView extends View implements PhaseView { export class GraphView extends PhaseView {
divElement: d3.Selection<any, any, any, any>; divElement: d3.Selection<any, any, any, any>;
svg: d3.Selection<any, any, any, any>; svg: d3.Selection<any, any, any, any>;
showPhaseByName: (p: string, s: Set<any>) => void; showPhaseByName: (p: string, s: Set<any>) => void;
...@@ -227,6 +227,7 @@ export class GraphView extends View implements PhaseView { ...@@ -227,6 +227,7 @@ export class GraphView extends View implements PhaseView {
} }
initializeContent(data, rememberedSelection) { initializeContent(data, rememberedSelection) {
this.show();
function createImgInput(id: string, title: string, onClick): HTMLElement { function createImgInput(id: string, title: string, onClick): HTMLElement {
const input = document.createElement("input"); const input = document.createElement("input");
input.setAttribute("id", id); input.setAttribute("id", id);
...@@ -267,11 +268,6 @@ export class GraphView extends View implements PhaseView { ...@@ -267,11 +268,6 @@ export class GraphView extends View implements PhaseView {
} }
} }
show(data, rememberedSelection): void {
this.container.appendChild(this.divNode);
this.initializeContent(data, rememberedSelection);
}
deleteContent() { deleteContent() {
for (const item of this.toolbox.querySelectorAll(".graph-toolbox-item")) { for (const item of this.toolbox.querySelectorAll(".graph-toolbox-item")) {
item.parentElement.removeChild(item); item.parentElement.removeChild(item);
...@@ -286,6 +282,11 @@ export class GraphView extends View implements PhaseView { ...@@ -286,6 +282,11 @@ export class GraphView extends View implements PhaseView {
this.updateGraphVisibility(); this.updateGraphVisibility();
} }
public hide(): void {
super.hide();
this.deleteContent();
}
createGraph(data, rememberedSelection) { createGraph(data, rememberedSelection) {
this.graph = new Graph(data); this.graph = new Graph(data);
...@@ -293,7 +294,7 @@ export class GraphView extends View implements PhaseView { ...@@ -293,7 +294,7 @@ export class GraphView extends View implements PhaseView {
if (rememberedSelection != undefined) { if (rememberedSelection != undefined) {
for (const n of this.graph.nodes()) { for (const n of this.graph.nodes()) {
n.visible = n.visible || rememberedSelection.has(nodeToStringKey(n); n.visible = n.visible || rememberedSelection.has(nodeToStringKey(n));
} }
} }
...@@ -559,7 +560,7 @@ export class GraphView extends View implements PhaseView { ...@@ -559,7 +560,7 @@ export class GraphView extends View implements PhaseView {
view.selectAllNodes(); view.selectAllNodes();
break; break;
case 38: case 38:
// UP // UP
case 40: { case 40: {
// DOWN // DOWN
showSelectionFrontierNodes(d3.event.keyCode == 38, undefined, true); showSelectionFrontierNodes(d3.event.keyCode == 38, undefined, true);
......
...@@ -28,7 +28,7 @@ export class GraphMultiView extends View { ...@@ -28,7 +28,7 @@ export class GraphMultiView extends View {
schedule: ScheduleView; schedule: ScheduleView;
sequence: SequenceView; sequence: SequenceView;
selectMenu: HTMLSelectElement; selectMenu: HTMLSelectElement;
currentPhaseView: View & PhaseView; currentPhaseView: PhaseView;
createViewElement() { createViewElement() {
const pane = document.createElement("div"); const pane = document.createElement("div");
...@@ -84,8 +84,8 @@ export class GraphMultiView extends View { ...@@ -84,8 +84,8 @@ export class GraphMultiView extends View {
}; };
} }
show(data, rememberedSelection) { show() {
super.show(data, rememberedSelection); super.show();
this.initializeSelect(); this.initializeSelect();
const lastPhaseIndex = +window.sessionStorage.getItem("lastSelectedPhase"); const lastPhaseIndex = +window.sessionStorage.getItem("lastSelectedPhase");
const initialPhaseIndex = this.sourceResolver.repairPhaseId(lastPhaseIndex); const initialPhaseIndex = this.sourceResolver.repairPhaseId(lastPhaseIndex);
...@@ -93,8 +93,6 @@ export class GraphMultiView extends View { ...@@ -93,8 +93,6 @@ export class GraphMultiView extends View {
this.displayPhase(this.sourceResolver.getPhase(initialPhaseIndex)); this.displayPhase(this.sourceResolver.getPhase(initialPhaseIndex));
} }
initializeContent() { }
displayPhase(phase, selection?: Set<any>) { displayPhase(phase, selection?: Set<any>) {
if (phase.type == "graph") { if (phase.type == "graph") {
this.displayPhaseView(this.graph, phase, selection); this.displayPhaseView(this.graph, phase, selection);
...@@ -105,9 +103,9 @@ export class GraphMultiView extends View { ...@@ -105,9 +103,9 @@ export class GraphMultiView extends View {
} }
} }
displayPhaseView(view, data, selection?: Set<any>) { displayPhaseView(view: PhaseView, data, selection?: Set<any>) {
const rememberedSelection = selection ? selection : this.hideCurrentPhase(); const rememberedSelection = selection ? selection : this.hideCurrentPhase();
view.show(data, rememberedSelection); view.initializeContent(data, rememberedSelection);
this.divNode.classList.toggle("scrollable", view.isScrollable()); this.divNode.classList.toggle("scrollable", view.isScrollable());
this.currentPhaseView = view; this.currentPhaseView = view;
} }
...@@ -132,10 +130,6 @@ export class GraphMultiView extends View { ...@@ -132,10 +130,6 @@ export class GraphMultiView extends View {
if (this.currentPhaseView) this.currentPhaseView.onresize(); if (this.currentPhaseView) this.currentPhaseView.onresize();
} }
deleteContent() {
this.hideCurrentPhase();
}
detachSelection() { detachSelection() {
return null; return null;
} }
......
...@@ -4,9 +4,6 @@ export class InfoView extends View { ...@@ -4,9 +4,6 @@ export class InfoView extends View {
constructor(idOrContainer: HTMLElement | string) { constructor(idOrContainer: HTMLElement | string) {
super(idOrContainer); super(idOrContainer);
}
initializeContent(data: any, rememberedSelection: Set<any>): void {
fetch("info-view.html") fetch("info-view.html")
.then(response => response.text()) .then(response => response.text())
.then(htmlText => this.divNode.innerHTML = htmlText); .then(htmlText => this.divNode.innerHTML = htmlText);
...@@ -17,12 +14,4 @@ export class InfoView extends View { ...@@ -17,12 +14,4 @@ export class InfoView extends View {
infoContainer.classList.add("info-container"); infoContainer.classList.add("info-container");
return infoContainer; return infoContainer;
} }
deleteContent(): void {
this.divNode.innerHTML = "";
}
detachSelection(): Set<string> {
return null;
}
} }
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
import { Schedule, SourceResolver } from "../src/source-resolver"; import { Schedule, SourceResolver } from "../src/source-resolver";
import { PhaseView } from "../src/view";
import { TextView } from "../src/text-view"; import { TextView } from "../src/text-view";
export class ScheduleView extends TextView implements PhaseView { export class ScheduleView extends TextView {
schedule: Schedule; schedule: Schedule;
sourceResolver: SourceResolver; sourceResolver: SourceResolver;
...@@ -41,6 +40,7 @@ export class ScheduleView extends TextView implements PhaseView { ...@@ -41,6 +40,7 @@ export class ScheduleView extends TextView implements PhaseView {
this.schedule = data.schedule; this.schedule = data.schedule;
this.addBlocks(data.schedule.blocks); this.addBlocks(data.schedule.blocks);
this.attachSelection(rememberedSelection); this.attachSelection(rememberedSelection);
this.show();
} }
createElementFromString(htmlString) { createElementFromString(htmlString) {
...@@ -183,6 +183,4 @@ export class ScheduleView extends TextView implements PhaseView { ...@@ -183,6 +183,4 @@ export class ScheduleView extends TextView implements PhaseView {
} }
this.selectionHandler.select(select, true); this.selectionHandler.select(select, true);
} }
onresize() { }
} }
...@@ -4,10 +4,9 @@ ...@@ -4,10 +4,9 @@
import { Sequence } from "../src/source-resolver"; import { Sequence } from "../src/source-resolver";
import { isIterable } from "../src/util"; import { isIterable } from "../src/util";
import { PhaseView } from "../src/view";
import { TextView } from "../src/text-view"; import { TextView } from "../src/text-view";
export class SequenceView extends TextView implements PhaseView { export class SequenceView extends TextView {
sequence: Sequence; sequence: Sequence;
searchInfo: Array<any>; searchInfo: Array<any>;
...@@ -49,6 +48,7 @@ export class SequenceView extends TextView implements PhaseView { ...@@ -49,6 +48,7 @@ export class SequenceView extends TextView implements PhaseView {
}); });
this.addBlocks(this.sequence.blocks); this.addBlocks(this.sequence.blocks);
this.attachSelection(rememberedSelection); this.attachSelection(rememberedSelection);
this.show();
} }
elementForBlock(block) { elementForBlock(block) {
...@@ -239,6 +239,4 @@ export class SequenceView extends TextView implements PhaseView { ...@@ -239,6 +239,4 @@ export class SequenceView extends TextView implements PhaseView {
} }
this.selectionHandler.select(select, true); this.selectionHandler.select(select, true);
} }
onresize() { }
} }
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import { View } from "../src/view"; import { PhaseView } from "../src/view";
import { anyToString, ViewElements, isIterable } from "../src/util"; import { anyToString, ViewElements, isIterable } from "../src/util";
import { MySelection } from "../src/selection"; import { MySelection } from "../src/selection";
import { SourceResolver } from "./source-resolver"; import { SourceResolver } from "./source-resolver";
import { SelectionBroker } from "./selection-broker"; import { SelectionBroker } from "./selection-broker";
import { NodeSelectionHandler, BlockSelectionHandler } from "./selection-handler"; import { NodeSelectionHandler, BlockSelectionHandler } from "./selection-handler";
export abstract class TextView extends View { export abstract class TextView extends PhaseView {
selectionHandler: NodeSelectionHandler; selectionHandler: NodeSelectionHandler;
blockSelectionHandler: BlockSelectionHandler; blockSelectionHandler: BlockSelectionHandler;
selection: MySelection; selection: MySelection;
...@@ -161,9 +161,8 @@ export abstract class TextView extends View { ...@@ -161,9 +161,8 @@ export abstract class TextView extends View {
} }
clearText() { clearText() {
const view = this; while (this.textListNode.firstChild) {
while (view.textListNode.firstChild) { this.textListNode.removeChild(this.textListNode.firstChild);
view.textListNode.removeChild(view.textListNode.firstChild);
} }
} }
...@@ -240,13 +239,12 @@ export abstract class TextView extends View { ...@@ -240,13 +239,12 @@ export abstract class TextView extends View {
} }
initializeContent(data, rememberedSelection) { initializeContent(data, rememberedSelection) {
const view = this; this.clearText();
view.clearText(); this.processText(data);
view.processText(data); this.show();
} }
deleteContent() { public onresize(): void {}
}
isScrollable() { isScrollable() {
return true; return true;
......
...@@ -13,11 +13,11 @@ import * as C from "../src/constants"; ...@@ -13,11 +13,11 @@ import * as C from "../src/constants";
import { InfoView } from "./info-view"; import { InfoView } from "./info-view";
window.onload = function () { window.onload = function () {
let multiview = null; let multiview: GraphMultiView = null;
let disassemblyView = null; let disassemblyView: DisassemblyView = null;
let sourceViews = []; let sourceViews: Array<CodeView> = [];
let selectionBroker = null; let selectionBroker: SelectionBroker = null;
let sourceResolver = null; let sourceResolver: SourceResolver = null;
const resizer = new Resizer(panesUpdatedCallback, 100); const resizer = new Resizer(panesUpdatedCallback, 100);
const sourceTabsContainer = document.getElementById(C.SOURCE_PANE_ID); const sourceTabsContainer = document.getElementById(C.SOURCE_PANE_ID);
const sourceTabs = new Tabs(sourceTabsContainer); const sourceTabs = new Tabs(sourceTabsContainer);
...@@ -29,7 +29,7 @@ window.onload = function () { ...@@ -29,7 +29,7 @@ window.onload = function () {
infoTab.classList.add("persistent-tab"); infoTab.classList.add("persistent-tab");
infoContainer.classList.add("viewpane", "scrollable"); infoContainer.classList.add("viewpane", "scrollable");
const infoView = new InfoView(infoContainer); const infoView = new InfoView(infoContainer);
infoView.show(null, null); infoView.show();
sourceTabs.activateTab(infoTab); sourceTabs.activateTab(infoTab);
function panesUpdatedCallback() { function panesUpdatedCallback() {
...@@ -80,12 +80,12 @@ window.onload = function () { ...@@ -80,12 +80,12 @@ window.onload = function () {
sourceContainer.classList.add("viewpane", "scrollable"); sourceContainer.classList.add("viewpane", "scrollable");
sourceTabs.activateTab(sourceTab); sourceTabs.activateTab(sourceTab);
const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE); const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, fnc, CodeMode.MAIN_SOURCE);
sourceView.show(null, null); sourceView.show();
sourceViews.push(sourceView); sourceViews.push(sourceView);
sourceResolver.forEachSource(source => { sourceResolver.forEachSource(source => {
const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE); const sourceView = new CodeView(sourceContainer, selectionBroker, sourceResolver, source, CodeMode.INLINED_SOURCE);
sourceView.show(null, null); sourceView.show();
sourceViews.push(sourceView); sourceViews.push(sourceView);
}); });
...@@ -96,11 +96,12 @@ window.onload = function () { ...@@ -96,11 +96,12 @@ window.onload = function () {
disassemblyView.initializeCode(fnc.sourceText); disassemblyView.initializeCode(fnc.sourceText);
if (sourceResolver.disassemblyPhase) { if (sourceResolver.disassemblyPhase) {
disassemblyView.initializePerfProfile(jsonObj.eventCounts); disassemblyView.initializePerfProfile(jsonObj.eventCounts);
disassemblyView.show(sourceResolver.disassemblyPhase.data, null); disassemblyView.showContent(sourceResolver.disassemblyPhase.data);
disassemblyView.show();
} }
multiview = new GraphMultiView(C.INTERMEDIATE_PANE_ID, selectionBroker, sourceResolver); multiview = new GraphMultiView(C.INTERMEDIATE_PANE_ID, selectionBroker, sourceResolver);
multiview.show(jsonObj); multiview.show();
} catch (err) { } catch (err) {
if (window.confirm("Error: Exception during load of TurboFan JSON file:\n" + if (window.confirm("Error: Exception during load of TurboFan JSON file:\n" +
"error: " + err.message + "\nDo you want to clear session storage?")) { "error: " + err.message + "\nDo you want to clear session storage?")) {
......
...@@ -3,34 +3,35 @@ ...@@ -3,34 +3,35 @@
// found in the LICENSE file. // found in the LICENSE file.
export abstract class View { export abstract class View {
container: HTMLElement; protected container: HTMLElement;
divNode: HTMLElement; protected divNode: HTMLElement;
abstract initializeContent(data: any, rememberedSelection: Set<any>): void; protected abstract createViewElement(): HTMLElement;
abstract createViewElement(): HTMLElement;
abstract deleteContent(): void;
abstract detachSelection(): Set<string>;
constructor(idOrContainer: string | HTMLElement) { constructor(idOrContainer: string | HTMLElement) {
this.container = typeof idOrContainer == "string" ? document.getElementById(idOrContainer) : idOrContainer; this.container = typeof idOrContainer == "string" ? document.getElementById(idOrContainer) : idOrContainer;
this.divNode = this.createViewElement(); this.divNode = this.createViewElement();
} }
isScrollable(): boolean { public show(): void {
return false;
}
show(data: any, rememberedSelection: Set<any>): void {
this.initializeContent(data, rememberedSelection);
this.container.appendChild(this.divNode); this.container.appendChild(this.divNode);
} }
hide(): void { public hide(): void {
this.container.removeChild(this.divNode); this.container.removeChild(this.divNode);
this.deleteContent();
} }
} }
export interface PhaseView { export abstract class PhaseView extends View {
onresize(): void; public abstract initializeContent(data: any, rememberedSelection: Set<any>): void;
searchInputAction(searchInput: HTMLInputElement, e: Event, onlyVisible: boolean): void; public abstract detachSelection(): Set<string>;
public abstract onresize(): void;
public abstract searchInputAction(searchInput: HTMLInputElement, e: Event, onlyVisible: boolean): void;
constructor(idOrContainer: string | HTMLElement) {
super(idOrContainer);
}
public isScrollable(): boolean {
return false;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment