Skip to content

Commit

Permalink
Reverting 15468.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15470 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed May 6, 2009
1 parent efb5ccb commit 50ddd8b
Show file tree
Hide file tree
Showing 19 changed files with 130 additions and 107 deletions.
2 changes: 0 additions & 2 deletions app/DEPS
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
include_rules = [
# TODO(beng): Modify this link to be more specific about what resource
# headers are included once app gets its own strings.
"+grit",
"+net",
# TODO(beng): Sever these links once we have extracted all deps from
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/automation/automation_window_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<>
Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/browser_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/browser_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions chrome/browser/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
#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"
#include "chrome/common/win_util.h"
#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"
Expand Down Expand Up @@ -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();
}
4 changes: 0 additions & 4 deletions chrome/common/common.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@
RelativePath=".\gears_api.h"
>
</File>
<File
RelativePath=".\hwnd_notification_source.h"
>
</File>
<File
RelativePath=".\important_file_writer.cc"
>
Expand Down
4 changes: 4 additions & 0 deletions chrome/common/notification_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions chrome/views/controls/native_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions chrome/views/focus/focus_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 6 additions & 5 deletions chrome/views/focus/focus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 22 additions & 16 deletions chrome/views/focus/view_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <algorithm>

#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "chrome/common/notification_service.h"

namespace views {

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
11 changes: 7 additions & 4 deletions chrome/views/focus/view_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions chrome/views/views.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@
RelativePath=".\widget\aero_tooltip_manager.h"
>
</File>
<File
RelativePath=".\widget\hwnd_notification_source.h"
>
</File>
<File
RelativePath=".\widget\root_view.cc"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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_
25 changes: 5 additions & 20 deletions chrome/views/widget/root_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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));
}
}

Expand Down
8 changes: 8 additions & 0 deletions chrome/views/widget/widget_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
}

Expand Down
Loading

0 comments on commit 50ddd8b

Please sign in to comment.