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/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 19 matching lines...) Expand all Loading... |
57 // Finally, make a default one. | 57 // Finally, make a default one. |
58 NativeWidget* CreateNativeWidget(NativeWidget* native_widget, | 58 NativeWidget* CreateNativeWidget(NativeWidget* native_widget, |
59 internal::NativeWidgetDelegate* delegate) { | 59 internal::NativeWidgetDelegate* delegate) { |
60 if (!native_widget) { | 60 if (!native_widget) { |
61 native_widget = | 61 native_widget = |
62 internal::NativeWidgetPrivate::CreateNativeWidget(delegate); | 62 internal::NativeWidgetPrivate::CreateNativeWidget(delegate); |
63 } | 63 } |
64 return native_widget; | 64 return native_widget; |
65 } | 65 } |
66 | 66 |
| 67 void NotifyCaretBoundsChanged(ui::InputMethod* input_method) { |
| 68 if (!input_method) |
| 69 return; |
| 70 ui::TextInputClient* client = input_method->GetTextInputClient(); |
| 71 if (client) |
| 72 input_method->OnCaretBoundsChanged(client); |
| 73 } |
| 74 |
67 } // namespace | 75 } // namespace |
68 | 76 |
69 // A default implementation of WidgetDelegate, used by Widget when no | 77 // A default implementation of WidgetDelegate, used by Widget when no |
70 // WidgetDelegate is supplied. | 78 // WidgetDelegate is supplied. |
71 class DefaultWidgetDelegate : public WidgetDelegate { | 79 class DefaultWidgetDelegate : public WidgetDelegate { |
72 public: | 80 public: |
73 explicit DefaultWidgetDelegate(Widget* widget) : widget_(widget) { | 81 explicit DefaultWidgetDelegate(Widget* widget) : widget_(widget) { |
74 } | 82 } |
75 ~DefaultWidgetDelegate() override {} | 83 ~DefaultWidgetDelegate() override {} |
76 | 84 |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 Widget* toplevel_widget = GetTopLevelWidget(); | 765 Widget* toplevel_widget = GetTopLevelWidget(); |
758 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; | 766 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; |
759 } | 767 } |
760 | 768 |
761 const FocusManager* Widget::GetFocusManager() const { | 769 const FocusManager* Widget::GetFocusManager() const { |
762 const Widget* toplevel_widget = GetTopLevelWidget(); | 770 const Widget* toplevel_widget = GetTopLevelWidget(); |
763 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; | 771 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; |
764 } | 772 } |
765 | 773 |
766 ui::TextInputClient* Widget::GetFocusedTextInputClient() { | 774 ui::TextInputClient* Widget::GetFocusedTextInputClient() { |
767 FocusManager* focus_manager = GetFocusManager(); | 775 return nullptr; |
768 View* view = focus_manager ? focus_manager->GetFocusedView() : nullptr; | |
769 return view ? view->GetTextInputClient() : nullptr; | |
770 } | 776 } |
771 | 777 |
772 InputMethod* Widget::GetInputMethod() { | 778 ui::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()) { | 779 if (is_top_level()) { |
779 if (!input_method_.get()) | 780 // Only creates the shared the input method instance on top level widget. |
780 input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass(); | 781 return native_widget_private()->GetInputMethod(); |
781 return input_method_.get(); | |
782 } else { | 782 } else { |
783 const Widget* toplevel = GetTopLevelWidget(); | 783 Widget* toplevel = GetTopLevelWidget(); |
784 // If GetTopLevelWidget() returns itself which is not toplevel, | 784 // If GetTopLevelWidget() returns itself which is not toplevel, |
785 // the widget is detached from toplevel widget. | 785 // the widget is detached from toplevel widget. |
786 // TODO(oshima): Fix GetTopLevelWidget() to return NULL | 786 // TODO(oshima): Fix GetTopLevelWidget() to return NULL |
787 // if there is no toplevel. We probably need to add GetTopMostWidget() | 787 // if there is no toplevel. We probably need to add GetTopMostWidget() |
788 // to replace some use cases. | 788 // to replace some use cases. |
789 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL; | 789 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() |
| 790 : nullptr; |
790 } | 791 } |
791 } | 792 } |
792 | 793 |
793 ui::InputMethod* Widget::GetHostInputMethod() { | |
794 return native_widget_private()->GetHostInputMethod(); | |
795 } | |
796 | |
797 void Widget::RunShellDrag(View* view, | 794 void Widget::RunShellDrag(View* view, |
798 const ui::OSExchangeData& data, | 795 const ui::OSExchangeData& data, |
799 const gfx::Point& location, | 796 const gfx::Point& location, |
800 int operation, | 797 int operation, |
801 ui::DragDropTypes::DragEventSource source) { | 798 ui::DragDropTypes::DragEventSource source) { |
802 dragged_view_ = view; | 799 dragged_view_ = view; |
803 OnDragWillStart(); | 800 OnDragWillStart(); |
804 | 801 |
805 WidgetDeletionObserver widget_deletion_observer(this); | 802 WidgetDeletionObserver widget_deletion_observer(this); |
806 native_widget_->RunShellDrag(view, data, location, operation, source); | 803 native_widget_->RunShellDrag(view, data, location, operation, source); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 gfx::Size Widget::GetMinimumSize() const { | 1105 gfx::Size Widget::GetMinimumSize() const { |
1109 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); | 1106 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); |
1110 } | 1107 } |
1111 | 1108 |
1112 gfx::Size Widget::GetMaximumSize() const { | 1109 gfx::Size Widget::GetMaximumSize() const { |
1113 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); | 1110 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); |
1114 } | 1111 } |
1115 | 1112 |
1116 void Widget::OnNativeWidgetMove() { | 1113 void Widget::OnNativeWidgetMove() { |
1117 widget_delegate_->OnWidgetMove(); | 1114 widget_delegate_->OnWidgetMove(); |
1118 View* root = GetRootView(); | 1115 NotifyCaretBoundsChanged(GetInputMethod()); |
1119 if (root && root->GetFocusManager()) { | 1116 |
1120 View* focused_view = root->GetFocusManager()->GetFocusedView(); | |
1121 if (focused_view && focused_view->GetInputMethod()) | |
1122 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); | |
1123 } | |
1124 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1117 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( |
1125 this, | 1118 this, |
1126 GetWindowBoundsInScreen())); | 1119 GetWindowBoundsInScreen())); |
1127 } | 1120 } |
1128 | 1121 |
1129 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { | 1122 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { |
1130 View* root = GetRootView(); | 1123 View* root = GetRootView(); |
1131 if (root) { | 1124 if (root) |
1132 root->SetSize(new_size); | 1125 root->SetSize(new_size); |
1133 if (root->GetFocusManager()) { | 1126 |
1134 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView(); | 1127 NotifyCaretBoundsChanged(GetInputMethod()); |
1135 if (focused_view && focused_view->GetInputMethod()) | |
1136 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); | |
1137 } | |
1138 } | |
1139 SaveWindowPlacementIfInitialized(); | 1128 SaveWindowPlacementIfInitialized(); |
1140 | 1129 |
1141 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1130 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( |
1142 this, | 1131 this, |
1143 GetWindowBoundsInScreen())); | 1132 GetWindowBoundsInScreen())); |
1144 } | 1133 } |
1145 | 1134 |
1146 void Widget::OnNativeWidgetWindowShowStateChanged() { | 1135 void Widget::OnNativeWidgetWindowShowStateChanged() { |
1147 SaveWindowPlacementIfInitialized(); | 1136 SaveWindowPlacementIfInitialized(); |
1148 } | 1137 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 // We explicitly do not capture here. Not capturing enables multiple widgets | 1276 // 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 | 1277 // to get tap events at the same time. Views (such as tab dragging) may |
1289 // explicitly capture. | 1278 // explicitly capture. |
1290 SendEventToProcessor(event); | 1279 SendEventToProcessor(event); |
1291 } | 1280 } |
1292 | 1281 |
1293 bool Widget::ExecuteCommand(int command_id) { | 1282 bool Widget::ExecuteCommand(int command_id) { |
1294 return widget_delegate_->ExecuteWindowsCommand(command_id); | 1283 return widget_delegate_->ExecuteWindowsCommand(command_id); |
1295 } | 1284 } |
1296 | 1285 |
1297 InputMethod* Widget::GetInputMethodDirect() { | |
1298 return input_method_.get(); | |
1299 } | |
1300 | |
1301 const std::vector<ui::Layer*>& Widget::GetRootLayers() { | 1286 const std::vector<ui::Layer*>& Widget::GetRootLayers() { |
1302 if (root_layers_dirty_) { | 1287 if (root_layers_dirty_) { |
1303 root_layers_dirty_ = false; | 1288 root_layers_dirty_ = false; |
1304 root_layers_.clear(); | 1289 root_layers_.clear(); |
1305 BuildRootLayers(GetRootView(), &root_layers_); | 1290 BuildRootLayers(GetRootView(), &root_layers_); |
1306 } | 1291 } |
1307 return root_layers_; | 1292 return root_layers_; |
1308 } | 1293 } |
1309 | 1294 |
1310 bool Widget::HasHitTestMask() const { | 1295 bool Widget::HasHitTestMask() const { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 //////////////////////////////////////////////////////////////////////////////// | 1369 //////////////////////////////////////////////////////////////////////////////// |
1385 // Widget, protected: | 1370 // Widget, protected: |
1386 | 1371 |
1387 internal::RootView* Widget::CreateRootView() { | 1372 internal::RootView* Widget::CreateRootView() { |
1388 return new internal::RootView(this); | 1373 return new internal::RootView(this); |
1389 } | 1374 } |
1390 | 1375 |
1391 void Widget::DestroyRootView() { | 1376 void Widget::DestroyRootView() { |
1392 non_client_view_ = NULL; | 1377 non_client_view_ = NULL; |
1393 root_view_.reset(); | 1378 root_view_.reset(); |
1394 // Input method has to be destroyed before focus manager. | |
1395 input_method_.reset(); | |
1396 } | 1379 } |
1397 | 1380 |
1398 void Widget::OnDragWillStart() { | 1381 void Widget::OnDragWillStart() { |
1399 } | 1382 } |
1400 | 1383 |
1401 void Widget::OnDragComplete() { | 1384 void Widget::OnDragComplete() { |
1402 } | 1385 } |
1403 | 1386 |
1404 //////////////////////////////////////////////////////////////////////////////// | 1387 //////////////////////////////////////////////////////////////////////////////// |
1405 // Widget, private: | 1388 // Widget, private: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 bounds->set_width(minimum_size.width()); | 1476 bounds->set_width(minimum_size.width()); |
1494 | 1477 |
1495 if (bounds->height() < minimum_size.height()) | 1478 if (bounds->height() < minimum_size.height()) |
1496 bounds->set_height(minimum_size.height()); | 1479 bounds->set_height(minimum_size.height()); |
1497 } | 1480 } |
1498 return true; | 1481 return true; |
1499 } | 1482 } |
1500 return false; | 1483 return false; |
1501 } | 1484 } |
1502 | 1485 |
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 { | 1486 namespace internal { |
1517 | 1487 |
1518 //////////////////////////////////////////////////////////////////////////////// | 1488 //////////////////////////////////////////////////////////////////////////////// |
1519 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1489 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1520 | 1490 |
1521 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1491 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1522 return this; | 1492 return this; |
1523 } | 1493 } |
1524 | 1494 |
1525 } // namespace internal | 1495 } // namespace internal |
1526 } // namespace views | 1496 } // namespace views |
OLD | NEW |