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_controller.h" |
15 #include "chrome/common/metrics/proto/omnibox_event.pb.h" | 16 #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
16 #include "chrome/common/omnibox_focus_state.h" | 17 #include "chrome/common/omnibox_focus_state.h" |
17 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "ui/base/window_open_disposition.h" | 20 #include "ui/base/window_open_disposition.h" |
20 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
21 | 22 |
22 class AutocompleteController; | 23 class AutocompleteController; |
23 class AutocompleteResult; | 24 class AutocompleteResult; |
24 struct InstantSuggestion; | 25 struct InstantSuggestion; |
(...skipping 16 matching lines...) Expand all Loading... |
41 OMNIBOX_FOCUS_CHANGE_EXPLICIT, | 42 OMNIBOX_FOCUS_CHANGE_EXPLICIT, |
42 | 43 |
43 // Focus changed to restore state from a tab the user switched to. | 44 // Focus changed to restore state from a tab the user switched to. |
44 OMNIBOX_FOCUS_CHANGE_TAB_SWITCH, | 45 OMNIBOX_FOCUS_CHANGE_TAB_SWITCH, |
45 | 46 |
46 // Focus changed because user started typing. This only happens when focus | 47 // Focus changed because user started typing. This only happens when focus |
47 // state is INVISIBLE (and this results in a change to VISIBLE). | 48 // state is INVISIBLE (and this results in a change to VISIBLE). |
48 OMNIBOX_FOCUS_CHANGE_TYPING, | 49 OMNIBOX_FOCUS_CHANGE_TYPING, |
49 }; | 50 }; |
50 | 51 |
51 class OmniboxEditModel : public AutocompleteControllerDelegate { | 52 class OmniboxEditModel { |
52 public: | 53 public: |
53 struct State { | 54 struct State { |
54 State(bool user_input_in_progress, | 55 State(bool user_input_in_progress, |
55 const string16& user_text, | 56 const string16& user_text, |
56 const string16& instant_suggestion, | 57 const string16& instant_suggestion, |
57 const string16& keyword, | 58 const string16& keyword, |
58 bool is_keyword_hint, | 59 bool is_keyword_hint, |
59 OmniboxFocusState focus_state); | 60 OmniboxFocusState focus_state); |
60 ~State(); | 61 ~State(); |
61 | 62 |
62 bool user_input_in_progress; | 63 bool user_input_in_progress; |
63 const string16 user_text; | 64 const string16 user_text; |
64 const string16 instant_suggestion; | 65 const string16 instant_suggestion; |
65 const string16 keyword; | 66 const string16 keyword; |
66 const bool is_keyword_hint; | 67 const bool is_keyword_hint; |
67 OmniboxFocusState focus_state; | 68 OmniboxFocusState focus_state; |
68 }; | 69 }; |
69 | 70 |
70 OmniboxEditModel(OmniboxView* view, | 71 OmniboxEditModel(OmniboxView* view, |
71 OmniboxEditController* controller, | 72 OmniboxEditController* controller, |
72 Profile* profile); | 73 Profile* profile); |
73 virtual ~OmniboxEditModel(); | 74 virtual ~OmniboxEditModel(); |
74 | 75 |
75 AutocompleteController* autocomplete_controller() const { | 76 AutocompleteController* autocomplete_controller() const { |
76 return autocomplete_controller_.get(); | 77 return omnibox_controller_->autocomplete_controller(); |
77 } | 78 } |
78 | 79 |
79 void set_popup_model(OmniboxPopupModel* popup_model) { | 80 void set_popup_model(OmniboxPopupModel* popup_model) { |
80 popup_ = popup_model; | 81 popup_ = popup_model; |
81 } | 82 } |
82 | 83 |
83 // TODO: The edit and popup should be siblings owned by the LocationBarView, | 84 // TODO: The edit and popup should be siblings owned by the LocationBarView, |
84 // making this accessor unnecessary. | 85 // making this accessor unnecessary. |
85 OmniboxPopupModel* popup_model() const { return popup_; } | 86 OmniboxPopupModel* popup_model() const { return popup_; } |
86 | 87 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 size_t selection_end, | 298 size_t selection_end, |
298 bool selection_differs, | 299 bool selection_differs, |
299 bool text_differs, | 300 bool text_differs, |
300 bool just_deleted_text, | 301 bool just_deleted_text, |
301 bool allow_keyword_ui_change); | 302 bool allow_keyword_ui_change); |
302 | 303 |
303 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 304 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
304 // is in screen coordinates. | 305 // is in screen coordinates. |
305 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 306 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
306 | 307 |
| 308 // Called when the results have changed in the OmniboxController. |
| 309 void OnResultChanged(bool default_match_changed); |
| 310 |
307 private: | 311 private: |
308 friend class InstantTestBase; | 312 friend class InstantTestBase; |
309 | 313 |
310 enum PasteState { | 314 enum PasteState { |
311 NONE, // Most recent edit was not a paste. | 315 NONE, // Most recent edit was not a paste. |
312 PASTING, // In the middle of doing a paste. We need this intermediate | 316 PASTING, // In the middle of doing a paste. We need this intermediate |
313 // state because OnPaste() does the actual detection of | 317 // state because OnPaste() does the actual detection of |
314 // paste, but OnAfterPossibleChange() has to update the | 318 // paste, but OnAfterPossibleChange() has to update the |
315 // paste state for every edit. If OnPaste() set the state | 319 // paste state for every edit. If OnPaste() set the state |
316 // directly to PASTED, OnAfterPossibleChange() wouldn't know | 320 // directly to PASTED, OnAfterPossibleChange() wouldn't know |
317 // whether that represented the current edit or a past one. | 321 // whether that represented the current edit or a past one. |
318 PASTED, // Most recent edit was a paste. | 322 PASTED, // Most recent edit was a paste. |
319 }; | 323 }; |
320 | 324 |
321 enum ControlKeyState { | 325 enum ControlKeyState { |
322 UP, // The control key is not depressed. | 326 UP, // The control key is not depressed. |
323 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's | 327 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's |
324 // contents/selection have not changed since it was | 328 // contents/selection have not changed since it was |
325 // depressed. This is the only state in which we | 329 // depressed. This is the only state in which we |
326 // do the "ctrl-enter" behavior when the user hits | 330 // do the "ctrl-enter" behavior when the user hits |
327 // enter. | 331 // enter. |
328 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's | 332 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's |
329 // contents/selection have changed since it was | 333 // contents/selection have changed since it was |
330 // depressed. If the user now hits enter, we assume | 334 // depressed. If the user now hits enter, we assume |
331 // he simply hasn't released the key, rather than that | 335 // he simply hasn't released the key, rather than that |
332 // he intended to hit "ctrl-enter". | 336 // he intended to hit "ctrl-enter". |
333 }; | 337 }; |
334 | 338 |
335 // AutocompleteControllerDelegate: | |
336 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; | |
337 | |
338 // Returns true if a query to an autocomplete provider is currently | 339 // Returns true if a query to an autocomplete provider is currently |
339 // in progress. This logic should in the future live in | 340 // in progress. This logic should in the future live in |
340 // AutocompleteController but resides here for now. This method is used by | 341 // AutocompleteController but resides here for now. This method is used by |
341 // AutomationProvider::AutocompleteEditIsQueryInProgress. | 342 // AutomationProvider::AutocompleteEditIsQueryInProgress. |
342 bool query_in_progress() const; | 343 bool query_in_progress() const; |
343 | 344 |
344 // Called whenever user_text_ should change. | 345 // Called whenever user_text_ should change. |
345 void InternalSetUserText(const string16& text); | 346 void InternalSetUserText(const string16& text); |
346 | 347 |
347 // Returns true if a keyword is selected. | 348 // Returns true if a keyword is selected. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 void ClassifyStringForPasteAndGo(const string16& text, | 417 void ClassifyStringForPasteAndGo(const string16& text, |
417 AutocompleteMatch* match, | 418 AutocompleteMatch* match, |
418 GURL* alternate_nav_url) const; | 419 GURL* alternate_nav_url) const; |
419 | 420 |
420 // If focus_state_ does not match |state|, we update it and notify the | 421 // If focus_state_ does not match |state|, we update it and notify the |
421 // InstantController about the change (passing along the |reason| for the | 422 // InstantController about the change (passing along the |reason| for the |
422 // change). If the caret visibility changes, we call ApplyCaretVisibility() on | 423 // change). If the caret visibility changes, we call ApplyCaretVisibility() on |
423 // the view. | 424 // the view. |
424 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); | 425 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); |
425 | 426 |
426 scoped_ptr<AutocompleteController> autocomplete_controller_; | 427 scoped_ptr<OmniboxController> omnibox_controller_; |
427 | 428 |
428 OmniboxView* view_; | 429 OmniboxView* view_; |
429 | 430 |
430 OmniboxPopupModel* popup_; | 431 OmniboxPopupModel* popup_; |
431 | 432 |
432 OmniboxEditController* controller_; | 433 OmniboxEditController* controller_; |
433 | 434 |
434 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; | 435 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; |
435 | 436 |
436 OmniboxFocusState focus_state_; | 437 OmniboxFocusState focus_state_; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 // an exact keyword match. If this is true then keyword mode will be | 541 // an exact keyword match. If this is true then keyword mode will be |
541 // triggered automatically if the input is "<keyword> <search string>". We | 542 // triggered automatically if the input is "<keyword> <search string>". We |
542 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 543 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
543 // This has no effect if we're already in keyword mode. | 544 // This has no effect if we're already in keyword mode. |
544 bool allow_exact_keyword_match_; | 545 bool allow_exact_keyword_match_; |
545 | 546 |
546 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 547 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
547 }; | 548 }; |
548 | 549 |
549 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 550 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |