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

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

Issue 14358005: Omnibox refactor, moved OnResultChanged to OmniboxController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nit. Created 7 years, 7 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"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Profile* profile); 82 Profile* profile);
83 virtual ~OmniboxEditModel(); 83 virtual ~OmniboxEditModel();
84 84
85 // TODO(beaudoin): Remove this accessor when the AutocompleteController has 85 // TODO(beaudoin): Remove this accessor when the AutocompleteController has
86 // completely moved to OmniboxController. 86 // completely moved to OmniboxController.
87 AutocompleteController* autocomplete_controller() const { 87 AutocompleteController* autocomplete_controller() const {
88 return omnibox_controller_->autocomplete_controller(); 88 return omnibox_controller_->autocomplete_controller();
89 } 89 }
90 90
91 void set_popup_model(OmniboxPopupModel* popup_model) { 91 void set_popup_model(OmniboxPopupModel* popup_model) {
92 popup_ = popup_model; 92 omnibox_controller_->set_popup_model(popup_model);
Peter Kasting 2013/05/22 23:56:54 I have no idea whether this is possible but it'd b
beaudoin 2013/05/23 14:16:41 I'd love this, unfortunately they're on two totall
sreeram 2013/05/23 14:18:45 I wouldn't worry too much about this. One of the g
93 } 93 }
94 94
95 // 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,
96 // making this accessor unnecessary. 96 // making this accessor unnecessary.
97 OmniboxPopupModel* popup_model() const { return popup_; } 97 OmniboxPopupModel* popup_model() const {
98 return omnibox_controller_->popup_model();
99 }
98 100
99 OmniboxEditController* controller() const { return controller_; } 101 OmniboxEditController* controller() const { return controller_; }
100 102
101 Profile* profile() const { return profile_; } 103 Profile* profile() const { return profile_; }
102 104
103 // Returns the current state. This assumes we are switching tabs, and changes 105 // Returns the current state. This assumes we are switching tabs, and changes
104 // the internal state appropriately. 106 // the internal state appropriately.
105 const State GetStateForTabSwitch(); 107 const State GetStateForTabSwitch();
106 108
107 // Restores local state from the saved |state|. 109 // Restores local state from the saved |state|.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // is_keyword_hint_). 224 // is_keyword_hint_).
223 const string16& keyword() const { return keyword_; } 225 const string16& keyword() const { return keyword_; }
224 bool is_keyword_hint() const { return is_keyword_hint_; } 226 bool is_keyword_hint() const { return is_keyword_hint_; }
225 227
226 // Accepts the current keyword hint as a keyword. It always returns true for 228 // Accepts the current keyword hint as a keyword. It always returns true for
227 // caller convenience. |entered_method| indicates how the use entered 229 // caller convenience. |entered_method| indicates how the use entered
228 // keyword mode. This parameter is only used for metrics/logging; it's not 230 // keyword mode. This parameter is only used for metrics/logging; it's not
229 // used to change user-visible behavior. 231 // used to change user-visible behavior.
230 bool AcceptKeyword(EnteredKeywordModeMethod entered_method); 232 bool AcceptKeyword(EnteredKeywordModeMethod entered_method);
231 233
234 // Accepts the current temporary text as the user text.
235 void AcceptTemporaryTextAsUserText();
236
232 // Clears the current keyword. |visible_text| is the (non-keyword) text 237 // Clears the current keyword. |visible_text| is the (non-keyword) text
233 // currently visible in the edit. 238 // currently visible in the edit.
234 void ClearKeyword(const string16& visible_text); 239 void ClearKeyword(const string16& visible_text);
235 240
236 // Returns the current autocomplete result. This logic should in the future 241 // Returns the current autocomplete result. This logic should in the future
237 // live in AutocompleteController but resides here for now. This method is 242 // live in AutocompleteController but resides here for now. This method is
238 // used by AutomationProvider::AutocompleteEditGetMatches. 243 // used by AutomationProvider::AutocompleteEditGetMatches.
239 const AutocompleteResult& result() const; 244 const AutocompleteResult& result() const {
245 return omnibox_controller_->result();
246 }
240 247
241 // Called when the view is gaining focus. |control_down| is whether the 248 // Called when the view is gaining focus. |control_down| is whether the
242 // control key is down (at the time we're gaining focus). 249 // control key is down (at the time we're gaining focus).
243 void OnSetFocus(bool control_down); 250 void OnSetFocus(bool control_down);
244 251
245 // Sets the visibility of the caret in the omnibox, if it has focus. The 252 // Sets the visibility of the caret in the omnibox, if it has focus. The
246 // visibility of the caret is reset to visible if either 253 // visibility of the caret is reset to visible if either
247 // - The user starts typing, or 254 // - The user starts typing, or
248 // - We explicitly focus the omnibox again. 255 // - We explicitly focus the omnibox again.
249 // The latter case must be handled in three separate places--OnSetFocus(), 256 // The latter case must be handled in three separate places--OnSetFocus(),
(...skipping 17 matching lines...) Expand all
267 // Called when the user presses or releases the control key. Changes state as 274 // Called when the user presses or releases the control key. Changes state as
268 // necessary. 275 // necessary.
269 void OnControlKeyChanged(bool pressed); 276 void OnControlKeyChanged(bool pressed);
270 277
271 // Called when the user pastes in text. 278 // Called when the user pastes in text.
272 void on_paste() { paste_state_ = PASTING; } 279 void on_paste() { paste_state_ = PASTING; }
273 280
274 // Returns true if pasting is in progress. 281 // Returns true if pasting is in progress.
275 bool is_pasting() const { return paste_state_ == PASTING; } 282 bool is_pasting() const { return paste_state_ == PASTING; }
276 283
284 // TODO(beaudoin): Try not to expose this.
285 bool in_revert() const { return in_revert_; }
286
277 // Called when the user presses up or down. |count| is a repeat count, 287 // Called when the user presses up or down. |count| is a repeat count,
278 // negative for moving up, positive for moving down. 288 // negative for moving up, positive for moving down.
279 virtual void OnUpOrDownKeyPressed(int count); 289 virtual void OnUpOrDownKeyPressed(int count);
280 290
281 // Called when any relevant data changes. This rolls together several 291 // Called when any relevant data changes. This rolls together several
282 // separate pieces of data into one call so we can update all the UI 292 // separate pieces of data into one call so we can update all the UI
283 // efficiently: 293 // efficiently:
284 // |text| is either the new temporary text from the user manually selecting 294 // |text| is either the new temporary text from the user manually selecting
285 // a different match, or the inline autocomplete text. We distinguish by 295 // a different match, or the inline autocomplete text. We distinguish by
286 // checking if |destination_for_temporary_text_change| is NULL. 296 // checking if |destination_for_temporary_text_change| is NULL.
(...skipping 20 matching lines...) Expand all
307 // may be false when the user is composing a text with an IME. 317 // may be false when the user is composing a text with an IME.
308 bool OnAfterPossibleChange(const string16& old_text, 318 bool OnAfterPossibleChange(const string16& old_text,
309 const string16& new_text, 319 const string16& new_text,
310 size_t selection_start, 320 size_t selection_start,
311 size_t selection_end, 321 size_t selection_end,
312 bool selection_differs, 322 bool selection_differs,
313 bool text_differs, 323 bool text_differs,
314 bool just_deleted_text, 324 bool just_deleted_text,
315 bool allow_keyword_ui_change); 325 bool allow_keyword_ui_change);
316 326
327 // TODO(beaudoin): Mac code still calls this here. We should try to untangle
328 // this.
317 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here 329 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here
318 // is in screen coordinates. 330 // is in screen coordinates.
319 void OnPopupBoundsChanged(const gfx::Rect& bounds); 331 void OnPopupBoundsChanged(const gfx::Rect& bounds) {
332 omnibox_controller_->OnPopupBoundsChanged(bounds);
333 }
320 334
321 // Called when the results have changed in the OmniboxController. 335 // Called when the results have changed in the OmniboxController.
322 void OnResultChanged(bool default_match_changed); 336 void OnResultChanged(bool default_match_changed);
323 337
324 private: 338 private:
325 friend class InstantTestBase; 339 friend class InstantTestBase;
340 friend class OmniboxControllerTest;
326 341
327 enum PasteState { 342 enum PasteState {
328 NONE, // Most recent edit was not a paste. 343 NONE, // Most recent edit was not a paste.
329 PASTING, // In the middle of doing a paste. We need this intermediate 344 PASTING, // In the middle of doing a paste. We need this intermediate
330 // state because OnPaste() does the actual detection of 345 // state because OnPaste() does the actual detection of
331 // paste, but OnAfterPossibleChange() has to update the 346 // paste, but OnAfterPossibleChange() has to update the
332 // paste state for every edit. If OnPaste() set the state 347 // paste state for every edit. If OnPaste() set the state
333 // directly to PASTED, OnAfterPossibleChange() wouldn't know 348 // directly to PASTED, OnAfterPossibleChange() wouldn't know
334 // whether that represented the current edit or a past one. 349 // whether that represented the current edit or a past one.
335 PASTED, // Most recent edit was a paste. 350 PASTED, // Most recent edit was a paste.
(...skipping 18 matching lines...) Expand all
354 // AutocompleteController but resides here for now. This method is used by 369 // AutocompleteController but resides here for now. This method is used by
355 // AutomationProvider::AutocompleteEditIsQueryInProgress. 370 // AutomationProvider::AutocompleteEditIsQueryInProgress.
356 bool query_in_progress() const; 371 bool query_in_progress() const;
357 372
358 // Called whenever user_text_ should change. 373 // Called whenever user_text_ should change.
359 void InternalSetUserText(const string16& text); 374 void InternalSetUserText(const string16& text);
360 375
361 // Returns true if a keyword is selected. 376 // Returns true if a keyword is selected.
362 bool KeywordIsSelected() const; 377 bool KeywordIsSelected() const;
363 378
364 // Turns off keyword mode for the current match.
365 void ClearPopupKeywordMode() const;
366
367 // Conversion between user text and display text. User text is the text the 379 // Conversion between user text and display text. User text is the text the
368 // user has input. Display text is the text being shown in the edit. The 380 // user has input. Display text is the text being shown in the edit. The
369 // two are different if a keyword is selected. 381 // two are different if a keyword is selected.
370 string16 DisplayTextFromUserText(const string16& text) const; 382 string16 DisplayTextFromUserText(const string16& text) const;
371 string16 UserTextFromDisplayText(const string16& text) const; 383 string16 UserTextFromDisplayText(const string16& text) const;
372 384
373 // If there's a selected match, copies it into |match|. Else, returns the 385 // If there's a selected match, copies it into |match|. Else, returns the
374 // default match for the current text, as well as the alternate nav URL, if 386 // default match for the current text, as well as the alternate nav URL, if
375 // |alternate_nav_url| is non-NULL and there is such a URL. 387 // |alternate_nav_url| is non-NULL and there is such a URL.
376 void GetInfoForCurrentText(AutocompleteMatch* match, 388 void GetInfoForCurrentText(AutocompleteMatch* match,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // 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
423 // InstantController about the change (passing along the |reason| for the 435 // InstantController about the change (passing along the |reason| for the
424 // change). If the caret visibility changes, we call ApplyCaretVisibility() on 436 // change). If the caret visibility changes, we call ApplyCaretVisibility() on
425 // the view. 437 // the view.
426 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); 438 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason);
427 439
428 scoped_ptr<OmniboxController> omnibox_controller_; 440 scoped_ptr<OmniboxController> omnibox_controller_;
429 441
430 OmniboxView* view_; 442 OmniboxView* view_;
431 443
432 OmniboxPopupModel* popup_;
433
434 OmniboxEditController* controller_; 444 OmniboxEditController* controller_;
435 445
436 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; 446 scoped_ptr<OmniboxCurrentPageDelegate> delegate_;
437 447
438 OmniboxFocusState focus_state_; 448 OmniboxFocusState focus_state_;
439 449
440 // The URL of the currently displayed page. 450 // The URL of the currently displayed page.
441 string16 permanent_text_; 451 string16 permanent_text_;
442 452
443 // This flag is true when the user has modified the contents of the edit, but 453 // This flag is true when the user has modified the contents of the edit, but
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // an exact keyword match. If this is true then keyword mode will be 566 // an exact keyword match. If this is true then keyword mode will be
557 // triggered automatically if the input is "<keyword> <search string>". We 567 // triggered automatically if the input is "<keyword> <search string>". We
558 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. 568 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true.
559 // This has no effect if we're already in keyword mode. 569 // This has no effect if we're already in keyword mode.
560 bool allow_exact_keyword_match_; 570 bool allow_exact_keyword_match_;
561 571
562 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); 572 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel);
563 }; 573 };
564 574
565 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 575 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698