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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
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); |
1384 } | 1389 } |
1385 | 1390 |
1386 LRESULT OmniboxViewWin::OnGetObject(UINT message, | 1391 LRESULT OmniboxViewWin::OnGetObject(UINT message, |
1387 WPARAM wparam, | 1392 WPARAM wparam, |
1388 LPARAM lparam) { | 1393 LPARAM lparam) { |
1389 // This is a request for the native accessibility object. | 1394 // This is a request for the native accessibility object. |
1390 if (lparam == OBJID_CLIENT) { | 1395 if (lparam == OBJID_CLIENT) { |
1391 return LresultFromObject(IID_IAccessible, wparam, | 1396 return LresultFromObject(IID_IAccessible, wparam, |
1392 native_view_host_->GetNativeViewAccessible()); | 1397 native_view_host_->GetNativeViewAccessible()); |
1393 } | 1398 } |
1394 return 0; | 1399 return 0; |
1395 } | 1400 } |
1396 | 1401 |
1402 void OmniboxViewWin::OnDestroy() { | |
1403 if (base::win::GetVersion() >= base::win::VERSION_WIN8) | |
1404 UnregisterTouchWindow(m_hWnd); | |
Peter Kasting
2012/10/12 21:16:31
Do we actually need to do this? It seems from the
ananta
2012/10/12 21:34:53
Removed this and the OnDestroy handler.
| |
1405 } | |
1406 | |
1397 LRESULT OmniboxViewWin::OnImeComposition(UINT message, | 1407 LRESULT OmniboxViewWin::OnImeComposition(UINT message, |
1398 WPARAM wparam, | 1408 WPARAM wparam, |
1399 LPARAM lparam) { | 1409 LPARAM lparam) { |
1400 if (ignore_ime_messages_) { | 1410 if (ignore_ime_messages_) { |
1401 // This message was sent while we're in the middle of meddling with the | 1411 // This message was sent while we're in the middle of meddling with the |
1402 // underlying edit control. If we handle it below, OnAfterPossibleChange() | 1412 // underlying edit control. If we handle it below, OnAfterPossibleChange() |
1403 // can get bogus text for the edit, and rerun autocomplete, destructively | 1413 // can get bogus text for the edit, and rerun autocomplete, destructively |
1404 // modifying the result set that we're in the midst of using. For example, | 1414 // modifying the result set that we're in the midst of using. For example, |
1405 // if SetWindowTextAndCaretPos() was called due to the user clicking an | 1415 // if SetWindowTextAndCaretPos() was called due to the user clicking an |
1406 // entry in the popup, we're in the middle of executing SetSelectedLine(), | 1416 // entry in the popup, we're in the middle of executing SetSelectedLine(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1439 if (model()->user_input_in_progress()) | 1449 if (model()->user_input_in_progress()) |
1440 UpdatePopup(); | 1450 UpdatePopup(); |
1441 | 1451 |
1442 break; | 1452 break; |
1443 default: | 1453 default: |
1444 break; | 1454 break; |
1445 } | 1455 } |
1446 return DefWindowProc(message, wparam, lparam); | 1456 return DefWindowProc(message, wparam, lparam); |
1447 } | 1457 } |
1448 | 1458 |
1449 LRESULT OmniboxViewWin::OnPointerDown(UINT message, | 1459 LRESULT OmniboxViewWin::OnTouchEvent(UINT message, |
1450 WPARAM wparam, | 1460 WPARAM wparam, |
1451 LPARAM lparam) { | 1461 LPARAM lparam) { |
1452 if (!model()->has_focus()) | 1462 // There is a bug in Windows 8 where in the generated mouse messages |
1453 SetFocus(); | 1463 // after touch go to the window which previously had focus. This means that |
1454 | 1464 // if a user taps the omnibox to give it focus, we don't get the simulated |
1455 if (IS_POINTER_FIRSTBUTTON_WPARAM(wparam)) { | 1465 // WM_LBUTTONDOWN, and thus don't properly select all the text. To ensure |
1456 TrackMousePosition(kLeft, CPoint(GET_X_LPARAM(lparam), | 1466 // that we get this message, we capture the mouse when the user is doing a |
1457 GET_Y_LPARAM(lparam))); | 1467 // single-point tap on an unfocused model. |
1468 if ((wparam == 1) && !model()->has_focus()) { | |
1469 TOUCHINPUT point = {0}; | |
1470 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(lparam), 1, | |
1471 &point, sizeof(TOUCHINPUT))) { | |
1472 if (point.dwFlags & TOUCHEVENTF_DOWN) { | |
1473 SetFocus(); | |
Peter Kasting
2012/10/12 21:16:31
Is this SetFocus() necessary? I thought you said
ananta
2012/10/12 21:34:53
Good point. Artifact of the previous iteration. Wi
| |
1474 SetCapture(); | |
1475 } else if (point.dwFlags & TOUCHEVENTF_UP) { | |
1476 ReleaseCapture(); | |
1477 } | |
1478 } | |
1458 } | 1479 } |
1459 | |
1460 SetMsgHandled(false); | 1480 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; | 1481 return 0; |
1470 } | 1482 } |
1471 | 1483 |
1472 void OmniboxViewWin::OnKeyDown(TCHAR key, | 1484 void OmniboxViewWin::OnKeyDown(TCHAR key, |
1473 UINT repeat_count, | 1485 UINT repeat_count, |
1474 UINT flags) { | 1486 UINT flags) { |
1475 delete_at_end_pressed_ = false; | 1487 delete_at_end_pressed_ = false; |
1476 | 1488 |
1477 if (OnKeyDownAllModes(key, repeat_count, flags)) | 1489 if (OnKeyDownAllModes(key, repeat_count, flags)) |
1478 return; | 1490 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1673 // actually going to activate and gain focus. | 1685 // actually going to activate and gain focus. |
1674 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, | 1686 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, |
1675 reinterpret_cast<WPARAM>(window), | 1687 reinterpret_cast<WPARAM>(window), |
1676 MAKELPARAM(hit_test, mouse_message)); | 1688 MAKELPARAM(hit_test, mouse_message)); |
1677 // Check if we're getting focus from a click. We have to do this here rather | 1689 // 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 | 1690 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be |
1679 // reached before OnXButtonDown(), preventing us from detecting this properly | 1691 // reached before OnXButtonDown(), preventing us from detecting this properly |
1680 // there. Also in those cases, we need to already know in OnSetFocus() that | 1692 // there. Also in those cases, we need to already know in OnSetFocus() that |
1681 // we should not restore the saved selection. | 1693 // we should not restore the saved selection. |
1682 if (!model()->has_focus() && | 1694 if (!model()->has_focus() && |
1683 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN || | 1695 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) && |
1684 mouse_message == WM_POINTERDOWN)) && | |
1685 (result == MA_ACTIVATE)) { | 1696 (result == MA_ACTIVATE)) { |
1686 DCHECK(!gaining_focus_.get()); | 1697 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when |
1698 // we click on the omnibox with the mouse. | |
1699 if (!base::win::IsMetroProcess()) | |
Peter Kasting
2012/10/12 21:16:31
Seems like it'd be better to do:
if (gaining_fo
ananta
2012/10/12 21:34:53
Done.
| |
1700 DCHECK(!gaining_focus_.get()); | |
1687 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); | 1701 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); |
1688 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not | 1702 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not |
1689 // guaranteed to call OnXButtonDown() later! Specifically, if this is the | 1703 // guaranteed to call OnXButtonDown() later! Specifically, if this is the |
1690 // second click of a double click, we'll reach here but later call | 1704 // second click of a double click, we'll reach here but later call |
1691 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, | 1705 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, |
1692 // or we'll have visual glitchiness and then DCHECK failures. | 1706 // or we'll have visual glitchiness and then DCHECK failures. |
1693 | 1707 |
1694 // Don't restore saved selection, it will just screw up our interaction | 1708 // Don't restore saved selection, it will just screw up our interaction |
1695 // with this edit. | 1709 // with this edit. |
1696 saved_selection_for_focus_change_.cpMin = -1; | 1710 saved_selection_for_focus_change_.cpMin = -1; |
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2679 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2693 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2680 } | 2694 } |
2681 | 2695 |
2682 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2696 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2683 // Use font_.GetStringWidth() instead of | 2697 // Use font_.GetStringWidth() instead of |
2684 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2698 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2685 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2699 // 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. | 2700 // PosFromChar(i) might return 0 when i is greater than 1. |
2687 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2701 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2688 } | 2702 } |
OLD | NEW |