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

Side by Side Diff: ui/views/widget/native_widget_aura.cc

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reverted changes for MockInputMethod. Created 5 years, 6 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
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/native_widget_aura.h" 5 #include "ui/views/widget/native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "third_party/skia/include/core/SkRegion.h" 9 #include "third_party/skia/include/core/SkRegion.h"
10 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/client/cursor_client.h" 11 #include "ui/aura/client/cursor_client.h"
12 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/client/screen_position_client.h" 13 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/client/window_tree_client.h" 14 #include "ui/aura/client/window_tree_client.h"
15 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h" 17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/aura/window_observer.h" 18 #include "ui/aura/window_observer.h"
19 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 20 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/ui_base_switches_util.h" 21 #include "ui/base/ui_base_switches_util.h"
22 #include "ui/base/ui_base_types.h" 22 #include "ui/base/ui_base_types.h"
23 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
24 #include "ui/events/event.h" 24 #include "ui/events/event.h"
25 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/font_list.h" 26 #include "ui/gfx/font_list.h"
27 #include "ui/gfx/screen.h" 27 #include "ui/gfx/screen.h"
28 #include "ui/native_theme/native_theme_aura.h" 28 #include "ui/native_theme/native_theme_aura.h"
29 #include "ui/views/drag_utils.h" 29 #include "ui/views/drag_utils.h"
30 #include "ui/views/ime/input_method_bridge.h" 30 #include "ui/views/views_delegate.h"
31 #include "ui/views/ime/null_input_method.h"
32 #include "ui/views/widget/drop_helper.h" 31 #include "ui/views/widget/drop_helper.h"
33 #include "ui/views/widget/native_widget_delegate.h" 32 #include "ui/views/widget/native_widget_delegate.h"
34 #include "ui/views/widget/root_view.h" 33 #include "ui/views/widget/root_view.h"
35 #include "ui/views/widget/tooltip_manager_aura.h" 34 #include "ui/views/widget/tooltip_manager_aura.h"
36 #include "ui/views/widget/widget_aura_utils.h" 35 #include "ui/views/widget/widget_aura_utils.h"
37 #include "ui/views/widget/widget_delegate.h" 36 #include "ui/views/widget/widget_delegate.h"
38 #include "ui/views/widget/window_reorderer.h" 37 #include "ui/views/widget/window_reorderer.h"
39 #include "ui/wm/core/shadow_types.h" 38 #include "ui/wm/core/shadow_types.h"
40 #include "ui/wm/core/window_animations.h" 39 #include "ui/wm/core/window_animations.h"
41 #include "ui/wm/core/window_util.h" 40 #include "ui/wm/core/window_util.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 259
261 void NativeWidgetAura::ReleaseCapture() { 260 void NativeWidgetAura::ReleaseCapture() {
262 if (window_) 261 if (window_)
263 window_->ReleaseCapture(); 262 window_->ReleaseCapture();
264 } 263 }
265 264
266 bool NativeWidgetAura::HasCapture() const { 265 bool NativeWidgetAura::HasCapture() const {
267 return window_ && window_->HasCapture(); 266 return window_ && window_->HasCapture();
268 } 267 }
269 268
270 InputMethod* NativeWidgetAura::CreateInputMethod() { 269 ui::InputMethod* NativeWidgetAura::GetInputMethod() {
271 if (!window_) 270 if (!window_)
272 return NULL; 271 return nullptr;
273
274 if (switches::IsTextInputFocusManagerEnabled())
275 return new NullInputMethod();
276
277 return new InputMethodBridge(this, GetHostInputMethod(), true);
278 }
279
280 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() {
281 return this;
282 }
283
284 ui::InputMethod* NativeWidgetAura::GetHostInputMethod() {
285 aura::Window* root_window = window_->GetRootWindow(); 272 aura::Window* root_window = window_->GetRootWindow();
286 return root_window->GetHost()->GetInputMethod(); 273 return root_window ? root_window->GetHost()->GetInputMethod() : nullptr;
287 } 274 }
288 275
289 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 276 void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
290 if (!window_) 277 if (!window_)
291 return; 278 return;
292 279
293 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 280 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow());
294 // When centering window, we take the intersection of the host and 281 // When centering window, we take the intersection of the host and
295 // the parent. We assume the root window represents the visible 282 // the parent. We assume the root window represents the visible
296 // rect of a single screen. 283 // rect of a single screen.
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 GetWidget()->widget_delegate()->CanMinimize()); 710 GetWidget()->widget_delegate()->CanMinimize());
724 window_->SetProperty(aura::client::kCanResizeKey, 711 window_->SetProperty(aura::client::kCanResizeKey,
725 GetWidget()->widget_delegate()->CanResize()); 712 GetWidget()->widget_delegate()->CanResize());
726 } 713 }
727 714
728 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { 715 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) {
729 OnEvent(native_event); 716 OnEvent(native_event);
730 } 717 }
731 718
732 //////////////////////////////////////////////////////////////////////////////// 719 ////////////////////////////////////////////////////////////////////////////////
733 // NativeWidgetAura, views::InputMethodDelegate implementation:
734
735 void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
736 FocusManager* focus_manager = GetWidget()->GetFocusManager();
737 delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
738 if (key.handled() || !focus_manager)
739 return;
740 focus_manager->OnKeyEvent(key);
741 }
742
743 ////////////////////////////////////////////////////////////////////////////////
744 // NativeWidgetAura, aura::WindowDelegate implementation: 720 // NativeWidgetAura, aura::WindowDelegate implementation:
745 721
746 gfx::Size NativeWidgetAura::GetMinimumSize() const { 722 gfx::Size NativeWidgetAura::GetMinimumSize() const {
747 return delegate_->GetMinimumSize(); 723 return delegate_->GetMinimumSize();
748 } 724 }
749 725
750 gfx::Size NativeWidgetAura::GetMaximumSize() const { 726 gfx::Size NativeWidgetAura::GetMaximumSize() const {
751 // If a window have a maximum size, the window should not be 727 // If a window have a maximum size, the window should not be
752 // maximizable. 728 // maximizable.
753 DCHECK(delegate_->GetMaximumSize().IsEmpty() || 729 DCHECK(delegate_->GetMaximumSize().IsEmpty() ||
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 intptr_t old) { 843 intptr_t old) {
868 if (key == aura::client::kShowStateKey) 844 if (key == aura::client::kShowStateKey)
869 delegate_->OnNativeWidgetWindowShowStateChanged(); 845 delegate_->OnNativeWidgetWindowShowStateChanged();
870 } 846 }
871 847
872 //////////////////////////////////////////////////////////////////////////////// 848 ////////////////////////////////////////////////////////////////////////////////
873 // NativeWidgetAura, ui::EventHandler implementation: 849 // NativeWidgetAura, ui::EventHandler implementation:
874 850
875 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 851 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
876 DCHECK(window_); 852 DCHECK(window_);
877 if (event->is_char()) {
878 // If a ui::InputMethod object is attached to the root window, character
879 // events are handled inside the object and are not passed to this function.
880 // If such object is not attached, character events might be sent (e.g. on
881 // Windows). In this case, we just skip these.
882 return;
883 }
884 // Renderer may send a key event back to us if the key event wasn't handled, 853 // Renderer may send a key event back to us if the key event wasn't handled,
885 // and the window may be invisible by that time. 854 // and the window may be invisible by that time.
886 if (!window_->IsVisible()) 855 if (!window_->IsVisible())
887 return; 856 return;
888 InputMethod* input_method = GetWidget()->GetInputMethod(); 857
889 if (!input_method) 858 FocusManager* focus_manager = GetWidget()->GetFocusManager();
890 return; 859 delegate_->OnKeyEvent(event);
891 input_method->DispatchKeyEvent(*event); 860 if (!event->handled() && focus_manager)
892 if (switches::IsTextInputFocusManagerEnabled()) { 861 focus_manager->OnKeyEvent(*event);
893 FocusManager* focus_manager = GetWidget()->GetFocusManager();
894 delegate_->OnKeyEvent(event);
895 if (!event->handled() && focus_manager)
896 focus_manager->OnKeyEvent(*event);
897 }
898 event->SetHandled(); 862 event->SetHandled();
899 } 863 }
900 864
901 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 865 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
902 DCHECK(window_); 866 DCHECK(window_);
903 DCHECK(window_->IsVisible()); 867 DCHECK(window_->IsVisible());
904 if (event->type() == ui::ET_MOUSEWHEEL) { 868 if (event->type() == ui::ET_MOUSEWHEEL) {
905 delegate_->OnMouseEvent(event); 869 delegate_->OnMouseEvent(event);
906 if (event->handled()) 870 if (event->handled())
907 return; 871 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 GetWidget()->GetFocusManager()->StoreFocusedView(true); 909 GetWidget()->GetFocusManager()->StoreFocusedView(true);
946 } 910 }
947 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 911 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active);
948 } 912 }
949 913
950 //////////////////////////////////////////////////////////////////////////////// 914 ////////////////////////////////////////////////////////////////////////////////
951 // NativeWidgetAura, aura::client::FocusChangeObserver: 915 // NativeWidgetAura, aura::client::FocusChangeObserver:
952 916
953 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 917 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
954 aura::Window* lost_focus) { 918 aura::Window* lost_focus) {
955 if (window_ == gained_focus) { 919 if (window_ == gained_focus)
956 // In aura, it is possible for child native widgets to take input and focus,
957 // this differs from the behavior on windows.
958 if (GetWidget()->GetInputMethod()) // Null in tests.
959 GetWidget()->GetInputMethod()->OnFocus();
960 delegate_->OnNativeFocus(); 920 delegate_->OnNativeFocus();
961 } else if (window_ == lost_focus) { 921 else if (window_ == lost_focus)
962 // GetInputMethod() recreates the input method if it's previously been
963 // destroyed. If we get called during destruction, the input method will be
964 // gone, and creating a new one and telling it that we lost the focus will
965 // trigger a DCHECK (the new input method doesn't think that we have the
966 // focus and doesn't expect a blur). OnBlur() shouldn't be called during
967 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the
968 // case in tests).
969 if (!destroying_) {
970 if (GetWidget()->GetInputMethod())
971 GetWidget()->GetInputMethod()->OnBlur();
972 } else {
973 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
974 }
975
976 delegate_->OnNativeBlur(); 922 delegate_->OnNativeBlur();
977 }
978 } 923 }
979 924
980 //////////////////////////////////////////////////////////////////////////////// 925 ////////////////////////////////////////////////////////////////////////////////
981 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: 926 // NativeWidgetAura, aura::WindowDragDropDelegate implementation:
982 927
983 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 928 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
984 DCHECK(drop_helper_.get() != NULL); 929 DCHECK(drop_helper_.get() != NULL);
985 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 930 last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
986 event.location(), event.source_operations()); 931 event.location(), event.source_operations());
987 } 932 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 1149 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
1205 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 1150 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
1206 return gfx::FontList(gfx::Font(caption_font)); 1151 return gfx::FontList(gfx::Font(caption_font));
1207 #else 1152 #else
1208 return gfx::FontList(); 1153 return gfx::FontList();
1209 #endif 1154 #endif
1210 } 1155 }
1211 1156
1212 } // namespace internal 1157 } // namespace internal
1213 } // namespace views 1158 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698