diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 23:23:11 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 23:23:11 +0000 |
commit | 50ddd8b885c03fe4fba19130918939026ae6ef24 (patch) | |
tree | 4df5857465cbded5c559c917320d2ee09f13eb97 /chrome | |
parent | efb5ccb4aa5aa111a1e894f8ad22cf6a8f053aba (diff) | |
download | chromium_src-50ddd8b885c03fe4fba19130918939026ae6ef24.zip chromium_src-50ddd8b885c03fe4fba19130918939026ae6ef24.tar.gz chromium_src-50ddd8b885c03fe4fba19130918939026ae6ef24.tar.bz2 |
Reverting 15468.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15470 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_window_tracker.h | 2 | ||||
-rw-r--r-- | chrome/browser/browser_list.cc | 8 | ||||
-rw-r--r-- | chrome/browser/browser_list.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 7 | ||||
-rw-r--r-- | chrome/common/common.vcproj | 4 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 4 | ||||
-rw-r--r-- | chrome/views/controls/native_control.cc | 1 | ||||
-rw-r--r-- | chrome/views/focus/focus_manager.cc | 20 | ||||
-rw-r--r-- | chrome/views/focus/focus_manager.h | 11 | ||||
-rw-r--r-- | chrome/views/focus/view_storage.cc | 38 | ||||
-rw-r--r-- | chrome/views/focus/view_storage.h | 11 | ||||
-rw-r--r-- | chrome/views/views.vcproj | 4 | ||||
-rw-r--r-- | chrome/views/widget/hwnd_notification_source.h (renamed from chrome/common/hwnd_notification_source.h) | 6 | ||||
-rw-r--r-- | chrome/views/widget/root_view.cc | 25 | ||||
-rw-r--r-- | chrome/views/widget/widget_win.cc | 8 | ||||
-rw-r--r-- | chrome/views/window/window.h | 12 | ||||
-rw-r--r-- | chrome/views/window/window_win.cc | 54 | ||||
-rw-r--r-- | chrome/views/window/window_win.h | 17 |
18 files changed, 130 insertions, 105 deletions
diff --git a/chrome/browser/automation/automation_window_tracker.h b/chrome/browser/automation/automation_window_tracker.h index effa61e..1b9aff8 100644 --- a/chrome/browser/automation/automation_window_tracker.h +++ b/chrome/browser/automation/automation_window_tracker.h @@ -13,7 +13,7 @@ // Since HWNDs aren't pointers, we can't have NativeWindow // be directly a pointer and so must explicitly declare the Source types // for it. -#include "chrome/common/hwnd_notification_source.h" +#include "chrome/views/widget/hwnd_notification_source.h" #elif defined(OS_LINUX) || defined(OS_MACOSX) // But on Linux and Mac, it is a pointer so this definition suffices. template<> diff --git a/chrome/browser/browser_list.cc b/chrome/browser/browser_list.cc index 034bba6..3b6ee8b 100644 --- a/chrome/browser/browser_list.cc +++ b/chrome/browser/browser_list.cc @@ -67,8 +67,12 @@ void BrowserList::RemoveBrowser(Browser* browser) { // If the last Browser object was destroyed, make sure we try to close any // remaining dependent windows too. - if (browsers_.empty()) - AllBrowsersClosed(); + if (browsers_.empty()) { + NotificationService::current()->Notify( + NotificationType::ALL_APPWINDOWS_CLOSED, + NotificationService::AllSources(), + NotificationService::NoDetails()); + } g_browser_process->ReleaseModule(); } diff --git a/chrome/browser/browser_list.h b/chrome/browser/browser_list.h index f167fdc..c73ac2e 100644 --- a/chrome/browser/browser_list.h +++ b/chrome/browser/browser_list.h @@ -115,9 +115,6 @@ class BrowserList { // Returns true if at least one off the record session is active. static bool IsOffTheRecordSessionActive(); - // Called when the last browser is closed. - static void AllBrowsersClosed(); - private: // Helper method to remove a browser instance from a list of browsers static void RemoveBrowserFrom(Browser* browser, list_type* browser_list); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 694c109..4d861f0 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -50,7 +50,6 @@ #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/hwnd_notification_source.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -58,6 +57,7 @@ #include "chrome/views/controls/scrollbar/native_scroll_bar.h" #include "chrome/views/fill_layout.h" #include "chrome/views/view.h" +#include "chrome/views/widget/hwnd_notification_source.h" #include "chrome/views/widget/root_view.h" #include "chrome/views/window/non_client_view.h" #include "chrome/views/window/window_win.h" @@ -1666,8 +1666,3 @@ BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { FindBar* BrowserWindow::CreateFindBar(Browser* browser) { return new FindBarWin(static_cast<BrowserView*>(browser->window())); } - -// static -void BrowserList::AllBrowsersClosed() { - views::Window::CloseAllSecondaryWindows(); -} diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index 4c2d021..90b15d8 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -458,10 +458,6 @@ > </File> <File - RelativePath=".\hwnd_notification_source.h" - > - </File> - <File RelativePath=".\important_file_writer.cc" > </File> diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 82d62e0..1f67ec3 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -184,6 +184,10 @@ class NotificationType { // details are passed. ALL_APPWINDOWS_CLOSED, + // Indicates a new top window has been created. The source is the + // WindowWin. + WINDOW_CREATED, + // Indicates that a top window has been closed. The source is the HWND // that was closed, no details are expected. WINDOW_CLOSED, diff --git a/chrome/views/controls/native_control.cc b/chrome/views/controls/native_control.cc index bf40711..84a3226 100644 --- a/chrome/views/controls/native_control.cc +++ b/chrome/views/controls/native_control.cc @@ -12,6 +12,7 @@ #include "app/l10n_util_win.h" #include "base/logging.h" #include "base/win_util.h" +#include "chrome/common/notification_service.h" #include "chrome/views/background.h" #include "chrome/views/border.h" #include "chrome/views/controls/hwnd_view.h" diff --git a/chrome/views/focus/focus_manager.cc b/chrome/views/focus/focus_manager.cc index 9e477e9..031cb0a 100644 --- a/chrome/views/focus/focus_manager.cc +++ b/chrome/views/focus/focus_manager.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/win_util.h" #include "chrome/browser/renderer_host/render_widget_host_view_win.h" +#include "chrome/common/notification_service.h" #include "chrome/views/accelerator.h" #include "chrome/views/focus/focus_manager.h" #include "chrome/views/focus/view_storage.h" @@ -101,6 +102,13 @@ FocusManager* FocusManager::CreateFocusManager(HWND window, FocusManager* focus_manager = new FocusManager(window, root_view); SetProp(window, kFocusManagerKey, focus_manager); + // We register for view removed notifications so we can make sure we don't + // keep references to invalidated views. + NotificationService::current()->AddObserver( + focus_manager, + NotificationType::VIEW_REMOVED, + NotificationService::AllSources()); + return focus_manager; } @@ -204,6 +212,11 @@ bool FocusManager::OnNCDestroy(HWND window) { // We are the top window. DCHECK(GetProp(window, kFocusManagerKey)); + // Unregister notifications. + NotificationService::current()->RemoveObserver( + this, + NotificationType::VIEW_REMOVED, + NotificationService::AllSources()); // Make sure this is called on the window that was set with the // FocusManager. @@ -672,8 +685,11 @@ AcceleratorTarget* FocusManager::GetTargetForAccelerator( return NULL; } -void FocusManager::ViewRemoved(View* parent, View* removed) { - if (focused_view_ && focused_view_ == removed) +void FocusManager::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::VIEW_REMOVED); + if (focused_view_ && Source<View>(focused_view_) == source) focused_view_ = NULL; } diff --git a/chrome/views/focus/focus_manager.h b/chrome/views/focus/focus_manager.h index 4a32c0d..190385b 100644 --- a/chrome/views/focus/focus_manager.h +++ b/chrome/views/focus/focus_manager.h @@ -13,6 +13,7 @@ #include <vector> #include <map> +#include "chrome/common/notification_observer.h" #include "chrome/views/accelerator.h" // The FocusManager class is used to handle focus traversal, store/restore @@ -151,7 +152,7 @@ class FocusChangeListener { virtual void FocusWillChange(View* focused_before, View* focused_now) = 0; }; -class FocusManager { +class FocusManager : public NotificationObserver { public: #if defined(OS_WIN) // Creates a FocusManager for the specified window. Top level windows @@ -263,10 +264,10 @@ class FocusManager { // Returns true if an accelerator was activated. bool ProcessAccelerator(const Accelerator& accelerator); - // Called by a RootView when a view within its hierarchy is removed from its - // parent. This will only be called by a RootView in a hierarchy of Widgets - // that this FocusManager is attached to the parent Widget of. - void ViewRemoved(View* parent, View* removed); + // NotificationObserver method. + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); void AddKeystrokeListener(KeystrokeListener* listener); void RemoveKeystrokeListener(KeystrokeListener* listener); diff --git a/chrome/views/focus/view_storage.cc b/chrome/views/focus/view_storage.cc index d8196b2..1a8324c 100644 --- a/chrome/views/focus/view_storage.cc +++ b/chrome/views/focus/view_storage.cc @@ -6,8 +6,8 @@ #include <algorithm> -#include "base/logging.h" #include "base/stl_util-inl.h" +#include "chrome/common/notification_service.h" namespace views { @@ -38,6 +38,8 @@ ViewStorage* ViewStorage::GetSharedInstance() { } ViewStorage::ViewStorage() : view_storage_next_id_(0) { + NotificationService::current()->AddObserver( + this, NotificationType::VIEW_REMOVED, NotificationService::AllSources()); } ViewStorage::~ViewStorage() { @@ -124,21 +126,6 @@ void ViewStorage::RemoveView(int storage_id) { EraseView(storage_id, false); } -void ViewStorage::ViewRemoved(View* parent, View* removed) { - // Let's first retrieve the ids for that view. - std::map<View*, std::vector<int>*>::iterator ids_iter = - view_to_ids_.find(removed); - - if (ids_iter == view_to_ids_.end()) { - // That view is not in the view storage. - return; - } - - std::vector<int>* ids = ids_iter->second; - DCHECK(!ids->empty()); - EraseView((*ids)[0], true); -} - void ViewStorage::EraseView(int storage_id, bool remove_all_ids) { // Remove the view from id_to_view_location_. std::map<int, ViewLocationInfo*>::iterator location_iter = @@ -179,4 +166,23 @@ void ViewStorage::EraseView(int storage_id, bool remove_all_ids) { } } +void ViewStorage::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::VIEW_REMOVED); + + // Let's first retrieve the ids for that view. + std::map<View*, std::vector<int>*>::iterator ids_iter = + view_to_ids_.find(Source<View>(source).ptr()); + + if (ids_iter == view_to_ids_.end()) { + // That view is not in the view storage. + return; + } + + std::vector<int>* ids = ids_iter->second; + DCHECK(!ids->empty()); + EraseView((*ids)[0], true); +} + } // namespace views diff --git a/chrome/views/focus/view_storage.h b/chrome/views/focus/view_storage.h index 7aac7bb..cb0cb67 100644 --- a/chrome/views/focus/view_storage.h +++ b/chrome/views/focus/view_storage.h @@ -6,6 +6,7 @@ #define CHROME_VIEWS_FOCUS_VIEW_STORAGE_H_ #include "base/singleton.h" +#include "chrome/common/notification_observer.h" #include "chrome/views/view.h" // This class is a simple storage place for storing/retrieving views. It is @@ -25,7 +26,7 @@ namespace views { struct ViewLocationInfo; -class ViewStorage { +class ViewStorage : public NotificationObserver { public: // Returns the global ViewStorage instance. // It is guaranted to be non NULL. @@ -43,15 +44,17 @@ class ViewStorage { // Removes the view associated with |storage_id| if any. void RemoveView(int storage_id); - // Notifies the ViewStorage that a view was removed from its parent somewhere. - void ViewRemoved(View* parent, View* removed); - private: friend struct DefaultSingletonTraits<ViewStorage>; ViewStorage(); ~ViewStorage(); + // NotificationObserver method. + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // Removes the view associated with |storage_id|. If |remove_all_ids| is true, // all other mapping pointing to the same view are removed as well. void EraseView(int storage_id, bool remove_all_ids); diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj index f972022..8e5d2fe 100644 --- a/chrome/views/views.vcproj +++ b/chrome/views/views.vcproj @@ -197,6 +197,10 @@ > </File> <File + RelativePath=".\widget\hwnd_notification_source.h" + > + </File> + <File RelativePath=".\widget\root_view.cc" > <FileConfiguration diff --git a/chrome/common/hwnd_notification_source.h b/chrome/views/widget/hwnd_notification_source.h index 63df703..602ae44 100644 --- a/chrome/common/hwnd_notification_source.h +++ b/chrome/views/widget/hwnd_notification_source.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_COMMON_HWND_NOTIFICATION_SOURCE_H_ -#define CHROME_COMMON_HWND_NOTIFICATION_SOURCE_H_ +#ifndef CHROME_VIEWS_WIDGET_HWND_NOTIFICATION_SOURCE_H_ +#define CHROME_VIEWS_WIDGET_HWND_NOTIFICATION_SOURCE_H_ #include "chrome/common/notification_source.h" @@ -21,4 +21,4 @@ class Source<HWND> : public NotificationSource { HWND ptr() const { return static_cast<HWND>(ptr_); } }; -#endif // #define CHROME_COMMON_HWND_NOTIFICATION_SOURCE_H_ +#endif // #define CHROME_VIEWS_WIDGET_HWND_NOTIFICATION_SOURCE_H_ diff --git a/chrome/views/widget/root_view.cc b/chrome/views/widget/root_view.cc index e674aac..bd57fe4 100644 --- a/chrome/views/widget/root_view.cc +++ b/chrome/views/widget/root_view.cc @@ -13,12 +13,11 @@ #endif #include "base/logging.h" #include "base/message_loop.h" +#include "chrome/common/notification_service.h" #if defined(OS_WIN) -#include "chrome/views/focus/view_storage.h" #include "chrome/views/widget/root_view_drop_target.h" #endif #include "chrome/views/widget/widget.h" -#include "chrome/views/window/window.h" namespace views { @@ -262,24 +261,10 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (default_keyboard_handler_ == child) { default_keyboard_handler_ = NULL; } - - // For a given widget hierarchy, focus is tracked by a FocusManager attached - // to our nearest enclosing Window. <-- Important Assumption! - // We may not have access to our window if this function is called as a - // result of teardown during the deletion of the RootView and its hierarchy, - // so we don't bother notifying the FocusManager in that case because it - // will have already been destroyed (the Widget that contains us is - // NCDESTROY'ed which in turn destroys the focus manager _before_ the - // RootView is deleted.) - Window* window = GetWindow(); - if (window) { - FocusManager* focus_manager = - FocusManager::GetFocusManager(window->GetNativeWindow()); - focus_manager->ViewRemoved(parent, child); - } -#if defined(OS_WIN) - ViewStorage::GetSharedInstance()->ViewRemoved(parent, child); -#endif + NotificationService::current()->Notify( + NotificationType::VIEW_REMOVED, + Source<View>(child), + Details<View>(parent)); } } diff --git a/chrome/views/widget/widget_win.cc b/chrome/views/widget/widget_win.cc index 5ee065a..0bb3e78 100644 --- a/chrome/views/widget/widget_win.cc +++ b/chrome/views/widget/widget_win.cc @@ -9,12 +9,14 @@ #include "base/string_util.h" #include "base/win_util.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/notification_service.h" #include "chrome/common/win_util.h" #include "chrome/views/accessibility/view_accessibility.h" #include "chrome/views/controls/native_control_win.h" #include "chrome/views/fill_layout.h" #include "chrome/views/focus/focus_util_win.h" #include "chrome/views/widget/aero_tooltip_manager.h" +#include "chrome/views/widget/hwnd_notification_source.h" #include "chrome/views/widget/root_view.h" #include "chrome/views/window/window_win.h" @@ -465,6 +467,12 @@ void WidgetWin::OnCaptureChanged(HWND hwnd) { } void WidgetWin::OnClose() { + // WARNING: this method is NOT called for all WidgetWins. If you need to do + // cleanup code before WidgetWin is destroyed, put it in OnDestroy. + NotificationService::current()->Notify( + NotificationType::WINDOW_CLOSED, Source<HWND>(hwnd_), + NotificationService::NoDetails()); + Close(); } diff --git a/chrome/views/window/window.h b/chrome/views/window/window.h index 819f31c..fe820da 100644 --- a/chrome/views/window/window.h +++ b/chrome/views/window/window.h @@ -39,11 +39,6 @@ class Window { static gfx::Size GetLocalizedContentsSize(int col_resource_id, int row_resource_id); - // Closes all windows that aren't identified as "app windows" via - // IsAppWindow. Called during application shutdown when the last "app window" - // is closed. - static void CloseAllSecondaryWindows(); - // Retrieves the window's bounds, including its frame. virtual gfx::Rect GetBounds() const = 0; @@ -52,7 +47,7 @@ class Window { // Sizes and/or places the window to the specified bounds, size or position. virtual void SetBounds(const gfx::Rect& bounds) = 0; - + // As above, except the window is inserted after |other_window| in the window // Z-order. If this window is not yet visible, other_window's monitor is used // as the constraining rectangle, rather than this window's monitor. @@ -90,11 +85,6 @@ class Window { virtual void SetFullscreen(bool fullscreen) = 0; virtual bool IsFullscreen() const = 0; - // Returns true if the Window is considered to be an "app window" - i.e. - // any window which when it is the last of its type closed causes the - // application to exit. - virtual bool IsAppWindow() const { return false; } - // Toggles the enable state for the Close button (and the Close menu item in // the system menu). virtual void EnableClose(bool enable) = 0; diff --git a/chrome/views/window/window_win.cc b/chrome/views/window/window_win.cc index 73be950..7b0c528 100644 --- a/chrome/views/window/window_win.cc +++ b/chrome/views/window/window_win.cc @@ -14,6 +14,7 @@ #include "app/resource_bundle.h" #include "base/win_util.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/notification_service.h" #include "chrome/common/win_util.h" #include "chrome/views/widget/root_view.h" #include "chrome/views/window/client_view.h" @@ -428,6 +429,19 @@ gfx::NativeWindow WindowWin::GetNativeWindow() const { return GetNativeView(); } +//////////////////////////////////////////////////////////////////////////////// +// WindowWin, NotificationObserver implementation: + +void WindowWin::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + // This window is closed when the last app window is closed. + DCHECK(type == NotificationType::ALL_APPWINDOWS_CLOSED); + // Only registered as an observer when we're not an app window. + // XXX DCHECK(!IsAppWindow()); + Close(); +} + /////////////////////////////////////////////////////////////////////////////// // WindowWin, protected: @@ -493,7 +507,20 @@ void WindowWin::Init(HWND parent, const gfx::Rect& bounds) { GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, &last_work_area_); + + if (!IsAppWindow()) { + notification_registrar_.Add( + this, + NotificationType::ALL_APPWINDOWS_CLOSED, + NotificationService::AllSources()); + } + ResetWindowRegion(false); + + NotificationService::current()->Notify( + NotificationType::WINDOW_CREATED, + Source<WindowWin>(this), + NotificationService::NoDetails()); } void WindowWin::SizeWindowToDefault() { @@ -1416,31 +1443,4 @@ void WindowWin::InitClass() { } } -namespace { -// static -static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { - WidgetWin* widget = reinterpret_cast<WidgetWin*>( - win_util::GetWindowUserData(hwnd)); - if (!widget) - return TRUE; - - // If the toplevel HWND is a Window, close it if it's identified as a - // secondary window. - Window* window = widget->GetWindow(); - if (window) { - if (!window->IsAppWindow()) - window->Close(); - } else { - // If it's not a Window, then close it anyway since it probably is - // secondary. - widget->Close(); - } - return TRUE; -} -} // namespace - -void Window::CloseAllSecondaryWindows() { - EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); -} - } // namespace views diff --git a/chrome/views/window/window_win.h b/chrome/views/window/window_win.h index 749ae94..239e17e 100644 --- a/chrome/views/window/window_win.h +++ b/chrome/views/window/window_win.h @@ -5,6 +5,7 @@ #ifndef CHROME_VIEWS_WINDOW_WINDOW_WIN_H__ #define CHROME_VIEWS_WINDOW_WINDOW_WIN_H__ +#include "chrome/common/notification_registrar.h" #include "chrome/views/widget/widget_win.h" #include "chrome/views/window/client_view.h" #include "chrome/views/window/non_client_view.h" @@ -29,7 +30,8 @@ class WindowDelegate; // /////////////////////////////////////////////////////////////////////////////// class WindowWin : public WidgetWin, - public Window { + public Window, + public NotificationObserver { public: virtual ~WindowWin(); @@ -89,6 +91,11 @@ class WindowWin : public WidgetWin, virtual ClientView* GetClientView() const; virtual gfx::NativeWindow GetNativeWindow() const; + // NotificationObserver overrides: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + protected: friend Window; @@ -104,6 +111,11 @@ class WindowWin : public WidgetWin, // Sizes the window to the default size specified by its ClientView. virtual void SizeWindowToDefault(); + // Returns true if the WindowWin is considered to be an "app window" - i.e. + // any window which when it is the last of its type closed causes the + // application to exit. + virtual bool IsAppWindow() const { return false; } + // Shows the system menu at the specified screen point. void RunSystemMenu(const gfx::Point& point); @@ -299,6 +311,9 @@ class WindowWin : public WidgetWin, HMONITOR last_monitor_; gfx::Rect last_monitor_rect_, last_work_area_; + // Hold onto notifications. + NotificationRegistrar notification_registrar_; + DISALLOW_COPY_AND_ASSIGN(WindowWin); }; |