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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
23 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
24 #include "ui/views/bubble/bubble_delegate.h" | 24 #include "ui/views/bubble/bubble_delegate.h" |
25 #include "ui/views/controls/textfield/textfield.h" | 25 #include "ui/views/controls/textfield/textfield.h" |
26 #include "ui/views/test/test_views.h" | 26 #include "ui/views/test/test_views.h" |
27 #include "ui/views/test/test_widget_observer.h" | 27 #include "ui/views/test/test_widget_observer.h" |
28 #include "ui/views/test/widget_test.h" | 28 #include "ui/views/test/widget_test.h" |
29 #include "ui/views/widget/native_widget_delegate.h" | 29 #include "ui/views/widget/native_widget_delegate.h" |
30 #include "ui/views/widget/root_view.h" | 30 #include "ui/views/widget/root_view.h" |
31 #include "ui/views/widget/widget_deletion_observer.h" | 31 #include "ui/views/widget/widget_deletion_observer.h" |
| 32 #include "ui/views/widget/widget_removals_observer.h" |
32 #include "ui/views/window/dialog_delegate.h" | 33 #include "ui/views/window/dialog_delegate.h" |
33 #include "ui/views/window/native_frame_view.h" | 34 #include "ui/views/window/native_frame_view.h" |
34 | 35 |
35 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
36 #include "ui/aura/window.h" | 37 #include "ui/aura/window.h" |
37 #include "ui/aura/window_tree_host.h" | 38 #include "ui/aura/window_tree_host.h" |
38 #include "ui/base/view_prop.h" | 39 #include "ui/base/view_prop.h" |
39 #include "ui/base/win/window_event_target.h" | 40 #include "ui/base/win/window_event_target.h" |
40 #include "ui/views/win/hwnd_util.h" | 41 #include "ui/views/win/hwnd_util.h" |
41 #endif | 42 #endif |
(...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 // about the initial scale factor. Fake it. | 3395 // about the initial scale factor. Fake it. |
3395 view->OnDeviceScaleFactorChanged(scale_factor); | 3396 view->OnDeviceScaleFactorChanged(scale_factor); |
3396 EXPECT_EQ(scale_factor, view->last_scale_factor()); | 3397 EXPECT_EQ(scale_factor, view->last_scale_factor()); |
3397 | 3398 |
3398 // Changes should be propagated. | 3399 // Changes should be propagated. |
3399 scale_factor *= 2.0f; | 3400 scale_factor *= 2.0f; |
3400 widget->GetLayer()->OnDeviceScaleFactorChanged(scale_factor); | 3401 widget->GetLayer()->OnDeviceScaleFactorChanged(scale_factor); |
3401 EXPECT_EQ(scale_factor, view->last_scale_factor()); | 3402 EXPECT_EQ(scale_factor, view->last_scale_factor()); |
3402 } | 3403 } |
3403 | 3404 |
| 3405 namespace { |
| 3406 |
| 3407 class TestWidgetRemovalsObserver : public WidgetRemovalsObserver { |
| 3408 public: |
| 3409 TestWidgetRemovalsObserver() {} |
| 3410 ~TestWidgetRemovalsObserver() override {} |
| 3411 |
| 3412 void OnWillRemoveView(Widget* widget, View* view) override { |
| 3413 removed_views_.insert(view); |
| 3414 } |
| 3415 |
| 3416 bool DidRemoveView(View* view) { |
| 3417 return removed_views_.find(view) != removed_views_.end(); |
| 3418 } |
| 3419 |
| 3420 private: |
| 3421 std::set<View*> removed_views_; |
| 3422 }; |
| 3423 |
| 3424 } |
| 3425 |
| 3426 // Test that WidgetRemovalsObserver::OnWillRemoveView is called on every |
| 3427 // deleted view. |
| 3428 TEST_F(WidgetTest, WidgetRemovalsObserver) { |
| 3429 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); |
| 3430 TestWidgetRemovalsObserver removals_observer; |
| 3431 widget->AddRemovalsObserver(&removals_observer); |
| 3432 |
| 3433 View* parent = new View(); |
| 3434 widget->client_view()->AddChildView(parent); |
| 3435 |
| 3436 View* child = new View(); |
| 3437 parent->AddChildView(child); |
| 3438 |
| 3439 widget->client_view()->RemoveChildView(parent); |
| 3440 EXPECT_TRUE(removals_observer.DidRemoveView(parent)); |
| 3441 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
| 3442 |
| 3443 widget->RemoveRemovalsObserver(&removals_observer); |
| 3444 } |
| 3445 |
3404 } // namespace test | 3446 } // namespace test |
3405 } // namespace views | 3447 } // namespace views |
OLD | NEW |