| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "ui/base/clipboard/clipboard.h" | 10 #include "ui/base/clipboard/clipboard.h" |
| 11 #include "ui/base/keycodes/keyboard_codes.h" | 11 #include "ui/base/keycodes/keyboard_codes.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 #endif | 150 #endif |
| 151 last_clip_.setEmpty(); | 151 last_clip_.setEmpty(); |
| 152 accelerator_count_map_.clear(); | 152 accelerator_count_map_.clear(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 155 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
| 156 virtual void ViewHierarchyChanged( | 156 virtual void ViewHierarchyChanged( |
| 157 bool is_add, View *parent, View *child) OVERRIDE; | 157 bool is_add, View *parent, View *child) OVERRIDE; |
| 158 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; | 158 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; |
| 159 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; | 159 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; |
| 160 virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE; | 160 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; |
| 161 #if defined(TOUCH_UI) | 161 #if defined(TOUCH_UI) |
| 162 virtual TouchStatus OnTouchEvent(const TouchEvent& event); | 162 virtual TouchStatus OnTouchEvent(const TouchEvent& event); |
| 163 #endif | 163 #endif |
| 164 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; | 164 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; |
| 165 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | 165 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; |
| 166 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; | 166 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; |
| 167 | 167 |
| 168 // OnBoundsChanged test | 168 // OnBoundsChanged test |
| 169 bool did_change_bounds_; | 169 bool did_change_bounds_; |
| 170 gfx::Rect new_bounds_; | 170 gfx::Rect new_bounds_; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 location_.SetPoint(event.x(), event.y()); | 350 location_.SetPoint(event.x(), event.y()); |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool TestView::OnMouseDragged(const MouseEvent& event) { | 354 bool TestView::OnMouseDragged(const MouseEvent& event) { |
| 355 last_mouse_event_type_ = event.type(); | 355 last_mouse_event_type_ = event.type(); |
| 356 location_.SetPoint(event.x(), event.y()); | 356 location_.SetPoint(event.x(), event.y()); |
| 357 return true; | 357 return true; |
| 358 } | 358 } |
| 359 | 359 |
| 360 void TestView::OnMouseReleased(const MouseEvent& event, bool canceled) { | 360 void TestView::OnMouseReleased(const MouseEvent& event) { |
| 361 last_mouse_event_type_ = event.type(); | 361 last_mouse_event_type_ = event.type(); |
| 362 location_.SetPoint(event.x(), event.y()); | 362 location_.SetPoint(event.x(), event.y()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST_F(ViewTest, MouseEvent) { | 365 TEST_F(ViewTest, MouseEvent) { |
| 366 TestView* v1 = new TestView(); | 366 TestView* v1 = new TestView(); |
| 367 v1->SetBounds(0, 0, 300, 300); | 367 v1->SetBounds(0, 0, 300, 300); |
| 368 | 368 |
| 369 TestView* v2 = new TestView(); | 369 TestView* v2 = new TestView(); |
| 370 v2->SetBounds(100, 100, 100, 100); | 370 v2->SetBounds(100, 100, 100, 100); |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest); | 1471 DISALLOW_COPY_AND_ASSIGN(ButtonDropDownTest); |
| 1472 }; | 1472 }; |
| 1473 | 1473 |
| 1474 // Ensure that regular clicks on the drop down button still work. (i.e. - the | 1474 // Ensure that regular clicks on the drop down button still work. (i.e. - the |
| 1475 // click events are processed and the listener gets the click) | 1475 // click events are processed and the listener gets the click) |
| 1476 TEST_F(ButtonDropDownTest, RegularClickTest) { | 1476 TEST_F(ButtonDropDownTest, RegularClickTest) { |
| 1477 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); | 1477 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); |
| 1478 MouseEvent release_event(ui::ET_MOUSE_RELEASED, 1, 1, | 1478 MouseEvent release_event(ui::ET_MOUSE_RELEASED, 1, 1, |
| 1479 ui::EF_LEFT_BUTTON_DOWN); | 1479 ui::EF_LEFT_BUTTON_DOWN); |
| 1480 button_as_view_->OnMousePressed(press_event); | 1480 button_as_view_->OnMousePressed(press_event); |
| 1481 button_as_view_->OnMouseReleased(release_event, false); | 1481 button_as_view_->OnMouseReleased(release_event); |
| 1482 EXPECT_EQ(test_dialog_->last_pressed_button_, test_dialog_->button_drop_); | 1482 EXPECT_EQ(test_dialog_->last_pressed_button_, test_dialog_->button_drop_); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 #if defined(OS_WIN) | 1485 #if defined(OS_WIN) |
| 1486 // Ensure that dragging downwards on the button shows the menu while keeping the | 1486 // Ensure that dragging downwards on the button shows the menu while keeping the |
| 1487 // button depressed. | 1487 // button depressed. |
| 1488 TEST_F(ButtonDropDownTest, DragMenuTest) { | 1488 TEST_F(ButtonDropDownTest, DragMenuTest) { |
| 1489 test_dialog_->last_pressed_button_ = NULL; | 1489 test_dialog_->last_pressed_button_ = NULL; |
| 1490 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); | 1490 MouseEvent press_event(ui::ET_MOUSE_PRESSED, 1, 1, ui::EF_LEFT_BUTTON_DOWN); |
| 1491 MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 1, 99, ui::EF_LEFT_BUTTON_DOWN); | 1491 MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 1, 99, ui::EF_LEFT_BUTTON_DOWN); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1746 MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1746 MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
| 1747 110, 210, | 1747 110, 210, |
| 1748 ui::EF_LEFT_BUTTON_DOWN); | 1748 ui::EF_LEFT_BUTTON_DOWN); |
| 1749 root->OnMousePressed(pressed); | 1749 root->OnMousePressed(pressed); |
| 1750 EXPECT_EQ(0, v1->last_mouse_event_type_); | 1750 EXPECT_EQ(0, v1->last_mouse_event_type_); |
| 1751 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); | 1751 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); |
| 1752 EXPECT_EQ(190, v2->location_.x()); | 1752 EXPECT_EQ(190, v2->location_.x()); |
| 1753 EXPECT_EQ(10, v2->location_.y()); | 1753 EXPECT_EQ(10, v2->location_.y()); |
| 1754 | 1754 |
| 1755 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0); | 1755 MouseEvent released(ui::ET_MOUSE_RELEASED, 0, 0, 0); |
| 1756 root->OnMouseReleased(released, false); | 1756 root->OnMouseReleased(released); |
| 1757 | 1757 |
| 1758 // Now rotate |v2| inside |v1| clockwise. | 1758 // Now rotate |v2| inside |v1| clockwise. |
| 1759 v2->SetRotation(90.0); | 1759 v2->SetRotation(90.0); |
| 1760 v2->SetTranslateX(100); | 1760 v2->SetTranslateX(100); |
| 1761 | 1761 |
| 1762 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to | 1762 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to |
| 1763 // (300, 400) in |root|. | 1763 // (300, 400) in |root|. |
| 1764 | 1764 |
| 1765 v1->Reset(); | 1765 v1->Reset(); |
| 1766 v2->Reset(); | 1766 v2->Reset(); |
| 1767 | 1767 |
| 1768 MouseEvent p2(ui::ET_MOUSE_PRESSED, | 1768 MouseEvent p2(ui::ET_MOUSE_PRESSED, |
| 1769 110, 320, | 1769 110, 320, |
| 1770 ui::EF_LEFT_BUTTON_DOWN); | 1770 ui::EF_LEFT_BUTTON_DOWN); |
| 1771 root->OnMousePressed(p2); | 1771 root->OnMousePressed(p2); |
| 1772 EXPECT_EQ(0, v1->last_mouse_event_type_); | 1772 EXPECT_EQ(0, v1->last_mouse_event_type_); |
| 1773 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); | 1773 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); |
| 1774 EXPECT_EQ(10, v2->location_.x()); | 1774 EXPECT_EQ(10, v2->location_.x()); |
| 1775 EXPECT_EQ(20, v2->location_.y()); | 1775 EXPECT_EQ(20, v2->location_.y()); |
| 1776 | 1776 |
| 1777 root->OnMouseReleased(released, false); | 1777 root->OnMouseReleased(released); |
| 1778 | 1778 |
| 1779 v1->ResetTransform(); | 1779 v1->ResetTransform(); |
| 1780 v2->ResetTransform(); | 1780 v2->ResetTransform(); |
| 1781 | 1781 |
| 1782 TestView* v3 = new TestView(); | 1782 TestView* v3 = new TestView(); |
| 1783 v3->SetBounds(10, 10, 20, 30); | 1783 v3->SetBounds(10, 10, 20, 30); |
| 1784 v2->AddChildView(v3); | 1784 v2->AddChildView(v3); |
| 1785 | 1785 |
| 1786 // Rotate |v3| clockwise with respect to |v2|. | 1786 // Rotate |v3| clockwise with respect to |v2|. |
| 1787 v3->SetRotation(90.0); | 1787 v3->SetRotation(90.0); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1798 | 1798 |
| 1799 MouseEvent p3(ui::ET_MOUSE_PRESSED, | 1799 MouseEvent p3(ui::ET_MOUSE_PRESSED, |
| 1800 112, 110, | 1800 112, 110, |
| 1801 ui::EF_LEFT_BUTTON_DOWN); | 1801 ui::EF_LEFT_BUTTON_DOWN); |
| 1802 root->OnMousePressed(p3); | 1802 root->OnMousePressed(p3); |
| 1803 | 1803 |
| 1804 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); | 1804 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); |
| 1805 EXPECT_EQ(10, v3->location_.x()); | 1805 EXPECT_EQ(10, v3->location_.x()); |
| 1806 EXPECT_EQ(25, v3->location_.y()); | 1806 EXPECT_EQ(25, v3->location_.y()); |
| 1807 | 1807 |
| 1808 root->OnMouseReleased(released, false); | 1808 root->OnMouseReleased(released); |
| 1809 | 1809 |
| 1810 v1->ResetTransform(); | 1810 v1->ResetTransform(); |
| 1811 v2->ResetTransform(); | 1811 v2->ResetTransform(); |
| 1812 v3->ResetTransform(); | 1812 v3->ResetTransform(); |
| 1813 | 1813 |
| 1814 v1->Reset(); | 1814 v1->Reset(); |
| 1815 v2->Reset(); | 1815 v2->Reset(); |
| 1816 v3->Reset(); | 1816 v3->Reset(); |
| 1817 | 1817 |
| 1818 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. | 1818 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1830 | 1830 |
| 1831 MouseEvent p4(ui::ET_MOUSE_PRESSED, | 1831 MouseEvent p4(ui::ET_MOUSE_PRESSED, |
| 1832 124, 125, | 1832 124, 125, |
| 1833 ui::EF_LEFT_BUTTON_DOWN); | 1833 ui::EF_LEFT_BUTTON_DOWN); |
| 1834 root->OnMousePressed(p4); | 1834 root->OnMousePressed(p4); |
| 1835 | 1835 |
| 1836 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); | 1836 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); |
| 1837 EXPECT_EQ(10, v3->location_.x()); | 1837 EXPECT_EQ(10, v3->location_.x()); |
| 1838 EXPECT_EQ(25, v3->location_.y()); | 1838 EXPECT_EQ(25, v3->location_.y()); |
| 1839 | 1839 |
| 1840 root->OnMouseReleased(released, false); | 1840 root->OnMouseReleased(released); |
| 1841 | 1841 |
| 1842 widget->CloseNow(); | 1842 widget->CloseNow(); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 //////////////////////////////////////////////////////////////////////////////// | 1845 //////////////////////////////////////////////////////////////////////////////// |
| 1846 // OnVisibleBoundsChanged() | 1846 // OnVisibleBoundsChanged() |
| 1847 | 1847 |
| 1848 class VisibleBoundsView : public View { | 1848 class VisibleBoundsView : public View { |
| 1849 public: | 1849 public: |
| 1850 VisibleBoundsView() : received_notification_(false) {} | 1850 VisibleBoundsView() : received_notification_(false) {} |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1933 top_view->scheduled_paint_rects_.clear(); | 1933 top_view->scheduled_paint_rects_.clear(); |
| 1934 child_view->SetBounds(30, 30, 20, 20); | 1934 child_view->SetBounds(30, 30, 20, 20); |
| 1935 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); | 1935 EXPECT_EQ(2U, top_view->scheduled_paint_rects_.size()); |
| 1936 | 1936 |
| 1937 // There should be 2 rects, spanning from (10, 10) to (50, 50). | 1937 // There should be 2 rects, spanning from (10, 10) to (50, 50). |
| 1938 gfx::Rect paint_rect = | 1938 gfx::Rect paint_rect = |
| 1939 top_view->scheduled_paint_rects_[0].Union( | 1939 top_view->scheduled_paint_rects_[0].Union( |
| 1940 top_view->scheduled_paint_rects_[1]); | 1940 top_view->scheduled_paint_rects_[1]); |
| 1941 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); | 1941 EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); |
| 1942 } | 1942 } |
| OLD | NEW |