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