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