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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::TextInputClient* Widget::GetFocusedTextInputClient() { |
767 FocusManager* focus_manager = GetFocusManager(); | 767 FocusManager* focus_manager = GetFocusManager(); |
768 View* view = focus_manager ? focus_manager->GetFocusedView() : nullptr; | 768 View* view = focus_manager ? focus_manager->GetFocusedView() : nullptr; |
769 return view ? view->GetTextInputClient() : nullptr; | 769 return view ? view->GetTextInputClient() : nullptr; |
770 } | 770 } |
771 | 771 |
772 InputMethod* Widget::GetInputMethod() { | 772 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()) { | 773 if (is_top_level()) { |
779 if (!input_method_.get()) | 774 // Only creates the shared the input method instance on top level widget. |
780 input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass(); | 775 return native_widget_private()->GetInputMethod(); |
781 return input_method_.get(); | |
782 } else { | 776 } else { |
783 const Widget* toplevel = GetTopLevelWidget(); | 777 Widget* toplevel = GetTopLevelWidget(); |
784 // If GetTopLevelWidget() returns itself which is not toplevel, | 778 // If GetTopLevelWidget() returns itself which is not toplevel, |
785 // the widget is detached from toplevel widget. | 779 // the widget is detached from toplevel widget. |
786 // TODO(oshima): Fix GetTopLevelWidget() to return NULL | 780 // TODO(oshima): Fix GetTopLevelWidget() to return NULL |
787 // if there is no toplevel. We probably need to add GetTopMostWidget() | 781 // if there is no toplevel. We probably need to add GetTopMostWidget() |
788 // to replace some use cases. | 782 // to replace some use cases. |
789 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL; | 783 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() |
| 784 : nullptr; |
790 } | 785 } |
791 } | 786 } |
792 | 787 |
793 ui::InputMethod* Widget::GetHostInputMethod() { | |
794 return native_widget_private()->GetHostInputMethod(); | |
795 } | |
796 | |
797 void Widget::RunShellDrag(View* view, | 788 void Widget::RunShellDrag(View* view, |
798 const ui::OSExchangeData& data, | 789 const ui::OSExchangeData& data, |
799 const gfx::Point& location, | 790 const gfx::Point& location, |
800 int operation, | 791 int operation, |
801 ui::DragDropTypes::DragEventSource source) { | 792 ui::DragDropTypes::DragEventSource source) { |
802 dragged_view_ = view; | 793 dragged_view_ = view; |
803 OnDragWillStart(); | 794 OnDragWillStart(); |
804 | 795 |
805 WidgetDeletionObserver widget_deletion_observer(this); | 796 WidgetDeletionObserver widget_deletion_observer(this); |
806 native_widget_->RunShellDrag(view, data, location, operation, source); | 797 native_widget_->RunShellDrag(view, data, location, operation, source); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 gfx::Size Widget::GetMinimumSize() const { | 1112 gfx::Size Widget::GetMinimumSize() const { |
1122 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); | 1113 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); |
1123 } | 1114 } |
1124 | 1115 |
1125 gfx::Size Widget::GetMaximumSize() const { | 1116 gfx::Size Widget::GetMaximumSize() const { |
1126 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); | 1117 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); |
1127 } | 1118 } |
1128 | 1119 |
1129 void Widget::OnNativeWidgetMove() { | 1120 void Widget::OnNativeWidgetMove() { |
1130 widget_delegate_->OnWidgetMove(); | 1121 widget_delegate_->OnWidgetMove(); |
1131 View* root = GetRootView(); | 1122 ui::InputMethod* input_method = GetInputMethod(); |
1132 if (root && root->GetFocusManager()) { | 1123 if (input_method) { |
1133 View* focused_view = root->GetFocusManager()->GetFocusedView(); | 1124 ui::TextInputClient* client = input_method->GetTextInputClient(); |
1134 if (focused_view && focused_view->GetInputMethod()) | 1125 if (client) |
1135 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); | 1126 input_method->OnCaretBoundsChanged(client); |
1136 } | 1127 } |
| 1128 |
1137 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1129 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( |
1138 this, | 1130 this, |
1139 GetWindowBoundsInScreen())); | 1131 GetWindowBoundsInScreen())); |
1140 } | 1132 } |
1141 | 1133 |
1142 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { | 1134 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { |
1143 View* root = GetRootView(); | 1135 View* root = GetRootView(); |
1144 if (root) { | 1136 if (root) |
1145 root->SetSize(new_size); | 1137 root->SetSize(new_size); |
1146 if (root->GetFocusManager()) { | 1138 ui::InputMethod* input_method = GetInputMethod(); |
1147 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView(); | 1139 if (input_method) { |
1148 if (focused_view && focused_view->GetInputMethod()) | 1140 ui::TextInputClient* client = input_method->GetTextInputClient(); |
1149 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view); | 1141 if (client) |
1150 } | 1142 input_method->OnCaretBoundsChanged(client); |
1151 } | 1143 } |
1152 SaveWindowPlacementIfInitialized(); | 1144 SaveWindowPlacementIfInitialized(); |
1153 | 1145 |
1154 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1146 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( |
1155 this, | 1147 this, |
1156 GetWindowBoundsInScreen())); | 1148 GetWindowBoundsInScreen())); |
1157 } | 1149 } |
1158 | 1150 |
1159 void Widget::OnNativeWidgetWindowShowStateChanged() { | 1151 void Widget::OnNativeWidgetWindowShowStateChanged() { |
1160 SaveWindowPlacementIfInitialized(); | 1152 SaveWindowPlacementIfInitialized(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 // We explicitly do not capture here. Not capturing enables multiple widgets | 1292 // We explicitly do not capture here. Not capturing enables multiple widgets |
1301 // to get tap events at the same time. Views (such as tab dragging) may | 1293 // to get tap events at the same time. Views (such as tab dragging) may |
1302 // explicitly capture. | 1294 // explicitly capture. |
1303 SendEventToProcessor(event); | 1295 SendEventToProcessor(event); |
1304 } | 1296 } |
1305 | 1297 |
1306 bool Widget::ExecuteCommand(int command_id) { | 1298 bool Widget::ExecuteCommand(int command_id) { |
1307 return widget_delegate_->ExecuteWindowsCommand(command_id); | 1299 return widget_delegate_->ExecuteWindowsCommand(command_id); |
1308 } | 1300 } |
1309 | 1301 |
1310 InputMethod* Widget::GetInputMethodDirect() { | |
1311 return input_method_.get(); | |
1312 } | |
1313 | |
1314 const std::vector<ui::Layer*>& Widget::GetRootLayers() { | 1302 const std::vector<ui::Layer*>& Widget::GetRootLayers() { |
1315 if (root_layers_dirty_) { | 1303 if (root_layers_dirty_) { |
1316 root_layers_dirty_ = false; | 1304 root_layers_dirty_ = false; |
1317 root_layers_.clear(); | 1305 root_layers_.clear(); |
1318 BuildRootLayers(GetRootView(), &root_layers_); | 1306 BuildRootLayers(GetRootView(), &root_layers_); |
1319 } | 1307 } |
1320 return root_layers_; | 1308 return root_layers_; |
1321 } | 1309 } |
1322 | 1310 |
1323 bool Widget::HasHitTestMask() const { | 1311 bool Widget::HasHitTestMask() const { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 //////////////////////////////////////////////////////////////////////////////// | 1385 //////////////////////////////////////////////////////////////////////////////// |
1398 // Widget, protected: | 1386 // Widget, protected: |
1399 | 1387 |
1400 internal::RootView* Widget::CreateRootView() { | 1388 internal::RootView* Widget::CreateRootView() { |
1401 return new internal::RootView(this); | 1389 return new internal::RootView(this); |
1402 } | 1390 } |
1403 | 1391 |
1404 void Widget::DestroyRootView() { | 1392 void Widget::DestroyRootView() { |
1405 non_client_view_ = NULL; | 1393 non_client_view_ = NULL; |
1406 root_view_.reset(); | 1394 root_view_.reset(); |
1407 // Input method has to be destroyed before focus manager. | |
1408 input_method_.reset(); | |
1409 } | 1395 } |
1410 | 1396 |
1411 void Widget::OnDragWillStart() { | 1397 void Widget::OnDragWillStart() { |
1412 } | 1398 } |
1413 | 1399 |
1414 void Widget::OnDragComplete() { | 1400 void Widget::OnDragComplete() { |
1415 } | 1401 } |
1416 | 1402 |
1417 //////////////////////////////////////////////////////////////////////////////// | 1403 //////////////////////////////////////////////////////////////////////////////// |
1418 // Widget, private: | 1404 // Widget, private: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 bounds->set_width(minimum_size.width()); | 1492 bounds->set_width(minimum_size.width()); |
1507 | 1493 |
1508 if (bounds->height() < minimum_size.height()) | 1494 if (bounds->height() < minimum_size.height()) |
1509 bounds->set_height(minimum_size.height()); | 1495 bounds->set_height(minimum_size.height()); |
1510 } | 1496 } |
1511 return true; | 1497 return true; |
1512 } | 1498 } |
1513 return false; | 1499 return false; |
1514 } | 1500 } |
1515 | 1501 |
1516 scoped_ptr<InputMethod> Widget::CreateInputMethod() { | |
1517 scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod()); | |
1518 if (input_method.get()) | |
1519 input_method->Init(this); | |
1520 return input_method.Pass(); | |
1521 } | |
1522 | |
1523 void Widget::ReplaceInputMethod(InputMethod* input_method) { | |
1524 input_method_.reset(input_method); | |
1525 input_method->SetDelegate(native_widget_->GetInputMethodDelegate()); | |
1526 input_method->Init(this); | |
1527 } | |
1528 | |
1529 namespace internal { | 1502 namespace internal { |
1530 | 1503 |
1531 //////////////////////////////////////////////////////////////////////////////// | 1504 //////////////////////////////////////////////////////////////////////////////// |
1532 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1505 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1533 | 1506 |
1534 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1507 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1535 return this; | 1508 return this; |
1536 } | 1509 } |
1537 | 1510 |
1538 } // namespace internal | 1511 } // namespace internal |
1539 } // namespace views | 1512 } // namespace views |
OLD | NEW |