summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-29 21:22:03 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-29 21:22:03 +0000
commit85ff2c48df0789ae2476cd85738e07cecae9b3e3 (patch)
treed5a15f916376146d8626b92d97556c80627c9d0c /chrome
parente2eb43115440dc442b92c5842274290caedb146f (diff)
downloadchromium_src-85ff2c48df0789ae2476cd85738e07cecae9b3e3.zip
chromium_src-85ff2c48df0789ae2476cd85738e07cecae9b3e3.tar.gz
chromium_src-85ff2c48df0789ae2476cd85738e07cecae9b3e3.tar.bz2
Revert the Omnibox when changing tabs while its contents have been deleted.
To do this, I needed to add a new TabStripModelObserver call that fired before the tab had been changed, since when the Omnibox asks for the current permanent_text_ it gets it from the selected tab's navigation controller. BUG=6850 Review URL: http://codereview.chromium.org/113983 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17241 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc14
-rw-r--r--chrome/browser/browser.cc12
-rw-r--r--chrome/browser/browser.h1
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc19
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h4
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc7
-rw-r--r--chrome/browser/tabs/tab_strip_model.h5
-rw-r--r--chrome/browser/views/frame/browser_view.cc14
-rw-r--r--chrome/browser/views/frame/browser_view.h1
9 files changed, 51 insertions, 26 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 2ab706b3..70622d3 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -71,8 +71,18 @@ const AutocompleteEditModel::State
// Like typing, switching tabs "accepts" the temporary text as the user
// text, because it makes little sense to have temporary text when the
// popup is closed.
- if (user_input_in_progress_)
- InternalSetUserText(UserTextFromDisplayText(view_->GetText()));
+ if (user_input_in_progress_) {
+ // Weird edge case to match other browsers: if the edit is empty, revert to
+ // the permanent text (so the user can get it back easily) but select it (so
+ // on switching back, typing will "just work").
+ const std::wstring user_text(UserTextFromDisplayText(view_->GetText()));
+ if (user_text.empty()) {
+ view_->RevertAll();
+ view_->SelectAll(true);
+ } else {
+ InternalSetUserText(user_text);
+ }
+ }
return State(user_input_in_progress_, user_text_, keyword_, is_keyword_hint_,
keyword_ui_state_, show_search_hint_);
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index bdb7fca..8ec46f1 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1583,6 +1583,12 @@ void Browser::TabDetachedAt(TabContents* contents, int index) {
Source<TabContents>(contents));
}
+void Browser::TabDeselectedAt(TabContents* contents, int index) {
+ // Save what the user's currently typing, so it can be restored when we
+ // switch back to this tab.
+ window_->GetLocationBar()->SaveStateToContents(contents);
+}
+
void Browser::TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
@@ -1593,12 +1599,6 @@ void Browser::TabSelectedAt(TabContents* old_contents,
if (!chrome_updater_factory_.empty() && old_contents)
ProcessPendingUIUpdates();
- if (old_contents) {
- // Save what the user's currently typing, so it can be restored when we
- // switch back to this tab.
- window_->GetLocationBar()->SaveStateToContents(old_contents);
- }
-
// Propagate the profile to the location bar.
UpdateToolbar(true);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index bb1c136..fb7ea3b 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -445,6 +445,7 @@ class Browser : public TabStripModelDelegate,
bool foreground);
virtual void TabClosingAt(TabContents* contents, int index);
virtual void TabDetachedAt(TabContents* contents, int index);
+ virtual void TabDeselectedAt(TabContents* contents, int index);
virtual void TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index b3f81ca..e0848c2 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -81,14 +81,15 @@ ExtensionBrowserEventRouter* ExtensionBrowserEventRouter::GetInstance() {
return Singleton<ExtensionBrowserEventRouter>::get();
}
-static void DispatchEvent(Profile *profile,
+static void DispatchEvent(Profile* profile,
const char* event_name,
const std::string json_args) {
ExtensionMessageService::GetInstance(profile->GetRequestContext())->
DispatchEventToRenderers(event_name, json_args);
}
-static void DispatchSimpleBrowserEvent(Profile *profile, const int window_id,
+static void DispatchSimpleBrowserEvent(Profile* profile,
+ const int window_id,
const char* event_name) {
ListValue args;
args.Append(Value::CreateIntegerValue(window_id));
@@ -165,7 +166,7 @@ void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents,
ListValue args;
args.Append(Value::CreateIntegerValue(tab_id));
- DictionaryValue *object_args = new DictionaryValue();
+ DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue(
ExtensionTabUtil::GetWindowIdOfTab(contents)));
object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue(
@@ -189,7 +190,7 @@ void ExtensionBrowserEventRouter::TabDetachedAt(TabContents* contents,
ListValue args;
args.Append(Value::CreateIntegerValue(tab_id));
- DictionaryValue *object_args = new DictionaryValue();
+ DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue(
ExtensionTabUtil::GetWindowIdOfTab(contents)));
object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue(
@@ -229,7 +230,7 @@ void ExtensionBrowserEventRouter::TabSelectedAt(TabContents* old_contents,
args.Append(Value::CreateIntegerValue(
ExtensionTabUtil::GetTabId(new_contents)));
- DictionaryValue *object_args = new DictionaryValue();
+ DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
ExtensionTabUtil::GetWindowIdOfTab(new_contents)));
args.Append(object_args);
@@ -247,7 +248,7 @@ void ExtensionBrowserEventRouter::TabMoved(TabContents* contents,
ListValue args;
args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
- DictionaryValue *object_args = new DictionaryValue();
+ DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
ExtensionTabUtil::GetWindowIdOfTab(contents)));
object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue(
@@ -309,15 +310,15 @@ void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents,
void ExtensionBrowserEventRouter::TabStripEmpty() { }
-void ExtensionBrowserEventRouter::PageActionExecuted(Profile *profile,
+void ExtensionBrowserEventRouter::PageActionExecuted(Profile* profile,
std::string page_action_id,
int tab_id,
std::string url) {
ListValue args;
- DictionaryValue *object_args = new DictionaryValue();
+ DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kPageActionIdKey,
Value::CreateStringValue(page_action_id));
- DictionaryValue *data = new DictionaryValue();
+ DictionaryValue* data = new DictionaryValue();
data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id));
data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url));
object_args->Set(tab_keys::kDataKey, data);
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index a818d32..034b2fd 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -49,7 +49,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
void TabStripEmpty();
// PageActions.
- void PageActionExecuted(Profile *profile,
+ void PageActionExecuted(Profile* profile,
std::string page_action_id,
int tab_id,
std::string url);
@@ -64,7 +64,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
// Internal processing of tab updated events. Is called by both TabChangedAt
// and Observe/NAV_ENTRY_COMMITTED.
- void TabUpdated(TabContents *contents, bool did_navigate);
+ void TabUpdated(TabContents* contents, bool did_navigate);
ExtensionBrowserEventRouter();
friend struct DefaultSingletonTraits<ExtensionBrowserEventRouter>;
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index e1a93f3..e5a509f 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -561,9 +561,14 @@ void TabStripModel::ChangeSelectedContentsFrom(
TabContents* new_contents = GetContentsAt(to_index);
if (old_contents == new_contents)
return;
+
TabContents* last_selected_contents = old_contents;
- selected_index_ = to_index;
+ if (last_selected_contents) {
+ FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
+ TabDeselectedAt(last_selected_contents, selected_index_));
+ }
+ selected_index_ = to_index;
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabSelectedAt(last_selected_contents, new_contents, selected_index_,
user_gesture));
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 7f496c8..2431883 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -58,6 +58,11 @@ class TabStripModelObserver {
// action is necessary to deal with the TabContents no longer being present.
virtual void TabDetachedAt(TabContents* contents, int index) { }
+ // The selected TabContents is about to change from |old_contents| at |index|.
+ // This gives observers a chance to prepare for an impending switch before it
+ // happens.
+ virtual void TabDeselectedAt(TabContents* contents, int index) { }
+
// The selected TabContents changed from |old_contents| to |new_contents| at
// |index|. |user_gesture| specifies whether or not this was done by a user
// input event (e.g. clicking on a tab, keystroke) or as a side-effect of
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 339c99c..d32e8b6 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -920,18 +920,20 @@ void BrowserView::TabDetachedAt(TabContents* contents, int index) {
}
}
+void BrowserView::TabDeselectedAt(TabContents* contents, int index) {
+ // We do not store the focus when closing the tab to work-around bug 4633.
+ // Some reports seem to show that the focus manager and/or focused view can
+ // be garbage at that point, it is not clear why.
+ if (!contents->is_being_destroyed())
+ contents->view()->StoreFocus();
+}
+
void BrowserView::TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
bool user_gesture) {
DCHECK(old_contents != new_contents);
- // We do not store the focus when closing the tab to work-around bug 4633.
- // Some reports seem to show that the focus manager and/or focused view can
- // be garbage at that point, it is not clear why.
- if (old_contents && !old_contents->is_being_destroyed())
- old_contents->view()->StoreFocus();
-
// Update various elements that are interested in knowing the current
// TabContents.
infobar_container_->ChangeTabContents(new_contents);
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index 47bf3ed..f4c0983 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -239,6 +239,7 @@ class BrowserView : public BrowserWindow,
// Overridden from TabStripModelObserver:
virtual void TabDetachedAt(TabContents* contents, int index);
+ virtual void TabDeselectedAt(TabContents* contents, int index);
virtual void TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,