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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura.cc

Issue 285403003: Re-land: Store and restore view focus in OnWindowFocused. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable ConstrainedWindowViewTest.ClosesOnEscape on Win XP. Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2012 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/cursor_client.h" 10 #include "ui/aura/client/cursor_client.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 internal::NativeWidgetDelegate* delegate) 249 internal::NativeWidgetDelegate* delegate)
250 : desktop_window_tree_host_(NULL), 250 : desktop_window_tree_host_(NULL),
251 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 251 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
252 close_widget_factory_(this), 252 close_widget_factory_(this),
253 can_activate_(true), 253 can_activate_(true),
254 content_window_container_(NULL), 254 content_window_container_(NULL),
255 content_window_(new aura::Window(this)), 255 content_window_(new aura::Window(this)),
256 native_widget_delegate_(delegate), 256 native_widget_delegate_(delegate),
257 last_drop_operation_(ui::DragDropTypes::DRAG_NONE), 257 last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
258 restore_focus_on_activate_(false), 258 restore_focus_on_activate_(false),
259 restore_focus_on_window_focus_(false),
259 cursor_(gfx::kNullCursor), 260 cursor_(gfx::kNullCursor),
260 widget_type_(Widget::InitParams::TYPE_WINDOW) { 261 widget_type_(Widget::InitParams::TYPE_WINDOW) {
261 aura::client::SetFocusChangeObserver(content_window_, this); 262 aura::client::SetFocusChangeObserver(content_window_, this);
262 aura::client::SetActivationChangeObserver(content_window_, this); 263 aura::client::SetActivationChangeObserver(content_window_, this);
263 } 264 }
264 265
265 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() { 266 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
266 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 267 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
267 delete native_widget_delegate_; 268 delete native_widget_delegate_;
268 else 269 else
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 //////////////////////////////////////////////////////////////////////////////// 1074 ////////////////////////////////////////////////////////////////////////////////
1074 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: 1075 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation:
1075 1076
1076 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 1077 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
1077 aura::Window* lost_focus) { 1078 aura::Window* lost_focus) {
1078 if (content_window_ == gained_focus) { 1079 if (content_window_ == gained_focus) {
1079 desktop_window_tree_host_->OnNativeWidgetFocus(); 1080 desktop_window_tree_host_->OnNativeWidgetFocus();
1080 native_widget_delegate_->OnNativeFocus(lost_focus); 1081 native_widget_delegate_->OnNativeFocus(lost_focus);
1081 1082
1082 // If focus is moving from a descendant Window to |content_window_| then 1083 // If focus is moving from a descendant Window to |content_window_| then
1083 // native activation hasn't changed. We still need to inform the InputMethod 1084 // native activation hasn't changed. Still, the InputMethod and FocusManager
1084 // we've been focused though. 1085 // must be informed of the Window focus change.
1085 InputMethod* input_method = GetWidget()->GetInputMethod(); 1086 InputMethod* input_method = GetWidget()->GetInputMethod();
1086 if (input_method) 1087 if (input_method)
1087 input_method->OnFocus(); 1088 input_method->OnFocus();
1089
1090 if (restore_focus_on_window_focus_) {
1091 restore_focus_on_window_focus_ = false;
1092 GetWidget()->GetFocusManager()->RestoreFocusedView();
1093 }
1088 } else if (content_window_ == lost_focus) { 1094 } else if (content_window_ == lost_focus) {
1089 desktop_window_tree_host_->OnNativeWidgetBlur(); 1095 desktop_window_tree_host_->OnNativeWidgetBlur();
1090 native_widget_delegate_->OnNativeBlur( 1096 native_widget_delegate_->OnNativeBlur(gained_focus);
1091 aura::client::GetFocusClient(content_window_)->GetFocusedWindow()); 1097
1098 DCHECK(!restore_focus_on_window_focus_);
1099 restore_focus_on_window_focus_ = true;
1100 GetWidget()->GetFocusManager()->StoreFocusedView(false);
1092 } 1101 }
1093 } 1102 }
1094 1103
1095 //////////////////////////////////////////////////////////////////////////////// 1104 ////////////////////////////////////////////////////////////////////////////////
1096 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate: 1105 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate:
1097 1106
1098 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 1107 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
1099 FocusManager* focus_manager = 1108 FocusManager* focus_manager =
1100 native_widget_delegate_->AsWidget()->GetFocusManager(); 1109 native_widget_delegate_->AsWidget()->GetFocusManager();
1101 native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 1110 native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 if (cursor_reference_count_ == 0) { 1203 if (cursor_reference_count_ == 0) {
1195 // We are the last DesktopNativeWidgetAura instance, and we are responsible 1204 // We are the last DesktopNativeWidgetAura instance, and we are responsible
1196 // for cleaning up |cursor_manager_|. 1205 // for cleaning up |cursor_manager_|.
1197 delete cursor_manager_; 1206 delete cursor_manager_;
1198 native_cursor_manager_ = NULL; 1207 native_cursor_manager_ = NULL;
1199 cursor_manager_ = NULL; 1208 cursor_manager_ = NULL;
1200 } 1209 }
1201 } 1210 }
1202 1211
1203 } // namespace views 1212 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_native_widget_aura.h ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698