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

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

Powered by Google App Engine
This is Rietveld 408576698