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

Side by Side Diff: ui/views/focus/focus_traversal_unittest.cc

Issue 2482193003: views_unittests: Fix FocusTraversalTest's BorderView::widget_ deletion. (Closed)
Patch Set: Use base::MakeUnique, add to imports. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/models/combobox_model.h" 12 #include "ui/base/models/combobox_model.h"
12 #include "ui/views/background.h" 13 #include "ui/views/background.h"
13 #include "ui/views/border.h" 14 #include "ui/views/border.h"
14 #include "ui/views/controls/button/checkbox.h" 15 #include "ui/views/controls/button/checkbox.h"
15 #include "ui/views/controls/button/label_button.h" 16 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/controls/button/md_text_button.h" 17 #include "ui/views/controls/button/md_text_button.h"
17 #include "ui/views/controls/button/radio_button.h" 18 #include "ui/views/controls/button/radio_button.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 126
126 private: 127 private:
127 FocusSearch* focus_search_; 128 FocusSearch* focus_search_;
128 }; 129 };
129 130
130 // BorderView is a view containing a native window with its own view hierarchy. 131 // BorderView is a view containing a native window with its own view hierarchy.
131 // It is interesting to test focus traversal from a view hierarchy to an inner 132 // It is interesting to test focus traversal from a view hierarchy to an inner
132 // view hierarchy. 133 // view hierarchy.
133 class BorderView : public NativeViewHost { 134 class BorderView : public NativeViewHost {
134 public: 135 public:
135 explicit BorderView(View* child) : child_(child), widget_(NULL) { 136 explicit BorderView(View* child) : child_(child) {
136 DCHECK(child); 137 DCHECK(child);
137 SetFocusBehavior(FocusBehavior::NEVER); 138 SetFocusBehavior(FocusBehavior::NEVER);
138 } 139 }
139 140
140 ~BorderView() override {
141 // TODO: ifdef should not be necessary. NativeWidgetMac has different
142 // ownership semantics: http://crbug.com/663418.
143 #if !defined(OS_MACOSX)
144 if (widget_)
145 widget_->CloseNow();
146 #endif
147 }
148
149 virtual internal::RootView* GetContentsRootView() { 141 virtual internal::RootView* GetContentsRootView() {
150 return static_cast<internal::RootView*>(widget_->GetRootView()); 142 return static_cast<internal::RootView*>(widget_->GetRootView());
151 } 143 }
152 144
153 FocusTraversable* GetFocusTraversable() override { 145 FocusTraversable* GetFocusTraversable() override {
154 return static_cast<internal::RootView*>(widget_->GetRootView()); 146 return static_cast<internal::RootView*>(widget_->GetRootView());
155 } 147 }
156 148
157 void ViewHierarchyChanged( 149 void ViewHierarchyChanged(
158 const ViewHierarchyChangedDetails& details) override { 150 const ViewHierarchyChangedDetails& details) override {
159 NativeViewHost::ViewHierarchyChanged(details); 151 NativeViewHost::ViewHierarchyChanged(details);
160 152
161 if (details.child == this && details.is_add) { 153 if (details.child == this && details.is_add) {
162 if (!widget_) { 154 if (!widget_) {
163 widget_ = new Widget; 155 widget_ = base::MakeUnique<Widget>();
164 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); 156 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
165 params.parent = details.parent->GetWidget()->GetNativeView(); 157 params.parent = details.parent->GetWidget()->GetNativeView();
158 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
166 widget_->Init(params); 159 widget_->Init(params);
167 widget_->SetFocusTraversableParentView(this); 160 widget_->SetFocusTraversableParentView(this);
168 widget_->SetContentsView(child_); 161 widget_->SetContentsView(child_);
169 } 162 }
170 163
171 // We have been added to a view hierarchy, attach the native view. 164 // We have been added to a view hierarchy, attach the native view.
172 Attach(widget_->GetNativeView()); 165 Attach(widget_->GetNativeView());
173 // Also update the FocusTraversable parent so the focus traversal works. 166 // Also update the FocusTraversable parent so the focus traversal works.
174 static_cast<internal::RootView*>(widget_->GetRootView())-> 167 static_cast<internal::RootView*>(widget_->GetRootView())->
175 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); 168 SetFocusTraversableParent(GetWidget()->GetFocusTraversable());
176 } 169 }
177 } 170 }
178 171
179 private: 172 private:
180 View* child_; 173 View* child_;
181 Widget* widget_; 174 std::unique_ptr<Widget> widget_;
182 175
183 DISALLOW_COPY_AND_ASSIGN(BorderView); 176 DISALLOW_COPY_AND_ASSIGN(BorderView);
184 }; 177 };
185 178
186 } // namespace 179 } // namespace
187 180
188 class FocusTraversalTest : public FocusManagerTest { 181 class FocusTraversalTest : public FocusManagerTest {
189 public: 182 public:
190 ~FocusTraversalTest() override; 183 ~FocusTraversalTest() override;
191 184
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 GetFocusManager()->AdvanceFocus(false); 879 GetFocusManager()->AdvanceFocus(false);
887 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 880 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
888 881
889 // Advance backwards from the root node. 882 // Advance backwards from the root node.
890 GetFocusManager()->ClearFocus(); 883 GetFocusManager()->ClearFocus();
891 GetFocusManager()->AdvanceFocus(true); 884 GetFocusManager()->AdvanceFocus(true);
892 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 885 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
893 } 886 }
894 887
895 } // namespace views 888 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698