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 13 matching lines...) Expand all Loading... |
24 class OmniboxEditController; | 24 class OmniboxEditController; |
25 class OmniboxPopupModel; | 25 class OmniboxPopupModel; |
26 class OmniboxView; | 26 class OmniboxView; |
27 class Profile; | 27 class Profile; |
28 | 28 |
29 namespace gfx { | 29 namespace gfx { |
30 class Image; | 30 class Image; |
31 class Rect; | 31 class Rect; |
32 } | 32 } |
33 | 33 |
| 34 // Omnibox focus state. |
| 35 enum OmniboxFocusState { |
| 36 // Not focused. |
| 37 OMNIBOX_FOCUS_NONE, |
| 38 |
| 39 // Visibly focused. |
| 40 OMNIBOX_FOCUS_VISIBLE, |
| 41 |
| 42 // Invisibly focused, i.e. focused with a hidden caret. |
| 43 OMNIBOX_FOCUS_INVISIBLE, |
| 44 }; |
| 45 |
| 46 // Reasons why the Omnibox focus state could change. |
| 47 enum OmniboxFocusChangeReason { |
| 48 // Includes any explicit changes to focus. (e.g. user clicking to change |
| 49 // focus, user tabbing to change focus, any explicit calls to SetFocus, |
| 50 // etc.) |
| 51 OMNIBOX_FOCUS_CHANGE_EXPLICIT, |
| 52 |
| 53 // Focus changed to restore state from a tab the user switched to. |
| 54 OMNIBOX_FOCUS_CHANGE_TAB_SWITCH, |
| 55 |
| 56 // Focus changed because user started typing. This only happens when focus |
| 57 // state is INVISIBLE (and this results in a change to VISIBLE). |
| 58 OMNIBOX_FOCUS_CHANGE_TYPING, |
| 59 }; |
| 60 |
34 class OmniboxEditModel : public AutocompleteControllerDelegate { | 61 class OmniboxEditModel : public AutocompleteControllerDelegate { |
35 public: | 62 public: |
36 struct State { | 63 struct State { |
37 State(bool user_input_in_progress, | 64 State(bool user_input_in_progress, |
38 const string16& user_text, | 65 const string16& user_text, |
39 const string16& keyword, | 66 const string16& keyword, |
40 bool is_keyword_hint, | 67 bool is_keyword_hint, |
41 bool is_caret_visible); | 68 OmniboxFocusState focus_state); |
42 ~State(); | 69 ~State(); |
43 | 70 |
44 bool user_input_in_progress; | 71 bool user_input_in_progress; |
45 const string16 user_text; | 72 const string16 user_text; |
46 const string16 keyword; | 73 const string16 keyword; |
47 const bool is_keyword_hint; | 74 const bool is_keyword_hint; |
48 const bool is_caret_visible; | 75 OmniboxFocusState focus_state; |
49 }; | 76 }; |
50 | 77 |
51 OmniboxEditModel(OmniboxView* view, | 78 OmniboxEditModel(OmniboxView* view, |
52 OmniboxEditController* controller, | 79 OmniboxEditController* controller, |
53 Profile* profile); | 80 Profile* profile); |
54 virtual ~OmniboxEditModel(); | 81 virtual ~OmniboxEditModel(); |
55 | 82 |
56 AutocompleteController* autocomplete_controller() const { | 83 AutocompleteController* autocomplete_controller() const { |
57 return autocomplete_controller_.get(); | 84 return autocomplete_controller_.get(); |
58 } | 85 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // URL to be autocompleted). | 211 // URL to be autocompleted). |
185 void AcceptInput(WindowOpenDisposition disposition, | 212 void AcceptInput(WindowOpenDisposition disposition, |
186 bool for_drop); | 213 bool for_drop); |
187 | 214 |
188 // Asks the browser to load the item at |index|, with the given properties. | 215 // Asks the browser to load the item at |index|, with the given properties. |
189 void OpenMatch(const AutocompleteMatch& match, | 216 void OpenMatch(const AutocompleteMatch& match, |
190 WindowOpenDisposition disposition, | 217 WindowOpenDisposition disposition, |
191 const GURL& alternate_nav_url, | 218 const GURL& alternate_nav_url, |
192 size_t index); | 219 size_t index); |
193 | 220 |
194 bool has_focus() const { return has_focus_; } | 221 OmniboxFocusState focus_state() const { return focus_state_; } |
195 bool is_caret_visible() const { return is_caret_visible_; } | 222 bool has_focus() const { return focus_state_ != OMNIBOX_FOCUS_NONE; } |
| 223 bool is_caret_visible() const { |
| 224 return focus_state_ == OMNIBOX_FOCUS_VISIBLE; |
| 225 } |
196 | 226 |
197 // Accessors for keyword-related state (see comments on keyword_ and | 227 // Accessors for keyword-related state (see comments on keyword_ and |
198 // is_keyword_hint_). | 228 // is_keyword_hint_). |
199 const string16& keyword() const { return keyword_; } | 229 const string16& keyword() const { return keyword_; } |
200 bool is_keyword_hint() const { return is_keyword_hint_; } | 230 bool is_keyword_hint() const { return is_keyword_hint_; } |
201 | 231 |
202 // Accepts the current keyword hint as a keyword. It always returns true for | 232 // Accepts the current keyword hint as a keyword. It always returns true for |
203 // caller convenience. | 233 // caller convenience. |
204 bool AcceptKeyword(); | 234 bool AcceptKeyword(); |
205 | 235 |
206 // Clears the current keyword. |visible_text| is the (non-keyword) text | 236 // Clears the current keyword. |visible_text| is the (non-keyword) text |
207 // currently visible in the edit. | 237 // currently visible in the edit. |
208 void ClearKeyword(const string16& visible_text); | 238 void ClearKeyword(const string16& visible_text); |
209 | 239 |
210 // Returns the current autocomplete result. This logic should in the future | 240 // Returns the current autocomplete result. This logic should in the future |
211 // live in AutocompleteController but resides here for now. This method is | 241 // live in AutocompleteController but resides here for now. This method is |
212 // used by AutomationProvider::AutocompleteEditGetMatches. | 242 // used by AutomationProvider::AutocompleteEditGetMatches. |
213 const AutocompleteResult& result() const; | 243 const AutocompleteResult& result() const; |
214 | 244 |
215 // Called when the view is gaining focus. |control_down| is whether the | 245 // Called when the view is gaining focus. |control_down| is whether the |
216 // control key is down (at the time we're gaining focus). | 246 // control key is down (at the time we're gaining focus). |
217 void OnSetFocus(bool control_down); | 247 void OnSetFocus(bool control_down); |
218 | 248 |
219 // Sets the visibility of the caret in the omnibox, if it has focus. The | 249 // 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 | 250 // visibility of the caret is reset to visible if either |
221 // happens: | 251 // - The user starts typing, or |
222 // - User starts typing in the omnibox | 252 // - We explicitly focus the omnibox again. |
223 // - User clicks in the omnibox | 253 // The latter case must be handled in three separate places--OnSetFocus(), |
224 // - Omnibox loses and then regains focus | 254 // OmniboxView::SetFocus(), and the mouse handlers in OmniboxView. See |
225 // - SetFocus() is explicitly called again | 255 // accompanying comments for why each of these is necessary. |
| 256 // |
226 // Caret visibility is tracked per-tab and updates automatically upon | 257 // Caret visibility is tracked per-tab and updates automatically upon |
227 // switching tabs. | 258 // switching tabs. |
228 void SetCaretVisibility(bool visible); | 259 void SetCaretVisibility(bool visible); |
229 | 260 |
230 // Sent before |OnKillFocus| and before the popup is closed. | 261 // Sent before |OnKillFocus| and before the popup is closed. |
231 void OnWillKillFocus(gfx::NativeView view_gaining_focus); | 262 void OnWillKillFocus(gfx::NativeView view_gaining_focus); |
232 | 263 |
233 // Called when the view is losing focus. Resets some state. | 264 // Called when the view is losing focus. Resets some state. |
234 void OnKillFocus(); | 265 void OnKillFocus(); |
235 | 266 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 // current page is the user's home page. | 431 // current page is the user's home page. |
401 metrics::OmniboxEventProto::PageClassification ClassifyPage( | 432 metrics::OmniboxEventProto::PageClassification ClassifyPage( |
402 const GURL& gurl) const; | 433 const GURL& gurl) const; |
403 | 434 |
404 // Sets |match| and |alternate_nav_url| based on classifying |text|. | 435 // Sets |match| and |alternate_nav_url| based on classifying |text|. |
405 // |alternate_nav_url| may be NULL. | 436 // |alternate_nav_url| may be NULL. |
406 void ClassifyStringForPasteAndGo(const string16& text, | 437 void ClassifyStringForPasteAndGo(const string16& text, |
407 AutocompleteMatch* match, | 438 AutocompleteMatch* match, |
408 GURL* alternate_nav_url) const; | 439 GURL* alternate_nav_url) const; |
409 | 440 |
| 441 // If focus_state_ does not match |state|, we update it and notify the |
| 442 // InstantController about the change (passing along the |reason| for the |
| 443 // change). If the caret visibility changes, we call ApplyCaretVisibility() on |
| 444 // the view. |
| 445 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); |
| 446 |
410 scoped_ptr<AutocompleteController> autocomplete_controller_; | 447 scoped_ptr<AutocompleteController> autocomplete_controller_; |
411 | 448 |
412 OmniboxView* view_; | 449 OmniboxView* view_; |
413 | 450 |
414 OmniboxPopupModel* popup_; | 451 OmniboxPopupModel* popup_; |
415 | 452 |
416 OmniboxEditController* controller_; | 453 OmniboxEditController* controller_; |
417 | 454 |
418 // Whether the edit has focus. | 455 OmniboxFocusState focus_state_; |
419 bool has_focus_; | |
420 | |
421 // Is the caret visible? Only meaningful if has_focus_ is true. | |
422 bool is_caret_visible_; | |
423 | 456 |
424 // The URL of the currently displayed page. | 457 // The URL of the currently displayed page. |
425 string16 permanent_text_; | 458 string16 permanent_text_; |
426 | 459 |
427 // This flag is true when the user has modified the contents of the edit, but | 460 // This flag is true when the user has modified the contents of the edit, but |
428 // not yet accepted them. We use this to determine when we need to save | 461 // not yet accepted them. We use this to determine when we need to save |
429 // state (on switching tabs) and whether changes to the page URL should be | 462 // state (on switching tabs) and whether changes to the page URL should be |
430 // immediately displayed. | 463 // immediately displayed. |
431 // This flag will be true in a superset of the cases where the popup is open. | 464 // This flag will be true in a superset of the cases where the popup is open. |
432 bool user_input_in_progress_; | 465 bool user_input_in_progress_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // an exact keyword match. If this is true then keyword mode will be | 554 // an exact keyword match. If this is true then keyword mode will be |
522 // triggered automatically if the input is "<keyword> <search string>". We | 555 // triggered automatically if the input is "<keyword> <search string>". We |
523 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 556 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
524 // This has no effect if we're already in keyword mode. | 557 // This has no effect if we're already in keyword mode. |
525 bool allow_exact_keyword_match_; | 558 bool allow_exact_keyword_match_; |
526 | 559 |
527 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 560 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
528 }; | 561 }; |
529 | 562 |
530 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 563 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |