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/ui/view_ids.h" | 7 #include "chrome/browser/ui/view_ids.h" |
8 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" | 8 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" |
9 #include "content/browser/renderer_host/render_view_host.h" | 9 #include "content/browser/renderer_host/render_view_host.h" |
10 #include "content/browser/renderer_host/render_widget_host_view.h" | 10 #include "content/browser/renderer_host/render_widget_host_view.h" |
11 #include "content/browser/tab_contents/interstitial_page.h" | 11 #include "content/browser/tab_contents/interstitial_page.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #include "ui/base/accessibility/accessible_view_state.h" | 16 #include "ui/base/accessibility/accessible_view_state.h" |
17 | 17 |
18 using content::WebContents; | 18 using content::WebContents; |
19 | 19 |
20 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
21 // TabContentsContainer, public: | 21 // TabContentsContainer, public: |
22 | 22 |
23 TabContentsContainer::TabContentsContainer() | 23 TabContentsContainer::TabContentsContainer() |
24 : native_container_(NULL), | 24 : native_container_(NULL), |
25 tab_contents_(NULL) { | 25 web_contents_(NULL) { |
26 set_id(VIEW_ID_TAB_CONTAINER); | 26 set_id(VIEW_ID_TAB_CONTAINER); |
27 } | 27 } |
28 | 28 |
29 TabContentsContainer::~TabContentsContainer() { | 29 TabContentsContainer::~TabContentsContainer() { |
30 if (tab_contents_) | 30 if (web_contents_) |
31 RemoveObservers(); | 31 RemoveObservers(); |
32 } | 32 } |
33 | 33 |
34 void TabContentsContainer::ChangeTabContents(TabContents* contents) { | 34 void TabContentsContainer::ChangeWebContents(WebContents* contents) { |
35 if (tab_contents_) { | 35 if (web_contents_) { |
36 native_container_->DetachContents(tab_contents_); | 36 native_container_->DetachContents(web_contents_); |
37 tab_contents_->WasHidden(); | 37 web_contents_->WasHidden(); |
38 RemoveObservers(); | 38 RemoveObservers(); |
39 } | 39 } |
40 tab_contents_ = contents; | 40 web_contents_ = contents; |
41 // When detaching the last tab of the browser ChangeTabContents is invoked | 41 // When detaching the last tab of the browser ChangeWebContents is invoked |
42 // with NULL. Don't attempt to do anything in that case. | 42 // with NULL. Don't attempt to do anything in that case. |
43 if (tab_contents_) { | 43 if (web_contents_) { |
44 RenderWidgetHostViewChanged(tab_contents_->GetRenderWidgetHostView()); | 44 RenderWidgetHostViewChanged(web_contents_->GetRenderWidgetHostView()); |
45 native_container_->AttachContents(tab_contents_); | 45 native_container_->AttachContents(web_contents_); |
46 AddObservers(); | 46 AddObservers(); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 content::WebContents* TabContentsContainer::web_contents() { | 50 content::WebContents* TabContentsContainer::web_contents() { |
51 return tab_contents_; | 51 return web_contents_; |
52 } | 52 } |
53 | 53 |
54 void TabContentsContainer::WebContentsFocused(WebContents* contents) { | 54 void TabContentsContainer::WebContentsFocused(WebContents* contents) { |
55 native_container_->WebContentsFocused(contents); | 55 native_container_->WebContentsFocused(contents); |
56 } | 56 } |
57 | 57 |
58 void TabContentsContainer::SetFastResize(bool fast_resize) { | 58 void TabContentsContainer::SetFastResize(bool fast_resize) { |
59 native_container_->SetFastResize(fast_resize); | 59 native_container_->SetFastResize(fast_resize); |
60 } | 60 } |
61 | 61 |
62 void TabContentsContainer::SetReservedContentsRect( | 62 void TabContentsContainer::SetReservedContentsRect( |
63 const gfx::Rect& reserved_rect) { | 63 const gfx::Rect& reserved_rect) { |
64 cached_reserved_rect_ = reserved_rect; | 64 cached_reserved_rect_ = reserved_rect; |
65 if (tab_contents_ && tab_contents_->GetRenderWidgetHostView()) { | 65 if (web_contents_ && web_contents_->GetRenderWidgetHostView()) { |
66 tab_contents_->GetRenderWidgetHostView()->set_reserved_contents_rect( | 66 web_contents_->GetRenderWidgetHostView()->set_reserved_contents_rect( |
67 reserved_rect); | 67 reserved_rect); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
72 // TabContentsContainer, content::NotificationObserver implementation: | 72 // TabContentsContainer, content::NotificationObserver implementation: |
73 | 73 |
74 void TabContentsContainer::Observe( | 74 void TabContentsContainer::Observe( |
75 int type, | 75 int type, |
76 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
(...skipping 26 matching lines...) Expand all Loading... |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void TabContentsContainer::GetAccessibleState(ui::AccessibleViewState* state) { | 107 void TabContentsContainer::GetAccessibleState(ui::AccessibleViewState* state) { |
108 state->role = ui::AccessibilityTypes::ROLE_WINDOW; | 108 state->role = ui::AccessibilityTypes::ROLE_WINDOW; |
109 } | 109 } |
110 | 110 |
111 #if defined(HAVE_XINPUT2) | 111 #if defined(HAVE_XINPUT2) |
112 bool TabContentsContainer::OnMousePressed(const views::MouseEvent& event) { | 112 bool TabContentsContainer::OnMousePressed(const views::MouseEvent& event) { |
113 DCHECK(tab_contents_); | 113 DCHECK(web_contents_); |
114 if (event.flags() & (ui::EF_LEFT_MOUSE_BUTTON | | 114 if (event.flags() & (ui::EF_LEFT_MOUSE_BUTTON | |
115 ui::EF_RIGHT_MOUSE_BUTTON | | 115 ui::EF_RIGHT_MOUSE_BUTTON | |
116 ui::EF_MIDDLE_MOUSE_BUTTON)) { | 116 ui::EF_MIDDLE_MOUSE_BUTTON)) { |
117 return false; | 117 return false; |
118 } | 118 } |
119 // It is necessary to look at the native event to determine what special | 119 // It is necessary to look at the native event to determine what special |
120 // button was pressed. | 120 // button was pressed. |
121 views::NativeEvent native_event = event.native_event(); | 121 views::NativeEvent native_event = event.native_event(); |
122 if (!native_event) | 122 if (!native_event) |
123 return false; | 123 return false; |
124 | 124 |
125 int button = 0; | 125 int button = 0; |
126 switch (native_event->type) { | 126 switch (native_event->type) { |
127 case ButtonPress: { | 127 case ButtonPress: { |
128 button = native_event->xbutton.button; | 128 button = native_event->xbutton.button; |
129 break; | 129 break; |
130 } | 130 } |
131 case GenericEvent: { | 131 case GenericEvent: { |
132 XIDeviceEvent* xievent = | 132 XIDeviceEvent* xievent = |
133 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 133 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
134 button = xievent->detail; | 134 button = xievent->detail; |
135 break; | 135 break; |
136 } | 136 } |
137 default: | 137 default: |
138 break; | 138 break; |
139 } | 139 } |
140 switch (button) { | 140 switch (button) { |
141 case 8: | 141 case 8: |
142 tab_contents_->GetController().GoBack(); | 142 web_contents_->GetController().GoBack(); |
143 return true; | 143 return true; |
144 case 9: | 144 case 9: |
145 tab_contents_->GetController().GoForward(); | 145 web_contents_->GetController().GoForward(); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 return false; | 149 return false; |
150 } | 150 } |
151 #endif | 151 #endif |
152 | 152 |
153 void TabContentsContainer::ViewHierarchyChanged(bool is_add, | 153 void TabContentsContainer::ViewHierarchyChanged(bool is_add, |
154 views::View* parent, | 154 views::View* parent, |
155 views::View* child) { | 155 views::View* child) { |
156 if (is_add && child == this) { | 156 if (is_add && child == this) { |
157 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); | 157 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); |
158 AddChildView(native_container_->GetView()); | 158 AddChildView(native_container_->GetView()); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
163 // TabContentsContainer, private: | 163 // TabContentsContainer, private: |
164 | 164 |
165 void TabContentsContainer::AddObservers() { | 165 void TabContentsContainer::AddObservers() { |
166 // TabContents can change their RenderViewHost and hence the HWND that is | 166 // TabContents can change their RenderViewHost and hence the HWND that is |
167 // shown and getting focused. We need to keep track of that so we install | 167 // shown and getting focused. We need to keep track of that so we install |
168 // the focus subclass on the shown HWND so we intercept focus change events. | 168 // the focus subclass on the shown HWND so we intercept focus change events. |
169 registrar_.Add( | 169 registrar_.Add( |
170 this, | 170 this, |
171 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 171 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
172 content::Source<NavigationController>(&tab_contents_->GetController())); | 172 content::Source<NavigationController>(&web_contents_->GetController())); |
173 | 173 |
174 registrar_.Add( | 174 registrar_.Add( |
175 this, | 175 this, |
176 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 176 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
177 content::Source<WebContents>(tab_contents_)); | 177 content::Source<WebContents>(web_contents_)); |
178 } | 178 } |
179 | 179 |
180 void TabContentsContainer::RemoveObservers() { | 180 void TabContentsContainer::RemoveObservers() { |
181 registrar_.RemoveAll(); | 181 registrar_.RemoveAll(); |
182 } | 182 } |
183 | 183 |
184 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, | 184 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, |
185 RenderViewHost* new_host) { | 185 RenderViewHost* new_host) { |
186 if (new_host) | 186 if (new_host) |
187 RenderWidgetHostViewChanged(new_host->view()); | 187 RenderWidgetHostViewChanged(new_host->view()); |
188 native_container_->RenderViewHostChanged(old_host, new_host); | 188 native_container_->RenderViewHostChanged(old_host, new_host); |
189 } | 189 } |
190 | 190 |
191 void TabContentsContainer::TabContentsDestroyed(WebContents* contents) { | 191 void TabContentsContainer::TabContentsDestroyed(WebContents* contents) { |
192 // Sometimes, a TabContents is destroyed before we know about it. This allows | 192 // Sometimes, a TabContents is destroyed before we know about it. This allows |
193 // us to clean up our state in case this happens. | 193 // us to clean up our state in case this happens. |
194 DCHECK(contents == tab_contents_); | 194 DCHECK(contents == web_contents_); |
195 ChangeTabContents(NULL); | 195 ChangeWebContents(NULL); |
196 } | 196 } |
197 | 197 |
198 void TabContentsContainer::RenderWidgetHostViewChanged( | 198 void TabContentsContainer::RenderWidgetHostViewChanged( |
199 RenderWidgetHostView* new_view) { | 199 RenderWidgetHostView* new_view) { |
200 if (new_view) | 200 if (new_view) |
201 new_view->set_reserved_contents_rect(cached_reserved_rect_); | 201 new_view->set_reserved_contents_rect(cached_reserved_rect_); |
202 } | 202 } |
OLD | NEW |