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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
35 #include "ui/compositor/scoped_layer_animation_settings.h" | 35 #include "ui/compositor/scoped_layer_animation_settings.h" |
36 #include "ui/compositor/test/test_layers.h" | 36 #include "ui/compositor/test/test_layers.h" |
37 #include "ui/events/event.h" | 37 #include "ui/events/event.h" |
38 #include "ui/events/event_utils.h" | 38 #include "ui/events/event_utils.h" |
39 #include "ui/events/gestures/gesture_configuration.h" | 39 #include "ui/events/gestures/gesture_configuration.h" |
40 #include "ui/events/keycodes/keyboard_codes.h" | 40 #include "ui/events/keycodes/keyboard_codes.h" |
41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
42 #include "ui/gfx/screen.h" | 42 #include "ui/gfx/screen.h" |
| 43 #include "ui/gfx/skia_util.h" |
43 | 44 |
44 DECLARE_WINDOW_PROPERTY_TYPE(const char*) | 45 DECLARE_WINDOW_PROPERTY_TYPE(const char*) |
45 DECLARE_WINDOW_PROPERTY_TYPE(int) | 46 DECLARE_WINDOW_PROPERTY_TYPE(int) |
46 | 47 |
47 namespace aura { | 48 namespace aura { |
48 namespace test { | 49 namespace test { |
49 | 50 |
50 class WindowTest : public AuraTestBase { | 51 class WindowTest : public AuraTestBase { |
51 public: | 52 public: |
52 WindowTest() : max_separation_(0) { | 53 WindowTest() : max_separation_(0) { |
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2872 | 2873 |
2873 // Animate to the end: will *not* notify of the change since we are hidden. | 2874 // Animate to the end: will *not* notify of the change since we are hidden. |
2874 base::TimeTicks start_time = | 2875 base::TimeTicks start_time = |
2875 window->layer()->GetAnimator()->last_step_time(); | 2876 window->layer()->GetAnimator()->last_step_time(); |
2876 gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); | 2877 gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); |
2877 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2878 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
2878 | 2879 |
2879 // No bounds changed notification at the end of animation since layer | 2880 // No bounds changed notification at the end of animation since layer |
2880 // delegate is NULL. | 2881 // delegate is NULL. |
2881 EXPECT_FALSE(delegate.bounds_changed()); | 2882 EXPECT_FALSE(delegate.bounds_changed()); |
2882 EXPECT_NE("0,0 100x100", window->bounds().ToString()); | 2883 EXPECT_NE("0,0 100x100", window->layer()->bounds().ToString()); |
2883 } | 2884 } |
2884 | 2885 |
2885 namespace { | 2886 namespace { |
2886 | 2887 |
2887 // Used by AddChildNotifications to track notification counts. | 2888 // Used by AddChildNotifications to track notification counts. |
2888 class AddChildNotificationsObserver : public WindowObserver { | 2889 class AddChildNotificationsObserver : public WindowObserver { |
2889 public: | 2890 public: |
2890 AddChildNotificationsObserver() : added_count_(0), removed_count_(0) {} | 2891 AddChildNotificationsObserver() : added_count_(0), removed_count_(0) {} |
2891 | 2892 |
2892 std::string CountStringAndReset() { | 2893 std::string CountStringAndReset() { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3178 Window* transient = new Window(&transient_delegate); // Owned by |parent|. | 3179 Window* transient = new Window(&transient_delegate); // Owned by |parent|. |
3179 transient->Init(ui::LAYER_NOT_DRAWN); | 3180 transient->Init(ui::LAYER_NOT_DRAWN); |
3180 parent->AddTransientChild(transient); | 3181 parent->AddTransientChild(transient); |
3181 parent.reset(); | 3182 parent.reset(); |
3182 | 3183 |
3183 ASSERT_EQ(2u, destruction_order.size()); | 3184 ASSERT_EQ(2u, destruction_order.size()); |
3184 EXPECT_EQ("transient", destruction_order[0]); | 3185 EXPECT_EQ("transient", destruction_order[0]); |
3185 EXPECT_EQ("parent", destruction_order[1]); | 3186 EXPECT_EQ("parent", destruction_order[1]); |
3186 } | 3187 } |
3187 | 3188 |
| 3189 // Verifies SchedulePaint() on a layerless window results in damaging the right |
| 3190 // thing. |
| 3191 TEST_F(WindowTest, LayerlessWindowSchedulePaint) { |
| 3192 Window root(NULL); |
| 3193 root.Init(ui::LAYER_NOT_DRAWN); |
| 3194 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 3195 |
| 3196 Window* layerless_window = new Window(NULL); // Owned by |root|. |
| 3197 layerless_window->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3198 layerless_window->SetBounds(gfx::Rect(10, 11, 12, 13)); |
| 3199 root.AddChild(layerless_window); |
| 3200 |
| 3201 root.layer()->SendDamagedRects(); |
| 3202 layerless_window->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); |
| 3203 // Note the the region is clipped by the parent hence 100 going to 11. |
| 3204 EXPECT_EQ("11,13 11x4", |
| 3205 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). |
| 3206 ToString()); |
| 3207 |
| 3208 Window* layerless_window2 = new Window(NULL); // Owned by |layerless_window|. |
| 3209 layerless_window2->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3210 layerless_window2->SetBounds(gfx::Rect(1, 2, 3, 4)); |
| 3211 layerless_window->AddChild(layerless_window2); |
| 3212 |
| 3213 root.layer()->SendDamagedRects(); |
| 3214 layerless_window2->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); |
| 3215 // Note the the region is clipped by the |layerless_window| hence 100 going to |
| 3216 // 2. |
| 3217 EXPECT_EQ("12,15 2x2", |
| 3218 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). |
| 3219 ToString()); |
| 3220 } |
| 3221 |
| 3222 // Verifies bounds of layerless windows are correctly updated when adding |
| 3223 // removing. |
| 3224 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnAddRemove) { |
| 3225 // Creates the following structure (all children owned by root): |
| 3226 // root |
| 3227 // w1ll 1,2 |
| 3228 // w11ll 3,4 |
| 3229 // w111 5,6 |
| 3230 // w12 7,8 |
| 3231 // w121 9,10 |
| 3232 // |
| 3233 // ll: layer less, eg no layer |
| 3234 Window root(NULL); |
| 3235 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3236 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 3237 |
| 3238 Window* w1ll = new Window(NULL); |
| 3239 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3240 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); |
| 3241 |
| 3242 Window* w11ll = new Window(NULL); |
| 3243 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3244 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); |
| 3245 w1ll->AddChild(w11ll); |
| 3246 |
| 3247 Window* w111 = new Window(NULL); |
| 3248 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3249 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
| 3250 w11ll->AddChild(w111); |
| 3251 |
| 3252 Window* w12 = new Window(NULL); |
| 3253 w12->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3254 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); |
| 3255 w1ll->AddChild(w12); |
| 3256 |
| 3257 Window* w121 = new Window(NULL); |
| 3258 w121->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3259 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); |
| 3260 w12->AddChild(w121); |
| 3261 |
| 3262 root.AddChild(w1ll); |
| 3263 |
| 3264 // All layers should be parented to the root. |
| 3265 EXPECT_EQ(root.layer(), w111->layer()->parent()); |
| 3266 EXPECT_EQ(root.layer(), w12->layer()->parent()); |
| 3267 EXPECT_EQ(w12->layer(), w121->layer()->parent()); |
| 3268 |
| 3269 // Ensure bounds are what we expect. |
| 3270 EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString()); |
| 3271 EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString()); |
| 3272 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); |
| 3273 EXPECT_EQ("7,8 100x100", w12->bounds().ToString()); |
| 3274 EXPECT_EQ("9,10 100x100", w121->bounds().ToString()); |
| 3275 |
| 3276 // Bounds of layers are relative to the nearest ancestor with a layer. |
| 3277 EXPECT_EQ("8,10 100x100", w12->layer()->bounds().ToString()); |
| 3278 EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString()); |
| 3279 EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString()); |
| 3280 |
| 3281 // Remove and repeat. |
| 3282 root.RemoveChild(w1ll); |
| 3283 |
| 3284 EXPECT_TRUE(w111->layer()->parent() == NULL); |
| 3285 EXPECT_TRUE(w12->layer()->parent() == NULL); |
| 3286 |
| 3287 // Verify bounds haven't changed again. |
| 3288 EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString()); |
| 3289 EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString()); |
| 3290 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); |
| 3291 EXPECT_EQ("7,8 100x100", w12->bounds().ToString()); |
| 3292 EXPECT_EQ("9,10 100x100", w121->bounds().ToString()); |
| 3293 |
| 3294 // Bounds of layers should now match that of windows. |
| 3295 EXPECT_EQ("7,8 100x100", w12->layer()->bounds().ToString()); |
| 3296 EXPECT_EQ("5,6 100x100", w111->layer()->bounds().ToString()); |
| 3297 EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString()); |
| 3298 |
| 3299 delete w1ll; |
| 3300 } |
| 3301 |
| 3302 // Verifies bounds of layerless windows are correctly updated when bounds |
| 3303 // of ancestor changes. |
| 3304 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnSetBounds) { |
| 3305 // Creates the following structure (all children owned by root): |
| 3306 // root |
| 3307 // w1ll 1,2 |
| 3308 // w11ll 3,4 |
| 3309 // w111 5,6 |
| 3310 // w12 7,8 |
| 3311 // w121 9,10 |
| 3312 // |
| 3313 // ll: layer less, eg no layer |
| 3314 Window root(NULL); |
| 3315 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3316 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 3317 |
| 3318 Window* w1ll = new Window(NULL); |
| 3319 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3320 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); |
| 3321 |
| 3322 Window* w11ll = new Window(NULL); |
| 3323 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); |
| 3324 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); |
| 3325 w1ll->AddChild(w11ll); |
| 3326 |
| 3327 Window* w111 = new Window(NULL); |
| 3328 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3329 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
| 3330 w11ll->AddChild(w111); |
| 3331 |
| 3332 Window* w12 = new Window(NULL); |
| 3333 w12->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3334 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); |
| 3335 w1ll->AddChild(w12); |
| 3336 |
| 3337 Window* w121 = new Window(NULL); |
| 3338 w121->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); |
| 3339 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); |
| 3340 w12->AddChild(w121); |
| 3341 |
| 3342 root.AddChild(w1ll); |
| 3343 |
| 3344 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); |
| 3345 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); |
| 3346 EXPECT_EQ("11,14 11x12", w111->layer()->bounds().ToString()); |
| 3347 |
| 3348 // Set back. |
| 3349 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
| 3350 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); |
| 3351 EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString()); |
| 3352 |
| 3353 // Setting the bounds of a layerless window needs to adjust the bounds of |
| 3354 // layered children. |
| 3355 w11ll->SetBounds(gfx::Rect(5, 6, 100, 100)); |
| 3356 EXPECT_EQ("5,6 100x100", w11ll->bounds().ToString()); |
| 3357 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); |
| 3358 EXPECT_EQ("11,14 100x100", w111->layer()->bounds().ToString()); |
| 3359 |
| 3360 root.RemoveChild(w1ll); |
| 3361 |
| 3362 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); |
| 3363 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); |
| 3364 EXPECT_EQ("7,8 11x12", w111->layer()->bounds().ToString()); |
| 3365 |
| 3366 delete w1ll; |
| 3367 } |
| 3368 |
3188 } // namespace test | 3369 } // namespace test |
3189 } // namespace aura | 3370 } // namespace aura |
OLD | NEW |