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/views/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/base/models/combobox_model.h" | 10 #include "ui/base/models/combobox_model.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const int kSearchButtonID = count++; | 82 const int kSearchButtonID = count++; |
83 const int kHelpLinkID = count++; | 83 const int kHelpLinkID = count++; |
84 | 84 |
85 const int kThumbnailContainerID = count++; // 45 | 85 const int kThumbnailContainerID = count++; // 45 |
86 const int kThumbnailStarID = count++; | 86 const int kThumbnailStarID = count++; |
87 const int kThumbnailSuperStarID = count++; | 87 const int kThumbnailSuperStarID = count++; |
88 | 88 |
89 class DummyComboboxModel : public ui::ComboboxModel { | 89 class DummyComboboxModel : public ui::ComboboxModel { |
90 public: | 90 public: |
91 // Overridden from ui::ComboboxModel: | 91 // Overridden from ui::ComboboxModel: |
92 virtual int GetItemCount() const override { return 10; } | 92 int GetItemCount() const override { return 10; } |
93 virtual base::string16 GetItemAt(int index) override { | 93 base::string16 GetItemAt(int index) override { |
94 return ASCIIToUTF16("Item ") + base::IntToString16(index); | 94 return ASCIIToUTF16("Item ") + base::IntToString16(index); |
95 } | 95 } |
96 }; | 96 }; |
97 | 97 |
98 // A View that can act as a pane. | 98 // A View that can act as a pane. |
99 class PaneView : public View, public FocusTraversable { | 99 class PaneView : public View, public FocusTraversable { |
100 public: | 100 public: |
101 PaneView() : focus_search_(NULL) {} | 101 PaneView() : focus_search_(NULL) {} |
102 | 102 |
103 // If this method is called, this view will use GetPaneFocusTraversable to | 103 // If this method is called, this view will use GetPaneFocusTraversable to |
104 // have this provided FocusSearch used instead of the default one, allowing | 104 // have this provided FocusSearch used instead of the default one, allowing |
105 // you to trap focus within the pane. | 105 // you to trap focus within the pane. |
106 void EnablePaneFocus(FocusSearch* focus_search) { | 106 void EnablePaneFocus(FocusSearch* focus_search) { |
107 focus_search_ = focus_search; | 107 focus_search_ = focus_search; |
108 } | 108 } |
109 | 109 |
110 // Overridden from View: | 110 // Overridden from View: |
111 virtual FocusTraversable* GetPaneFocusTraversable() override { | 111 FocusTraversable* GetPaneFocusTraversable() override { |
112 if (focus_search_) | 112 if (focus_search_) |
113 return this; | 113 return this; |
114 else | 114 else |
115 return NULL; | 115 return NULL; |
116 } | 116 } |
117 | 117 |
118 // Overridden from FocusTraversable: | 118 // Overridden from FocusTraversable: |
119 virtual views::FocusSearch* GetFocusSearch() override { | 119 views::FocusSearch* GetFocusSearch() override { return focus_search_; } |
120 return focus_search_; | 120 FocusTraversable* GetFocusTraversableParent() override { return NULL; } |
121 } | 121 View* GetFocusTraversableParentView() override { return NULL; } |
122 virtual FocusTraversable* GetFocusTraversableParent() override { | |
123 return NULL; | |
124 } | |
125 virtual View* GetFocusTraversableParentView() override { | |
126 return NULL; | |
127 } | |
128 | 122 |
129 private: | 123 private: |
130 FocusSearch* focus_search_; | 124 FocusSearch* focus_search_; |
131 }; | 125 }; |
132 | 126 |
133 // BorderView is a view containing a native window with its own view hierarchy. | 127 // BorderView is a view containing a native window with its own view hierarchy. |
134 // It is interesting to test focus traversal from a view hierarchy to an inner | 128 // It is interesting to test focus traversal from a view hierarchy to an inner |
135 // view hierarchy. | 129 // view hierarchy. |
136 class BorderView : public NativeViewHost { | 130 class BorderView : public NativeViewHost { |
137 public: | 131 public: |
138 explicit BorderView(View* child) : child_(child), widget_(NULL) { | 132 explicit BorderView(View* child) : child_(child), widget_(NULL) { |
139 DCHECK(child); | 133 DCHECK(child); |
140 SetFocusable(false); | 134 SetFocusable(false); |
141 } | 135 } |
142 | 136 |
143 virtual ~BorderView() {} | 137 ~BorderView() override {} |
144 | 138 |
145 virtual internal::RootView* GetContentsRootView() { | 139 virtual internal::RootView* GetContentsRootView() { |
146 return static_cast<internal::RootView*>(widget_->GetRootView()); | 140 return static_cast<internal::RootView*>(widget_->GetRootView()); |
147 } | 141 } |
148 | 142 |
149 virtual FocusTraversable* GetFocusTraversable() override { | 143 FocusTraversable* GetFocusTraversable() override { |
150 return static_cast<internal::RootView*>(widget_->GetRootView()); | 144 return static_cast<internal::RootView*>(widget_->GetRootView()); |
151 } | 145 } |
152 | 146 |
153 virtual void ViewHierarchyChanged( | 147 void ViewHierarchyChanged( |
154 const ViewHierarchyChangedDetails& details) override { | 148 const ViewHierarchyChangedDetails& details) override { |
155 NativeViewHost::ViewHierarchyChanged(details); | 149 NativeViewHost::ViewHierarchyChanged(details); |
156 | 150 |
157 if (details.child == this && details.is_add) { | 151 if (details.child == this && details.is_add) { |
158 if (!widget_) { | 152 if (!widget_) { |
159 widget_ = new Widget; | 153 widget_ = new Widget; |
160 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 154 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
161 params.parent = details.parent->GetWidget()->GetNativeView(); | 155 params.parent = details.parent->GetWidget()->GetNativeView(); |
162 widget_->Init(params); | 156 widget_->Init(params); |
163 widget_->SetFocusTraversableParentView(this); | 157 widget_->SetFocusTraversableParentView(this); |
(...skipping 12 matching lines...) Expand all Loading... |
176 View* child_; | 170 View* child_; |
177 Widget* widget_; | 171 Widget* widget_; |
178 | 172 |
179 DISALLOW_COPY_AND_ASSIGN(BorderView); | 173 DISALLOW_COPY_AND_ASSIGN(BorderView); |
180 }; | 174 }; |
181 | 175 |
182 } // namespace | 176 } // namespace |
183 | 177 |
184 class FocusTraversalTest : public FocusManagerTest { | 178 class FocusTraversalTest : public FocusManagerTest { |
185 public: | 179 public: |
186 virtual ~FocusTraversalTest(); | 180 ~FocusTraversalTest() override; |
187 | 181 |
188 virtual void InitContentView() override; | 182 void InitContentView() override; |
189 | 183 |
190 protected: | 184 protected: |
191 FocusTraversalTest(); | 185 FocusTraversalTest(); |
192 | 186 |
193 View* FindViewByID(int id) { | 187 View* FindViewByID(int id) { |
194 View* view = GetContentsView()->GetViewByID(id); | 188 View* view = GetContentsView()->GetViewByID(id); |
195 if (view) | 189 if (view) |
196 return view; | 190 return view; |
197 if (style_tab_) | 191 if (style_tab_) |
198 view = style_tab_->GetSelectedTab()->GetViewByID(id); | 192 view = style_tab_->GetSelectedTab()->GetViewByID(id); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 GetFocusManager()->AdvanceFocus(true); | 764 GetFocusManager()->AdvanceFocus(true); |
771 View* focused_view = GetFocusManager()->GetFocusedView(); | 765 View* focused_view = GetFocusManager()->GetFocusedView(); |
772 EXPECT_TRUE(focused_view != NULL); | 766 EXPECT_TRUE(focused_view != NULL); |
773 if (focused_view) | 767 if (focused_view) |
774 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 768 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
775 } | 769 } |
776 } | 770 } |
777 } | 771 } |
778 | 772 |
779 } // namespace views | 773 } // namespace views |
OLD | NEW |