summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 21:03:13 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 21:03:13 +0000
commite00e18af2f61e8eec071778f66ef15e8bf671d42 (patch)
treeae6a8d76011d08df79e2e7e3c22bb3440c822973 /chrome
parentf9a88c50069a49d1314a755dd2aac3812c23659d (diff)
downloadchromium_src-e00e18af2f61e8eec071778f66ef15e8bf671d42.zip
chromium_src-e00e18af2f61e8eec071778f66ef15e8bf671d42.tar.gz
chromium_src-e00e18af2f61e8eec071778f66ef15e8bf671d42.tar.bz2
Making browser bubble notifies to its delegate whether it
lost focus to a child window. This is used to prevent closing browser/page action bubble when they lose focus to a select popup or alert box. BUG=37784 TEST=Start Chrome with extensions that have a page action and browser action that contains selects (combobox) and a way to show an alert box. Verify that showing the select popup or the alert dialog does not cause the bubble to close. Review URL: http://codereview.chromium.org/899002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41630 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/browser_actions_container.cc24
-rw-r--r--chrome/browser/views/browser_actions_container.h3
-rw-r--r--chrome/browser/views/browser_bubble.h5
-rw-r--r--chrome/browser/views/browser_bubble_gtk.cc9
-rw-r--r--chrome/browser/views/browser_bubble_win.cc19
-rw-r--r--chrome/browser/views/location_bar_view.cc7
-rw-r--r--chrome/browser/views/location_bar_view.h2
7 files changed, 36 insertions, 33 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc
index 3029c5d..a8fa362 100644
--- a/chrome/browser/views/browser_actions_container.cc
+++ b/chrome/browser/views/browser_actions_container.cc
@@ -843,28 +843,12 @@ void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) {
}
void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble,
- gfx::NativeView focused_view) {
- if (!popup_)
+ bool lost_focus_to_child) {
+ // Don't close when we are losing focus to a child window, this is the case
+ // for select popups and alert for example.
+ if (!popup_ || lost_focus_to_child)
return;
-#if defined(OS_WIN)
- // Don't hide when we are losing focus to a child window. This is the case
- // with select popups.
- // TODO(jcampan): http://crbugs.com/29131 make that work on toolkit views
- // so this #if defined can be removed.
- gfx::NativeView popup_native_view = popup_->native_view();
- gfx::NativeView parent = focused_view;
- while (parent = ::GetParent(parent)) {
- if (parent == popup_native_view)
- return;
- }
-
- // Don't close when we are losing focus to a window we own.
- // This is the case with JavaScript message boxes (such as alerts).
- if (::GetWindow(focused_view, GW_OWNER) == popup_native_view)
- return;
-#endif
-
// This is a bit annoying. If you click on the button that generated the
// current popup, then we first get this lost focus message, and then
// we get the click action. This results in the popup being immediately
diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h
index 2a55ed6..1452358 100644
--- a/chrome/browser/views/browser_actions_container.h
+++ b/chrome/browser/views/browser_actions_container.h
@@ -311,8 +311,7 @@ class BrowserActionsContainer
virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble);
virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble);
virtual void BubbleGotFocus(BrowserBubble* bubble);
- virtual void BubbleLostFocus(BrowserBubble* bubble,
- gfx::NativeView focused_view);
+ virtual void BubbleLostFocus(BrowserBubble* bubble, bool lost_focus_to_child);
// Overridden from views::ViewMenuDelegate:
virtual void RunMenu(View* source, const gfx::Point& pt);
diff --git a/chrome/browser/views/browser_bubble.h b/chrome/browser/views/browser_bubble.h
index a75211c..c891785 100644
--- a/chrome/browser/views/browser_bubble.h
+++ b/chrome/browser/views/browser_bubble.h
@@ -31,10 +31,9 @@ class BrowserBubble {
virtual void BubbleGotFocus(BrowserBubble* bubble) {}
// Called when the bubble became inactive / lost focus.
- // |focused_view| is the NativeView getting the focus, it may be NULL if the
- // popup was closed programatically.
+ // |lost_focus_to_child| is true when a child window became active.
virtual void BubbleLostFocus(BrowserBubble* bubble,
- gfx::NativeView focused_view) {}
+ bool lost_focus_to_child) {}
};
// Note that the bubble will size itself to the preferred size of |view|.
diff --git a/chrome/browser/views/browser_bubble_gtk.cc b/chrome/browser/views/browser_bubble_gtk.cc
index cf2ff0c..8fdedb8 100644
--- a/chrome/browser/views/browser_bubble_gtk.cc
+++ b/chrome/browser/views/browser_bubble_gtk.cc
@@ -34,7 +34,7 @@ class BubbleWidget : public views::WidgetGtk {
if (IsActive()) {
BrowserBubble::Delegate* delegate = bubble_->delegate();
if (delegate)
- delegate->BubbleLostFocus(bubble_, NULL);
+ delegate->BubbleLostFocus(bubble_, false);
}
views::WidgetGtk::Close();
}
@@ -43,7 +43,7 @@ class BubbleWidget : public views::WidgetGtk {
if (IsActive()) {
BrowserBubble::Delegate* delegate = bubble_->delegate();
if (delegate)
- delegate->BubbleLostFocus(bubble_, NULL);
+ delegate->BubbleLostFocus(bubble_, false);
}
views::WidgetGtk::Hide();
}
@@ -58,7 +58,10 @@ class BubbleWidget : public views::WidgetGtk {
return;
}
- delegate->BubbleLostFocus(bubble_, GetNativeView());
+ // TODO(jcampan): http://crbugs.com/29131 Check if the window we are losing
+ // focus to is a child window and pass that to the call
+ // below.
+ delegate->BubbleLostFocus(bubble_, false);
}
virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event) {
diff --git a/chrome/browser/views/browser_bubble_win.cc b/chrome/browser/views/browser_bubble_win.cc
index a74b84a..c9add4f 100644
--- a/chrome/browser/views/browser_bubble_win.cc
+++ b/chrome/browser/views/browser_bubble_win.cc
@@ -59,7 +59,24 @@ class BubbleWidget : public views::WidgetWin {
}
if (action == WA_INACTIVE && !closed_) {
- delegate->BubbleLostFocus(bubble_, window);
+ bool lost_focus_to_child = false;
+
+ // Are we a parent of this window?
+ gfx::NativeView parent = window;
+ while (parent = ::GetParent(parent)) {
+ if (window == GetNativeView()) {
+ lost_focus_to_child = true;
+ break;
+ }
+ }
+
+ // Do we own this window?
+ if (!lost_focus_to_child &&
+ ::GetWindow(window, GW_OWNER) == GetNativeView()) {
+ lost_focus_to_child = true;
+ }
+
+ delegate->BubbleLostFocus(bubble_, lost_focus_to_child);
}
}
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index d52ac39..37c1759 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -1635,9 +1635,10 @@ void LocationBarView::PageActionImageView::BubbleBrowserWindowClosing(
}
void LocationBarView::PageActionImageView::BubbleLostFocus(
- BrowserBubble* bubble,
- gfx::NativeView focused_view) {
- if (!popup_)
+ BrowserBubble* bubble, bool lost_focus_to_child) {
+ // Don't close when we are losing focus to a child window, this is the case
+ // for select popups and alert for example.
+ if (!popup_ || lost_focus_to_child)
return;
MessageLoop::current()->PostTask(FROM_HERE,
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index 11965fb..e3b4597 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -441,7 +441,7 @@ class LocationBarView : public LocationBar,
// Overridden from BrowserBubble::Delegate
virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble);
virtual void BubbleLostFocus(BrowserBubble* bubble,
- gfx::NativeView focused_view);
+ bool lost_focus_to_child);
// Called to notify the PageAction that it should determine whether to be
// visible or hidden. |contents| is the TabContents that is active, |url|