summaryrefslogtreecommitdiffstats
path: root/views/window
diff options
context:
space:
mode:
authorgeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 00:55:16 +0000
committergeorgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 00:55:16 +0000
commitbda9556c63579835dd14055a048f4e2094e7b3f5 (patch)
treef215d883f2ded85f48bc14d27edd4048f12c364b /views/window
parentc83c9e683a9376cea1ef675bfe92f7dbb98d45f5 (diff)
downloadchromium_src-bda9556c63579835dd14055a048f4e2094e7b3f5.zip
chromium_src-bda9556c63579835dd14055a048f4e2094e7b3f5.tar.gz
chromium_src-bda9556c63579835dd14055a048f4e2094e7b3f5.tar.bz2
Addded notification when ancestor gets changed. So windows that lack focus manager, because of being
created on inactive tab, could do the necessary work when focus manager is actually attached. This is relevant for Windows only, but some support functions (FindAllRootViews) could be useful for other architectures as well. BUG=22481 TEST=in the bug Review URL: http://codereview.chromium.org/492025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r--views/window/dialog_client_view.cc54
-rw-r--r--views/window/dialog_client_view.h14
2 files changed, 57 insertions, 11 deletions
diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc
index 64c4677..b25c6bc 100644
--- a/views/window/dialog_client_view.cc
+++ b/views/window/dialog_client_view.cc
@@ -110,7 +110,9 @@ DialogClientView::DialogClientView(Window* owner, View* contents_view)
cancel_button_(NULL),
default_button_(NULL),
extra_view_(NULL),
- accepted_(false) {
+ accepted_(false),
+ listening_to_focus_(false),
+ saved_focus_manager_(NULL) {
InitClass();
}
@@ -236,6 +238,17 @@ void DialogClientView::CancelWindow() {
}
///////////////////////////////////////////////////////////////////////////////
+// DialogClientView, View overrides:
+
+void DialogClientView::NativeViewHierarchyChanged(bool attached,
+ gfx::NativeView native_view,
+ RootView* root_view) {
+ if (attached) {
+ UpdateFocusListener();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
// DialogClientView, ClientView overrides:
bool DialogClientView::CanClose() const {
@@ -251,10 +264,11 @@ bool DialogClientView::CanClose() const {
}
void DialogClientView::WindowClosing() {
- FocusManager* focus_manager = GetFocusManager();
- DCHECK(focus_manager);
- if (focus_manager)
- focus_manager->RemoveFocusChangeListener(this);
+ if (listening_to_focus_) {
+ DCHECK(saved_focus_manager_);
+ if (saved_focus_manager_)
+ saved_focus_manager_->RemoveFocusChangeListener(this);
+ }
ClientView::WindowClosing();
}
@@ -302,12 +316,7 @@ void DialogClientView::ViewHierarchyChanged(bool is_add, View* parent,
ShowDialogButtons();
ClientView::ViewHierarchyChanged(is_add, parent, child);
- FocusManager* focus_manager = GetFocusManager();
- // Listen for focus change events so we can update the default button.
- DCHECK(focus_manager); // bug #1291225: crash reports seem to indicate it
- // can be NULL.
- if (focus_manager)
- focus_manager->AddFocusChangeListener(this);
+ UpdateFocusListener();
// The "extra view" must be created and installed after the contents view
// has been inserted into the view hierarchy.
@@ -503,4 +512,27 @@ void DialogClientView::Close() {
GetDialogDelegate()->OnClose();
}
+void DialogClientView::UpdateFocusListener() {
+ FocusManager* focus_manager = GetFocusManager();
+ // Listen for focus change events so we can update the default button.
+ // focus_manager can be NULL when the dialog is created on un-shown view.
+ // We start listening for focus changes when the page is visible.
+ // Focus manager could also change if window host changes a parent.
+ if (listening_to_focus_) {
+ if (saved_focus_manager_ == focus_manager)
+ return;
+ DCHECK(saved_focus_manager_);
+ if (saved_focus_manager_)
+ saved_focus_manager_->RemoveFocusChangeListener(this);
+ listening_to_focus_ = false;
+ }
+ saved_focus_manager_ = focus_manager;
+ // Listen for focus change events so we can update the default button.
+ if (focus_manager) {
+ focus_manager->AddFocusChangeListener(this);
+ listening_to_focus_ = true;
+ }
+}
+
+
} // namespace views
diff --git a/views/window/dialog_client_view.h b/views/window/dialog_client_view.h
index 1c3d19f..d7a5fb2 100644
--- a/views/window/dialog_client_view.h
+++ b/views/window/dialog_client_view.h
@@ -50,6 +50,11 @@ class DialogClientView : public ClientView,
NativeButton* ok_button() const { return ok_button_; }
NativeButton* cancel_button() const { return cancel_button_; }
+ // Overridden from View:
+ virtual void NativeViewHierarchyChanged(bool attached,
+ gfx::NativeView native_view,
+ RootView* root_view);
+
// Overridden from ClientView:
virtual bool CanClose() const;
virtual void WindowClosing();
@@ -98,6 +103,9 @@ class DialogClientView : public ClientView,
// Closes the window.
void Close();
+ // Updates focus listener.
+ void UpdateFocusListener();
+
// The dialog buttons.
NativeButton* ok_button_;
NativeButton* cancel_button_;
@@ -114,6 +122,12 @@ class DialogClientView : public ClientView,
// True if the window was Accepted by the user using the OK button.
bool accepted_;
+ // true if focus listener is added.
+ bool listening_to_focus_;
+
+ // When ancestor gets changed focus manager gets changed as well.
+ FocusManager* saved_focus_manager_;
+
// Static resource initialization
static void InitClass();
static gfx::Font* dialog_button_font_;