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

Side by Side Diff: chrome/browser/views/tab_contents/native_tab_contents_container_gtk.cc

Issue 194041: Making the focus remembering across tab switch work. (Closed)
Patch Set: Fix for conflicts Created 11 years, 3 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/native_tab_contents_container_gtk.h" 5 #include "chrome/browser/views/tab_contents/native_tab_contents_container_gtk.h"
6 6
7 #include "chrome/browser/renderer_host/render_widget_host_view.h" 7 #include "chrome/browser/renderer_host/render_widget_host_view.h"
8 #include "chrome/browser/tab_contents/interstitial_page.h" 8 #include "chrome/browser/tab_contents/interstitial_page.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 9 #include "chrome/browser/tab_contents/tab_contents.h"
10 #include "chrome/browser/views/tab_contents/tab_contents_container.h" 10 #include "chrome/browser/views/tab_contents/tab_contents_container.h"
11 #include "views/focus/focus_manager.h" 11 #include "views/focus/focus_manager.h"
12 #include "views/widget/root_view.h" 12 #include "views/widget/root_view.h"
13 #include "views/widget/widget.h" 13 #include "views/widget/widget.h"
14 14
15 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
16 // NativeTabContentsContainerGtk, public: 16 // NativeTabContentsContainerGtk, public:
17 17
18 NativeTabContentsContainerGtk::NativeTabContentsContainerGtk( 18 NativeTabContentsContainerGtk::NativeTabContentsContainerGtk(
19 TabContentsContainer* container) 19 TabContentsContainer* container)
20 : container_(container) { 20 : container_(container),
21 focus_callback_id_(0) {
21 } 22 }
22 23
23 NativeTabContentsContainerGtk::~NativeTabContentsContainerGtk() { 24 NativeTabContentsContainerGtk::~NativeTabContentsContainerGtk() {
24 } 25 }
25 26
26 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
27 // NativeTabContentsContainerGtk, NativeTabContentsContainer overrides: 28 // NativeTabContentsContainerGtk, NativeTabContentsContainer overrides:
28 29
29 void NativeTabContentsContainerGtk::AttachContents(TabContents* contents) { 30 void NativeTabContentsContainerGtk::AttachContents(TabContents* contents) {
30 // We need to register the tab contents window with the BrowserContainer so
31 // that the BrowserContainer is the focused view when the focus is on the
32 // TabContents window (for the TabContents case).
33 set_focus_view(this);
34
35 Attach(contents->GetNativeView()); 31 Attach(contents->GetNativeView());
36
37 // TODO(port): figure out focus interception
38 #if defined(OS_WIN)
39 HWND contents_hwnd = contents->GetContentNativeView();
40 if (contents_hwnd)
41 views::FocusManager::InstallFocusSubclass(contents_hwnd, this);
42 #else
43 NOTIMPLEMENTED();
44 #endif
45 } 32 }
46 33
47 void NativeTabContentsContainerGtk::DetachContents(TabContents* contents) { 34 void NativeTabContentsContainerGtk::DetachContents(TabContents* contents) {
48 // TODO(port): figure out focus interception
49 #if defined(OS_WIN)
50 // TODO(brettw) should this move to NativeViewHost::Detach which is called
51 // below? It needs cleanup regardless.
52 HWND container_hwnd = contents->GetNativeView();
53
54 // Hide the contents before adjusting its parent to avoid a full desktop
55 // flicker.
56 ShowWindow(container_hwnd, SW_HIDE);
57
58 // Reset the parent to NULL to ensure hidden tabs don't receive messages.
59 ::SetParent(container_hwnd, NULL);
60
61 // Unregister the tab contents window from the FocusManager.
62 views::FocusManager::UninstallFocusSubclass(container_hwnd);
63 HWND hwnd = contents->GetContentNativeView();
64 if (hwnd) {
65 // We may not have an HWND anymore, if the renderer crashed and we are
66 // displaying the sad tab for example.
67 views::FocusManager::UninstallFocusSubclass(hwnd);
68 }
69 #else
70 gtk_widget_hide(contents->GetNativeView()); 35 gtk_widget_hide(contents->GetNativeView());
71 #endif
72 36
73 // Now detach the TabContents. 37 // Now detach the TabContents.
74 Detach(); 38 Detach();
75 } 39 }
76 40
77 void NativeTabContentsContainerGtk::SetFastResize(bool fast_resize) { 41 void NativeTabContentsContainerGtk::SetFastResize(bool fast_resize) {
78 set_fast_resize(fast_resize); 42 set_fast_resize(fast_resize);
79 } 43 }
80 44
81 void NativeTabContentsContainerGtk::RenderViewHostChanged( 45 void NativeTabContentsContainerGtk::RenderViewHostChanged(
82 RenderViewHost* old_host, 46 RenderViewHost* old_host,
83 RenderViewHost* new_host) { 47 RenderViewHost* new_host) {
84 // TODO(port): figure out focus interception
85 #if defined(OS_WIN)
86 if (old_host && old_host->view()) {
87 views::FocusManager::UninstallFocusSubclass(
88 old_host->view()->GetNativeView());
89 }
90
91 if (new_host && new_host->view()) {
92 views::FocusManager::InstallFocusSubclass(
93 new_host->view()->GetNativeView(), this);
94 }
95
96 // If we are focused, we need to pass the focus to the new RenderViewHost. 48 // If we are focused, we need to pass the focus to the new RenderViewHost.
97 views::FocusManager* focus_manager = views::FocusManager::GetFocusManager( 49 views::FocusManager* focus_manager = GetFocusManager();
98 GetRootView()->GetWidget()->GetNativeView());
99 if (focus_manager->GetFocusedView() == this) 50 if (focus_manager->GetFocusedView() == this)
100 Focus(); 51 Focus();
101 #else
102 // If we are focused, we need to pass the focus to the new RenderViewHost.
103 // TODO: uncomment this once FocusManager has been ported.
104 // views::FocusManager* focus_manager = views::FocusManager::GetFocusManager(
105 // GetRootView()->GetWidget()->GetNativeView());
106 // if (focus_manager->GetFocusedView() == this)
107 // Focus();
108 #endif
109 } 52 }
110 53
111 views::View* NativeTabContentsContainerGtk::GetView() { 54 views::View* NativeTabContentsContainerGtk::GetView() {
112 return this; 55 return this;
113 } 56 }
114 57
115 void NativeTabContentsContainerGtk::TabContentsFocused( 58 void NativeTabContentsContainerGtk::TabContentsFocused(
116 TabContents* tab_contents) { 59 TabContents* tab_contents) {
117 #if defined(OS_WIN) 60 // Called when the tab contents native view gets focused (typically through a
61 // user click). We make ourself the focused view, so the focus is restored
62 // properly when the browser window is deactivated/reactivated.
118 views::FocusManager* focus_manager = GetFocusManager(); 63 views::FocusManager* focus_manager = GetFocusManager();
119 if (!focus_manager) { 64 if (!focus_manager) {
120 NOTREACHED(); 65 NOTREACHED();
121 return; 66 return;
122 } 67 }
123 focus_manager->SetFocusedView(this); 68 focus_manager->SetFocusedView(this);
124 #endif
125 } 69 }
126 70
127 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
128 // NativeTabContentsContainerGtk, views::View overrides: 72 // NativeTabContentsContainerGtk, views::View overrides:
129 73
130 bool NativeTabContentsContainerGtk::SkipDefaultKeyEventProcessing( 74 bool NativeTabContentsContainerGtk::SkipDefaultKeyEventProcessing(
131 const views::KeyEvent& e) { 75 const views::KeyEvent& e) {
132 // Don't look-up accelerators or tab-traverse if we are showing a non-crashed 76 // Don't look-up accelerators or tab-traverse if we are showing a non-crashed
133 // TabContents. 77 // TabContents.
134 // We'll first give the page a chance to process the key events. If it does 78 // We'll first give the page a chance to process the key events. If it does
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 142 }
199 143
200 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
201 // NativeTabContentsContainer, public: 145 // NativeTabContentsContainer, public:
202 146
203 // static 147 // static
204 NativeTabContentsContainer* NativeTabContentsContainer::CreateNativeContainer( 148 NativeTabContentsContainer* NativeTabContentsContainer::CreateNativeContainer(
205 TabContentsContainer* container) { 149 TabContentsContainer* container) {
206 return new NativeTabContentsContainerGtk(container); 150 return new NativeTabContentsContainerGtk(container);
207 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698