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

Unified Diff: chrome/views/view_unittest.cc

Issue 73087: Make TextFields reroute mouse wheel messages (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/views/controls/text_field.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/views/view_unittest.cc
===================================================================
--- chrome/views/view_unittest.cc (revision 13748)
+++ chrome/views/view_unittest.cc (working copy)
@@ -10,6 +10,10 @@
#include "chrome/common/notification_service.h"
#include "chrome/views/background.h"
#include "chrome/views/controls/button/checkbox.h"
+#if defined(OS_WIN)
+#include "chrome/views/controls/button/native_button_win.h"
+#endif
+#include "chrome/views/controls/scroll_view.h"
#include "chrome/views/controls/text_field.h"
#include "chrome/views/event.h"
#include "chrome/views/view.h"
@@ -702,7 +706,121 @@
}
#endif
+#if defined(OS_WIN)
////////////////////////////////////////////////////////////////////////////////
+// Mouse-wheel message rerouting
+////////////////////////////////////////////////////////////////////////////////
+class ButtonTest : public NativeButton {
+ public:
+ ButtonTest(ButtonListener* listener, const std::wstring& label)
+ : NativeButton(listener, label) {
+ }
+
+ HWND GetHWND() {
+ return static_cast<NativeButtonWin*>(native_wrapper_)->GetHWND();
+ }
+};
+
+class CheckboxTest : public Checkbox {
+ public:
+ explicit CheckboxTest(const std::wstring& label) : Checkbox(label) {
+ }
+
+ HWND GetHWND() {
+ return static_cast<NativeCheckboxWin*>(native_wrapper_)->GetHWND();
+ }
+};
+
+class ScrollableTestView : public View {
+ public:
+ ScrollableTestView() { }
+
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(100, 10000);
+ }
+
+ virtual void Layout() {
+ SizeToPreferredSize();
+ }
+};
+
+class TestViewWithControls : public View {
+ public:
+ TestViewWithControls() {
+ button_ = new ButtonTest(NULL, L"Button");
+ checkbox_ = new CheckboxTest(L"My checkbox");
+ text_field_ = new TextField();
+ AddChildView(button_);
+ AddChildView(checkbox_);
+ AddChildView(text_field_);
+ }
+
+ ButtonTest* button_;
+ CheckboxTest* checkbox_;
+ TextField* text_field_;
+};
+
+class SimpleWindowDelegate : public WindowDelegate {
+ public:
+ SimpleWindowDelegate(View* contents) : contents_(contents) { }
+
+ virtual void DeleteDelegate() { delete this; }
+
+ virtual View* GetContentsView() { return contents_; }
+
+ private:
+ View* contents_;
+};
+
+// Tests that the mouse-wheel messages are correctly rerouted to the window
+// under the mouse.
+TEST_F(ViewTest, RerouteMouseWheelTest) {
+ TestViewWithControls* view_with_controls = new TestViewWithControls();
+ views::Window* window1 =
+ views::Window::CreateChromeWindow(
+ NULL, gfx::Rect(0, 0, 100, 100),
+ new SimpleWindowDelegate(view_with_controls));
+ window1->Show();
+ ScrollView* scroll_view = new ScrollView();
+ scroll_view->SetContents(new ScrollableTestView());
+ views::Window* window2 =
+ views::Window::CreateChromeWindow(NULL, gfx::Rect(200, 200, 100, 100),
+ new SimpleWindowDelegate(scroll_view));
+ window2->Show();
amit 2009/04/15 20:52:23 Does showing automatically activate this window? T
+ EXPECT_EQ(0, scroll_view->GetVisibleRect().y());
+
+ // Let's send a mouse-wheel message to the different controls and check that
+ // it is rerouted to the window under the mouse (effectively scrolling the
+ // scroll-view).
+
+ // First to the Window's HWND.
+ ::SendMessage(view_with_controls->GetWidget()->GetNativeView(),
+ WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250));
+ EXPECT_EQ(20, scroll_view->GetVisibleRect().y());
+
+ // Then the button.
+ ::SendMessage(view_with_controls->button_->GetHWND(),
+ WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250));
+ EXPECT_EQ(40, scroll_view->GetVisibleRect().y());
+
+ // Then the check-box.
+ ::SendMessage(view_with_controls->checkbox_->GetHWND(),
+ WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250));
+ EXPECT_EQ(60, scroll_view->GetVisibleRect().y());
+
+ // Then the text-field.
+ ::SendMessage(view_with_controls->text_field_->GetNativeComponent(),
+ WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250));
+ EXPECT_EQ(80, scroll_view->GetVisibleRect().y());
+
+ // Ensure we don't scroll when the mouse is not over that window.
+ ::SendMessage(view_with_controls->text_field_->GetNativeComponent(),
+ WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50));
+ EXPECT_EQ(80, scroll_view->GetVisibleRect().y());
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
// Dialogs' default button
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « chrome/views/controls/text_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698