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) |
(...skipping 11 matching lines...) Expand all Loading... |
68 return true; | 90 return true; |
69 | 91 |
70 // Let the native panel decide. | 92 // Let the native panel decide. |
71 return native_panel_->ShouldBringUpPanelTitlebar(mouse_x, mouse_y); | 93 return native_panel_->ShouldBringUpPanelTitlebar(mouse_x, mouse_y); |
72 } | 94 } |
73 | 95 |
74 bool Panel::IsDrawingAttention() const { | 96 bool Panel::IsDrawingAttention() const { |
75 return native_panel_->IsDrawingAttention(); | 97 return native_panel_->IsDrawingAttention(); |
76 } | 98 } |
77 | 99 |
| 100 int Panel::GetRestoredHeight() const { |
| 101 return native_panel_->GetRestoredHeight(); |
| 102 } |
| 103 |
| 104 void Panel::SetRestoredHeight(int height) { |
| 105 native_panel_->SetRestoredHeight(height); |
| 106 } |
| 107 |
78 void Panel::Show() { | 108 void Panel::Show() { |
79 native_panel_->ShowPanel(); | 109 native_panel_->ShowPanel(); |
80 } | 110 } |
81 | 111 |
82 void Panel::ShowInactive() { | 112 void Panel::ShowInactive() { |
83 native_panel_->ShowPanelInactive(); | 113 native_panel_->ShowPanelInactive(); |
84 } | 114 } |
85 | 115 |
86 void Panel::SetBounds(const gfx::Rect& bounds) { | 116 void Panel::SetBounds(const gfx::Rect& bounds) { |
87 // Ignore any SetBounds requests since the bounds are completely controlled | 117 // Ignore any SetBounds requests since the bounds are completely controlled |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 FindBar* Panel::CreateFindBar() { | 468 FindBar* Panel::CreateFindBar() { |
439 return native_panel_->CreatePanelFindBar(); | 469 return native_panel_->CreatePanelFindBar(); |
440 } | 470 } |
441 | 471 |
442 #if defined(OS_CHROMEOS) | 472 #if defined(OS_CHROMEOS) |
443 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { | 473 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { |
444 NOTIMPLEMENTED(); | 474 NOTIMPLEMENTED(); |
445 } | 475 } |
446 #endif | 476 #endif |
447 | 477 |
| 478 void Panel::UpdatePreferredSize(TabContents* tab_contents, |
| 479 const gfx::Size& pref_size) { |
| 480 gfx::Size non_client_size = native_panel_->GetNonClientAreaExtent(); |
| 481 return manager()->OnPreferredWindowSizeChanged(this, |
| 482 gfx::Size(pref_size.width() + non_client_size.width(), |
| 483 pref_size.height() + non_client_size.height())); |
| 484 } |
| 485 |
| 486 void Panel::Observe(int type, |
| 487 const NotificationSource& source, |
| 488 const NotificationDetails& details) { |
| 489 switch (type) { |
| 490 case content::NOTIFICATION_TAB_ADDED: |
| 491 case content::NOTIFICATION_TAB_CONTENTS_SWAPPED: { |
| 492 RenderViewHost* render_view_host = GetRenderViewHost(); |
| 493 DCHECK(render_view_host); |
| 494 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( |
| 495 render_view_host->routing_id(), |
| 496 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); |
| 497 RequestRenderViewHostToDisableScrollbars(render_view_host); |
| 498 break; |
| 499 } |
| 500 default: |
| 501 NOTREACHED() << "Got a notification we didn't register for!"; |
| 502 break; |
| 503 } |
| 504 } |
| 505 |
| 506 RenderViewHost* Panel::GetRenderViewHost() const { |
| 507 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 508 if (!tab_contents) |
| 509 return NULL; |
| 510 return tab_contents->render_view_host(); |
| 511 } |
| 512 |
| 513 void Panel::RequestRenderViewHostToDisableScrollbars( |
| 514 RenderViewHost* render_view_host) { |
| 515 DCHECK(render_view_host); |
| 516 |
| 517 gfx::Size non_client_size = native_panel_->GetNonClientAreaExtent(); |
| 518 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( |
| 519 render_view_host->routing_id(), |
| 520 gfx::Size(max_size_.width() - non_client_size.width(), |
| 521 max_size_.height() - non_client_size.height()))); |
| 522 } |
| 523 |
448 Browser* Panel::browser() const { | 524 Browser* Panel::browser() const { |
449 return native_panel_->GetPanelBrowser(); | 525 return native_panel_->GetPanelBrowser(); |
450 } | 526 } |
451 | 527 |
452 void Panel::DestroyBrowser() { | 528 void Panel::DestroyBrowser() { |
453 native_panel_->DestroyPanelBrowser(); | 529 native_panel_->DestroyPanelBrowser(); |
454 } | 530 } |
OLD | NEW |