Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/views/tab_contents/tab_contents_container.h" | 5 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_view_host.h" | 7 #include "chrome/browser/renderer_host/render_view_host.h" |
| 8 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 8 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 9 #include "chrome/browser/tab_contents/interstitial_page.h" | 9 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/ui/view_ids.h" | 11 #include "chrome/browser/ui/view_ids.h" |
| 12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" | 12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" |
| 13 #include "chrome/common/notification_details.h" | 13 #include "chrome/common/notification_details.h" |
| 14 #include "chrome/common/notification_source.h" | 14 #include "chrome/common/notification_source.h" |
| 15 | 15 |
| 16 #if defined(TOUCH_UI) | 16 // Some of this class is implemented in tab_contents_container.cc, where |
| 17 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk .h" | 17 // the implementation doesn't vary between a pure views approach and a |
| 18 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" | 18 // native view host approach. See the header file for details. |
| 19 #include "views/border.h" | |
| 20 #include "views/fill_layout.h" | |
| 21 #endif | |
| 22 | 19 |
| 23 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 24 // TabContentsContainer, public: | 21 // TabContentsContainer, public: |
| 25 | 22 |
| 26 TabContentsContainer::TabContentsContainer() | 23 TabContentsContainer::TabContentsContainer() |
| 27 : native_container_(NULL), | 24 : native_container_(NULL), |
| 28 tab_contents_(NULL), | 25 tab_contents_(NULL), |
| 29 reserved_area_delegate_(NULL) { | 26 reserved_area_delegate_(NULL) { |
| 30 SetID(VIEW_ID_TAB_CONTAINER); | 27 SetID(VIEW_ID_TAB_CONTAINER); |
| 31 } | 28 } |
| 32 | 29 |
| 33 TabContentsContainer::~TabContentsContainer() { | |
| 34 if (tab_contents_) | |
| 35 RemoveObservers(); | |
| 36 } | |
| 37 | |
| 38 void TabContentsContainer::ChangeTabContents(TabContents* contents) { | 30 void TabContentsContainer::ChangeTabContents(TabContents* contents) { |
| 39 if (tab_contents_) { | 31 if (tab_contents_) { |
| 40 #if !defined(TOUCH_UI) | |
| 41 native_container_->DetachContents(tab_contents_); | 32 native_container_->DetachContents(tab_contents_); |
| 42 #else | |
| 43 views::View *v = static_cast<TabContentsViewViews*>(tab_contents_->view()); | |
| 44 RemoveChildView(v); | |
| 45 #endif | |
| 46 tab_contents_->WasHidden(); | 33 tab_contents_->WasHidden(); |
| 47 RemoveObservers(); | 34 RemoveObservers(); |
| 48 } | 35 } |
| 49 #if !defined(TOUCH_UI) | |
| 50 TabContents* old_contents = tab_contents_; | 36 TabContents* old_contents = tab_contents_; |
| 51 #endif | |
| 52 tab_contents_ = contents; | 37 tab_contents_ = contents; |
| 53 // When detaching the last tab of the browser ChangeTabContents is invoked | 38 // When detaching the last tab of the browser ChangeTabContents is invoked |
| 54 // with NULL. Don't attempt to do anything in that case. | 39 // with NULL. Don't attempt to do anything in that case. |
| 55 if (tab_contents_) { | 40 if (tab_contents_) { |
| 56 #if defined(TOUCH_UI) | |
| 57 views::View *v = static_cast<TabContentsViewViews*>(contents->view()); | |
| 58 // Guard against re-adding ourselves, which happens because the NULL | |
| 59 // value is ignored by the pre-existing if() above. | |
| 60 if (v->GetParent() != this) { | |
| 61 AddChildView(v); | |
| 62 SetLayoutManager(new views::FillLayout()); | |
| 63 Layout(); | |
| 64 } | |
| 65 #else | |
| 66 RenderWidgetHostViewChanged( | 41 RenderWidgetHostViewChanged( |
| 67 old_contents ? old_contents->GetRenderWidgetHostView() : NULL, | 42 old_contents ? old_contents->GetRenderWidgetHostView() : NULL, |
| 68 tab_contents_->GetRenderWidgetHostView()); | 43 tab_contents_->GetRenderWidgetHostView()); |
| 69 native_container_->AttachContents(tab_contents_); | 44 native_container_->AttachContents(tab_contents_); |
| 70 #endif | |
| 71 AddObservers(); | 45 AddObservers(); |
| 72 } | 46 } |
| 73 } | 47 } |
| 74 | 48 |
| 75 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { | 49 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { |
| 76 if (native_container_) | 50 native_container_->TabContentsFocused(tab_contents); |
| 77 native_container_->TabContentsFocused(tab_contents); | |
| 78 } | 51 } |
| 79 | 52 |
| 80 void TabContentsContainer::SetFastResize(bool fast_resize) { | 53 void TabContentsContainer::SetFastResize(bool fast_resize) { |
| 81 if (native_container_) | 54 native_container_->SetFastResize(fast_resize); |
| 82 native_container_->SetFastResize(fast_resize); | |
| 83 } | |
| 84 | |
| 85 //////////////////////////////////////////////////////////////////////////////// | |
| 86 // TabContentsContainer, NotificationObserver implementation: | |
| 87 | |
| 88 void TabContentsContainer::Observe(NotificationType type, | |
| 89 const NotificationSource& source, | |
| 90 const NotificationDetails& details) { | |
| 91 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | |
| 92 RenderViewHostSwitchedDetails* switched_details = | |
| 93 Details<RenderViewHostSwitchedDetails>(details).ptr(); | |
| 94 RenderViewHostChanged(switched_details->old_host, | |
| 95 switched_details->new_host); | |
| 96 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | |
| 97 TabContentsDestroyed(Source<TabContents>(source).ptr()); | |
| 98 } else { | |
| 99 NOTREACHED(); | |
| 100 } | |
| 101 } | 55 } |
| 102 | 56 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
| 104 // TabContentsContainer, View overrides: | 58 // TabContentsContainer, View overrides: |
| 105 | 59 |
| 106 void TabContentsContainer::Layout() { | 60 void TabContentsContainer::Layout() { |
| 107 #if defined(TOUCH_UI) | 61 if (reserved_area_delegate_) |
| 108 views::View::Layout(); | 62 reserved_area_delegate_->UpdateReservedContentsRect(this); |
| 109 #else | 63 native_container_->GetView()->SetBounds(0, 0, width(), height()); |
| 110 if (native_container_) { | 64 native_container_->GetView()->Layout(); |
|
sky
2011/01/12 19:06:53
You need this if.
Alex Nicolaou
2011/01/13 15:56:29
Oh :( You're right, this pre-exists my previous ch
| |
| 111 if (reserved_area_delegate_) | |
| 112 reserved_area_delegate_->UpdateReservedContentsRect(this); | |
| 113 native_container_->GetView()->SetBounds(0, 0, width(), height()); | |
| 114 native_container_->GetView()->Layout(); | |
| 115 } | |
| 116 #endif | |
| 117 } | |
| 118 | |
| 119 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { | |
| 120 return AccessibilityTypes::ROLE_WINDOW; | |
| 121 } | 65 } |
| 122 | 66 |
| 123 void TabContentsContainer::ViewHierarchyChanged(bool is_add, | 67 void TabContentsContainer::ViewHierarchyChanged(bool is_add, |
| 124 views::View* parent, | 68 views::View* parent, |
| 125 views::View* child) { | 69 views::View* child) { |
| 126 #if defined(TOUCH_UI) | |
| 127 views::View::ViewHierarchyChanged(is_add, parent, child); | |
| 128 #else | |
| 129 if (is_add && child == this) { | 70 if (is_add && child == this) { |
| 130 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); | 71 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); |
| 131 AddChildView(native_container_->GetView()); | 72 AddChildView(native_container_->GetView()); |
| 132 } | 73 } |
| 133 #endif | |
| 134 } | 74 } |
| 135 | 75 |
| 136 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
| 137 // TabContentsContainer, private: | 77 // TabContentsContainer, private: |
| 138 | 78 |
| 139 void TabContentsContainer::AddObservers() { | |
| 140 // TabContents can change their RenderViewHost and hence the HWND that is | |
| 141 // shown and getting focused. We need to keep track of that so we install | |
| 142 // the focus subclass on the shown HWND so we intercept focus change events. | |
| 143 registrar_.Add(this, | |
| 144 NotificationType::RENDER_VIEW_HOST_CHANGED, | |
| 145 Source<NavigationController>(&tab_contents_->controller())); | |
| 146 | |
| 147 registrar_.Add(this, | |
| 148 NotificationType::TAB_CONTENTS_DESTROYED, | |
| 149 Source<TabContents>(tab_contents_)); | |
| 150 } | |
| 151 | |
| 152 void TabContentsContainer::RemoveObservers() { | |
| 153 registrar_.RemoveAll(); | |
| 154 } | |
| 155 | |
| 156 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, | 79 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, |
| 157 RenderViewHost* new_host) { | 80 RenderViewHost* new_host) { |
| 158 #if defined(TOUCH_UI) | |
| 159 NOTIMPLEMENTED(); // TODO(anicolao) | |
| 160 #else | |
| 161 if (new_host) { | 81 if (new_host) { |
| 162 RenderWidgetHostViewChanged( | 82 RenderWidgetHostViewChanged( |
| 163 old_host ? old_host->view() : NULL, new_host->view()); | 83 old_host ? old_host->view() : NULL, new_host->view()); |
| 164 } | 84 } |
| 165 native_container_->RenderViewHostChanged(old_host, new_host); | 85 native_container_->RenderViewHostChanged(old_host, new_host); |
| 166 #endif | |
| 167 } | 86 } |
| 168 | |
| 169 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { | |
| 170 // Sometimes, a TabContents is destroyed before we know about it. This allows | |
| 171 // us to clean up our state in case this happens. | |
| 172 DCHECK(contents == tab_contents_); | |
| 173 ChangeTabContents(NULL); | |
| 174 } | |
| 175 | |
| 176 void TabContentsContainer::RenderWidgetHostViewChanged( | |
| 177 RenderWidgetHostView* old_view, RenderWidgetHostView* new_view) { | |
| 178 // Carry over the reserved rect, if possible. | |
| 179 if (old_view && new_view) { | |
| 180 new_view->set_reserved_contents_rect(old_view->reserved_contents_rect()); | |
| 181 } else { | |
| 182 if (reserved_area_delegate_) | |
| 183 reserved_area_delegate_->UpdateReservedContentsRect(this); | |
| 184 } | |
| 185 } | |
| OLD | NEW |