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/trace_event/trace_event.h" | 8 #include "base/trace_event/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 10 matching lines...) Expand all Loading... |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
23 #include "ui/gfx/geometry/point_conversions.h" | 23 #include "ui/gfx/geometry/point_conversions.h" |
24 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
25 #include "ui/gfx/geometry/size_conversions.h" | 25 #include "ui/gfx/geometry/size_conversions.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
28 #include "ui/views/corewm/tooltip.h" | 28 #include "ui/views/corewm/tooltip.h" |
29 #include "ui/views/corewm/tooltip_controller.h" | 29 #include "ui/views/corewm/tooltip_controller.h" |
30 #include "ui/views/drag_utils.h" | 30 #include "ui/views/drag_utils.h" |
31 #include "ui/views/ime/input_method_bridge.h" | |
32 #include "ui/views/ime/null_input_method.h" | |
33 #include "ui/views/view_constants_aura.h" | 31 #include "ui/views/view_constants_aura.h" |
34 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" | 32 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" |
35 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 33 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
36 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" | 34 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" |
37 #include "ui/views/widget/desktop_aura/desktop_event_client.h" | 35 #include "ui/views/widget/desktop_aura/desktop_event_client.h" |
38 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" | 36 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" |
39 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 37 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
40 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" | 38 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" |
41 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" | 39 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" |
42 #include "ui/views/widget/drop_helper.h" | 40 #include "ui/views/widget/drop_helper.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 View* view_for_activation = | 371 View* view_for_activation = |
374 GetWidget()->GetFocusManager()->GetFocusedView() ? | 372 GetWidget()->GetFocusManager()->GetFocusedView() ? |
375 GetWidget()->GetFocusManager()->GetFocusedView() : | 373 GetWidget()->GetFocusManager()->GetFocusedView() : |
376 GetWidget()->GetFocusManager()->GetStoredFocusView(); | 374 GetWidget()->GetFocusManager()->GetStoredFocusView(); |
377 if (!view_for_activation) | 375 if (!view_for_activation) |
378 view_for_activation = GetWidget()->GetRootView(); | 376 view_for_activation = GetWidget()->GetRootView(); |
379 activation_client->ActivateWindow( | 377 activation_client->ActivateWindow( |
380 view_for_activation->GetWidget()->GetNativeView()); | 378 view_for_activation->GetWidget()->GetNativeView()); |
381 // Refreshes the focus info to IMF in case that IMF cached the old info | 379 // Refreshes the focus info to IMF in case that IMF cached the old info |
382 // about focused text input client when it was "inactive". | 380 // about focused text input client when it was "inactive". |
383 GetHostInputMethod()->OnFocus(); | 381 GetInputMethod()->OnFocus(); |
384 } | 382 } |
385 } else { | 383 } else { |
386 // If we're not active we need to deactivate the corresponding | 384 // If we're not active we need to deactivate the corresponding |
387 // aura::Window. This way if a child widget is active it gets correctly | 385 // aura::Window. This way if a child widget is active it gets correctly |
388 // deactivated (child widgets don't get native desktop activation changes, | 386 // deactivated (child widgets don't get native desktop activation changes, |
389 // only aura activation changes). | 387 // only aura activation changes). |
390 aura::Window* active_window = activation_client->GetActiveWindow(); | 388 aura::Window* active_window = activation_client->GetActiveWindow(); |
391 if (active_window) { | 389 if (active_window) { |
392 activation_client->DeactivateWindow(active_window); | 390 activation_client->DeactivateWindow(active_window); |
393 GetHostInputMethod()->OnBlur(); | 391 GetInputMethod()->OnBlur(); |
394 } | 392 } |
395 } | 393 } |
396 } | 394 } |
397 | 395 |
398 //////////////////////////////////////////////////////////////////////////////// | 396 //////////////////////////////////////////////////////////////////////////////// |
399 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation: | 397 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation: |
400 | 398 |
401 void DesktopNativeWidgetAura::InitNativeWidget( | 399 void DesktopNativeWidgetAura::InitNativeWidget( |
402 const Widget::InitParams& params) { | 400 const Widget::InitParams& params) { |
403 ownership_ = params.ownership; | 401 ownership_ = params.ownership; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return; | 619 return; |
622 | 620 |
623 content_window_->ReleaseCapture(); | 621 content_window_->ReleaseCapture(); |
624 } | 622 } |
625 | 623 |
626 bool DesktopNativeWidgetAura::HasCapture() const { | 624 bool DesktopNativeWidgetAura::HasCapture() const { |
627 return content_window_ && content_window_->HasCapture() && | 625 return content_window_ && content_window_->HasCapture() && |
628 desktop_window_tree_host_->HasCapture(); | 626 desktop_window_tree_host_->HasCapture(); |
629 } | 627 } |
630 | 628 |
631 InputMethod* DesktopNativeWidgetAura::CreateInputMethod() { | 629 ui::InputMethod* DesktopNativeWidgetAura::GetInputMethod() { |
632 if (switches::IsTextInputFocusManagerEnabled()) | 630 return host() ? host()->GetInputMethod() : nullptr; |
633 return new NullInputMethod(); | |
634 | |
635 return new InputMethodBridge(this, GetHostInputMethod(), false); | |
636 } | |
637 | |
638 internal::InputMethodDelegate* | |
639 DesktopNativeWidgetAura::GetInputMethodDelegate() { | |
640 return this; | |
641 } | |
642 | |
643 ui::InputMethod* DesktopNativeWidgetAura::GetHostInputMethod() { | |
644 return host()->GetInputMethod(); | |
645 } | 631 } |
646 | 632 |
647 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) { | 633 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) { |
648 if (content_window_) | 634 if (content_window_) |
649 desktop_window_tree_host_->CenterWindow(size); | 635 desktop_window_tree_host_->CenterWindow(size); |
650 } | 636 } |
651 | 637 |
652 void DesktopNativeWidgetAura::GetWindowPlacement( | 638 void DesktopNativeWidgetAura::GetWindowPlacement( |
653 gfx::Rect* bounds, | 639 gfx::Rect* bounds, |
654 ui::WindowShowState* maximized) const { | 640 ui::WindowShowState* maximized) const { |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 } | 1110 } |
1125 | 1111 |
1126 //////////////////////////////////////////////////////////////////////////////// | 1112 //////////////////////////////////////////////////////////////////////////////// |
1127 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: | 1113 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: |
1128 | 1114 |
1129 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, | 1115 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, |
1130 aura::Window* lost_focus) { | 1116 aura::Window* lost_focus) { |
1131 if (content_window_ == gained_focus) { | 1117 if (content_window_ == gained_focus) { |
1132 desktop_window_tree_host_->OnNativeWidgetFocus(); | 1118 desktop_window_tree_host_->OnNativeWidgetFocus(); |
1133 native_widget_delegate_->OnNativeFocus(); | 1119 native_widget_delegate_->OnNativeFocus(); |
1134 | |
1135 // If focus is moving from a descendant Window to |content_window_| then | |
1136 // native activation hasn't changed. Still, the InputMethod must be informed | |
1137 // of the Window focus change. | |
1138 InputMethod* input_method = GetWidget()->GetInputMethod(); | |
1139 if (input_method) | |
1140 input_method->OnFocus(); | |
1141 } else if (content_window_ == lost_focus) { | 1120 } else if (content_window_ == lost_focus) { |
1142 desktop_window_tree_host_->OnNativeWidgetBlur(); | 1121 desktop_window_tree_host_->OnNativeWidgetBlur(); |
1143 native_widget_delegate_->OnNativeBlur(); | 1122 native_widget_delegate_->OnNativeBlur(); |
1144 } | 1123 } |
1145 } | 1124 } |
1146 | 1125 |
1147 //////////////////////////////////////////////////////////////////////////////// | 1126 //////////////////////////////////////////////////////////////////////////////// |
1148 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate: | |
1149 | |
1150 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | |
1151 FocusManager* focus_manager = | |
1152 native_widget_delegate_->AsWidget()->GetFocusManager(); | |
1153 native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | |
1154 if (key.handled() || !focus_manager) | |
1155 return; | |
1156 focus_manager->OnKeyEvent(key); | |
1157 } | |
1158 | |
1159 //////////////////////////////////////////////////////////////////////////////// | |
1160 // DesktopNativeWidgetAura, aura::WindowDragDropDelegate implementation: | 1127 // DesktopNativeWidgetAura, aura::WindowDragDropDelegate implementation: |
1161 | 1128 |
1162 void DesktopNativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { | 1129 void DesktopNativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { |
1163 DCHECK(drop_helper_.get() != NULL); | 1130 DCHECK(drop_helper_.get() != NULL); |
1164 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), | 1131 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), |
1165 event.location(), event.source_operations()); | 1132 event.location(), event.source_operations()); |
1166 } | 1133 } |
1167 | 1134 |
1168 int DesktopNativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { | 1135 int DesktopNativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { |
1169 DCHECK(drop_helper_.get() != NULL); | 1136 DCHECK(drop_helper_.get() != NULL); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 if (cursor_reference_count_ == 0) { | 1200 if (cursor_reference_count_ == 0) { |
1234 // We are the last DesktopNativeWidgetAura instance, and we are responsible | 1201 // We are the last DesktopNativeWidgetAura instance, and we are responsible |
1235 // for cleaning up |cursor_manager_|. | 1202 // for cleaning up |cursor_manager_|. |
1236 delete cursor_manager_; | 1203 delete cursor_manager_; |
1237 native_cursor_manager_ = NULL; | 1204 native_cursor_manager_ = NULL; |
1238 cursor_manager_ = NULL; | 1205 cursor_manager_ = NULL; |
1239 } | 1206 } |
1240 } | 1207 } |
1241 | 1208 |
1242 } // namespace views | 1209 } // namespace views |
OLD | NEW |