summaryrefslogtreecommitdiffstats
path: root/ui/views/widget
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 23:27:40 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-18 23:27:40 +0000
commit87a4b990583c80a24b2122662beebc63e7b96451 (patch)
tree70a000af2b45c1465eaf5f49dc8a1c67d83aa12c /ui/views/widget
parent1fe51aca23ab7d0d9286045077d0c50f0ddabddd (diff)
downloadchromium_src-87a4b990583c80a24b2122662beebc63e7b96451.zip
chromium_src-87a4b990583c80a24b2122662beebc63e7b96451.tar.gz
chromium_src-87a4b990583c80a24b2122662beebc63e7b96451.tar.bz2
aura: Fix WidgetFocusChangeListener::OnNativeFocusChange().
In Aura, we were passing the newly-focused view through views::WidgetFocusManager::OnWidgetFocusEvent()'s "focused_before" parameter. This made us not close extension popups when they lost the focus. (Note that a popup still doesn't get closed upon clicking outside of the popup on the desktop, presumably because the popup retains the focus in Ash.) BUG=132697 TEST=added, also manual testing Review URL: https://chromiumcodereview.appspot.com/10562025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/widget')
-rw-r--r--ui/views/widget/native_widget_aura.cc21
-rw-r--r--ui/views/widget/native_widget_aura.h5
-rw-r--r--ui/views/widget/native_widget_win.cc4
-rw-r--r--ui/views/widget/native_widget_win.h2
-rw-r--r--ui/views/widget/widget.cc8
-rw-r--r--ui/views/widget/widget.h4
6 files changed, 29 insertions, 15 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index b169f74..76761ec 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -149,6 +149,7 @@ NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
can_activate_(true),
+ destroying_(false),
cursor_(gfx::kNullCursor),
saved_window_state_(ui::SHOW_STATE_DEFAULT) {
}
@@ -700,17 +701,26 @@ void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
}
-void NativeWidgetAura::OnFocus() {
+void NativeWidgetAura::OnFocus(aura::Window* old_focused_window) {
// In aura, it is possible for child native widgets to take input and focus,
// this differs from the behavior on windows.
GetWidget()->GetInputMethod()->OnFocus();
- delegate_->OnNativeFocus(window_);
+ delegate_->OnNativeFocus(old_focused_window);
}
void NativeWidgetAura::OnBlur() {
- // Not only top level native widget can take input and focus, child
- // widgets are allowed also.
- GetWidget()->GetInputMethod()->OnBlur();
+ // GetInputMethod() recreates the input method if it's previously been
+ // destroyed. If we get called during destruction, the input method will be
+ // gone, and creating a new one and telling it that we lost the focus will
+ // trigger a DCHECK (the new input method doesn't think that we have the focus
+ // and doesn't expect a blur). OnBlur() shouldn't be called during
+ // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case
+ // in tests).
+ if (!destroying_)
+ GetWidget()->GetInputMethod()->OnBlur();
+ else
+ DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
+
delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow());
}
@@ -902,6 +912,7 @@ int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) {
// NativeWidgetAura, protected:
NativeWidgetAura::~NativeWidgetAura() {
+ destroying_ = true;
if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
delete delegate_;
else
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index 57dbe27..f4c177f 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -131,7 +131,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
- virtual void OnFocus() OVERRIDE;
+ virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE;
virtual void OnBlur() OVERRIDE;
virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE;
virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
@@ -189,6 +189,9 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
// Can we be made active?
bool can_activate_;
+ // Are we in the destructor?
+ bool destroying_;
+
gfx::NativeCursor cursor_;
// The saved window state for exiting full screen state.
diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc
index 402d53f..2fcf057 100644
--- a/ui/views/widget/native_widget_win.cc
+++ b/ui/views/widget/native_widget_win.cc
@@ -2022,8 +2022,8 @@ LRESULT NativeWidgetWin::OnSetCursor(UINT message,
return 0;
}
-void NativeWidgetWin::OnSetFocus(HWND focused_window) {
- delegate_->OnNativeFocus(focused_window);
+void NativeWidgetWin::OnSetFocus(HWND old_focused_window) {
+ delegate_->OnNativeFocus(old_focused_window);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->OnFocus();
diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h
index 868c24b..b02b3b2 100644
--- a/ui/views/widget/native_widget_win.h
+++ b/ui/views/widget/native_widget_win.h
@@ -427,7 +427,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data);
virtual LRESULT OnReflectedMessage(UINT msg, WPARAM w_param, LPARAM l_param);
virtual LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param);
- virtual void OnSetFocus(HWND focused_window);
+ virtual void OnSetFocus(HWND old_focused_window);
virtual LRESULT OnSetText(const wchar_t* text);
virtual void OnSettingChange(UINT flags, const wchar_t* section);
virtual void OnSize(UINT param, const CSize& size);
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index 0bc0906..31748ed 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -941,14 +941,14 @@ void Widget::OnNativeWidgetActivationChanged(bool active) {
OnWidgetActivationChanged(this, active));
}
-void Widget::OnNativeFocus(gfx::NativeView focused_view) {
- WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(focused_view,
+void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
+ WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
GetNativeView());
}
-void Widget::OnNativeBlur(gfx::NativeView focused_view) {
+void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
- focused_view);
+ new_focused_view);
}
void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index 92d1b28..9ee8792 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -630,8 +630,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
virtual bool IsInactiveRenderingDisabled() const OVERRIDE;
virtual void EnableInactiveRendering() OVERRIDE;
virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE;
- virtual void OnNativeFocus(gfx::NativeView focused_view) OVERRIDE;
- virtual void OnNativeBlur(gfx::NativeView focused_view) OVERRIDE;
+ virtual void OnNativeFocus(gfx::NativeView old_focused_view) OVERRIDE;
+ virtual void OnNativeBlur(gfx::NativeView new_focused_view) OVERRIDE;
virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE;
virtual void OnNativeWidgetCreated() OVERRIDE;
virtual void OnNativeWidgetDestroying() OVERRIDE;