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

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

Issue 2345183002: Views: Draw Textfield selected text in gray when top-level Widget loses focus.
Patch Set: Review comments. 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
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/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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
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), widget_(NULL) {
136 DCHECK(child); 136 DCHECK(child);
137 SetFocusBehavior(FocusBehavior::NEVER); 137 SetFocusBehavior(FocusBehavior::NEVER);
138 } 138 }
139 139
140 ~BorderView() override {} 140 ~BorderView() override {
141 #if !defined(OS_MACOSX)
142 // TYPE_CONTROL Widget close order is different on macOS vs Windows/Linux.
tapted 2016/11/07 06:14:50 We generally need platforms to behave the same - t
Patti Lor 2016/11/08 01:47:31 Deleted as discussed offline.
143 // On macOS, |widget_|'s native widget will be destroyed by the time this
144 // destructor is reached, so avoid possible use-after-frees on it (see
145 // Widget::CloseNow()) by calling this only on Windows and Linux.
146 widget_->CloseNow();
147 #endif
148 }
141 149
142 virtual internal::RootView* GetContentsRootView() { 150 virtual internal::RootView* GetContentsRootView() {
143 return static_cast<internal::RootView*>(widget_->GetRootView()); 151 return static_cast<internal::RootView*>(widget_->GetRootView());
144 } 152 }
145 153
146 FocusTraversable* GetFocusTraversable() override { 154 FocusTraversable* GetFocusTraversable() override {
147 return static_cast<internal::RootView*>(widget_->GetRootView()); 155 return static_cast<internal::RootView*>(widget_->GetRootView());
148 } 156 }
149 157
150 void ViewHierarchyChanged( 158 void ViewHierarchyChanged(
151 const ViewHierarchyChangedDetails& details) override { 159 const ViewHierarchyChangedDetails& details) override {
152 NativeViewHost::ViewHierarchyChanged(details); 160 NativeViewHost::ViewHierarchyChanged(details);
153 161
154 if (details.child == this && details.is_add) { 162 if (details.child == this && details.is_add) {
155 if (!widget_) { 163 if (!widget_) {
156 widget_ = new Widget; 164 widget_ = new Widget;
157 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); 165 Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
158 params.parent = details.parent->GetWidget()->GetNativeView(); 166 params.parent = details.parent->GetWidget()->GetNativeView();
159 widget_->Init(params); 167 widget_->Init(params);
160 widget_->SetFocusTraversableParentView(this); 168 widget_->SetFocusTraversableParentView(this);
161 widget_->SetContentsView(child_); 169 widget_->SetContentsView(child_);
162 } 170 }
163 171
164 // We have been added to a view hierarchy, attach the native view. 172 // We have been added to a view hierarchy, attach the native view.
165 Attach(widget_->GetNativeView()); 173 Attach(widget_->GetNativeView());
tapted 2016/11/07 06:14:50 Note there's some weirdness that starts because of
Patti Lor 2016/11/08 01:47:31 Acknowledged.
166 // Also update the FocusTraversable parent so the focus traversal works. 174 // Also update the FocusTraversable parent so the focus traversal works.
167 static_cast<internal::RootView*>(widget_->GetRootView())-> 175 static_cast<internal::RootView*>(widget_->GetRootView())->
168 SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); 176 SetFocusTraversableParent(GetWidget()->GetFocusTraversable());
169 } 177 }
170 } 178 }
171 179
172 private: 180 private:
173 View* child_; 181 View* child_;
174 Widget* widget_; 182 Widget* widget_;
175 183
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 GetFocusManager()->AdvanceFocus(false); 887 GetFocusManager()->AdvanceFocus(false);
880 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 888 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
881 889
882 // Advance backwards from the root node. 890 // Advance backwards from the root node.
883 GetFocusManager()->ClearFocus(); 891 GetFocusManager()->ClearFocus();
884 GetFocusManager()->AdvanceFocus(true); 892 GetFocusManager()->AdvanceFocus(true);
885 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 893 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
886 } 894 }
887 895
888 } // namespace views 896 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698