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

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: typo 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/public/cpp/shell_window_ids.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
13 #include "chrome/browser/chromeos/options/network_property_ui_data.h" 14 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
14 #include "chrome/browser/chromeos/options/vpn_config_view.h" 15 #include "chrome/browser/chromeos/options/vpn_config_view.h"
15 #include "chrome/browser/chromeos/options/wifi_config_view.h" 16 #include "chrome/browser/chromeos/options/wifi_config_view.h"
16 #include "chrome/browser/chromeos/options/wimax_config_view.h" 17 #include "chrome/browser/chromeos/options/wimax_config_view.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/ui/ash/ash_util.h"
18 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
22 #include "chrome/grit/locale_settings.h" 24 #include "chrome/grit/locale_settings.h"
23 #include "chromeos/login/login_state.h" 25 #include "chromeos/login/login_state.h"
24 #include "chromeos/network/network_state.h" 26 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h" 27 #include "chromeos/network/network_state_handler.h"
26 #include "components/device_event_log/device_event_log.h" 28 #include "components/device_event_log/device_event_log.h"
27 #include "components/user_manager/user.h" 29 #include "components/user_manager/user.h"
30 #include "services/ui/public/cpp/property_type_converters.h"
31 #include "services/ui/public/interfaces/window_manager.mojom.h"
28 #include "ui/accessibility/ax_view_state.h" 32 #include "ui/accessibility/ax_view_state.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"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 116 }
113 return child_config_view_ != nullptr; 117 return child_config_view_ != nullptr;
114 } 118 }
115 119
116 NetworkConfigView::~NetworkConfigView() { 120 NetworkConfigView::~NetworkConfigView() {
117 DCHECK(GetActiveDialog() == this); 121 DCHECK(GetActiveDialog() == this);
118 SetActiveDialog(nullptr); 122 SetActiveDialog(nullptr);
119 } 123 }
120 124
121 // static 125 // static
122 void NetworkConfigView::Show(const std::string& service_path, 126 void NetworkConfigView::ShowByServicePath(const std::string& service_path,
123 gfx::NativeWindow parent) { 127 gfx::NativeWindow parent) {
128 DCHECK(parent);
124 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 129 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
125 GetNetworkState(service_path); 130 GetNetworkState(service_path);
126 ShowByNetwork(network, parent); 131 ShowByNetwork(network, parent, ash::kShellWindowId_Invalid);
127 } 132 }
128 133
129 // static 134 // static
130 void NetworkConfigView::ShowByNetworkId(const std::string& network_id, 135 void NetworkConfigView::ShowByNetworkId(const std::string& network_id,
131 gfx::NativeWindow parent) { 136 int container_id) {
137 DCHECK_NE(container_id, ash::kShellWindowId_Invalid);
132 const NetworkState* network = 138 const NetworkState* network =
133 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( 139 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
134 network_id); 140 network_id);
135 ShowByNetwork(network, parent); 141 ShowByNetwork(network, nullptr, container_id);
136 } 142 }
137 143
138 // static 144 // static
139 void NetworkConfigView::ShowByNetwork(const NetworkState* network, 145 void NetworkConfigView::ShowByNetwork(const NetworkState* network,
140 gfx::NativeWindow parent) { 146 gfx::NativeWindow parent,
147 int container_id) {
148 DCHECK(parent || container_id != ash::kShellWindowId_Invalid);
141 if (GetActiveDialog() != nullptr) 149 if (GetActiveDialog() != nullptr)
142 return; 150 return;
143 if (!network) { 151 if (!network) {
144 LOG(ERROR) << "NetworkConfigView::Show called with invalid network"; 152 LOG(ERROR) << "NetworkConfigView::Show called with invalid network";
145 return; 153 return;
146 } 154 }
147 NetworkConfigView* view = new NetworkConfigView(); 155 NetworkConfigView* view = new NetworkConfigView();
148 if (!view->InitWithNetworkState(network)) { 156 if (!view->InitWithNetworkState(network)) {
149 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " 157 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: "
150 << network->type(); 158 << network->type();
151 delete view; 159 delete view;
152 return; 160 return;
153 } 161 }
154 NET_LOG(USER) << "NetworkConfigView::Show: " << network->path(); 162 NET_LOG(USER) << "NetworkConfigView::Show: " << network->path();
155 view->ShowDialog(parent); 163 if (parent)
164 view->ShowDialog(parent);
165 else
166 view->ShowDialogInContainer(container_id);
156 } 167 }
157 168
158 // static 169 // static
159 void NetworkConfigView::ShowForType(const std::string& type, 170 void NetworkConfigView::ShowForType(const std::string& type,
160 gfx::NativeWindow parent) { 171 gfx::NativeWindow parent) {
161 if (GetActiveDialog() != nullptr) 172 if (GetActiveDialog() != nullptr)
162 return; 173 return;
163 NetworkConfigView* view = new NetworkConfigView(); 174 NetworkConfigView* view = new NetworkConfigView();
164 if (!view->InitWithType(type)) { 175 if (!view->InitWithType(type)) {
165 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " 176 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: "
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Failed connections may result in a pop-up with no natural parent window, 306 // Failed connections may result in a pop-up with no natural parent window,
296 // so provide a fallback context on the primary display. This is necessary 307 // so provide a fallback context on the primary display. This is necessary
297 // becase one of parent or context must be non nullptr. 308 // becase one of parent or context must be non nullptr.
298 gfx::NativeWindow context = 309 gfx::NativeWindow context =
299 parent ? nullptr : ash::Shell::GetPrimaryRootWindow(); 310 parent ? nullptr : ash::Shell::GetPrimaryRootWindow();
300 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); 311 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent);
301 window->SetAlwaysOnTop(true); 312 window->SetAlwaysOnTop(true);
302 window->Show(); 313 window->Show();
303 } 314 }
304 315
316 void NetworkConfigView::ShowDialogInContainer(int container_id) {
317 DCHECK_NE(container_id, ash::kShellWindowId_Invalid);
318 Widget::InitParams params = DialogDelegate::GetDialogWidgetInitParams(
319 this, nullptr, nullptr, gfx::Rect());
320 Widget* window = new Widget;
321 if (chrome::IsRunningInMash()) {
322 using ui::mojom::WindowManager;
323 params.mus_properties[WindowManager::kInitialContainerId_Property] =
324 mojo::ConvertTo<std::vector<uint8_t>>(container_id);
325 } else {
326 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
327 container_id);
328 }
329 window->Init(params);
330 window->SetAlwaysOnTop(true);
331 window->Show();
332 }
333
305 // ChildNetworkConfigView 334 // ChildNetworkConfigView
306 335
307 ChildNetworkConfigView::ChildNetworkConfigView( 336 ChildNetworkConfigView::ChildNetworkConfigView(
308 NetworkConfigView* parent, 337 NetworkConfigView* parent,
309 const std::string& service_path) 338 const std::string& service_path)
310 : parent_(parent), 339 : parent_(parent),
311 service_path_(service_path) { 340 service_path_(service_path) {
312 } 341 }
313 342
314 ChildNetworkConfigView::~ChildNetworkConfigView() { 343 ChildNetworkConfigView::~ChildNetworkConfigView() {
(...skipping 28 matching lines...) Expand all
343 } 372 }
344 373
345 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} 374 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {}
346 375
347 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { 376 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const {
348 return (managed_ && visible()) ? image_view_->GetPreferredSize() 377 return (managed_ && visible()) ? image_view_->GetPreferredSize()
349 : gfx::Size(); 378 : gfx::Size();
350 } 379 }
351 380
352 } // namespace chromeos 381 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698