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 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 keyword_, is_keyword_hint_, | 216 keyword_, is_keyword_hint_, |
217 controller_->GetToolbarModel()->search_term_replacement_enabled(), | 217 controller_->GetToolbarModel()->search_term_replacement_enabled(), |
218 focus_state_, focus_source_); | 218 focus_state_, focus_source_); |
219 } | 219 } |
220 | 220 |
221 void OmniboxEditModel::RestoreState(const State* state) { | 221 void OmniboxEditModel::RestoreState(const State* state) { |
222 // We need to update the permanent text correctly and revert the view | 222 // We need to update the permanent text correctly and revert the view |
223 // regardless of whether there is saved state. | 223 // regardless of whether there is saved state. |
224 controller_->GetToolbarModel()->set_search_term_replacement_enabled( | 224 controller_->GetToolbarModel()->set_search_term_replacement_enabled( |
225 !state || state->search_term_replacement_enabled); | 225 !state || state->search_term_replacement_enabled); |
226 permanent_text_ = controller_->GetToolbarModel()->GetText(true); | 226 permanent_text_ = controller_->GetToolbarModel()->GetText(); |
227 // Don't muck with the search term replacement state, as we've just set it | 227 // Don't muck with the search term replacement state, as we've just set it |
228 // correctly. | 228 // correctly. |
229 view_->RevertWithoutResettingSearchTermReplacement(); | 229 view_->RevertWithoutResettingSearchTermReplacement(); |
230 if (!state) | 230 if (!state) |
231 return; | 231 return; |
232 | 232 |
233 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); | 233 SetFocusState(state->focus_state, OMNIBOX_FOCUS_CHANGE_TAB_SWITCH); |
234 focus_source_ = state->focus_source; | 234 focus_source_ = state->focus_source; |
235 // Restore any user editing. | 235 // Restore any user editing. |
236 if (state->user_input_in_progress) { | 236 if (state->user_input_in_progress) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // always safe to change the text; this also prevents someone toggling "Show | 276 // always safe to change the text; this also prevents someone toggling "Show |
277 // URL" (which sounds as if it might be persistent) from seeing just that URL | 277 // URL" (which sounds as if it might be persistent) from seeing just that URL |
278 // forever afterwards. | 278 // forever afterwards. |
279 // | 279 // |
280 // If the page is auto-committing gray text, however, we generally don't want | 280 // If the page is auto-committing gray text, however, we generally don't want |
281 // to make any change to the edit. While auto-commits modify the underlying | 281 // to make any change to the edit. While auto-commits modify the underlying |
282 // permanent URL, they're intended to have no effect on the user's editing | 282 // permanent URL, they're intended to have no effect on the user's editing |
283 // process -- before and after the auto-commit, the omnibox should show the | 283 // process -- before and after the auto-commit, the omnibox should show the |
284 // same user text and the same instant suggestion, even if the auto-commit | 284 // same user text and the same instant suggestion, even if the auto-commit |
285 // happens while the edit doesn't have focus. | 285 // happens while the edit doesn't have focus. |
286 string16 new_permanent_text = controller_->GetToolbarModel()->GetText(true); | 286 string16 new_permanent_text = controller_->GetToolbarModel()->GetText(); |
287 string16 gray_text = view_->GetGrayTextAutocompletion(); | 287 string16 gray_text = view_->GetGrayTextAutocompletion(); |
288 const bool visibly_changed_permanent_text = | 288 const bool visibly_changed_permanent_text = |
289 (permanent_text_ != new_permanent_text) && | 289 (permanent_text_ != new_permanent_text) && |
290 (!has_focus() || | 290 (!has_focus() || |
291 (!user_input_in_progress_ && !popup_model()->IsOpen() && | 291 (!user_input_in_progress_ && !popup_model()->IsOpen() && |
292 controller_->GetToolbarModel()->search_term_replacement_enabled())) && | 292 controller_->GetToolbarModel()->search_term_replacement_enabled())) && |
293 (gray_text.empty() || | 293 (gray_text.empty() || |
294 new_permanent_text != user_text_ + gray_text); | 294 new_permanent_text != user_text_ + gray_text); |
295 | 295 |
296 permanent_text_ = new_permanent_text; | 296 permanent_text_ = new_permanent_text; |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 instant->OmniboxFocusChanged(state, reason, NULL); | 1405 instant->OmniboxFocusChanged(state, reason, NULL); |
1406 | 1406 |
1407 // Update state and notify view if the omnibox has focus and the caret | 1407 // Update state and notify view if the omnibox has focus and the caret |
1408 // visibility changed. | 1408 // visibility changed. |
1409 const bool was_caret_visible = is_caret_visible(); | 1409 const bool was_caret_visible = is_caret_visible(); |
1410 focus_state_ = state; | 1410 focus_state_ = state; |
1411 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1411 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1412 is_caret_visible() != was_caret_visible) | 1412 is_caret_visible() != was_caret_visible) |
1413 view_->ApplyCaretVisibility(); | 1413 view_->ApplyCaretVisibility(); |
1414 } | 1414 } |
OLD | NEW |