| 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/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // the root_view_ being removed. | 428 // the root_view_ being removed. |
| 429 if (focus_manager) | 429 if (focus_manager) |
| 430 focus_manager->ViewRemoved(root_view_.get()); | 430 focus_manager->ViewRemoved(root_view_.get()); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void Widget::NotifyNativeViewHierarchyChanged() { | 433 void Widget::NotifyNativeViewHierarchyChanged() { |
| 434 root_view_->NotifyNativeViewHierarchyChanged(); | 434 root_view_->NotifyNativeViewHierarchyChanged(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void Widget::NotifyWillRemoveView(View* view) { | 437 void Widget::NotifyWillRemoveView(View* view) { |
| 438 FOR_EACH_OBSERVER(WidgetRemovalsObserver, | 438 for (auto& observer : removals_observers_) |
| 439 removals_observers_, | 439 observer.OnWillRemoveView(this, view); |
| 440 OnWillRemoveView(this, view)); | |
| 441 } | 440 } |
| 442 | 441 |
| 443 // Converted methods (see header) ---------------------------------------------- | 442 // Converted methods (see header) ---------------------------------------------- |
| 444 | 443 |
| 445 Widget* Widget::GetTopLevelWidget() { | 444 Widget* Widget::GetTopLevelWidget() { |
| 446 return const_cast<Widget*>( | 445 return const_cast<Widget*>( |
| 447 static_cast<const Widget*>(this)->GetTopLevelWidget()); | 446 static_cast<const Widget*>(this)->GetTopLevelWidget()); |
| 448 } | 447 } |
| 449 | 448 |
| 450 const Widget* Widget::GetTopLevelWidget() const { | 449 const Widget* Widget::GetTopLevelWidget() const { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 SaveWindowPlacement(); | 571 SaveWindowPlacement(); |
| 573 | 572 |
| 574 // During tear-down the top-level focus manager becomes unavailable to | 573 // During tear-down the top-level focus manager becomes unavailable to |
| 575 // GTK tabbed panes and their children, so normal deregistration via | 574 // GTK tabbed panes and their children, so normal deregistration via |
| 576 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here | 575 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here |
| 577 // to avoid these redundant steps and to avoid accessing deleted views | 576 // to avoid these redundant steps and to avoid accessing deleted views |
| 578 // that may have been in focus. | 577 // that may have been in focus. |
| 579 if (is_top_level() && focus_manager_.get()) | 578 if (is_top_level() && focus_manager_.get()) |
| 580 focus_manager_->SetFocusedView(NULL); | 579 focus_manager_->SetFocusedView(NULL); |
| 581 | 580 |
| 582 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this)); | 581 for (auto& observer : observers_) |
| 582 observer.OnWidgetClosing(this); |
| 583 native_widget_->Close(); | 583 native_widget_->Close(); |
| 584 widget_closed_ = true; | 584 widget_closed_ = true; |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 | 587 |
| 588 void Widget::CloseNow() { | 588 void Widget::CloseNow() { |
| 589 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this)); | 589 for (auto& observer : observers_) |
| 590 observer.OnWidgetClosing(this); |
| 590 native_widget_->CloseNow(); | 591 native_widget_->CloseNow(); |
| 591 } | 592 } |
| 592 | 593 |
| 593 bool Widget::IsClosed() const { | 594 bool Widget::IsClosed() const { |
| 594 return widget_closed_; | 595 return widget_closed_; |
| 595 } | 596 } |
| 596 | 597 |
| 597 void Widget::Show() { | 598 void Widget::Show() { |
| 598 const ui::Layer* layer = GetLayer(); | 599 const ui::Layer* layer = GetLayer(); |
| 599 TRACE_EVENT1("views", "Widget::Show", "layer", | 600 TRACE_EVENT1("views", "Widget::Show", "layer", |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 return always_render_as_active_; | 1020 return always_render_as_active_; |
| 1020 } | 1021 } |
| 1021 | 1022 |
| 1022 void Widget::OnNativeWidgetActivationChanged(bool active) { | 1023 void Widget::OnNativeWidgetActivationChanged(bool active) { |
| 1023 // On windows we may end up here before we've completed initialization (from | 1024 // On windows we may end up here before we've completed initialization (from |
| 1024 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know | 1025 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know |
| 1025 // the Widget and will crash attempting to access it. | 1026 // the Widget and will crash attempting to access it. |
| 1026 if (!active && native_widget_initialized_) | 1027 if (!active && native_widget_initialized_) |
| 1027 SaveWindowPlacement(); | 1028 SaveWindowPlacement(); |
| 1028 | 1029 |
| 1029 FOR_EACH_OBSERVER(WidgetObserver, observers_, | 1030 for (auto& observer : observers_) |
| 1030 OnWidgetActivationChanged(this, active)); | 1031 observer.OnWidgetActivationChanged(this, active); |
| 1031 | 1032 |
| 1032 if (non_client_view()) | 1033 if (non_client_view()) |
| 1033 non_client_view()->frame_view()->ActivationChanged(active); | 1034 non_client_view()->frame_view()->ActivationChanged(active); |
| 1034 } | 1035 } |
| 1035 | 1036 |
| 1036 void Widget::OnNativeFocus() { | 1037 void Widget::OnNativeFocus() { |
| 1037 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(GetNativeView()); | 1038 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(GetNativeView()); |
| 1038 } | 1039 } |
| 1039 | 1040 |
| 1040 void Widget::OnNativeBlur() { | 1041 void Widget::OnNativeBlur() { |
| 1041 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(nullptr); | 1042 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(nullptr); |
| 1042 } | 1043 } |
| 1043 | 1044 |
| 1044 void Widget::OnNativeWidgetVisibilityChanging(bool visible) { | 1045 void Widget::OnNativeWidgetVisibilityChanging(bool visible) { |
| 1045 FOR_EACH_OBSERVER(WidgetObserver, observers_, | 1046 for (auto& observer : observers_) |
| 1046 OnWidgetVisibilityChanging(this, visible)); | 1047 observer.OnWidgetVisibilityChanging(this, visible); |
| 1047 } | 1048 } |
| 1048 | 1049 |
| 1049 void Widget::OnNativeWidgetVisibilityChanged(bool visible) { | 1050 void Widget::OnNativeWidgetVisibilityChanged(bool visible) { |
| 1050 View* root = GetRootView(); | 1051 View* root = GetRootView(); |
| 1051 if (root) | 1052 if (root) |
| 1052 root->PropagateVisibilityNotifications(root, visible); | 1053 root->PropagateVisibilityNotifications(root, visible); |
| 1053 FOR_EACH_OBSERVER(WidgetObserver, observers_, | 1054 for (auto& observer : observers_) |
| 1054 OnWidgetVisibilityChanged(this, visible)); | 1055 observer.OnWidgetVisibilityChanged(this, visible); |
| 1055 if (GetCompositor() && root && root->layer()) | 1056 if (GetCompositor() && root && root->layer()) |
| 1056 root->layer()->SetVisible(visible); | 1057 root->layer()->SetVisible(visible); |
| 1057 } | 1058 } |
| 1058 | 1059 |
| 1059 void Widget::OnNativeWidgetCreated(bool desktop_widget) { | 1060 void Widget::OnNativeWidgetCreated(bool desktop_widget) { |
| 1060 if (is_top_level()) | 1061 if (is_top_level()) |
| 1061 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget)); | 1062 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget)); |
| 1062 | 1063 |
| 1063 native_widget_->InitModalType(widget_delegate_->GetModalType()); | 1064 native_widget_->InitModalType(widget_delegate_->GetModalType()); |
| 1064 | 1065 |
| 1065 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this)); | 1066 for (auto& observer : observers_) |
| 1067 observer.OnWidgetCreated(this); |
| 1066 } | 1068 } |
| 1067 | 1069 |
| 1068 void Widget::OnNativeWidgetDestroying() { | 1070 void Widget::OnNativeWidgetDestroying() { |
| 1069 // Tell the focus manager (if any) that root_view is being removed | 1071 // Tell the focus manager (if any) that root_view is being removed |
| 1070 // in case that the focused view is under this root view. | 1072 // in case that the focused view is under this root view. |
| 1071 if (GetFocusManager() && root_view_) | 1073 if (GetFocusManager() && root_view_) |
| 1072 GetFocusManager()->ViewRemoved(root_view_.get()); | 1074 GetFocusManager()->ViewRemoved(root_view_.get()); |
| 1073 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this)); | 1075 for (auto& observer : observers_) |
| 1076 observer.OnWidgetDestroying(this); |
| 1074 if (non_client_view_) | 1077 if (non_client_view_) |
| 1075 non_client_view_->WindowClosing(); | 1078 non_client_view_->WindowClosing(); |
| 1076 widget_delegate_->WindowClosing(); | 1079 widget_delegate_->WindowClosing(); |
| 1077 } | 1080 } |
| 1078 | 1081 |
| 1079 void Widget::OnNativeWidgetDestroyed() { | 1082 void Widget::OnNativeWidgetDestroyed() { |
| 1080 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this)); | 1083 for (auto& observer : observers_) |
| 1084 observer.OnWidgetDestroyed(this); |
| 1081 widget_delegate_->DeleteDelegate(); | 1085 widget_delegate_->DeleteDelegate(); |
| 1082 widget_delegate_ = NULL; | 1086 widget_delegate_ = NULL; |
| 1083 native_widget_destroyed_ = true; | 1087 native_widget_destroyed_ = true; |
| 1084 } | 1088 } |
| 1085 | 1089 |
| 1086 gfx::Size Widget::GetMinimumSize() const { | 1090 gfx::Size Widget::GetMinimumSize() const { |
| 1087 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); | 1091 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); |
| 1088 } | 1092 } |
| 1089 | 1093 |
| 1090 gfx::Size Widget::GetMaximumSize() const { | 1094 gfx::Size Widget::GetMaximumSize() const { |
| 1091 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); | 1095 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); |
| 1092 } | 1096 } |
| 1093 | 1097 |
| 1094 void Widget::OnNativeWidgetMove() { | 1098 void Widget::OnNativeWidgetMove() { |
| 1095 widget_delegate_->OnWidgetMove(); | 1099 widget_delegate_->OnWidgetMove(); |
| 1096 NotifyCaretBoundsChanged(GetInputMethod()); | 1100 NotifyCaretBoundsChanged(GetInputMethod()); |
| 1097 | 1101 |
| 1098 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1102 for (auto& observer : observers_) |
| 1099 this, | 1103 observer.OnWidgetBoundsChanged(this, GetWindowBoundsInScreen()); |
| 1100 GetWindowBoundsInScreen())); | |
| 1101 } | 1104 } |
| 1102 | 1105 |
| 1103 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { | 1106 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { |
| 1104 View* root = GetRootView(); | 1107 View* root = GetRootView(); |
| 1105 if (root) | 1108 if (root) |
| 1106 root->SetSize(new_size); | 1109 root->SetSize(new_size); |
| 1107 | 1110 |
| 1108 NotifyCaretBoundsChanged(GetInputMethod()); | 1111 NotifyCaretBoundsChanged(GetInputMethod()); |
| 1109 SaveWindowPlacementIfInitialized(); | 1112 SaveWindowPlacementIfInitialized(); |
| 1110 | 1113 |
| 1111 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( | 1114 for (auto& observer : observers_) |
| 1112 this, | 1115 observer.OnWidgetBoundsChanged(this, GetWindowBoundsInScreen()); |
| 1113 GetWindowBoundsInScreen())); | |
| 1114 } | 1116 } |
| 1115 | 1117 |
| 1116 void Widget::OnNativeWidgetWorkspaceChanged() {} | 1118 void Widget::OnNativeWidgetWorkspaceChanged() {} |
| 1117 | 1119 |
| 1118 void Widget::OnNativeWidgetWindowShowStateChanged() { | 1120 void Widget::OnNativeWidgetWindowShowStateChanged() { |
| 1119 SaveWindowPlacementIfInitialized(); | 1121 SaveWindowPlacementIfInitialized(); |
| 1120 } | 1122 } |
| 1121 | 1123 |
| 1122 void Widget::OnNativeWidgetBeginUserBoundsChange() { | 1124 void Widget::OnNativeWidgetBeginUserBoundsChange() { |
| 1123 widget_delegate_->OnWindowBeginUserBoundsChange(); | 1125 widget_delegate_->OnWindowBeginUserBoundsChange(); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 | 1496 |
| 1495 //////////////////////////////////////////////////////////////////////////////// | 1497 //////////////////////////////////////////////////////////////////////////////// |
| 1496 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1498 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1497 | 1499 |
| 1498 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1500 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1499 return this; | 1501 return this; |
| 1500 } | 1502 } |
| 1501 | 1503 |
| 1502 } // namespace internal | 1504 } // namespace internal |
| 1503 } // namespace views | 1505 } // namespace views |
| OLD | NEW |