Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / find_controller.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2012 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/filter.html">
9 <link rel="import" href="/tracing/selection.html">
10
11 <script>
12 'use strict';
13
14 /**
15  * @fileoverview FindController.
16  */
17 tvcm.exportTo('tracing', function() {
18   function FindController() {
19     this.timeline_ = undefined;
20     this.model_ = undefined;
21     this.filterText_ = '';
22     this.filterHits_ = new tracing.Selection();
23     this.filterHitsDirty_ = true;
24     this.currentHitIndex_ = -1;
25   };
26
27   FindController.prototype = {
28     __proto__: Object.prototype,
29
30     get timeline() {
31       return this.timeline_;
32     },
33
34     set timeline(t) {
35       this.timeline_ = t;
36       this.filterHitsDirty_ = true;
37     },
38
39     get filterText() {
40       return this.filterText_;
41     },
42
43     set filterText(f) {
44       if (f == this.filterText_)
45         return;
46       this.filterText_ = f;
47       this.filterHitsDirty_ = true;
48
49       if (!this.timeline)
50         return;
51
52       this.timeline.setHighlightAndClearSelection(this.filterHits);
53     },
54
55     get filterHits() {
56       if (this.filterHitsDirty_) {
57         this.filterHitsDirty_ = false;
58         this.filterHits_ = new tracing.Selection();
59         this.currentHitIndex_ = -1;
60
61         if (this.timeline_ && this.filterText.length) {
62           var filter = new tracing.TitleFilter(this.filterText);
63           this.timeline.addAllObjectsMatchingFilterToSelection(
64               filter, this.filterHits_);
65         }
66       }
67       return this.filterHits_;
68     },
69
70     get currentHitIndex() {
71       return this.currentHitIndex_;
72     },
73
74     find_: function(dir) {
75       var firstHit = this.currentHitIndex_ === -1;
76       if (firstHit && dir < 0)
77         this.currentHitIndex_ = 0;
78
79       var N = this.filterHits.length;
80       this.currentHitIndex_ = (this.currentHitIndex_ + dir + N) % N;
81
82       if (!this.timeline)
83         return;
84
85       this.timeline.selection =
86           this.filterHits.subSelection(this.currentHitIndex_, 1);
87     },
88
89     findNext: function() {
90       this.find_(1);
91     },
92
93     findPrevious: function() {
94       this.find_(-1);
95     },
96
97     reset: function() {
98       this.filterText_ = '';
99       this.filterHitsDirty_ = true;
100     }
101   };
102
103   return {
104     FindController: FindController
105   };
106 });
107 </script>