Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: chrome/browser/ui/panels/panel.cc

Issue 8704005: Add autoresize capability to chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 573 }
574 } 574 }
575 575
576 void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) { 576 void Panel::EnableTabContentsAutoResize(TabContents* tab_contents) {
577 DCHECK(tab_contents); 577 DCHECK(tab_contents);
578 RenderViewHost* render_view_host = tab_contents->render_view_host(); 578 RenderViewHost* render_view_host = tab_contents->render_view_host();
579 if (render_view_host) 579 if (render_view_host)
580 EnableRendererAutoResize(render_view_host); 580 EnableRendererAutoResize(render_view_host);
581 581
582 // We also need to know when the render view host changes in order 582 // We also need to know when the render view host changes in order
583 // to turn on preferred size changed notifications in the new 583 // to turn on autosize in the new render view host.
584 // render view host.
585 registrar_.RemoveAll(); // Stop notifications for previous contents, if any. 584 registrar_.RemoveAll(); // Stop notifications for previous contents, if any.
586 registrar_.Add( 585 registrar_.Add(
587 this, 586 this,
588 content::NOTIFICATION_TAB_CONTENTS_SWAPPED, 587 content::NOTIFICATION_TAB_CONTENTS_SWAPPED,
589 content::Source<TabContents>(tab_contents)); 588 content::Source<TabContents>(tab_contents));
590 } 589 }
591 590
592 void Panel::Observe(int type, 591 void Panel::Observe(int type,
593 const content::NotificationSource& source, 592 const content::NotificationSource& source,
594 const content::NotificationDetails& details) { 593 const content::NotificationDetails& details) {
595 if (auto_resizable_) { 594 if (auto_resizable_) {
596 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED); 595 DCHECK_EQ(type, content::NOTIFICATION_TAB_CONTENTS_SWAPPED);
597 RenderViewHost* render_view_host = 596 RenderViewHost* render_view_host =
598 content::Source<TabContents>(source).ptr()->render_view_host(); 597 content::Source<TabContents>(source).ptr()->render_view_host();
599 if (render_view_host) 598 if (render_view_host)
600 EnableRendererAutoResize(render_view_host); 599 EnableRendererAutoResize(render_view_host);
601 } 600 }
602 } 601 }
603 602
604 RenderViewHost* Panel::GetRenderViewHost() const { 603 RenderViewHost* Panel::GetRenderViewHost() const {
605 TabContents* tab_contents = browser()->GetSelectedTabContents(); 604 TabContents* tab_contents = browser()->GetSelectedTabContents();
606 if (!tab_contents) 605 if (!tab_contents)
607 return NULL; 606 return NULL;
608 return tab_contents->render_view_host(); 607 return tab_contents->render_view_host();
609 } 608 }
610 609
611 void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) { 610 void Panel::EnableRendererAutoResize(RenderViewHost* render_view_host) {
612 DCHECK(auto_resizable_); 611 DCHECK(auto_resizable_);
613 DCHECK(render_view_host); 612 DCHECK(render_view_host);
614 render_view_host->EnablePreferredSizeMode(); 613 render_view_host->EnableAutoResize(
615 RequestRenderViewHostToDisableScrollbars(render_view_host); 614 min_size_,
616 }
617
618 void Panel::RequestRenderViewHostToDisableScrollbars(
619 RenderViewHost* render_view_host) {
620 DCHECK(auto_resizable_);
621 DCHECK(render_view_host);
622 render_view_host->DisableScrollbarsForThreshold(
623 native_panel_->ContentSizeFromWindowSize(max_size_)); 615 native_panel_->ContentSizeFromWindowSize(max_size_));
624 } 616 }
625 617
626 void Panel::OnWindowSizeAvailable() {
jennb 2011/11/28 18:02:24 We still need this because on GTK, ContentSizeFrom
627 if (auto_resizable_) {
628 RenderViewHost* render_view_host = GetRenderViewHost();
629 if (render_view_host)
630 RequestRenderViewHostToDisableScrollbars(render_view_host);
631 }
632 }
633
634 Browser* Panel::browser() const { 618 Browser* Panel::browser() const {
635 return native_panel_->GetPanelBrowser(); 619 return native_panel_->GetPanelBrowser();
636 } 620 }
637 621
638 void Panel::DestroyBrowser() { 622 void Panel::DestroyBrowser() {
639 native_panel_->DestroyPanelBrowser(); 623 native_panel_->DestroyPanelBrowser();
640 } 624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698