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 25 matching lines...) Expand all Loading... |
50 | 51 |
51 // Reasons why the Omnibox could change into keyword mode. | 52 // Reasons why the Omnibox could change into keyword mode. |
52 // These numeric values are used in UMA logs; do not change them. | 53 // These numeric values are used in UMA logs; do not change them. |
53 enum EnteredKeywordModeMethod { | 54 enum EnteredKeywordModeMethod { |
54 ENTERED_KEYWORD_MODE_VIA_TAB = 0, | 55 ENTERED_KEYWORD_MODE_VIA_TAB = 0, |
55 ENTERED_KEYWORD_MODE_VIA_SPACE_AT_END = 1, | 56 ENTERED_KEYWORD_MODE_VIA_SPACE_AT_END = 1, |
56 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE = 2, | 57 ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE = 2, |
57 ENTERED_KEYWORD_MODE_NUM_ITEMS | 58 ENTERED_KEYWORD_MODE_NUM_ITEMS |
58 }; | 59 }; |
59 | 60 |
60 class OmniboxEditModel : public AutocompleteControllerDelegate { | 61 class OmniboxEditModel { |
61 public: | 62 public: |
62 struct State { | 63 struct State { |
63 State(bool user_input_in_progress, | 64 State(bool user_input_in_progress, |
64 const string16& user_text, | 65 const string16& user_text, |
65 const string16& instant_suggestion, | 66 const string16& instant_suggestion, |
66 const string16& keyword, | 67 const string16& keyword, |
67 bool is_keyword_hint, | 68 bool is_keyword_hint, |
68 OmniboxFocusState focus_state); | 69 OmniboxFocusState focus_state); |
69 ~State(); | 70 ~State(); |
70 | 71 |
71 bool user_input_in_progress; | 72 bool user_input_in_progress; |
72 const string16 user_text; | 73 const string16 user_text; |
73 const string16 instant_suggestion; | 74 const string16 instant_suggestion; |
74 const string16 keyword; | 75 const string16 keyword; |
75 const bool is_keyword_hint; | 76 const bool is_keyword_hint; |
76 OmniboxFocusState focus_state; | 77 OmniboxFocusState focus_state; |
77 }; | 78 }; |
78 | 79 |
79 OmniboxEditModel(OmniboxView* view, | 80 OmniboxEditModel(OmniboxView* view, |
80 OmniboxEditController* controller, | 81 OmniboxEditController* controller, |
81 Profile* profile); | 82 Profile* profile); |
82 virtual ~OmniboxEditModel(); | 83 virtual ~OmniboxEditModel(); |
83 | 84 |
84 AutocompleteController* autocomplete_controller() const { | 85 AutocompleteController* autocomplete_controller() const { |
85 return autocomplete_controller_.get(); | 86 return omnibox_controller_->autocomplete_controller(); |
86 } | 87 } |
87 | 88 |
88 void set_popup_model(OmniboxPopupModel* popup_model) { | 89 void set_popup_model(OmniboxPopupModel* popup_model) { |
89 popup_ = popup_model; | 90 popup_ = popup_model; |
90 } | 91 } |
91 | 92 |
92 // TODO: The edit and popup should be siblings owned by the LocationBarView, | 93 // TODO: The edit and popup should be siblings owned by the LocationBarView, |
93 // making this accessor unnecessary. | 94 // making this accessor unnecessary. |
94 OmniboxPopupModel* popup_model() const { return popup_; } | 95 OmniboxPopupModel* popup_model() const { return popup_; } |
95 | 96 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 size_t selection_end, | 309 size_t selection_end, |
309 bool selection_differs, | 310 bool selection_differs, |
310 bool text_differs, | 311 bool text_differs, |
311 bool just_deleted_text, | 312 bool just_deleted_text, |
312 bool allow_keyword_ui_change); | 313 bool allow_keyword_ui_change); |
313 | 314 |
314 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 315 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
315 // is in screen coordinates. | 316 // is in screen coordinates. |
316 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 317 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
317 | 318 |
| 319 // Called when the results have changed in the OmniboxController. |
| 320 void OnResultChanged(bool default_match_changed); |
| 321 |
318 private: | 322 private: |
319 friend class InstantTestBase; | 323 friend class InstantTestBase; |
320 | 324 |
321 enum PasteState { | 325 enum PasteState { |
322 NONE, // Most recent edit was not a paste. | 326 NONE, // Most recent edit was not a paste. |
323 PASTING, // In the middle of doing a paste. We need this intermediate | 327 PASTING, // In the middle of doing a paste. We need this intermediate |
324 // state because OnPaste() does the actual detection of | 328 // state because OnPaste() does the actual detection of |
325 // paste, but OnAfterPossibleChange() has to update the | 329 // paste, but OnAfterPossibleChange() has to update the |
326 // paste state for every edit. If OnPaste() set the state | 330 // paste state for every edit. If OnPaste() set the state |
327 // directly to PASTED, OnAfterPossibleChange() wouldn't know | 331 // directly to PASTED, OnAfterPossibleChange() wouldn't know |
328 // whether that represented the current edit or a past one. | 332 // whether that represented the current edit or a past one. |
329 PASTED, // Most recent edit was a paste. | 333 PASTED, // Most recent edit was a paste. |
330 }; | 334 }; |
331 | 335 |
332 enum ControlKeyState { | 336 enum ControlKeyState { |
333 UP, // The control key is not depressed. | 337 UP, // The control key is not depressed. |
334 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's | 338 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's |
335 // contents/selection have not changed since it was | 339 // contents/selection have not changed since it was |
336 // depressed. This is the only state in which we | 340 // depressed. This is the only state in which we |
337 // do the "ctrl-enter" behavior when the user hits | 341 // do the "ctrl-enter" behavior when the user hits |
338 // enter. | 342 // enter. |
339 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's | 343 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's |
340 // contents/selection have changed since it was | 344 // contents/selection have changed since it was |
341 // depressed. If the user now hits enter, we assume | 345 // depressed. If the user now hits enter, we assume |
342 // he simply hasn't released the key, rather than that | 346 // he simply hasn't released the key, rather than that |
343 // he intended to hit "ctrl-enter". | 347 // he intended to hit "ctrl-enter". |
344 }; | 348 }; |
345 | 349 |
346 // AutocompleteControllerDelegate: | |
347 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; | |
348 | |
349 // Returns true if a query to an autocomplete provider is currently | 350 // Returns true if a query to an autocomplete provider is currently |
350 // in progress. This logic should in the future live in | 351 // in progress. This logic should in the future live in |
351 // AutocompleteController but resides here for now. This method is used by | 352 // AutocompleteController but resides here for now. This method is used by |
352 // AutomationProvider::AutocompleteEditIsQueryInProgress. | 353 // AutomationProvider::AutocompleteEditIsQueryInProgress. |
353 bool query_in_progress() const; | 354 bool query_in_progress() const; |
354 | 355 |
355 // Called whenever user_text_ should change. | 356 // Called whenever user_text_ should change. |
356 void InternalSetUserText(const string16& text); | 357 void InternalSetUserText(const string16& text); |
357 | 358 |
358 // Returns true if a keyword is selected. | 359 // Returns true if a keyword is selected. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 void ClassifyStringForPasteAndGo(const string16& text, | 428 void ClassifyStringForPasteAndGo(const string16& text, |
428 AutocompleteMatch* match, | 429 AutocompleteMatch* match, |
429 GURL* alternate_nav_url) const; | 430 GURL* alternate_nav_url) const; |
430 | 431 |
431 // If focus_state_ does not match |state|, we update it and notify the | 432 // If focus_state_ does not match |state|, we update it and notify the |
432 // InstantController about the change (passing along the |reason| for the | 433 // InstantController about the change (passing along the |reason| for the |
433 // change). If the caret visibility changes, we call ApplyCaretVisibility() on | 434 // change). If the caret visibility changes, we call ApplyCaretVisibility() on |
434 // the view. | 435 // the view. |
435 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); | 436 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); |
436 | 437 |
437 scoped_ptr<AutocompleteController> autocomplete_controller_; | 438 scoped_ptr<OmniboxController> omnibox_controller_; |
438 | 439 |
439 OmniboxView* view_; | 440 OmniboxView* view_; |
440 | 441 |
441 OmniboxPopupModel* popup_; | 442 OmniboxPopupModel* popup_; |
442 | 443 |
443 OmniboxEditController* controller_; | 444 OmniboxEditController* controller_; |
444 | 445 |
445 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; | 446 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; |
446 | 447 |
447 OmniboxFocusState focus_state_; | 448 OmniboxFocusState focus_state_; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // an exact keyword match. If this is true then keyword mode will be | 552 // an exact keyword match. If this is true then keyword mode will be |
552 // triggered automatically if the input is "<keyword> <search string>". We | 553 // triggered automatically if the input is "<keyword> <search string>". We |
553 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 554 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
554 // This has no effect if we're already in keyword mode. | 555 // This has no effect if we're already in keyword mode. |
555 bool allow_exact_keyword_match_; | 556 bool allow_exact_keyword_match_; |
556 | 557 |
557 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 558 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
558 }; | 559 }; |
559 | 560 |
560 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 561 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |