| 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* win = GetNativeWindow(); |
| 276 create_params.bounds); | 278 win->SetProperty(ash::internal::kPanelAttachedKey, false); |
| 277 window_->SetBounds(window_bounds); | 279 win->SetDefaultParentByRootWindow( |
| 280 win->GetRootWindow(), |
| 281 win->GetBoundsInScreen()); |
| 282 window_->SetBounds(window_bounds); |
| 283 } |
| 284 #else |
| 285 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
| 286 // platforms. |
| 278 #endif | 287 #endif |
| 279 } | 288 } |
| 280 | 289 |
| 281 // BaseWindow implementation. | 290 // BaseWindow implementation. |
| 282 | 291 |
| 283 bool NativeAppWindowViews::IsActive() const { | 292 bool NativeAppWindowViews::IsActive() const { |
| 284 return window_->IsActive(); | 293 return window_->IsActive(); |
| 285 } | 294 } |
| 286 | 295 |
| 287 bool NativeAppWindowViews::IsMaximized() const { | 296 bool NativeAppWindowViews::IsMaximized() const { |
| 288 return window_->IsMaximized(); | 297 return window_->IsMaximized(); |
| 289 } | 298 } |
| 290 | 299 |
| 291 bool NativeAppWindowViews::IsMinimized() const { | 300 bool NativeAppWindowViews::IsMinimized() const { |
| 292 return window_->IsMinimized(); | 301 return window_->IsMinimized(); |
| 293 } | 302 } |
| 294 | 303 |
| 295 bool NativeAppWindowViews::IsFullscreen() const { | 304 bool NativeAppWindowViews::IsFullscreen() const { |
| 296 return window_->IsFullscreen(); | 305 return window_->IsFullscreen(); |
| 297 } | 306 } |
| 298 | 307 |
| 299 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { | 308 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { |
| 300 return window_->GetNativeWindow(); | 309 return window_->GetNativeWindow(); |
| 301 } | 310 } |
| 302 | 311 |
| 303 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { | 312 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { |
| 304 return window_->GetRestoredBounds(); | 313 return window_->GetRestoredBounds(); |
| 305 } | 314 } |
| 306 | 315 |
| 316 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { |
| 317 if (IsMaximized()) |
| 318 return ui::SHOW_STATE_MAXIMIZED; |
| 319 #if defined(USE_ASH) |
| 320 // On Ash, restore fullscreen. |
| 321 if (IsFullscreen()) |
| 322 return ui::SHOW_STATE_FULLSCREEN; |
| 323 // Use kRestoreShowStateKey in case a window is minimized/hidden. |
| 324 ui::WindowShowState restore_state = |
| 325 window_->GetNativeWindow()->GetProperty( |
| 326 aura::client::kRestoreShowStateKey); |
| 327 if (restore_state != ui::SHOW_STATE_MINIMIZED) |
| 328 return restore_state; |
| 329 #endif |
| 330 return ui::SHOW_STATE_NORMAL; |
| 331 } |
| 332 |
| 307 gfx::Rect NativeAppWindowViews::GetBounds() const { | 333 gfx::Rect NativeAppWindowViews::GetBounds() const { |
| 308 return window_->GetWindowBoundsInScreen(); | 334 return window_->GetWindowBoundsInScreen(); |
| 309 } | 335 } |
| 310 | 336 |
| 311 void NativeAppWindowViews::Show() { | 337 void NativeAppWindowViews::Show() { |
| 312 if (window_->IsVisible()) { | 338 if (window_->IsVisible()) { |
| 313 window_->Activate(); | 339 window_->Activate(); |
| 314 return; | 340 return; |
| 315 } | 341 } |
| 316 | 342 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 window_->SetFullscreen(fullscreen); | 684 window_->SetFullscreen(fullscreen); |
| 659 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 685 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 660 // ever drop the window out of fullscreen in response to something that | 686 // ever drop the window out of fullscreen in response to something that |
| 661 // wasn't the app calling webkitCancelFullScreen(). | 687 // wasn't the app calling webkitCancelFullScreen(). |
| 662 } | 688 } |
| 663 | 689 |
| 664 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 690 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 665 return is_fullscreen_; | 691 return is_fullscreen_; |
| 666 } | 692 } |
| 667 | 693 |
| 694 bool NativeAppWindowViews::IsDetached() const { |
| 695 if (!shell_window_->window_type_is_panel()) |
| 696 return false; |
| 697 #if defined(USE_ASH) |
| 698 return !window_->GetNativeWindow()->GetProperty( |
| 699 ash::internal::kPanelAttachedKey); |
| 700 #else |
| 701 return false; |
| 702 #endif |
| 703 } |
| 704 |
| 668 views::View* NativeAppWindowViews::GetContentsView() { | 705 views::View* NativeAppWindowViews::GetContentsView() { |
| 669 return this; | 706 return this; |
| 670 } | 707 } |
| 671 | 708 |
| 672 void NativeAppWindowViews::UpdateWindowIcon() { | 709 void NativeAppWindowViews::UpdateWindowIcon() { |
| 673 window_->UpdateWindowIcon(); | 710 window_->UpdateWindowIcon(); |
| 674 } | 711 } |
| 675 | 712 |
| 676 void NativeAppWindowViews::UpdateWindowTitle() { | 713 void NativeAppWindowViews::UpdateWindowTitle() { |
| 677 window_->UpdateWindowTitle(); | 714 window_->UpdateWindowTitle(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 698 } | 735 } |
| 699 | 736 |
| 700 //------------------------------------------------------------------------------ | 737 //------------------------------------------------------------------------------ |
| 701 // NativeAppWindow::Create | 738 // NativeAppWindow::Create |
| 702 | 739 |
| 703 // static | 740 // static |
| 704 NativeAppWindow* NativeAppWindow::Create( | 741 NativeAppWindow* NativeAppWindow::Create( |
| 705 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 742 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 706 return new NativeAppWindowViews(shell_window, params); | 743 return new NativeAppWindowViews(shell_window, params); |
| 707 } | 744 } |
| OLD | NEW |