diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 23:24:57 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 23:24:57 +0000 |
commit | c53ce46a3bff3f1990095588ad6764bfd4480cad (patch) | |
tree | 78901cccfbc1d4cdc7ab835eb892e2ecdcdbb6a9 /ui | |
parent | 279d0db954367d00b49a1600423858b4dcb32139 (diff) | |
download | chromium_src-c53ce46a3bff3f1990095588ad6764bfd4480cad.zip chromium_src-c53ce46a3bff3f1990095588ad6764bfd4480cad.tar.gz chromium_src-c53ce46a3bff3f1990095588ad6764bfd4480cad.tar.bz2 |
Gets touch semantics working on windows. Specifically the following:
. If you use a mouse then left click reorders and control-left click
changes the visible tabs.
. If you use a touch device left click moves the set of visible tabs
and if you right click (corresponds to long press) then you reorder.
Additionally we don't allow detaching on metro.
BUG=123274
TEST=none
R=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10399073
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137769 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/events.h | 2 | ||||
-rw-r--r-- | ui/base/layout.cc | 32 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.cc | 27 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.h | 9 |
4 files changed, 53 insertions, 17 deletions
diff --git a/ui/base/events.h b/ui/base/events.h index e0e712d..74cfd63 100644 --- a/ui/base/events.h +++ b/ui/base/events.h @@ -83,6 +83,8 @@ enum MouseEventFlags { EF_IS_TRIPLE_CLICK = 1 << 17, EF_IS_NON_CLIENT = 1 << 18, EF_IS_SYNTHESIZED = 1 << 19, // Only for Aura. See ui/aura/root_window.h + EF_FROM_TOUCH = 1 << 20, // Indicates this mouse event is generated + // from an unconsumed touch/gesture event. }; enum TouchStatus { diff --git a/ui/base/layout.cc b/ui/base/layout.cc index e0e6471..fffa271 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -22,23 +22,23 @@ namespace { // Helper function that determines whether we want to optimize the UI for touch. bool UseTouchOptimizedUI() { - // If --touch-optimized-ui is specified and not set to "auto", then override - // the hardware-determined setting (eg. for testing purposes). - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kTouchOptimizedUI)) { - const std::string switch_value = CommandLine::ForCurrentProcess()-> - GetSwitchValueASCII(switches::kTouchOptimizedUI); + // If --touch-optimized-ui is specified and not set to "auto", then override + // the hardware-determined setting (eg. for testing purposes). + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kTouchOptimizedUI)) { + const std::string switch_value = CommandLine::ForCurrentProcess()-> + GetSwitchValueASCII(switches::kTouchOptimizedUI); - // Note that simply specifying the switch is the same as enabled. - if (switch_value.empty() || - switch_value == switches::kTouchOptimizedUIEnabled) { - return true; - } else if (switch_value == switches::kTouchOptimizedUIDisabled) { - return false; - } else if (switch_value != switches::kTouchOptimizedUIAuto) { - LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; - } - } + // Note that simply specifying the switch is the same as enabled. + if (switch_value.empty() || + switch_value == switches::kTouchOptimizedUIEnabled) { + return true; + } else if (switch_value == switches::kTouchOptimizedUIDisabled) { + return false; + } else if (switch_value != switches::kTouchOptimizedUIAuto) { + LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; + } + } #if defined(ENABLE_METRO) return base::win::GetMetroModule() != NULL; diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index fe4c6b1..7e53c8e 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -1181,7 +1181,8 @@ HICON NativeWidgetWin::GetDefaultWindowIcon() const { return NULL; } -LRESULT NativeWidgetWin::OnWndProc(UINT message, WPARAM w_param, +LRESULT NativeWidgetWin::OnWndProc(UINT message, + WPARAM w_param, LPARAM l_param) { HWND window = hwnd(); LRESULT result = 0; @@ -1334,6 +1335,9 @@ LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) { // Get access to a modifiable copy of the system menu. GetSystemMenu(hwnd(), false); + if (base::win::GetVersion() >= base::win::VERSION_WIN7) + RegisterTouchWindow(hwnd(), 0); + return 0; } @@ -1584,6 +1588,8 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message, MSG msg = { hwnd(), message, w_param, l_param, 0, { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; MouseEvent event(msg); + if (!touch_ids_.empty()) + event.set_flags(event.flags() | ui::EF_FROM_TOUCH); if (!(event.flags() & ui::EF_IS_NON_CLIENT)) if (tooltip_manager_.get()) @@ -2041,6 +2047,25 @@ void NativeWidgetWin::OnThemeChanged() { ui::NativeThemeWin::instance()->CloseHandles(); } +LRESULT NativeWidgetWin::OnTouchEvent(UINT message, + WPARAM w_param, + LPARAM l_param) { + int num_points = LOWORD(w_param); + scoped_array<TOUCHINPUT> input(new TOUCHINPUT[num_points]); + if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(l_param), + num_points, input.get(), sizeof(TOUCHINPUT))) { + for (int i = 0; i < num_points; ++i) { + if (input[i].dwFlags & TOUCHEVENTF_DOWN) + touch_ids_.insert(input[i].dwID); + if (input[i].dwFlags & TOUCHEVENTF_UP) + touch_ids_.erase(input[i].dwID); + } + } + CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param)); + SetMsgHandled(FALSE); + return 0; +} + void NativeWidgetWin::OnVScroll(int scroll_type, short position, HWND scrollbar) { diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index 5e1b7b7..61019a9 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -11,6 +11,7 @@ #include <atlcrack.h> #include <atlmisc.h> +#include <set> #include <string> #include <vector> @@ -319,6 +320,9 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages) MESSAGE_HANDLER_EX(WM_SYSDEADCHAR, OnImeMessages) + // Touch Events. + MESSAGE_HANDLER_EX(WM_TOUCH, OnTouchEvent) + // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. MSG_WM_ACTIVATE(OnActivate) MSG_WM_ACTIVATEAPP(OnActivateApp) @@ -422,6 +426,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual void OnSize(UINT param, const CSize& size); virtual void OnSysCommand(UINT notification_code, CPoint click); virtual void OnThemeChanged(); + virtual LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); virtual void OnWindowPosChanging(WINDOWPOS* window_pos); virtual void OnWindowPosChanged(WINDOWPOS* window_pos); @@ -468,6 +473,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, private: typedef ScopedVector<ui::ViewProp> ViewProps; + typedef std::set<DWORD> TouchIDs; // Called after the WM_ACTIVATE message has been processed by the default // windows procedure. @@ -654,6 +660,9 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, bool remove_standard_frame_; + // The set of touch devices currently down. + TouchIDs touch_ids_; + DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); }; |