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/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 #if defined(TOUCH_UI) |
17 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk
.h" | 17 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk
.h" |
18 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" | 18 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
19 #include "views/border.h" | 19 #include "views/border.h" |
20 #include "views/fill_layout.h" | 20 #include "views/fill_layout.h" |
21 #endif | 21 #endif |
22 | 22 |
23 //////////////////////////////////////////////////////////////////////////////// | 23 //////////////////////////////////////////////////////////////////////////////// |
24 // TabContentsContainer, public: | 24 // TabContentsContainer, public: |
25 | 25 |
26 TabContentsContainer::TabContentsContainer() | 26 TabContentsContainer::TabContentsContainer() |
27 : native_container_(NULL), | 27 : native_container_(NULL), |
28 tab_contents_(NULL) { | 28 tab_contents_(NULL), |
| 29 reserved_area_delegate_(NULL) { |
29 SetID(VIEW_ID_TAB_CONTAINER); | 30 SetID(VIEW_ID_TAB_CONTAINER); |
30 } | 31 } |
31 | 32 |
32 TabContentsContainer::~TabContentsContainer() { | 33 TabContentsContainer::~TabContentsContainer() { |
33 if (tab_contents_) | 34 if (tab_contents_) |
34 RemoveObservers(); | 35 RemoveObservers(); |
35 } | 36 } |
36 | 37 |
37 void TabContentsContainer::ChangeTabContents(TabContents* contents) { | 38 void TabContentsContainer::ChangeTabContents(TabContents* contents) { |
38 if (tab_contents_) { | 39 if (tab_contents_) { |
39 #if !defined(TOUCH_UI) | 40 #if !defined(TOUCH_UI) |
40 native_container_->DetachContents(tab_contents_); | 41 native_container_->DetachContents(tab_contents_); |
41 #else | 42 #else |
42 views::View *v = static_cast<TabContentsViewViews*>(tab_contents_->view()); | 43 views::View *v = static_cast<TabContentsViewViews*>(tab_contents_->view()); |
43 RemoveChildView(v); | 44 RemoveChildView(v); |
44 #endif | 45 #endif |
45 tab_contents_->WasHidden(); | 46 tab_contents_->WasHidden(); |
46 RemoveObservers(); | 47 RemoveObservers(); |
47 } | 48 } |
| 49 #if !defined(TOUCH_UI) |
| 50 TabContents* old_contents = tab_contents_; |
| 51 #endif |
48 tab_contents_ = contents; | 52 tab_contents_ = contents; |
49 // When detaching the last tab of the browser ChangeTabContents is invoked | 53 // When detaching the last tab of the browser ChangeTabContents is invoked |
50 // with NULL. Don't attempt to do anything in that case. | 54 // with NULL. Don't attempt to do anything in that case. |
51 if (tab_contents_) { | 55 if (tab_contents_) { |
52 #if defined(TOUCH_UI) | 56 #if defined(TOUCH_UI) |
53 views::View *v = static_cast<TabContentsViewViews*>(contents->view()); | 57 views::View *v = static_cast<TabContentsViewViews*>(contents->view()); |
54 // Guard against re-adding ourselves, which happens because the NULL | 58 // Guard against re-adding ourselves, which happens because the NULL |
55 // value is ignored by the pre-existing if() above. | 59 // value is ignored by the pre-existing if() above. |
56 if (v->GetParent() != this) { | 60 if (v->GetParent() != this) { |
57 AddChildView(v); | 61 AddChildView(v); |
58 SetLayoutManager(new views::FillLayout()); | 62 SetLayoutManager(new views::FillLayout()); |
59 Layout(); | 63 Layout(); |
60 } | 64 } |
61 #else | 65 #else |
62 RenderWidgetHostViewChanged(tab_contents_->GetRenderWidgetHostView()); | 66 RenderWidgetHostViewChanged( |
| 67 old_contents ? old_contents->GetRenderWidgetHostView() : NULL, |
| 68 tab_contents_->GetRenderWidgetHostView()); |
63 native_container_->AttachContents(tab_contents_); | 69 native_container_->AttachContents(tab_contents_); |
64 #endif | 70 #endif |
65 AddObservers(); | 71 AddObservers(); |
66 } | 72 } |
67 } | 73 } |
68 | 74 |
69 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { | 75 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { |
70 if (native_container_) | 76 if (native_container_) |
71 native_container_->TabContentsFocused(tab_contents); | 77 native_container_->TabContentsFocused(tab_contents); |
72 } | 78 } |
73 | 79 |
74 void TabContentsContainer::SetFastResize(bool fast_resize) { | 80 void TabContentsContainer::SetFastResize(bool fast_resize) { |
75 if (native_container_) | 81 if (native_container_) |
76 native_container_->SetFastResize(fast_resize); | 82 native_container_->SetFastResize(fast_resize); |
77 } | 83 } |
78 | 84 |
79 void TabContentsContainer::SetReservedContentsRect( | |
80 const gfx::Rect& reserved_rect) { | |
81 cached_reserved_rect_ = reserved_rect; | |
82 #if !defined(TOUCH_UI) | |
83 if (tab_contents_ && tab_contents_->GetRenderWidgetHostView()) { | |
84 tab_contents_->GetRenderWidgetHostView()->set_reserved_contents_rect( | |
85 reserved_rect); | |
86 } | |
87 #endif | |
88 } | |
89 | |
90 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
91 // TabContentsContainer, NotificationObserver implementation: | 86 // TabContentsContainer, NotificationObserver implementation: |
92 | 87 |
93 void TabContentsContainer::Observe(NotificationType type, | 88 void TabContentsContainer::Observe(NotificationType type, |
94 const NotificationSource& source, | 89 const NotificationSource& source, |
95 const NotificationDetails& details) { | 90 const NotificationDetails& details) { |
96 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 91 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { |
97 RenderViewHostSwitchedDetails* switched_details = | 92 RenderViewHostSwitchedDetails* switched_details = |
98 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 93 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
99 RenderViewHostChanged(switched_details->old_host, | 94 RenderViewHostChanged(switched_details->old_host, |
100 switched_details->new_host); | 95 switched_details->new_host); |
101 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 96 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { |
102 TabContentsDestroyed(Source<TabContents>(source).ptr()); | 97 TabContentsDestroyed(Source<TabContents>(source).ptr()); |
103 } else { | 98 } else { |
104 NOTREACHED(); | 99 NOTREACHED(); |
105 } | 100 } |
106 } | 101 } |
107 | 102 |
108 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
109 // TabContentsContainer, View overrides: | 104 // TabContentsContainer, View overrides: |
110 | 105 |
111 void TabContentsContainer::Layout() { | 106 void TabContentsContainer::Layout() { |
112 #if defined(TOUCH_UI) | 107 #if defined(TOUCH_UI) |
113 views::View::Layout(); | 108 views::View::Layout(); |
114 #else | 109 #else |
115 if (native_container_) { | 110 if (native_container_) { |
| 111 if (reserved_area_delegate_) |
| 112 reserved_area_delegate_->UpdateReservedContentsRect(this); |
116 native_container_->GetView()->SetBounds(0, 0, width(), height()); | 113 native_container_->GetView()->SetBounds(0, 0, width(), height()); |
117 native_container_->GetView()->Layout(); | 114 native_container_->GetView()->Layout(); |
118 } | 115 } |
119 #endif | 116 #endif |
120 } | 117 } |
121 | 118 |
122 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { | 119 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { |
123 return AccessibilityTypes::ROLE_WINDOW; | 120 return AccessibilityTypes::ROLE_WINDOW; |
124 } | 121 } |
125 | 122 |
(...skipping 28 matching lines...) Expand all Loading... |
154 | 151 |
155 void TabContentsContainer::RemoveObservers() { | 152 void TabContentsContainer::RemoveObservers() { |
156 registrar_.RemoveAll(); | 153 registrar_.RemoveAll(); |
157 } | 154 } |
158 | 155 |
159 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, | 156 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, |
160 RenderViewHost* new_host) { | 157 RenderViewHost* new_host) { |
161 #if defined(TOUCH_UI) | 158 #if defined(TOUCH_UI) |
162 NOTIMPLEMENTED(); // TODO(anicolao) | 159 NOTIMPLEMENTED(); // TODO(anicolao) |
163 #else | 160 #else |
164 if (new_host) | 161 if (new_host) { |
165 RenderWidgetHostViewChanged(new_host->view()); | 162 RenderWidgetHostViewChanged( |
| 163 old_host ? old_host->view() : NULL, new_host->view()); |
| 164 } |
166 native_container_->RenderViewHostChanged(old_host, new_host); | 165 native_container_->RenderViewHostChanged(old_host, new_host); |
167 #endif | 166 #endif |
168 } | 167 } |
169 | 168 |
170 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { | 169 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { |
171 // Sometimes, a TabContents is destroyed before we know about it. This allows | 170 // Sometimes, a TabContents is destroyed before we know about it. This allows |
172 // us to clean up our state in case this happens. | 171 // us to clean up our state in case this happens. |
173 DCHECK(contents == tab_contents_); | 172 DCHECK(contents == tab_contents_); |
174 ChangeTabContents(NULL); | 173 ChangeTabContents(NULL); |
175 } | 174 } |
176 | 175 |
177 void TabContentsContainer::RenderWidgetHostViewChanged( | 176 void TabContentsContainer::RenderWidgetHostViewChanged( |
178 RenderWidgetHostView* new_view) { | 177 RenderWidgetHostView* old_view, RenderWidgetHostView* new_view) { |
179 if (new_view) | 178 // Carry over the reserved rect, if possible. |
180 new_view->set_reserved_contents_rect(cached_reserved_rect_); | 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 } |
181 } | 185 } |
OLD | NEW |