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