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" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
15 #include "chrome/browser/ui/omnibox/omnibox_types.h" | |
15 #include "chrome/common/metrics/proto/omnibox_event.pb.h" | 16 #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
16 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
19 #include "webkit/glue/window_open_disposition.h" | 20 #include "webkit/glue/window_open_disposition.h" |
20 | 21 |
21 class AutocompleteController; | 22 class AutocompleteController; |
22 class AutocompleteResult; | 23 class AutocompleteResult; |
23 struct InstantSuggestion; | 24 struct InstantSuggestion; |
24 class OmniboxEditController; | 25 class OmniboxEditController; |
25 class OmniboxPopupModel; | 26 class OmniboxPopupModel; |
26 class OmniboxView; | 27 class OmniboxView; |
27 class Profile; | 28 class Profile; |
28 | 29 |
29 namespace gfx { | 30 namespace gfx { |
30 class Image; | 31 class Image; |
31 class Rect; | 32 class Rect; |
32 } | 33 } |
33 | 34 |
34 class OmniboxEditModel : public AutocompleteControllerDelegate { | 35 class OmniboxEditModel : public AutocompleteControllerDelegate { |
35 public: | 36 public: |
36 struct State { | 37 struct State { |
37 State(bool user_input_in_progress, | 38 State(bool user_input_in_progress, |
38 const string16& user_text, | 39 const string16& user_text, |
39 const string16& keyword, | 40 const string16& keyword, |
40 bool is_keyword_hint, | 41 bool is_keyword_hint, |
41 bool is_caret_visible); | 42 OmniboxFocusState focus_state); |
42 ~State(); | 43 ~State(); |
43 | 44 |
44 bool user_input_in_progress; | 45 bool user_input_in_progress; |
45 const string16 user_text; | 46 const string16 user_text; |
46 const string16 keyword; | 47 const string16 keyword; |
47 const bool is_keyword_hint; | 48 const bool is_keyword_hint; |
48 const bool is_caret_visible; | 49 OmniboxFocusState focus_state; |
49 }; | 50 }; |
50 | 51 |
51 OmniboxEditModel(OmniboxView* view, | 52 OmniboxEditModel(OmniboxView* view, |
52 OmniboxEditController* controller, | 53 OmniboxEditController* controller, |
53 Profile* profile); | 54 Profile* profile); |
54 virtual ~OmniboxEditModel(); | 55 virtual ~OmniboxEditModel(); |
55 | 56 |
56 AutocompleteController* autocomplete_controller() const { | 57 AutocompleteController* autocomplete_controller() const { |
57 return autocomplete_controller_.get(); | 58 return autocomplete_controller_.get(); |
58 } | 59 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 // URL to be autocompleted). | 185 // URL to be autocompleted). |
185 void AcceptInput(WindowOpenDisposition disposition, | 186 void AcceptInput(WindowOpenDisposition disposition, |
186 bool for_drop); | 187 bool for_drop); |
187 | 188 |
188 // Asks the browser to load the item at |index|, with the given properties. | 189 // Asks the browser to load the item at |index|, with the given properties. |
189 void OpenMatch(const AutocompleteMatch& match, | 190 void OpenMatch(const AutocompleteMatch& match, |
190 WindowOpenDisposition disposition, | 191 WindowOpenDisposition disposition, |
191 const GURL& alternate_nav_url, | 192 const GURL& alternate_nav_url, |
192 size_t index); | 193 size_t index); |
193 | 194 |
194 bool has_focus() const { return has_focus_; } | 195 OmniboxFocusState focus_state() const { return focus_state_; } |
195 bool is_caret_visible() const { return is_caret_visible_; } | 196 bool has_focus() const { return focus_state_ != OMNIBOX_FOCUS_NONE; } |
197 bool is_caret_visible() const { | |
198 return focus_state_ == OMNIBOX_FOCUS_VISIBLE; | |
199 } | |
Peter Kasting
2012/12/11 19:20:50
Normally I would not provide the has_focus() and i
samarth
2012/12/12 01:11:26
I left these in because I thought it made the call
Peter Kasting
2012/12/12 01:21:42
OK.
| |
196 | 200 |
197 // Accessors for keyword-related state (see comments on keyword_ and | 201 // Accessors for keyword-related state (see comments on keyword_ and |
198 // is_keyword_hint_). | 202 // is_keyword_hint_). |
199 const string16& keyword() const { return keyword_; } | 203 const string16& keyword() const { return keyword_; } |
200 bool is_keyword_hint() const { return is_keyword_hint_; } | 204 bool is_keyword_hint() const { return is_keyword_hint_; } |
201 | 205 |
202 // Accepts the current keyword hint as a keyword. It always returns true for | 206 // Accepts the current keyword hint as a keyword. It always returns true for |
203 // caller convenience. | 207 // caller convenience. |
204 bool AcceptKeyword(); | 208 bool AcceptKeyword(); |
205 | 209 |
206 // Clears the current keyword. |visible_text| is the (non-keyword) text | 210 // Clears the current keyword. |visible_text| is the (non-keyword) text |
207 // currently visible in the edit. | 211 // currently visible in the edit. |
208 void ClearKeyword(const string16& visible_text); | 212 void ClearKeyword(const string16& visible_text); |
209 | 213 |
210 // Returns the current autocomplete result. This logic should in the future | 214 // Returns the current autocomplete result. This logic should in the future |
211 // live in AutocompleteController but resides here for now. This method is | 215 // live in AutocompleteController but resides here for now. This method is |
212 // used by AutomationProvider::AutocompleteEditGetMatches. | 216 // used by AutomationProvider::AutocompleteEditGetMatches. |
213 const AutocompleteResult& result() const; | 217 const AutocompleteResult& result() const; |
214 | 218 |
215 // Called when the view is gaining focus. |control_down| is whether the | 219 // Called when the view is gaining focus. |control_down| is whether the |
216 // control key is down (at the time we're gaining focus). | 220 // control key is down (at the time we're gaining focus). |
217 void OnSetFocus(bool control_down); | 221 void OnSetFocus(bool control_down); |
218 | 222 |
219 // Sets the visibility of the caret in the omnibox, if it has focus. The | 223 // 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 | 224 // visibility of the caret is reset to visible if either |
221 // happens: | 225 // - The user starts typing, or |
222 // - User starts typing in the omnibox | 226 // - We explicitly focus the omnibox again. |
223 // - User clicks in the omnibox | 227 // The latter case must be handled in three separate places--OnSetFocus(), |
224 // - Omnibox loses and then regains focus | 228 // OmniboxView::SetFocus(), and the mouse handlers in OmniboxView. See |
225 // - SetFocus() is explicitly called again | 229 // accompanying comments for why each of these is necessary. |
230 // | |
226 // Caret visibility is tracked per-tab and updates automatically upon | 231 // Caret visibility is tracked per-tab and updates automatically upon |
227 // switching tabs. | 232 // switching tabs. |
228 void SetCaretVisibility(bool visible); | 233 void SetCaretVisibility(bool visible); |
229 | 234 |
230 // Sent before |OnKillFocus| and before the popup is closed. | 235 // Sent before |OnKillFocus| and before the popup is closed. |
231 void OnWillKillFocus(gfx::NativeView view_gaining_focus); | 236 void OnWillKillFocus(gfx::NativeView view_gaining_focus); |
232 | 237 |
233 // Called when the view is losing focus. Resets some state. | 238 // Called when the view is losing focus. Resets some state. |
234 void OnKillFocus(); | 239 void OnKillFocus(); |
235 | 240 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 // current page is the user's home page. | 405 // current page is the user's home page. |
401 metrics::OmniboxEventProto::PageClassification ClassifyPage( | 406 metrics::OmniboxEventProto::PageClassification ClassifyPage( |
402 const GURL& gurl) const; | 407 const GURL& gurl) const; |
403 | 408 |
404 // Sets |match| and |alternate_nav_url| based on classifying |text|. | 409 // Sets |match| and |alternate_nav_url| based on classifying |text|. |
405 // |alternate_nav_url| may be NULL. | 410 // |alternate_nav_url| may be NULL. |
406 void ClassifyStringForPasteAndGo(const string16& text, | 411 void ClassifyStringForPasteAndGo(const string16& text, |
407 AutocompleteMatch* match, | 412 AutocompleteMatch* match, |
408 GURL* alternate_nav_url) const; | 413 GURL* alternate_nav_url) const; |
409 | 414 |
415 // If focus_state_ does not match |state|, we update it and notify the | |
416 // InstantController about the change (passing along the |reason| for the | |
417 // change). If the caret visibility changes, we call ApplyCaretVisibility() on | |
418 // the view. | |
419 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); | |
420 | |
410 scoped_ptr<AutocompleteController> autocomplete_controller_; | 421 scoped_ptr<AutocompleteController> autocomplete_controller_; |
411 | 422 |
412 OmniboxView* view_; | 423 OmniboxView* view_; |
413 | 424 |
414 OmniboxPopupModel* popup_; | 425 OmniboxPopupModel* popup_; |
415 | 426 |
416 OmniboxEditController* controller_; | 427 OmniboxEditController* controller_; |
417 | 428 |
418 // Whether the edit has focus. | 429 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 | 430 |
424 // The URL of the currently displayed page. | 431 // The URL of the currently displayed page. |
425 string16 permanent_text_; | 432 string16 permanent_text_; |
426 | 433 |
427 // This flag is true when the user has modified the contents of the edit, but | 434 // 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 | 435 // 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 | 436 // state (on switching tabs) and whether changes to the page URL should be |
430 // immediately displayed. | 437 // immediately displayed. |
431 // This flag will be true in a superset of the cases where the popup is open. | 438 // This flag will be true in a superset of the cases where the popup is open. |
432 bool user_input_in_progress_; | 439 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 | 528 // an exact keyword match. If this is true then keyword mode will be |
522 // triggered automatically if the input is "<keyword> <search string>". We | 529 // triggered automatically if the input is "<keyword> <search string>". We |
523 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 530 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
524 // This has no effect if we're already in keyword mode. | 531 // This has no effect if we're already in keyword mode. |
525 bool allow_exact_keyword_match_; | 532 bool allow_exact_keyword_match_; |
526 | 533 |
527 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 534 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
528 }; | 535 }; |
529 | 536 |
530 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 537 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |