Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/common/clipboard_service.h" | 7 #include "chrome/common/clipboard_service.h" |
| 8 #include "chrome/common/gfx/chrome_canvas.h" | 8 #include "chrome/common/gfx/chrome_canvas.h" |
| 9 #include "chrome/common/gfx/path.h" | 9 #include "chrome/common/gfx/path.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/views/background.h" | 11 #include "chrome/views/background.h" |
| 12 #include "chrome/views/controls/button/checkbox.h" | 12 #include "chrome/views/controls/button/checkbox.h" |
| 13 #if defined(OS_WIN) | |
| 14 #include "chrome/views/controls/button/native_button_win.h" | |
| 15 #endif | |
| 16 #include "chrome/views/controls/scroll_view.h" | |
| 13 #include "chrome/views/controls/text_field.h" | 17 #include "chrome/views/controls/text_field.h" |
| 14 #include "chrome/views/event.h" | 18 #include "chrome/views/event.h" |
| 15 #include "chrome/views/view.h" | 19 #include "chrome/views/view.h" |
| 16 #include "chrome/views/widget/root_view.h" | 20 #include "chrome/views/widget/root_view.h" |
| 17 #include "chrome/views/widget/widget_win.h" | 21 #include "chrome/views/widget/widget_win.h" |
| 18 #include "chrome/views/window/dialog_delegate.h" | 22 #include "chrome/views/window/dialog_delegate.h" |
| 19 #include "chrome/views/window/window.h" | 23 #include "chrome/views/window/window.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 25 |
| 22 using namespace views; | 26 using namespace views; |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 // current one. | 699 // current one. |
| 696 read_only->SelectAll(); | 700 read_only->SelectAll(); |
| 697 ::SendMessage(read_only->GetNativeComponent(), WM_COPY, 0, 0); | 701 ::SendMessage(read_only->GetNativeComponent(), WM_COPY, 0, 0); |
| 698 normal->SelectAll(); | 702 normal->SelectAll(); |
| 699 ::SendMessage(normal->GetNativeComponent(), WM_PASTE, 0, 0); | 703 ::SendMessage(normal->GetNativeComponent(), WM_PASTE, 0, 0); |
| 700 ::GetWindowText(normal->GetNativeComponent(), buffer, 1024); | 704 ::GetWindowText(normal->GetNativeComponent(), buffer, 1024); |
| 701 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); | 705 EXPECT_EQ(kReadOnlyText, std::wstring(buffer)); |
| 702 } | 706 } |
| 703 #endif | 707 #endif |
| 704 | 708 |
| 709 #if defined(OS_WIN) | |
| 710 //////////////////////////////////////////////////////////////////////////////// | |
| 711 // Mouse-wheel message rerouting | |
| 712 //////////////////////////////////////////////////////////////////////////////// | |
| 713 class ButtonTest : public NativeButton { | |
| 714 public: | |
| 715 ButtonTest(ButtonListener* listener, const std::wstring& label) | |
| 716 : NativeButton(listener, label) { | |
| 717 } | |
| 718 | |
| 719 HWND GetHWND() { | |
| 720 return static_cast<NativeButtonWin*>(native_wrapper_)->GetHWND(); | |
| 721 } | |
| 722 }; | |
| 723 | |
| 724 class CheckboxTest : public Checkbox { | |
| 725 public: | |
| 726 explicit CheckboxTest(const std::wstring& label) : Checkbox(label) { | |
| 727 } | |
| 728 | |
| 729 HWND GetHWND() { | |
| 730 return static_cast<NativeCheckboxWin*>(native_wrapper_)->GetHWND(); | |
| 731 } | |
| 732 }; | |
| 733 | |
| 734 class ScrollableTestView : public View { | |
| 735 public: | |
| 736 ScrollableTestView() { } | |
| 737 | |
| 738 virtual gfx::Size GetPreferredSize() { | |
| 739 return gfx::Size(100, 10000); | |
| 740 } | |
| 741 | |
| 742 virtual void Layout() { | |
| 743 SizeToPreferredSize(); | |
| 744 } | |
| 745 }; | |
| 746 | |
| 747 class TestViewWithControls : public View { | |
| 748 public: | |
| 749 TestViewWithControls() { | |
| 750 button_ = new ButtonTest(NULL, L"Button"); | |
| 751 checkbox_ = new CheckboxTest(L"My checkbox"); | |
| 752 text_field_ = new TextField(); | |
| 753 AddChildView(button_); | |
| 754 AddChildView(checkbox_); | |
| 755 AddChildView(text_field_); | |
| 756 } | |
| 757 | |
| 758 ButtonTest* button_; | |
| 759 CheckboxTest* checkbox_; | |
| 760 TextField* text_field_; | |
| 761 }; | |
| 762 | |
| 763 class SimpleWindowDelegate : public WindowDelegate { | |
| 764 public: | |
| 765 SimpleWindowDelegate(View* contents) : contents_(contents) { } | |
| 766 | |
| 767 virtual void DeleteDelegate() { delete this; } | |
| 768 | |
| 769 virtual View* GetContentsView() { return contents_; } | |
| 770 | |
| 771 private: | |
| 772 View* contents_; | |
| 773 }; | |
| 774 | |
| 775 // Tests that the mouse-wheel messages are correctly rerouted to the window | |
| 776 // under the mouse. | |
| 777 TEST_F(ViewTest, RerouteMouseWheelTest) { | |
| 778 TestViewWithControls* view_with_controls = new TestViewWithControls(); | |
| 779 views::Window* window1 = | |
| 780 views::Window::CreateChromeWindow( | |
| 781 NULL, gfx::Rect(0, 0, 100, 100), | |
| 782 new SimpleWindowDelegate(view_with_controls)); | |
| 783 window1->Show(); | |
| 784 ScrollView* scroll_view = new ScrollView(); | |
| 785 scroll_view->SetContents(new ScrollableTestView()); | |
| 786 views::Window* window2 = | |
| 787 views::Window::CreateChromeWindow(NULL, gfx::Rect(200, 200, 100, 100), | |
| 788 new SimpleWindowDelegate(scroll_view)); | |
| 789 window2->Show(); | |
|
amit
2009/04/15 20:52:23
Does showing automatically activate this window? T
| |
| 790 EXPECT_EQ(0, scroll_view->GetVisibleRect().y()); | |
| 791 | |
| 792 // Let's send a mouse-wheel message to the different controls and check that | |
| 793 // it is rerouted to the window under the mouse (effectively scrolling the | |
| 794 // scroll-view). | |
| 795 | |
| 796 // First to the Window's HWND. | |
| 797 ::SendMessage(view_with_controls->GetWidget()->GetNativeView(), | |
| 798 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | |
| 799 EXPECT_EQ(20, scroll_view->GetVisibleRect().y()); | |
| 800 | |
| 801 // Then the button. | |
| 802 ::SendMessage(view_with_controls->button_->GetHWND(), | |
| 803 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | |
| 804 EXPECT_EQ(40, scroll_view->GetVisibleRect().y()); | |
| 805 | |
| 806 // Then the check-box. | |
| 807 ::SendMessage(view_with_controls->checkbox_->GetHWND(), | |
| 808 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | |
| 809 EXPECT_EQ(60, scroll_view->GetVisibleRect().y()); | |
| 810 | |
| 811 // Then the text-field. | |
| 812 ::SendMessage(view_with_controls->text_field_->GetNativeComponent(), | |
| 813 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(250, 250)); | |
| 814 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | |
| 815 | |
| 816 // Ensure we don't scroll when the mouse is not over that window. | |
| 817 ::SendMessage(view_with_controls->text_field_->GetNativeComponent(), | |
| 818 WM_MOUSEWHEEL, MAKEWPARAM(0, -20), MAKELPARAM(50, 50)); | |
| 819 EXPECT_EQ(80, scroll_view->GetVisibleRect().y()); | |
| 820 } | |
| 821 #endif | |
| 822 | |
| 705 //////////////////////////////////////////////////////////////////////////////// | 823 //////////////////////////////////////////////////////////////////////////////// |
| 706 // Dialogs' default button | 824 // Dialogs' default button |
| 707 //////////////////////////////////////////////////////////////////////////////// | 825 //////////////////////////////////////////////////////////////////////////////// |
| 708 | 826 |
| 709 class TestDialogView : public views::View, | 827 class TestDialogView : public views::View, |
| 710 public views::DialogDelegate, | 828 public views::DialogDelegate, |
| 711 public views::ButtonListener { | 829 public views::ButtonListener { |
| 712 public: | 830 public: |
| 713 TestDialogView() | 831 TestDialogView() |
| 714 : last_pressed_button_(NULL), | 832 : last_pressed_button_(NULL), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 SimularePressingEnterAndCheckDefaultButton(OK); | 1001 SimularePressingEnterAndCheckDefaultButton(OK); |
| 884 | 1002 |
| 885 // Focus the cancel button. | 1003 // Focus the cancel button. |
| 886 client_view_->FocusWillChange(NULL, cancel_button_); | 1004 client_view_->FocusWillChange(NULL, cancel_button_); |
| 887 EXPECT_FALSE(ok_button_->is_default()); | 1005 EXPECT_FALSE(ok_button_->is_default()); |
| 888 EXPECT_TRUE(cancel_button_->is_default()); | 1006 EXPECT_TRUE(cancel_button_->is_default()); |
| 889 EXPECT_FALSE(dialog_view_->button1_->is_default()); | 1007 EXPECT_FALSE(dialog_view_->button1_->is_default()); |
| 890 EXPECT_FALSE(dialog_view_->button2_->is_default()); | 1008 EXPECT_FALSE(dialog_view_->button2_->is_default()); |
| 891 SimularePressingEnterAndCheckDefaultButton(CANCEL); | 1009 SimularePressingEnterAndCheckDefaultButton(CANCEL); |
| 892 } | 1010 } |
| OLD | NEW |