OLD | NEW |
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/ui/views/extensions/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/extensions/native_app_window_views.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "ui/base/win/shell.h" | 33 #include "ui/base/win/shell.h" |
34 #endif | 34 #endif |
35 | 35 |
36 #if defined(USE_ASH) | 36 #if defined(USE_ASH) |
37 #include "ash/screen_ash.h" | 37 #include "ash/screen_ash.h" |
38 #include "ash/shell.h" | 38 #include "ash/shell.h" |
39 #include "ash/wm/custom_frame_view_ash.h" | 39 #include "ash/wm/custom_frame_view_ash.h" |
40 #include "ash/wm/panels/panel_frame_view.h" | 40 #include "ash/wm/panels/panel_frame_view.h" |
41 #include "ash/wm/window_properties.h" | 41 #include "ash/wm/window_properties.h" |
42 #include "chrome/browser/ui/ash/ash_util.h" | 42 #include "chrome/browser/ui/ash/ash_util.h" |
| 43 #include "ui/aura/client/aura_constants.h" |
43 #include "ui/aura/root_window.h" | 44 #include "ui/aura/root_window.h" |
| 45 #include "ui/aura/window.h" |
44 #endif | 46 #endif |
45 | 47 |
46 namespace { | 48 namespace { |
47 | 49 |
48 const int kMinPanelWidth = 100; | 50 const int kMinPanelWidth = 100; |
49 const int kMinPanelHeight = 100; | 51 const int kMinPanelHeight = 100; |
50 const int kDefaultPanelWidth = 200; | 52 const int kDefaultPanelWidth = 200; |
51 const int kDefaultPanelHeight = 300; | 53 const int kDefaultPanelHeight = 300; |
52 const int kResizeInsideBoundsSize = 5; | 54 const int kResizeInsideBoundsSize = 5; |
53 | 55 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 261 } |
260 #else | 262 #else |
261 params.bounds = gfx::Rect(preferred_size_); | 263 params.bounds = gfx::Rect(preferred_size_); |
262 #endif | 264 #endif |
263 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 265 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
264 // could plumb context through to here in some cases. | 266 // could plumb context through to here in some cases. |
265 params.top_level = true; | 267 params.top_level = true; |
266 window_->Init(params); | 268 window_->Init(params); |
267 window_->set_focus_on_creation(create_params.focused); | 269 window_->set_focus_on_creation(create_params.focused); |
268 | 270 |
269 #if !defined(USE_ASH) | 271 #if defined(USE_ASH) |
270 // TODO(oshima|stevenjb): Ideally, we should be able to just pre-determine | 272 if (create_params.state == ui::SHOW_STATE_DETACHED) { |
271 // the exact location and size, but this doesn't work well | 273 gfx::Rect window_bounds(create_params.bounds.x(), |
272 // on non-ash environment where we don't have full control over | 274 create_params.bounds.y(), |
273 // window management. | 275 preferred_size_.width(), |
274 gfx::Rect window_bounds = | 276 preferred_size_.height()); |
275 window_->non_client_view()->GetWindowBoundsForClientBounds( | 277 aura::Window* native_window = GetNativeWindow(); |
276 create_params.bounds); | 278 native_window->SetProperty(ash::internal::kPanelAttachedKey, false); |
277 window_->SetBounds(window_bounds); | 279 native_window->SetDefaultParentByRootWindow( |
| 280 native_window->GetRootWindow(), native_window->GetBoundsInScreen()); |
| 281 window_->SetBounds(window_bounds); |
| 282 } |
| 283 #else |
| 284 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
| 285 // platforms. |
278 #endif | 286 #endif |
279 } | 287 } |
280 | 288 |
281 // BaseWindow implementation. | 289 // BaseWindow implementation. |
282 | 290 |
283 bool NativeAppWindowViews::IsActive() const { | 291 bool NativeAppWindowViews::IsActive() const { |
284 return window_->IsActive(); | 292 return window_->IsActive(); |
285 } | 293 } |
286 | 294 |
287 bool NativeAppWindowViews::IsMaximized() const { | 295 bool NativeAppWindowViews::IsMaximized() const { |
288 return window_->IsMaximized(); | 296 return window_->IsMaximized(); |
289 } | 297 } |
290 | 298 |
291 bool NativeAppWindowViews::IsMinimized() const { | 299 bool NativeAppWindowViews::IsMinimized() const { |
292 return window_->IsMinimized(); | 300 return window_->IsMinimized(); |
293 } | 301 } |
294 | 302 |
295 bool NativeAppWindowViews::IsFullscreen() const { | 303 bool NativeAppWindowViews::IsFullscreen() const { |
296 return window_->IsFullscreen(); | 304 return window_->IsFullscreen(); |
297 } | 305 } |
298 | 306 |
299 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { | 307 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { |
300 return window_->GetNativeWindow(); | 308 return window_->GetNativeWindow(); |
301 } | 309 } |
302 | 310 |
303 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { | 311 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { |
304 return window_->GetRestoredBounds(); | 312 return window_->GetRestoredBounds(); |
305 } | 313 } |
306 | 314 |
| 315 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { |
| 316 if (IsMaximized()) |
| 317 return ui::SHOW_STATE_MAXIMIZED; |
| 318 #if defined(USE_ASH) |
| 319 // On Ash, restore fullscreen. |
| 320 if (IsFullscreen()) |
| 321 return ui::SHOW_STATE_FULLSCREEN; |
| 322 // Use kRestoreShowStateKey in case a window is minimized/hidden. |
| 323 ui::WindowShowState restore_state = |
| 324 window_->GetNativeWindow()->GetProperty( |
| 325 aura::client::kRestoreShowStateKey); |
| 326 if (restore_state != ui::SHOW_STATE_MINIMIZED) |
| 327 return restore_state; |
| 328 #endif |
| 329 return ui::SHOW_STATE_NORMAL; |
| 330 } |
| 331 |
307 gfx::Rect NativeAppWindowViews::GetBounds() const { | 332 gfx::Rect NativeAppWindowViews::GetBounds() const { |
308 return window_->GetWindowBoundsInScreen(); | 333 return window_->GetWindowBoundsInScreen(); |
309 } | 334 } |
310 | 335 |
311 void NativeAppWindowViews::Show() { | 336 void NativeAppWindowViews::Show() { |
312 if (window_->IsVisible()) { | 337 if (window_->IsVisible()) { |
313 window_->Activate(); | 338 window_->Activate(); |
314 return; | 339 return; |
315 } | 340 } |
316 | 341 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 window_->SetFullscreen(fullscreen); | 693 window_->SetFullscreen(fullscreen); |
669 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 694 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
670 // ever drop the window out of fullscreen in response to something that | 695 // ever drop the window out of fullscreen in response to something that |
671 // wasn't the app calling webkitCancelFullScreen(). | 696 // wasn't the app calling webkitCancelFullScreen(). |
672 } | 697 } |
673 | 698 |
674 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 699 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
675 return is_fullscreen_; | 700 return is_fullscreen_; |
676 } | 701 } |
677 | 702 |
| 703 bool NativeAppWindowViews::IsDetached() const { |
| 704 if (!shell_window_->window_type_is_panel()) |
| 705 return false; |
| 706 #if defined(USE_ASH) |
| 707 return !window_->GetNativeWindow()->GetProperty( |
| 708 ash::internal::kPanelAttachedKey); |
| 709 #else |
| 710 return false; |
| 711 #endif |
| 712 } |
| 713 |
678 views::View* NativeAppWindowViews::GetContentsView() { | 714 views::View* NativeAppWindowViews::GetContentsView() { |
679 return this; | 715 return this; |
680 } | 716 } |
681 | 717 |
682 void NativeAppWindowViews::UpdateWindowIcon() { | 718 void NativeAppWindowViews::UpdateWindowIcon() { |
683 window_->UpdateWindowIcon(); | 719 window_->UpdateWindowIcon(); |
684 } | 720 } |
685 | 721 |
686 void NativeAppWindowViews::UpdateWindowTitle() { | 722 void NativeAppWindowViews::UpdateWindowTitle() { |
687 window_->UpdateWindowTitle(); | 723 window_->UpdateWindowTitle(); |
(...skipping 20 matching lines...) Expand all Loading... |
708 } | 744 } |
709 | 745 |
710 //------------------------------------------------------------------------------ | 746 //------------------------------------------------------------------------------ |
711 // NativeAppWindow::Create | 747 // NativeAppWindow::Create |
712 | 748 |
713 // static | 749 // static |
714 NativeAppWindow* NativeAppWindow::Create( | 750 NativeAppWindow* NativeAppWindow::Create( |
715 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 751 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
716 return new NativeAppWindowViews(shell_window, params); | 752 return new NativeAppWindowViews(shell_window, params); |
717 } | 753 } |
OLD | NEW |