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 virtual int GetItemCount() const override { return 10; } |
93 virtual base::string16 GetItemAt(int index) OVERRIDE { | 93 virtual 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 virtual 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 virtual views::FocusSearch* GetFocusSearch() override { |
120 return focus_search_; | 120 return focus_search_; |
121 } | 121 } |
122 virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE { | 122 virtual FocusTraversable* GetFocusTraversableParent() override { |
123 return NULL; | 123 return NULL; |
124 } | 124 } |
125 virtual View* GetFocusTraversableParentView() OVERRIDE { | 125 virtual View* GetFocusTraversableParentView() override { |
126 return NULL; | 126 return NULL; |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 FocusSearch* focus_search_; | 130 FocusSearch* focus_search_; |
131 }; | 131 }; |
132 | 132 |
133 // BorderView is a view containing a native window with its own view hierarchy. | 133 // 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 | 134 // It is interesting to test focus traversal from a view hierarchy to an inner |
135 // view hierarchy. | 135 // view hierarchy. |
136 class BorderView : public NativeViewHost { | 136 class BorderView : public NativeViewHost { |
137 public: | 137 public: |
138 explicit BorderView(View* child) : child_(child), widget_(NULL) { | 138 explicit BorderView(View* child) : child_(child), widget_(NULL) { |
139 DCHECK(child); | 139 DCHECK(child); |
140 SetFocusable(false); | 140 SetFocusable(false); |
141 } | 141 } |
142 | 142 |
143 virtual ~BorderView() {} | 143 virtual ~BorderView() {} |
144 | 144 |
145 virtual internal::RootView* GetContentsRootView() { | 145 virtual internal::RootView* GetContentsRootView() { |
146 return static_cast<internal::RootView*>(widget_->GetRootView()); | 146 return static_cast<internal::RootView*>(widget_->GetRootView()); |
147 } | 147 } |
148 | 148 |
149 virtual FocusTraversable* GetFocusTraversable() OVERRIDE { | 149 virtual FocusTraversable* GetFocusTraversable() override { |
150 return static_cast<internal::RootView*>(widget_->GetRootView()); | 150 return static_cast<internal::RootView*>(widget_->GetRootView()); |
151 } | 151 } |
152 | 152 |
153 virtual void ViewHierarchyChanged( | 153 virtual void ViewHierarchyChanged( |
154 const ViewHierarchyChangedDetails& details) OVERRIDE { | 154 const ViewHierarchyChangedDetails& details) override { |
155 NativeViewHost::ViewHierarchyChanged(details); | 155 NativeViewHost::ViewHierarchyChanged(details); |
156 | 156 |
157 if (details.child == this && details.is_add) { | 157 if (details.child == this && details.is_add) { |
158 if (!widget_) { | 158 if (!widget_) { |
159 widget_ = new Widget; | 159 widget_ = new Widget; |
160 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 160 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
161 params.parent = details.parent->GetWidget()->GetNativeView(); | 161 params.parent = details.parent->GetWidget()->GetNativeView(); |
162 widget_->Init(params); | 162 widget_->Init(params); |
163 widget_->SetFocusTraversableParentView(this); | 163 widget_->SetFocusTraversableParentView(this); |
164 widget_->SetContentsView(child_); | 164 widget_->SetContentsView(child_); |
(...skipping 13 matching lines...) Expand all Loading... |
178 | 178 |
179 DISALLOW_COPY_AND_ASSIGN(BorderView); | 179 DISALLOW_COPY_AND_ASSIGN(BorderView); |
180 }; | 180 }; |
181 | 181 |
182 } // namespace | 182 } // namespace |
183 | 183 |
184 class FocusTraversalTest : public FocusManagerTest { | 184 class FocusTraversalTest : public FocusManagerTest { |
185 public: | 185 public: |
186 virtual ~FocusTraversalTest(); | 186 virtual ~FocusTraversalTest(); |
187 | 187 |
188 virtual void InitContentView() OVERRIDE; | 188 virtual void InitContentView() override; |
189 | 189 |
190 protected: | 190 protected: |
191 FocusTraversalTest(); | 191 FocusTraversalTest(); |
192 | 192 |
193 View* FindViewByID(int id) { | 193 View* FindViewByID(int id) { |
194 View* view = GetContentsView()->GetViewByID(id); | 194 View* view = GetContentsView()->GetViewByID(id); |
195 if (view) | 195 if (view) |
196 return view; | 196 return view; |
197 if (style_tab_) | 197 if (style_tab_) |
198 view = style_tab_->GetSelectedTab()->GetViewByID(id); | 198 view = style_tab_->GetSelectedTab()->GetViewByID(id); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 GetFocusManager()->AdvanceFocus(true); | 770 GetFocusManager()->AdvanceFocus(true); |
771 View* focused_view = GetFocusManager()->GetFocusedView(); | 771 View* focused_view = GetFocusManager()->GetFocusedView(); |
772 EXPECT_TRUE(focused_view != NULL); | 772 EXPECT_TRUE(focused_view != NULL); |
773 if (focused_view) | 773 if (focused_view) |
774 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 774 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
775 } | 775 } |
776 } | 776 } |
777 } | 777 } |
778 | 778 |
779 } // namespace views | 779 } // namespace views |
OLD | NEW |