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