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

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: nits. Created 5 years, 5 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
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_types.h" 21 #include "ui/base/ui_base_types.h"
22 #include "ui/compositor/layer.h" 22 #include "ui/compositor/layer.h"
23 #include "ui/events/event.h" 23 #include "ui/events/event.h"
24 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/font_list.h" 25 #include "ui/gfx/font_list.h"
26 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
27 #include "ui/native_theme/native_theme_aura.h" 27 #include "ui/native_theme/native_theme_aura.h"
28 #include "ui/views/drag_utils.h" 28 #include "ui/views/drag_utils.h"
29 #include "ui/views/ime/input_method_bridge.h" 29 #include "ui/views/views_delegate.h"
30 #include "ui/views/ime/null_input_method.h"
31 #include "ui/views/widget/drop_helper.h" 30 #include "ui/views/widget/drop_helper.h"
32 #include "ui/views/widget/native_widget_delegate.h" 31 #include "ui/views/widget/native_widget_delegate.h"
33 #include "ui/views/widget/root_view.h" 32 #include "ui/views/widget/root_view.h"
34 #include "ui/views/widget/tooltip_manager_aura.h" 33 #include "ui/views/widget/tooltip_manager_aura.h"
35 #include "ui/views/widget/widget_aura_utils.h" 34 #include "ui/views/widget/widget_aura_utils.h"
36 #include "ui/views/widget/widget_delegate.h" 35 #include "ui/views/widget/widget_delegate.h"
37 #include "ui/views/widget/window_reorderer.h" 36 #include "ui/views/widget/window_reorderer.h"
38 #include "ui/wm/core/shadow_types.h" 37 #include "ui/wm/core/shadow_types.h"
39 #include "ui/wm/core/window_animations.h" 38 #include "ui/wm/core/window_animations.h"
40 #include "ui/wm/core/window_util.h" 39 #include "ui/wm/core/window_util.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 258
260 void NativeWidgetAura::ReleaseCapture() { 259 void NativeWidgetAura::ReleaseCapture() {
261 if (window_) 260 if (window_)
262 window_->ReleaseCapture(); 261 window_->ReleaseCapture();
263 } 262 }
264 263
265 bool NativeWidgetAura::HasCapture() const { 264 bool NativeWidgetAura::HasCapture() const {
266 return window_ && window_->HasCapture(); 265 return window_ && window_->HasCapture();
267 } 266 }
268 267
269 InputMethod* NativeWidgetAura::CreateInputMethod() { 268 ui::InputMethod* NativeWidgetAura::GetInputMethod() {
270 if (!window_) 269 if (!window_)
271 return NULL; 270 return nullptr;
272
273 return new InputMethodBridge(this, GetHostInputMethod(), true);
274 }
275
276 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() {
277 return this;
278 }
279
280 ui::InputMethod* NativeWidgetAura::GetHostInputMethod() {
281 aura::Window* root_window = window_->GetRootWindow(); 271 aura::Window* root_window = window_->GetRootWindow();
282 return root_window->GetHost()->GetInputMethod(); 272 return root_window ? root_window->GetHost()->GetInputMethod() : nullptr;
283 } 273 }
284 274
285 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 275 void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
286 if (!window_) 276 if (!window_)
287 return; 277 return;
288 278
289 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 279 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow());
290 // When centering window, we take the intersection of the host and 280 // When centering window, we take the intersection of the host and
291 // the parent. We assume the root window represents the visible 281 // the parent. We assume the root window represents the visible
292 // rect of a single screen. 282 // rect of a single screen.
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 GetWidget()->widget_delegate()->CanMinimize()); 709 GetWidget()->widget_delegate()->CanMinimize());
720 window_->SetProperty(aura::client::kCanResizeKey, 710 window_->SetProperty(aura::client::kCanResizeKey,
721 GetWidget()->widget_delegate()->CanResize()); 711 GetWidget()->widget_delegate()->CanResize());
722 } 712 }
723 713
724 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { 714 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) {
725 OnEvent(native_event); 715 OnEvent(native_event);
726 } 716 }
727 717
728 //////////////////////////////////////////////////////////////////////////////// 718 ////////////////////////////////////////////////////////////////////////////////
729 // NativeWidgetAura, views::InputMethodDelegate implementation:
730
731 void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
732 FocusManager* focus_manager = GetWidget()->GetFocusManager();
733 delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
734 if (key.handled() || !focus_manager)
735 return;
736 focus_manager->OnKeyEvent(key);
737 }
738
739 ////////////////////////////////////////////////////////////////////////////////
740 // NativeWidgetAura, aura::WindowDelegate implementation: 719 // NativeWidgetAura, aura::WindowDelegate implementation:
741 720
742 gfx::Size NativeWidgetAura::GetMinimumSize() const { 721 gfx::Size NativeWidgetAura::GetMinimumSize() const {
743 return delegate_->GetMinimumSize(); 722 return delegate_->GetMinimumSize();
744 } 723 }
745 724
746 gfx::Size NativeWidgetAura::GetMaximumSize() const { 725 gfx::Size NativeWidgetAura::GetMaximumSize() const {
747 // If a window have a maximum size, the window should not be 726 // If a window have a maximum size, the window should not be
748 // maximizable. 727 // maximizable.
749 DCHECK(delegate_->GetMaximumSize().IsEmpty() || 728 DCHECK(delegate_->GetMaximumSize().IsEmpty() ||
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 intptr_t old) { 842 intptr_t old) {
864 if (key == aura::client::kShowStateKey) 843 if (key == aura::client::kShowStateKey)
865 delegate_->OnNativeWidgetWindowShowStateChanged(); 844 delegate_->OnNativeWidgetWindowShowStateChanged();
866 } 845 }
867 846
868 //////////////////////////////////////////////////////////////////////////////// 847 ////////////////////////////////////////////////////////////////////////////////
869 // NativeWidgetAura, ui::EventHandler implementation: 848 // NativeWidgetAura, ui::EventHandler implementation:
870 849
871 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 850 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
872 DCHECK(window_); 851 DCHECK(window_);
873 if (event->is_char()) {
874 // If a ui::InputMethod object is attached to the root window, character
875 // events are handled inside the object and are not passed to this function.
876 // If such object is not attached, character events might be sent (e.g. on
877 // Windows). In this case, we just skip these.
878 return;
879 }
880 // Renderer may send a key event back to us if the key event wasn't handled, 852 // Renderer may send a key event back to us if the key event wasn't handled,
881 // and the window may be invisible by that time. 853 // and the window may be invisible by that time.
882 if (!window_->IsVisible()) 854 if (!window_->IsVisible())
883 return; 855 return;
884 InputMethod* input_method = GetWidget()->GetInputMethod(); 856
885 if (!input_method) 857 FocusManager* focus_manager = GetWidget()->GetFocusManager();
886 return; 858 delegate_->OnKeyEvent(event);
887 input_method->DispatchKeyEvent(*event); 859 if (!event->handled() && focus_manager)
860 focus_manager->OnKeyEvent(*event);
888 event->SetHandled(); 861 event->SetHandled();
889 } 862 }
890 863
891 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 864 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
892 DCHECK(window_); 865 DCHECK(window_);
893 DCHECK(window_->IsVisible()); 866 DCHECK(window_->IsVisible());
894 if (event->type() == ui::ET_MOUSEWHEEL) { 867 if (event->type() == ui::ET_MOUSEWHEEL) {
895 delegate_->OnMouseEvent(event); 868 delegate_->OnMouseEvent(event);
896 if (event->handled()) 869 if (event->handled())
897 return; 870 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 GetWidget()->GetFocusManager()->StoreFocusedView(true); 908 GetWidget()->GetFocusManager()->StoreFocusedView(true);
936 } 909 }
937 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 910 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active);
938 } 911 }
939 912
940 //////////////////////////////////////////////////////////////////////////////// 913 ////////////////////////////////////////////////////////////////////////////////
941 // NativeWidgetAura, aura::client::FocusChangeObserver: 914 // NativeWidgetAura, aura::client::FocusChangeObserver:
942 915
943 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 916 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
944 aura::Window* lost_focus) { 917 aura::Window* lost_focus) {
945 if (window_ == gained_focus) { 918 if (window_ == gained_focus)
946 // In aura, it is possible for child native widgets to take input and focus,
947 // this differs from the behavior on windows.
948 if (GetWidget()->GetInputMethod()) // Null in tests.
949 GetWidget()->GetInputMethod()->OnFocus();
950 delegate_->OnNativeFocus(); 919 delegate_->OnNativeFocus();
951 } else if (window_ == lost_focus) { 920 else if (window_ == lost_focus)
952 // GetInputMethod() recreates the input method if it's previously been
953 // destroyed. If we get called during destruction, the input method will be
954 // gone, and creating a new one and telling it that we lost the focus will
955 // trigger a DCHECK (the new input method doesn't think that we have the
956 // focus and doesn't expect a blur). OnBlur() shouldn't be called during
957 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the
958 // case in tests).
959 if (!destroying_) {
960 if (GetWidget()->GetInputMethod())
961 GetWidget()->GetInputMethod()->OnBlur();
962 } else {
963 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
964 }
965
966 delegate_->OnNativeBlur(); 921 delegate_->OnNativeBlur();
967 }
968 } 922 }
969 923
970 //////////////////////////////////////////////////////////////////////////////// 924 ////////////////////////////////////////////////////////////////////////////////
971 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: 925 // NativeWidgetAura, aura::WindowDragDropDelegate implementation:
972 926
973 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 927 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
974 DCHECK(drop_helper_.get() != NULL); 928 DCHECK(drop_helper_.get() != NULL);
975 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 929 last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
976 event.location(), event.source_operations()); 930 event.location(), event.source_operations());
977 } 931 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 1148 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
1195 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 1149 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
1196 return gfx::FontList(gfx::Font(caption_font)); 1150 return gfx::FontList(gfx::Font(caption_font));
1197 #else 1151 #else
1198 return gfx::FontList(); 1152 return gfx::FontList();
1199 #endif 1153 #endif
1200 } 1154 }
1201 1155
1202 } // namespace internal 1156 } // namespace internal
1203 } // namespace views 1157 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698