| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/views/controls/native/native_view_host_aura.h" | 5 #include "ui/views/controls/native/native_view_host_aura.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // Test that the fast resize path places the clipping and content windows were | 177 // Test that the fast resize path places the clipping and content windows were |
| 178 // they are supposed to be. | 178 // they are supposed to be. |
| 179 TEST_F(NativeViewHostAuraTest, FastResizePath) { | 179 TEST_F(NativeViewHostAuraTest, FastResizePath) { |
| 180 CreateHost(); | 180 CreateHost(); |
| 181 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); | 181 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); |
| 182 | 182 |
| 183 // Without fast resize, the clipping window should size to the native view | 183 // Without fast resize, the clipping window should size to the native view |
| 184 // with the native view positioned at the origin of the clipping window and | 184 // with the native view positioned at the origin of the clipping window and |
| 185 // the clipping window positioned where the native view was requested. | 185 // the clipping window positioned where the native view was requested. |
| 186 host()->set_fast_resize(false); | 186 host()->set_fast_resize(false); |
| 187 native_host()->ShowWidget(5, 10, 100, 100); | 187 native_host()->ShowWidget(5, 10, 100, 100, 100, 100); |
| 188 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | 188 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 189 host()->native_view()->bounds().ToString()); | 189 host()->native_view()->bounds().ToString()); |
| 190 EXPECT_EQ(gfx::Rect(5, 10, 100, 100).ToString(), | 190 EXPECT_EQ(gfx::Rect(5, 10, 100, 100).ToString(), |
| 191 clipping_window()->bounds().ToString()); | 191 clipping_window()->bounds().ToString()); |
| 192 | 192 |
| 193 // With fast resize, the native view should remain the same size but be | 193 // With fast resize, the native view should remain the same size but be |
| 194 // clipped the requested size. | 194 // clipped the requested size. |
| 195 host()->set_fast_resize(true); | 195 host()->set_fast_resize(true); |
| 196 native_host()->ShowWidget(10, 25, 50, 50); | 196 native_host()->ShowWidget(10, 25, 50, 50, 50, 50); |
| 197 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | 197 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 198 host()->native_view()->bounds().ToString()); | 198 host()->native_view()->bounds().ToString()); |
| 199 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), | 199 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), |
| 200 clipping_window()->bounds().ToString()); | 200 clipping_window()->bounds().ToString()); |
| 201 | 201 |
| 202 // Turning off fast resize should make the native view start resizing again. | 202 // Turning off fast resize should make the native view start resizing again. |
| 203 host()->set_fast_resize(false); | 203 host()->set_fast_resize(false); |
| 204 native_host()->ShowWidget(10, 25, 50, 50); | 204 native_host()->ShowWidget(10, 25, 50, 50, 50, 50); |
| 205 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), | 205 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), |
| 206 host()->native_view()->bounds().ToString()); | 206 host()->native_view()->bounds().ToString()); |
| 207 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), | 207 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), |
| 208 clipping_window()->bounds().ToString()); | 208 clipping_window()->bounds().ToString()); |
| 209 | 209 |
| 210 DestroyHost(); | 210 DestroyHost(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Test that the clipping and content windows' bounds are set to the correct |
| 214 // values while the rendering size is not equal to the View size. During fast |
| 215 // resize, the size and transform of the NativeView should not be modified. |
| 216 TEST_F(NativeViewHostAuraTest, BoundsWhileScaling) { |
| 217 CreateHost(); |
| 218 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); |
| 219 EXPECT_EQ(gfx::Transform(), host()->native_view()->transform()); |
| 220 |
| 221 // Without fast resize, the clipping window should size to the native view |
| 222 // with the native view positioned at the origin of the clipping window and |
| 223 // the clipping window positioned where the native view was requested. The |
| 224 // size of the native view should be 200x200 (so it's content will be |
| 225 // shown at half-size). |
| 226 host()->set_fast_resize(false); |
| 227 native_host()->ShowWidget(5, 10, 100, 100, 200, 200); |
| 228 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), |
| 229 host()->native_view()->bounds().ToString()); |
| 230 EXPECT_EQ(gfx::Rect(5, 10, 100, 100).ToString(), |
| 231 clipping_window()->bounds().ToString()); |
| 232 gfx::Transform expected_transform; |
| 233 expected_transform.Scale(0.5, 0.5); |
| 234 EXPECT_EQ(expected_transform, host()->native_view()->transform()); |
| 235 |
| 236 // With fast resize, the native view should remain the same size but be |
| 237 // clipped the requested size. Also, its transform should not be changed. |
| 238 host()->set_fast_resize(true); |
| 239 native_host()->ShowWidget(10, 25, 50, 50, 200, 200); |
| 240 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), |
| 241 host()->native_view()->bounds().ToString()); |
| 242 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), |
| 243 clipping_window()->bounds().ToString()); |
| 244 EXPECT_EQ(expected_transform, host()->native_view()->transform()); |
| 245 |
| 246 // Turning off fast resize should make the native view start resizing again, |
| 247 // and its transform modified to show at the new quarter-size. |
| 248 host()->set_fast_resize(false); |
| 249 native_host()->ShowWidget(10, 25, 50, 50, 200, 200); |
| 250 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), |
| 251 host()->native_view()->bounds().ToString()); |
| 252 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), |
| 253 clipping_window()->bounds().ToString()); |
| 254 expected_transform = gfx::Transform(); |
| 255 expected_transform.Scale(0.25, 0.25); |
| 256 EXPECT_EQ(expected_transform, host()->native_view()->transform()); |
| 257 |
| 258 // When the NativeView is detached, its original transform should be restored. |
| 259 auto* const detached_view = host()->native_view(); |
| 260 host()->Detach(); |
| 261 EXPECT_EQ(gfx::Transform(), detached_view->transform()); |
| 262 // Attach it again so it's torn down with everything else at the end. |
| 263 host()->Attach(detached_view); |
| 264 |
| 265 DestroyHost(); |
| 266 } |
| 267 |
| 213 // Test installing and uninstalling a clip. | 268 // Test installing and uninstalling a clip. |
| 214 TEST_F(NativeViewHostAuraTest, InstallClip) { | 269 TEST_F(NativeViewHostAuraTest, InstallClip) { |
| 215 CreateHost(); | 270 CreateHost(); |
| 216 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); | 271 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); |
| 217 | 272 |
| 218 // Without a clip, the clipping window should always be positioned at the | 273 // Without a clip, the clipping window should always be positioned at the |
| 219 // requested coordinates with the native view positioned at the origin of the | 274 // requested coordinates with the native view positioned at the origin of the |
| 220 // clipping window. | 275 // clipping window. |
| 221 native_host()->ShowWidget(10, 20, 100, 100); | 276 native_host()->ShowWidget(10, 20, 100, 100, 100, 100); |
| 222 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | 277 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 223 host()->native_view()->bounds().ToString()); | 278 host()->native_view()->bounds().ToString()); |
| 224 EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(), | 279 EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(), |
| 225 clipping_window()->bounds().ToString()); | 280 clipping_window()->bounds().ToString()); |
| 226 | 281 |
| 227 // Clip to the bottom right quarter of the native view. | 282 // Clip to the bottom right quarter of the native view. |
| 228 native_host()->InstallClip(60, 70, 50, 50); | 283 native_host()->InstallClip(60, 70, 50, 50); |
| 229 native_host()->ShowWidget(10, 20, 100, 100); | 284 native_host()->ShowWidget(10, 20, 100, 100, 100, 100); |
| 230 EXPECT_EQ(gfx::Rect(-50, -50, 100, 100).ToString(), | 285 EXPECT_EQ(gfx::Rect(-50, -50, 100, 100).ToString(), |
| 231 host()->native_view()->bounds().ToString()); | 286 host()->native_view()->bounds().ToString()); |
| 232 EXPECT_EQ(gfx::Rect(60, 70, 50, 50).ToString(), | 287 EXPECT_EQ(gfx::Rect(60, 70, 50, 50).ToString(), |
| 233 clipping_window()->bounds().ToString()); | 288 clipping_window()->bounds().ToString()); |
| 234 | 289 |
| 235 // Clip to the center of the native view. | 290 // Clip to the center of the native view. |
| 236 native_host()->InstallClip(35, 45, 50, 50); | 291 native_host()->InstallClip(35, 45, 50, 50); |
| 237 native_host()->ShowWidget(10, 20, 100, 100); | 292 native_host()->ShowWidget(10, 20, 100, 100, 100, 100); |
| 238 EXPECT_EQ(gfx::Rect(-25, -25, 100, 100).ToString(), | 293 EXPECT_EQ(gfx::Rect(-25, -25, 100, 100).ToString(), |
| 239 host()->native_view()->bounds().ToString()); | 294 host()->native_view()->bounds().ToString()); |
| 240 EXPECT_EQ(gfx::Rect(35, 45, 50, 50).ToString(), | 295 EXPECT_EQ(gfx::Rect(35, 45, 50, 50).ToString(), |
| 241 clipping_window()->bounds().ToString()); | 296 clipping_window()->bounds().ToString()); |
| 242 | 297 |
| 243 // Uninstalling the clip should make the clipping window match the native view | 298 // Uninstalling the clip should make the clipping window match the native view |
| 244 // again. | 299 // again. |
| 245 native_host()->UninstallClip(); | 300 native_host()->UninstallClip(); |
| 246 native_host()->ShowWidget(10, 20, 100, 100); | 301 native_host()->ShowWidget(10, 20, 100, 100, 100, 100); |
| 247 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | 302 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), |
| 248 host()->native_view()->bounds().ToString()); | 303 host()->native_view()->bounds().ToString()); |
| 249 EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(), | 304 EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(), |
| 250 clipping_window()->bounds().ToString()); | 305 clipping_window()->bounds().ToString()); |
| 251 | 306 |
| 252 DestroyHost(); | 307 DestroyHost(); |
| 253 } | 308 } |
| 254 | 309 |
| 255 // Ensure native view is parented to the root window after detaching. This is | 310 // Ensure native view is parented to the root window after detaching. This is |
| 256 // a regression test for http://crbug.com/389261. | 311 // a regression test for http://crbug.com/389261. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 285 ASSERT_EQ(1u, test_observer.events().size()); | 340 ASSERT_EQ(1u, test_observer.events().size()); |
| 286 EXPECT_EQ(NativeViewHostWindowObserver::EVENT_DESTROYED, | 341 EXPECT_EQ(NativeViewHostWindowObserver::EVENT_DESTROYED, |
| 287 test_observer.events().back().type); | 342 test_observer.events().back().type); |
| 288 } | 343 } |
| 289 | 344 |
| 290 // Ensure the clipping window is hidden before setting the native view's bounds. | 345 // Ensure the clipping window is hidden before setting the native view's bounds. |
| 291 // This is a regression test for http://crbug.com/388699. | 346 // This is a regression test for http://crbug.com/388699. |
| 292 TEST_F(NativeViewHostAuraTest, RemoveClippingWindowOrder) { | 347 TEST_F(NativeViewHostAuraTest, RemoveClippingWindowOrder) { |
| 293 CreateHost(); | 348 CreateHost(); |
| 294 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); | 349 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); |
| 295 native_host()->ShowWidget(10, 20, 100, 100); | 350 native_host()->ShowWidget(10, 20, 100, 100, 100, 100); |
| 296 | 351 |
| 297 NativeViewHostWindowObserver test_observer; | 352 NativeViewHostWindowObserver test_observer; |
| 298 clipping_window()->AddObserver(&test_observer); | 353 clipping_window()->AddObserver(&test_observer); |
| 299 | 354 |
| 300 aura::Window* child_win = child()->GetNativeView(); | 355 aura::Window* child_win = child()->GetNativeView(); |
| 301 child_win->AddObserver(&test_observer); | 356 child_win->AddObserver(&test_observer); |
| 302 | 357 |
| 303 host()->Detach(); | 358 host()->Detach(); |
| 304 | 359 |
| 305 ASSERT_EQ(3u, test_observer.events().size()); | 360 ASSERT_EQ(3u, test_observer.events().size()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 425 |
| 371 host()->SetVisible(false); | 426 host()->SetVisible(false); |
| 372 EXPECT_FALSE(clipping_window()->IsVisible()); | 427 EXPECT_FALSE(clipping_window()->IsVisible()); |
| 373 EXPECT_FALSE(child()->IsVisible()); | 428 EXPECT_FALSE(child()->IsVisible()); |
| 374 | 429 |
| 375 DestroyHost(); | 430 DestroyHost(); |
| 376 DestroyTopLevel(); | 431 DestroyTopLevel(); |
| 377 } | 432 } |
| 378 | 433 |
| 379 } // namespace views | 434 } // namespace views |
| OLD | NEW |