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

Side by Side Diff: chrome/browser/chromeos/options/network_config_view.cc

Issue 2426473009: mash: Place views Wi-Fi network config dialogs in correct window parent (Closed)
Patch Set: rebase 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 (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 "chrome/browser/chromeos/options/network_config_view.h" 5 #include "chrome/browser/chromeos/options/network_config_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 12 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
13 #include "chrome/browser/chromeos/options/network_property_ui_data.h" 13 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
14 #include "chrome/browser/chromeos/options/vpn_config_view.h" 14 #include "chrome/browser/chromeos/options/vpn_config_view.h"
15 #include "chrome/browser/chromeos/options/wifi_config_view.h" 15 #include "chrome/browser/chromeos/options/wifi_config_view.h"
16 #include "chrome/browser/chromeos/options/wimax_config_view.h" 16 #include "chrome/browser/chromeos/options/wimax_config_view.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/ash/ash_util.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
22 #include "chrome/grit/locale_settings.h" 23 #include "chrome/grit/locale_settings.h"
23 #include "chromeos/login/login_state.h" 24 #include "chromeos/login/login_state.h"
24 #include "chromeos/network/network_state.h" 25 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h" 26 #include "chromeos/network/network_state_handler.h"
26 #include "components/device_event_log/device_event_log.h" 27 #include "components/device_event_log/device_event_log.h"
27 #include "components/user_manager/user.h" 28 #include "components/user_manager/user.h"
29 #include "services/ui/public/cpp/property_type_converters.h"
30 #include "services/ui/public/interfaces/window_manager.mojom.h"
28 #include "ui/accessibility/ax_view_state.h" 31 #include "ui/accessibility/ax_view_state.h"
32 #include "ui/aura/mus/mus_util.h"
29 #include "ui/aura/window_event_dispatcher.h" 33 #include "ui/aura/window_event_dispatcher.h"
30 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/gfx/color_palette.h" 35 #include "ui/gfx/color_palette.h"
32 #include "ui/gfx/geometry/rect.h" 36 #include "ui/gfx/geometry/rect.h"
33 #include "ui/gfx/image/image.h" 37 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/paint_vector_icon.h" 38 #include "ui/gfx/paint_vector_icon.h"
35 #include "ui/gfx/vector_icons_public.h" 39 #include "ui/gfx/vector_icons_public.h"
36 #include "ui/views/controls/button/md_text_button.h" 40 #include "ui/views/controls/button/md_text_button.h"
37 #include "ui/views/controls/image_view.h" 41 #include "ui/views/controls/image_view.h"
38 #include "ui/views/layout/fill_layout.h" 42 #include "ui/views/layout/fill_layout.h"
39 #include "ui/views/layout/layout_constants.h" 43 #include "ui/views/layout/layout_constants.h"
40 #include "ui/views/widget/widget.h" 44 #include "ui/views/widget/widget.h"
45 #include "ui/views/widget/widget_parent.h"
41 46
42 using views::Widget; 47 using views::Widget;
48 using views::WidgetParent;
43 49
44 namespace chromeos { 50 namespace chromeos {
45 51
46 namespace { 52 namespace {
47 53
48 gfx::NativeWindow GetParentForUnhostedDialog() { 54 gfx::NativeWindow GetParentForUnhostedDialog() {
49 if (LoginDisplayHost::default_host()) { 55 if (LoginDisplayHost::default_host()) {
50 return LoginDisplayHost::default_host()->GetNativeWindow(); 56 return LoginDisplayHost::default_host()->GetNativeWindow();
51 } else { 57 } else {
52 Browser* browser = chrome::FindTabbedBrowser( 58 Browser* browser = chrome::FindTabbedBrowser(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return child_config_view_ != nullptr; 119 return child_config_view_ != nullptr;
114 } 120 }
115 121
116 NetworkConfigView::~NetworkConfigView() { 122 NetworkConfigView::~NetworkConfigView() {
117 DCHECK(GetActiveDialog() == this); 123 DCHECK(GetActiveDialog() == this);
118 SetActiveDialog(nullptr); 124 SetActiveDialog(nullptr);
119 } 125 }
120 126
121 // static 127 // static
122 void NetworkConfigView::Show(const std::string& service_path, 128 void NetworkConfigView::Show(const std::string& service_path,
123 gfx::NativeWindow parent) { 129 const views::WidgetParent& widget_parent) {
124 if (GetActiveDialog() != nullptr) 130 if (GetActiveDialog() != nullptr)
125 return; 131 return;
126 NetworkConfigView* view = new NetworkConfigView(); 132 NetworkConfigView* view = new NetworkConfigView();
127 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 133 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
128 GetNetworkState(service_path); 134 GetNetworkState(service_path);
129 if (!network) { 135 if (!network) {
130 LOG(ERROR) << "NetworkConfigView::Show called with invalid service_path"; 136 LOG(ERROR) << "NetworkConfigView::Show called with invalid service_path";
131 return; 137 return;
132 } 138 }
133 if (!view->InitWithNetworkState(network)) { 139 if (!view->InitWithNetworkState(network)) {
134 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " 140 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: "
135 << network->type(); 141 << network->type();
136 delete view; 142 delete view;
137 return; 143 return;
138 } 144 }
139 NET_LOG(USER) << "NetworkConfigView::Show: " << service_path; 145 NET_LOG(USER) << "NetworkConfigView::Show: " << service_path;
140 view->ShowDialog(parent); 146 view->ShowDialog(widget_parent);
141 } 147 }
142 148
143 // static 149 // static
144 void NetworkConfigView::ShowForType(const std::string& type, 150 void NetworkConfigView::ShowForType(const std::string& type,
145 gfx::NativeWindow parent) { 151 const views::WidgetParent& widget_parent) {
146 if (GetActiveDialog() != nullptr) 152 if (GetActiveDialog() != nullptr)
147 return; 153 return;
148 NetworkConfigView* view = new NetworkConfigView(); 154 NetworkConfigView* view = new NetworkConfigView();
149 if (!view->InitWithType(type)) { 155 if (!view->InitWithType(type)) {
150 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " 156 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: "
151 << type; 157 << type;
152 delete view; 158 delete view;
153 return; 159 return;
154 } 160 }
155 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type; 161 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type;
156 view->ShowDialog(parent); 162 view->ShowDialog(widget_parent);
157 } 163 }
158 164
159 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { 165 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const {
160 return GetWidget()->GetNativeWindow(); 166 return GetWidget()->GetNativeWindow();
161 } 167 }
162 168
163 base::string16 NetworkConfigView::GetDialogButtonLabel( 169 base::string16 NetworkConfigView::GetDialogButtonLabel(
164 ui::DialogButton button) const { 170 ui::DialogButton button) const {
165 if (button == ui::DIALOG_BUTTON_OK) { 171 if (button == ui::DIALOG_BUTTON_OK) {
166 if (child_config_view_->IsConfigureDialog()) 172 if (child_config_view_->IsConfigureDialog())
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void NetworkConfigView::ViewHierarchyChanged( 273 void NetworkConfigView::ViewHierarchyChanged(
268 const ViewHierarchyChangedDetails& details) { 274 const ViewHierarchyChangedDetails& details) {
269 // Can't init before we're inserted into a Container, because we require 275 // Can't init before we're inserted into a Container, because we require
270 // a HWND to parent native child controls to. 276 // a HWND to parent native child controls to.
271 views::DialogDelegateView::ViewHierarchyChanged(details); 277 views::DialogDelegateView::ViewHierarchyChanged(details);
272 if (details.is_add && details.child == this) { 278 if (details.is_add && details.child == this) {
273 AddChildView(child_config_view_); 279 AddChildView(child_config_view_);
274 } 280 }
275 } 281 }
276 282
277 void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { 283 void NetworkConfigView::ShowDialog(const views::WidgetParent& widget_parent) {
278 if (parent == nullptr) 284 Widget::InitParams params = GetDialogWidgetInitParams(widget_parent);
279 parent = GetParentForUnhostedDialog(); 285 Widget* window = new Widget;
280 // Failed connections may result in a pop-up with no natural parent window, 286 window->Init(params);
281 // so provide a fallback context on the primary display. This is necessary
282 // becase one of parent or context must be non nullptr.
283 gfx::NativeWindow context =
284 parent ? nullptr : ash::Shell::GetPrimaryRootWindow();
285 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent);
286 window->SetAlwaysOnTop(true); 287 window->SetAlwaysOnTop(true);
287 window->Show(); 288 window->Show();
288 } 289 }
289 290
291 Widget::InitParams NetworkConfigView::GetDialogWidgetInitParams(
292 const views::WidgetParent& widget_parent) {
293 // Start with the usual params for a dialog.
294 Widget::InitParams params = DialogDelegate::GetDialogWidgetInitParams(
295 this, nullptr, nullptr, gfx::Rect());
296
297 if (chrome::IsRunningInMash()) {
298 // If the native window maps to a mus window, use that.
299 if (widget_parent.native_parent) {
300 params.parent_mus = aura::GetMusWindow(widget_parent.native_parent);
301 if (params.parent_mus)
302 return params;
303 }
304
305 // Use ash container id if available.
306 if (widget_parent.container_id != WidgetParent::kInvalidContainerId) {
307 using ui::mojom::WindowManager;
308 params.mus_properties[WindowManager::kInitialContainerId_Property] =
309 mojo::ConvertTo<std::vector<uint8_t>>(widget_parent.container_id);
310 return params;
311 }
312
313 // Use a fallback window. |parent_mus| may still be null, which will result
314 // in the default window placement based on type and last active display.
315 params.parent_mus = aura::GetMusWindow(GetParentForUnhostedDialog());
316 return params;
317 }
318
319 if (widget_parent.native_parent) {
320 params.parent = widget_parent.native_parent;
321 return params;
322 }
323
324 // Use ash container id if available.
325 if (widget_parent.container_id != WidgetParent::kInvalidContainerId) {
326 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
327 widget_parent.container_id);
328 return params;
329 }
330
331 // Use a fallback parent.
332 params.parent = GetParentForUnhostedDialog();
333 // Failed connections may result in a pop-up with no natural parent window,
334 // so provide a fallback context on the primary display. This is necessary
335 // becase one of parent or context must be non nullptr.
336 if (!params.parent)
337 params.context = ash::Shell::GetPrimaryRootWindow();
338 return params;
339 }
stevenjb 2016/10/19 17:40:07 This doesn't feel like it belongs here. I'm sure w
James Cook 2016/10/19 18:05:27 Yeah, I know. Copy/pasting what I said to sky in t
stevenjb 2016/10/19 18:23:38 Hrmm. Can we at least put this in an anonymous nam
340
290 // ChildNetworkConfigView 341 // ChildNetworkConfigView
291 342
292 ChildNetworkConfigView::ChildNetworkConfigView( 343 ChildNetworkConfigView::ChildNetworkConfigView(
293 NetworkConfigView* parent, 344 NetworkConfigView* parent,
294 const std::string& service_path) 345 const std::string& service_path)
295 : parent_(parent), 346 : parent_(parent),
296 service_path_(service_path) { 347 service_path_(service_path) {
297 } 348 }
298 349
299 ChildNetworkConfigView::~ChildNetworkConfigView() { 350 ChildNetworkConfigView::~ChildNetworkConfigView() {
(...skipping 28 matching lines...) Expand all
328 } 379 }
329 380
330 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} 381 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {}
331 382
332 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { 383 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const {
333 return (managed_ && visible()) ? image_view_->GetPreferredSize() 384 return (managed_ && visible()) ? image_view_->GetPreferredSize()
334 : gfx::Size(); 385 : gfx::Size();
335 } 386 }
336 387
337 } // namespace chromeos 388 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/network_config_view.h ('k') | chrome/browser/chromeos/status/network_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698