OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var chrome; | 5 var chrome; |
6 if (!chrome) | 6 if (!chrome) |
7 chrome = {}; | 7 chrome = {}; |
8 if (!chrome.searchBox) { | 8 if (!chrome.searchBox) { |
9 chrome.searchBox = new function() { | 9 chrome.searchBox = new function() { |
10 // ========================================================================= | 10 // ========================================================================= |
(...skipping 13 matching lines...) Expand all Loading... | |
24 native function GetVerbatim(); | 24 native function GetVerbatim(); |
25 native function GetSelectionStart(); | 25 native function GetSelectionStart(); |
26 native function GetSelectionEnd(); | 26 native function GetSelectionEnd(); |
27 native function GetX(); | 27 native function GetX(); |
28 native function GetY(); | 28 native function GetY(); |
29 native function GetWidth(); | 29 native function GetWidth(); |
30 native function GetHeight(); | 30 native function GetHeight(); |
31 native function GetAutocompleteResults(); | 31 native function GetAutocompleteResults(); |
32 native function GetIsFocused(); | 32 native function GetIsFocused(); |
33 native function GetContext(); | 33 native function GetContext(); |
34 native function GetThemeBackgroundInfo(); | |
35 native function GetThemeAreaHeight(); | |
34 native function NavigateContentWindow(); | 36 native function NavigateContentWindow(); |
35 native function SetSuggestions(); | 37 native function SetSuggestions(); |
36 native function SetQuerySuggestion(); | 38 native function SetQuerySuggestion(); |
37 native function SetQuerySuggestionFromAutocompleteResult(); | 39 native function SetQuerySuggestionFromAutocompleteResult(); |
38 native function SetQuery(); | 40 native function SetQuery(); |
39 native function SetQueryFromAutocompleteResult(); | 41 native function SetQueryFromAutocompleteResult(); |
40 native function Show(); | 42 native function Show(); |
41 | 43 |
42 // Returns the |restrictedText| wrapped in a ShadowDOM. | 44 // Returns the |restrictedText| wrapped in a ShadowDOM. |
43 function SafeWrap(restrictedText) { | 45 function SafeWrap(restrictedText) { |
44 var node = document.createElement('div'); | 46 var node = document.createElement('div'); |
45 var nodeShadow = new WebKitShadowRoot(node); | 47 var nodeShadow = new WebKitShadowRoot(node); |
46 nodeShadow.applyAuthorStyles = true; | 48 nodeShadow.applyAuthorStyles = true; |
47 nodeShadow.innerHTML = | 49 nodeShadow.innerHTML = |
48 '<div style="width:700px!important;' + | 50 '<div style="width:700px!important;' + |
49 ' height:22px!important;' + | 51 ' height:22px!important;' + |
50 ' font-family:\'Chrome Droid Sans\',\'Arial\'!important;' + | 52 ' font-family:\'Chrome Droid Sans\',\'Arial\'!important;' + |
51 ' overflow:hidden!important;' + | 53 ' overflow:hidden!important;' + |
52 ' text-overflow:ellipsis!important">' + | 54 ' text-overflow:ellipsis!important">' + |
53 ' <nobr>' + restrictedText + '</nobr>' + | 55 ' <nobr>' + restrictedText + '</nobr>' + |
54 '</div>'; | 56 '</div>'; |
55 return node; | 57 return node; |
56 } | 58 } |
57 | 59 |
58 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that | 60 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that |
59 // the JS cannot access them and deletes the raw values. | 61 // the JS cannot access them and deletes the raw values. |
60 function GetAutocompleteResultsWrapper() { | 62 function GetAutocompleteResultsWrapper() { |
61 var autocompleteResults = DedupeAutcompleteResults( | 63 var autocompleteResults = DedupeAutocompleteResults( |
62 GetAutocompleteResults()); | 64 GetAutocompleteResults()); |
63 var userInput = GetQuery(); | 65 var userInput = GetQuery(); |
64 for (var i = 0, result; result = autocompleteResults[i]; ++i) { | 66 for (var i = 0, result; result = autocompleteResults[i]; ++i) { |
65 var title = result.contents; | 67 var title = result.contents; |
66 var url = CleanUrl(result.destination_url, userInput); | 68 var url = CleanUrl(result.destination_url, userInput); |
67 var combinedHtml = '<span class=chrome_url>' + url + '</span>'; | 69 var combinedHtml = '<span class=chrome_url>' + url + '</span>'; |
68 if (title) { | 70 if (title) { |
69 result.titleNode = SafeWrap(title); | 71 result.titleNode = SafeWrap(title); |
70 combinedHtml += '<span class=chrome_separator> – </span>' + | 72 combinedHtml += '<span class=chrome_separator> – </span>' + |
71 '<span class=chrome_title>' + title + '</span>'; | 73 '<span class=chrome_title>' + title + '</span>'; |
(...skipping 18 matching lines...) Expand all Loading... | |
90 return url.replace(WWW_REGEX, ''); | 92 return url.replace(WWW_REGEX, ''); |
91 } | 93 } |
92 | 94 |
93 // TODO(dcblack): Do this in C++ instead of JS. | 95 // TODO(dcblack): Do this in C++ instead of JS. |
94 function CanonicalizeUrl(url) { | 96 function CanonicalizeUrl(url) { |
95 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); | 97 return url.replace(HTTP_REGEX, '').replace(WWW_REGEX, ''); |
96 } | 98 } |
97 | 99 |
98 // Removes duplicates from AutocompleteResults. | 100 // Removes duplicates from AutocompleteResults. |
99 // TODO(dcblack): Do this in C++ instead of JS. | 101 // TODO(dcblack): Do this in C++ instead of JS. |
100 function DedupeAutcompleteResults(autocompleteResults) { | 102 function DedupeAutocompleteResults(autocompleteResults) { |
101 var urlToResultMap = {}; | 103 var urlToResultMap = {}; |
102 for (var i = 0, result; result = autocompleteResults[i]; ++i) { | 104 for (var i = 0, result; result = autocompleteResults[i]; ++i) { |
103 var url = CanonicalizeUrl(result.destination_url); | 105 var url = CanonicalizeUrl(result.destination_url); |
104 if (url in urlToResultMap) { | 106 if (url in urlToResultMap) { |
105 var oldRelevance = urlToResultMap[url].rankingData.relevance; | 107 var oldRelevance = urlToResultMap[url].rankingData.relevance; |
106 var newRelevance = result.rankingData.relevance; | 108 var newRelevance = result.rankingData.relevance; |
107 if (newRelevance > oldRelevance) { | 109 if (newRelevance > oldRelevance) { |
108 urlToResultMap[url] = result; | 110 urlToResultMap[url] = result; |
109 } | 111 } |
110 } else { | 112 } else { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 this.__defineGetter__('verbatim', GetVerbatim); | 172 this.__defineGetter__('verbatim', GetVerbatim); |
171 this.__defineGetter__('selectionStart', GetSelectionStart); | 173 this.__defineGetter__('selectionStart', GetSelectionStart); |
172 this.__defineGetter__('selectionEnd', GetSelectionEnd); | 174 this.__defineGetter__('selectionEnd', GetSelectionEnd); |
173 this.__defineGetter__('x', GetX); | 175 this.__defineGetter__('x', GetX); |
174 this.__defineGetter__('y', GetY); | 176 this.__defineGetter__('y', GetY); |
175 this.__defineGetter__('width', GetWidth); | 177 this.__defineGetter__('width', GetWidth); |
176 this.__defineGetter__('height', GetHeight); | 178 this.__defineGetter__('height', GetHeight); |
177 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); | 179 this.__defineGetter__('nativeSuggestions', GetAutocompleteResultsWrapper); |
178 this.__defineGetter__('isFocused', GetIsFocused); | 180 this.__defineGetter__('isFocused', GetIsFocused); |
179 this.__defineGetter__('context', GetContext); | 181 this.__defineGetter__('context', GetContext); |
182 this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo); | |
183 this.__defineGetter__('themeAreaHeight', GetThemeAreaHeight); | |
David Black
2012/11/16 00:57:17
Why isn't the theme area height part of the return
kuan
2012/11/16 01:10:03
the height changes a lot more: when browser window
| |
180 this.setSuggestions = function(text) { | 184 this.setSuggestions = function(text) { |
181 SetSuggestions(text); | 185 SetSuggestions(text); |
182 }; | 186 }; |
183 this.setAutocompleteText = function(text, behavior) { | 187 this.setAutocompleteText = function(text, behavior) { |
184 SetQuerySuggestion(text, behavior); | 188 SetQuerySuggestion(text, behavior); |
185 }; | 189 }; |
186 this.setRestrictedAutocompleteText = function(resultId) { | 190 this.setRestrictedAutocompleteText = function(resultId) { |
187 SetQuerySuggestionFromAutocompleteResult(resultId); | 191 SetQuerySuggestionFromAutocompleteResult(resultId); |
188 }; | 192 }; |
189 this.setValue = function(text, type) { | 193 this.setValue = function(text, type) { |
(...skipping 15 matching lines...) Expand all Loading... | |
205 this.onsubmit = null; | 209 this.onsubmit = null; |
206 this.oncancel = null; | 210 this.oncancel = null; |
207 this.onresize = null; | 211 this.onresize = null; |
208 this.onautocompleteresults = null; | 212 this.onautocompleteresults = null; |
209 this.onkeypress = null; | 213 this.onkeypress = null; |
210 this.onfocus = null; | 214 this.onfocus = null; |
211 this.onblur = null; | 215 this.onblur = null; |
212 this.oncontextchange = null; | 216 this.oncontextchange = null; |
213 }; | 217 }; |
214 } | 218 } |
OLD | NEW |