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

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

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/widget.h" 5 #include "ui/views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "ui/base/cursor/cursor.h" 11 #include "ui/base/cursor/cursor.h"
12 #include "ui/base/default_theme_provider.h" 12 #include "ui/base/default_theme_provider.h"
13 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
14 #include "ui/base/ime/input_method.h"
14 #include "ui/base/l10n/l10n_font_util.h" 15 #include "ui/base/l10n/l10n_font_util.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/compositor/compositor.h" 17 #include "ui/compositor/compositor.h"
17 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
18 #include "ui/events/event.h" 19 #include "ui/events/event.h"
19 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
20 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
21 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
22 #include "ui/views/controls/menu/menu_controller.h" 23 #include "ui/views/controls/menu/menu_controller.h"
23 #include "ui/views/focus/focus_manager.h" 24 #include "ui/views/focus/focus_manager.h"
24 #include "ui/views/focus/focus_manager_factory.h" 25 #include "ui/views/focus/focus_manager_factory.h"
25 #include "ui/views/focus/view_storage.h" 26 #include "ui/views/focus/view_storage.h"
26 #include "ui/views/focus/widget_focus_manager.h" 27 #include "ui/views/focus/widget_focus_manager.h"
27 #include "ui/views/ime/input_method.h"
28 #include "ui/views/views_delegate.h" 28 #include "ui/views/views_delegate.h"
29 #include "ui/views/widget/native_widget_private.h" 29 #include "ui/views/widget/native_widget_private.h"
30 #include "ui/views/widget/root_view.h" 30 #include "ui/views/widget/root_view.h"
31 #include "ui/views/widget/tooltip_manager.h" 31 #include "ui/views/widget/tooltip_manager.h"
32 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
33 #include "ui/views/widget/widget_deletion_observer.h" 33 #include "ui/views/widget/widget_deletion_observer.h"
34 #include "ui/views/widget/widget_observer.h" 34 #include "ui/views/widget/widget_observer.h"
35 #include "ui/views/widget/widget_removals_observer.h" 35 #include "ui/views/widget/widget_removals_observer.h"
36 #include "ui/views/window/custom_frame_view.h" 36 #include "ui/views/window/custom_frame_view.h"
37 #include "ui/views/window/dialog_delegate.h" 37 #include "ui/views/window/dialog_delegate.h"
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 FocusManager* Widget::GetFocusManager() { 756 FocusManager* Widget::GetFocusManager() {
757 Widget* toplevel_widget = GetTopLevelWidget(); 757 Widget* toplevel_widget = GetTopLevelWidget();
758 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; 758 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
759 } 759 }
760 760
761 const FocusManager* Widget::GetFocusManager() const { 761 const FocusManager* Widget::GetFocusManager() const {
762 const Widget* toplevel_widget = GetTopLevelWidget(); 762 const Widget* toplevel_widget = GetTopLevelWidget();
763 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; 763 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
764 } 764 }
765 765
766 ui::TextInputClient* Widget::GetFocusedTextInputClient() { 766 ui::InputMethod* Widget::GetInputMethod() {
767 FocusManager* focus_manager = GetFocusManager();
768 View* view = focus_manager ? focus_manager->GetFocusedView() : nullptr;
769 return view ? view->GetTextInputClient() : nullptr;
770 }
771
772 InputMethod* Widget::GetInputMethod() {
773 return const_cast<InputMethod*>(
774 const_cast<const Widget*>(this)->GetInputMethod());
775 }
776
777 const InputMethod* Widget::GetInputMethod() const {
778 if (is_top_level()) { 767 if (is_top_level()) {
779 if (!input_method_.get()) 768 // Only creates the shared the input method instance on top level widget.
780 input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass(); 769 return native_widget_private()->GetInputMethod();
781 return input_method_.get();
782 } else { 770 } else {
783 const Widget* toplevel = GetTopLevelWidget(); 771 Widget* toplevel = GetTopLevelWidget();
784 // If GetTopLevelWidget() returns itself which is not toplevel, 772 // If GetTopLevelWidget() returns itself which is not toplevel,
785 // the widget is detached from toplevel widget. 773 // the widget is detached from toplevel widget.
786 // TODO(oshima): Fix GetTopLevelWidget() to return NULL 774 // TODO(oshima): Fix GetTopLevelWidget() to return NULL
787 // if there is no toplevel. We probably need to add GetTopMostWidget() 775 // if there is no toplevel. We probably need to add GetTopMostWidget()
788 // to replace some use cases. 776 // to replace some use cases.
789 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL; 777 return (toplevel && toplevel != this) ? toplevel->GetInputMethod()
778 : nullptr;
790 } 779 }
791 } 780 }
792 781
793 ui::InputMethod* Widget::GetHostInputMethod() {
794 return native_widget_private()->GetHostInputMethod();
795 }
796
797 void Widget::RunShellDrag(View* view, 782 void Widget::RunShellDrag(View* view,
798 const ui::OSExchangeData& data, 783 const ui::OSExchangeData& data,
799 const gfx::Point& location, 784 const gfx::Point& location,
800 int operation, 785 int operation,
801 ui::DragDropTypes::DragEventSource source) { 786 ui::DragDropTypes::DragEventSource source) {
802 dragged_view_ = view; 787 dragged_view_ = view;
803 OnDragWillStart(); 788 OnDragWillStart();
804 789
805 WidgetDeletionObserver widget_deletion_observer(this); 790 WidgetDeletionObserver widget_deletion_observer(this);
806 native_widget_->RunShellDrag(view, data, location, operation, source); 791 native_widget_->RunShellDrag(view, data, location, operation, source);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 gfx::Size Widget::GetMinimumSize() const { 1093 gfx::Size Widget::GetMinimumSize() const {
1109 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); 1094 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
1110 } 1095 }
1111 1096
1112 gfx::Size Widget::GetMaximumSize() const { 1097 gfx::Size Widget::GetMaximumSize() const {
1113 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); 1098 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
1114 } 1099 }
1115 1100
1116 void Widget::OnNativeWidgetMove() { 1101 void Widget::OnNativeWidgetMove() {
1117 widget_delegate_->OnWidgetMove(); 1102 widget_delegate_->OnWidgetMove();
1118 View* root = GetRootView(); 1103 ui::InputMethod* input_method = GetInputMethod();
1119 if (root && root->GetFocusManager()) { 1104 if (input_method) {
1120 View* focused_view = root->GetFocusManager()->GetFocusedView(); 1105 ui::TextInputClient* client = input_method->GetTextInputClient();
1121 if (focused_view && focused_view->GetInputMethod()) 1106 if (client)
1122 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); 1107 input_method->OnCaretBoundsChanged(client);
1123 } 1108 }
1109
1124 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( 1110 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1125 this, 1111 this,
1126 GetWindowBoundsInScreen())); 1112 GetWindowBoundsInScreen()));
1127 } 1113 }
1128 1114
1129 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { 1115 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
1130 View* root = GetRootView(); 1116 View* root = GetRootView();
1131 if (root) { 1117 if (root)
1132 root->SetSize(new_size); 1118 root->SetSize(new_size);
1133 if (root->GetFocusManager()) { 1119 ui::InputMethod* input_method = GetInputMethod();
1134 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView(); 1120 if (input_method) {
1135 if (focused_view && focused_view->GetInputMethod()) 1121 ui::TextInputClient* client = input_method->GetTextInputClient();
1136 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); 1122 if (client)
1137 } 1123 input_method->OnCaretBoundsChanged(client);
1138 } 1124 }
1139 SaveWindowPlacementIfInitialized(); 1125 SaveWindowPlacementIfInitialized();
1140 1126
1141 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( 1127 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1142 this, 1128 this,
1143 GetWindowBoundsInScreen())); 1129 GetWindowBoundsInScreen()));
1144 } 1130 }
1145 1131
1146 void Widget::OnNativeWidgetWindowShowStateChanged() { 1132 void Widget::OnNativeWidgetWindowShowStateChanged() {
1147 SaveWindowPlacementIfInitialized(); 1133 SaveWindowPlacementIfInitialized();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 // We explicitly do not capture here. Not capturing enables multiple widgets 1273 // We explicitly do not capture here. Not capturing enables multiple widgets
1288 // to get tap events at the same time. Views (such as tab dragging) may 1274 // to get tap events at the same time. Views (such as tab dragging) may
1289 // explicitly capture. 1275 // explicitly capture.
1290 SendEventToProcessor(event); 1276 SendEventToProcessor(event);
1291 } 1277 }
1292 1278
1293 bool Widget::ExecuteCommand(int command_id) { 1279 bool Widget::ExecuteCommand(int command_id) {
1294 return widget_delegate_->ExecuteWindowsCommand(command_id); 1280 return widget_delegate_->ExecuteWindowsCommand(command_id);
1295 } 1281 }
1296 1282
1297 InputMethod* Widget::GetInputMethodDirect() {
1298 return input_method_.get();
1299 }
1300
1301 const std::vector<ui::Layer*>& Widget::GetRootLayers() { 1283 const std::vector<ui::Layer*>& Widget::GetRootLayers() {
1302 if (root_layers_dirty_) { 1284 if (root_layers_dirty_) {
1303 root_layers_dirty_ = false; 1285 root_layers_dirty_ = false;
1304 root_layers_.clear(); 1286 root_layers_.clear();
1305 BuildRootLayers(GetRootView(), &root_layers_); 1287 BuildRootLayers(GetRootView(), &root_layers_);
1306 } 1288 }
1307 return root_layers_; 1289 return root_layers_;
1308 } 1290 }
1309 1291
1310 bool Widget::HasHitTestMask() const { 1292 bool Widget::HasHitTestMask() const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 //////////////////////////////////////////////////////////////////////////////// 1366 ////////////////////////////////////////////////////////////////////////////////
1385 // Widget, protected: 1367 // Widget, protected:
1386 1368
1387 internal::RootView* Widget::CreateRootView() { 1369 internal::RootView* Widget::CreateRootView() {
1388 return new internal::RootView(this); 1370 return new internal::RootView(this);
1389 } 1371 }
1390 1372
1391 void Widget::DestroyRootView() { 1373 void Widget::DestroyRootView() {
1392 non_client_view_ = NULL; 1374 non_client_view_ = NULL;
1393 root_view_.reset(); 1375 root_view_.reset();
1394 // Input method has to be destroyed before focus manager.
1395 input_method_.reset();
1396 } 1376 }
1397 1377
1398 void Widget::OnDragWillStart() { 1378 void Widget::OnDragWillStart() {
1399 } 1379 }
1400 1380
1401 void Widget::OnDragComplete() { 1381 void Widget::OnDragComplete() {
1402 } 1382 }
1403 1383
1404 //////////////////////////////////////////////////////////////////////////////// 1384 ////////////////////////////////////////////////////////////////////////////////
1405 // Widget, private: 1385 // Widget, private:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 bounds->set_width(minimum_size.width()); 1473 bounds->set_width(minimum_size.width());
1494 1474
1495 if (bounds->height() < minimum_size.height()) 1475 if (bounds->height() < minimum_size.height())
1496 bounds->set_height(minimum_size.height()); 1476 bounds->set_height(minimum_size.height());
1497 } 1477 }
1498 return true; 1478 return true;
1499 } 1479 }
1500 return false; 1480 return false;
1501 } 1481 }
1502 1482
1503 scoped_ptr<InputMethod> Widget::CreateInputMethod() {
1504 scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
1505 if (input_method.get())
1506 input_method->Init(this);
1507 return input_method.Pass();
1508 }
1509
1510 void Widget::ReplaceInputMethod(InputMethod* input_method) {
1511 input_method_.reset(input_method);
1512 input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
1513 input_method->Init(this);
1514 }
1515
1516 namespace internal { 1483 namespace internal {
1517 1484
1518 //////////////////////////////////////////////////////////////////////////////// 1485 ////////////////////////////////////////////////////////////////////////////////
1519 // internal::NativeWidgetPrivate, NativeWidget implementation: 1486 // internal::NativeWidgetPrivate, NativeWidget implementation:
1520 1487
1521 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1488 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1522 return this; 1489 return this;
1523 } 1490 }
1524 1491
1525 } // namespace internal 1492 } // namespace internal
1526 } // namespace views 1493 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698