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 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 1375 BOOL touch_mode = RegisterTouchWindow(m_hWnd, TWF_WANTPALM); |
| 1376 DCHECK(touch_mode); |
| 1377 } |
1374 SetMsgHandled(FALSE); | 1378 SetMsgHandled(FALSE); |
1375 return 0; | 1379 return 0; |
1376 } | 1380 } |
1377 | 1381 |
1378 void OmniboxViewWin::OnCut() { | 1382 void OmniboxViewWin::OnCut() { |
1379 OnCopy(); | 1383 OnCopy(); |
1380 | 1384 |
1381 // This replace selection will have no effect (even on the undo stack) if the | 1385 // This replace selection will have no effect (even on the undo stack) if the |
1382 // current selection is empty. | 1386 // current selection is empty. |
1383 ReplaceSel(L"", true); | 1387 ReplaceSel(L"", true); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 if (model()->user_input_in_progress()) | 1443 if (model()->user_input_in_progress()) |
1440 UpdatePopup(); | 1444 UpdatePopup(); |
1441 | 1445 |
1442 break; | 1446 break; |
1443 default: | 1447 default: |
1444 break; | 1448 break; |
1445 } | 1449 } |
1446 return DefWindowProc(message, wparam, lparam); | 1450 return DefWindowProc(message, wparam, lparam); |
1447 } | 1451 } |
1448 | 1452 |
1449 LRESULT OmniboxViewWin::OnPointerDown(UINT message, | 1453 LRESULT OmniboxViewWin::OnTouchEvent(UINT message, |
1450 WPARAM wparam, | 1454 WPARAM wparam, |
1451 LPARAM lparam) { | 1455 LPARAM lparam) { |
1452 if (!model()->has_focus()) | 1456 // There is a bug in Windows 8 where in the generated mouse messages |
1453 SetFocus(); | 1457 // after touch go to the window which previously had focus. This means that |
1454 | 1458 // if a user taps the omnibox to give it focus, we don't get the simulated |
1455 if (IS_POINTER_FIRSTBUTTON_WPARAM(wparam)) { | 1459 // WM_LBUTTONDOWN, and thus don't properly select all the text. To ensure |
1456 TrackMousePosition(kLeft, CPoint(GET_X_LPARAM(lparam), | 1460 // that we get this message, we capture the mouse when the user is doing a |
1457 GET_Y_LPARAM(lparam))); | 1461 // single-point tap on an unfocused model. |
| 1462 if ((wparam == 1) && !model()->has_focus()) { |
| 1463 TOUCHINPUT point = {0}; |
| 1464 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(lparam), 1, |
| 1465 &point, sizeof(TOUCHINPUT))) { |
| 1466 if (point.dwFlags & TOUCHEVENTF_DOWN) |
| 1467 SetCapture(); |
| 1468 else if (point.dwFlags & TOUCHEVENTF_UP) |
| 1469 ReleaseCapture(); |
| 1470 } |
1458 } | 1471 } |
1459 | |
1460 SetMsgHandled(false); | 1472 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; | 1473 return 0; |
1470 } | 1474 } |
1471 | 1475 |
1472 void OmniboxViewWin::OnKeyDown(TCHAR key, | 1476 void OmniboxViewWin::OnKeyDown(TCHAR key, |
1473 UINT repeat_count, | 1477 UINT repeat_count, |
1474 UINT flags) { | 1478 UINT flags) { |
1475 delete_at_end_pressed_ = false; | 1479 delete_at_end_pressed_ = false; |
1476 | 1480 |
1477 if (OnKeyDownAllModes(key, repeat_count, flags)) | 1481 if (OnKeyDownAllModes(key, repeat_count, flags)) |
1478 return; | 1482 return; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 // actually going to activate and gain focus. | 1677 // actually going to activate and gain focus. |
1674 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, | 1678 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, |
1675 reinterpret_cast<WPARAM>(window), | 1679 reinterpret_cast<WPARAM>(window), |
1676 MAKELPARAM(hit_test, mouse_message)); | 1680 MAKELPARAM(hit_test, mouse_message)); |
1677 // Check if we're getting focus from a click. We have to do this here rather | 1681 // 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 | 1682 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be |
1679 // reached before OnXButtonDown(), preventing us from detecting this properly | 1683 // reached before OnXButtonDown(), preventing us from detecting this properly |
1680 // there. Also in those cases, we need to already know in OnSetFocus() that | 1684 // there. Also in those cases, we need to already know in OnSetFocus() that |
1681 // we should not restore the saved selection. | 1685 // we should not restore the saved selection. |
1682 if (!model()->has_focus() && | 1686 if (!model()->has_focus() && |
1683 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN || | 1687 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN)) && |
1684 mouse_message == WM_POINTERDOWN)) && | |
1685 (result == MA_ACTIVATE)) { | 1688 (result == MA_ACTIVATE)) { |
1686 DCHECK(!gaining_focus_.get()); | 1689 if (gaining_focus_) { |
| 1690 // On Windows 8 in metro mode, we get two WM_MOUSEACTIVATE messages when |
| 1691 // we click on the omnibox with the mouse. |
| 1692 DCHECK(base::win::IsMetroProcess()); |
| 1693 return result; |
| 1694 } |
1687 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); | 1695 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); |
1688 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not | 1696 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not |
1689 // guaranteed to call OnXButtonDown() later! Specifically, if this is the | 1697 // guaranteed to call OnXButtonDown() later! Specifically, if this is the |
1690 // second click of a double click, we'll reach here but later call | 1698 // second click of a double click, we'll reach here but later call |
1691 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, | 1699 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, |
1692 // or we'll have visual glitchiness and then DCHECK failures. | 1700 // or we'll have visual glitchiness and then DCHECK failures. |
1693 | 1701 |
1694 // Don't restore saved selection, it will just screw up our interaction | 1702 // Don't restore saved selection, it will just screw up our interaction |
1695 // with this edit. | 1703 // with this edit. |
1696 saved_selection_for_focus_change_.cpMin = -1; | 1704 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); | 2687 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2680 } | 2688 } |
2681 | 2689 |
2682 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2690 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2683 // Use font_.GetStringWidth() instead of | 2691 // Use font_.GetStringWidth() instead of |
2684 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2692 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2685 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2693 // 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. | 2694 // PosFromChar(i) might return 0 when i is greater than 1. |
2687 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2695 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2688 } | 2696 } |
OLD | NEW |