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