Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 11418144: [Search] Implementation of the invisible focus on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@samarthlatest
Patch Set: Caret height + comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
763 } 764 }
764 765
765 void OmniboxViewWin::ApplyFocusVisibility() { 766 void OmniboxViewWin::ApplyCaretVisibility() {
766 // TODO(mathp): implement for Windows. 767 // We hide the caret just before destroying it, since destroying a caret that
767 NOTIMPLEMENTED(); 768 // is in the "solid" phase of its blinking will leave a solid vertical bar.
769 // We also hide and destroy the caret before re-creating it, to avoid a solid
770 // vertical bar.
Peter Kasting 2012/12/04 22:45:35 Nit: This second sentence might be clearer as: "W
Mathieu 2012/12/05 01:51:20 Done. It's precisely right and well worded.
771 HideCaret();
772 // We use DestroyCaret()/CreateCaret() instead of simply HideCaret()/
773 // ShowCaret() because HideCaret() is not sticky across paint events, e.g. a
774 // window resize will effectively restore caret visibility, regardless of
775 // whether HideCaret() was called before. While we do catch and handle these
776 // paint events (see OnPaint()), it doesn't seem to be enough to simply call
777 // HideCaret() while handling them because of the unpredictability of this
778 // Windows API. According to the documentation, it should be a cumulative call
779 // e.g. 5 hide calls should be balanced by 5 show calls. We have not found
780 // this to be true, which may be explained by the fact that this API is called
781 // internally in Windows, as well.
782 ::DestroyCaret();
783 if (model()->is_focus_visible()) {
784 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, font_.GetHeight());
785 // According to the Windows API documentation, a newly created caret needs
786 // ShowCaret to be visible.
787 ShowCaret();
788 }
768 } 789 }
769 790
770 void OmniboxViewWin::SetDropHighlightPosition(int position) { 791 void OmniboxViewWin::SetDropHighlightPosition(int position) {
771 if (drop_highlight_position_ != position) { 792 if (drop_highlight_position_ != position) {
772 RepaintDropHighlight(drop_highlight_position_); 793 RepaintDropHighlight(drop_highlight_position_);
773 drop_highlight_position_ = position; 794 drop_highlight_position_ = position;
774 RepaintDropHighlight(drop_highlight_position_); 795 RepaintDropHighlight(drop_highlight_position_);
775 } 796 }
776 } 797 }
777 798
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 TextChanged(); 863 TextChanged();
843 return true; 864 return true;
844 } 865 }
845 866
846 void OmniboxViewWin::OnRevertTemporaryText() { 867 void OmniboxViewWin::OnRevertTemporaryText() {
847 SetSelectionRange(original_selection_); 868 SetSelectionRange(original_selection_);
848 TextChanged(); 869 TextChanged();
849 } 870 }
850 871
851 void OmniboxViewWin::OnBeforePossibleChange() { 872 void OmniboxViewWin::OnBeforePossibleChange() {
873 // We set the focus to visible here to cover two cases. This is called when
874 // the user directly clicks on the omnibox as well as when a character is
875 // about to be entered.
876 model()->SetFocusVisibility(true);
852 // Record our state. 877 // Record our state.
853 text_before_change_ = GetText(); 878 text_before_change_ = GetText();
854 GetSelection(sel_before_change_); 879 GetSelection(sel_before_change_);
855 } 880 }
856 881
857 bool OmniboxViewWin::OnAfterPossibleChange() { 882 bool OmniboxViewWin::OnAfterPossibleChange() {
858 return OnAfterPossibleChangeInternal(false); 883 return OnAfterPossibleChangeInternal(false);
859 } 884 }
860 885
861 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) { 886 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) {
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 1917
1893 // Draw the drop highlight. 1918 // Draw the drop highlight.
1894 if (drop_highlight_position_ != -1) 1919 if (drop_highlight_position_ != -1)
1895 DrawDropHighlight(memory_dc, rect, paint_clip_rect); 1920 DrawDropHighlight(memory_dc, rect, paint_clip_rect);
1896 1921
1897 // Blit the memory DC to the actual paint DC and clean up. 1922 // 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, 1923 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc,
1899 rect.left, rect.top, SRCCOPY); 1924 rect.left, rect.top, SRCCOPY);
1900 memory_dc.SelectBitmap(old_bitmap); 1925 memory_dc.SelectBitmap(old_bitmap);
1901 edit_hwnd = old_edit_hwnd; 1926 edit_hwnd = old_edit_hwnd;
1927
1928 // This needs to be called regardless of the current state of the caret, even
1929 // if reaffirming a current state (hidden or shown). Otherwise, the caret may
1930 // show when it is supposed to be hidden (i.e. it is re-created by the OS).
Peter Kasting 2012/12/04 22:45:35 Nit: If you could be clearer in this second senten
Mathieu 2012/12/05 01:51:20 Done. I modified a little bit to say "paint events
1931 ApplyCaretVisibility();
1902 } 1932 }
1903 1933
1904 void OmniboxViewWin::OnPaste() { 1934 void OmniboxViewWin::OnPaste() {
1905 // Replace the selection if we have something to paste. 1935 // Replace the selection if we have something to paste.
1906 const string16 text(GetClipboardText()); 1936 const string16 text(GetClipboardText());
1907 if (!text.empty()) { 1937 if (!text.empty()) {
1908 // Record this paste, so we can do different behavior. 1938 // Record this paste, so we can do different behavior.
1909 model()->on_paste(); 1939 model()->on_paste();
1910 // Force a Paste operation to trigger the text_changed code in 1940 // Force a Paste operation to trigger the text_changed code in
1911 // OnAfterPossibleChange(), even if identical contents are pasted into the 1941 // OnAfterPossibleChange(), even if identical contents are pasted into the
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2781 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2752 } 2782 }
2753 2783
2754 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { 2784 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const {
2755 // Use font_.GetStringWidth() instead of 2785 // Use font_.GetStringWidth() instead of
2756 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2786 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2757 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2787 // 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. 2788 // PosFromChar(i) might return 0 when i is greater than 1.
2759 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2789 return font_.GetStringWidth(text) + GetHorizontalMargin();
2760 } 2790 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698