| 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 if (model()->UpdatePermanentText()) { | 487 if (model()->UpdatePermanentText()) { |
| 488 // Something visibly changed. Re-enable URL replacement. | 488 // Something visibly changed. Re-enable URL replacement. |
| 489 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | 489 controller()->GetToolbarModel()->set_url_replacement_enabled(true); |
| 490 model()->UpdatePermanentText(); | 490 model()->UpdatePermanentText(); |
| 491 | 491 |
| 492 // Tweak: if the user had all the text selected, select all the new text. | 492 // Tweak: if the user had all the text selected, select all the new text. |
| 493 // This makes one particular case better: the user clicks in the box to | 493 // This makes one particular case better: the user clicks in the box to |
| 494 // change it right before the permanent URL is changed. Since the new URL | 494 // change it right before the permanent URL is changed. Since the new URL |
| 495 // is still fully selected, the user's typing will replace the edit contents | 495 // is still fully selected, the user's typing will replace the edit contents |
| 496 // as they'd intended. | 496 // as they'd intended. |
| 497 const gfx::Range range(GetSelectedRange()); | 497 const bool was_select_all = !text().empty() && IsSelectAll(); |
| 498 const bool was_select_all = (range.length() == text().length()); | 498 const bool was_reversed = GetSelectedRange().is_reversed(); |
| 499 | 499 |
| 500 RevertAll(); | 500 RevertAll(); |
| 501 | 501 |
| 502 // Only select all when we have focus. If we don't have focus, selecting | 502 // Only select all when we have focus. If we don't have focus, selecting |
| 503 // all is unnecessary since the selection will change on regaining focus, | 503 // all is unnecessary since the selection will change on regaining focus, |
| 504 // and can in fact cause artifacts, e.g. if the user is on the NTP and | 504 // and can in fact cause artifacts, e.g. if the user is on the NTP and |
| 505 // clicks a link to navigate, causing |was_select_all| to be vacuously true | 505 // clicks a link to navigate, causing |was_select_all| to be vacuously true |
| 506 // for the empty omnibox, and we then select all here, leading to the | 506 // for the empty omnibox, and we then select all here, leading to the |
| 507 // trailing portion of a long URL being scrolled into view. We could try | 507 // trailing portion of a long URL being scrolled into view. We could try |
| 508 // and address cases like this, but it seems better to just not muck with | 508 // and address cases like this, but it seems better to just not muck with |
| 509 // things when the omnibox isn't focused to begin with. | 509 // things when the omnibox isn't focused to begin with. |
| 510 if (was_select_all && model()->has_focus()) | 510 if (was_select_all && model()->has_focus()) |
| 511 SelectAll(range.is_reversed()); | 511 SelectAll(was_reversed); |
| 512 } else if (old_security_level != security_level_) { | 512 } else if (old_security_level != security_level_) { |
| 513 EmphasizeURLComponents(); | 513 EmphasizeURLComponents(); |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 base::string16 OmniboxViewViews::GetText() const { | 517 base::string16 OmniboxViewViews::GetText() const { |
| 518 // TODO(oshima): IME support | 518 // TODO(oshima): IME support |
| 519 return text(); | 519 return text(); |
| 520 } | 520 } |
| 521 | 521 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 const base::string16 text(GetClipboardText()); | 1019 const base::string16 text(GetClipboardText()); |
| 1020 if (!text.empty()) { | 1020 if (!text.empty()) { |
| 1021 // Record this paste, so we can do different behavior. | 1021 // Record this paste, so we can do different behavior. |
| 1022 model()->OnPaste(); | 1022 model()->OnPaste(); |
| 1023 // Force a Paste operation to trigger the text_changed code in | 1023 // Force a Paste operation to trigger the text_changed code in |
| 1024 // OnAfterPossibleChange(), even if identical contents are pasted. | 1024 // OnAfterPossibleChange(), even if identical contents are pasted. |
| 1025 text_before_change_.clear(); | 1025 text_before_change_.clear(); |
| 1026 InsertOrReplaceText(text); | 1026 InsertOrReplaceText(text); |
| 1027 } | 1027 } |
| 1028 } | 1028 } |
| OLD | NEW |