12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_match.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/omnibox/omnibox_controller.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/omnibox_focus_state.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h" 207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutocompleteController; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutocompleteResult; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class OmniboxCurrentPageDelegate; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OmniboxEditController; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OmniboxPopupModel; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OmniboxView; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Image; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Rect; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Reasons why the Omnibox could change into keyword mode. 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// These numeric values are used in UMA logs; do not change them. 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum EnteredKeywordModeMethod { 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ENTERED_KEYWORD_MODE_VIA_TAB = 0, 39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ENTERED_KEYWORD_MODE_VIA_SPACE_AT_END = 1, 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ENTERED_KEYWORD_MODE_VIA_SPACE_IN_MIDDLE = 2, 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ENTERED_KEYWORD_MODE_NUM_ITEMS 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class OmniboxEditModel { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 463240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Did the Omnibox focus originate via the user clicking on the Omnibox or on 473240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // the Fakebox? 483240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch enum FocusSource { 493240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch INVALID = 0, 503240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch OMNIBOX = 1, 513240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch FAKEBOX = 2 523240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch }; 533240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct State { 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) State(bool user_input_in_progress, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& user_text, 577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const string16& gray_text, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& keyword, 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_keyword_hint, 603240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch OmniboxFocusState focus_state, 613240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch FocusSource focus_source); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~State(); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool user_input_in_progress; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 user_text; 667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const string16 gray_text; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16 keyword; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const bool is_keyword_hint; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OmniboxFocusState focus_state; 703240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch FocusSource focus_source; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OmniboxEditModel(OmniboxView* view, 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OmniboxEditController* controller, 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~OmniboxEditModel(); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // TODO(beaudoin): Remove this accessor when the AutocompleteController has 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // completely moved to OmniboxController. 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AutocompleteController* autocomplete_controller() const { 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return omnibox_controller_->autocomplete_controller(); 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_popup_model(OmniboxPopupModel* popup_model) { 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) omnibox_controller_->set_popup_model(popup_model); 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO: The edit and popup should be siblings owned by the LocationBarView, 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // making this accessor unnecessary. 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) OmniboxPopupModel* popup_model() const { 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return omnibox_controller_->popup_model(); 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OmniboxEditController* controller() const { return controller_; } 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile() const { return profile_; } 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current state. This assumes we are switching tabs, and changes 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the internal state appropriately. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const State GetStateForTabSwitch(); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restores local state from the saved |state|. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RestoreState(const State& state); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the match for the current text. If the user has not edited the text 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // this is the match corresponding to the permanent text. Returns the 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // alternate nav URL, if |alternate_nav_url| is non-NULL and there is such a 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // URL. 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AutocompleteMatch CurrentMatch(GURL* alternate_nav_url) const; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user wants to export the entire current text as a URL. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the url, and if known, the title and favicon. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetDataForURLExport(GURL* url, string16* title, gfx::Image* favicon); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the current edit contents will be treated as a 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL/navigation, as opposed to a search. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CurrentTextIsURL() const; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the match type for the current edit contents. 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AutocompleteMatch::Type CurrentTextType() const; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked to adjust the text before writting to the clipboard for a copy 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (e.g. by adding 'http' to the front). |sel_min| gives the minimum position 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the selection e.g. min(selection_start, selection_end). |text| is the 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // currently selected text. If |is_all_selected| is true all the text in the 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // edit is selected. If the url should be copied to the clipboard |write_url| 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is set to true and |url| set to the url to write. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AdjustTextForCopy(int sel_min, 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_all_selected, 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16* text, 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL* url, 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* write_url); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool user_input_in_progress() const { return user_input_in_progress_; } 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the state of user_input_in_progress_, and notifies the observer if 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that state has changed. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetInputInProgress(bool in_progress); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates permanent_text_ to |new_permanent_text|. Returns true if this 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // change should be immediately user-visible, because either the user is not 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // editing or the edit does not have focus. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool UpdatePermanentText(const string16& new_permanent_text); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the URL corresponding to the permanent text. 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL PermanentURL(); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the user_text_ to |text|. Only the View should call this. 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetUserText(const string16& text); 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Commits the gray suggested text as if it's been input by the user. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the text was committed. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO: can the return type be void? 154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool CommitSuggestedText(); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Invoked any time the text may have changed in the edit. Notifies the 1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // controller. 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnChanged(); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reverts the edit model back to its unedited state (permanent text showing, 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no user input in progress). 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Revert(); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Directs the popup to start autocomplete. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartAutocomplete(bool has_selected_text, 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool prevent_inline_autocomplete) const; 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Closes the popup and cancels any pending asynchronous queries. 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StopAutocomplete(); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Determines whether the user can "paste and go", given the specified text. 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanPasteAndGo(const string16& text) const; 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Navigates to the destination last supplied to CanPasteAndGo. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PasteAndGo(const string16& text); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this is a paste-and-search rather than paste-and-go (or 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nothing). 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsPasteAndSearch(const string16& text) const; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Asks the browser to load the popup's currently selected item, using the 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // supplied disposition. This may close the popup. If |for_drop| is true, 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it indicates the input is being accepted as part of a drop operation and 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the transition should be treated as LINK (so that it won't trigger the 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL to be autocompleted). 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AcceptInput(WindowOpenDisposition disposition, 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool for_drop); 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Asks the browser to load the item at |index|, with the given properties. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OpenMatch(const AutocompleteMatch& match, 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowOpenDisposition disposition, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& alternate_nav_url, 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t index); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OmniboxFocusState focus_state() const { return focus_state_; } 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool has_focus() const { return focus_state_ != OMNIBOX_FOCUS_NONE; } 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_caret_visible() const { 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return focus_state_ == OMNIBOX_FOCUS_VISIBLE; 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Accessors for keyword-related state (see comments on keyword_ and 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is_keyword_hint_). 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& keyword() const { return keyword_; } 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_keyword_hint() const { return is_keyword_hint_; } 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Accepts the current keyword hint as a keyword. It always returns true for 207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // caller convenience. |entered_method| indicates how the use entered 208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // keyword mode. This parameter is only used for metrics/logging; it's not 209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // used to change user-visible behavior. 210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool AcceptKeyword(EnteredKeywordModeMethod entered_method); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Accepts the current temporary text as the user text. 21390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void AcceptTemporaryTextAsUserText(); 21490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears the current keyword. |visible_text| is the (non-keyword) text 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // currently visible in the edit. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearKeyword(const string16& visible_text); 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current autocomplete result. This logic should in the future 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // live in AutocompleteController but resides here for now. This method is 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used by AutomationProvider::AutocompleteEditGetMatches. 22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const AutocompleteResult& result() const { 22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return omnibox_controller_->result(); 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the view is gaining focus. |control_down| is whether the 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // control key is down (at the time we're gaining focus). 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnSetFocus(bool control_down); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the visibility of the caret in the omnibox, if it has focus. The 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // visibility of the caret is reset to visible if either 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // - The user starts typing, or 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // - We explicitly focus the omnibox again. 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The latter case must be handled in three separate places--OnSetFocus(), 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // OmniboxView::SetFocus(), and the mouse handlers in OmniboxView. See 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // accompanying comments for why each of these is necessary. 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Caret visibility is tracked per-tab and updates automatically upon 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // switching tabs. 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetCaretVisibility(bool visible); 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sent before |OnKillFocus| and before the popup is closed. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnWillKillFocus(gfx::NativeView view_gaining_focus); 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the view is losing focus. Resets some state. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnKillFocus(); 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user presses the escape key. Decides what, if anything, to 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // revert about any current edits. Returns whether the key was handled. 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool OnEscapeKeyPressed(); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user presses or releases the control key. Changes state as 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // necessary. 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnControlKeyChanged(bool pressed); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user pastes in text. 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void on_paste() { paste_state_ = PASTING; } 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if pasting is in progress. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_pasting() const { return paste_state_ == PASTING; } 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 26290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(beaudoin): Try not to expose this. 26390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool in_revert() const { return in_revert_; } 26490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user presses up or down. |count| is a repeat count, 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // negative for moving up, positive for moving down. 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnUpOrDownKeyPressed(int count); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when any relevant data changes. This rolls together several 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // separate pieces of data into one call so we can update all the UI 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // efficiently: 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |text| is either the new temporary text from the user manually selecting 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a different match, or the inline autocomplete text. We distinguish by 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // checking if |destination_for_temporary_text_change| is NULL. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |destination_for_temporary_text_change| is NULL (if temporary text should 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not change) or the pre-change destination URL (if temporary text should 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // change) so we can save it off to restore later. 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |keyword| is the keyword to show a hint for if |is_keyword_hint| is true, 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or the currently selected keyword if |is_keyword_hint| is false (see 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // comments on keyword_ and is_keyword_hint_). 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnPopupDataChanged( 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& text, 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL* destination_for_temporary_text_change, 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& keyword, 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_keyword_hint); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by the OmniboxView after something changes, with details about what 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // state changes occured. Updates internal state, updates the popup if 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // necessary, and returns true if any significant changes occurred. Note that 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |text_differs| may be set even if |old_text| == |new_text|, e.g. if we've 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // just committed an IME composition. 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |allow_keyword_ui_change| is false then the change should not affect 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // keyword ui state, even if the text matches a keyword exactly. This value 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // may be false when the user is composing a text with an IME. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool OnAfterPossibleChange(const string16& old_text, 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& new_text, 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t selection_start, 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t selection_end, 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool selection_differs, 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool text_differs, 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool just_deleted_text, 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool allow_keyword_ui_change); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Called when the current match has changed in the OmniboxController. 306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void OnCurrentMatchChanged(); 3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Access the current view text. 3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) string16 GetViewText() const; 3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 311868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // TODO(beaudoin): We need this to allow OmniboxController access the 312868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // InstantController via OmniboxEditController, because the only valid pointer 313868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // to InstantController is kept in Browser. We should try to get rid of this, 314868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // maybe by ensuring InstantController lives as long as Browser. 315868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) InstantController* GetInstantController() const; 316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 31890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) friend class OmniboxControllerTest; 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum PasteState { 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NONE, // Most recent edit was not a paste. 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PASTING, // In the middle of doing a paste. We need this intermediate 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // state because OnPaste() does the actual detection of 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // paste, but OnAfterPossibleChange() has to update the 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // paste state for every edit. If OnPaste() set the state 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // directly to PASTED, OnAfterPossibleChange() wouldn't know 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // whether that represented the current edit or a past one. 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PASTED, // Most recent edit was a paste. 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum ControlKeyState { 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UP, // The control key is not depressed. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DOWN_WITHOUT_CHANGE, // The control key is depressed, and the edit's 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // contents/selection have not changed since it was 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // depressed. This is the only state in which we 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // do the "ctrl-enter" behavior when the user hits 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // enter. 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DOWN_WITH_CHANGE, // The control key is depressed, and the edit's 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // contents/selection have changed since it was 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // depressed. If the user now hits enter, we assume 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // he simply hasn't released the key, rather than that 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // he intended to hit "ctrl-enter". 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if a query to an autocomplete provider is currently 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in progress. This logic should in the future live in 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // AutocompleteController but resides here for now. This method is used by 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // AutomationProvider::AutocompleteEditIsQueryInProgress. 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool query_in_progress() const; 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called whenever user_text_ should change. 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void InternalSetUserText(const string16& text); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if a keyword is selected. 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool KeywordIsSelected() const; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 357868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Turns off keyword mode for the current match. 358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void ClearPopupKeywordMode() const; 359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Conversion between user text and display text. User text is the text the 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user has input. Display text is the text being shown in the edit. The 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // two are different if a keyword is selected. 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 DisplayTextFromUserText(const string16& text) const; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 UserTextFromDisplayText(const string16& text) const; 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 366b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // If there's a selected match, copies it into |match|. Else, returns the 367b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // default match for the current text, as well as the alternate nav URL, if 368b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // |alternate_nav_url| is non-NULL and there is such a URL. 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetInfoForCurrentText(AutocompleteMatch* match, 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL* alternate_nav_url) const; 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reverts the edit box from a temporary text back to the original user text. 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |revert_popup| is true then the popup will be reverted as well. 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RevertTemporaryText(bool revert_popup); 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Accepts current keyword if the user just typed a space at the end of 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |new_text|. This handles both of the following cases: 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (assume "foo" is a keyword, | is the input caret, [] is selected text) 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // foo| -> foo | (a space was appended to a keyword) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // foo[bar] -> foo | (a space replaced other text after a keyword) 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the current keyword is accepted. 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool MaybeAcceptKeywordBySpace(const string16& new_text); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks whether the user inserted a space into |old_text| and by doing so 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // created a |new_text| that looks like "<keyword> <search phrase>". 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CreatedKeywordSearchByInsertingSpaceInMiddle( 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& old_text, 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& new_text, 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t caret_position) const; 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks if a given character is a valid space character for accepting 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // keyword. 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsSpaceCharForAcceptingKeyword(wchar_t c); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Classify the current page being viewed as, for example, the new tab 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // page or a normal web page. Used for logging omnibox events for 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // UMA opted-in users. Examines the user's profile to determine if the 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // current page is the user's home page. 399558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch AutocompleteInput::PageClassification ClassifyPage() const; 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets |match| and |alternate_nav_url| based on classifying |text|. 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |alternate_nav_url| may be NULL. 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClassifyStringForPasteAndGo(const string16& text, 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AutocompleteMatch* match, 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL* alternate_nav_url) const; 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If focus_state_ does not match |state|, we update it and notify the 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // InstantController about the change (passing along the |reason| for the 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // change). If the caret visibility changes, we call ApplyCaretVisibility() on 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the view. 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetFocusState(OmniboxFocusState state, OmniboxFocusChangeReason reason); 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 413c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<OmniboxController> omnibox_controller_; 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OmniboxView* view_; 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OmniboxEditController* controller_; 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<OmniboxCurrentPageDelegate> delegate_; 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OmniboxFocusState focus_state_; 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4233240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // Used to keep track whether the input currently in progress originated by 4243240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // focusing in the Omnibox or in the Fakebox. This will be INVALID if no input 4253240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch // is in progress or the Omnibox is not focused. 4263240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch FocusSource focus_source_; 4273240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The URL of the currently displayed page. 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 permanent_text_; 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This flag is true when the user has modified the contents of the edit, but 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not yet accepted them. We use this to determine when we need to save 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // state (on switching tabs) and whether changes to the page URL should be 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // immediately displayed. 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This flag will be true in a superset of the cases where the popup is open. 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool user_input_in_progress_; 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The text that the user has entered. This does not include inline 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // autocomplete text that has not yet been accepted. 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 user_text_; 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4422385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch // We keep track of when the user last focused on the omnibox. 4432385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch base::TimeTicks last_omnibox_focus_; 4442385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch 4452385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch // Whether any user input has occurred since focusing on the omnibox. This is 4462385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch // used along with |last_omnibox_focus_| to calculate the time between a user 4472385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch // focusing on the omnibox and editing. It is initialized to true since 4482385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch // there was no focus event. 4492385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch bool user_input_since_focus_; 4507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We keep track of when the user began modifying the omnibox text. 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This should be valid whenever user_input_in_progress_ is true. 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks time_user_first_modified_omnibox_; 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When the user closes the popup, we need to remember the URL for their 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // desired choice, so that if they hit enter without reopening the popup we 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // know where to go. We could simply rerun autocomplete in this case, but 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // we'd need to either wait for all results to come in (unacceptably slow) or 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // do the wrong thing when the user had chosen some provider whose results 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // were not returned instantaneously. 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This variable is only valid when user_input_in_progress_ is true, since 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when it is false the user has either never input anything (so there won't 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be a value here anyway) or has canceled their input, which should be 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // treated the same way. Also, since this is for preserving a desired URL 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // after the popup has been closed, we ignore this if the popup is open, and 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // simply ask the popup for the desired URL directly. As a result, the 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // contents of this variable only need to be updated when the popup is closed 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // but user_input_in_progress_ is not being cleared. 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 url_for_remembered_user_selection_; 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Inline autocomplete is allowed if the user has not just deleted text, and 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no temporary text is showing. In this case, inline_autocomplete_text_ is 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // appended to the user_text_ and displayed selected (at least initially). 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: When the popup is closed there should never be inline autocomplete 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // text (actions that close the popup should either accept the text, convert 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it to a normal selection, or change the edit entirely). 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool just_deleted_text_; 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 inline_autocomplete_text_; 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used by OnPopupDataChanged to keep track of whether there is currently a 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // temporary text. 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Example of use: If the user types "goog", then arrows down in the 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // autocomplete popup until, say, "google.com" appears in the edit box, then 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the user_text_ is still "goog", and "google.com" is "temporary text". 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When the user hits <esc>, the edit box reverts to "goog". Hit <esc> again 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the popup is closed and "goog" is replaced by the permanent_text_, 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which is the URL of the current page. 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // original_url_ is only valid when there is temporary text, and is used as 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the unique identifier of the originally selected item. Thus, if the user 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // arrows to a different item with the same text, we can still distinguish 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // them and not revert all the way to the permanent_text_. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_temporary_text_; 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL original_url_; 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When the user's last action was to paste, we disallow inline autocomplete 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (on the theory that the user is trying to paste in a new URL or part of 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // one, and in either case inline autocomplete would get in the way). 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PasteState paste_state_; 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether the control key is depressed. We track this to avoid calling 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // UpdatePopup() repeatedly if the user holds down the key, and to know 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // whether to trigger "ctrl-enter" behavior. 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ControlKeyState control_key_state_; 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The keyword associated with the current match. The user may have an actual 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // selected keyword, or just some input text that looks like a keyword (so we 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // can show a hint to press <tab>). This is the keyword in either case; 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is_keyword_hint_ (below) distinguishes the two cases. 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 keyword_; 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the keyword associated with this match is merely a hint, i.e. the 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user hasn't actually selected a keyword yet. When this is true, we can use 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // keyword_ to show a "Press <tab> to search" sort of hint. 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_keyword_hint_; 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // This is needed to properly update the SearchModel state when the user 5237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // presses escape. 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool in_revert_; 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates if the upcoming autocomplete search is allowed to be treated as 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an exact keyword match. If this is true then keyword mode will be 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // triggered automatically if the input is "<keyword> <search string>". We 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true. 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This has no effect if we're already in keyword mode. 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool allow_exact_keyword_match_; 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(OmniboxEditModel); 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_EDIT_MODEL_H_ 537