| 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 // Only select all when we have focus. If we don't have focus, selecting |
| 656 SelectAll(was_reversed); | 654 // all is unnecessary since the selection will change on regaining focus, |
| 655 // and can in fact cause artifacts, e.g. if the user is on the NTP and |
| 656 // clicks a link to navigate, causing |was_select_all| to be vacuously true |
| 657 // for the empty omnibox, and we then select all here, leading to the |
| 658 // trailing portion of a long URL being scrolled into view. We could try |
| 659 // and address cases like this, but it seems better to just not muck with |
| 660 // things when the omnibox isn't focused to begin with. |
| 661 if (was_select_all && model()->has_focus()) |
| 662 SelectAll(sel.cpMin > sel.cpMax); |
| 657 } else if (changed_security_level) { | 663 } else if (changed_security_level) { |
| 658 // Only the security style changed, nothing else. Redraw our text using it. | 664 // Only the security style changed, nothing else. Redraw our text using it. |
| 659 EmphasizeURLComponents(); | 665 EmphasizeURLComponents(); |
| 660 } | 666 } |
| 661 } | 667 } |
| 662 | 668 |
| 663 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, | 669 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, |
| 664 WindowOpenDisposition disposition, | 670 WindowOpenDisposition disposition, |
| 665 const GURL& alternate_nav_url, | 671 const GURL& alternate_nav_url, |
| 666 size_t selected_line) { | 672 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); | 2831 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2826 } | 2832 } |
| 2827 | 2833 |
| 2828 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2834 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2829 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because | 2835 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because |
| 2830 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with | 2836 // 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 | 2837 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than |
| 2832 // 1. | 2838 // 1. |
| 2833 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2839 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2834 } | 2840 } |
| OLD | NEW |