| 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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // 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 |
| 133 // view hierarchy. | 133 // view hierarchy. |
| 134 class BorderView : public NativeViewHost { | 134 class BorderView : public NativeViewHost { |
| 135 public: | 135 public: |
| 136 explicit BorderView(View* child) : child_(child) { | 136 explicit BorderView(View* child) : child_(child) { |
| 137 DCHECK(child); | 137 DCHECK(child); |
| 138 SetFocusBehavior(FocusBehavior::NEVER); | 138 SetFocusBehavior(FocusBehavior::NEVER); |
| 139 } | 139 } |
| 140 | 140 |
| 141 virtual internal::RootView* GetContentsRootView() { | 141 virtual internal::RootView* GetContentsRootView() { |
| 142 return static_cast<internal::RootView*>(widget_->GetRootView()); | 142 return static_cast<internal::RootView*>(widget_.GetRootView()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 FocusTraversable* GetFocusTraversable() override { | 145 FocusTraversable* GetFocusTraversable() override { |
| 146 return static_cast<internal::RootView*>(widget_->GetRootView()); | 146 return static_cast<internal::RootView*>(widget_.GetRootView()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void ViewHierarchyChanged( | 149 void ViewHierarchyChanged( |
| 150 const ViewHierarchyChangedDetails& details) override { | 150 const ViewHierarchyChangedDetails& details) override { |
| 151 NativeViewHost::ViewHierarchyChanged(details); | 151 NativeViewHost::ViewHierarchyChanged(details); |
| 152 | 152 |
| 153 if (details.child == this && details.is_add) { | 153 if (details.child == this && details.is_add) { |
| 154 if (!widget_) { | 154 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
| 155 widget_ = base::MakeUnique<Widget>(); | 155 params.parent = details.parent->GetWidget()->GetNativeView(); |
| 156 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); | 156 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 157 params.parent = details.parent->GetWidget()->GetNativeView(); | 157 widget_.Init(params); |
| 158 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 158 widget_.SetFocusTraversableParentView(this); |
| 159 widget_->Init(params); | 159 widget_.SetContentsView(child_); |
| 160 widget_->SetFocusTraversableParentView(this); | |
| 161 widget_->SetContentsView(child_); | |
| 162 } | |
| 163 | 160 |
| 164 // We have been added to a view hierarchy, attach the native view. | 161 // We have been added to a view hierarchy, attach the native view. |
| 165 Attach(widget_->GetNativeView()); | 162 Attach(widget_.GetNativeView()); |
| 166 // Also update the FocusTraversable parent so the focus traversal works. | 163 // Also update the FocusTraversable parent so the focus traversal works. |
| 167 static_cast<internal::RootView*>(widget_->GetRootView())-> | 164 static_cast<internal::RootView*>(widget_.GetRootView())-> |
| 168 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); | 165 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); |
| 169 } | 166 } |
| 170 } | 167 } |
| 171 | 168 |
| 172 private: | 169 private: |
| 173 View* child_; | 170 View* child_; |
| 174 std::unique_ptr<Widget> widget_; | 171 Widget widget_; |
| 175 | 172 |
| 176 DISALLOW_COPY_AND_ASSIGN(BorderView); | 173 DISALLOW_COPY_AND_ASSIGN(BorderView); |
| 177 }; | 174 }; |
| 178 | 175 |
| 179 } // namespace | 176 } // namespace |
| 180 | 177 |
| 181 class FocusTraversalTest : public FocusManagerTest { | 178 class FocusTraversalTest : public FocusManagerTest { |
| 182 public: | 179 public: |
| 183 ~FocusTraversalTest() override; | 180 ~FocusTraversalTest() override; |
| 184 | 181 |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 GetFocusManager()->AdvanceFocus(false); | 876 GetFocusManager()->AdvanceFocus(false); |
| 880 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | 877 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); |
| 881 | 878 |
| 882 // Advance backwards from the root node. | 879 // Advance backwards from the root node. |
| 883 GetFocusManager()->ClearFocus(); | 880 GetFocusManager()->ClearFocus(); |
| 884 GetFocusManager()->AdvanceFocus(true); | 881 GetFocusManager()->AdvanceFocus(true); |
| 885 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | 882 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); |
| 886 } | 883 } |
| 887 | 884 |
| 888 } // namespace views | 885 } // namespace views |
| OLD | NEW |