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" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
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 Loading... |
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 Loading... |
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 29 matching lines...) Expand all Loading... |
316 | 326 |
317 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here | 327 // Invoked when the popup has changed its bounds to |bounds|. |bounds| here |
318 // is in screen coordinates. | 328 // is in screen coordinates. |
319 void OnPopupBoundsChanged(const gfx::Rect& bounds); | 329 void OnPopupBoundsChanged(const gfx::Rect& bounds); |
320 | 330 |
321 // Called when the results have changed in the OmniboxController. | 331 // Called when the results have changed in the OmniboxController. |
322 void OnResultChanged(bool default_match_changed); | 332 void OnResultChanged(bool default_match_changed); |
323 | 333 |
324 private: | 334 private: |
325 friend class InstantTestBase; | 335 friend class InstantTestBase; |
| 336 friend class OmniboxControllerTest; |
326 | 337 |
327 enum PasteState { | 338 enum PasteState { |
328 NONE, // Most recent edit was not a paste. | 339 NONE, // Most recent edit was not a paste. |
329 PASTING, // In the middle of doing a paste. We need this intermediate | 340 PASTING, // In the middle of doing a paste. We need this intermediate |
330 // state because OnPaste() does the actual detection of | 341 // state because OnPaste() does the actual detection of |
331 // paste, but OnAfterPossibleChange() has to update the | 342 // paste, but OnAfterPossibleChange() has to update the |
332 // paste state for every edit. If OnPaste() set the state | 343 // paste state for every edit. If OnPaste() set the state |
333 // directly to PASTED, OnAfterPossibleChange() wouldn't know | 344 // directly to PASTED, OnAfterPossibleChange() wouldn't know |
334 // whether that represented the current edit or a past one. | 345 // whether that represented the current edit or a past one. |
335 PASTED, // Most recent edit was a paste. | 346 PASTED, // Most recent edit was a paste. |
(...skipping 18 matching lines...) Expand all Loading... |
354 // AutocompleteController but resides here for now. This method is used by | 365 // AutocompleteController but resides here for now. This method is used by |
355 // AutomationProvider::AutocompleteEditIsQueryInProgress. | 366 // AutomationProvider::AutocompleteEditIsQueryInProgress. |
356 bool query_in_progress() const; | 367 bool query_in_progress() const; |
357 | 368 |
358 // Called whenever user_text_ should change. | 369 // Called whenever user_text_ should change. |
359 void InternalSetUserText(const string16& text); | 370 void InternalSetUserText(const string16& text); |
360 | 371 |
361 // Returns true if a keyword is selected. | 372 // Returns true if a keyword is selected. |
362 bool KeywordIsSelected() const; | 373 bool KeywordIsSelected() const; |
363 | 374 |
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 | 375 // 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 | 376 // user has input. Display text is the text being shown in the edit. The |
369 // two are different if a keyword is selected. | 377 // two are different if a keyword is selected. |
370 string16 DisplayTextFromUserText(const string16& text) const; | 378 string16 DisplayTextFromUserText(const string16& text) const; |
371 string16 UserTextFromDisplayText(const string16& text) const; | 379 string16 UserTextFromDisplayText(const string16& text) const; |
372 | 380 |
373 // Copies the selected match into |match|. If an update is in progress, | 381 // Copies the selected match into |match|. If an update is in progress, |
374 // "selected" means "default in the latest matches". If there are no matches, | 382 // "selected" means "default in the latest matches". If there are no matches, |
375 // does not update |match|. | 383 // does not update |match|. |
376 // | 384 // |
377 // If |alternate_nav_url| is non-NULL, it will be set to the alternate | 385 // If |alternate_nav_url| is non-NULL, it will be set to the alternate |
378 // navigation URL for |url| if one exists, or left unchanged otherwise. See | 386 // navigation URL for |url| if one exists, or left unchanged otherwise. See |
379 // comments on AutocompleteResult::GetAlternateNavURL(). | 387 // comments on AutocompleteResult::GetAlternateNavURL(). |
380 // | 388 // |
381 // TODO(pkasting): When manually_selected_match_ moves to the controller, this | 389 // TODO(pkasting): When manually_selected_match_ moves to the controller, this |
382 // can move too. | 390 // can move too. |
383 void InfoForCurrentSelection(AutocompleteMatch* match, | 391 void InfoForCurrentSelection(AutocompleteMatch* match, |
384 GURL* alternate_nav_url) const; | 392 GURL* alternate_nav_url) const { |
| 393 omnibox_controller_->InfoForCurrentSelection(match, alternate_nav_url); |
| 394 } |
385 | 395 |
386 // Returns the default match for the current text, as well as the alternate | 396 // Returns the default match for the current text, as well as the alternate |
387 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. | 397 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. |
388 void GetInfoForCurrentText(AutocompleteMatch* match, | 398 void GetInfoForCurrentText(AutocompleteMatch* match, |
389 GURL* alternate_nav_url) const; | 399 GURL* alternate_nav_url) const; |
390 | 400 |
391 // Reverts the edit box from a temporary text back to the original user text. | 401 // Reverts the edit box from a temporary text back to the original user text. |
392 // If |revert_popup| is true then the popup will be reverted as well. | 402 // If |revert_popup| is true then the popup will be reverted as well. |
393 void RevertTemporaryText(bool revert_popup); | 403 void RevertTemporaryText(bool revert_popup); |
394 | 404 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // If focus_state_ does not match |state|, we update it and notify the | 444 // If focus_state_ does not match |state|, we update it and notify the |
435 // InstantController about the change (passing along the |reason| for the | 445 // InstantController about the change (passing along the |reason| for the |
436 // change). If the caret visibility changes, we call ApplyCaretVisibility() on | 446 // change). If the caret visibility changes, we call ApplyCaretVisibility() on |
437 // the view. | 447 // the view. |
438 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); | 448 void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); |
439 | 449 |
440 scoped_ptr<OmniboxController> omnibox_controller_; | 450 scoped_ptr<OmniboxController> omnibox_controller_; |
441 | 451 |
442 OmniboxView* view_; | 452 OmniboxView* view_; |
443 | 453 |
444 OmniboxPopupModel* popup_; | |
445 | |
446 OmniboxEditController* controller_; | 454 OmniboxEditController* controller_; |
447 | 455 |
448 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; | 456 scoped_ptr<OmniboxCurrentPageDelegate> delegate_; |
449 | 457 |
450 OmniboxFocusState focus_state_; | 458 OmniboxFocusState focus_state_; |
451 | 459 |
452 // The URL of the currently displayed page. | 460 // The URL of the currently displayed page. |
453 string16 permanent_text_; | 461 string16 permanent_text_; |
454 | 462 |
455 // This flag is true when the user has modified the contents of the edit, but | 463 // This flag is true when the user has modified the contents of the edit, but |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // an exact keyword match. If this is true then keyword mode will be | 570 // an exact keyword match. If this is true then keyword mode will be |
563 // triggered automatically if the input is "<keyword> <search string>". We | 571 // triggered automatically if the input is "<keyword> <search string>". We |
564 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. | 572 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. |
565 // This has no effect if we're already in keyword mode. | 573 // This has no effect if we're already in keyword mode. |
566 bool allow_exact_keyword_match_; | 574 bool allow_exact_keyword_match_; |
567 | 575 |
568 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); | 576 DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); |
569 }; | 577 }; |
570 | 578 |
571 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ | 579 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ |
OLD | NEW |