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