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_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 class Image; | 30 class Image; |
31 class Rect; | 31 class Rect; |
32 } | 32 } |
33 | 33 |
34 class OmniboxEditModel : public AutocompleteControllerDelegate { | 34 class OmniboxEditModel : public AutocompleteControllerDelegate { |
35 public: | 35 public: |
36 struct State { | 36 struct State { |
37 State(bool user_input_in_progress, | 37 State(bool user_input_in_progress, |
38 const string16& user_text, | 38 const string16& user_text, |
39 const string16& keyword, | 39 const string16& keyword, |
40 bool is_keyword_hint); | 40 bool is_keyword_hint, |
| 41 bool is_caret_visible); |
41 ~State(); | 42 ~State(); |
42 | 43 |
43 bool user_input_in_progress; | 44 bool user_input_in_progress; |
44 const string16 user_text; | 45 const string16 user_text; |
45 const string16 keyword; | 46 const string16 keyword; |
46 const bool is_keyword_hint; | 47 const bool is_keyword_hint; |
| 48 const bool is_caret_visible; |
47 }; | 49 }; |
48 | 50 |
49 OmniboxEditModel(OmniboxView* view, | 51 OmniboxEditModel(OmniboxView* view, |
50 OmniboxEditController* controller, | 52 OmniboxEditController* controller, |
51 Profile* profile); | 53 Profile* profile); |
52 virtual ~OmniboxEditModel(); | 54 virtual ~OmniboxEditModel(); |
53 | 55 |
54 AutocompleteController* autocomplete_controller() const { | 56 AutocompleteController* autocomplete_controller() const { |
55 return autocomplete_controller_.get(); | 57 return autocomplete_controller_.get(); |
56 } | 58 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void AcceptInput(WindowOpenDisposition disposition, | 185 void AcceptInput(WindowOpenDisposition disposition, |
184 bool for_drop); | 186 bool for_drop); |
185 | 187 |
186 // Asks the browser to load the item at |index|, with the given properties. | 188 // Asks the browser to load the item at |index|, with the given properties. |
187 void OpenMatch(const AutocompleteMatch& match, | 189 void OpenMatch(const AutocompleteMatch& match, |
188 WindowOpenDisposition disposition, | 190 WindowOpenDisposition disposition, |
189 const GURL& alternate_nav_url, | 191 const GURL& alternate_nav_url, |
190 size_t index); | 192 size_t index); |
191 | 193 |
192 bool has_focus() const { return has_focus_; } | 194 bool has_focus() const { return has_focus_; } |
| 195 bool is_caret_visible() const { return is_caret_visible_; } |
193 | 196 |
194 // Accessors for keyword-related state (see comments on keyword_ and | 197 // Accessors for keyword-related state (see comments on keyword_ and |
195 // is_keyword_hint_). | 198 // is_keyword_hint_). |
196 const string16& keyword() const { return keyword_; } | 199 const string16& keyword() const { return keyword_; } |
197 bool is_keyword_hint() const { return is_keyword_hint_; } | 200 bool is_keyword_hint() const { return is_keyword_hint_; } |
198 | 201 |
199 // Accepts the current keyword hint as a keyword. It always returns true for | 202 // Accepts the current keyword hint as a keyword. It always returns true for |
200 // caller convenience. | 203 // caller convenience. |
201 bool AcceptKeyword(); | 204 bool AcceptKeyword(); |
202 | 205 |
203 // Clears the current keyword. |visible_text| is the (non-keyword) text | 206 // Clears the current keyword. |visible_text| is the (non-keyword) text |
204 // currently visible in the edit. | 207 // currently visible in the edit. |
205 void ClearKeyword(const string16& visible_text); | 208 void ClearKeyword(const string16& visible_text); |
206 | 209 |
207 // Returns the current autocomplete result. This logic should in the future | 210 // Returns the current autocomplete result. This logic should in the future |
208 // live in AutocompleteController but resides here for now. This method is | 211 // live in AutocompleteController but resides here for now. This method is |
209 // used by AutomationProvider::AutocompleteEditGetMatches. | 212 // used by AutomationProvider::AutocompleteEditGetMatches. |
210 const AutocompleteResult& result() const; | 213 const AutocompleteResult& result() const; |
211 | 214 |
212 // Called when the view is gaining focus. |control_down| is whether the | 215 // Called when the view is gaining focus. |control_down| is whether the |
213 // control key is down (at the time we're gaining focus). | 216 // control key is down (at the time we're gaining focus). |
214 void OnSetFocus(bool control_down); | 217 void OnSetFocus(bool control_down); |
215 | 218 |
| 219 // Sets the visibility of the caret in the omnibox, if it has focus. The |
| 220 // visibility of the caret is reset to visible if any of the following |
| 221 // happens: |
| 222 // - User starts typing in the omnibox |
| 223 // - User clicks in the omnibox |
| 224 // - Omnibox loses and then regains focus |
| 225 // - SetFocus() is explicitly called again |
| 226 // Caret visibility is tracked per-tab and updates automatically upon |
| 227 // switching tabs. |
| 228 void SetCaretVisibility(bool visible); |
| 229 |
216 // Sent before |OnKillFocus| and before the popup is closed. | 230 // Sent before |OnKillFocus| and before the popup is closed. |
217 void OnWillKillFocus(gfx::NativeView view_gaining_focus); | 231 void OnWillKillFocus(gfx::NativeView view_gaining_focus); |
218 | 232 |
219 // Called when the view is losing focus. Resets some state. | 233 // Called when the view is losing focus. Resets some state. |
220 void OnKillFocus(); | 234 void OnKillFocus(); |
221 | 235 |
222 // Called when the user presses the escape key. Decides what, if anything, to | 236 // Called when the user presses the escape key. Decides what, if anything, to |
223 // revert about any current edits. Returns whether the key was handled. | 237 // revert about any current edits. Returns whether the key was handled. |
224 bool OnEscapeKeyPressed(); | 238 bool OnEscapeKeyPressed(); |
225 | 239 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 411 |
398 OmniboxView* view_; | 412 OmniboxView* view_; |
399 | 413 |
400 OmniboxPopupModel* popup_; | 414 OmniboxPopupModel* popup_; |
401 | 415 |
402 OmniboxEditController* controller_; | 416 OmniboxEditController* controller_; |
403 | 417 |
404 // Whether the edit has focus. | 418 // Whether the edit has focus. |
405 bool has_focus_; | 419 bool has_focus_; |
406 | 420 |
| 421 // Is the caret visible? Only meaningful if has_focus_ is true. |
| 422 bool is_caret_visible_; |
| 423 |
407 // The URL of the currently displayed page. | 424 // The URL of the currently displayed page. |
408 string16 permanent_text_; | 425 string16 permanent_text_; |
409 | 426 |
410 // This flag is true when the user has modified the contents of the edit, but | 427 // This flag is true when the user has modified the contents of the edit, but |
411 // not yet accepted them. We use this to determine when we need to save | 428 // not yet accepted them. We use this to determine when we need to save |
412 // state (on switching tabs) and whether changes to the page URL should be | 429 // state (on switching tabs) and whether changes to the page URL should be |
413 // immediately displayed. | 430 // immediately displayed. |
414 // This flag will be true in a superset of the cases where the popup is open. | 431 // This flag will be true in a superset of the cases where the popup is open. |
415 bool user_input_in_progress_; | 432 bool user_input_in_progress_; |
416 | 433 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // an exact keyword match. If this is true then keyword mode will be | 521 // an exact keyword match. If this is true then keyword mode will be |
505 // triggered automatically if the input is "<keyword> <search string>". We | 522 // triggered automatically if the input is "<keyword> <search string>". We |
506 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 523 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
507 // This has no effect if we're already in keyword mode. | 524 // This has no effect if we're already in keyword mode. |
508 bool allow_exact_keyword_match_; | 525 bool allow_exact_keyword_match_; |
509 | 526 |
510 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 527 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
511 }; | 528 }; |
512 | 529 |
513 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 530 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |