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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 // Not switching tabs, just updating the permanent text. (In the case where | 379 // Not switching tabs, just updating the permanent text. (In the case where |
380 // we _were_ switching tabs, the RevertAll() above already drew the new | 380 // we _were_ switching tabs, the RevertAll() above already drew the new |
381 // permanent text.) | 381 // permanent text.) |
382 | 382 |
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()); |
msw
2013/07/02 23:35:21
nit: |was_select_all| should include the non-empty
Peter Kasting
2013/07/02 23:38:45
|was_select_all| is vacuously true when there's no
msw
2013/07/03 00:04:07
The current logic will 'make it also mean "...or t
| |
390 | 390 |
391 RevertAll(); | 391 RevertAll(); |
392 | 392 |
393 if (was_select_all) | 393 // When the old text was empty, we don't bother selecting the new text. |
394 // You might think we could reach here if the user has deleted the previous | |
msw
2013/07/02 23:35:21
nit: Just explain the reasoning plainly: "Do not s
Peter Kasting
2013/07/02 23:38:45
Rendering jank isn't my concern, and the rest of t
msw
2013/07/03 00:04:07
Fine, but there's little reason to speculate about
| |
395 // URL, but in that case the model will see that user input is in progress | |
396 // and return false from UpdatePermanentText() (so we won't reach here), | |
397 // unless we don't have focus, in which case we don't care anyway because | |
398 // re-focusing the omnibox will modify the selection regardless. The only | |
399 // time we actually reach here with empty text is when the user was on the | |
400 // NTP and clicked something on the page to navigate, in which case the | |
401 // omnibox shouldn't have focus anyway, and selecting all will at best do | |
msw
2013/07/03 00:04:07
The comment, "in which case the omnibox shouldn't
| |
402 // nothing and at worst cause problems like reversing the URL. | |
msw
2013/07/03 00:04:07
The URL would not be reversed; the problem we obse
| |
403 if (was_select_all && !range.is_empty()) | |
394 SelectAll(range.is_reversed()); | 404 SelectAll(range.is_reversed()); |
395 } else if (changed_security_level) { | 405 } else if (changed_security_level) { |
396 EmphasizeURLComponents(); | 406 EmphasizeURLComponents(); |
397 } | 407 } |
398 } | 408 } |
399 | 409 |
400 string16 OmniboxViewViews::GetText() const { | 410 string16 OmniboxViewViews::GetText() const { |
401 // TODO(oshima): IME support | 411 // TODO(oshima): IME support |
402 return text(); | 412 return text(); |
403 } | 413 } |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 const string16 text(GetClipboardText()); | 917 const string16 text(GetClipboardText()); |
908 if (!text.empty()) { | 918 if (!text.empty()) { |
909 // Record this paste, so we can do different behavior. | 919 // Record this paste, so we can do different behavior. |
910 model()->on_paste(); | 920 model()->on_paste(); |
911 // Force a Paste operation to trigger the text_changed code in | 921 // Force a Paste operation to trigger the text_changed code in |
912 // OnAfterPossibleChange(), even if identical contents are pasted. | 922 // OnAfterPossibleChange(), even if identical contents are pasted. |
913 text_before_change_.clear(); | 923 text_before_change_.clear(); |
914 InsertOrReplaceText(text); | 924 InsertOrReplaceText(text); |
915 } | 925 } |
916 } | 926 } |
OLD | NEW |