Chromium Code Reviews| Index: chrome/browser/ui/panels/panel.cc |
| =================================================================== |
| --- chrome/browser/ui/panels/panel.cc (revision 95921) |
| +++ chrome/browser/ui/panels/panel.cc (working copy) |
| @@ -8,12 +8,16 @@ |
| #include "chrome/browser/extensions/extension_prefs.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "content/browser/renderer_host/render_view_host.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/panels/native_panel.h" |
| #include "chrome/browser/ui/panels/panel_manager.h" |
| #include "chrome/browser/ui/window_sizer.h" |
| #include "chrome/browser/web_applications/web_app.h" |
| #include "chrome/common/extensions/extension.h" |
| +#include "content/browser/tab_contents/tab_contents.h" |
| +#include "content/common/content_notification_types.h" |
| +#include "content/common/view_messages.h" |
| #include "ui/gfx/rect.h" |
| // static |
| @@ -27,9 +31,15 @@ |
| } |
| Panel::Panel(Browser* browser, const gfx::Rect& bounds) |
| - : native_panel_(NULL), |
| + : min_size_(bounds.size()), |
| + max_size_(bounds.size()), |
| + native_panel_(NULL), |
| expansion_state_(EXPANDED) { |
| native_panel_ = CreateNativePanel(browser, this, bounds); |
| + |
| + registrar_.Add(this, |
| + content::NOTIFICATION_TAB_ADDED, |
| + Source<TabContentsDelegate>(browser)); |
| } |
| Panel::~Panel() { |
| @@ -44,6 +54,24 @@ |
| native_panel_->SetPanelBounds(bounds); |
| } |
| +void Panel::SetMaxSize(const gfx::Size& max_size) { |
| + if (max_size_ == max_size) |
| + return; |
| + max_size_ = max_size; |
| + |
| + // Tell the renderer not to show the scroll bar till |max_size_| since the |
| + // panel can grow to |max_size_|. |
| + // Note: It might be possible that the tab is not created yet. If so, we will |
| + // send the message when NOTIFICATION_TAB_ADDED is received. |
| + 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.
|
| + if (!tab_contents) |
| + return; |
| + RenderViewHost* render_view_host = tab_contents->render_view_host(); |
| + if (!render_view_host) |
| + return; |
| + RequestRenderViewHostToDisableScrollbars(render_view_host); |
| +} |
| + |
| void Panel::SetExpansionState(ExpansionState new_expansion_state) { |
| if (expansion_state_ == new_expansion_state) |
| return; |
| @@ -70,6 +98,14 @@ |
| return native_panel_->IsDrawingAttention(); |
| } |
| +int Panel::GetRestoredHeight() const { |
| + return native_panel_->GetRestoredHeight(); |
| +} |
| + |
| +void Panel::SetRestoredHeight(int height) { |
| + native_panel_->SetRestoredHeight(height); |
| +} |
| + |
| void Panel::Show() { |
| native_panel_->ShowPanel(); |
| } |
| @@ -427,6 +463,42 @@ |
| } |
| #endif |
| +void Panel::UpdatePreferredSize(const gfx::Size& pref_size) { |
| + gfx::Size non_client_size = native_panel_->GetNonClientAreaSize(); |
| + return manager()->OnPreferredWindowSizeChanged(this, |
| + gfx::Size(pref_size.width() + non_client_size.width(), |
| + pref_size.height() + non_client_size.height())); |
| +} |
| + |
| +void Panel::Observe(int type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + switch (type) { |
| + case content::NOTIFICATION_TAB_ADDED: { |
| + RenderViewHost* render_view_host = |
| + 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.
|
| + render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( |
| + render_view_host->routing_id(), |
| + kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow)); |
| + RequestRenderViewHostToDisableScrollbars(render_view_host); |
| + } |
| + default: |
| + NOTREACHED() << "Got a notification we didn't register for!"; |
| + break; |
| + } |
| +} |
| + |
| +void Panel::RequestRenderViewHostToDisableScrollbars( |
| + RenderViewHost* render_view_host) { |
| + DCHECK(render_view_host); |
| + |
| + gfx::Size non_client_size = native_panel_->GetNonClientAreaSize(); |
| + render_view_host->Send(new ViewMsg_DisableScrollbarsForSmallWindows( |
| + render_view_host->routing_id(), |
| + gfx::Size(max_size_.width() - non_client_size.width(), |
| + max_size_.height() - non_client_size.height()))); |
| +} |
| + |
| Browser* Panel::browser() const { |
| return native_panel_->GetPanelBrowser(); |
| } |