Commit 33c86b8f authored by levin@chromium.org's avatar levin@chromium.org

Change the panel using the improved way of doing autosizing.

Review URL: http://codereview.chromium.org/8774016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112792 0039d316-1c4b-4281-b951-d872f2087c98
parent e7104ae1
...@@ -115,12 +115,7 @@ void Panel::SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size) { ...@@ -115,12 +115,7 @@ void Panel::SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size) {
min_size_ = min_size; min_size_ = min_size;
max_size_ = max_size; max_size_ = max_size;
// Need to update the renderer on the new size range. ConfigureAutoResize(browser()->GetSelectedTabContents());
if (auto_resizable_) {
RenderViewHost* render_view_host = GetRenderViewHost();
if (render_view_host)
RequestRenderViewHostToDisableScrollbars(render_view_host);
}
} }
void Panel::SetExpansionState(ExpansionState new_state) { void Panel::SetExpansionState(ExpansionState new_state) {
...@@ -602,13 +597,10 @@ void Panel::TabInsertedAt(TabContentsWrapper* contents, ...@@ -602,13 +597,10 @@ void Panel::TabInsertedAt(TabContentsWrapper* contents,
void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) { void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) {
DCHECK(tab_contents); DCHECK(tab_contents);
RenderViewHost* render_view_host = tab_contents->render_view_host(); ConfigureAutoResize(tab_contents);
if (render_view_host)
EnableRendererAutoResize(render_view_host);
// We also need to know when the render view host changes in order // We also need to know when the render view host changes in order
// to turn on preferred size changed notifications in the new // to turn on auto-resize notifications in the new render view host.
// render view host.
registrar_.RemoveAll(); // Stop notifications for previous contents, if any. registrar_.RemoveAll(); // Stop notifications for previous contents, if any.
registrar_.Add( registrar_.Add(
this, this,
...@@ -619,43 +611,26 @@ void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) { ...@@ -619,43 +611,26 @@ void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) {
void Panel::Observe(int type, void Panel::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (auto_resizable_) { DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED);
DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); ConfigureAutoResize(content::Source<TabContents>(source).ptr());
RenderViewHost* render_view_host =
content::Source<TabContents>(source).ptr()->render_view_host();
if (render_view_host)
EnableRendererAutoResize(render_view_host);
}
} }
RenderViewHost* Panel::GetRenderViewHost() const { void Panel::ConfigureAutoResize(TabContents* tab_contents) {
TabContents* tab_contents = browser()->GetSelectedTabContents(); if (!auto_resizable_ || !tab_contents)
if (!tab_contents) return;
return NULL;
return tab_contents->render_view_host();
}
void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) { // NULL might be returned if the tab has not been added.
DCHECK(auto_resizable_); RenderViewHost* render_view_host = tab_contents->render_view_host();
DCHECK(render_view_host); if (!render_view_host)
render_view_host->EnablePreferredSizeMode(); return;
RequestRenderViewHostToDisableScrollbars(render_view_host);
}
void Panel::RequestRenderViewHostToDisableScrollbars( render_view_host->EnableAutoResize(
RenderViewHost* render_view_host) { min_size_,
DCHECK(auto_resizable_);
DCHECK(render_view_host);
render_view_host->DisableScrollbarsForThreshold(
native_panel_->ContentSizeFromWindowSize(max_size_)); native_panel_->ContentSizeFromWindowSize(max_size_));
} }
void Panel::OnWindowSizeAvailable() { void Panel::OnWindowSizeAvailable() {
if (auto_resizable_) { ConfigureAutoResize(browser()->GetSelectedTabContents());
RenderViewHost* render_view_host = GetRenderViewHost();
if (render_view_host)
RequestRenderViewHostToDisableScrollbars(render_view_host);
}
} }
void Panel::DestroyBrowser() { void Panel::DestroyBrowser() {
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
class NativePanel; class NativePanel;
class PanelManager; class PanelManager;
class RenderViewHost;
// A platform independent implementation of BrowserWindow for Panels. This // A platform independent implementation of BrowserWindow for Panels. This
// class would get the first crack at all the BrowserWindow calls for Panels and // class would get the first crack at all the BrowserWindow calls for Panels and
...@@ -250,20 +249,12 @@ class Panel : public BrowserWindow, ...@@ -250,20 +249,12 @@ class Panel : public BrowserWindow,
// size may differ after panel layout. // size may differ after panel layout.
Panel(Browser* browser, const gfx::Size& requested_size); Panel(Browser* browser, const gfx::Size& requested_size);
// NULL might be returned if the tab has not been added.
RenderViewHost* GetRenderViewHost() const;
// Configures the tab contents for auto resize, including configurations // Configures the tab contents for auto resize, including configurations
// on the renderer and detecting renderer changes. // on the renderer and detecting renderer changes.
void EnableTabContentsAutoResize(TabContents* tab_contents); void EnableTabContentsAutoResize(TabContents* tab_contents);
// Configures the renderer for auto resize. // Configures the renderer for auto resize (if auto resize is enabled).
void EnableRendererAutoResize(RenderViewHost* render_view_host); void ConfigureAutoResize(TabContents* tab_contents);
// Requests RenderViewHost not to show the scrollbars till |max_size_| since
// the panel can grow to |max_size_|.
void RequestRenderViewHostToDisableScrollbars(
RenderViewHost* render_view_host);
Browser* browser_; // Weak, owned by native panel. Browser* browser_; // Weak, owned by native panel.
......
...@@ -859,7 +859,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AutoResize) { ...@@ -859,7 +859,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AutoResize) {
EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
panel->browser()->GetSelectedTabContents()->render_view_host(), panel->browser()->GetSelectedTabContents()->render_view_host(),
std::wstring(), std::wstring(),
L"changeSize(50);")); L"changeSize(10);"));
enlarge.Wait(); enlarge.Wait();
gfx::Rect bounds_on_grow = panel->GetBounds(); gfx::Rect bounds_on_grow = panel->GetBounds();
EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); EXPECT_GT(bounds_on_grow.width(), initial_bounds.width());
...@@ -872,7 +872,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AutoResize) { ...@@ -872,7 +872,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_AutoResize) {
EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
panel->browser()->GetSelectedTabContents()->render_view_host(), panel->browser()->GetSelectedTabContents()->render_view_host(),
std::wstring(), std::wstring(),
L"changeSize(-30);")); L"changeSize(-5);"));
shrink.Wait(); shrink.Wait();
gfx::Rect bounds_on_shrink = panel->GetBounds(); gfx::Rect bounds_on_shrink = panel->GetBounds();
EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment