diff options
author | joshia@google.com <joshia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 17:39:00 +0000 |
---|---|---|
committer | joshia@google.com <joshia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 17:39:00 +0000 |
commit | 1345bda1781a2d1fd5120f852ac0ff04a871a3a1 (patch) | |
tree | fa088e916728f87c8ab7e751dfb7631d0e814a95 /chrome/browser | |
parent | c3ce34fb49289027feccf7a4e66714096872f97d (diff) | |
download | chromium_src-1345bda1781a2d1fd5120f852ac0ff04a871a3a1.zip chromium_src-1345bda1781a2d1fd5120f852ac0ff04a871a3a1.tar.gz chromium_src-1345bda1781a2d1fd5120f852ac0ff04a871a3a1.tar.bz2 |
Touchpad support for laptops
This fix is a workaround to receive mouse wheel and scroll messages
from synaptics touchpad driver used in majority of laptops.
Removed fake scroll bars in RenderWidgetHostHwnd so that it can now
receive mouse wheel messages from synaptics drivers for Dell, Toshiba
laptops.
Added fake scroll bars to WebContents so that it can receive scroll
messages. WebContents then reflects scroll messages to the view to
give it a chance to handle them.
BUG=4
TEST=Touchpad scrolling and zooming (control + scroll) on various laptops.
Review URL: http://codereview.chromium.org/2878
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/render_widget_host_hwnd.cc | 33 | ||||
-rw-r--r-- | chrome/browser/render_widget_host_hwnd.h | 7 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 81 | ||||
-rw-r--r-- | chrome/browser/web_contents.h | 4 |
4 files changed, 64 insertions, 61 deletions
diff --git a/chrome/browser/render_widget_host_hwnd.cc b/chrome/browser/render_widget_host_hwnd.cc index 346b050..8ca727c 100644 --- a/chrome/browser/render_widget_host_hwnd.cc +++ b/chrome/browser/render_widget_host_hwnd.cc @@ -724,39 +724,6 @@ LRESULT RenderWidgetHostHWND::OnWheelEvent(UINT message, WPARAM wparam, return 0; } -LRESULT RenderWidgetHostHWND::OnNcCalcSize(UINT message, WPARAM w_param, - LPARAM l_param, BOOL& handled) { - // Handle WM_NCCALCSIZE and make scrollbar size to 0. - // Here we indicate that the entire window area is our - // client area. The assumption is that we won't have a border - // or any other non-client widget. - return 0; -} - -LRESULT RenderWidgetHostHWND::OnSize(UINT message, WPARAM w_param, - LPARAM l_param, BOOL& handled) { - // Set arbitrary but valid scroll information so that - // our window will get WS_VSCROLL and WS_HSCROLL style. - - // TODO(joshia): The correct thing to do here is to get - // the correct scroll information from the renderer and - // set it here. - SCROLLINFO si = {0}; - si.cbSize = sizeof(si); - si.fMask = SIF_ALL; - - si.nMin = 1; - si.nMax = 100; - si.nPage = 10; - si.nTrackPos = 50; - - SetScrollInfo(SB_HORZ, &si, FALSE); - SetScrollInfo(SB_VERT, &si, FALSE); - - handled = FALSE; - return 0; -} - LRESULT RenderWidgetHostHWND::OnMouseActivate(UINT, WPARAM, LPARAM, BOOL& handled) { // We handle WM_MOUSEACTIVATE to set focus to the underlying plugin diff --git a/chrome/browser/render_widget_host_hwnd.h b/chrome/browser/render_widget_host_hwnd.h index 5f245cb..bc16c6d 100644 --- a/chrome/browser/render_widget_host_hwnd.h +++ b/chrome/browser/render_widget_host_hwnd.h @@ -106,8 +106,6 @@ class RenderWidgetHostHWND : MESSAGE_HANDLER(WM_CHAR, OnKeyEvent) MESSAGE_HANDLER(WM_SYSCHAR, OnKeyEvent) MESSAGE_HANDLER(WM_IME_CHAR, OnKeyEvent) - MESSAGE_HANDLER(WM_NCCALCSIZE, OnNcCalcSize) - MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate) END_MSG_MAP() @@ -165,11 +163,6 @@ class RenderWidgetHostHWND : UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); LRESULT OnWheelEvent( UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); - // Handle WM_NCCALCSIZE and supress scrollbars - LRESULT OnNcCalcSize(UINT, WPARAM, LPARAM, BOOL& handled); - // Handle WM_SIZE and indicate that we have a valid scroll info - // so that windows will give us the WS_HSCROLL and WS_VSCROLL style. - LRESULT OnSize(UINT, WPARAM, LPARAM, BOOL& handled); LRESULT OnMouseActivate(UINT, WPARAM, LPARAM, BOOL& handled); // Handle vertical scrolling LRESULT OnVScroll(int code, short position, HWND scrollbar_control); diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 7084bd8..3a9fd3a 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -376,13 +376,6 @@ void WebContents::OnPaint(HDC junk_dc) { SetMsgHandled(FALSE); } -void WebContents::OnHScroll(int scroll_type, short position, HWND scrollbar) { - // This window can receive scroll events as a result of the ThinkPad's - // trackpad scroll wheel emulation. - if (!ScrollZoom(scroll_type)) - SetMsgHandled(FALSE); -} - LRESULT WebContents::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) { switch (msg) { case WM_LBUTTONDOWN: @@ -398,12 +391,7 @@ LRESULT WebContents::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) { if (delegate()) delegate()->ContentsMouseEvent(this, WM_MOUSEMOVE); break; - case WM_MOUSEWHEEL: - // This message is reflected from the view() to this window. - if (GET_KEYSTATE_WPARAM(w_param) & MK_CONTROL) { - WheelZoom(GET_WHEEL_DELTA_WPARAM(w_param)); - return 1; - } + default: break; } @@ -418,23 +406,74 @@ void WebContents::OnMouseLeave() { SetMsgHandled(FALSE); } +// A message is reflected here from view(). +// Return non-zero to indicate that it is handled here. +// Return 0 to allow view() to further process it. LRESULT WebContents::OnReflectedMessage(UINT msg, WPARAM w_param, LPARAM l_param) { MSG* message = reinterpret_cast<MSG*>(l_param); - LRESULT ret = 0; - if (message) { - ProcessWindowMessage(message->hwnd, message->message, message->wParam, - message->lParam, ret); + switch (message->message) { + case WM_MOUSEWHEEL: + // This message is reflected from the view() to this window. + if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) { + WheelZoom(GET_WHEEL_DELTA_WPARAM(message->wParam)); + return 1; + } + break; + case WM_HSCROLL: + case WM_VSCROLL: + if (ScrollZoom(LOWORD(message->wParam))) + return 1; + default: + break; } - return ret; + return 0; +} + +void WebContents::OnSize(UINT param, const CSize& size) { + HWNDViewContainer::OnSize(param, size); + + // Hack for thinkpad touchpad driver. + // Set fake scrollbars so that we can get scroll messages, + SCROLLINFO si = {0}; + si.cbSize = sizeof(si); + si.fMask = SIF_ALL; + + si.nMin = 1; + si.nMax = 100; + si.nPage = 10; + si.nTrackPos = 50; + + ::SetScrollInfo(GetHWND(), SB_HORZ, &si, FALSE); + ::SetScrollInfo(GetHWND(), SB_VERT, &si, FALSE); +} + +LRESULT WebContents::OnNCCalcSize(BOOL w_param, LPARAM l_param) { + // Hack for thinkpad mouse wheel driver. We have set the fake scroll bars + // to receive scroll messages from thinkpad touchpad driver. Suppress + // painting of scrollbars by returning 0 size for them. + return 0; +} + +void WebContents::OnHScroll(int scroll_type, short position, HWND scrollbar) { + ScrollCommon(WM_HSCROLL, scroll_type, position, scrollbar); } void WebContents::OnVScroll(int scroll_type, short position, HWND scrollbar) { + ScrollCommon(WM_VSCROLL, scroll_type, position, scrollbar); +} + +void WebContents::ScrollCommon(UINT message, int scroll_type, short position, + HWND scrollbar) { // This window can receive scroll events as a result of the ThinkPad's - // TrackPad scroll wheel emulation. - if (!ScrollZoom(scroll_type)) - SetMsgHandled(FALSE); + // Trackpad scroll wheel emulation. + if (!ScrollZoom(scroll_type)) { + // Reflect scroll message to the view() to give it a chance + // to process scrolling. + SendMessage(GetContentHWND(), message, MAKELONG(scroll_type, position), + (LPARAM) scrollbar); + } } bool WebContents::ScrollZoom(int scroll_type) { diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index 866862a..30b4c2f 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -493,6 +493,8 @@ class WebContents : public TabContents, GearsCreateShortcutCallbackFunctor* callback_functor; }; + void ScrollCommon(UINT message, int scroll_type, short position, + HWND scrollbar); bool ScrollZoom(int scroll_type); void WheelZoom(int distance); @@ -511,6 +513,8 @@ class WebContents : public TabContents, virtual void OnSetFocus(HWND window); virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); virtual void OnWindowPosChanged(WINDOWPOS* window_pos); + virtual void OnSize(UINT param, const CSize& size); + virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); // Callback from HistoryService for our request for a favicon. void OnFavIconData(HistoryService::Handle handle, |