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" |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 581 } |
582 } | 582 } |
583 | 583 |
584 void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) { | 584 void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) { |
585 DCHECK(tab_contents); | 585 DCHECK(tab_contents); |
586 RenderViewHost* render_view_host = tab_contents->render_view_host(); | 586 RenderViewHost* render_view_host = tab_contents->render_view_host(); |
587 if (render_view_host) | 587 if (render_view_host) |
588 EnableRendererAutoResize(render_view_host); | 588 EnableRendererAutoResize(render_view_host); |
589 | 589 |
590 // We also need to know when the render view host changes in order | 590 // We also need to know when the render view host changes in order |
591 // to turn on preferred size changed notifications in the new | 591 // to turn on autosize notifications in the new render view host. |
592 // render view host. | |
593 registrar_.RemoveAll(); // Stop notifications for previous contents, if any. | 592 registrar_.RemoveAll(); // Stop notifications for previous contents, if any. |
594 registrar_.Add( | 593 registrar_.Add( |
595 this, | 594 this, |
596 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 595 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
597 content::Source<TabContents>(tab_contents)); | 596 content::Source<TabContents>(tab_contents)); |
598 } | 597 } |
599 | 598 |
600 void Panel::Observe(int type, | 599 void Panel::Observe(int type, |
601 const content::NotificationSource& source, | 600 const content::NotificationSource& source, |
602 const content::NotificationDetails& details) { | 601 const content::NotificationDetails& details) { |
603 if (auto_resizable_) { | 602 if (auto_resizable_) { |
604 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); | 603 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); |
605 RenderViewHost* render_view_host = | 604 RenderViewHost* render_view_host = |
606 content::Source<TabContents>(source).ptr()->render_view_host(); | 605 content::Source<TabContents>(source).ptr()->render_view_host(); |
607 if (render_view_host) | 606 if (render_view_host) |
608 EnableRendererAutoResize(render_view_host); | 607 EnableRendererAutoResize(render_view_host); |
609 } | 608 } |
610 } | 609 } |
611 | 610 |
612 RenderViewHost* Panel::GetRenderViewHost() const { | 611 RenderViewHost* Panel::GetRenderViewHost() const { |
613 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 612 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
614 if (!tab_contents) | 613 if (!tab_contents) |
615 return NULL; | 614 return NULL; |
616 return tab_contents->render_view_host(); | 615 return tab_contents->render_view_host(); |
617 } | 616 } |
618 | 617 |
619 void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) { | 618 void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) { |
620 DCHECK(auto_resizable_); | 619 DCHECK(auto_resizable_); |
621 DCHECK(render_view_host); | 620 DCHECK(render_view_host); |
622 render_view_host->EnablePreferredSizeMode(); | 621 render_view_host->EnableAutoResize( |
623 RequestRenderViewHostToDisableScrollbars(render_view_host); | 622 min_size_, |
624 } | |
625 | |
626 void Panel::RequestRenderViewHostToDisableScrollbars( | |
627 RenderViewHost* render_view_host) { | |
628 DCHECK(auto_resizable_); | |
629 DCHECK(render_view_host); | |
630 render_view_host->DisableScrollbarsForThreshold( | |
631 native_panel_->ContentSizeFromWindowSize(max_size_)); | 623 native_panel_->ContentSizeFromWindowSize(max_size_)); |
632 } | 624 } |
633 | 625 |
634 void Panel::OnWindowSizeAvailable() { | 626 void Panel::OnWindowSizeAvailable() { |
635 if (auto_resizable_) { | 627 if (auto_resizable_) { |
636 RenderViewHost* render_view_host = GetRenderViewHost(); | 628 RenderViewHost* render_view_host = GetRenderViewHost(); |
637 if (render_view_host) | 629 if (render_view_host) |
638 RequestRenderViewHostToDisableScrollbars(render_view_host); | 630 EnableRendererAutoResize(render_view_host); |
639 } | 631 } |
640 } | 632 } |
641 | 633 |
642 void Panel::DestroyBrowser() { | 634 void Panel::DestroyBrowser() { |
643 native_panel_->DestroyPanelBrowser(); | 635 native_panel_->DestroyPanelBrowser(); |
644 } | 636 } |
OLD | NEW |