Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc

Issue 8477042: Move Sad Tab implementation out of the TabContentsViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes for jochen and jam Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_view_views.h" 5 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "chrome/browser/browser_shutdown.h"
11 #include "chrome/browser/ui/constrained_window.h" 10 #include "chrome/browser/ui/constrained_window.h"
12 #include "chrome/browser/ui/constrained_window_tab_helper.h" 11 #include "chrome/browser/ui/constrained_window_tab_helper.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/browser/ui/views/sad_tab_view.h"
15 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" 13 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h"
16 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" 14 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h"
17 #include "content/browser/renderer_host/render_process_host.h" 15 #include "content/browser/renderer_host/render_process_host.h"
18 #include "content/browser/renderer_host/render_view_host.h" 16 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/renderer_host/render_view_host_factory.h" 17 #include "content/browser/renderer_host/render_view_host_factory.h"
20 #include "content/browser/renderer_host/render_widget_host_view.h" 18 #include "content/browser/renderer_host/render_widget_host_view.h"
21 #include "content/browser/tab_contents/interstitial_page.h" 19 #include "content/browser/tab_contents/interstitial_page.h"
22 #include "content/browser/tab_contents/tab_contents.h" 20 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/browser/tab_contents/tab_contents_delegate.h" 21 #include "content/browser/tab_contents/tab_contents_delegate.h"
24 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
25 #include "views/focus/focus_manager.h" 23 #include "views/focus/focus_manager.h"
26 #include "views/focus/view_storage.h" 24 #include "views/focus/view_storage.h"
27 #include "views/widget/native_widget.h" 25 #include "views/widget/native_widget.h"
28 #include "views/widget/widget.h" 26 #include "views/widget/widget.h"
29 27
30 #if defined(OS_WIN) 28 #if defined(OS_WIN)
31 #include <windows.h> 29 #include <windows.h>
32 #endif 30 #endif
33 31
34 using WebKit::WebDragOperation; 32 using WebKit::WebDragOperation;
35 using WebKit::WebDragOperationNone; 33 using WebKit::WebDragOperationNone;
36 using WebKit::WebDragOperationsMask; 34 using WebKit::WebDragOperationsMask;
37 using WebKit::WebInputEvent; 35 using WebKit::WebInputEvent;
38 36
39 TabContentsViewViews::TabContentsViewViews(TabContents* tab_contents) 37 TabContentsViewViews::TabContentsViewViews(TabContents* tab_contents)
40 : tab_contents_(tab_contents), 38 : tab_contents_(tab_contents),
41 native_tab_contents_view_(NULL), 39 native_tab_contents_view_(NULL),
42 sad_tab_widget_(NULL),
43 close_tab_after_drag_ends_(false), 40 close_tab_after_drag_ends_(false),
44 focus_manager_(NULL) { 41 focus_manager_(NULL),
42 overlaid_view_(NULL) {
45 last_focused_view_storage_id_ = 43 last_focused_view_storage_id_ =
46 views::ViewStorage::GetInstance()->CreateStorageID(); 44 views::ViewStorage::GetInstance()->CreateStorageID();
47 } 45 }
48 46
49 TabContentsViewViews::~TabContentsViewViews() { 47 TabContentsViewViews::~TabContentsViewViews() {
50 // Makes sure to remove any stored view we may still have in the ViewStorage. 48 // Makes sure to remove any stored view we may still have in the ViewStorage.
51 // 49 //
52 // It is possible the view went away before us, so we only do this if the 50 // It is possible the view went away before us, so we only do this if the
53 // view is registered. 51 // view is registered.
54 views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); 52 views::ViewStorage* view_storage = views::ViewStorage::GetInstance();
(...skipping 27 matching lines...) Expand all
82 if (render_widget_host->view()) { 80 if (render_widget_host->view()) {
83 // During testing, the view will already be set up in most cases to the 81 // During testing, the view will already be set up in most cases to the
84 // test view, so we don't want to clobber it with a real one. To verify that 82 // test view, so we don't want to clobber it with a real one. To verify that
85 // this actually is happening (and somebody isn't accidentally creating the 83 // this actually is happening (and somebody isn't accidentally creating the
86 // view twice), we check for the RVH Factory, which will be set when we're 84 // view twice), we check for the RVH Factory, which will be set when we're
87 // making special ones (which go along with the special views). 85 // making special ones (which go along with the special views).
88 DCHECK(RenderViewHostFactory::has_factory()); 86 DCHECK(RenderViewHostFactory::has_factory());
89 return render_widget_host->view(); 87 return render_widget_host->view();
90 } 88 }
91 89
92 // If we were showing sad tab, remove it now.
93 if (sad_tab_widget_) {
94 sad_tab_widget_->Close();
95 sad_tab_widget_ = NULL;
96 }
97
98 return native_tab_contents_view_->CreateRenderWidgetHostView( 90 return native_tab_contents_view_->CreateRenderWidgetHostView(
99 render_widget_host); 91 render_widget_host);
100 } 92 }
101 93
102 gfx::NativeView TabContentsViewViews::GetNativeView() const { 94 gfx::NativeView TabContentsViewViews::GetNativeView() const {
103 return Widget::GetNativeView(); 95 return Widget::GetNativeView();
104 } 96 }
105 97
106 gfx::NativeView TabContentsViewViews::GetContentNativeView() const { 98 gfx::NativeView TabContentsViewViews::GetContentNativeView() const {
107 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 99 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
(...skipping 15 matching lines...) Expand all
123 const gfx::Point& image_offset) { 115 const gfx::Point& image_offset) {
124 native_tab_contents_view_->StartDragging(drop_data, ops, image, image_offset); 116 native_tab_contents_view_->StartDragging(drop_data, ops, image, image_offset);
125 } 117 }
126 118
127 void TabContentsViewViews::SetPageTitle(const string16& title) { 119 void TabContentsViewViews::SetPageTitle(const string16& title) {
128 native_tab_contents_view_->SetPageTitle(title); 120 native_tab_contents_view_->SetPageTitle(title);
129 } 121 }
130 122
131 void TabContentsViewViews::OnTabCrashed(base::TerminationStatus status, 123 void TabContentsViewViews::OnTabCrashed(base::TerminationStatus status,
132 int /* error_code */) { 124 int /* error_code */) {
133 // Only show the sad tab if we're not in browser shutdown, so that TabContents
134 // objects that are not in a browser (e.g., HTML dialogs) and thus are
135 // visible do not flash a sad tab page.
136 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
137 return;
138
139 // Note that it's possible to get this message after the window was destroyed.
140 if (GetNativeView()) {
141 SadTabView::Kind kind =
142 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
143 SadTabView::KILLED : SadTabView::CRASHED;
144 views::Widget::InitParams sad_tab_widget_params(
145 views::Widget::InitParams::TYPE_CONTROL);
146 sad_tab_widget_params.parent_widget = this;
147 sad_tab_widget_params.bounds =
148 gfx::Rect(GetClientAreaScreenBounds().size());
149 sad_tab_widget_ = new views::Widget;
150 sad_tab_widget_->Init(sad_tab_widget_params);
151 sad_tab_widget_->SetContentsView(new SadTabView(tab_contents_, kind));
152 }
153 } 125 }
154 126
155 void TabContentsViewViews::SizeContents(const gfx::Size& size) { 127 void TabContentsViewViews::SizeContents(const gfx::Size& size) {
156 gfx::Rect bounds; 128 gfx::Rect bounds;
157 GetContainerBounds(&bounds); 129 GetContainerBounds(&bounds);
158 if (bounds.size() != size) { 130 if (bounds.size() != size) {
159 SetSize(size); 131 SetSize(size);
160 } else { 132 } else {
161 // Our size matches what we want but the renderers size may not match. 133 // Our size matches what we want but the renderers size may not match.
162 // Pretend we were resized so that the renderers size is updated too. 134 // Pretend we were resized so that the renderers size is updated too.
163 OnNativeTabContentsViewSized(size); 135 OnNativeTabContentsViewSized(size);
164 } 136 }
165 } 137 }
166 138
167 void TabContentsViewViews::RenderViewCreated(RenderViewHost* host) { 139 void TabContentsViewViews::RenderViewCreated(RenderViewHost* host) {
168 } 140 }
169 141
170 void TabContentsViewViews::Focus() { 142 void TabContentsViewViews::Focus() {
171 if (tab_contents_->interstitial_page()) { 143 if (tab_contents_->interstitial_page()) {
172 tab_contents_->interstitial_page()->Focus(); 144 tab_contents_->interstitial_page()->Focus();
173 return; 145 return;
174 } 146 }
175 147
176 if (tab_contents_->is_crashed() && sad_tab_widget_ != NULL) { 148 if (overlaid_view_) {
177 sad_tab_widget_->GetContentsView()->RequestFocus(); 149 overlaid_view_->GetContentsView()->RequestFocus();
178 return; 150 return;
179 } 151 }
180 152
181 TabContentsWrapper* wrapper = 153 TabContentsWrapper* wrapper =
182 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); 154 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_);
183 if (wrapper) { 155 if (wrapper) {
184 // TODO(erg): TabContents used to own constrained windows, which is why 156 // TODO(erg): TabContents used to own constrained windows, which is why
185 // this is here. Eventually this should be ported to a containing view 157 // this is here. Eventually this should be ported to a containing view
186 // specializing in constrained window management. 158 // specializing in constrained window management.
187 ConstrainedWindowTabHelper* helper = 159 ConstrainedWindowTabHelper* helper =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return false; 250 return false;
279 } 251 }
280 252
281 void TabContentsViewViews::CloseTabAfterEventTracking() { 253 void TabContentsViewViews::CloseTabAfterEventTracking() {
282 } 254 }
283 255
284 void TabContentsViewViews::GetViewBounds(gfx::Rect* out) const { 256 void TabContentsViewViews::GetViewBounds(gfx::Rect* out) const {
285 *out = GetWindowScreenBounds(); 257 *out = GetWindowScreenBounds();
286 } 258 }
287 259
260 void TabContentsViewViews::InstallOverlayView(gfx::NativeView view) {
261 DCHECK(!overlaid_view_);
262 views::Widget::ReparentNativeView(view, GetNativeView());
263 overlaid_view_ = views::Widget::GetWidgetForNativeView(view);
264 overlaid_view_->SetBounds(gfx::Rect(GetClientAreaScreenBounds().size()));
265 }
266
267 void TabContentsViewViews::RemoveOverlayView() {
268 DCHECK(overlaid_view_);
269 overlaid_view_->Close();
270 overlaid_view_ = NULL;
271 }
272
288 void TabContentsViewViews::UpdateDragCursor(WebDragOperation operation) { 273 void TabContentsViewViews::UpdateDragCursor(WebDragOperation operation) {
289 native_tab_contents_view_->SetDragCursor(operation); 274 native_tab_contents_view_->SetDragCursor(operation);
290 } 275 }
291 276
292 void TabContentsViewViews::GotFocus() { 277 void TabContentsViewViews::GotFocus() {
293 if (tab_contents_->delegate()) 278 if (tab_contents_->delegate())
294 tab_contents_->delegate()->TabContentsFocused(tab_contents_); 279 tab_contents_->delegate()->TabContentsFocused(tab_contents_);
295 } 280 }
296 281
297 void TabContentsViewViews::TakeFocus(bool reverse) { 282 void TabContentsViewViews::TakeFocus(bool reverse) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 363 }
379 364
380 //////////////////////////////////////////////////////////////////////////////// 365 ////////////////////////////////////////////////////////////////////////////////
381 // TabContentsViewViews, internal::NativeTabContentsViewDelegate implementation: 366 // TabContentsViewViews, internal::NativeTabContentsViewDelegate implementation:
382 367
383 TabContents* TabContentsViewViews::GetTabContents() { 368 TabContents* TabContentsViewViews::GetTabContents() {
384 return tab_contents_; 369 return tab_contents_;
385 } 370 }
386 371
387 bool TabContentsViewViews::IsShowingSadTab() const { 372 bool TabContentsViewViews::IsShowingSadTab() const {
388 return tab_contents_->is_crashed() && sad_tab_widget_; 373 return tab_contents_->is_crashed() && overlaid_view_;
389 } 374 }
390 375
391 void TabContentsViewViews::OnNativeTabContentsViewShown() { 376 void TabContentsViewViews::OnNativeTabContentsViewShown() {
392 tab_contents_->ShowContents(); 377 tab_contents_->ShowContents();
393 } 378 }
394 379
395 void TabContentsViewViews::OnNativeTabContentsViewHidden() { 380 void TabContentsViewViews::OnNativeTabContentsViewHidden() {
396 tab_contents_->HideContents(); 381 tab_contents_->HideContents();
397 } 382 }
398 383
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 views::Widget::OnNativeWidgetVisibilityChanged(visible); 450 views::Widget::OnNativeWidgetVisibilityChanged(visible);
466 if (visible) { 451 if (visible) {
467 tab_contents_->ShowContents(); 452 tab_contents_->ShowContents();
468 } else { 453 } else {
469 tab_contents_->HideContents(); 454 tab_contents_->HideContents();
470 } 455 }
471 } 456 }
472 457
473 void TabContentsViewViews::OnNativeWidgetSizeChanged( 458 void TabContentsViewViews::OnNativeWidgetSizeChanged(
474 const gfx::Size& new_size) { 459 const gfx::Size& new_size) {
475 if (sad_tab_widget_) 460 if (overlaid_view_)
476 sad_tab_widget_->SetBounds(gfx::Rect(new_size)); 461 overlaid_view_->SetBounds(gfx::Rect(new_size));
477 views::Widget::OnNativeWidgetSizeChanged(new_size); 462 views::Widget::OnNativeWidgetSizeChanged(new_size);
478 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698