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

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

Issue 2418983002: ui/views: convert usage of FOR_EACH_OBSERVER macro (Closed)
Patch Set: Created 4 years, 2 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/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
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 (WidgetRemovalsObserver& 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
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 (WidgetObserver& observer : observers_)
582 observer.OnWidgetClosing(this);
583
583 native_widget_->Close(); 584 native_widget_->Close();
584 widget_closed_ = true; 585 widget_closed_ = true;
585 } 586 }
586 } 587 }
587 588
588 void Widget::CloseNow() { 589 void Widget::CloseNow() {
589 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this)); 590 for (WidgetObserver& observer : observers_)
591 observer.OnWidgetClosing(this);
590 native_widget_->CloseNow(); 592 native_widget_->CloseNow();
591 } 593 }
592 594
593 bool Widget::IsClosed() const { 595 bool Widget::IsClosed() const {
594 return widget_closed_; 596 return widget_closed_;
595 } 597 }
596 598
597 void Widget::Show() { 599 void Widget::Show() {
598 const ui::Layer* layer = GetLayer(); 600 const ui::Layer* layer = GetLayer();
599 TRACE_EVENT1("views", "Widget::Show", "layer", 601 TRACE_EVENT1("views", "Widget::Show", "layer",
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 return always_render_as_active_; 1021 return always_render_as_active_;
1020 } 1022 }
1021 1023
1022 void Widget::OnNativeWidgetActivationChanged(bool active) { 1024 void Widget::OnNativeWidgetActivationChanged(bool active) {
1023 // On windows we may end up here before we've completed initialization (from 1025 // 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 1026 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know
1025 // the Widget and will crash attempting to access it. 1027 // the Widget and will crash attempting to access it.
1026 if (!active && native_widget_initialized_) 1028 if (!active && native_widget_initialized_)
1027 SaveWindowPlacement(); 1029 SaveWindowPlacement();
1028 1030
1029 FOR_EACH_OBSERVER(WidgetObserver, observers_, 1031 for (WidgetObserver& observer : observers_)
1030 OnWidgetActivationChanged(this, active)); 1032 observer.OnWidgetActivationChanged(this, active);
1031 1033
1032 if (non_client_view()) 1034 if (non_client_view())
1033 non_client_view()->frame_view()->ActivationChanged(active); 1035 non_client_view()->frame_view()->ActivationChanged(active);
1034 } 1036 }
1035 1037
1036 void Widget::OnNativeFocus() { 1038 void Widget::OnNativeFocus() {
1037 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(GetNativeView()); 1039 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(GetNativeView());
1038 } 1040 }
1039 1041
1040 void Widget::OnNativeBlur() { 1042 void Widget::OnNativeBlur() {
1041 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(nullptr); 1043 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(nullptr);
1042 } 1044 }
1043 1045
1044 void Widget::OnNativeWidgetVisibilityChanging(bool visible) { 1046 void Widget::OnNativeWidgetVisibilityChanging(bool visible) {
1045 FOR_EACH_OBSERVER(WidgetObserver, observers_, 1047 for (WidgetObserver& observer : observers_)
1046 OnWidgetVisibilityChanging(this, visible)); 1048 observer.OnWidgetVisibilityChanging(this, visible);
1047 } 1049 }
1048 1050
1049 void Widget::OnNativeWidgetVisibilityChanged(bool visible) { 1051 void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
1050 View* root = GetRootView(); 1052 View* root = GetRootView();
1051 if (root) 1053 if (root)
1052 root->PropagateVisibilityNotifications(root, visible); 1054 root->PropagateVisibilityNotifications(root, visible);
1053 FOR_EACH_OBSERVER(WidgetObserver, observers_, 1055 for (WidgetObserver& observer : observers_)
1054 OnWidgetVisibilityChanged(this, visible)); 1056 observer.OnWidgetVisibilityChanged(this, visible);
1055 if (GetCompositor() && root && root->layer()) 1057 if (GetCompositor() && root && root->layer())
1056 root->layer()->SetVisible(visible); 1058 root->layer()->SetVisible(visible);
1057 } 1059 }
1058 1060
1059 void Widget::OnNativeWidgetCreated(bool desktop_widget) { 1061 void Widget::OnNativeWidgetCreated(bool desktop_widget) {
1060 if (is_top_level()) 1062 if (is_top_level())
1061 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget)); 1063 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget));
1062 1064
1063 native_widget_->InitModalType(widget_delegate_->GetModalType()); 1065 native_widget_->InitModalType(widget_delegate_->GetModalType());
1064 1066
1065 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this)); 1067 for (WidgetObserver& observer : observers_)
1068 observer.OnWidgetCreated(this);
1066 } 1069 }
1067 1070
1068 void Widget::OnNativeWidgetDestroying() { 1071 void Widget::OnNativeWidgetDestroying() {
1069 // Tell the focus manager (if any) that root_view is being removed 1072 // Tell the focus manager (if any) that root_view is being removed
1070 // in case that the focused view is under this root view. 1073 // in case that the focused view is under this root view.
1071 if (GetFocusManager() && root_view_) 1074 if (GetFocusManager() && root_view_)
1072 GetFocusManager()->ViewRemoved(root_view_.get()); 1075 GetFocusManager()->ViewRemoved(root_view_.get());
1073 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this)); 1076 for (WidgetObserver& observer : observers_)
1077 observer.OnWidgetDestroying(this);
1074 if (non_client_view_) 1078 if (non_client_view_)
1075 non_client_view_->WindowClosing(); 1079 non_client_view_->WindowClosing();
1076 widget_delegate_->WindowClosing(); 1080 widget_delegate_->WindowClosing();
1077 } 1081 }
1078 1082
1079 void Widget::OnNativeWidgetDestroyed() { 1083 void Widget::OnNativeWidgetDestroyed() {
1080 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this)); 1084 for (WidgetObserver& observer : observers_)
1085 observer.OnWidgetDestroyed(this);
1081 widget_delegate_->DeleteDelegate(); 1086 widget_delegate_->DeleteDelegate();
1082 widget_delegate_ = NULL; 1087 widget_delegate_ = NULL;
1083 native_widget_destroyed_ = true; 1088 native_widget_destroyed_ = true;
1084 } 1089 }
1085 1090
1086 gfx::Size Widget::GetMinimumSize() const { 1091 gfx::Size Widget::GetMinimumSize() const {
1087 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size(); 1092 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
1088 } 1093 }
1089 1094
1090 gfx::Size Widget::GetMaximumSize() const { 1095 gfx::Size Widget::GetMaximumSize() const {
1091 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size(); 1096 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
1092 } 1097 }
1093 1098
1094 void Widget::OnNativeWidgetMove() { 1099 void Widget::OnNativeWidgetMove() {
1095 widget_delegate_->OnWidgetMove(); 1100 widget_delegate_->OnWidgetMove();
1096 NotifyCaretBoundsChanged(GetInputMethod()); 1101 NotifyCaretBoundsChanged(GetInputMethod());
1097 1102
1098 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( 1103 for (WidgetObserver& observer : observers_)
1099 this, 1104 observer.OnWidgetBoundsChanged(this, GetWindowBoundsInScreen());
1100 GetWindowBoundsInScreen()));
1101 } 1105 }
1102 1106
1103 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { 1107 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
1104 View* root = GetRootView(); 1108 View* root = GetRootView();
1105 if (root) 1109 if (root)
1106 root->SetSize(new_size); 1110 root->SetSize(new_size);
1107 1111
1108 NotifyCaretBoundsChanged(GetInputMethod()); 1112 NotifyCaretBoundsChanged(GetInputMethod());
1109 SaveWindowPlacementIfInitialized(); 1113 SaveWindowPlacementIfInitialized();
1110 1114
1111 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged( 1115 for (WidgetObserver& observer : observers_)
1112 this, 1116 observer.OnWidgetBoundsChanged(this, GetWindowBoundsInScreen());
1113 GetWindowBoundsInScreen()));
1114 } 1117 }
1115 1118
1116 void Widget::OnNativeWidgetWorkspaceChanged() {} 1119 void Widget::OnNativeWidgetWorkspaceChanged() {}
1117 1120
1118 void Widget::OnNativeWidgetWindowShowStateChanged() { 1121 void Widget::OnNativeWidgetWindowShowStateChanged() {
1119 SaveWindowPlacementIfInitialized(); 1122 SaveWindowPlacementIfInitialized();
1120 } 1123 }
1121 1124
1122 void Widget::OnNativeWidgetBeginUserBoundsChange() { 1125 void Widget::OnNativeWidgetBeginUserBoundsChange() {
1123 widget_delegate_->OnWindowBeginUserBoundsChange(); 1126 widget_delegate_->OnWindowBeginUserBoundsChange();
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 1497
1495 //////////////////////////////////////////////////////////////////////////////// 1498 ////////////////////////////////////////////////////////////////////////////////
1496 // internal::NativeWidgetPrivate, NativeWidget implementation: 1499 // internal::NativeWidgetPrivate, NativeWidget implementation:
1497 1500
1498 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { 1501 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1499 return this; 1502 return this;
1500 } 1503 }
1501 1504
1502 } // namespace internal 1505 } // namespace internal
1503 } // namespace views 1506 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/x11_desktop_handler.cc ('k') | ui/views/win/windows_session_change_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698