| 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/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <locale> | 8 #include <locale> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // we _were_ switching tabs, the RevertAll() above already drew the new | 639 // we _were_ switching tabs, the RevertAll() above already drew the new |
| 640 // permanent text.) | 640 // permanent text.) |
| 641 | 641 |
| 642 // Tweak: if the user had all the text selected, select all the new text. | 642 // Tweak: if the user had all the text selected, select all the new text. |
| 643 // This makes one particular case better: the user clicks in the box to | 643 // This makes one particular case better: the user clicks in the box to |
| 644 // change it right before the permanent URL is changed. Since the new URL | 644 // change it right before the permanent URL is changed. Since the new URL |
| 645 // is still fully selected, the user's typing will replace the edit contents | 645 // is still fully selected, the user's typing will replace the edit contents |
| 646 // as they'd intended. | 646 // as they'd intended. |
| 647 CHARRANGE sel; | 647 CHARRANGE sel; |
| 648 GetSelection(sel); | 648 GetSelection(sel); |
| 649 const bool was_reversed = (sel.cpMin > sel.cpMax); | 649 const bool was_select_all = IsSelectAllForRange(sel); |
| 650 const bool was_select_all = (sel.cpMin != sel.cpMax) && | |
| 651 IsSelectAllForRange(sel); | |
| 652 | 650 |
| 653 RevertAll(); | 651 RevertAll(); |
| 654 | 652 |
| 655 if (was_select_all) | 653 // When the old text was empty, we don't bother selecting the new text. |
| 656 SelectAll(was_reversed); | 654 // You might think we could reach here if the user has deleted the previous |
| 655 // URL, but in that case the model will see that user input is in progress |
| 656 // and return false from UpdatePermanentText() (so we won't reach here), |
| 657 // unless we don't have focus, in which case we don't care anyway because |
| 658 // re-focusing the omnibox will modify the selection regardless. The only |
| 659 // time we actually reach here with empty text is when the user was on the |
| 660 // NTP and clicked something on the page to navigate, in which case the |
| 661 // omnibox shouldn't have focus anyway, and selecting all will at best do |
| 662 // nothing and at worst cause problems like reversing the URL. |
| 663 if (was_select_all && (sel.cpMin != sel.cpMax)) |
| 664 SelectAll(sel.cpMin > sel.cpMax); |
| 657 } else if (changed_security_level) { | 665 } else if (changed_security_level) { |
| 658 // Only the security style changed, nothing else. Redraw our text using it. | 666 // Only the security style changed, nothing else. Redraw our text using it. |
| 659 EmphasizeURLComponents(); | 667 EmphasizeURLComponents(); |
| 660 } | 668 } |
| 661 } | 669 } |
| 662 | 670 |
| 663 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, | 671 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, |
| 664 WindowOpenDisposition disposition, | 672 WindowOpenDisposition disposition, |
| 665 const GURL& alternate_nav_url, | 673 const GURL& alternate_nav_url, |
| 666 size_t selected_line) { | 674 size_t selected_line) { |
| (...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2825 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2833 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2826 } | 2834 } |
| 2827 | 2835 |
| 2828 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2836 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2829 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because | 2837 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because |
| 2830 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with | 2838 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with |
| 2831 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than | 2839 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than |
| 2832 // 1. | 2840 // 1. |
| 2833 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2841 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2834 } | 2842 } |
| OLD | NEW |