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

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

Issue 11418040: gfx::Transform API clean-up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | 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 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 2051
2052 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2052 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2053 v1->ClearScheduledPaintRect(); 2053 v1->ClearScheduledPaintRect();
2054 v2->SchedulePaint(); 2054 v2->SchedulePaint();
2055 2055
2056 EXPECT_EQ(gfx::Rect(100, 100, 200, 100), v1->scheduled_paint_rect()); 2056 EXPECT_EQ(gfx::Rect(100, 100, 200, 100), v1->scheduled_paint_rect());
2057 2057
2058 // Rotate |v1| counter-clockwise. 2058 // Rotate |v1| counter-clockwise.
2059 gfx::Transform transform; 2059 gfx::Transform transform;
2060 RotateCounterclockwise(&transform); 2060 RotateCounterclockwise(&transform);
2061 transform.SetTranslateY(500.0f); 2061 transform.matrix().set(1, 3, 500.0);
2062 v1->SetTransform(transform); 2062 v1->SetTransform(transform);
2063 2063
2064 // |v2| now occupies (100, 200) to (200, 400) in |root|. 2064 // |v2| now occupies (100, 200) to (200, 400) in |root|.
2065 2065
2066 v1->ClearScheduledPaintRect(); 2066 v1->ClearScheduledPaintRect();
2067 v2->SchedulePaint(); 2067 v2->SchedulePaint();
2068 2068
2069 EXPECT_EQ(gfx::Rect(100, 200, 100, 200), v1->scheduled_paint_rect()); 2069 EXPECT_EQ(gfx::Rect(100, 200, 100, 200), v1->scheduled_paint_rect());
2070 2070
2071 widget->CloseNow(); 2071 widget->CloseNow();
(...skipping 13 matching lines...) Expand all
2085 View* root = widget->GetRootView(); 2085 View* root = widget->GetRootView();
2086 2086
2087 root->AddChildView(v1); 2087 root->AddChildView(v1);
2088 v1->AddChildView(v2); 2088 v1->AddChildView(v2);
2089 2089
2090 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. 2090 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|.
2091 2091
2092 // Rotate |v1| counter-clockwise. 2092 // Rotate |v1| counter-clockwise.
2093 gfx::Transform transform(v1->GetTransform()); 2093 gfx::Transform transform(v1->GetTransform());
2094 RotateCounterclockwise(&transform); 2094 RotateCounterclockwise(&transform);
2095 transform.SetTranslateY(500.0f); 2095 transform.matrix().set(1, 3, 500.0);
2096 v1->SetTransform(transform); 2096 v1->SetTransform(transform);
2097 2097
2098 // |v2| now occupies (100, 200) to (200, 400) in |root|. 2098 // |v2| now occupies (100, 200) to (200, 400) in |root|.
2099 v1->Reset(); 2099 v1->Reset();
2100 v2->Reset(); 2100 v2->Reset();
2101 2101
2102 gfx::Point p1(110, 210); 2102 gfx::Point p1(110, 210);
2103 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1, 2103 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1,
2104 ui::EF_LEFT_MOUSE_BUTTON); 2104 ui::EF_LEFT_MOUSE_BUTTON);
2105 root->OnMousePressed(pressed); 2105 root->OnMousePressed(pressed);
2106 EXPECT_EQ(0, v1->last_mouse_event_type_); 2106 EXPECT_EQ(0, v1->last_mouse_event_type_);
2107 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 2107 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
2108 EXPECT_EQ(190, v2->location_.x()); 2108 EXPECT_EQ(190, v2->location_.x());
2109 EXPECT_EQ(10, v2->location_.y()); 2109 EXPECT_EQ(10, v2->location_.y());
2110 2110
2111 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0); 2111 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0);
2112 root->OnMouseReleased(released); 2112 root->OnMouseReleased(released);
2113 2113
2114 // Now rotate |v2| inside |v1| clockwise. 2114 // Now rotate |v2| inside |v1| clockwise.
2115 transform = v2->GetTransform(); 2115 transform = v2->GetTransform();
2116 RotateClockwise(&transform); 2116 RotateClockwise(&transform);
2117 transform.SetTranslateX(100.0f); 2117 transform.matrix().setDouble(0, 3, 100.0);
2118 v2->SetTransform(transform); 2118 v2->SetTransform(transform);
2119 2119
2120 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to 2120 // Now, |v2| occupies (100, 100) to (200, 300) in |v1|, and (100, 300) to
2121 // (300, 400) in |root|. 2121 // (300, 400) in |root|.
2122 2122
2123 v1->Reset(); 2123 v1->Reset();
2124 v2->Reset(); 2124 v2->Reset();
2125 2125
2126 gfx::Point point2(110, 320); 2126 gfx::Point point2(110, 320);
2127 ui::MouseEvent p2(ui::ET_MOUSE_PRESSED, point2, point2, 2127 ui::MouseEvent p2(ui::ET_MOUSE_PRESSED, point2, point2,
2128 ui::EF_LEFT_MOUSE_BUTTON); 2128 ui::EF_LEFT_MOUSE_BUTTON);
2129 root->OnMousePressed(p2); 2129 root->OnMousePressed(p2);
2130 EXPECT_EQ(0, v1->last_mouse_event_type_); 2130 EXPECT_EQ(0, v1->last_mouse_event_type_);
2131 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_); 2131 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v2->last_mouse_event_type_);
2132 EXPECT_EQ(10, v2->location_.x()); 2132 EXPECT_EQ(10, v2->location_.x());
2133 EXPECT_EQ(20, v2->location_.y()); 2133 EXPECT_EQ(20, v2->location_.y());
2134 2134
2135 root->OnMouseReleased(released); 2135 root->OnMouseReleased(released);
2136 2136
2137 v1->SetTransform(gfx::Transform()); 2137 v1->SetTransform(gfx::Transform());
2138 v2->SetTransform(gfx::Transform()); 2138 v2->SetTransform(gfx::Transform());
2139 2139
2140 TestView* v3 = new TestView(); 2140 TestView* v3 = new TestView();
2141 v3->SetBoundsRect(gfx::Rect(10, 10, 20, 30)); 2141 v3->SetBoundsRect(gfx::Rect(10, 10, 20, 30));
2142 v2->AddChildView(v3); 2142 v2->AddChildView(v3);
2143 2143
2144 // Rotate |v3| clockwise with respect to |v2|. 2144 // Rotate |v3| clockwise with respect to |v2|.
2145 transform = v1->GetTransform(); 2145 transform = v1->GetTransform();
2146 RotateClockwise(&transform); 2146 RotateClockwise(&transform);
2147 transform.SetTranslateX(30.0f); 2147 transform.matrix().setDouble(0, 3, 30.0);
2148 v3->SetTransform(transform); 2148 v3->SetTransform(transform);
2149 2149
2150 // Scale |v2| with respect to |v1| along both axis. 2150 // Scale |v2| with respect to |v1| along both axis.
2151 transform = v2->GetTransform(); 2151 transform = v2->GetTransform();
2152 transform.SetScale(0.8f, 0.5f); 2152 transform.matrix().setDouble(0, 0, 0.8);
2153 transform.matrix().setDouble(1, 1, 0.5);
2153 v2->SetTransform(transform); 2154 v2->SetTransform(transform);
2154 2155
2155 // |v3| occupies (108, 105) to (132, 115) in |root|. 2156 // |v3| occupies (108, 105) to (132, 115) in |root|.
2156 2157
2157 v1->Reset(); 2158 v1->Reset();
2158 v2->Reset(); 2159 v2->Reset();
2159 v3->Reset(); 2160 v3->Reset();
2160 2161
2161 gfx::Point point(112, 110); 2162 gfx::Point point(112, 110);
2162 ui::MouseEvent p3(ui::ET_MOUSE_PRESSED, point, point, 2163 ui::MouseEvent p3(ui::ET_MOUSE_PRESSED, point, point,
(...skipping 10 matching lines...) Expand all
2173 v2->SetTransform(gfx::Transform()); 2174 v2->SetTransform(gfx::Transform());
2174 v3->SetTransform(gfx::Transform()); 2175 v3->SetTransform(gfx::Transform());
2175 2176
2176 v1->Reset(); 2177 v1->Reset();
2177 v2->Reset(); 2178 v2->Reset();
2178 v3->Reset(); 2179 v3->Reset();
2179 2180
2180 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis. 2181 // Rotate |v3| clockwise with respect to |v2|, and scale it along both axis.
2181 transform = v3->GetTransform(); 2182 transform = v3->GetTransform();
2182 RotateClockwise(&transform); 2183 RotateClockwise(&transform);
2183 transform.SetTranslateX(30.0f); 2184 transform.matrix().setDouble(0, 3, 30.0);
2184 // Rotation sets some scaling transformation. Using SetScale would overwrite 2185 // Rotation sets some scaling transformation. Using SetScale would overwrite
2185 // that and pollute the rotation. So combine the scaling with the existing 2186 // that and pollute the rotation. So combine the scaling with the existing
2186 // transforamtion. 2187 // transforamtion.
2187 transform.ConcatScale(0.8f, 0.5f); 2188 gfx::Transform scale;
2189 scale.Scale(0.8, 0.5);
2190 transform.ConcatTransform(scale);
2188 v3->SetTransform(transform); 2191 v3->SetTransform(transform);
2189 2192
2190 // Translate |v2| with respect to |v1|. 2193 // Translate |v2| with respect to |v1|.
2191 transform = v2->GetTransform(); 2194 transform = v2->GetTransform();
2192 transform.SetTranslate(10, 10); 2195 transform.matrix().setDouble(0, 3, 10.0);
2196 transform.matrix().setDouble(1, 3, 10.0);
2193 v2->SetTransform(transform); 2197 v2->SetTransform(transform);
2194 2198
2195 // |v3| now occupies (120, 120) to (144, 130) in |root|. 2199 // |v3| now occupies (120, 120) to (144, 130) in |root|.
2196 2200
2197 gfx::Point point3(124, 125); 2201 gfx::Point point3(124, 125);
2198 ui::MouseEvent p4(ui::ET_MOUSE_PRESSED, point3, point3, 2202 ui::MouseEvent p4(ui::ET_MOUSE_PRESSED, point3, point3,
2199 ui::EF_LEFT_MOUSE_BUTTON); 2203 ui::EF_LEFT_MOUSE_BUTTON);
2200 root->OnMousePressed(p4); 2204 root->OnMousePressed(p4);
2201 2205
2202 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_); 2206 EXPECT_EQ(ui::ET_MOUSE_PRESSED, v3->last_mouse_event_type_);
(...skipping 23 matching lines...) Expand all
2226 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); 2230 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200));
2227 2231
2228 View* child = new View; 2232 View* child = new View;
2229 contents->AddChildView(child); 2233 contents->AddChildView(child);
2230 child->SetBoundsRect(gfx::Rect(10, 90, 50, 50)); 2234 child->SetBoundsRect(gfx::Rect(10, 90, 50, 50));
2231 EXPECT_EQ(gfx::Rect(0, 0, 50, 10), child->GetVisibleBounds()); 2235 EXPECT_EQ(gfx::Rect(0, 0, 50, 10), child->GetVisibleBounds());
2232 2236
2233 // Rotate |child| counter-clockwise 2237 // Rotate |child| counter-clockwise
2234 gfx::Transform transform; 2238 gfx::Transform transform;
2235 RotateCounterclockwise(&transform); 2239 RotateCounterclockwise(&transform);
2236 transform.SetTranslateY(50.0f); 2240 transform.matrix().setDouble(1, 3, 50.0);
2237 child->SetTransform(transform); 2241 child->SetTransform(transform);
2238 EXPECT_EQ(gfx::Rect(40, 0, 10, 50), child->GetVisibleBounds()); 2242 EXPECT_EQ(gfx::Rect(40, 0, 10, 50), child->GetVisibleBounds());
2239 2243
2240 widget->CloseNow(); 2244 widget->CloseNow();
2241 } 2245 }
2242 2246
2243 //////////////////////////////////////////////////////////////////////////////// 2247 ////////////////////////////////////////////////////////////////////////////////
2244 // OnVisibleBoundsChanged() 2248 // OnVisibleBoundsChanged()
2245 2249
2246 class VisibleBoundsView : public View { 2250 class VisibleBoundsView : public View {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 TestView* child = new TestView; 2344 TestView* child = new TestView;
2341 TestView* child_child = new TestView; 2345 TestView* child_child = new TestView;
2342 2346
2343 top_view.AddChildView(child); 2347 top_view.AddChildView(child);
2344 child->AddChildView(child_child); 2348 child->AddChildView(child_child);
2345 2349
2346 top_view.SetBoundsRect(gfx::Rect(0, 0, 1000, 1000)); 2350 top_view.SetBoundsRect(gfx::Rect(0, 0, 1000, 1000));
2347 2351
2348 child->SetBoundsRect(gfx::Rect(7, 19, 500, 500)); 2352 child->SetBoundsRect(gfx::Rect(7, 19, 500, 500));
2349 gfx::Transform transform; 2353 gfx::Transform transform;
2350 transform.SetScale(3.0f, 4.0f); 2354 transform.Scale(3.0, 4.0);
2351 child->SetTransform(transform); 2355 child->SetTransform(transform);
2352 2356
2353 child_child->SetBoundsRect(gfx::Rect(17, 13, 100, 100)); 2357 child_child->SetBoundsRect(gfx::Rect(17, 13, 100, 100));
2354 transform = gfx::Transform(); 2358 transform.MakeIdentity();
2355 transform.SetScale(5.0f, 7.0f); 2359 transform.Scale(5.0, 7.0);
2356 child_child->SetTransform(transform); 2360 child_child->SetTransform(transform);
2357 2361
2358 // Sanity check to make sure basic transforms act as expected. 2362 // Sanity check to make sure basic transforms act as expected.
2359 { 2363 {
2360 gfx::Transform transform; 2364 gfx::Transform transform;
2361 transform.ConcatTranslate(1, 1); 2365 transform.Translate(110.0, -110.0);
2362 transform.ConcatScale(100, 55); 2366 transform.Scale(100.0, 55.0);
2363 transform.ConcatTranslate(110, -110); 2367 transform.Translate(1.0, 1.0);
2364 2368
2365 // convert to a 3x3 matrix. 2369 // convert to a 3x3 matrix.
2366 const SkMatrix& matrix = transform.matrix(); 2370 const SkMatrix& matrix = transform.matrix();
2367 2371
2368 EXPECT_EQ(210, matrix.getTranslateX()); 2372 EXPECT_EQ(210, matrix.getTranslateX());
2369 EXPECT_EQ(-55, matrix.getTranslateY()); 2373 EXPECT_EQ(-55, matrix.getTranslateY());
2370 EXPECT_EQ(100, matrix.getScaleX()); 2374 EXPECT_EQ(100, matrix.getScaleX());
2371 EXPECT_EQ(55, matrix.getScaleY()); 2375 EXPECT_EQ(55, matrix.getScaleY());
2372 EXPECT_EQ(0, matrix.getSkewX()); 2376 EXPECT_EQ(0, matrix.getSkewX());
2373 EXPECT_EQ(0, matrix.getSkewY()); 2377 EXPECT_EQ(0, matrix.getSkewY());
2374 } 2378 }
2375 2379
2376 { 2380 {
2377 gfx::Transform transform; 2381 gfx::Transform transform;
2378 transform.SetTranslate(1, 1); 2382 transform.Translate(1.0, 1.0);
2379 gfx::Transform t2; 2383 gfx::Transform t2;
2380 t2.SetScale(100, 55); 2384 t2.Scale(100.0, 55.0);
2381 gfx::Transform t3; 2385 gfx::Transform t3;
2382 t3.SetTranslate(110, -110); 2386 t3.Translate(110.0, -110.0);
2383 transform.ConcatTransform(t2); 2387 transform.ConcatTransform(t2);
2384 transform.ConcatTransform(t3); 2388 transform.ConcatTransform(t3);
2385 2389
2386 // convert to a 3x3 matrix 2390 // convert to a 3x3 matrix
2387 const SkMatrix& matrix = transform.matrix(); 2391 const SkMatrix& matrix = transform.matrix();
2388 2392
2389 EXPECT_EQ(210, matrix.getTranslateX()); 2393 EXPECT_EQ(210, matrix.getTranslateX());
2390 EXPECT_EQ(-55, matrix.getTranslateY()); 2394 EXPECT_EQ(-55, matrix.getTranslateY());
2391 EXPECT_EQ(100, matrix.getScaleX()); 2395 EXPECT_EQ(100, matrix.getScaleX());
2392 EXPECT_EQ(55, matrix.getScaleY()); 2396 EXPECT_EQ(55, matrix.getScaleY());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2461 v2->SetBoundsRect(gfx::Rect(20, 20, 100, 200)); 2465 v2->SetBoundsRect(gfx::Rect(20, 20, 100, 200));
2462 2466
2463 // |v2| now occupies (30, 30) to (130, 230) in |widget| 2467 // |v2| now occupies (30, 30) to (130, 230) in |widget|
2464 gfx::Rect rect(5, 5, 15, 40); 2468 gfx::Rect rect(5, 5, 15, 40);
2465 EXPECT_EQ(gfx::Rect(25, 25, 15, 40), v2->ConvertRectToParent(rect)); 2469 EXPECT_EQ(gfx::Rect(25, 25, 15, 40), v2->ConvertRectToParent(rect));
2466 EXPECT_EQ(gfx::Rect(35, 35, 15, 40), v2->ConvertRectToWidget(rect)); 2470 EXPECT_EQ(gfx::Rect(35, 35, 15, 40), v2->ConvertRectToWidget(rect));
2467 2471
2468 // Rotate |v2| 2472 // Rotate |v2|
2469 gfx::Transform t2; 2473 gfx::Transform t2;
2470 RotateCounterclockwise(&t2); 2474 RotateCounterclockwise(&t2);
2471 t2.SetTranslateY(100.0f); 2475 t2.matrix().setDouble(1, 3, 100.0);
2472 v2->SetTransform(t2); 2476 v2->SetTransform(t2);
2473 2477
2474 // |v2| now occupies (30, 30) to (230, 130) in |widget| 2478 // |v2| now occupies (30, 30) to (230, 130) in |widget|
2475 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect)); 2479 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect));
2476 EXPECT_EQ(gfx::Rect(35, 110, 40, 15), v2->ConvertRectToWidget(rect)); 2480 EXPECT_EQ(gfx::Rect(35, 110, 40, 15), v2->ConvertRectToWidget(rect));
2477 2481
2478 // Scale down |v1| 2482 // Scale down |v1|
2479 gfx::Transform t1; 2483 gfx::Transform t1;
2480 t1.SetScale(0.5, 0.5); 2484 t1.Scale(0.5, 0.5);
2481 v1->SetTransform(t1); 2485 v1->SetTransform(t1);
2482 2486
2483 // The rectangle should remain the same for |v1|. 2487 // The rectangle should remain the same for |v1|.
2484 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect)); 2488 EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect));
2485 2489
2486 // |v2| now occupies (20, 20) to (120, 70) in |widget| 2490 // |v2| now occupies (20, 20) to (120, 70) in |widget|
2487 EXPECT_EQ(gfx::Rect(22, 60, 21, 8).ToString(), 2491 EXPECT_EQ(gfx::Rect(22, 60, 21, 8).ToString(),
2488 v2->ConvertRectToWidget(rect).ToString()); 2492 v2->ConvertRectToWidget(rect).ToString());
2489 2493
2490 widget->CloseNow(); 2494 widget->CloseNow();
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 EXPECT_TRUE(v2->layer() != NULL); 2978 EXPECT_TRUE(v2->layer() != NULL);
2975 EXPECT_EQ(root_layer, v2->layer()->parent()); 2979 EXPECT_EQ(root_layer, v2->layer()->parent());
2976 ASSERT_EQ(1u, root_layer->children().size()); 2980 ASSERT_EQ(1u, root_layer->children().size());
2977 EXPECT_EQ(root_layer->children()[0], v2->layer()); 2981 EXPECT_EQ(root_layer->children()[0], v2->layer());
2978 // The bounds of the layer should have changed to be relative to the root view 2982 // The bounds of the layer should have changed to be relative to the root view
2979 // now. 2983 // now.
2980 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); 2984 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds());
2981 2985
2982 // Make v1 have a layer again and verify v2s layer is wired up correctly. 2986 // Make v1 have a layer again and verify v2s layer is wired up correctly.
2983 gfx::Transform transform; 2987 gfx::Transform transform;
2984 transform.SetScale(2.0f, 2.0f); 2988 transform.Scale(2.0, 2.0);
2985 v1->SetTransform(transform); 2989 v1->SetTransform(transform);
2986 EXPECT_TRUE(v1->layer() != NULL); 2990 EXPECT_TRUE(v1->layer() != NULL);
2987 EXPECT_TRUE(v2->layer() != NULL); 2991 EXPECT_TRUE(v2->layer() != NULL);
2988 EXPECT_EQ(root_layer, v1->layer()->parent()); 2992 EXPECT_EQ(root_layer, v1->layer()->parent());
2989 EXPECT_EQ(v1->layer(), v2->layer()->parent()); 2993 EXPECT_EQ(v1->layer(), v2->layer()->parent());
2990 ASSERT_EQ(1u, root_layer->children().size()); 2994 ASSERT_EQ(1u, root_layer->children().size());
2991 EXPECT_EQ(root_layer->children()[0], v1->layer()); 2995 EXPECT_EQ(root_layer->children()[0], v1->layer());
2992 ASSERT_EQ(1u, v1->layer()->children().size()); 2996 ASSERT_EQ(1u, v1->layer()->children().size());
2993 EXPECT_EQ(v1->layer()->children()[0], v2->layer()); 2997 EXPECT_EQ(v1->layer()->children()[0], v2->layer());
2994 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); 2998 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 EXPECT_EQ(l2bounds, v2->layer()->bounds()); 3130 EXPECT_EQ(l2bounds, v2->layer()->bounds());
3127 3131
3128 // Reset locale. 3132 // Reset locale.
3129 base::i18n::SetICUDefaultLocale(locale); 3133 base::i18n::SetICUDefaultLocale(locale);
3130 } 3134 }
3131 3135
3132 // Makes sure a transform persists after toggling the visibility. 3136 // Makes sure a transform persists after toggling the visibility.
3133 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { 3137 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) {
3134 View* view = new View; 3138 View* view = new View;
3135 gfx::Transform transform; 3139 gfx::Transform transform;
3136 transform.SetScale(2.0f, 2.0f); 3140 transform.Scale(2.0, 2.0);
3137 view->SetTransform(transform); 3141 view->SetTransform(transform);
3138 widget()->SetContentsView(view); 3142 widget()->SetContentsView(view);
3139 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); 3143 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0));
3140 3144
3141 view->SetVisible(false); 3145 view->SetVisible(false);
3142 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); 3146 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0));
3143 3147
3144 view->SetVisible(true); 3148 view->SetVisible(true);
3145 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); 3149 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0));
3146 } 3150 }
3147 3151
3148 // Verifies a transform persists after removing/adding a view with a transform. 3152 // Verifies a transform persists after removing/adding a view with a transform.
3149 TEST_F(ViewLayerTest, ResetTransformOnLayerAfterAdd) { 3153 TEST_F(ViewLayerTest, ResetTransformOnLayerAfterAdd) {
3150 View* view = new View; 3154 View* view = new View;
3151 gfx::Transform transform; 3155 gfx::Transform transform;
3152 transform.SetScale(2.0f, 2.0f); 3156 transform.Scale(2.0, 2.0);
3153 view->SetTransform(transform); 3157 view->SetTransform(transform);
3154 widget()->SetContentsView(view); 3158 widget()->SetContentsView(view);
3155 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0)); 3159 EXPECT_EQ(2.0f, view->GetTransform().matrix().get(0, 0));
3156 ASSERT_TRUE(view->layer() != NULL); 3160 ASSERT_TRUE(view->layer() != NULL);
3157 EXPECT_EQ(2.0f, view->layer()->transform().matrix().get(0, 0)); 3161 EXPECT_EQ(2.0f, view->layer()->transform().matrix().get(0, 0));
3158 3162
3159 View* parent = view->parent(); 3163 View* parent = view->parent();
3160 parent->RemoveChildView(view); 3164 parent->RemoveChildView(view);
3161 parent->AddChildView(view); 3165 parent->AddChildView(view);
3162 3166
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 // Set to non default value. 3391 // Set to non default value.
3388 v->layer()->set_scale_content(false); 3392 v->layer()->set_scale_content(false);
3389 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); 3393 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer());
3390 ui::Layer* new_layer = v->layer(); 3394 ui::Layer* new_layer = v->layer();
3391 EXPECT_FALSE(new_layer->scale_content()); 3395 EXPECT_FALSE(new_layer->scale_content());
3392 } 3396 }
3393 3397
3394 #endif // USE_AURA 3398 #endif // USE_AURA
3395 3399
3396 } // namespace views 3400 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698