Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1032)

Unified Diff: chrome/browser/resources/tracing/timeline.js

Issue 10170001: Find feature for tracing, at long last. (Closed) Base URL: git://localhost/home/nduca/Local/chrome/src@master
Patch Set: patch for landing Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/tracing/tests.html ('k') | chrome/browser/resources/tracing/timeline_model.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/tracing/timeline.js
diff --git a/chrome/browser/resources/tracing/timeline.js b/chrome/browser/resources/tracing/timeline.js
index ef80c6e2255d0e005320e2752a6fa3367d633550..e38ec41671f64122dcf8e997cea21d0bb39454d8 100644
--- a/chrome/browser/resources/tracing/timeline.js
+++ b/chrome/browser/resources/tracing/timeline.js
@@ -194,6 +194,13 @@ cr.define('tracing', function() {
this.xPanWorldPosToViewPos(worldMax, 'right', viewWidth);
},
+ xSetWorldRange: function(worldMin, worldMax, viewWidth) {
+ var worldRange = worldMax - worldMin;
+ var scaleX = viewWidth / worldRange;
+ var panX = -worldMin;
+ this.setPanAndScale(panX, scaleX);
+ },
+
get gridEnabled() {
return this.gridEnabled_;
},
@@ -415,16 +422,28 @@ cr.define('tracing', function() {
// Set up a reasonable viewport.
this.viewport_.setWhenPossible(function() {
- var rangeTimestamp = this.model_.maxTimestamp -
- this.model_.minTimestamp;
var w = this.firstCanvas.width;
- var scaleX = w / rangeTimestamp;
- var panX = -this.model_.minTimestamp;
- this.viewport_.setPanAndScale(panX, scaleX);
+ this.viewport_.xSetWorldRange(this.model_.minTimestamp,
+ this.model_.maxTimestamp,
+ w);
}.bind(this));
},
/**
+ * @return {Array} An array of objects that match the provided
+ * TimelineFilter.
+ */
+ findAllObjectsMatchingFilter: function(filter) {
+ var hits = [];
+ for (var i = 0; i < this.tracks_.children.length; ++i) {
+ var trackHits =
+ this.tracks_.children[i].findAllObjectsMatchingFilter(filter);
+ Array.prototype.push.apply(hits, trackHits);
+ }
+ return hits;
+ },
+
+ /**
* @return {Element} The element whose focused state determines
* whether to respond to keyboard inputs.
* Defaults to the parent element.
@@ -444,6 +463,8 @@ cr.define('tracing', function() {
},
get listenToKeys_() {
+ if (!this.viewport_.isAttachedToDocument_)
+ return false;
if (!this.focusElement_)
return true;
if (this.focusElement.tabIndex >= 0)
@@ -586,6 +607,7 @@ cr.define('tracing', function() {
return false;
}
this.selection = selection;
+
// Potentially move the viewport to keep the new selection in view.
this.viewport_.xPanWorldRangeIntoView(minTime, maxTime,
this.firstCanvas.width);
@@ -630,6 +652,39 @@ cr.define('tracing', function() {
this.viewport_.dispatchChangeEvent(); // Triggers a redraw.
},
+ getSelectionRange: function() {
+ var wmin = Infinity;
+ var wmax = -wmin;
+ for (var i = 0; i < this.selection_.length; i++) {
+ var hit = this.selection_[i];
+ if (hit.slice) {
+ wmin = Math.min(wmin, hit.slice.start);
+ wmax = Math.max(wmax, hit.slice.end);
+ }
+ }
+ return {
+ min: wmin,
+ max: wmax
+ };
+ },
+
+ setSelectionAndMakeVisible: function(selection, zoomAllowed) {
+ this.selection = selection;
+ var range = this.getSelectionRange();
+ var size = this.viewport_.xWorldVectorToView(range.max - range.min);
+ if (zoomAllowed && size < 50) {
+ var worldCenter = range.min + (range.max - range.min) * 0.5;
+ var worldRange = (range.max - range.min) * 5;
+ this.viewport_.xSetWorldRange(worldCenter - worldRange * 0.5,
+ worldCenter + worldRange * 0.5,
+ this.firstCanvas.width);
+ return;
+ }
+
+ this.viewport_.xPanWorldRangeIntoView(range.min, range.max,
+ this.firstCanvas.width);
+ },
+
get firstCanvas() {
return this.tracks_.firstChild ?
this.tracks_.firstChild.firstCanvas : undefined;
« no previous file with comments | « chrome/browser/resources/tracing/tests.html ('k') | chrome/browser/resources/tracing/timeline_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698