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

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

Issue 11098077: Grab mouse capture in the WM_POINTERDOWN message handler in the omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.h ('k') | 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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 // the smaller value. 1364 // the smaller value.
1365 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); 1365 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url);
1366 DoCopy(text, write_url ? &url : NULL); 1366 DoCopy(text, write_url ? &url : NULL);
1367 } 1367 }
1368 1368
1369 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) { 1369 LRESULT OmniboxViewWin::OnCreate(const CREATESTRUCTW* /*create_struct*/) {
1370 if (base::win::IsTsfAwareRequired()) { 1370 if (base::win::IsTsfAwareRequired()) {
1371 // Enable TSF support of RichEdit. 1371 // Enable TSF support of RichEdit.
1372 SetEditStyle(SES_USECTF, SES_USECTF); 1372 SetEditStyle(SES_USECTF, SES_USECTF);
1373 } 1373 }
1374
Peter Kasting 2012/10/12 21:36:57 Nit: Either delete this or add a similar blank lin
ananta 2012/10/12 21:44:00 Done.
1375 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
1376 BOOL touch_mode = RegisterTouchWindow(m_hWnd, TWF_WANTPALM);
1377 DCHECK(touch_mode);
1378 }
1374 SetMsgHandled(FALSE); 1379 SetMsgHandled(FALSE);
1375 return 0; 1380 return 0;
1376 } 1381 }
1377 1382
1378 void OmniboxViewWin::OnCut() { 1383 void OmniboxViewWin::OnCut() {
1379 OnCopy(); 1384 OnCopy();
1380 1385
1381 // This replace selection will have no effect (even on the undo stack) if the 1386 // This replace selection will have no effect (even on the undo stack) if the
1382 // current selection is empty. 1387 // current selection is empty.
1383 ReplaceSel(L"", true); 1388 ReplaceSel(L"", true);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 if (model()->user_input_in_progress()) 1444 if (model()->user_input_in_progress())
1440 UpdatePopup(); 1445 UpdatePopup();
1441 1446
1442 break; 1447 break;
1443 default: 1448 default:
1444 break; 1449 break;
1445 } 1450 }
1446 return DefWindowProc(message, wparam, lparam); 1451 return DefWindowProc(message, wparam, lparam);
1447 } 1452 }
1448 1453
1449 LRESULT OmniboxViewWin::OnPointerDown(UINT message, 1454 LRESULT OmniboxViewWin::OnTouchEvent(UINT message,
1450 WPARAM wparam, 1455 WPARAM wparam,
1451 LPARAM lparam) { 1456 LPARAM lparam) {
1452 if (!model()->has_focus()) 1457 // There is a bug in Windows 8 where in the generated mouse messages
1453 SetFocus(); 1458 // after touch go to the window which previously had focus. This means that
1454 1459 // if a user taps the omnibox to give it focus, we don't get the simulated
1455 if (IS_POINTER_FIRSTBUTTON_WPARAM(wparam)) { 1460 // WM_LBUTTONDOWN, and thus don't properly select all the text. To ensure
1456 TrackMousePosition(kLeft, CPoint(GET_X_LPARAM(lparam), 1461 // that we get this message, we capture the mouse when the user is doing a
1457 GET_Y_LPARAM(lparam))); 1462 // single-point tap on an unfocused model.
1463 if ((wparam == 1) && !model()->has_focus()) {
1464 TOUCHINPUT point = {0};
1465 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(lparam), 1,
1466 &point, sizeof(TOUCHINPUT))) {
1467 if (point.dwFlags & TOUCHEVENTF_DOWN)
1468 SetCapture();
1469 else if (point.dwFlags & TOUCHEVENTF_UP)
1470 ReleaseCapture();
1471 }
1458 } 1472 }
1459
1460 SetMsgHandled(false); 1473 SetMsgHandled(false);
1461
1462 return 0;
1463 }
1464
1465 LRESULT OmniboxViewWin::OnPointerUp(UINT message, WPARAM wparam,
1466 LPARAM lparam) {
1467 SetMsgHandled(false);
1468
1469 return 0; 1474 return 0;
1470 } 1475 }
1471 1476
1472 void OmniboxViewWin::OnKeyDown(TCHAR key, 1477 void OmniboxViewWin::OnKeyDown(TCHAR key,
1473 UINT repeat_count, 1478 UINT repeat_count,
1474 UINT flags) { 1479 UINT flags) {
1475 delete_at_end_pressed_ = false; 1480 delete_at_end_pressed_ = false;
1476 1481
1477 if (OnKeyDownAllModes(key, repeat_count, flags)) 1482 if (OnKeyDownAllModes(key, repeat_count, flags))
1478 return; 1483 return;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 // actually going to activate and gain focus. 1678 // actually going to activate and gain focus.
1674 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, 1679 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE,
1675 reinterpret_cast<WPARAM>(window), 1680 reinterpret_cast<WPARAM>(window),
1676 MAKELPARAM(hit_test, mouse_message)); 1681 MAKELPARAM(hit_test, mouse_message));
1677 // Check if we're getting focus from a click. We have to do this here rather 1682 // Check if we're getting focus from a click. We have to do this here rather
1678 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be 1683 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be
1679 // reached before OnXButtonDown(), preventing us from detecting this properly 1684 // reached before OnXButtonDown(), preventing us from detecting this properly
1680 // there. Also in those cases, we need to already know in OnSetFocus() that 1685 // there. Also in those cases, we need to already know in OnSetFocus() that
1681 // we should not restore the saved selection. 1686 // we should not restore the saved selection.
1682 if (!model()->has_focus() && 1687 if (!model()->has_focus() &&
1683 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN || 1688 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) &&
1684 mouse_message == WM_POINTERDOWN)) &&
1685 (result == MA_ACTIVATE)) { 1689 (result == MA_ACTIVATE)) {
1686 DCHECK(!gaining_focus_.get()); 1690 if (gaining_focus_) {
1691 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when
1692 // we click on the omnibox with the mouse.
1693 DCHECK(base::win::IsMetroProcess());
1694 return result;
1695 }
1696 if (!base::win::IsMetroProcess())
Peter Kasting 2012/10/12 21:36:57 This conditional should go away entirely, the DCHE
ananta 2012/10/12 21:44:00 Yes. It was taken out in the patch I uploaded afte
1697 DCHECK(!gaining_focus_.get());
1687 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); 1698 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel()));
1688 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not 1699 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not
1689 // guaranteed to call OnXButtonDown() later! Specifically, if this is the 1700 // guaranteed to call OnXButtonDown() later! Specifically, if this is the
1690 // second click of a double click, we'll reach here but later call 1701 // second click of a double click, we'll reach here but later call
1691 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, 1702 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places,
1692 // or we'll have visual glitchiness and then DCHECK failures. 1703 // or we'll have visual glitchiness and then DCHECK failures.
1693 1704
1694 // Don't restore saved selection, it will just screw up our interaction 1705 // Don't restore saved selection, it will just screw up our interaction
1695 // with this edit. 1706 // with this edit.
1696 saved_selection_for_focus_change_.cpMin = -1; 1707 saved_selection_for_focus_change_.cpMin = -1;
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2690 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2680 } 2691 }
2681 2692
2682 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { 2693 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const {
2683 // Use font_.GetStringWidth() instead of 2694 // Use font_.GetStringWidth() instead of
2684 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2695 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2685 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2696 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
2686 // PosFromChar(i) might return 0 when i is greater than 1. 2697 // PosFromChar(i) might return 0 when i is greater than 1.
2687 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2698 return font_.GetStringWidth(text) + GetHorizontalMargin();
2688 } 2699 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698