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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_popup.cc

Issue 9193018: Tweak Win ExtensionPopup::OnNativeFocusChange logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and update copyright years. Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_popup.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_popup.h" 5 #include "chrome/browser/ui/views/extensions/extension_popup.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/debugger/devtools_window.h" 9 #include "chrome/browser/debugger/devtools_window.h"
10 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 set_close_on_deactivate(!inspect_with_devtools); 50 set_close_on_deactivate(!inspect_with_devtools);
51 #endif 51 #endif
52 52
53 // Wait to show the popup until the contained host finishes loading. 53 // Wait to show the popup until the contained host finishes loading.
54 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 54 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
55 content::Source<WebContents>(host->host_contents())); 55 content::Source<WebContents>(host->host_contents()));
56 56
57 // Listen for the containing view calling window.close(); 57 // Listen for the containing view calling window.close();
58 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 58 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
59 content::Source<Profile>(host->profile())); 59 content::Source<Profile>(host->profile()));
60
61 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
62 } 60 }
63 61
64 ExtensionPopup::~ExtensionPopup() { 62 ExtensionPopup::~ExtensionPopup() {
65 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); 63 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
66 } 64 }
67 65
68 void ExtensionPopup::Observe(int type, 66 void ExtensionPopup::Observe(int type,
69 const content::NotificationSource& source, 67 const content::NotificationSource& source,
70 const content::NotificationDetails& details) { 68 const content::NotificationDetails& details) {
71 switch (type) { 69 switch (type) {
72 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: 70 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
73 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); 71 DCHECK(content::Source<WebContents>(host()->host_contents()) == source);
74 // Show when the content finishes loading and its width is computed. 72 // Show when the content finishes loading and its width is computed.
75 Show(); 73 ShowBubble();
76 // Focus on the host contents when the bubble is first shown.
77 host()->host_contents()->Focus();
78 if (inspect_with_devtools_) {
79 // Listen for the the devtools window closing.
80 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
81 content::Source<content::BrowserContext>(host()->profile()));
82 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(),
83 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
84 }
85 break; 74 break;
86 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: 75 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
87 // If we aren't the host of the popup, then disregard the notification. 76 // If we aren't the host of the popup, then disregard the notification.
88 if (content::Details<ExtensionHost>(host()) == details) 77 if (content::Details<ExtensionHost>(host()) == details)
89 GetWidget()->Close(); 78 GetWidget()->Close();
90 break; 79 break;
91 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING: 80 case content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING:
92 // Make sure its the devtools window that inspecting our popup. 81 // Make sure its the devtools window that inspecting our popup.
93 // Widget::Close posts a task, which should give the devtools window a 82 // Widget::Close posts a task, which should give the devtools window a
94 // chance to finish detaching from the inspected RenderViewHost. 83 // chance to finish detaching from the inspected RenderViewHost.
(...skipping 18 matching lines...) Expand all
113 return sz; 102 return sz;
114 } 103 }
115 104
116 void ExtensionPopup::OnNativeFocusChange(gfx::NativeView focused_before, 105 void ExtensionPopup::OnNativeFocusChange(gfx::NativeView focused_before,
117 gfx::NativeView focused_now) { 106 gfx::NativeView focused_now) {
118 // TODO(msw): Implement something equivalent for Aura. See crbug.com/106958 107 // TODO(msw): Implement something equivalent for Aura. See crbug.com/106958
119 #if defined(OS_WIN) && !defined(USE_AURA) 108 #if defined(OS_WIN) && !defined(USE_AURA)
120 // Don't close if a child of this window is activated (only needed on Win). 109 // Don't close if a child of this window is activated (only needed on Win).
121 // ExtensionPopups can create Javascipt dialogs; see crbug.com/106723. 110 // ExtensionPopups can create Javascipt dialogs; see crbug.com/106723.
122 gfx::NativeView this_window = GetWidget()->GetNativeView(); 111 gfx::NativeView this_window = GetWidget()->GetNativeView();
123 if (!inspect_with_devtools_ && focused_before == this_window) { 112 if (inspect_with_devtools_ || focused_now == this_window ||
124 DCHECK_NE(focused_now, this_window); 113 ::GetWindow(focused_now, GW_OWNER) == this_window)
125 if (::GetWindow(focused_now, GW_OWNER) == this_window) 114 return;
115 gfx::NativeView focused_parent = focused_now;
116 while (focused_parent = ::GetParent(focused_parent)) {
117 if (this_window == focused_parent)
126 return; 118 return;
127 gfx::NativeView focused_parent = focused_now;
128 while (focused_parent = ::GetParent(focused_parent)) {
129 if (this_window == focused_parent)
130 return;
131 }
132 GetWidget()->Close();
133 } 119 }
120 GetWidget()->Close();
134 #endif 121 #endif
135 } 122 }
136 123
137 // static 124 // static
138 ExtensionPopup* ExtensionPopup::ShowPopup( 125 ExtensionPopup* ExtensionPopup::ShowPopup(
139 const GURL& url, 126 const GURL& url,
140 Browser* browser, 127 Browser* browser,
141 views::View* anchor_view, 128 views::View* anchor_view,
142 views::BubbleBorder::ArrowLocation arrow_location, 129 views::BubbleBorder::ArrowLocation arrow_location,
143 bool inspect_with_devtools) { 130 bool inspect_with_devtools) {
144 ExtensionProcessManager* manager = 131 ExtensionProcessManager* manager =
145 browser->profile()->GetExtensionProcessManager(); 132 browser->profile()->GetExtensionProcessManager();
146 ExtensionHost* host = manager->CreatePopupHost(url, browser); 133 ExtensionHost* host = manager->CreatePopupHost(url, browser);
147 ExtensionPopup* popup = new ExtensionPopup(browser, host, anchor_view, 134 ExtensionPopup* popup = new ExtensionPopup(browser, host, anchor_view,
148 arrow_location, inspect_with_devtools); 135 arrow_location, inspect_with_devtools);
149 browser::CreateViewsBubble(popup); 136 browser::CreateViewsBubble(popup);
150 137
151 // If the host had somehow finished loading, then we'd miss the notification 138 // If the host had somehow finished loading, then we'd miss the notification
152 // and not show. This seems to happen in single-process mode. 139 // and not show. This seems to happen in single-process mode.
153 if (host->did_stop_loading()) { 140 if (host->did_stop_loading())
154 popup->Show(); 141 popup->ShowBubble();
155 // Focus on the host contents when the bubble is first shown.
156 host->host_contents()->Focus();
157 }
158 142
159 return popup; 143 return popup;
160 } 144 }
145
146 void ExtensionPopup::ShowBubble() {
147 Show();
148
149 // Focus on the host contents when the bubble is first shown.
150 host()->host_contents()->Focus();
151
152 // Listen for widget focus changes after showing (used for non-aura win).
153 views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
154
155 if (inspect_with_devtools_) {
156 // Listen for the the devtools window closing.
157 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
158 content::Source<content::BrowserContext>(host()->profile()));
159 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(),
160 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
161 }
162 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_popup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698