summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 09:57:50 +0000
committerflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 09:57:50 +0000
commite9c6c0f12d733b7a9764319179c6ed439a155122 (patch)
tree15c3d841d4e0c774c085daad068bef1eb8aa8bea
parentfa2f8a3c004f7a929d24451e7d5b9ba1e9f7098a (diff)
downloadchromium_src-e9c6c0f12d733b7a9764319179c6ed439a155122.zip
chromium_src-e9c6c0f12d733b7a9764319179c6ed439a155122.tar.gz
chromium_src-e9c6c0f12d733b7a9764319179c6ed439a155122.tar.bz2
Set the view to restore focus to when an initially unfocused window is restored.
BUG=179271 TEST=Open a panel (with focused: false) having a focusable element. Focus that element. Select another panel. Select the initial panel. The element should be focused and ready to receive keyboard input. Review URL: https://chromiumcodereview.appspot.com/13485003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192274 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc2
-rw-r--r--ui/views/focus/focus_manager.cc30
-rw-r--r--ui/views/focus/focus_manager.h5
-rw-r--r--ui/views/widget/widget.cc8
4 files changed, 26 insertions, 19 deletions
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 8f57163..6dab0a2 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -1618,8 +1618,6 @@ string16 BrowserView::GetAccessibleWindowTitle() const {
}
views::View* BrowserView::GetInitiallyFocusedView() {
- // We set the frame not focus on creation so this should never be called.
- NOTREACHED();
return NULL;
}
diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc
index 24baff1..bee68c2 100644
--- a/ui/views/focus/focus_manager.cc
+++ b/ui/views/focus/focus_manager.cc
@@ -276,23 +276,10 @@ void FocusManager::ClearFocus() {
}
void FocusManager::StoreFocusedView(bool clear_native_focus) {
- ViewStorage* view_storage = ViewStorage::GetInstance();
- if (!view_storage) {
- // This should never happen but bug 981648 seems to indicate it could.
- NOTREACHED();
- return;
- }
-
- // TODO(jcivelli): when a TabContents containing a popup is closed, the focus
- // is stored twice causing an assert. We should find a better alternative than
- // removing the view from the storage explicitly.
- view_storage->RemoveView(stored_focused_view_storage_id_);
-
+ SetStoredFocusView(focused_view_);
if (!focused_view_)
return;
- view_storage->StoreView(stored_focused_view_storage_id_, focused_view_);
-
View* v = focused_view_;
if (clear_native_focus) {
@@ -341,14 +328,27 @@ bool FocusManager::RestoreFocusedView() {
return false;
}
-void FocusManager::ClearStoredFocusedView() {
+void FocusManager::SetStoredFocusView(View* focus_view) {
ViewStorage* view_storage = ViewStorage::GetInstance();
if (!view_storage) {
// This should never happen but bug 981648 seems to indicate it could.
NOTREACHED();
return;
}
+
+ // TODO(jcivelli): when a TabContents containing a popup is closed, the focus
+ // is stored twice causing an assert. We should find a better alternative than
+ // removing the view from the storage explicitly.
view_storage->RemoveView(stored_focused_view_storage_id_);
+
+ if (!focus_view)
+ return;
+
+ view_storage->StoreView(stored_focused_view_storage_id_, focus_view);
+}
+
+void FocusManager::ClearStoredFocusedView() {
+ SetStoredFocusView(NULL);
}
// Find the next (previous if reverse is true) focusable view for the specified
diff --git a/ui/views/focus/focus_manager.h b/ui/views/focus/focus_manager.h
index 7686cf6..55310cf 100644
--- a/ui/views/focus/focus_manager.h
+++ b/ui/views/focus/focus_manager.h
@@ -186,6 +186,11 @@ class VIEWS_EXPORT FocusManager {
// successfully refocused - otherwise false.
bool RestoreFocusedView();
+ // Sets the |view| to be restored when calling RestoreFocusView. This is used
+ // to set where the focus should go on restoring a Window created without
+ // focus being set.
+ void SetStoredFocusView(View* view);
+
// Clears the stored focused view.
void ClearStoredFocusedView();
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index 6c8c609..7178e37 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -943,9 +943,13 @@ void Widget::TooltipTextChanged(View* view) {
}
bool Widget::SetInitialFocus() {
- if (!focus_on_creation_)
- return true;
View* v = widget_delegate_->GetInitiallyFocusedView();
+ if (!focus_on_creation_) {
+ // If not focusing the window now, tell the focus manager which view to
+ // focus when the window is restored.
+ focus_manager_->SetStoredFocusView(v);
+ return true;
+ }
if (v)
v->RequestFocus();
return !!v;