OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 EXPECT_EQ(NULL, vs->RetrieveView(s1)); | 778 EXPECT_EQ(NULL, vs->RetrieveView(s1)); |
779 EXPECT_EQ(NULL, vs->RetrieveView(s12)); | 779 EXPECT_EQ(NULL, vs->RetrieveView(s12)); |
780 EXPECT_EQ(NULL, vs->RetrieveView(s11)); | 780 EXPECT_EQ(NULL, vs->RetrieveView(s11)); |
781 EXPECT_EQ(NULL, vs->RetrieveView(s12)); | 781 EXPECT_EQ(NULL, vs->RetrieveView(s12)); |
782 EXPECT_EQ(NULL, vs->RetrieveView(s21)); | 782 EXPECT_EQ(NULL, vs->RetrieveView(s21)); |
783 EXPECT_EQ(NULL, vs->RetrieveView(s111)); | 783 EXPECT_EQ(NULL, vs->RetrieveView(s111)); |
784 EXPECT_EQ(NULL, vs->RetrieveView(s112)); | 784 EXPECT_EQ(NULL, vs->RetrieveView(s112)); |
785 } | 785 } |
786 | 786 |
787 namespace { | 787 namespace { |
788 class HitTestView : public View { | |
789 public: | |
790 explicit HitTestView(bool has_hittest_mask) | |
791 : has_hittest_mask_(has_hittest_mask) { | |
792 } | |
793 virtual ~HitTestView() {} | |
794 | |
795 protected: | |
796 // Overridden from View: | |
797 virtual bool HasHitTestMask() const OVERRIDE { | |
798 return has_hittest_mask_; | |
799 } | |
800 virtual void GetHitTestMaskDeprecated(HitTestSource source, | |
801 gfx::Path* mask) const OVERRIDE { | |
802 DCHECK(has_hittest_mask_); | |
803 DCHECK(mask); | |
804 | |
805 SkScalar w = SkIntToScalar(width()); | |
806 SkScalar h = SkIntToScalar(height()); | |
807 | |
808 // Create a triangular mask within the bounds of this View. | |
809 mask->moveTo(w / 2, 0); | |
810 mask->lineTo(w, h); | |
811 mask->lineTo(0, h); | |
812 mask->close(); | |
813 } | |
814 | |
815 private: | |
816 bool has_hittest_mask_; | |
817 | |
818 DISALLOW_COPY_AND_ASSIGN(HitTestView); | |
819 }; | |
820 | |
821 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) { | |
822 gfx::Point tmp(p); | |
823 View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp); | |
824 return tmp; | |
825 } | |
826 | |
827 gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) { | |
828 gfx::Rect tmp(r); | |
829 tmp.set_origin(ConvertPointToView(view, r.origin())); | |
830 return tmp; | |
831 } | |
832 | 788 |
833 void RotateCounterclockwise(gfx::Transform* transform) { | 789 void RotateCounterclockwise(gfx::Transform* transform) { |
834 transform->matrix().set3x3(0, -1, 0, | 790 transform->matrix().set3x3(0, -1, 0, |
835 1, 0, 0, | 791 1, 0, 0, |
836 0, 0, 1); | 792 0, 0, 1); |
837 } | 793 } |
838 | 794 |
839 void RotateClockwise(gfx::Transform* transform) { | 795 void RotateClockwise(gfx::Transform* transform) { |
840 transform->matrix().set3x3( 0, 1, 0, | 796 transform->matrix().set3x3( 0, 1, 0, |
841 -1, 0, 0, | 797 -1, 0, 0, |
842 0, 0, 1); | 798 0, 0, 1); |
843 } | 799 } |
844 | 800 |
845 } // namespace | 801 } // namespace |
846 | 802 |
847 TEST_F(ViewTest, HitTestMasks) { | |
848 Widget* widget = new Widget; | |
849 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | |
850 widget->Init(params); | |
851 View* root_view = widget->GetRootView(); | |
852 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); | |
853 | |
854 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); | |
855 HitTestView* v1 = new HitTestView(false); | |
856 v1->SetBoundsRect(v1_bounds); | |
857 root_view->AddChildView(v1); | |
858 | |
859 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); | |
860 HitTestView* v2 = new HitTestView(true); | |
861 v2->SetBoundsRect(v2_bounds); | |
862 root_view->AddChildView(v2); | |
863 | |
864 gfx::Point v1_centerpoint = v1_bounds.CenterPoint(); | |
865 gfx::Point v2_centerpoint = v2_bounds.CenterPoint(); | |
866 gfx::Point v1_origin = v1_bounds.origin(); | |
867 gfx::Point v2_origin = v2_bounds.origin(); | |
868 | |
869 gfx::Rect r1(10, 10, 110, 15); | |
870 gfx::Rect r2(106, 1, 98, 98); | |
871 gfx::Rect r3(0, 0, 300, 300); | |
872 gfx::Rect r4(115, 342, 200, 10); | |
873 | |
874 // Test HitTestPoint | |
875 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint))); | |
876 EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint))); | |
877 | |
878 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin))); | |
879 EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin))); | |
880 | |
881 // Test HitTestRect | |
882 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1))); | |
883 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1))); | |
884 | |
885 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2))); | |
886 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2))); | |
887 | |
888 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3))); | |
889 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3))); | |
890 | |
891 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4))); | |
892 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4))); | |
893 | |
894 // Test GetEventHandlerForPoint | |
895 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint)); | |
896 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); | |
897 | |
898 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); | |
899 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); | |
900 | |
901 // Test GetTooltipHandlerForPoint | |
902 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_centerpoint)); | |
903 EXPECT_EQ(v2, root_view->GetTooltipHandlerForPoint(v2_centerpoint)); | |
904 | |
905 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); | |
906 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); | |
907 | |
908 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); | |
909 | |
910 widget->CloseNow(); | |
911 } | |
912 | |
913 // Tests the correctness of the rect-based targeting algorithm implemented in | 803 // Tests the correctness of the rect-based targeting algorithm implemented in |
914 // View::GetEventHandlerForRect(). See http://goo.gl/3Jp2BD for a description | 804 // View::GetEventHandlerForRect(). See http://goo.gl/3Jp2BD for a description |
915 // of rect-based targeting. | 805 // of rect-based targeting. |
916 TEST_F(ViewTest, GetEventHandlerForRect) { | 806 TEST_F(ViewTest, GetEventHandlerForRect) { |
917 Widget* widget = new Widget; | 807 Widget* widget = new Widget; |
918 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 808 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
919 widget->Init(params); | 809 widget->Init(params); |
920 View* root_view = widget->GetRootView(); | 810 View* root_view = widget->GetRootView(); |
921 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); | 811 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); |
922 | 812 |
(...skipping 3041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3964 // notification. | 3854 // notification. |
3965 TestView* test_view_child_2 = new TestView(); | 3855 TestView* test_view_child_2 = new TestView(); |
3966 test_view->AddChildView(test_view_child_2); | 3856 test_view->AddChildView(test_view_child_2); |
3967 EXPECT_TRUE(test_view_child_2->native_theme_); | 3857 EXPECT_TRUE(test_view_child_2->native_theme_); |
3968 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3858 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3969 | 3859 |
3970 widget->CloseNow(); | 3860 widget->CloseNow(); |
3971 } | 3861 } |
3972 | 3862 |
3973 } // namespace views | 3863 } // namespace views |
OLD | NEW |