Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 FocusSearch* focus_search_; | 127 FocusSearch* focus_search_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // BorderView is a view containing a native window with its own view hierarchy. | 130 // 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 | 131 // It is interesting to test focus traversal from a view hierarchy to an inner |
| 132 // view hierarchy. | 132 // view hierarchy. |
| 133 class BorderView : public NativeViewHost { | 133 class BorderView : public NativeViewHost { |
| 134 public: | 134 public: |
| 135 explicit BorderView(View* child) : child_(child), widget_(NULL) { | 135 explicit BorderView(View* child) : child_(child) { |
| 136 DCHECK(child); | 136 DCHECK(child); |
| 137 SetFocusBehavior(FocusBehavior::NEVER); | 137 SetFocusBehavior(FocusBehavior::NEVER); |
| 138 } | 138 } |
| 139 | 139 |
| 140 ~BorderView() override {} | |
| 141 | |
| 142 virtual internal::RootView* GetContentsRootView() { | 140 virtual internal::RootView* GetContentsRootView() { |
| 143 return static_cast<internal::RootView*>(widget_->GetRootView()); | 141 return static_cast<internal::RootView*>(widget_->GetRootView()); |
| 144 } | 142 } |
| 145 | 143 |
| 146 FocusTraversable* GetFocusTraversable() override { | 144 FocusTraversable* GetFocusTraversable() override { |
| 147 return static_cast<internal::RootView*>(widget_->GetRootView()); | 145 return static_cast<internal::RootView*>(widget_->GetRootView()); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void ViewHierarchyChanged( | 148 void ViewHierarchyChanged( |
| 151 const ViewHierarchyChangedDetails& details) override { | 149 const ViewHierarchyChangedDetails& details) override { |
| 152 NativeViewHost::ViewHierarchyChanged(details); | 150 NativeViewHost::ViewHierarchyChanged(details); |
| 153 | 151 |
| 154 if (details.child == this && details.is_add) { | 152 if (details.child == this && details.is_add) { |
| 155 if (!widget_) { | 153 if (!widget_) { |
| 156 widget_ = new Widget; | 154 widget_.reset(new Widget); |
| 157 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 155 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
| 158 params.parent = details.parent->GetWidget()->GetNativeView(); | 156 params.parent = details.parent->GetWidget()->GetNativeView(); |
| 157 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 159 widget_->Init(params); | 158 widget_->Init(params); |
| 160 widget_->SetFocusTraversableParentView(this); | 159 widget_->SetFocusTraversableParentView(this); |
| 161 widget_->SetContentsView(child_); | 160 widget_->SetContentsView(child_); |
| 162 } | 161 } |
| 163 | 162 |
| 164 // We have been added to a view hierarchy, attach the native view. | 163 // We have been added to a view hierarchy, attach the native view. |
| 165 Attach(widget_->GetNativeView()); | 164 Attach(widget_->GetNativeView()); |
| 166 // Also update the FocusTraversable parent so the focus traversal works. | 165 // Also update the FocusTraversable parent so the focus traversal works. |
| 167 static_cast<internal::RootView*>(widget_->GetRootView())-> | 166 static_cast<internal::RootView*>(widget_->GetRootView())-> |
| 168 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); | 167 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 private: | 171 private: |
| 173 View* child_; | 172 View* child_; |
| 174 Widget* widget_; | 173 std::unique_ptr<Widget> widget_; |
|
Patti Lor
2016/11/08 04:00:27
BorderView uses a Widget as convenient way to crea
tapted
2016/11/08 23:35:19
See also http://crbug.com/663418 about this - let'
msw
2016/11/09 02:08:53
Scott already has context on this nuanced issue; s
Patti Lor
2016/11/10 07:29:09
Reverted this file, changes are in https://coderev
msw
2016/11/10 18:45:01
If you just do |Widget widget_;|, it'll be automat
Patti Lor
2016/11/10 23:37:48
Oops, sorry - I didn't realise you meant a non-poi
| |
| 175 | 174 |
| 176 DISALLOW_COPY_AND_ASSIGN(BorderView); | 175 DISALLOW_COPY_AND_ASSIGN(BorderView); |
| 177 }; | 176 }; |
| 178 | 177 |
| 179 } // namespace | 178 } // namespace |
| 180 | 179 |
| 181 class FocusTraversalTest : public FocusManagerTest { | 180 class FocusTraversalTest : public FocusManagerTest { |
| 182 public: | 181 public: |
| 183 ~FocusTraversalTest() override; | 182 ~FocusTraversalTest() override; |
| 184 | 183 |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 GetFocusManager()->AdvanceFocus(false); | 878 GetFocusManager()->AdvanceFocus(false); |
| 880 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | 879 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); |
| 881 | 880 |
| 882 // Advance backwards from the root node. | 881 // Advance backwards from the root node. |
| 883 GetFocusManager()->ClearFocus(); | 882 GetFocusManager()->ClearFocus(); |
| 884 GetFocusManager()->AdvanceFocus(true); | 883 GetFocusManager()->AdvanceFocus(true); |
| 885 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | 884 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); |
| 886 } | 885 } |
| 887 | 886 |
| 888 } // namespace views | 887 } // namespace views |
| OLD | NEW |