tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / inspector / front-end / ConsolePanel.js
1 /*
2  * Copyright (C) 2009 Joseph Pecoraro
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /**
30  * @constructor
31  * @extends {WebInspector.Panel}
32  */
33 WebInspector.ConsolePanel = function()
34 {
35     WebInspector.Panel.call(this, "console");
36
37     WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.EntryAdded, this._consoleMessageAdded, this);
38     WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.ConsoleCleared, this._consoleCleared, this);
39     this._view = WebInspector.consoleView;
40 }
41
42 WebInspector.ConsolePanel.prototype = {
43     get toolbarItemLabel()
44     {
45         return WebInspector.UIString("Console");
46     },
47
48     get statusBarItems()
49     {
50         return this._view.statusBarItems;
51     },
52
53     wasShown: function()
54     {
55         WebInspector.Panel.prototype.wasShown.call(this);
56         if (WebInspector.drawer.visible) {
57             WebInspector.drawer.hide(WebInspector.Drawer.AnimationType.Immediately);
58             this._drawerWasVisible = true;
59         }
60         this._view.show(this.element);
61     },
62
63     willHide: function()
64     {
65         if (this._drawerWasVisible) {
66             WebInspector.drawer.show(this._view, WebInspector.Drawer.AnimationType.Immediately);
67             delete this._drawerWasVisible;
68         }
69         WebInspector.Panel.prototype.willHide.call(this);
70     },
71
72     searchCanceled: function()
73     {
74         this._clearCurrentSearchResultHighlight();
75         delete this._searchResults;
76         delete this._searchRegex;
77     },
78
79     performSearch: function(query)
80     {
81         WebInspector.searchController.updateSearchMatchesCount(0, this);
82         this.searchCanceled();
83         this._searchRegex = createPlainTextSearchRegex(query, "gi");
84
85         this._searchResults = [];
86         var messages = WebInspector.consoleView.messages;
87         for (var i = 0; i < messages.length; i++) {
88             if (messages[i].matchesRegex(this._searchRegex)) {
89                 this._searchResults.push(messages[i]);
90                 this._searchRegex.lastIndex = 0;
91             }
92         }
93         WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
94         this._currentSearchResultIndex = -1;
95         if (this._searchResults.length)
96             this._jumpToSearchResult(0);
97     },
98
99     jumpToNextSearchResult: function()
100     {
101         if (!this._searchResults || !this._searchResults.length)
102             return;
103         this._jumpToSearchResult((this._currentSearchResultIndex + 1) % this._searchResults.length);
104     },
105
106     jumpToPreviousSearchResult: function()
107     {
108         if (!this._searchResults || !this._searchResults.length)
109             return;
110         var index = this._currentSearchResultIndex - 1;
111         if (index === -1)
112             index = this._searchResults.length - 1;
113         this._jumpToSearchResult(index);
114     },
115
116     _clearCurrentSearchResultHighlight: function()
117     {
118         if (!this._searchResults)
119             return;
120         var highlightedMessage = this._searchResults[this._currentSearchResultIndex];
121         if (highlightedMessage)
122             highlightedMessage.clearHighlight();
123         this._currentSearchResultIndex = -1;
124     },
125
126     _jumpToSearchResult: function(index)
127     {
128         this._clearCurrentSearchResultHighlight();
129         this._currentSearchResultIndex = index;
130         this._searchResults[index].highlightSearchResults(this._searchRegex);
131     },
132
133     _consoleMessageAdded: function(event)
134     {
135         if (!this._searchRegex || !this.isShowing())
136             return;
137         var message = event.data;
138         this._searchRegex.lastIndex = 0;
139         if (message.matchesRegex(this._searchRegex)) {
140             this._searchResults.push(message);
141             WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
142         }
143     },
144
145     _consoleCleared: function()
146     {
147         if (!this._searchResults)
148             return;
149         this._clearCurrentSearchResultHighlight();
150         this._searchResults.length = 0;
151         if (this.isShowing())
152             WebInspector.searchController.updateSearchMatchesCount(0, this);
153     }
154 }
155
156 WebInspector.ConsolePanel.prototype.__proto__ = WebInspector.Panel.prototype;