Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/panels/panel.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/browser/renderer_host/render_view_host.h" | |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/panels/native_panel.h" | 13 #include "chrome/browser/ui/panels/native_panel.h" |
| 13 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/browser/ui/window_sizer.h" | 15 #include "chrome/browser/ui/window_sizer.h" |
| 15 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | |
| 19 #include "content/common/content_notification_types.h" | |
| 20 #include "content/common/view_messages.h" | |
| 17 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 18 | 22 |
| 19 // static | 23 // static |
| 20 const Extension* Panel::GetExtension(Browser* browser) { | 24 const Extension* Panel::GetExtension(Browser* browser) { |
| 21 // Find the extension. When we create a panel from an extension, the extension | 25 // Find the extension. When we create a panel from an extension, the extension |
| 22 // ID is passed as the app name to the Browser. | 26 // ID is passed as the app name to the Browser. |
| 23 ExtensionService* extension_service = | 27 ExtensionService* extension_service = |
| 24 browser->GetProfile()->GetExtensionService(); | 28 browser->GetProfile()->GetExtensionService(); |
| 25 return extension_service->GetExtensionById( | 29 return extension_service->GetExtensionById( |
| 26 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); | 30 web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); |
| 27 } | 31 } |
| 28 | 32 |
| 29 Panel::Panel(Browser* browser, const gfx::Rect& bounds) | 33 Panel::Panel(Browser* browser, const gfx::Rect& bounds) |
| 30 : native_panel_(NULL), | 34 : min_size_(bounds.size()), |
| 35 max_size_(bounds.size()), | |
| 36 native_panel_(NULL), | |
| 31 expansion_state_(EXPANDED) { | 37 expansion_state_(EXPANDED) { |
| 32 native_panel_ = CreateNativePanel(browser, this, bounds); | 38 native_panel_ = CreateNativePanel(browser, this, bounds); |
| 39 | |
| 40 registrar_.Add(this, | |
| 41 content::NOTIFICATION_TAB_ADDED, | |
| 42 Source<TabContentsDelegate>(browser)); | |
| 33 } | 43 } |
| 34 | 44 |
| 35 Panel::~Panel() { | 45 Panel::~Panel() { |
| 36 // Invoked by native panel so do not access native_panel_ here. | 46 // Invoked by native panel so do not access native_panel_ here. |
| 37 } | 47 } |
| 38 | 48 |
| 39 PanelManager* Panel::manager() const { | 49 PanelManager* Panel::manager() const { |
| 40 return PanelManager::GetInstance(); | 50 return PanelManager::GetInstance(); |
| 41 } | 51 } |
| 42 | 52 |
| 43 void Panel::SetPanelBounds(const gfx::Rect& bounds) { | 53 void Panel::SetPanelBounds(const gfx::Rect& bounds) { |
| 44 native_panel_->SetPanelBounds(bounds); | 54 native_panel_->SetPanelBounds(bounds); |
| 45 } | 55 } |
| 46 | 56 |
| 57 void Panel::SetMaxSize(const gfx::Size& max_size) { | |
| 58 if (max_size_ == max_size) | |
| 59 return; | |
| 60 max_size_ = max_size; | |
| 61 | |
| 62 // Note: |render_view_host| might be NULL if the tab has not been created. | |
| 63 // If so, we will do it when NOTIFICATION_TAB_ADDED is received. | |
| 64 RenderViewHost* render_view_host = GetRenderViewHost(); | |
| 65 if (render_view_host) | |
| 66 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
| 67 } | |
| 68 | |
| 47 void Panel::SetExpansionState(ExpansionState new_expansion_state) { | 69 void Panel::SetExpansionState(ExpansionState new_expansion_state) { |
| 48 if (expansion_state_ == new_expansion_state) | 70 if (expansion_state_ == new_expansion_state) |
| 49 return; | 71 return; |
| 50 | 72 |
| 51 expansion_state_ = new_expansion_state; | 73 expansion_state_ = new_expansion_state; |
| 52 | 74 |
| 53 native_panel_->OnPanelExpansionStateChanged(expansion_state_); | 75 native_panel_->OnPanelExpansionStateChanged(expansion_state_); |
| 54 | 76 |
| 55 // The minimized panel should not get the focus. | 77 // The minimized panel should not get the focus. |
| 56 if (expansion_state_ == MINIMIZED) | 78 if (expansion_state_ == MINIMIZED) |
| 57 Deactivate(); | 79 Deactivate(); |
| 58 } | 80 } |
| 59 | 81 |
| 60 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { | 82 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { |
| 61 // Skip the expanded panel. | 83 // Skip the expanded panel. |
| 62 if (expansion_state_ == Panel::EXPANDED) | 84 if (expansion_state_ == Panel::EXPANDED) |
| 63 return false; | 85 return false; |
| 64 | 86 |
| 65 // Let the native panel decide. | 87 // Let the native panel decide. |
| 66 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); | 88 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); |
| 67 } | 89 } |
| 68 | 90 |
| 69 bool Panel::IsDrawingAttention() const { | 91 bool Panel::IsDrawingAttention() const { |
| 70 return native_panel_->IsDrawingAttention(); | 92 return native_panel_->IsDrawingAttention(); |
| 71 } | 93 } |
| 72 | 94 |
| 95 int Panel::GetRestoredHeight() const { | |
| 96 return native_panel_->GetRestoredHeight(); | |
| 97 } | |
| 98 | |
| 99 void Panel::SetRestoredHeight(int height) { | |
| 100 native_panel_->SetRestoredHeight(height); | |
| 101 } | |
| 102 | |
| 73 void Panel::Show() { | 103 void Panel::Show() { |
| 74 native_panel_->ShowPanel(); | 104 native_panel_->ShowPanel(); |
| 75 } | 105 } |
| 76 | 106 |
| 77 void Panel::ShowInactive() { | 107 void Panel::ShowInactive() { |
| 78 native_panel_->ShowPanelInactive(); | 108 native_panel_->ShowPanelInactive(); |
| 79 } | 109 } |
| 80 | 110 |
| 81 void Panel::SetBounds(const gfx::Rect& bounds) { | 111 void Panel::SetBounds(const gfx::Rect& bounds) { |
| 82 // Ignore any SetBounds requests since the bounds are completely controlled | 112 // Ignore any SetBounds requests since the bounds are completely controlled |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 FindBar* Panel::CreateFindBar() { | 450 FindBar* Panel::CreateFindBar() { |
| 421 return native_panel_->CreatePanelFindBar(); | 451 return native_panel_->CreatePanelFindBar(); |
| 422 } | 452 } |
| 423 | 453 |
| 424 #if defined(OS_CHROMEOS) | 454 #if defined(OS_CHROMEOS) |
| 425 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { | 455 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { |
| 426 NOTIMPLEMENTED(); | 456 NOTIMPLEMENTED(); |
| 427 } | 457 } |
| 428 #endif | 458 #endif |
| 429 | 459 |
| 460 void Panel::UpdatePreferredSize(const gfx::Size& pref_size) { | |
| 461 gfx::Size non_client_size = native_panel_->GetNonClientAreaExtent(); | |
| 462 return manager()->OnPreferredWindowSizeChanged(this, | |
| 463 gfx::Size(pref_size.width() + non_client_size.width(), | |
| 464 pref_size.height() + non_client_size.height())); | |
| 465 } | |
| 466 | |
| 467 void Panel::Observe(int type, | |
| 468 const NotificationSource& source, | |
| 469 const NotificationDetails& details) { | |
| 470 switch (type) { | |
| 471 case content::NOTIFICATION_TAB_ADDED: { | |
| 472 RenderViewHost* render_view_host = GetRenderViewHost(); | |
| 473 DCHECK(render_view_host); | |
| 474 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( | |
|
brettw
2011/08/10 23:39:36
This seems wrong. What about cross site transition
jianli
2011/08/10 23:57:18
I want to notify RenderViewHost to enable preferre
| |
| 475 render_view_host->routing_id(), | |
| 476 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); | |
| 477 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
| 478 } | |
| 479 default: | |
| 480 NOTREACHED() << "Got a notification we didn't register for!"; | |
| 481 break; | |
| 482 } | |
| 483 } | |
| 484 | |
| 485 RenderViewHost* Panel::GetRenderViewHost() const { | |
| 486 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 487 if (!tab_contents) | |
| 488 return NULL; | |
| 489 return tab_contents->render_view_host(); | |
| 490 } | |
| 491 | |
| 492 void Panel::RequestRenderViewHostToDisableScrollbars( | |
| 493 RenderViewHost* render_view_host) { | |
| 494 DCHECK(render_view_host); | |
| 495 | |
| 496 gfx::Size non_client_size = native_panel_->GetNonClientAreaExtent(); | |
| 497 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( | |
| 498 render_view_host->routing_id(), | |
| 499 gfx::Size(max_size_.width() - non_client_size.width(), | |
| 500 max_size_.height() - non_client_size.height()))); | |
| 501 } | |
| 502 | |
| 430 Browser* Panel::browser() const { | 503 Browser* Panel::browser() const { |
| 431 return native_panel_->GetPanelBrowser(); | 504 return native_panel_->GetPanelBrowser(); |
| 432 } | 505 } |
| 433 | 506 |
| 434 void Panel::DestroyBrowser() { | 507 void Panel::DestroyBrowser() { |
| 435 native_panel_->DestroyPanelBrowser(); | 508 native_panel_->DestroyPanelBrowser(); |
| 436 } | 509 } |
| OLD | NEW |