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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 // * The user has just pasted in something that replaced all the text | 753 // * The user has just pasted in something that replaced all the text |
754 // * The user is trying to compose something in an IME | 754 // * The user is trying to compose something in an IME |
755 CHARRANGE sel; | 755 CHARRANGE sel; |
756 GetSel(sel); | 756 GetSel(sel); |
757 model()->StartAutocomplete(sel.cpMax != sel.cpMin, | 757 model()->StartAutocomplete(sel.cpMax != sel.cpMin, |
758 (sel.cpMax < GetTextLength()) || IsImeComposing()); | 758 (sel.cpMax < GetTextLength()) || IsImeComposing()); |
759 } | 759 } |
760 | 760 |
761 void OmniboxViewWin::SetFocus() { | 761 void OmniboxViewWin::SetFocus() { |
762 ::SetFocus(m_hWnd); | 762 ::SetFocus(m_hWnd); |
763 model()->SetFocusVisibility(true); | |
Peter Kasting
2012/12/04 02:18:30
See question in the other CL about this particular
Mathieu
2012/12/04 17:00:14
Acknowledged. Will wait for the outcome of that co
| |
763 } | 764 } |
764 | 765 |
765 void OmniboxViewWin::ApplyFocusVisibility() { | 766 void OmniboxViewWin::ApplyFocusVisibility() { |
766 // TODO(mathp): implement for Windows. | 767 if (!chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile())) |
Peter Kasting
2012/12/04 02:18:30
I don't think it's appropriate to check this here.
Mathieu
2012/12/04 17:00:14
I was trying to minimize the manipulation of the C
Peter Kasting
2012/12/04 21:24:43
If they don't have instant extended enabled, this
Mathieu
2012/12/04 22:30:51
Well there is an ApplyCaretVisibility() call in On
| |
767 NOTIMPLEMENTED(); | 768 return; |
769 // We hide the caret just before destroying it, since destroying a caret that | |
Peter Kasting
2012/12/04 02:18:30
I still don't see why the hide/destroy part is don
Mathieu
2012/12/04 17:00:14
Moved the DestroyCaret() call in an else, but that
Peter Kasting
2012/12/04 21:24:43
Then don't put any of it in an else, and add comme
Mathieu
2012/12/04 22:30:51
Done.
| |
770 // is in the "solid" phase of its blinking will leave a solid vertical bar. | |
771 HideCaret(); | |
772 // We use DestroyCaret/CreateCaret instead of simply HideCaret/ShowCaret | |
773 // because HideCaret is not sticky across paint events, e.g. a window resize | |
774 // will effectively restore caret visibility, regardless of whether HideCaret | |
775 // was called before. | |
Peter Kasting
2012/12/04 02:18:30
Nit: And add "While we do catch and handle these p
Mathieu
2012/12/04 17:00:14
Done.
| |
776 ::DestroyCaret(); | |
777 if (model()->is_focus_visible()) { | |
778 // Get caret height from omnibox height. | |
779 CRect rect; | |
780 GetClientRect(&rect); | |
781 int caret_height = rect.Height() - 3; | |
Peter Kasting
2012/12/04 02:18:30
I suspect this calculation is wrong to hardcode "c
Mathieu
2012/12/04 17:00:14
The 3 points seem odd to me too, I agree. I looked
Peter Kasting
2012/12/04 21:24:43
You don't want to refer to that rect. It's not gu
Mathieu
2012/12/04 22:30:51
Wow, it was indeed font_.GetHeight()!
I tested wi
| |
782 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, caret_height); | |
783 // According to the Windows API documentation, a newly created caret needs | |
784 // ShowCaret to be visible. | |
785 ShowCaret(); | |
786 } | |
768 } | 787 } |
769 | 788 |
770 void OmniboxViewWin::SetDropHighlightPosition(int position) { | 789 void OmniboxViewWin::SetDropHighlightPosition(int position) { |
771 if (drop_highlight_position_ != position) { | 790 if (drop_highlight_position_ != position) { |
772 RepaintDropHighlight(drop_highlight_position_); | 791 RepaintDropHighlight(drop_highlight_position_); |
773 drop_highlight_position_ = position; | 792 drop_highlight_position_ = position; |
774 RepaintDropHighlight(drop_highlight_position_); | 793 RepaintDropHighlight(drop_highlight_position_); |
775 } | 794 } |
776 } | 795 } |
777 | 796 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
842 TextChanged(); | 861 TextChanged(); |
843 return true; | 862 return true; |
844 } | 863 } |
845 | 864 |
846 void OmniboxViewWin::OnRevertTemporaryText() { | 865 void OmniboxViewWin::OnRevertTemporaryText() { |
847 SetSelectionRange(original_selection_); | 866 SetSelectionRange(original_selection_); |
848 TextChanged(); | 867 TextChanged(); |
849 } | 868 } |
850 | 869 |
851 void OmniboxViewWin::OnBeforePossibleChange() { | 870 void OmniboxViewWin::OnBeforePossibleChange() { |
871 model()->SetFocusVisibility(true); | |
Peter Kasting
2012/12/04 02:18:30
Nit: Add comments about this.
Mathieu
2012/12/04 17:00:14
Done.
| |
852 // Record our state. | 872 // Record our state. |
853 text_before_change_ = GetText(); | 873 text_before_change_ = GetText(); |
854 GetSelection(sel_before_change_); | 874 GetSelection(sel_before_change_); |
855 } | 875 } |
856 | 876 |
857 bool OmniboxViewWin::OnAfterPossibleChange() { | 877 bool OmniboxViewWin::OnAfterPossibleChange() { |
858 return OnAfterPossibleChangeInternal(false); | 878 return OnAfterPossibleChangeInternal(false); |
859 } | 879 } |
860 | 880 |
861 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) { | 881 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) { |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1892 | 1912 |
1893 // Draw the drop highlight. | 1913 // Draw the drop highlight. |
1894 if (drop_highlight_position_ != -1) | 1914 if (drop_highlight_position_ != -1) |
1895 DrawDropHighlight(memory_dc, rect, paint_clip_rect); | 1915 DrawDropHighlight(memory_dc, rect, paint_clip_rect); |
1896 | 1916 |
1897 // Blit the memory DC to the actual paint DC and clean up. | 1917 // Blit the memory DC to the actual paint DC and clean up. |
1898 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc, | 1918 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc, |
1899 rect.left, rect.top, SRCCOPY); | 1919 rect.left, rect.top, SRCCOPY); |
1900 memory_dc.SelectBitmap(old_bitmap); | 1920 memory_dc.SelectBitmap(old_bitmap); |
1901 edit_hwnd = old_edit_hwnd; | 1921 edit_hwnd = old_edit_hwnd; |
1922 | |
1923 ApplyFocusVisibility(); | |
Peter Kasting
2012/12/04 02:18:30
Do you actually need to do this on every paint cal
Mathieu
2012/12/04 17:00:14
I've tested this, and it is not so. This call need
Peter Kasting
2012/12/04 21:24:43
Then you need to add commentary about this too.
T
Mathieu
2012/12/04 22:30:51
Got it. Makes sense, thanks.
| |
1902 } | 1924 } |
1903 | 1925 |
1904 void OmniboxViewWin::OnPaste() { | 1926 void OmniboxViewWin::OnPaste() { |
1905 // Replace the selection if we have something to paste. | 1927 // Replace the selection if we have something to paste. |
1906 const string16 text(GetClipboardText()); | 1928 const string16 text(GetClipboardText()); |
1907 if (!text.empty()) { | 1929 if (!text.empty()) { |
1908 // Record this paste, so we can do different behavior. | 1930 // Record this paste, so we can do different behavior. |
1909 model()->on_paste(); | 1931 model()->on_paste(); |
1910 // Force a Paste operation to trigger the text_changed code in | 1932 // Force a Paste operation to trigger the text_changed code in |
1911 // OnAfterPossibleChange(), even if identical contents are pasted into the | 1933 // OnAfterPossibleChange(), even if identical contents are pasted into the |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2751 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2773 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2752 } | 2774 } |
2753 | 2775 |
2754 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2776 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2755 // Use font_.GetStringWidth() instead of | 2777 // Use font_.GetStringWidth() instead of |
2756 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2778 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2757 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2779 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2758 // PosFromChar(i) might return 0 when i is greater than 1. | 2780 // PosFromChar(i) might return 0 when i is greater than 1. |
2759 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2781 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2760 } | 2782 } |
OLD | NEW |