| 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_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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 // * The user has just pasted in something that replaced all the text | 754 // * The user has just pasted in something that replaced all the text |
| 755 // * The user is trying to compose something in an IME | 755 // * The user is trying to compose something in an IME |
| 756 CHARRANGE sel; | 756 CHARRANGE sel; |
| 757 GetSel(sel); | 757 GetSel(sel); |
| 758 model()->StartAutocomplete(sel.cpMax != sel.cpMin, | 758 model()->StartAutocomplete(sel.cpMax != sel.cpMin, |
| 759 (sel.cpMax < GetTextLength()) || IsImeComposing()); | 759 (sel.cpMax < GetTextLength()) || IsImeComposing()); |
| 760 } | 760 } |
| 761 | 761 |
| 762 void OmniboxViewWin::SetFocus() { | 762 void OmniboxViewWin::SetFocus() { |
| 763 ::SetFocus(m_hWnd); | 763 ::SetFocus(m_hWnd); |
| 764 // Restore caret visibility if focused explicitly. We need to do this here | 764 // Restore caret visibility if focus is explicitly requested. This is |
| 765 // because if we already have invisible focus, the ::SetFocus call above will | 765 // necessary because if we already have invisible focus, the ::SetFocus() |
| 766 // short-circuit, preventing us from reaching OmniboxEditModel::OnSetFocus(), | 766 // call above will short-circuit, preventing us from reaching |
| 767 // which handles restoring visibility when we didn't previously have focus. | 767 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the |
| 768 // omnibox regains focus after losing focus. |
| 768 model()->SetCaretVisibility(true); | 769 model()->SetCaretVisibility(true); |
| 769 } | 770 } |
| 770 | 771 |
| 771 void OmniboxViewWin::ApplyCaretVisibility() { | 772 void OmniboxViewWin::ApplyCaretVisibility() { |
| 772 // We hide the caret just before destroying it, since destroying a caret that | 773 // We hide the caret just before destroying it, since destroying a caret that |
| 773 // is in the "solid" phase of its blinking will leave a solid vertical bar. | 774 // is in the "solid" phase of its blinking will leave a solid vertical bar. |
| 774 // We even hide and destroy the caret if we're going to create it again below. | 775 // We even hide and destroy the caret if we're going to create it again below. |
| 775 // If the caret was already visible on entry to this function, the | 776 // If the caret was already visible on entry to this function, the |
| 776 // CreateCaret() call (which first destroys the old caret) might leave a solid | 777 // CreateCaret() call (which first destroys the old caret) might leave a solid |
| 777 // vertical bar for the same reason as above. Unconditionally hiding prevents | 778 // vertical bar for the same reason as above. Unconditionally hiding prevents |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) && | 1777 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) && |
| 1777 (result == MA_ACTIVATE)) { | 1778 (result == MA_ACTIVATE)) { |
| 1778 if (gaining_focus_) { | 1779 if (gaining_focus_) { |
| 1779 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when | 1780 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when |
| 1780 // we click on the omnibox with the mouse. | 1781 // we click on the omnibox with the mouse. |
| 1781 DCHECK(win8::IsSingleWindowMetroMode()); | 1782 DCHECK(win8::IsSingleWindowMetroMode()); |
| 1782 return result; | 1783 return result; |
| 1783 } | 1784 } |
| 1784 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); | 1785 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); |
| 1785 | 1786 |
| 1786 // Explicitely set focus visibility in the case of clicking on the omnibox, | 1787 // Restore caret visibility whenever the user clicks in the omnibox in a |
| 1787 // which will remove invisible focus if present. | 1788 // way that would give it focus. We must handle this case separately here |
| 1789 // because if the omnibox currently has invisible focus, the mouse event |
| 1790 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). |
| 1788 model()->SetCaretVisibility(true); | 1791 model()->SetCaretVisibility(true); |
| 1789 | 1792 |
| 1790 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not | 1793 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not |
| 1791 // guaranteed to call OnXButtonDown() later! Specifically, if this is the | 1794 // guaranteed to call OnXButtonDown() later! Specifically, if this is the |
| 1792 // second click of a double click, we'll reach here but later call | 1795 // second click of a double click, we'll reach here but later call |
| 1793 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, | 1796 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, |
| 1794 // or we'll have visual glitchiness and then DCHECK failures. | 1797 // or we'll have visual glitchiness and then DCHECK failures. |
| 1795 | 1798 |
| 1796 // Don't restore saved selection, it will just screw up our interaction | 1799 // Don't restore saved selection, it will just screw up our interaction |
| 1797 // with this edit. | 1800 // with this edit. |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2793 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2796 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2794 } | 2797 } |
| 2795 | 2798 |
| 2796 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2799 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2797 // Use font_.GetStringWidth() instead of | 2800 // Use font_.GetStringWidth() instead of |
| 2798 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2801 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2799 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2802 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
| 2800 // PosFromChar(i) might return 0 when i is greater than 1. | 2803 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2801 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2804 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2802 } | 2805 } |
| OLD | NEW |