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

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: copied comment from other patch 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // * The caret/selection isn't at the end of the text 752 // * The caret/selection isn't at the end of the text
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 // Restore caret visibility if focused explicitly. We need to do this here
763 // because if we already have invisible focus, the ::SetFocus() call below
764 // will short-circuit, preventing us from reaching
Peter Kasting 2012/12/05 02:28:50 You did verify this short-circuiting occurs on Win
Mathieu 2012/12/05 03:57:21 Modified the comment to better reflect that in cer
765 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we
766 // didn't previously have focus.
762 ::SetFocus(m_hWnd); 767 ::SetFocus(m_hWnd);
768 model()->SetCaretVisibility(true);
Peter Kasting 2012/12/05 02:28:50 Nit: This should be next to the comment.
Mathieu 2012/12/05 03:57:21 Done.
763 } 769 }
764 770
765 void OmniboxViewWin::ApplyFocusVisibility() { 771 void OmniboxViewWin::ApplyCaretVisibility() {
766 // TODO(mathp): implement for Windows. 772 // We hide the caret just before destroying it, since destroying a caret that
767 NOTIMPLEMENTED(); 773 // 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 // 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 // vertical bar for the same reason as above. Unconditionally hiding prevents
778 // this. The caret could be visible on entry to this function if the
779 // underlying edit control had re-created it automatically (see comments in
780 // OnPaint()).
781 HideCaret();
782 // We use DestroyCaret()/CreateCaret() instead of simply HideCaret()/
783 // ShowCaret() because HideCaret() is not sticky across paint events, e.g. a
784 // window resize will effectively restore caret visibility, regardless of
785 // whether HideCaret() was called before. While we do catch and handle these
786 // paint events (see OnPaint()), it doesn't seem to be enough to simply call
787 // HideCaret() while handling them because of the unpredictability of this
788 // Windows API. According to the documentation, it should be a cumulative call
789 // e.g. 5 hide calls should be balanced by 5 show calls. We have not found
790 // this to be true, which may be explained by the fact that this API is called
791 // internally in Windows, as well.
792 ::DestroyCaret();
793 if (model()->is_focus_visible()) {
794 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, font_.GetHeight());
795 // According to the Windows API documentation, a newly created caret needs
796 // ShowCaret to be visible.
797 ShowCaret();
798 }
768 } 799 }
769 800
770 void OmniboxViewWin::SetDropHighlightPosition(int position) { 801 void OmniboxViewWin::SetDropHighlightPosition(int position) {
771 if (drop_highlight_position_ != position) { 802 if (drop_highlight_position_ != position) {
772 RepaintDropHighlight(drop_highlight_position_); 803 RepaintDropHighlight(drop_highlight_position_);
773 drop_highlight_position_ = position; 804 drop_highlight_position_ = position;
774 RepaintDropHighlight(drop_highlight_position_); 805 RepaintDropHighlight(drop_highlight_position_);
775 } 806 }
776 } 807 }
777 808
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 // Modifying the selection counts as accepting any inline autocompletion, so 1712 // Modifying the selection counts as accepting any inline autocompletion, so
1682 // track "changes" made by clicking the mouse button. 1713 // track "changes" made by clicking the mouse button.
1683 ScopedFreeze freeze(this, GetTextObjectModel()); 1714 ScopedFreeze freeze(this, GetTextObjectModel());
1684 OnBeforePossibleChange(); 1715 OnBeforePossibleChange();
1685 DefWindowProc(WM_LBUTTONDOWN, keys, 1716 DefWindowProc(WM_LBUTTONDOWN, keys,
1686 MAKELPARAM(ClipXCoordToVisibleText(point.x, is_triple_click), 1717 MAKELPARAM(ClipXCoordToVisibleText(point.x, is_triple_click),
1687 point.y)); 1718 point.y));
1688 OnAfterPossibleChange(); 1719 OnAfterPossibleChange();
1689 1720
1690 gaining_focus_.reset(); 1721 gaining_focus_.reset();
1722
1723 // Restore caret visibility whenever the user clicks in the the omnibox. This
1724 // is not always covered by OnSetFocus() because when clicking while the
1725 // omnibox has invisible focus does not trigger a new OnSetFocus() call.
1726 model()->SetCaretVisibility(true);
Peter Kasting 2012/12/05 02:28:50 A couple things. (1) Left clicks aren't enough, y
Mathieu 2012/12/05 03:57:21 Your proposal was almost correct; I need to check
1691 } 1727 }
1692 1728
1693 void OmniboxViewWin::OnLButtonUp(UINT keys, const CPoint& point) { 1729 void OmniboxViewWin::OnLButtonUp(UINT keys, const CPoint& point) {
1694 // default processing should happen first so we can see the result of the 1730 // default processing should happen first so we can see the result of the
1695 // selection 1731 // selection
1696 ScopedFreeze freeze(this, GetTextObjectModel()); 1732 ScopedFreeze freeze(this, GetTextObjectModel());
1697 DefWindowProc(WM_LBUTTONUP, keys, 1733 DefWindowProc(WM_LBUTTONUP, keys,
1698 MAKELPARAM(ClipXCoordToVisibleText(point.x, false), point.y)); 1734 MAKELPARAM(ClipXCoordToVisibleText(point.x, false), point.y));
1699 1735
1700 SelectAllIfNecessary(kLeft, point); 1736 SelectAllIfNecessary(kLeft, point);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 1928
1893 // Draw the drop highlight. 1929 // Draw the drop highlight.
1894 if (drop_highlight_position_ != -1) 1930 if (drop_highlight_position_ != -1)
1895 DrawDropHighlight(memory_dc, rect, paint_clip_rect); 1931 DrawDropHighlight(memory_dc, rect, paint_clip_rect);
1896 1932
1897 // Blit the memory DC to the actual paint DC and clean up. 1933 // 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, 1934 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc,
1899 rect.left, rect.top, SRCCOPY); 1935 rect.left, rect.top, SRCCOPY);
1900 memory_dc.SelectBitmap(old_bitmap); 1936 memory_dc.SelectBitmap(old_bitmap);
1901 edit_hwnd = old_edit_hwnd; 1937 edit_hwnd = old_edit_hwnd;
1938
1939 // This needs to be called regardless of the current state of the caret, even
1940 // if reaffirming a current state (hidden or shown). This is because the
1941 // underlying edit control will automatically re-create the caret when it
1942 // receives a paint event, e.g. a window resize event.
Peter Kasting 2012/12/05 02:28:50 A resize event and a paint event aren't the same t
Mathieu 2012/12/05 03:57:21 Done.
1943 ApplyCaretVisibility();
1902 } 1944 }
1903 1945
1904 void OmniboxViewWin::OnPaste() { 1946 void OmniboxViewWin::OnPaste() {
1905 // Replace the selection if we have something to paste. 1947 // Replace the selection if we have something to paste.
1906 const string16 text(GetClipboardText()); 1948 const string16 text(GetClipboardText());
1907 if (!text.empty()) { 1949 if (!text.empty()) {
1908 // Record this paste, so we can do different behavior. 1950 // Record this paste, so we can do different behavior.
1909 model()->on_paste(); 1951 model()->on_paste();
1910 // Force a Paste operation to trigger the text_changed code in 1952 // Force a Paste operation to trigger the text_changed code in
1911 // OnAfterPossibleChange(), even if identical contents are pasted into the 1953 // 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); 2793 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2752 } 2794 }
2753 2795
2754 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { 2796 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const {
2755 // Use font_.GetStringWidth() instead of 2797 // Use font_.GetStringWidth() instead of
2756 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2798 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2757 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2799 // 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. 2800 // PosFromChar(i) might return 0 when i is greater than 1.
2759 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2801 return font_.GetStringWidth(text) + GetHorizontalMargin();
2760 } 2802 }
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