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

Side by Side Diff: ui/views/test/widget_test.cc

Issue 2409423003: Move WidgetActivationWaiter to a common place (Closed)
Patch Set: remove run_loop include Created 4 years, 2 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/widget_test.h" 5 #include "ui/views/test/widget_test.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "ui/gfx/native_widget_types.h" 8 #include "ui/gfx/native_widget_types.h"
9 #include "ui/views/test/native_widget_factory.h" 9 #include "ui/views/test/native_widget_factory.h"
10 #include "ui/views/widget/root_view.h" 10 #include "ui/views/widget/root_view.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 GetWidget()->Init(params); 143 GetWidget()->Init(params);
144 GetWidget()->GetContentsView()->AddChildView(view_); 144 GetWidget()->GetContentsView()->AddChildView(view_);
145 } 145 }
146 146
147 TestInitialFocusWidgetDelegate::~TestInitialFocusWidgetDelegate() {} 147 TestInitialFocusWidgetDelegate::~TestInitialFocusWidgetDelegate() {}
148 148
149 View* TestInitialFocusWidgetDelegate::GetInitiallyFocusedView() { 149 View* TestInitialFocusWidgetDelegate::GetInitiallyFocusedView() {
150 return view_; 150 return view_;
151 } 151 }
152 152
153 WidgetActivationWaiter::WidgetActivationWaiter(Widget* widget, bool active)
154 : observed_(false), active_(active) {
155 #if defined(OS_WIN)
156 // On Windows, a HWND can receive a WM_ACTIVATE message without the value
157 // of ::GetActiveWindow() updating to reflect that change. This can cause
158 // the active window reported by IsActive() to get out of sync. Usually this
159 // happens after a call to HWNDMessageHandler::Deactivate() which works by
160 // activating some other window, which might be in another application.
161 // Doing this can trigger the native OS activation-blocker, causing the
162 // taskbar icon to flash instead. But since activation of native widgets on
163 // Windows is synchronous, we never have to wait anyway, so it's safe to
164 // return here.
165 if (active == widget->IsActive()) {
166 observed_ = true;
167 return;
168 }
169 #endif
170 // Always expect a change for tests using this.
171 EXPECT_NE(active, widget->IsActive());
sky 2016/10/12 16:05:43 I think this is error prone for a general class. Y
Qiang(Joe) Xu 2016/10/12 16:55:58 Done.
172 widget->AddObserver(this);
173 }
174
175 WidgetActivationWaiter::~WidgetActivationWaiter() {}
176
177 void WidgetActivationWaiter::Wait() {
178 if (!observed_)
179 run_loop_.Run();
180 }
181
182 void WidgetActivationWaiter::OnWidgetActivationChanged(Widget* widget,
183 bool active) {
184 if (active_ != active)
185 return;
186
187 observed_ = true;
188 widget->RemoveObserver(this);
189 if (run_loop_.running())
190 run_loop_.Quit();
191 }
192
153 } // namespace test 193 } // namespace test
154 } // namespace views 194 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698