OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h" | 5 #include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/gfx/point.h" | 11 #include "base/gfx/point.h" |
12 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
13 #include "base/gfx/size.h" | 13 #include "base/gfx/size.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/blocked_popup_container.h" | 15 #include "chrome/browser/blocked_popup_container.h" |
16 #include "chrome/browser/download/download_shelf.h" | 16 #include "chrome/browser/download/download_shelf.h" |
17 #include "chrome/browser/gtk/tab_contents_drag_source.h" | 17 #include "chrome/browser/gtk/tab_contents_drag_source.h" |
18 #include "chrome/browser/renderer_host/render_view_host.h" | 18 #include "chrome/browser/renderer_host/render_view_host.h" |
19 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 19 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
20 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 20 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
21 #include "chrome/browser/tab_contents/interstitial_page.h" | 21 #include "chrome/browser/tab_contents/interstitial_page.h" |
22 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
23 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 23 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
24 #include "chrome/browser/views/sad_tab_view.h" | 24 #include "chrome/browser/views/sad_tab_view.h" |
25 #include "chrome/browser/views/tab_contents/render_view_context_menu_win.h" | 25 #include "chrome/browser/views/tab_contents/render_view_context_menu_win.h" |
| 26 #include "views/focus/view_storage.h" |
26 #include "views/controls/native/native_view_host.h" | 27 #include "views/controls/native/native_view_host.h" |
27 #include "views/widget/root_view.h" | 28 #include "views/widget/root_view.h" |
28 | 29 |
29 using WebKit::WebDragOperation; | 30 using WebKit::WebDragOperation; |
30 using WebKit::WebDragOperationsMask; | 31 using WebKit::WebDragOperationsMask; |
31 using WebKit::WebInputEvent; | 32 using WebKit::WebInputEvent; |
32 | 33 |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // static | 91 // static |
91 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 92 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
92 return new TabContentsViewGtk(tab_contents); | 93 return new TabContentsViewGtk(tab_contents); |
93 } | 94 } |
94 | 95 |
95 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) | 96 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) |
96 : TabContentsView(tab_contents), | 97 : TabContentsView(tab_contents), |
97 views::WidgetGtk(TYPE_CHILD), | 98 views::WidgetGtk(TYPE_CHILD), |
98 ignore_next_char_event_(false) { | 99 ignore_next_char_event_(false) { |
99 drag_source_.reset(new TabContentsDragSource(this)); | 100 drag_source_.reset(new TabContentsDragSource(this)); |
| 101 last_focused_view_storage_id_ = |
| 102 views::ViewStorage::GetSharedInstance()->CreateStorageID(); |
100 } | 103 } |
101 | 104 |
102 TabContentsViewGtk::~TabContentsViewGtk() { | 105 TabContentsViewGtk::~TabContentsViewGtk() { |
| 106 // Make sure to remove any stored view we may still have in the ViewStorage. |
| 107 // |
| 108 // It is possible the view went away before us, so we only do this if the |
| 109 // view is registered. |
| 110 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 111 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
| 112 view_storage->RemoveView(last_focused_view_storage_id_); |
| 113 |
103 // Just deleting the object doesn't destroy the GtkWidget. We need to do that | 114 // Just deleting the object doesn't destroy the GtkWidget. We need to do that |
104 // manually, and synchronously, since subsequent signal handlers may expect | 115 // manually, and synchronously, since subsequent signal handlers may expect |
105 // to locate this object. | 116 // to locate this object. |
106 CloseNow(); | 117 CloseNow(); |
107 } | 118 } |
108 | 119 |
109 void TabContentsViewGtk::CreateView() { | 120 void TabContentsViewGtk::CreateView() { |
110 set_delete_on_destroy(false); | 121 set_delete_on_destroy(false); |
111 WidgetGtk::Init(NULL, gfx::Rect()); | 122 WidgetGtk::Init(NULL, gfx::Rect()); |
112 } | 123 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 222 } |
212 | 223 |
213 void TabContentsViewGtk::SetInitialFocus() { | 224 void TabContentsViewGtk::SetInitialFocus() { |
214 if (tab_contents()->FocusLocationBarByDefault()) | 225 if (tab_contents()->FocusLocationBarByDefault()) |
215 tab_contents()->delegate()->SetFocusToLocationBar(); | 226 tab_contents()->delegate()->SetFocusToLocationBar(); |
216 else | 227 else |
217 Focus(); | 228 Focus(); |
218 } | 229 } |
219 | 230 |
220 void TabContentsViewGtk::StoreFocus() { | 231 void TabContentsViewGtk::StoreFocus() { |
221 NOTIMPLEMENTED(); | 232 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 233 |
| 234 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
| 235 view_storage->RemoveView(last_focused_view_storage_id_); |
| 236 |
| 237 views::FocusManager* focus_manager = |
| 238 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 239 if (focus_manager) { |
| 240 // |focus_manager| can be NULL if the tab has been detached but still |
| 241 // exists. |
| 242 views::View* focused_view = focus_manager->GetFocusedView(); |
| 243 if (focused_view) |
| 244 view_storage->StoreView(last_focused_view_storage_id_, focused_view); |
| 245 } |
222 } | 246 } |
223 | 247 |
224 void TabContentsViewGtk::RestoreFocus() { | 248 void TabContentsViewGtk::RestoreFocus() { |
225 NOTIMPLEMENTED(); | 249 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
226 SetInitialFocus(); | 250 views::View* last_focused_view = |
| 251 view_storage->RetrieveView(last_focused_view_storage_id_); |
| 252 if (!last_focused_view) { |
| 253 SetInitialFocus(); |
| 254 } else { |
| 255 views::FocusManager* focus_manager = |
| 256 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 257 |
| 258 // If you hit this DCHECK, please report it to Jay (jcampan). |
| 259 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus."; |
| 260 |
| 261 if (last_focused_view->IsFocusable() && focus_manager && |
| 262 focus_manager->ContainsView(last_focused_view)) { |
| 263 last_focused_view->RequestFocus(); |
| 264 } else { |
| 265 // The focused view may not belong to the same window hierarchy (e.g. |
| 266 // if the location bar was focused and the tab is dragged out), or it may |
| 267 // no longer be focusable (e.g. if the location bar was focused and then |
| 268 // we switched to fullscreen mode). In that case we default to the |
| 269 // default focus. |
| 270 SetInitialFocus(); |
| 271 } |
| 272 view_storage->RemoveView(last_focused_view_storage_id_); |
| 273 } |
227 } | 274 } |
228 | 275 |
229 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { | 276 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { |
230 NOTIMPLEMENTED(); | 277 NOTIMPLEMENTED(); |
231 } | 278 } |
232 | 279 |
233 void TabContentsViewGtk::GotFocus() { | 280 void TabContentsViewGtk::GotFocus() { |
234 tab_contents()->delegate()->TabContentsFocused(tab_contents()); | 281 tab_contents()->delegate()->TabContentsFocused(tab_contents()); |
235 } | 282 } |
236 | 283 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 386 |
340 private: | 387 private: |
341 DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewGtk); | 388 DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewGtk); |
342 }; | 389 }; |
343 | 390 |
344 // static | 391 // static |
345 BlockedPopupContainerView* BlockedPopupContainerView::Create( | 392 BlockedPopupContainerView* BlockedPopupContainerView::Create( |
346 BlockedPopupContainer* container) { | 393 BlockedPopupContainer* container) { |
347 return new BlockedPopupContainerViewGtk; | 394 return new BlockedPopupContainerViewGtk; |
348 } | 395 } |
OLD | NEW |