OLD | NEW |
---|---|
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 Loading... | |
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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 // DesktopNativeWidgetAura, aura::client::ActivationDelegate implementation: | 1050 // DesktopNativeWidgetAura, aura::client::ActivationDelegate implementation: |
1050 | 1051 |
1051 bool DesktopNativeWidgetAura::ShouldActivate() const { | 1052 bool DesktopNativeWidgetAura::ShouldActivate() const { |
1052 return can_activate_ && native_widget_delegate_->CanActivate(); | 1053 return can_activate_ && native_widget_delegate_->CanActivate(); |
1053 } | 1054 } |
1054 | 1055 |
1055 //////////////////////////////////////////////////////////////////////////////// | 1056 //////////////////////////////////////////////////////////////////////////////// |
1056 // DesktopNativeWidgetAura, aura::client::ActivationChangeObserver | 1057 // DesktopNativeWidgetAura, aura::client::ActivationChangeObserver |
1057 // implementation: | 1058 // implementation: |
1058 | 1059 |
1059 void DesktopNativeWidgetAura::OnWindowActivated(aura::Window* gained_active, | 1060 void DesktopNativeWidgetAura::OnWindowActivated(aura::Window* gained_active, |
sky
2014/05/16 19:41:54
Is this still needed after your changes? Same comm
msw
2014/05/16 19:55:41
Sadly yes; at least for now. Without this behavior
| |
1060 aura::Window* lost_active) { | 1061 aura::Window* lost_active) { |
1061 DCHECK(content_window_ == gained_active || content_window_ == lost_active); | 1062 DCHECK(content_window_ == gained_active || content_window_ == lost_active); |
1062 if (gained_active == content_window_ && restore_focus_on_activate_) { | 1063 if (gained_active == content_window_ && restore_focus_on_activate_) { |
1063 restore_focus_on_activate_ = false; | 1064 restore_focus_on_activate_ = false; |
1064 GetWidget()->GetFocusManager()->RestoreFocusedView(); | 1065 GetWidget()->GetFocusManager()->RestoreFocusedView(); |
1065 } else if (lost_active == content_window_ && GetWidget()->HasFocusManager()) { | 1066 } else if (lost_active == content_window_ && GetWidget()->HasFocusManager()) { |
1066 DCHECK(!restore_focus_on_activate_); | 1067 DCHECK(!restore_focus_on_activate_); |
1067 restore_focus_on_activate_ = true; | 1068 restore_focus_on_activate_ = true; |
1068 // Pass in false so that ClearNativeFocus() isn't invoked. | 1069 // Pass in false so that ClearNativeFocus() isn't invoked. |
1069 GetWidget()->GetFocusManager()->StoreFocusedView(false); | 1070 GetWidget()->GetFocusManager()->StoreFocusedView(false); |
1070 } | 1071 } |
1071 } | 1072 } |
1072 | 1073 |
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 Loading... | |
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 |
OLD | NEW |