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

Side by Side Diff: ui/views/view_unittest.cc

Issue 10827198: Change View::HitTest to View::HitTestRect (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed errors reported by trybots Created 8 years, 4 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 unified diff | Download patch
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/window/non_client_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 937
938 DISALLOW_COPY_AND_ASSIGN(HitTestView); 938 DISALLOW_COPY_AND_ASSIGN(HitTestView);
939 }; 939 };
940 940
941 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) { 941 gfx::Point ConvertPointToView(View* view, const gfx::Point& p) {
942 gfx::Point tmp(p); 942 gfx::Point tmp(p);
943 View::ConvertPointToView(view->GetWidget()->GetRootView(), view, &tmp); 943 View::ConvertPointToView(view->GetWidget()->GetRootView(), view, &tmp);
944 return tmp; 944 return tmp;
945 } 945 }
946 946
947 gfx::Rect ConvertRectToView(View* view, const gfx::Rect& r) {
948 gfx::Rect tmp(r);
949 tmp.set_origin(ConvertPointToView(view, r.origin()));
950 return tmp;
951 }
952
947 void RotateCounterclockwise(ui::Transform* transform) { 953 void RotateCounterclockwise(ui::Transform* transform) {
948 transform->matrix().set3x3(0, -1, 0, 954 transform->matrix().set3x3(0, -1, 0,
949 1, 0, 0, 955 1, 0, 0,
950 0, 0, 1); 956 0, 0, 1);
951 } 957 }
952 958
953 void RotateClockwise(ui::Transform* transform) { 959 void RotateClockwise(ui::Transform* transform) {
954 transform->matrix().set3x3( 0, 1, 0, 960 transform->matrix().set3x3( 0, 1, 0,
955 -1, 0, 0, 961 -1, 0, 0,
956 0, 0, 1); 962 0, 0, 1);
(...skipping 15 matching lines...) Expand all
972 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); 978 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100);
973 HitTestView* v2 = new HitTestView(true); 979 HitTestView* v2 = new HitTestView(true);
974 v2->SetBoundsRect(v2_bounds); 980 v2->SetBoundsRect(v2_bounds);
975 root_view->AddChildView(v2); 981 root_view->AddChildView(v2);
976 982
977 gfx::Point v1_centerpoint = v1_bounds.CenterPoint(); 983 gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
978 gfx::Point v2_centerpoint = v2_bounds.CenterPoint(); 984 gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
979 gfx::Point v1_origin = v1_bounds.origin(); 985 gfx::Point v1_origin = v1_bounds.origin();
980 gfx::Point v2_origin = v2_bounds.origin(); 986 gfx::Point v2_origin = v2_bounds.origin();
981 987
982 // Test HitTest 988 gfx::Rect r1(10, 10, 110, 15);
983 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_centerpoint))); 989 gfx::Rect r2(106, 1, 98, 98);
984 EXPECT_TRUE(v2->HitTest(ConvertPointToView(v2, v2_centerpoint))); 990 gfx::Rect r3(0, 0, 300, 300);
991 gfx::Rect r4(115, 342, 200, 10);
985 992
986 EXPECT_TRUE(v1->HitTest(ConvertPointToView(v1, v1_origin))); 993 // Test HitTestPoint
987 EXPECT_FALSE(v2->HitTest(ConvertPointToView(v2, v2_origin))); 994 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_centerpoint)));
995 EXPECT_TRUE(v2->HitTestPoint(ConvertPointToView(v2, v2_centerpoint)));
996
997 EXPECT_TRUE(v1->HitTestPoint(ConvertPointToView(v1, v1_origin)));
998 EXPECT_FALSE(v2->HitTestPoint(ConvertPointToView(v2, v2_origin)));
999
1000 // Test HitTestRect
1001 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r1)));
1002 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r1)));
1003
1004 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r2)));
1005 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r2)));
1006
1007 EXPECT_TRUE(v1->HitTestRect(ConvertRectToView(v1, r3)));
1008 EXPECT_TRUE(v2->HitTestRect(ConvertRectToView(v2, r3)));
1009
1010 EXPECT_FALSE(v1->HitTestRect(ConvertRectToView(v1, r4)));
1011 EXPECT_FALSE(v2->HitTestRect(ConvertRectToView(v2, r4)));
988 1012
989 // Test GetEventHandlerForPoint 1013 // Test GetEventHandlerForPoint
990 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint)); 1014 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_centerpoint));
991 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); 1015 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint));
1016
992 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); 1017 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin));
993 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); 1018 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin));
994 1019
995 widget->CloseNow(); 1020 widget->CloseNow();
996 } 1021 }
997 1022
998 TEST_F(ViewTest, NotifyEnterExitOnChild) { 1023 TEST_F(ViewTest, NotifyEnterExitOnChild) {
999 Widget* widget = new Widget; 1024 Widget* widget = new Widget;
1000 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); 1025 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP));
1001 View* root_view = widget->GetRootView(); 1026 View* root_view = widget->GetRootView();
(...skipping 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 // Set to non default value. 3360 // Set to non default value.
3336 v->layer()->set_scale_content(false); 3361 v->layer()->set_scale_content(false);
3337 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3362 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3338 ui::Layer* new_layer = v->layer(); 3363 ui::Layer* new_layer = v->layer();
3339 EXPECT_FALSE(new_layer->scale_content()); 3364 EXPECT_FALSE(new_layer->scale_content());
3340 } 3365 }
3341 3366
3342 #endif // USE_AURA 3367 #endif // USE_AURA
3343 3368
3344 } // namespace views 3369 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/window/non_client_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698