OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/views/apps/chrome_native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
6 | 6 |
7 #include "apps/ui/views/app_window_frame_view.h" | 7 #include "apps/ui/views/app_window_frame_view.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/app_mode/app_mode_utils.h" | 10 #include "chrome/browser/app_mode/app_mode_utils.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. | 217 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. |
218 init_params.remove_standard_frame = true; | 218 init_params.remove_standard_frame = true; |
219 #endif | 219 #endif |
220 init_params.use_system_default_icon = true; | 220 init_params.use_system_default_icon = true; |
221 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 221 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
222 // could plumb context through to here in some cases. | 222 // could plumb context through to here in some cases. |
223 init_params.top_level = true; | 223 init_params.top_level = true; |
224 if (create_params.transparent_background) | 224 if (create_params.transparent_background) |
225 init_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 225 init_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
226 init_params.keep_on_top = create_params.always_on_top; | 226 init_params.keep_on_top = create_params.always_on_top; |
227 gfx::Rect window_bounds = create_params.bounds; | |
228 bool position_specified = | |
229 window_bounds.x() != INT_MIN && window_bounds.y() != INT_MIN; | |
230 if (position_specified && !window_bounds.IsEmpty()) | |
231 init_params.bounds = window_bounds; | |
232 | 227 |
233 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 228 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
234 // Set up a custom WM_CLASS for app windows. This allows task switchers in | 229 // Set up a custom WM_CLASS for app windows. This allows task switchers in |
235 // X11 environments to distinguish them from main browser windows. | 230 // X11 environments to distinguish them from main browser windows. |
236 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | 231 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); |
237 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); | 232 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); |
238 const char kX11WindowRoleApp[] = "app"; | 233 const char kX11WindowRoleApp[] = "app"; |
239 init_params.wm_role_name = std::string(kX11WindowRoleApp); | 234 init_params.wm_role_name = std::string(kX11WindowRoleApp); |
240 #endif | 235 #endif |
241 | 236 |
242 OnBeforeWidgetInit(&init_params, window()); | 237 OnBeforeWidgetInit(&init_params, window()); |
243 window()->Init(init_params); | 238 window()->Init(init_params); |
244 | 239 |
245 gfx::Rect adjusted_bounds = window_bounds; | 240 // The frame insets are required to resolve the bounds specifications |
246 adjusted_bounds.Inset(-GetFrameInsets()); | 241 // correctly. So we set the window bounds and constraints now. |
247 // Center window if no position was specified. | 242 gfx::Insets frame_insets = GetFrameInsets(); |
248 if (!position_specified) | 243 gfx::Rect window_bounds = create_params.GetInitialWindowBounds(frame_insets); |
249 window()->CenterWindow(adjusted_bounds.size()); | 244 SetContentMinimumSize(create_params.GetContentMinimumSize(frame_insets)); |
250 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | 245 SetContentMaximumSize(create_params.GetContentMaximumSize(frame_insets)); |
251 window()->SetBounds(adjusted_bounds); | 246 if (!window_bounds.IsEmpty()) { |
| 247 typedef apps::AppWindow::BoundsSpecification BoundsSpecification; |
| 248 bool position_specified = |
| 249 window_bounds.x() != BoundsSpecification::kUnspecifiedPosition && |
| 250 window_bounds.y() != BoundsSpecification::kUnspecifiedPosition; |
| 251 if (!position_specified) |
| 252 window()->CenterWindow(window_bounds.size()); |
| 253 else |
| 254 window()->SetBounds(window_bounds); |
| 255 } |
252 | 256 |
253 // Register accelarators supported by app windows. | 257 // Register accelarators supported by app windows. |
254 // TODO(jeremya/stevenjb): should these be registered for panels too? | 258 // TODO(jeremya/stevenjb): should these be registered for panels too? |
255 views::FocusManager* focus_manager = GetFocusManager(); | 259 views::FocusManager* focus_manager = GetFocusManager(); |
256 const std::map<ui::Accelerator, int>& accelerator_table = | 260 const std::map<ui::Accelerator, int>& accelerator_table = |
257 GetAcceleratorTable(); | 261 GetAcceleratorTable(); |
258 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); | 262 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); |
259 | 263 |
260 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be | 264 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be |
261 // future proof). This is needed because GetAcceleratorTable() uses a static | 265 // future proof). This is needed because GetAcceleratorTable() uses a static |
(...skipping 14 matching lines...) Expand all Loading... |
276 focus_manager->RegisterAccelerator( | 280 focus_manager->RegisterAccelerator( |
277 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 281 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
278 } | 282 } |
279 } | 283 } |
280 | 284 |
281 void ChromeNativeAppWindowViews::InitializePanelWindow( | 285 void ChromeNativeAppWindowViews::InitializePanelWindow( |
282 const AppWindow::CreateParams& create_params) { | 286 const AppWindow::CreateParams& create_params) { |
283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 287 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
284 params.delegate = this; | 288 params.delegate = this; |
285 | 289 |
286 preferred_size_ = gfx::Size(create_params.bounds.width(), | 290 gfx::Rect initial_window_bounds = |
287 create_params.bounds.height()); | 291 create_params.GetInitialWindowBounds(gfx::Insets()); |
| 292 preferred_size_ = gfx::Size(initial_window_bounds.width(), |
| 293 initial_window_bounds.height()); |
288 if (preferred_size_.width() == 0) | 294 if (preferred_size_.width() == 0) |
289 preferred_size_.set_width(kDefaultPanelWidth); | 295 preferred_size_.set_width(kDefaultPanelWidth); |
290 else if (preferred_size_.width() < kMinPanelWidth) | 296 else if (preferred_size_.width() < kMinPanelWidth) |
291 preferred_size_.set_width(kMinPanelWidth); | 297 preferred_size_.set_width(kMinPanelWidth); |
292 | 298 |
293 if (preferred_size_.height() == 0) | 299 if (preferred_size_.height() == 0) |
294 preferred_size_.set_height(kDefaultPanelHeight); | 300 preferred_size_.set_height(kDefaultPanelHeight); |
295 else if (preferred_size_.height() < kMinPanelHeight) | 301 else if (preferred_size_.height() < kMinPanelHeight) |
296 preferred_size_.set_height(kMinPanelHeight); | 302 preferred_size_.set_height(kMinPanelHeight); |
297 #if defined(USE_ASH) | 303 #if defined(USE_ASH) |
298 if (ash::Shell::HasInstance()) { | 304 if (ash::Shell::HasInstance()) { |
299 // Open a new panel on the target root. | 305 // Open a new panel on the target root. |
300 aura::Window* target = ash::Shell::GetTargetRootWindow(); | 306 aura::Window* target = ash::Shell::GetTargetRootWindow(); |
301 params.bounds = ash::ScreenUtil::ConvertRectToScreen( | 307 params.bounds = ash::ScreenUtil::ConvertRectToScreen( |
302 target, gfx::Rect(preferred_size_)); | 308 target, gfx::Rect(preferred_size_)); |
303 } else { | 309 } else { |
304 params.bounds = gfx::Rect(preferred_size_); | 310 params.bounds = gfx::Rect(preferred_size_); |
305 } | 311 } |
306 #else | 312 #else |
307 params.bounds = gfx::Rect(preferred_size_); | 313 params.bounds = gfx::Rect(preferred_size_); |
308 #endif | 314 #endif |
309 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 315 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
310 // could plumb context through to here in some cases. | 316 // could plumb context through to here in some cases. |
311 params.top_level = true; | 317 params.top_level = true; |
312 window()->Init(params); | 318 window()->Init(params); |
313 window()->set_focus_on_creation(create_params.focused); | 319 window()->set_focus_on_creation(create_params.focused); |
314 | 320 |
315 #if defined(USE_ASH) | 321 #if defined(USE_ASH) |
316 if (create_params.state == ui::SHOW_STATE_DETACHED) { | 322 if (create_params.state == ui::SHOW_STATE_DETACHED) { |
317 gfx::Rect window_bounds(create_params.bounds.x(), | 323 gfx::Rect window_bounds(initial_window_bounds.x(), |
318 create_params.bounds.y(), | 324 initial_window_bounds.y(), |
319 preferred_size_.width(), | 325 preferred_size_.width(), |
320 preferred_size_.height()); | 326 preferred_size_.height()); |
321 aura::Window* native_window = GetNativeWindow(); | 327 aura::Window* native_window = GetNativeWindow(); |
322 ash::wm::GetWindowState(native_window)->set_panel_attached(false); | 328 ash::wm::GetWindowState(native_window)->set_panel_attached(false); |
323 aura::client::ParentWindowWithContext(native_window, | 329 aura::client::ParentWindowWithContext(native_window, |
324 native_window->GetRootWindow(), | 330 native_window->GetRootWindow(), |
325 native_window->GetBoundsInScreen()); | 331 native_window->GetBoundsInScreen()); |
326 window()->SetBounds(window_bounds); | 332 window()->SetBounds(window_bounds); |
327 } | 333 } |
328 #else | 334 #else |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 NULL)); | 679 NULL)); |
674 | 680 |
675 #if defined(OS_WIN) | 681 #if defined(OS_WIN) |
676 if (!ShouldUseNativeFrame() && | 682 if (!ShouldUseNativeFrame() && |
677 chrome::GetHostDesktopTypeForNativeWindow(window()->GetNativeWindow()) != | 683 chrome::GetHostDesktopTypeForNativeWindow(window()->GetNativeWindow()) != |
678 chrome::HOST_DESKTOP_TYPE_ASH) { | 684 chrome::HOST_DESKTOP_TYPE_ASH) { |
679 InstallEasyResizeTargeterOnContainer(); | 685 InstallEasyResizeTargeterOnContainer(); |
680 } | 686 } |
681 #endif | 687 #endif |
682 } | 688 } |
OLD | NEW |