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

Unified Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 20587003: InstantExtended: record initial focus state for omnibox interactions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/omnibox/omnibox_edit_model.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
index bdc292c8f8a68c89f27e61b0512d755ff3eca873..af053ced56886d47aea60494ab9d195165487e63 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -142,13 +142,15 @@ OmniboxEditModel::State::State(bool user_input_in_progress,
const string16& gray_text,
const string16& keyword,
bool is_keyword_hint,
- OmniboxFocusState focus_state)
+ OmniboxFocusState focus_state,
+ OmniboxFocusState focus_state_for_input)
: user_input_in_progress(user_input_in_progress),
user_text(user_text),
gray_text(gray_text),
keyword(keyword),
is_keyword_hint(is_keyword_hint),
- focus_state(focus_state) {
+ focus_state(focus_state),
+ focus_state_for_input(focus_state_for_input) {
}
OmniboxEditModel::State::~State() {
@@ -163,6 +165,7 @@ OmniboxEditModel::OmniboxEditModel(OmniboxView* view,
: view_(view),
controller_(controller),
focus_state_(OMNIBOX_FOCUS_NONE),
+ focus_state_for_input_(OMNIBOX_FOCUS_NONE),
user_input_in_progress_(false),
just_deleted_text_(false),
has_temporary_text_(false),
@@ -202,11 +205,13 @@ const OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() {
view_->GetGrayTextAutocompletion(),
keyword_,
is_keyword_hint_,
- focus_state_);
+ focus_state_,
+ focus_state_for_input_);
}
void OmniboxEditModel::RestoreState(const State& state) {
SetFocusState(state.focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH);
+ focus_state_for_input_ = state.focus_state_for_input;
// Restore any user editing.
if (state.user_input_in_progress) {
// NOTE: Be sure and set keyword-related state BEFORE invoking
@@ -445,6 +450,7 @@ void OmniboxEditModel::Revert() {
keyword_.clear();
is_keyword_hint_ = false;
has_temporary_text_ = false;
+ focus_state_for_input_ = OMNIBOX_FOCUS_NONE;
Peter Kasting 2013/07/26 22:58:09 Is this right? What if the user reverts everythin
samarth 2013/07/26 23:00:55 That works today because PageClassifcation is only
samarth 2013/07/26 23:19:01 Ok, Peter convinced me that not keeping this here
Peter Kasting 2013/07/26 23:22:34 Turns out you mean OpenMatch(), which is called, b
Mark P 2013/07/26 23:36:35 Okay. That sounds fine.
view_->SetWindowTextAndCaretPos(permanent_text_,
has_focus() ? permanent_text_.length() : 0,
false, true);
@@ -841,6 +847,7 @@ void OmniboxEditModel::OnKillFocus() {
// OmniboxFocusChanged() from OnWillKillFocus() to here, which would let us
// just call SetFocusState() to handle the state change.
focus_state_ = OMNIBOX_FOCUS_NONE;
+ focus_state_for_input_ = OMNIBOX_FOCUS_NONE;
control_key_state_ = UP;
paste_state_ = NONE;
}
@@ -1014,10 +1021,16 @@ bool OmniboxEditModel::OnAfterPossibleChange(const string16& old_text,
else if (text_differs)
paste_state_ = NONE;
- // Restore caret visibility whenever the user changes text or selection in the
- // omnibox.
- if (text_differs || selection_differs)
+ if (text_differs || selection_differs) {
+ // Record current focus state for this input if we haven't already.
+ DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_);
+ if (focus_state_for_input_ == OMNIBOX_FOCUS_NONE)
+ focus_state_for_input_ = focus_state_;
+
+ // Restore caret visibility whenever the user changes text or selection in
+ // the omnibox.
SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING);
+ }
// Modifying the selection counts as accepting the autocompleted text.
const bool user_text_changed =
@@ -1258,8 +1271,18 @@ metrics::OmniboxEventProto::PageClassification
OmniboxEditModel::ClassifyPage() const {
if (!delegate_->CurrentPageExists())
return metrics::OmniboxEventProto::OTHER;
- if (delegate_->IsInstantNTP())
- return metrics::OmniboxEventProto::INSTANT_NEW_TAB_PAGE;
+ if (delegate_->IsInstantNTP()) {
+ DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_for_input_);
+ if (focus_state_for_input_ == OMNIBOX_FOCUS_VISIBLE) {
+ return metrics::OmniboxEventProto::
+ INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS;
+ } else if (focus_state_for_input_ == OMNIBOX_FOCUS_INVISIBLE) {
Peter Kasting 2013/07/26 23:22:34 Nit: No else after return; also, per Chromium styl
samarth 2013/07/29 18:55:35 Done.
+ return metrics::OmniboxEventProto::
+ INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS;
+ }
+ NOTREACHED();
+ return metrics::OmniboxEventProto::OBSOLETE_INSTANT_NEW_TAB_PAGE;
+ }
const GURL& gurl = delegate_->GetURL();
if (!gurl.is_valid())
return metrics::OmniboxEventProto::INVALID_SPEC;

Powered by Google App Engine
This is Rietveld 408576698