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

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

Issue 11413217: Instant API: tell page whether the browser is capturing key strokes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@focus
Patch Set: Rebase. 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
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 16 matching lines...) Expand all
27 #include "chrome/app/chrome_command_ids.h" 27 #include "chrome/app/chrome_command_ids.h"
28 #include "chrome/browser/autocomplete/autocomplete_input.h" 28 #include "chrome/browser/autocomplete/autocomplete_input.h"
29 #include "chrome/browser/autocomplete/autocomplete_match.h" 29 #include "chrome/browser/autocomplete/autocomplete_match.h"
30 #include "chrome/browser/autocomplete/keyword_provider.h" 30 #include "chrome/browser/autocomplete/keyword_provider.h"
31 #include "chrome/browser/command_updater.h" 31 #include "chrome/browser/command_updater.h"
32 #include "chrome/browser/net/url_fixer_upper.h" 32 #include "chrome/browser/net/url_fixer_upper.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/ui/browser.h" 34 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" 35 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
36 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 36 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
37 #include "chrome/browser/ui/omnibox/omnibox_types.h"
37 #include "chrome/browser/ui/search/search.h" 38 #include "chrome/browser/ui/search/search.h"
38 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 39 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
39 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 40 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
40 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
41 #include "content/public/browser/user_metrics.h" 42 #include "content/public/browser/user_metrics.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "googleurl/src/url_util.h" 44 #include "googleurl/src/url_util.h"
44 #include "grit/generated_resources.h" 45 #include "grit/generated_resources.h"
45 #include "net/base/escape.h" 46 #include "net/base/escape.h"
46 #include "skia/ext/skia_utils_win.h" 47 #include "skia/ext/skia_utils_win.h"
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // * The user has just pasted in something that replaced all the text 755 // * The user has just pasted in something that replaced all the text
755 // * The user is trying to compose something in an IME 756 // * The user is trying to compose something in an IME
756 CHARRANGE sel; 757 CHARRANGE sel;
757 GetSel(sel); 758 GetSel(sel);
758 model()->StartAutocomplete(sel.cpMax != sel.cpMin, 759 model()->StartAutocomplete(sel.cpMax != sel.cpMin,
759 (sel.cpMax < GetTextLength()) || IsImeComposing()); 760 (sel.cpMax < GetTextLength()) || IsImeComposing());
760 } 761 }
761 762
762 void OmniboxViewWin::SetFocus() { 763 void OmniboxViewWin::SetFocus() {
763 ::SetFocus(m_hWnd); 764 ::SetFocus(m_hWnd);
764 // Restore caret visibility if focused explicitly. We need to do this here 765 // Restore caret visibility if focus is explicitly requested. This is
765 // because if we already have invisible focus, the ::SetFocus call above will 766 // necessary because if we already have invisible focus, the ::SetFocus()
766 // short-circuit, preventing us from reaching OmniboxEditModel::OnSetFocus(), 767 // call above will short-circuit, preventing us from reaching
767 // which handles restoring visibility when we didn't previously have focus. 768 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the
769 // omnibox regains focus after losing focus.
768 model()->SetCaretVisibility(true); 770 model()->SetCaretVisibility(true);
769 } 771 }
770 772
771 void OmniboxViewWin::ApplyCaretVisibility() { 773 void OmniboxViewWin::ApplyCaretVisibility() {
772 // We hide the caret just before destroying it, since destroying a caret that 774 // 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. 775 // 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. 776 // 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 777 // 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 778 // CreateCaret() call (which first destroys the old caret) might leave a solid
777 // vertical bar for the same reason as above. Unconditionally hiding prevents 779 // vertical bar for the same reason as above. Unconditionally hiding prevents
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 // First, give other handlers a chance to handle the message to see if we are 1767 // First, give other handlers a chance to handle the message to see if we are
1766 // actually going to activate and gain focus. 1768 // actually going to activate and gain focus.
1767 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, 1769 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE,
1768 reinterpret_cast<WPARAM>(window), 1770 reinterpret_cast<WPARAM>(window),
1769 MAKELPARAM(hit_test, mouse_message)); 1771 MAKELPARAM(hit_test, mouse_message));
1770 // Check if we're getting focus from a click. We have to do this here rather 1772 // Check if we're getting focus from a click. We have to do this here rather
1771 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be 1773 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be
1772 // reached before OnXButtonDown(), preventing us from detecting this properly 1774 // reached before OnXButtonDown(), preventing us from detecting this properly
1773 // there. Also in those cases, we need to already know in OnSetFocus() that 1775 // there. Also in those cases, we need to already know in OnSetFocus() that
1774 // we should not restore the saved selection. 1776 // we should not restore the saved selection.
1775 if ((!model()->has_focus() || !model()->is_caret_visible()) && 1777 if ((!model()->has_focus() ||
1778 model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE) &&
Peter Kasting 2012/12/11 19:20:50 Nit: Same comment.
samarth 2012/12/12 01:11:26 Done.
1776 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) && 1779 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) &&
1777 (result == MA_ACTIVATE)) { 1780 (result == MA_ACTIVATE)) {
1778 if (gaining_focus_) { 1781 if (gaining_focus_) {
1779 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when 1782 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when
1780 // we click on the omnibox with the mouse. 1783 // we click on the omnibox with the mouse.
1781 DCHECK(win8::IsSingleWindowMetroMode()); 1784 DCHECK(win8::IsSingleWindowMetroMode());
1782 return result; 1785 return result;
1783 } 1786 }
1784 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); 1787 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel()));
1785 1788
1786 // Explicitely set focus visibility in the case of clicking on the omnibox, 1789 // Restore caret visibility whenever the user clicks in the omnibox in a
1787 // which will remove invisible focus if present. 1790 // way that would give it focus. We must handle this case separately here
1791 // because if the omnibox currently has invisible focus, the mouse event
1792 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus().
1788 model()->SetCaretVisibility(true); 1793 model()->SetCaretVisibility(true);
1789 1794
1790 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not 1795 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not
1791 // guaranteed to call OnXButtonDown() later! Specifically, if this is the 1796 // guaranteed to call OnXButtonDown() later! Specifically, if this is the
1792 // second click of a double click, we'll reach here but later call 1797 // second click of a double click, we'll reach here but later call
1793 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, 1798 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places,
1794 // or we'll have visual glitchiness and then DCHECK failures. 1799 // or we'll have visual glitchiness and then DCHECK failures.
1795 1800
1796 // Don't restore saved selection, it will just screw up our interaction 1801 // Don't restore saved selection, it will just screw up our interaction
1797 // with this edit. 1802 // with this edit.
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2807 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2803 } 2808 }
2804 2809
2805 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { 2810 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const {
2806 // Use font_.GetStringWidth() instead of 2811 // Use font_.GetStringWidth() instead of
2807 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2812 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2808 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2813 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
2809 // PosFromChar(i) might return 0 when i is greater than 1. 2814 // PosFromChar(i) might return 0 when i is greater than 1.
2810 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2815 return font_.GetStringWidth(text) + GetHorizontalMargin();
2811 } 2816 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698