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

Side by Side Diff: ui/views/corewm/focus_controller_unittest.cc

Issue 11414304: Fleshes out the basic set of focus rules a bit more. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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
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 "ui/views/corewm/focus_controller.h" 5 #include "ui/views/corewm/focus_controller.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "ui/aura/client/activation_client.h" 9 #include "ui/aura/client/activation_client.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/aura_test_base.h" 11 #include "ui/aura/test/aura_test_base.h"
12 #include "ui/aura/test/event_generator.h" 12 #include "ui/aura/test/event_generator.h"
13 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/base/events/event_handler.h" 16 #include "ui/base/events/event_handler.h"
17 #include "ui/views/corewm/base_focus_rules.h"
18 #include "ui/views/corewm/focus_change_event.h" 17 #include "ui/views/corewm/focus_change_event.h"
19 18
20 namespace views { 19 namespace views {
21 namespace corewm { 20 namespace corewm {
22 21
23 class FocusEventsTestHandler : public ui::EventHandler, 22 class FocusEventsTestHandler : public ui::EventHandler,
24 public aura::WindowObserver { 23 public aura::WindowObserver {
25 public: 24 public:
26 explicit FocusEventsTestHandler(aura::Window* window) 25 explicit FocusEventsTestHandler(aura::Window* window)
27 : window_(window), 26 : window_(window),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 class TestFocusRules : public BaseFocusRules { 77 class TestFocusRules : public BaseFocusRules {
79 public: 78 public:
80 TestFocusRules() : focus_restriction_(NULL) {} 79 TestFocusRules() : focus_restriction_(NULL) {}
81 80
82 // Restricts focus and activation to this window and its child hierarchy. 81 // Restricts focus and activation to this window and its child hierarchy.
83 void set_focus_restriction(aura::Window* focus_restriction) { 82 void set_focus_restriction(aura::Window* focus_restriction) {
84 focus_restriction_ = focus_restriction; 83 focus_restriction_ = focus_restriction;
85 } 84 }
86 85
87 // Overridden from BaseFocusRules: 86 // Overridden from BaseFocusRules:
87 virtual bool SupportsChildActivation(aura::Window* window) OVERRIDE {
88 // In FocusControllerTests, only the RootWindow has activatable children.
89 return window->GetRootWindow() == window;
90 }
88 virtual bool CanActivateWindow(aura::Window* window) OVERRIDE { 91 virtual bool CanActivateWindow(aura::Window* window) OVERRIDE {
89 // Restricting focus to a non-activatable child window means the activatable 92 // Restricting focus to a non-activatable child window means the activatable
90 // parent outside the focus restriction is activatable. 93 // parent outside the focus restriction is activatable.
91 bool can_activate = CanFocusOrActivate(window) || 94 bool can_activate =
92 window->Contains(GetActivatableWindow(focus_restriction_)); 95 CanFocusOrActivate(window) || window->Contains(focus_restriction_);
93 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false; 96 return can_activate ? BaseFocusRules::CanActivateWindow(window) : false;
94 } 97 }
95 virtual bool CanFocusWindow(aura::Window* window) OVERRIDE { 98 virtual bool CanFocusWindow(aura::Window* window) OVERRIDE {
96 return CanFocusOrActivate(window) ? 99 return CanFocusOrActivate(window) ?
97 BaseFocusRules::CanFocusWindow(window) : false; 100 BaseFocusRules::CanFocusWindow(window) : false;
98 } 101 }
99 virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE { 102 virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE {
100 return BaseFocusRules::GetActivatableWindow( 103 return BaseFocusRules::GetActivatableWindow(
101 CanFocusOrActivate(window) ? window : focus_restriction_); 104 CanFocusOrActivate(window) ? window : focus_restriction_);
102 } 105 }
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow); 735 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow);
733 736
734 // - Verifies that FocusRules determine what can be focused. 737 // - Verifies that FocusRules determine what can be focused.
735 ALL_FOCUS_TESTS(FocusRulesOverride); 738 ALL_FOCUS_TESTS(FocusRulesOverride);
736 739
737 // - Verifies that FocusRules determine what can be activated. 740 // - Verifies that FocusRules determine what can be activated.
738 TARGET_FOCUS_TESTS(ActivationRulesOverride); 741 TARGET_FOCUS_TESTS(ActivationRulesOverride);
739 742
740 } // namespace corewm 743 } // namespace corewm
741 } // namespace views 744 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698