diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-04 01:36:38 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-04 01:36:38 +0000 |
commit | d3f46ce867559fe47e6ae589f0d03a1bb0ca7e21 (patch) | |
tree | b2af3549dff9e98948f262fffb007d7c0aff5512 | |
parent | 1812f7055141b1f1d2648ae58f489eb5c4fc35b0 (diff) | |
download | chromium_src-d3f46ce867559fe47e6ae589f0d03a1bb0ca7e21.zip chromium_src-d3f46ce867559fe47e6ae589f0d03a1bb0ca7e21.tar.gz chromium_src-d3f46ce867559fe47e6ae589f0d03a1bb0ca7e21.tar.bz2 |
Ensure that only one app in the app list is highlighted at a time.
BUG=176629
Review URL: https://chromiumcodereview.appspot.com/12388041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185824 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/app_list/apps_model_builder.cc | 42 | ||||
-rw-r--r-- | chrome/browser/ui/app_list/apps_model_builder.h | 18 |
2 files changed, 48 insertions, 12 deletions
diff --git a/chrome/browser/ui/app_list/apps_model_builder.cc b/chrome/browser/ui/app_list/apps_model_builder.cc index b318935..850d6a1 100644 --- a/chrome/browser/ui/app_list/apps_model_builder.cc +++ b/chrome/browser/ui/app_list/apps_model_builder.cc @@ -57,6 +57,7 @@ AppsModelBuilder::AppsModelBuilder(Profile* profile, : profile_(profile), controller_(controller), model_(model), + highlighted_app_pending_(false), ignore_changes_(false), tracker_(extensions::InstallTrackerFactory::GetForProfile(profile_)) { tracker_->AddObserver(this); @@ -72,7 +73,7 @@ void AppsModelBuilder::Build() { DCHECK(model_ && model_->item_count() == 0); PopulateApps(); - HighlightApp(); + UpdateHighlight(); // Start observing after model is built. extensions::ExtensionPrefs* extension_prefs = @@ -106,8 +107,7 @@ void AppsModelBuilder::OnBeginExtensionInstall( controller_, extension_name, installing_icon)); - highlight_app_id_ = extension_id; - HighlightApp(); + SetHighlightedApp(extension_id); } void AppsModelBuilder::OnDownloadProgress(const std::string& extension_id, @@ -218,9 +218,34 @@ int AppsModelBuilder::FindApp(const std::string& app_id) { return -1; } -void AppsModelBuilder::HighlightApp() { +void AppsModelBuilder::SetHighlightedApp(const std::string& extension_id) { + if (extension_id == highlight_app_id_) + return; + ExtensionAppItem* old_app = GetApp(highlight_app_id_); + if (old_app) + old_app->SetHighlighted(false); + highlight_app_id_ = extension_id; + ExtensionAppItem* new_app = GetApp(highlight_app_id_); + highlighted_app_pending_ = !new_app; + if (new_app) + new_app->SetHighlighted(true); +} + +ExtensionAppItem* AppsModelBuilder::GetApp( + const std::string& extension_id) { + DCHECK(model_); + if (extension_id.empty()) + return NULL; + + int index = FindApp(highlight_app_id_); + if (index == -1) + return NULL; + return GetAppAt(index); +} + +void AppsModelBuilder::UpdateHighlight() { DCHECK(model_); - if (highlight_app_id_.empty()) + if (!highlighted_app_pending_ || highlight_app_id_.empty()) return; int index = FindApp(highlight_app_id_); @@ -228,7 +253,7 @@ void AppsModelBuilder::HighlightApp() { return; model_->GetItemAt(index)->SetHighlighted(true); - highlight_app_id_.clear(); + highlighted_app_pending_ = false; } ExtensionAppItem* AppsModelBuilder::GetAppAt(size_t index) { @@ -261,7 +286,7 @@ void AppsModelBuilder::Observe(int type, controller_, "", gfx::ImageSkia())); - HighlightApp(); + UpdateHighlight(); break; } case chrome::NOTIFICATION_EXTENSION_UNLOADED: { @@ -283,8 +308,7 @@ void AppsModelBuilder::Observe(int type, break; } case chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST: { - highlight_app_id_ = *content::Details<const std::string>(details).ptr(); - HighlightApp(); + SetHighlightedApp(*content::Details<const std::string>(details).ptr()); break; } default: diff --git a/chrome/browser/ui/app_list/apps_model_builder.h b/chrome/browser/ui/app_list/apps_model_builder.h index ae4a3bc..53a1820 100644 --- a/chrome/browser/ui/app_list/apps_model_builder.h +++ b/chrome/browser/ui/app_list/apps_model_builder.h @@ -72,14 +72,22 @@ class AppsModelBuilder : public content::NotificationObserver, // no match is found, returns -1. int FindApp(const std::string& app_id); + // Sets which app is intended to be highlighted. Will remove the highlight + // from a currently highlighted app. + void SetHighlightedApp(const std::string& extension_id); + // Sets the application app with |highlight_app_id_| in |model_| as - // highlighted. If such an app is found, reset |highlight_app_id_| so that it - // is highlighted once per install notification. - void HighlightApp(); + // highlighted if |highlighted_app_pending_| is true. If such an app is found, + // reset |highlighted_app_pending_| so that won't be highlighted again until + // another call to SetHighlightedApp() is made. + void UpdateHighlight(); // Returns app instance at given |index|. ExtensionAppItem* GetAppAt(size_t index); + // Returns app instance with id |extension_id|. + ExtensionAppItem* GetApp(const std::string& extension_id); + // content::NotificationObserver virtual void Observe(int type, const content::NotificationSource& source, @@ -99,6 +107,10 @@ class AppsModelBuilder : public content::NotificationObserver, std::string highlight_app_id_; + // True if we haven't set |highlight_app_id_| to be highlighted. This happens + // if we try to highlight an app that doesn't exist in the list yet. + bool highlighted_app_pending_; + // True to ignore |model_| changes. bool ignore_changes_; |