| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // Tweak: if the user had all the text selected, select all the new text. | 383 // Tweak: if the user had all the text selected, select all the new text. |
| 384 // This makes one particular case better: the user clicks in the box to | 384 // This makes one particular case better: the user clicks in the box to |
| 385 // change it right before the permanent URL is changed. Since the new URL | 385 // change it right before the permanent URL is changed. Since the new URL |
| 386 // is still fully selected, the user's typing will replace the edit contents | 386 // is still fully selected, the user's typing will replace the edit contents |
| 387 // as they'd intended. | 387 // as they'd intended. |
| 388 const ui::Range range(GetSelectedRange()); | 388 const ui::Range range(GetSelectedRange()); |
| 389 const bool was_select_all = (range.length() == text().length()); | 389 const bool was_select_all = (range.length() == text().length()); |
| 390 | 390 |
| 391 RevertAll(); | 391 RevertAll(); |
| 392 | 392 |
| 393 if (was_select_all) | 393 // Only select all when we have focus. If we don't have focus, selecting |
| 394 // all is unnecessary since the selection will change on regaining focus, |
| 395 // and can in fact cause artifacts, e.g. if the user is on the NTP and |
| 396 // clicks a link to navigate, causing |was_select_all| to be vacuously true |
| 397 // for the empty omnibox, and we then select all here, leading to the |
| 398 // trailing portion of a long URL being scrolled into view. We could try |
| 399 // and address cases like this, but it seems better to just not muck with |
| 400 // things when the omnibox isn't focused to begin with. |
| 401 if (was_select_all && model()->has_focus()) |
| 394 SelectAll(range.is_reversed()); | 402 SelectAll(range.is_reversed()); |
| 395 } else if (changed_security_level) { | 403 } else if (changed_security_level) { |
| 396 EmphasizeURLComponents(); | 404 EmphasizeURLComponents(); |
| 397 } | 405 } |
| 398 } | 406 } |
| 399 | 407 |
| 400 string16 OmniboxViewViews::GetText() const { | 408 string16 OmniboxViewViews::GetText() const { |
| 401 // TODO(oshima): IME support | 409 // TODO(oshima): IME support |
| 402 return text(); | 410 return text(); |
| 403 } | 411 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 const string16 text(GetClipboardText()); | 915 const string16 text(GetClipboardText()); |
| 908 if (!text.empty()) { | 916 if (!text.empty()) { |
| 909 // Record this paste, so we can do different behavior. | 917 // Record this paste, so we can do different behavior. |
| 910 model()->on_paste(); | 918 model()->on_paste(); |
| 911 // Force a Paste operation to trigger the text_changed code in | 919 // Force a Paste operation to trigger the text_changed code in |
| 912 // OnAfterPossibleChange(), even if identical contents are pasted. | 920 // OnAfterPossibleChange(), even if identical contents are pasted. |
| 913 text_before_change_.clear(); | 921 text_before_change_.clear(); |
| 914 InsertOrReplaceText(text); | 922 InsertOrReplaceText(text); |
| 915 } | 923 } |
| 916 } | 924 } |
| OLD | NEW |