| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 5 #ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| 6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| 7 | 7 |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" |
| 11 #include "base/string16.h" | 10 #include "base/string16.h" |
| 12 #include "chrome/common/instant_types.h" | |
| 13 #include "chrome/common/search_types.h" | |
| 14 #include "content/public/common/page_transition_types.h" | |
| 15 #include "content/public/renderer/render_view_observer.h" | 11 #include "content/public/renderer/render_view_observer.h" |
| 16 #include "content/public/renderer/render_view_observer_tracker.h" | 12 #include "content/public/renderer/render_view_observer_tracker.h" |
| 17 #include "ui/base/window_open_disposition.h" | |
| 18 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 19 | 14 |
| 15 struct InstantSuggestion; |
| 16 |
| 20 namespace content { | 17 namespace content { |
| 21 class RenderView; | 18 class RenderView; |
| 22 } | 19 } |
| 23 | 20 |
| 24 class SearchBox : public content::RenderViewObserver, | 21 class SearchBox : public content::RenderViewObserver, |
| 25 public content::RenderViewObserverTracker<SearchBox> { | 22 public content::RenderViewObserverTracker<SearchBox> { |
| 26 public: | 23 public: |
| 27 explicit SearchBox(content::RenderView* render_view); | 24 explicit SearchBox(content::RenderView* render_view); |
| 28 virtual ~SearchBox(); | 25 virtual ~SearchBox(); |
| 29 | 26 |
| 30 // Sends ChromeViewHostMsg_SetSuggestions to the browser. | |
| 31 void SetSuggestions(const std::vector<InstantSuggestion>& suggestions); | |
| 32 | |
| 33 // Sends ChromeViewHostMsg_ShowInstantOverlay to the browser. | |
| 34 void ShowInstantOverlay(InstantShownReason reason, | |
| 35 int height, | |
| 36 InstantSizeUnits units); | |
| 37 | |
| 38 // Sends ChromeViewHostMsg_FocusOmnibox to the browser. | |
| 39 void FocusOmnibox(); | |
| 40 | |
| 41 // Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser. | |
| 42 void StartCapturingKeyStrokes(); | |
| 43 | |
| 44 // Sends ChromeViewHostMsg_StopCapturingKeyStrokes to the browser. | |
| 45 void StopCapturingKeyStrokes(); | |
| 46 | |
| 47 // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser. | |
| 48 void NavigateToURL(const GURL& url, | |
| 49 content::PageTransition transition, | |
| 50 WindowOpenDisposition disposition); | |
| 51 | |
| 52 // Sends ChromeViewHostMsg_InstantDeleteMostVisitedItem to the browser. | |
| 53 void DeleteMostVisitedItem(int restrict_id); | |
| 54 | |
| 55 // Sends ChromeViewHostMsg_InstantUndoMostVisitedDeletion to the browser. | |
| 56 void UndoMostVisitedDeletion(int restrict_id); | |
| 57 | |
| 58 // Sends ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions to the browser. | |
| 59 void UndoAllMostVisitedDeletions(); | |
| 60 | |
| 61 const string16& query() const { return query_; } | 27 const string16& query() const { return query_; } |
| 62 bool verbatim() const { return verbatim_; } | 28 bool verbatim() const { return verbatim_; } |
| 63 size_t selection_start() const { return selection_start_; } | 29 size_t selection_start() const { return selection_start_; } |
| 64 size_t selection_end() const { return selection_end_; } | 30 size_t selection_end() const { return selection_end_; } |
| 65 int results_base() const { return results_base_; } | |
| 66 bool is_key_capture_enabled() const { return is_key_capture_enabled_; } | |
| 67 bool display_instant_results() const { return display_instant_results_; } | |
| 68 const string16& omnibox_font() const { return omnibox_font_; } | |
| 69 size_t omnibox_font_size() const { return omnibox_font_size_; } | |
| 70 | 31 |
| 71 // In extended Instant, returns the start-edge margin of the location bar in | 32 // Returns the bounds of the omnibox popup, adjusted for page zoom. |
| 72 // screen pixels. | |
| 73 int GetStartMargin() const; | |
| 74 | |
| 75 // Returns the bounds of the omnibox popup in screen coordinates. | |
| 76 gfx::Rect GetPopupBounds() const; | 33 gfx::Rect GetPopupBounds() const; |
| 77 | 34 |
| 78 const std::vector<InstantAutocompleteResult>& GetAutocompleteResults(); | 35 void SetSuggestion(const InstantSuggestion& suggestion); |
| 79 // Searchbox retains ownership of this object. | |
| 80 const InstantAutocompleteResult* | |
| 81 GetAutocompleteResultWithId(size_t restricted_id) const; | |
| 82 const ThemeBackgroundInfo& GetThemeBackgroundInfo(); | |
| 83 | |
| 84 // Most Visited items. | |
| 85 const std::vector<MostVisitedItem>& GetMostVisitedItems(); | |
| 86 | |
| 87 // Secure Urls. | |
| 88 int UrlToRestrictedId(const string16 url); | |
| 89 string16 RestrictedIdToURL(int id); | |
| 90 string16 GenerateThumbnailUrl(int id); | |
| 91 string16 GenerateFaviconUrl(int id); | |
| 92 | 36 |
| 93 private: | 37 private: |
| 94 // Overridden from content::RenderViewObserver: | 38 // Overridden from content::RenderViewObserver: |
| 95 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 39 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 96 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; | |
| 97 | 40 |
| 41 void OnDetermineInstantSupport(); |
| 98 void OnChange(const string16& query, | 42 void OnChange(const string16& query, |
| 99 bool verbatim, | 43 bool verbatim, |
| 100 size_t selection_start, | 44 size_t selection_start, |
| 101 size_t selection_end); | 45 size_t selection_end); |
| 102 void OnSubmit(const string16& query); | 46 void OnSubmit(const string16& query); |
| 103 void OnCancel(const string16& query); | 47 void OnBlur(const string16& query); |
| 104 void OnPopupResize(const gfx::Rect& bounds); | 48 void OnPopupBounds(const gfx::Rect& bounds); |
| 105 void OnMarginChange(int margin, int width); | |
| 106 void OnDetermineIfPageSupportsInstant(); | |
| 107 void OnAutocompleteResults( | |
| 108 const std::vector<InstantAutocompleteResult>& results); | |
| 109 void OnUpOrDownKeyPressed(int count); | |
| 110 void OnCancelSelection(const string16& query); | |
| 111 void OnKeyCaptureChange(bool is_key_capture_enabled); | |
| 112 void OnSetDisplayInstantResults(bool display_instant_results); | |
| 113 void OnThemeChanged(const ThemeBackgroundInfo& theme_info); | |
| 114 void OnThemeAreaHeightChanged(int height); | |
| 115 void OnFontInformationReceived(const string16& omnibox_font, | |
| 116 size_t omnibox_font_size); | |
| 117 void OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url); | |
| 118 void OnMostVisitedChanged(const std::vector<MostVisitedItem>& items); | |
| 119 | 49 |
| 120 // Returns the current zoom factor of the render view or 1 on failure. | 50 // Returns the current zoom factor of the render view or 1 on failure. |
| 121 double GetZoom() const; | 51 double GetZoom() const; |
| 122 | 52 |
| 123 // Sets the searchbox values to their initial value. | |
| 124 void Reset(); | |
| 125 | |
| 126 string16 query_; | 53 string16 query_; |
| 127 bool verbatim_; | 54 bool verbatim_; |
| 128 size_t selection_start_; | 55 size_t selection_start_; |
| 129 size_t selection_end_; | 56 size_t selection_end_; |
| 130 size_t results_base_; | |
| 131 int start_margin_; | |
| 132 gfx::Rect popup_bounds_; | 57 gfx::Rect popup_bounds_; |
| 133 std::vector<InstantAutocompleteResult> autocomplete_results_; | |
| 134 size_t last_results_base_; | |
| 135 std::vector<InstantAutocompleteResult> last_autocomplete_results_; | |
| 136 bool is_key_capture_enabled_; | |
| 137 ThemeBackgroundInfo theme_info_; | |
| 138 bool display_instant_results_; | |
| 139 string16 omnibox_font_; | |
| 140 size_t omnibox_font_size_; | |
| 141 std::vector<MostVisitedItem> most_visited_items_; | |
| 142 | |
| 143 // URL to Restricted Id mapping. | |
| 144 // TODO(dcblack): Unify this logic to work with both Most Visited and | |
| 145 // history suggestions. (crbug/175768) | |
| 146 std::map<string16, int> url_to_restricted_id_map_; | |
| 147 std::map<int, string16> restricted_id_to_url_map_; | |
| 148 int last_restricted_id_; | |
| 149 | 58 |
| 150 DISALLOW_COPY_AND_ASSIGN(SearchBox); | 59 DISALLOW_COPY_AND_ASSIGN(SearchBox); |
| 151 }; | 60 }; |
| 152 | 61 |
| 153 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 62 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| OLD | NEW |