| 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 "services/window_manager/focus_controller.h" | 5 #include "services/window_manager/focus_controller.h" |
| 6 | 6 |
| 7 #include "mojo/converters/geometry/geometry_type_converters.h" | 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 8 #include "services/window_manager/basic_focus_rules.h" | 8 #include "services/window_manager/basic_focus_rules.h" |
| 9 #include "services/window_manager/focus_controller_observer.h" | 9 #include "services/window_manager/focus_controller_observer.h" |
| 10 #include "services/window_manager/view_event_dispatcher.h" | 10 #include "services/window_manager/view_event_dispatcher.h" |
| 11 #include "services/window_manager/view_targeter.h" | 11 #include "services/window_manager/view_targeter.h" |
| 12 #include "services/window_manager/window_manager_test_util.h" | 12 #include "services/window_manager/window_manager_test_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/events/test/event_generator.h" | 14 #include "ui/events/test/event_generator.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 using mojo::View; |
| 18 |
| 19 namespace window_manager { |
| 18 | 20 |
| 19 // Counts the number of events that occur. | 21 // Counts the number of events that occur. |
| 20 class FocusNotificationObserver : public FocusControllerObserver { | 22 class FocusNotificationObserver : public FocusControllerObserver { |
| 21 public: | 23 public: |
| 22 FocusNotificationObserver() | 24 FocusNotificationObserver() |
| 23 : activation_changed_count_(0), | 25 : activation_changed_count_(0), |
| 24 focus_changed_count_(0), | 26 focus_changed_count_(0), |
| 25 reactivation_count_(0), | 27 reactivation_count_(0), |
| 26 reactivation_requested_view_(NULL), | 28 reactivation_requested_view_(NULL), |
| 27 reactivation_actual_view_(NULL) {} | 29 reactivation_actual_view_(NULL) {} |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (lost_active && lost_active == destroyer_->GetDestroyedView()) | 100 if (lost_active && lost_active == destroyer_->GetDestroyedView()) |
| 99 was_notified_with_destroyed_view_ = true; | 101 was_notified_with_destroyed_view_ = true; |
| 100 } | 102 } |
| 101 | 103 |
| 102 void OnViewFocused(View* gained_focus, View* lost_focus) override { | 104 void OnViewFocused(View* gained_focus, View* lost_focus) override { |
| 103 if (lost_focus && lost_focus == destroyer_->GetDestroyedView()) | 105 if (lost_focus && lost_focus == destroyer_->GetDestroyedView()) |
| 104 was_notified_with_destroyed_view_ = true; | 106 was_notified_with_destroyed_view_ = true; |
| 105 } | 107 } |
| 106 | 108 |
| 107 private: | 109 private: |
| 108 mojo::FocusController* focus_controller_; | 110 FocusController* focus_controller_; |
| 109 | 111 |
| 110 // Not owned. | 112 // Not owned. |
| 111 ViewDestroyer* destroyer_; | 113 ViewDestroyer* destroyer_; |
| 112 | 114 |
| 113 // Whether the observer was notified about the loss of activation or the | 115 // Whether the observer was notified about the loss of activation or the |
| 114 // loss of focus with a view already destroyed by |destroyer_| as the | 116 // loss of focus with a view already destroyed by |destroyer_| as the |
| 115 // |lost_active| or |lost_focus| parameter. | 117 // |lost_active| or |lost_focus| parameter. |
| 116 bool was_notified_with_destroyed_view_; | 118 bool was_notified_with_destroyed_view_; |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(RecordingFocusNotificationObserver); | 120 DISALLOW_COPY_AND_ASSIGN(RecordingFocusNotificationObserver); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 public: | 161 public: |
| 160 ScopedFocusNotificationObserver(FocusController* focus_controller) | 162 ScopedFocusNotificationObserver(FocusController* focus_controller) |
| 161 : focus_controller_(focus_controller) { | 163 : focus_controller_(focus_controller) { |
| 162 focus_controller_->AddObserver(this); | 164 focus_controller_->AddObserver(this); |
| 163 } | 165 } |
| 164 ~ScopedFocusNotificationObserver() override { | 166 ~ScopedFocusNotificationObserver() override { |
| 165 focus_controller_->RemoveObserver(this); | 167 focus_controller_->RemoveObserver(this); |
| 166 } | 168 } |
| 167 | 169 |
| 168 private: | 170 private: |
| 169 mojo::FocusController* focus_controller_; | 171 FocusController* focus_controller_; |
| 170 | 172 |
| 171 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver); | 173 DISALLOW_COPY_AND_ASSIGN(ScopedFocusNotificationObserver); |
| 172 }; | 174 }; |
| 173 | 175 |
| 174 // Only responds to events if a message contains |target| as a parameter. | 176 // Only responds to events if a message contains |target| as a parameter. |
| 175 class ScopedFilteringFocusNotificationObserver | 177 class ScopedFilteringFocusNotificationObserver |
| 176 : public FocusNotificationObserver { | 178 : public FocusNotificationObserver { |
| 177 public: | 179 public: |
| 178 ScopedFilteringFocusNotificationObserver(FocusController* focus_controller, | 180 ScopedFilteringFocusNotificationObserver(FocusController* focus_controller, |
| 179 View* target) | 181 View* target) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 197 } | 199 } |
| 198 | 200 |
| 199 void OnAttemptToReactivateView(View* request_active, | 201 void OnAttemptToReactivateView(View* request_active, |
| 200 View* actual_active) override { | 202 View* actual_active) override { |
| 201 if (request_active == target_ || actual_active == target_) { | 203 if (request_active == target_ || actual_active == target_) { |
| 202 FocusNotificationObserver::OnAttemptToReactivateView(request_active, | 204 FocusNotificationObserver::OnAttemptToReactivateView(request_active, |
| 203 actual_active); | 205 actual_active); |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 | 208 |
| 207 mojo::FocusController* focus_controller_; | 209 FocusController* focus_controller_; |
| 208 View* target_; | 210 View* target_; |
| 209 | 211 |
| 210 DISALLOW_COPY_AND_ASSIGN(ScopedFilteringFocusNotificationObserver); | 212 DISALLOW_COPY_AND_ASSIGN(ScopedFilteringFocusNotificationObserver); |
| 211 }; | 213 }; |
| 212 | 214 |
| 213 // Used to fake the handling of events in the pre-target phase. | 215 // Used to fake the handling of events in the pre-target phase. |
| 214 class SimpleEventHandler : public ui::EventHandler { | 216 class SimpleEventHandler : public ui::EventHandler { |
| 215 public: | 217 public: |
| 216 SimpleEventHandler() {} | 218 SimpleEventHandler() {} |
| 217 ~SimpleEventHandler() override {} | 219 ~SimpleEventHandler() override {} |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 // TODO(erg): Add the capture tests here. | 1125 // TODO(erg): Add the capture tests here. |
| 1124 | 1126 |
| 1125 // See description above DontPassDestroyedView() for details. | 1127 // See description above DontPassDestroyedView() for details. |
| 1126 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDestroyedView); | 1128 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDestroyedView); |
| 1127 | 1129 |
| 1128 // TODO(erg): Add the TextInputClient tests here. | 1130 // TODO(erg): Add the TextInputClient tests here. |
| 1129 | 1131 |
| 1130 // If a mouse event was handled, it should not activate a view. | 1132 // If a mouse event was handled, it should not activate a view. |
| 1131 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1133 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1132 | 1134 |
| 1133 } // namespace mojo | 1135 } // namespace window_manager |
| OLD | NEW |