tab_contents_container_native.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" 6 7#include "chrome/browser/renderer_host/render_view_host.h" 8#include "chrome/browser/renderer_host/render_widget_host_view.h" 9#include "chrome/browser/tab_contents/interstitial_page.h" 10#include "chrome/browser/tab_contents/tab_contents.h" 11#include "chrome/browser/ui/view_ids.h" 12#include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" 13#include "chrome/common/notification_details.h" 14#include "chrome/common/notification_source.h" 15 16// Some of this class is implemented in tab_contents_container.cc, where 17// the implementation doesn't vary between a pure views approach and a 18// native view host approach. See the header file for details. 19 20//////////////////////////////////////////////////////////////////////////////// 21// TabContentsContainer, public: 22 23TabContentsContainer::TabContentsContainer() 24 : native_container_(NULL), 25 tab_contents_(NULL) { 26 SetID(VIEW_ID_TAB_CONTAINER); 27} 28 29void TabContentsContainer::SetReservedContentsRect( 30 const gfx::Rect& reserved_rect) { 31 cached_reserved_rect_ = reserved_rect; 32 if (tab_contents_ && tab_contents_->GetRenderWidgetHostView()) { 33 tab_contents_->GetRenderWidgetHostView()->set_reserved_contents_rect( 34 reserved_rect); 35 } 36} 37 38void TabContentsContainer::ChangeTabContents(TabContents* contents) { 39 if (tab_contents_) { 40 native_container_->DetachContents(tab_contents_); 41 tab_contents_->WasHidden(); 42 RemoveObservers(); 43 } 44 tab_contents_ = contents; 45 // When detaching the last tab of the browser ChangeTabContents is invoked 46 // with NULL. Don't attempt to do anything in that case. 47 if (tab_contents_) { 48 RenderWidgetHostViewChanged(tab_contents_->GetRenderWidgetHostView()); 49 native_container_->AttachContents(tab_contents_); 50 AddObservers(); 51 } 52} 53 54void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { 55 native_container_->TabContentsFocused(tab_contents); 56} 57 58void TabContentsContainer::SetFastResize(bool fast_resize) { 59 native_container_->SetFastResize(fast_resize); 60} 61 62//////////////////////////////////////////////////////////////////////////////// 63// TabContentsContainer, View overrides: 64 65void TabContentsContainer::Layout() { 66 if (native_container_) { 67 native_container_->GetView()->SetBounds(0, 0, width(), height()); 68 native_container_->GetView()->Layout(); 69 } 70} 71 72void TabContentsContainer::ViewHierarchyChanged(bool is_add, 73 views::View* parent, 74 views::View* child) { 75 if (is_add && child == this) { 76 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); 77 AddChildView(native_container_->GetView()); 78 } 79} 80 81//////////////////////////////////////////////////////////////////////////////// 82// TabContentsContainer, private: 83 84void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, 85 RenderViewHost* new_host) { 86 if (new_host) 87 RenderWidgetHostViewChanged(new_host->view()); 88 native_container_->RenderViewHostChanged(old_host, new_host); 89} 90