| 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 "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" | 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 10 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 web_view_(NULL), | 50 web_view_(NULL), |
| 51 window_(NULL), | 51 window_(NULL), |
| 52 is_fullscreen_(false), | 52 is_fullscreen_(false), |
| 53 frameless_(create_params.frame == ShellWindow::FRAME_NONE), | 53 frameless_(create_params.frame == ShellWindow::FRAME_NONE), |
| 54 transparent_background_(create_params.transparent_background) { | 54 transparent_background_(create_params.transparent_background) { |
| 55 Observe(shell_window_->web_contents()); | 55 Observe(shell_window_->web_contents()); |
| 56 minimum_size_ = create_params.minimum_size; | 56 minimum_size_ = create_params.minimum_size; |
| 57 maximum_size_ = create_params.maximum_size; | 57 maximum_size_ = create_params.maximum_size; |
| 58 | 58 |
| 59 window_ = new views::Widget; | 59 window_ = new views::Widget; |
| 60 if (create_params.window_type == ShellWindow::WINDOW_TYPE_PANEL) | 60 if (create_params.window_type == ShellWindow::WINDOW_TYPE_PANEL || |
| 61 create_params.window_type == ShellWindow::WINDOW_TYPE_V1_PANEL) { |
| 61 InitializePanelWindow(create_params); | 62 InitializePanelWindow(create_params); |
| 62 else | 63 } else { |
| 63 InitializeDefaultWindow(create_params); | 64 InitializeDefaultWindow(create_params); |
| 64 | 65 } |
| 65 extension_keybinding_registry_.reset( | 66 extension_keybinding_registry_.reset( |
| 66 new ExtensionKeybindingRegistryViews( | 67 new ExtensionKeybindingRegistryViews( |
| 67 profile(), | 68 profile(), |
| 68 window_->GetFocusManager(), | 69 window_->GetFocusManager(), |
| 69 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 70 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 70 shell_window_)); | 71 shell_window_)); |
| 71 | 72 |
| 72 OnViewWasResized(); | 73 OnViewWasResized(); |
| 73 window_->AddObserver(this); | 74 window_->AddObserver(this); |
| 74 } | 75 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 229 |
| 229 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | 230 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { |
| 230 GetWidget()->SetBounds(bounds); | 231 GetWidget()->SetBounds(bounds); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void NativeAppWindowViews::FlashFrame(bool flash) { | 234 void NativeAppWindowViews::FlashFrame(bool flash) { |
| 234 window_->FlashFrame(flash); | 235 window_->FlashFrame(flash); |
| 235 } | 236 } |
| 236 | 237 |
| 237 bool NativeAppWindowViews::IsAlwaysOnTop() const { | 238 bool NativeAppWindowViews::IsAlwaysOnTop() const { |
| 238 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL; | 239 return shell_window_->window_type_is_panel(); |
| 239 } | 240 } |
| 240 | 241 |
| 241 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 242 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
| 242 if (frameless()) | 243 if (frameless()) |
| 243 return gfx::Insets(); | 244 return gfx::Insets(); |
| 244 | 245 |
| 245 // The pretend client_bounds passed in need to be large enough to ensure that | 246 // The pretend client_bounds passed in need to be large enough to ensure that |
| 246 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 247 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
| 247 // the specified amount of space to fit the window controls in, and return a | 248 // the specified amount of space to fit the window controls in, and return a |
| 248 // number larger than the real frame insets. Most window controls are smaller | 249 // number larger than the real frame insets. Most window controls are smaller |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 325 |
| 325 bool NativeAppWindowViews::CanMaximize() const { | 326 bool NativeAppWindowViews::CanMaximize() const { |
| 326 return maximum_size_.IsEmpty(); | 327 return maximum_size_.IsEmpty(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 string16 NativeAppWindowViews::GetWindowTitle() const { | 330 string16 NativeAppWindowViews::GetWindowTitle() const { |
| 330 return shell_window_->GetTitle(); | 331 return shell_window_->GetTitle(); |
| 331 } | 332 } |
| 332 | 333 |
| 333 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 334 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
| 334 return false; | 335 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_V1_PANEL; |
| 335 } | 336 } |
| 336 | 337 |
| 337 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | 338 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { |
| 338 gfx::Image app_icon = shell_window_->app_icon(); | 339 gfx::Image app_icon = shell_window_->app_icon(); |
| 339 if (app_icon.IsEmpty()) | 340 if (app_icon.IsEmpty()) |
| 340 return GetWindowIcon(); | 341 return GetWindowIcon(); |
| 341 else | 342 else |
| 342 return *app_icon.ToImageSkia(); | 343 return *app_icon.ToImageSkia(); |
| 343 } | 344 } |
| 344 | 345 |
| 345 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { | 346 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { |
| 346 content::WebContents* web_contents = shell_window_->web_contents(); | 347 content::WebContents* web_contents = shell_window_->web_contents(); |
| 347 if (web_contents) { | 348 if (web_contents) { |
| 348 FaviconTabHelper* favicon_tab_helper = | 349 FaviconTabHelper* favicon_tab_helper = |
| 349 FaviconTabHelper::FromWebContents(web_contents); | 350 FaviconTabHelper::FromWebContents(web_contents); |
| 350 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | 351 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); |
| 351 if (!app_icon.IsEmpty()) | 352 if (!app_icon.IsEmpty()) |
| 352 return *app_icon.ToImageSkia(); | 353 return *app_icon.ToImageSkia(); |
| 353 } | 354 } |
| 354 return gfx::ImageSkia(); | 355 return gfx::ImageSkia(); |
| 355 } | 356 } |
| 356 | 357 |
| 358 bool NativeAppWindowViews::ShouldShowWindowIcon() const { |
| 359 return shell_window_->window_type() == ShellWindow::WINDOW_TYPE_V1_PANEL; |
| 360 } |
| 361 |
| 357 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | 362 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, |
| 358 ui::WindowShowState show_state) { | 363 ui::WindowShowState show_state) { |
| 359 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 364 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
| 360 shell_window_->OnNativeWindowChanged(); | 365 shell_window_->OnNativeWindowChanged(); |
| 361 } | 366 } |
| 362 | 367 |
| 363 void NativeAppWindowViews::DeleteDelegate() { | 368 void NativeAppWindowViews::DeleteDelegate() { |
| 364 window_->RemoveObserver(this); | 369 window_->RemoveObserver(this); |
| 365 shell_window_->OnNativeClose(); | 370 shell_window_->OnNativeClose(); |
| 366 } | 371 } |
| 367 | 372 |
| 368 views::Widget* NativeAppWindowViews::GetWidget() { | 373 views::Widget* NativeAppWindowViews::GetWidget() { |
| 369 return window_; | 374 return window_; |
| 370 } | 375 } |
| 371 | 376 |
| 372 const views::Widget* NativeAppWindowViews::GetWidget() const { | 377 const views::Widget* NativeAppWindowViews::GetWidget() const { |
| 373 return window_; | 378 return window_; |
| 374 } | 379 } |
| 375 | 380 |
| 376 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 381 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
| 377 views::Widget* widget) { | 382 views::Widget* widget) { |
| 378 #if defined(USE_ASH) | 383 #if defined(USE_ASH) |
| 379 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 384 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 380 if (shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL) { | 385 if (shell_window_->window_type_is_panel()) { |
| 381 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 386 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
| 382 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 387 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 383 return new ash::PanelFrameView(widget, frame_type); | 388 return new ash::PanelFrameView(widget, frame_type); |
| 384 } | 389 } |
| 385 if (!frameless_) { | 390 if (!frameless_) { |
| 386 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 391 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); |
| 387 frame->Init(widget); | 392 frame->Init(widget); |
| 388 return frame; | 393 return frame; |
| 389 } | 394 } |
| 390 } | 395 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 475 } |
| 471 | 476 |
| 472 void NativeAppWindowViews::OnFocus() { | 477 void NativeAppWindowViews::OnFocus() { |
| 473 web_view_->RequestFocus(); | 478 web_view_->RequestFocus(); |
| 474 } | 479 } |
| 475 | 480 |
| 476 // NativeAppWindow implementation. | 481 // NativeAppWindow implementation. |
| 477 | 482 |
| 478 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 483 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { |
| 479 // Fullscreen not supported by panels. | 484 // Fullscreen not supported by panels. |
| 480 if (shell_window_->window_type() == ShellWindow::WINDOW_TYPE_PANEL) | 485 if (shell_window_->window_type_is_panel()) |
| 481 return; | 486 return; |
| 482 is_fullscreen_ = fullscreen; | 487 is_fullscreen_ = fullscreen; |
| 483 window_->SetFullscreen(fullscreen); | 488 window_->SetFullscreen(fullscreen); |
| 484 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 489 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 485 // ever drop the window out of fullscreen in response to something that | 490 // ever drop the window out of fullscreen in response to something that |
| 486 // wasn't the app calling webkitCancelFullScreen(). | 491 // wasn't the app calling webkitCancelFullScreen(). |
| 487 } | 492 } |
| 488 | 493 |
| 489 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 494 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 490 return is_fullscreen_; | 495 return is_fullscreen_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 528 } |
| 524 | 529 |
| 525 //------------------------------------------------------------------------------ | 530 //------------------------------------------------------------------------------ |
| 526 // NativeAppWindow::Create | 531 // NativeAppWindow::Create |
| 527 | 532 |
| 528 // static | 533 // static |
| 529 NativeAppWindow* NativeAppWindow::Create( | 534 NativeAppWindow* NativeAppWindow::Create( |
| 530 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 535 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 531 return new NativeAppWindowViews(shell_window, params); | 536 return new NativeAppWindowViews(shell_window, params); |
| 532 } | 537 } |
| OLD | NEW |