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 // This file defines the interface class OmniboxView. Each toolkit will | 5 // This file defines the interface class OmniboxView. Each toolkit will |
6 // implement the edit view differently, so that code is inherently platform | 6 // implement the edit view differently, so that code is inherently platform |
7 // specific. However, the OmniboxEditModel needs to do some communication with | 7 // specific. However, the OmniboxEditModel needs to do some communication with |
8 // the view. Since the model is shared between platforms, we need to define an | 8 // the view. Since the model is shared between platforms, we need to define an |
9 // interface that all view implementations will share. | 9 // interface that all view implementations will share. |
10 | 10 |
11 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 11 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
12 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 12 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | |
21 #include "chrome/browser/ui/toolbar/toolbar_model.h" | |
20 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
21 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
22 #include "webkit/glue/window_open_disposition.h" | 24 #include "webkit/glue/window_open_disposition.h" |
23 | 25 |
24 class CommandUpdater; | 26 class CommandUpdater; |
25 class GURL; | 27 class GURL; |
28 class OmniboxEditController; | |
26 class OmniboxEditModel; | 29 class OmniboxEditModel; |
30 class Profile; | |
31 class ToolbarModel; | |
27 | 32 |
28 namespace content { | 33 namespace content { |
29 class WebContents; | 34 class WebContents; |
30 } | 35 } |
31 | 36 |
32 #if defined(TOOLKIT_VIEWS) | 37 #if defined(TOOLKIT_VIEWS) |
33 // TODO(beng): Move all views-related code to a views-specific sub-interface. | 38 // TODO(beng): Move all views-related code to a views-specific sub-interface. |
34 namespace gfx { | 39 namespace gfx { |
35 class Font; | 40 class Font; |
36 } | 41 } |
37 | 42 |
38 namespace views { | 43 namespace views { |
39 class DropTargetEvent; | 44 class DropTargetEvent; |
40 class View; | 45 class View; |
41 } | 46 } |
42 #endif | 47 #endif |
43 | 48 |
44 class OmniboxView { | 49 class OmniboxView { |
45 public: | 50 public: |
46 // Used by the automation system for getting at the model from the view. | 51 // Used by the automation system for getting at the model from the view. |
47 virtual OmniboxEditModel* model() = 0; | 52 virtual OmniboxEditModel* GetModel(); |
48 virtual const OmniboxEditModel* model() const = 0; | 53 virtual const OmniboxEditModel* GetModel() const; |
49 | 54 |
50 // For use when switching tabs, this saves the current state onto the tab so | 55 // For use when switching tabs, this saves the current state onto the tab so |
51 // that it can be restored during a later call to Update(). | 56 // that it can be restored during a later call to Update(). |
52 virtual void SaveStateToTab(content::WebContents* tab) = 0; | 57 virtual void SaveStateToTab(content::WebContents* tab) = 0; |
53 | 58 |
54 // Called when any LocationBarView state changes. If | 59 // Called when any LocationBarView state changes. If |
55 // |tab_for_state_restoring| is non-NULL, it points to a WebContents whose | 60 // |tab_for_state_restoring| is non-NULL, it points to a WebContents whose |
56 // state we should restore. | 61 // state we should restore. |
57 virtual void Update(const content::WebContents* tab_for_state_restoring) = 0; | 62 virtual void Update(const content::WebContents* tab_for_state_restoring) = 0; |
58 | 63 |
59 // Asks the browser to load the specified match's |destination_url|, which | 64 // Asks the browser to load the specified match's |destination_url|, which |
60 // is assumed to be one of the popup entries, using the supplied disposition | 65 // is assumed to be one of the popup entries, using the supplied disposition |
61 // and transition type. |alternate_nav_url|, if non-empty, contains the | 66 // and transition type. |alternate_nav_url|, if non-empty, contains the |
62 // alternate navigation URL for for this match. See comments on | 67 // alternate navigation URL for for this match. See comments on |
63 // AutocompleteResult::GetAlternateNavURL(). | 68 // AutocompleteResult::GetAlternateNavURL(). |
64 // | 69 // |
65 // |selected_line| is passed to SendOpenNotification(); see comments there. | 70 // |selected_line| is passed to SendOpenNotification(); see comments there. |
66 // | 71 // |
67 // This may close the popup. | 72 // This may close the popup. |
68 virtual void OpenMatch(const AutocompleteMatch& match, | 73 virtual void OpenMatch(const AutocompleteMatch& match, |
69 WindowOpenDisposition disposition, | 74 WindowOpenDisposition disposition, |
70 const GURL& alternate_nav_url, | 75 const GURL& alternate_nav_url, |
71 size_t selected_line) = 0; | 76 size_t selected_line); |
72 | 77 |
73 // Returns the current text of the edit control, which could be the | 78 // Returns the current text of the edit control, which could be the |
74 // "temporary" text set by the popup, the "permanent" text set by the | 79 // "temporary" text set by the popup, the "permanent" text set by the |
75 // browser, or just whatever the user has currently typed. | 80 // browser, or just whatever the user has currently typed. |
76 virtual string16 GetText() const = 0; | 81 virtual string16 GetText() const = 0; |
77 | 82 |
78 // |true| if the user is in the process of editing the field, or if | 83 // |true| if the user is in the process of editing the field, or if |
79 // the field is empty. | 84 // the field is empty. |
80 virtual bool IsEditingOrEmpty() const = 0; | 85 virtual bool IsEditingOrEmpty() const; |
81 | 86 |
82 // Returns the resource ID of the icon to show for the current text. | 87 // Returns the resource ID of the icon to show for the current text. |
83 virtual int GetIcon() const = 0; | 88 virtual int GetIcon() const; |
84 | 89 |
85 // The user text is the text the user has manually keyed in. When present, | 90 // The user text is the text the user has manually keyed in. When present, |
86 // this is shown in preference to the permanent text; hitting escape will | 91 // this is shown in preference to the permanent text; hitting escape will |
87 // revert to the permanent text. | 92 // revert to the permanent text. |
88 virtual void SetUserText(const string16& text) = 0; | 93 void SetUserText(const string16& text); |
89 virtual void SetUserText(const string16& text, | 94 virtual void SetUserText(const string16& text, |
90 const string16& display_text, | 95 const string16& display_text, |
91 bool update_popup) = 0; | 96 bool update_popup); |
92 | 97 |
93 // Sets the window text and the caret position. | 98 // Sets the window text and the caret position. |
94 virtual void SetWindowTextAndCaretPos(const string16& text, | 99 virtual void SetWindowTextAndCaretPos(const string16& text, |
95 size_t caret_pos, | 100 size_t caret_pos, |
96 bool update_popup, | 101 bool update_popup, |
97 bool notify_text_changed) = 0; | 102 bool notify_text_changed) = 0; |
98 | 103 |
99 // Sets the edit to forced query mode. Practically speaking, this means that | 104 // Sets the edit to forced query mode. Practically speaking, this means that |
100 // if the edit is not in forced query mode, its text is set to "?" with the | 105 // if the edit is not in forced query mode, its text is set to "?" with the |
101 // cursor at the end, and if the edit is in forced query mode (its first | 106 // cursor at the end, and if the edit is in forced query mode (its first |
(...skipping 14 matching lines...) Expand all Loading... | |
116 // directed. If there is no selection, |start| and |end| will both be equal | 121 // directed. If there is no selection, |start| and |end| will both be equal |
117 // to the current cursor position. | 122 // to the current cursor position. |
118 virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0; | 123 virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0; |
119 | 124 |
120 // Selects all the text in the edit. Use this in place of SetSelAll() to | 125 // Selects all the text in the edit. Use this in place of SetSelAll() to |
121 // avoid selecting the "phantom newline" at the end of the edit. | 126 // avoid selecting the "phantom newline" at the end of the edit. |
122 virtual void SelectAll(bool reversed) = 0; | 127 virtual void SelectAll(bool reversed) = 0; |
123 | 128 |
124 // Reverts the edit and popup back to their unedited state (permanent text | 129 // Reverts the edit and popup back to their unedited state (permanent text |
125 // showing, popup closed, no user input in progress). | 130 // showing, popup closed, no user input in progress). |
126 virtual void RevertAll() = 0; | 131 virtual void RevertAll(); |
127 | 132 |
128 // Updates the autocomplete popup and other state after the text has been | 133 // Updates the autocomplete popup and other state after the text has been |
129 // changed by the user. | 134 // changed by the user. |
130 virtual void UpdatePopup() = 0; | 135 virtual void UpdatePopup() = 0; |
131 | 136 |
132 // Closes the autocomplete popup, if it's open. | 137 // Closes the autocomplete popup, if it's open. |
133 virtual void ClosePopup() = 0; | 138 virtual void ClosePopup(); |
134 | 139 |
135 // Sets the focus to the autocomplete view. | 140 // Sets the focus to the autocomplete view. |
136 virtual void SetFocus() = 0; | 141 virtual void SetFocus() = 0; |
137 | 142 |
138 // Called when the temporary text in the model may have changed. | 143 // Called when the temporary text in the model may have changed. |
139 // |display_text| is the new text to show; |save_original_selection| is true | 144 // |display_text| is the new text to show; |save_original_selection| is true |
140 // when there wasn't previously a temporary text and thus we need to save off | 145 // when there wasn't previously a temporary text and thus we need to save off |
141 // the user's existing selection. | 146 // the user's existing selection. |
142 virtual void OnTemporaryTextMaybeChanged(const string16& display_text, | 147 virtual void OnTemporaryTextMaybeChanged(const string16& display_text, |
143 bool save_original_selection) = 0; | 148 bool save_original_selection) = 0; |
(...skipping 19 matching lines...) Expand all Loading... | |
163 | 168 |
164 // Returns the gfx::NativeView of the edit view. | 169 // Returns the gfx::NativeView of the edit view. |
165 virtual gfx::NativeView GetNativeView() const = 0; | 170 virtual gfx::NativeView GetNativeView() const = 0; |
166 | 171 |
167 // Gets the relative window for the pop up window of OmniboxPopupView. The pop | 172 // Gets the relative window for the pop up window of OmniboxPopupView. The pop |
168 // up window will be shown under the relative window. When an IME is attached | 173 // up window will be shown under the relative window. When an IME is attached |
169 // to the rich edit control, the IME window is the relative window. Otherwise, | 174 // to the rich edit control, the IME window is the relative window. Otherwise, |
170 // the top-most window is the relative window. | 175 // the top-most window is the relative window. |
171 virtual gfx::NativeView GetRelativeWindowForPopup() const = 0; | 176 virtual gfx::NativeView GetRelativeWindowForPopup() const = 0; |
172 | 177 |
173 // Returns the command updater for this view. | |
174 virtual CommandUpdater* GetCommandUpdater() = 0; | |
175 | |
176 // Shows the instant suggestion text. If |animate_to_complete| is true the | 178 // Shows the instant suggestion text. If |animate_to_complete| is true the |
177 // view should start an animation that when done commits the text. | 179 // view should start an animation that when done commits the text. |
178 virtual void SetInstantSuggestion(const string16& input, | 180 virtual void SetInstantSuggestion(const string16& input, |
179 bool animate_to_complete) = 0; | 181 bool animate_to_complete) = 0; |
180 | 182 |
181 // Returns the current instant suggestion text. | 183 // Returns the current instant suggestion text. |
182 virtual string16 GetInstantSuggestion() const = 0; | 184 virtual string16 GetInstantSuggestion() const = 0; |
183 | 185 |
184 // Returns the width in pixels needed to display the current text. The | 186 // Returns the width in pixels needed to display the current text. The |
185 // returned value includes margins. | 187 // returned value includes margins. |
(...skipping 13 matching lines...) Expand all Loading... | |
199 virtual int OnPerformDrop(const views::DropTargetEvent& event) = 0; | 201 virtual int OnPerformDrop(const views::DropTargetEvent& event) = 0; |
200 | 202 |
201 // Returns the font. | 203 // Returns the font. |
202 virtual gfx::Font GetFont() = 0; | 204 virtual gfx::Font GetFont() = 0; |
203 | 205 |
204 // Returns the width in pixels needed to display the text from one character | 206 // Returns the width in pixels needed to display the text from one character |
205 // before the caret to the end of the string. | 207 // before the caret to the end of the string. |
206 virtual int WidthOfTextAfterCursor() = 0; | 208 virtual int WidthOfTextAfterCursor() = 0; |
207 #endif | 209 #endif |
208 | 210 |
211 virtual CommandUpdater* GetCommandUpdater(); | |
212 virtual const CommandUpdater* GetCommandUpdater() const; | |
213 | |
209 // Returns a string with any leading javascript schemas stripped from the | 214 // Returns a string with any leading javascript schemas stripped from the |
210 // input text. | 215 // input text. |
211 static string16 StripJavascriptSchemas(const string16& text); | 216 static string16 StripJavascriptSchemas(const string16& text); |
212 | 217 |
213 // Returns the current clipboard contents as a string that can be pasted in. | 218 // Returns the current clipboard contents as a string that can be pasted in. |
214 // In addition to just getting CF_UNICODETEXT out, this can also extract URLs | 219 // In addition to just getting CF_UNICODETEXT out, this can also extract URLs |
215 // from bookmarks on the clipboard. | 220 // from bookmarks on the clipboard. |
216 static string16 GetClipboardText(); | 221 static string16 GetClipboardText(); |
217 | 222 |
218 virtual ~OmniboxView() {} | 223 virtual ~OmniboxView(); |
Peter Kasting
2012/07/26 03:59:17
Nit: Destructor should be at the top of the releva
dominich
2012/07/26 22:33:24
It can't be protected. It's destroyed through scop
Peter Kasting
2012/07/26 23:03:24
Ah, I see. Yeah, has to be public.
| |
224 | |
225 protected: | |
226 OmniboxView(Profile* profile, | |
227 OmniboxEditController* controller, | |
228 ToolbarModel* toolbar_model, | |
229 CommandUpdater* command_updater); | |
230 | |
231 // Internally invoked whenever the text changes in some way. | |
232 virtual void TextChanged(); | |
233 | |
234 // Return the number of characters in the current buffer. | |
235 virtual int GetOmniboxTextLength() const = 0; | |
236 | |
237 // Try to parse the current text as a URL and colorize the components. | |
238 virtual void EmphasizeURLComponents() = 0; | |
239 | |
240 scoped_ptr<OmniboxEditModel> model_; | |
Peter Kasting
2012/07/26 03:59:17
Nit: The Google style guide forbids protected data
dominich
2012/07/26 22:33:24
Done.
| |
241 OmniboxEditController* controller_; | |
242 ToolbarModel* toolbar_model_; | |
243 | |
244 // The object that handles additional command functionality exposed on the | |
245 // edit, such as invoking the keyword editor. | |
246 CommandUpdater* command_updater_; | |
219 }; | 247 }; |
220 | 248 |
221 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 249 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
OLD | NEW |