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 // Tell the renderer not to show the scroll bar till |max_size_| since the | |
63 // panel can grow to |max_size_|. | |
64 // Note: It might be possible that the tab is not created yet. If so, we will | |
65 // send the message when NOTIFICATION_TAB_ADDED is received. | |
66 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
Dmitry Titov
2011/08/09 21:08:16
This code to pull the RVH is repeated at elast twi
jianli
2011/08/09 22:15:49
I added a helper function GetRenderViewHost.
| |
67 if (!tab_contents) | |
68 return; | |
69 RenderViewHost* render_view_host = tab_contents->render_view_host(); | |
70 if (!render_view_host) | |
71 return; | |
72 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
73 } | |
74 | |
47 void Panel::SetExpansionState(ExpansionState new_expansion_state) { | 75 void Panel::SetExpansionState(ExpansionState new_expansion_state) { |
48 if (expansion_state_ == new_expansion_state) | 76 if (expansion_state_ == new_expansion_state) |
49 return; | 77 return; |
50 | 78 |
51 expansion_state_ = new_expansion_state; | 79 expansion_state_ = new_expansion_state; |
52 | 80 |
53 native_panel_->OnPanelExpansionStateChanged(expansion_state_); | 81 native_panel_->OnPanelExpansionStateChanged(expansion_state_); |
54 | 82 |
55 // The minimized panel should not get the focus. | 83 // The minimized panel should not get the focus. |
56 if (expansion_state_ == MINIMIZED) | 84 if (expansion_state_ == MINIMIZED) |
57 Deactivate(); | 85 Deactivate(); |
58 } | 86 } |
59 | 87 |
60 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { | 88 bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { |
61 // Skip the expanded panel. | 89 // Skip the expanded panel. |
62 if (expansion_state_ == Panel::EXPANDED) | 90 if (expansion_state_ == Panel::EXPANDED) |
63 return false; | 91 return false; |
64 | 92 |
65 // Let the native panel decide. | 93 // Let the native panel decide. |
66 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); | 94 return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); |
67 } | 95 } |
68 | 96 |
69 bool Panel::IsDrawingAttention() const { | 97 bool Panel::IsDrawingAttention() const { |
70 return native_panel_->IsDrawingAttention(); | 98 return native_panel_->IsDrawingAttention(); |
71 } | 99 } |
72 | 100 |
101 int Panel::GetRestoredHeight() const { | |
102 return native_panel_->GetRestoredHeight(); | |
103 } | |
104 | |
105 void Panel::SetRestoredHeight(int height) { | |
106 native_panel_->SetRestoredHeight(height); | |
107 } | |
108 | |
73 void Panel::Show() { | 109 void Panel::Show() { |
74 native_panel_->ShowPanel(); | 110 native_panel_->ShowPanel(); |
75 } | 111 } |
76 | 112 |
77 void Panel::ShowInactive() { | 113 void Panel::ShowInactive() { |
78 native_panel_->ShowPanelInactive(); | 114 native_panel_->ShowPanelInactive(); |
79 } | 115 } |
80 | 116 |
81 void Panel::SetBounds(const gfx::Rect& bounds) { | 117 void Panel::SetBounds(const gfx::Rect& bounds) { |
82 // Ignore any SetBounds requests since the bounds are completely controlled | 118 // 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() { | 456 FindBar* Panel::CreateFindBar() { |
421 return native_panel_->CreatePanelFindBar(); | 457 return native_panel_->CreatePanelFindBar(); |
422 } | 458 } |
423 | 459 |
424 #if defined(OS_CHROMEOS) | 460 #if defined(OS_CHROMEOS) |
425 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { | 461 void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { |
426 NOTIMPLEMENTED(); | 462 NOTIMPLEMENTED(); |
427 } | 463 } |
428 #endif | 464 #endif |
429 | 465 |
466 void Panel::UpdatePreferredSize(const gfx::Size& pref_size) { | |
467 gfx::Size non_client_size = native_panel_->GetNonClientAreaSize(); | |
468 return manager()->OnPreferredWindowSizeChanged(this, | |
469 gfx::Size(pref_size.width() + non_client_size.width(), | |
470 pref_size.height() + non_client_size.height())); | |
471 } | |
472 | |
473 void Panel::Observe(int type, | |
474 const NotificationSource& source, | |
475 const NotificationDetails& details) { | |
476 switch (type) { | |
477 case content::NOTIFICATION_TAB_ADDED: { | |
478 RenderViewHost* render_view_host = | |
479 browser()->GetSelectedTabContents()->render_view_host(); | |
Dmitry Titov
2011/08/09 21:08:16
In SetMaxSize, you have checks for TC and RVH bein
jianli
2011/08/09 22:15:49
Done.
| |
480 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( | |
481 render_view_host->routing_id(), | |
482 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); | |
483 RequestRenderViewHostToDisableScrollbars(render_view_host); | |
484 } | |
485 default: | |
486 NOTREACHED() << "Got a notification we didn't register for!"; | |
487 break; | |
488 } | |
489 } | |
490 | |
491 void Panel::RequestRenderViewHostToDisableScrollbars( | |
492 RenderViewHost* render_view_host) { | |
493 DCHECK(render_view_host); | |
494 | |
495 gfx::Size non_client_size = native_panel_->GetNonClientAreaSize(); | |
496 render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( | |
497 render_view_host->routing_id(), | |
498 gfx::Size(max_size_.width() - non_client_size.width(), | |
499 max_size_.height() - non_client_size.height()))); | |
500 } | |
501 | |
430 Browser* Panel::browser() const { | 502 Browser* Panel::browser() const { |
431 return native_panel_->GetPanelBrowser(); | 503 return native_panel_->GetPanelBrowser(); |
432 } | 504 } |
433 | 505 |
434 void Panel::DestroyBrowser() { | 506 void Panel::DestroyBrowser() { |
435 native_panel_->DestroyPanelBrowser(); | 507 native_panel_->DestroyPanelBrowser(); |
436 } | 508 } |
OLD | NEW |