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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 // Update the paste state as appropriate: if we're just finishing a paste | 1025 // Update the paste state as appropriate: if we're just finishing a paste |
1026 // that replaced all the text, preserve that information; otherwise, if we've | 1026 // that replaced all the text, preserve that information; otherwise, if we've |
1027 // made some other edit, clear paste tracking. | 1027 // made some other edit, clear paste tracking. |
1028 if (paste_state_ == PASTING) | 1028 if (paste_state_ == PASTING) |
1029 paste_state_ = PASTED; | 1029 paste_state_ = PASTED; |
1030 else if (text_differs) | 1030 else if (text_differs) |
1031 paste_state_ = NONE; | 1031 paste_state_ = NONE; |
1032 | 1032 |
1033 if (text_differs || selection_differs) { | 1033 if (text_differs || selection_differs) { |
1034 // Record current focus state for this input if we haven't already. | 1034 // Record current focus state for this input if we haven't already. |
1035 DCHECK_NE(OMNIBOX_FOCUS_NONE, focus_state_); | |
1036 if (focus_source_ == INVALID) { | 1035 if (focus_source_ == INVALID) { |
1037 focus_source_ = (focus_state_ == OMNIBOX_FOCUS_VISIBLE) ? | 1036 // We should generally expect the omnibox to have focus at this point, but |
1038 OMNIBOX : FAKEBOX; | 1037 // it doesn't always on Linux. This is because, unlike other platforms, |
| 1038 // right clicking in the omnibox on Linux doesn't focus it. So pasting via |
| 1039 // right-click can change the contents without focusing the omnibox. |
| 1040 // TODO(samarth): fix Linux focus behavior and add a DCHECK here to |
| 1041 // check that the omnibox does have focus. |
| 1042 focus_source_ = (focus_state_ == OMNIBOX_FOCUS_INVISIBLE) ? |
| 1043 FAKEBOX : OMNIBOX; |
1039 } | 1044 } |
1040 | 1045 |
1041 // Restore caret visibility whenever the user changes text or selection in | 1046 // Restore caret visibility whenever the user changes text or selection in |
1042 // the omnibox. | 1047 // the omnibox. |
1043 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING); | 1048 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_TYPING); |
1044 } | 1049 } |
1045 | 1050 |
1046 // Modifying the selection counts as accepting the autocompleted text. | 1051 // Modifying the selection counts as accepting the autocompleted text. |
1047 const bool user_text_changed = | 1052 const bool user_text_changed = |
1048 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); | 1053 text_differs || (selection_differs && !inline_autocomplete_text_.empty()); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 instant->OmniboxFocusChanged(state, reason, NULL); | 1326 instant->OmniboxFocusChanged(state, reason, NULL); |
1322 | 1327 |
1323 // Update state and notify view if the omnibox has focus and the caret | 1328 // Update state and notify view if the omnibox has focus and the caret |
1324 // visibility changed. | 1329 // visibility changed. |
1325 const bool was_caret_visible = is_caret_visible(); | 1330 const bool was_caret_visible = is_caret_visible(); |
1326 focus_state_ = state; | 1331 focus_state_ = state; |
1327 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1332 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1328 is_caret_visible() != was_caret_visible) | 1333 is_caret_visible() != was_caret_visible) |
1329 view_->ApplyCaretVisibility(); | 1334 view_->ApplyCaretVisibility(); |
1330 } | 1335 } |
OLD | NEW |