Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.h

Issue 13932034: Omnibox refactor, introduced OmniboxController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
85 // TODO(beaudoin): Remove this accessor when the AutocompleteController has
86 // completely moved to OmniboxController.
84 AutocompleteController* autocomplete_controller() const { 87 AutocompleteController* autocomplete_controller() const {
85 return autocomplete_controller_.get(); 88 return omnibox_controller_->autocomplete_controller();
86 } 89 }
87 90
88 void set_popup_model(OmniboxPopupModel* popup_model) { 91 void set_popup_model(OmniboxPopupModel* popup_model) {
89 popup_ = popup_model; 92 popup_ = popup_model;
90 } 93 }
91 94
92 // TODO: The edit and popup should be siblings owned by the LocationBarView, 95 // TODO: The edit and popup should be siblings owned by the LocationBarView,
93 // making this accessor unnecessary. 96 // making this accessor unnecessary.
94 OmniboxPopupModel* popup_model() const { return popup_; } 97 OmniboxPopupModel* popup_model() const { return popup_; }
95 98
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 size_t selection_end, 311 size_t selection_end,
309 bool selection_differs, 312 bool selection_differs,
310 bool text_differs, 313 bool text_differs,
311 bool just_deleted_text, 314 bool just_deleted_text,
312 bool allow_keyword_ui_change); 315 bool allow_keyword_ui_change);
313 316
314 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here 317 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here
315 // is in screen coordinates. 318 // is in screen coordinates.
316 void OnPopupBoundsChanged(const gfx::Rect& bounds); 319 void OnPopupBoundsChanged(const gfx::Rect& bounds);
317 320
321 // Called when the results have changed in the OmniboxController.
322 void OnResultChanged(bool default_match_changed);
323
318 private: 324 private:
319 friend class InstantTestBase; 325 friend class InstantTestBase;
320 326
321 enum PasteState { 327 enum PasteState {
322 NONE, // Most recent edit was not a paste. 328 NONE, // Most recent edit was not a paste.
323 PASTING, // In the middle of doing a paste. We need this intermediate 329 PASTING, // In the middle of doing a paste. We need this intermediate
324 // state because OnPaste() does the actual detection of 330 // state because OnPaste() does the actual detection of
325 // paste, but OnAfterPossibleChange() has to update the 331 // paste, but OnAfterPossibleChange() has to update the
326 // paste state for every edit. If OnPaste() set the state 332 // paste state for every edit. If OnPaste() set the state
327 // directly to PASTED, OnAfterPossibleChange() wouldn't know 333 // directly to PASTED, OnAfterPossibleChange() wouldn't know
328 // whether that represented the current edit or a past one. 334 // whether that represented the current edit or a past one.
329 PASTED, // Most recent edit was a paste. 335 PASTED, // Most recent edit was a paste.
330 }; 336 };
331 337
332 enum ControlKeyState { 338 enum ControlKeyState {
333 UP, // The control key is not depressed. 339 UP, // The control key is not depressed.
334 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's 340 DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's
335 // contents/selection have not changed since it was 341 // contents/selection have not changed since it was
336 // depressed. This is the only state in which we 342 // depressed. This is the only state in which we
337 // do the "ctrl-enter" behavior when the user hits 343 // do the "ctrl-enter" behavior when the user hits
338 // enter. 344 // enter.
339 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's 345 DOWN_WITH_CHANGE, // The control key is depressed, and the edit's
340 // contents/selection have changed since it was 346 // contents/selection have changed since it was
341 // depressed. If the user now hits enter, we assume 347 // depressed. If the user now hits enter, we assume
342 // he simply hasn't released the key, rather than that 348 // he simply hasn't released the key, rather than that
343 // he intended to hit "ctrl-enter". 349 // he intended to hit "ctrl-enter".
344 }; 350 };
345 351
346 // AutocompleteControllerDelegate:
347 virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
348
349 // Returns true if a query to an autocomplete provider is currently 352 // Returns true if a query to an autocomplete provider is currently
350 // in progress. This logic should in the future live in 353 // in progress. This logic should in the future live in
351 // AutocompleteController but resides here for now. This method is used by 354 // AutocompleteController but resides here for now. This method is used by
352 // AutomationProvider::AutocompleteEditIsQueryInProgress. 355 // AutomationProvider::AutocompleteEditIsQueryInProgress.
353 bool query_in_progress() const; 356 bool query_in_progress() const;
354 357
355 // Called whenever user_text_ should change. 358 // Called whenever user_text_ should change.
356 void InternalSetUserText(const string16& text); 359 void InternalSetUserText(const string16& text);
357 360
358 // Returns true if a keyword is selected. 361 // Returns true if a keyword is selected.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 void ClassifyStringForPasteAndGo(const string16& text, 430 void ClassifyStringForPasteAndGo(const string16& text,
428 AutocompleteMatch* match, 431 AutocompleteMatch* match,
429 GURL* alternate_nav_url) const; 432 GURL* alternate_nav_url) const;
430 433
431 // If focus_state_ does not match |state|, we update it and notify the 434 // If focus_state_ does not match |state|, we update it and notify the
432 // InstantController about the change (passing along the |reason| for the 435 // InstantController about the change (passing along the |reason| for the
433 // change). If the caret visibility changes, we call ApplyCaretVisibility() on 436 // change). If the caret visibility changes, we call ApplyCaretVisibility() on
434 // the view. 437 // the view.
435 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); 438 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason);
436 439
437 scoped_ptr<AutocompleteController> autocomplete_controller_; 440 scoped_ptr<OmniboxController> omnibox_controller_;
438 441
439 OmniboxView* view_; 442 OmniboxView* view_;
440 443
441 OmniboxPopupModel* popup_; 444 OmniboxPopupModel* popup_;
442 445
443 OmniboxEditController* controller_; 446 OmniboxEditController* controller_;
444 447
445 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; 448 scoped_ptr<OmniboxCurrentPageDelegate> delegate_;
446 449
447 OmniboxFocusState focus_state_; 450 OmniboxFocusState focus_state_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // 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
552 // triggered automatically if the input is "<keyword> <search string>". We 555 // triggered automatically if the input is "<keyword> <search string>". We
553 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. 556 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true.
554 // This has no effect if we're already in keyword mode. 557 // This has no effect if we're already in keyword mode.
555 bool allow_exact_keyword_match_; 558 bool allow_exact_keyword_match_;
556 559
557 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); 560 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel);
558 }; 561 };
559 562
560 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 563 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_controller_unittest.cc ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698