ac9836a500e0bce7d48ee14a77baf1a0aaa9e9fb
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ClusterContentView.js
1 /*
2  * Copyright (C) 2013 Apple Inc. All rights reserved.
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  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WebInspector.ClusterContentView = function(representedObject)
27 {
28     WebInspector.ContentView.call(this, representedObject);
29
30     this.element.classList.add(WebInspector.ClusterContentView.StyleClassName);
31
32     this._contentViewContainer = new WebInspector.ContentViewContainer();
33     this._contentViewContainer.addEventListener(WebInspector.ContentViewContainer.Event.CurrentContentViewDidChange, this._currentContentViewDidChange, this);
34     this.element.appendChild(this._contentViewContainer.element);
35
36     WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.SelectionPathComponentsDidChange, this._contentViewSelectionPathComponentDidChange, this);
37     WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange, this._contentViewSupplementalRepresentedObjectsDidChange, this);
38     WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange, this._contentViewNumberOfSearchResultsDidChange, this);
39 };
40
41 WebInspector.ClusterContentView.StyleClassName = "cluster";
42
43 WebInspector.ClusterContentView.prototype = {
44     constructor: WebInspector.ClusterContentView,
45
46     // Public
47
48     get navigationItems()
49     {
50         var currentContentView = this._contentViewContainer.currentContentView;
51         return currentContentView ? currentContentView.navigationItems : [];
52     },
53
54     get contentViewContainer()
55     {
56         return this._contentViewContainer;
57     },
58
59     get supportsSplitContentBrowser()
60     {
61         if (this._contentViewContainer.currentContentView)
62             return this._contentViewContainer.currentContentView.supportsSplitContentBrowser;
63         return true;
64     },
65
66     updateLayout: function()
67     {
68         var currentContentView = this._contentViewContainer.currentContentView;
69         if (currentContentView)
70             currentContentView.updateLayout();
71     },
72
73     shown: function()
74     {
75         this._contentViewContainer.shown();
76     },
77
78     hidden: function()
79     {
80         this._contentViewContainer.hidden();
81     },
82
83     closed: function()
84     {
85         this._contentViewContainer.closeAllContentViews();
86
87         WebInspector.ContentView.removeEventListener(WebInspector.ContentView.Event.SelectionPathComponentsDidChange, this._contentViewSelectionPathComponentDidChange, this);
88         WebInspector.ContentView.removeEventListener(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange, this._contentViewSupplementalRepresentedObjectsDidChange, this);
89         WebInspector.ContentView.removeEventListener(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange, this._contentViewNumberOfSearchResultsDidChange, this);
90     },
91
92     canGoBack: function()
93     {
94         return this._contentViewContainer.canGoBack();
95     },
96
97     canGoForward: function()
98     {
99         return this._contentViewContainer.canGoForward();
100     },
101
102     goBack: function()
103     {
104         this._contentViewContainer.goBack();
105     },
106
107     goForward: function()
108     {
109         this._contentViewContainer.goForward();
110     },
111
112     get selectionPathComponents()
113     {
114         if (!this._contentViewContainer.currentContentView)
115             return [];
116         return this._contentViewContainer.currentContentView.selectionPathComponents;
117     },
118
119     get supplementalRepresentedObjects()
120     {
121         if (!this._contentViewContainer.currentContentView)
122             return [];
123         return this._contentViewContainer.currentContentView.supplementalRepresentedObjects;
124     },
125
126     get handleCopyEvent()
127     {
128         var currentContentView = this._contentViewContainer.currentContentView;
129         return currentContentView && typeof currentContentView.handleCopyEvent === "function" ? currentContentView.handleCopyEvent.bind(currentContentView) : null;
130     },
131
132     get supportsSave()
133     {
134         var currentContentView = this._contentViewContainer.currentContentView;
135         return currentContentView && currentContentView.supportsSave;
136     },
137
138     get saveData()
139     {
140         var currentContentView = this._contentViewContainer.currentContentView;
141         return currentContentView && currentContentView.saveData || null;
142     },
143
144     get supportsSearch()
145     {
146         // Always return true so we can intercept the search query to resend it when switching content views.
147         return true;
148     },
149
150     get numberOfSearchResults()
151     {
152         var currentContentView = this._contentViewContainer.currentContentView;
153         if (!currentContentView || !currentContentView.supportsSearch)
154             return null;
155         return currentContentView.numberOfSearchResults;
156     },
157
158     get hasPerformedSearch()
159     {
160         var currentContentView = this._contentViewContainer.currentContentView;
161         if (!currentContentView || !currentContentView.supportsSearch)
162             return false;
163         return currentContentView.hasPerformedSearch;
164     },
165
166     set automaticallyRevealFirstSearchResult(reveal)
167     {
168         var currentContentView = this._contentViewContainer.currentContentView;
169         if (!currentContentView || !currentContentView.supportsSearch)
170             return;
171         currentContentView.automaticallyRevealFirstSearchResult = reveal;
172     },
173
174     performSearch: function(query)
175     {
176         this._searchQuery = query;
177
178         var currentContentView = this._contentViewContainer.currentContentView;
179         if (!currentContentView || !currentContentView.supportsSearch)
180             return;
181         currentContentView.performSearch(query);
182     },
183
184     searchCleared: function()
185     {
186         this._searchQuery = null;
187
188         var currentContentView = this._contentViewContainer.currentContentView;
189         if (!currentContentView || !currentContentView.supportsSearch)
190             return;
191         currentContentView.searchCleared();
192     },
193
194     searchQueryWithSelection: function()
195     {
196         var currentContentView = this._contentViewContainer.currentContentView;
197         if (!currentContentView || !currentContentView.supportsSearch)
198             return null;
199         return currentContentView.searchQueryWithSelection();
200     },
201
202     revealPreviousSearchResult: function(changeFocus)
203     {
204         var currentContentView = this._contentViewContainer.currentContentView;
205         if (!currentContentView || !currentContentView.supportsSearch)
206             return;
207         currentContentView.revealPreviousSearchResult(changeFocus);
208     },
209
210     revealNextSearchResult: function(changeFocus)
211     {
212         var currentContentView = this._contentViewContainer.currentContentView;
213         if (!currentContentView || !currentContentView.supportsSearch)
214             return;
215         currentContentView.revealNextSearchResult(changeFocus);
216     },
217
218     // Private
219
220     _currentContentViewDidChange: function(event)
221     {
222         var currentContentView = this._contentViewContainer.currentContentView;
223         if (currentContentView && currentContentView.supportsSearch) {
224             if (this._searchQuery)
225                 currentContentView.performSearch(this._searchQuery);
226             else
227                 currentContentView.searchCleared();
228         }
229
230         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
231         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
232         this.dispatchEventToListeners(WebInspector.ContentView.Event.NavigationItemsDidChange);
233     },
234
235     _contentViewSelectionPathComponentDidChange: function(event)
236     {
237         if (event.target !== this._contentViewContainer.currentContentView)
238             return;
239         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
240     },
241
242     _contentViewSupplementalRepresentedObjectsDidChange: function(event)
243     {
244         if (event.target !== this._contentViewContainer.currentContentView)
245             return;
246         this.dispatchEventToListeners(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange);
247     },
248
249     _contentViewNumberOfSearchResultsDidChange: function(event)
250     {
251         if (event.target !== this._contentViewContainer.currentContentView)
252             return;
253         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
254     }
255 };
256
257 WebInspector.ClusterContentView.prototype.__proto__ = WebInspector.ContentView.prototype;