Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: chrome/browser/sidebar/sidebar_manager.cc

Issue 6250141: Sidebar mini tabs UI (views version).... Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sidebar/sidebar_manager.h ('k') | chrome/browser/sidebar/sidebar_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sidebar/sidebar_manager.cc
===================================================================
--- chrome/browser/sidebar/sidebar_manager.cc (revision 74134)
+++ chrome/browser/sidebar/sidebar_manager.cc (working copy)
@@ -10,8 +10,9 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_sidebar_api.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sidebar/sidebar_container.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/sidebar/sidebar_container.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
@@ -37,8 +38,27 @@
SidebarManager::SidebarManager() {
}
+// SidebarModel overrides.
+
+std::vector<SidebarContainer*> SidebarManager::GetAllSidebarsFor(
+ TabContentsWrapper* tab) {
+ std::vector<SidebarContainer*> sidebars;
+ TabToSidebarHostMap::const_iterator it = tab_to_sidebar_host_.find(tab);
+ if (it != tab_to_sidebar_host_.end()) {
+ const ContentIdToSidebarHostMap& hosts =
+ it->second.content_id_to_sidebar_host;
+
+ sidebars.reserve(hosts.size());
+ for (ContentIdToSidebarHostMap::const_iterator it = hosts.begin();
+ it != hosts.end(); ++it) {
+ sidebars.push_back(it->second);
+ }
+ }
+ return sidebars;
+}
+
SidebarContainer* SidebarManager::GetActiveSidebarContainerFor(
- TabContents* tab) {
+ TabContentsWrapper* tab) {
TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
if (it == tab_to_sidebar_host_.end())
return NULL;
@@ -51,7 +71,7 @@
}
SidebarContainer* SidebarManager::GetSidebarContainerFor(
- TabContents* tab, const std::string& content_id) {
+ TabContentsWrapper* tab, const std::string& content_id) {
DCHECK(!content_id.empty());
TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
if (it == tab_to_sidebar_host_.end())
@@ -64,7 +84,7 @@
}
TabContents* SidebarManager::GetSidebarTabContents(
- TabContents* tab, const std::string& content_id) {
+ TabContentsWrapper* tab, const std::string& content_id) {
DCHECK(!content_id.empty());
SidebarContainer* sidebar_host = GetSidebarContainerFor(tab, content_id);
if (!sidebar_host)
@@ -88,19 +108,32 @@
if (was_active_host != NULL) {
ExtensionSidebarEventRouter::OnStateChanged(
was_active_sidebar_contents->profile(),
- was_active_host->tab_contents(), was_active_host->content_id(),
+ was_active_host->tab(), was_active_host->content_id(),
extension_sidebar_constants::kShownState);
}
if (active_host != NULL) {
ExtensionSidebarEventRouter::OnStateChanged(
active_sidebar_contents->profile(),
- active_host->tab_contents(), active_host->content_id(),
+ active_host->tab(), active_host->content_id(),
extension_sidebar_constants::kActiveState);
}
}
-void SidebarManager::ShowSidebar(TabContents* tab,
+void SidebarManager::ToggleSidebar(TabContentsWrapper* tab,
+ const std::string& content_id) {
+ DCHECK(!content_id.empty());
+ TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
+ if (it == tab_to_sidebar_host_.end())
+ return;
+ // If it's not active, expand it.
+ if (it->second.active_content_id != content_id)
+ ExpandSidebar(tab, content_id);
+ else
+ CollapseSidebar(tab, content_id);
+}
+
+void SidebarManager::ShowSidebar(TabContentsWrapper* tab,
const std::string& content_id) {
DCHECK(!content_id.empty());
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
@@ -119,7 +152,7 @@
extension_sidebar_constants::kShownState);
}
-void SidebarManager::ExpandSidebar(TabContents* tab,
+void SidebarManager::ExpandSidebar(TabContentsWrapper* tab,
const std::string& content_id) {
DCHECK(!content_id.empty());
TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
@@ -130,7 +163,6 @@
return;
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
- DCHECK(host);
if (!host)
return;
it->second.active_content_id = content_id;
@@ -138,7 +170,7 @@
host->Expand();
}
-void SidebarManager::CollapseSidebar(TabContents* tab,
+void SidebarManager::CollapseSidebar(TabContentsWrapper* tab,
const std::string& content_id) {
DCHECK(!content_id.empty());
TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
@@ -149,7 +181,6 @@
return;
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
- DCHECK(host);
if (!host)
return;
it->second.active_content_id.clear();
@@ -157,7 +188,7 @@
host->Collapse();
}
-void SidebarManager::HideSidebar(TabContents* tab,
+void SidebarManager::HideSidebar(TabContentsWrapper* tab,
const std::string& content_id) {
DCHECK(!content_id.empty());
TabToSidebarHostMap::iterator it = tab_to_sidebar_host_.find(tab);
@@ -167,7 +198,8 @@
it->second.active_content_id.clear();
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
- DCHECK(host);
+ if (!host)
+ return;
UnregisterSidebarContainerFor(tab, content_id);
@@ -176,7 +208,7 @@
extension_sidebar_constants::kHiddenState);
}
-void SidebarManager::NavigateSidebar(TabContents* tab,
+void SidebarManager::NavigateSidebar(TabContentsWrapper* tab,
const std::string& content_id,
const GURL& url) {
DCHECK(!content_id.empty());
@@ -188,7 +220,7 @@
}
void SidebarManager::SetSidebarBadgeText(
- TabContents* tab, const std::string& content_id,
+ TabContentsWrapper* tab, const std::string& content_id,
const string16& badge_text) {
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
if (!host)
@@ -197,7 +229,7 @@
}
void SidebarManager::SetSidebarIcon(
- TabContents* tab, const std::string& content_id,
+ TabContentsWrapper* tab, const std::string& content_id,
const SkBitmap& bitmap) {
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
if (!host)
@@ -206,7 +238,7 @@
}
void SidebarManager::SetSidebarTitle(
- TabContents* tab, const std::string& content_id,
+ TabContentsWrapper* tab, const std::string& content_id,
const string16& title) {
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
if (!host)
@@ -214,29 +246,45 @@
host->SetTitle(title);
}
+// SidebarManager, public.
+
+bool SidebarManager::IsAnySidebarDefinedFor(TabContentsWrapper* tab) {
+ TabToSidebarHostMap::const_iterator it = tab_to_sidebar_host_.find(tab);
+ if (it == tab_to_sidebar_host_.end())
+ return false;
+ return !it->second.content_id_to_sidebar_host.empty();
+}
+
SidebarManager::~SidebarManager() {
DCHECK(tab_to_sidebar_host_.empty());
DCHECK(sidebar_host_to_tab_.empty());
}
+// NotificationObserver overrides.
+
void SidebarManager::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
- HideAllSidebars(Source<TabContents>(source).ptr());
+ TabContents* tab_contents = Source<TabContents>(source).ptr();
+ HideAllSidebars(FindTabContentsWrapperFor(tab_contents));
} else {
NOTREACHED() << "Got a notification we didn't register for!";
}
}
-void SidebarManager::UpdateSidebar(SidebarContainer* host) {
+// SidebarContainer::Delegate overrides.
+
+void SidebarManager::UpdateSidebar(SidebarChangedDetails* details) {
NotificationService::current()->Notify(
NotificationType::SIDEBAR_CHANGED,
Source<SidebarManager>(this),
- Details<SidebarContainer>(host));
+ Details<SidebarChangedDetails>(details));
}
-void SidebarManager::HideAllSidebars(TabContents* tab) {
+// SidebarManager, private.
+
+void SidebarManager::HideAllSidebars(TabContentsWrapper* tab) {
TabToSidebarHostMap::iterator tab_it = tab_to_sidebar_host_.find(tab);
if (tab_it == tab_to_sidebar_host_.end())
return;
@@ -266,22 +314,32 @@
return NULL;
}
+TabContentsWrapper* SidebarManager::FindTabContentsWrapperFor(
+ TabContents* tab_contents) {
+ for (TabToSidebarHostMap::const_iterator it = tab_to_sidebar_host_.begin();
+ it != tab_to_sidebar_host_.end(); ++it) {
+ if (it->first->tab_contents() == tab_contents)
+ return it->first;
+ }
+ return NULL;
+}
+
void SidebarManager::RegisterSidebarContainerFor(
- TabContents* tab, SidebarContainer* sidebar_host) {
+ TabContentsWrapper* tab, SidebarContainer* sidebar_host) {
DCHECK(!GetSidebarContainerFor(tab, sidebar_host->content_id()));
// If it's a first sidebar for this tab, register destroy notification.
if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) {
registrar_.Add(this,
NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab));
+ Source<TabContents>(tab->tab_contents()));
}
BindSidebarHost(tab, sidebar_host);
}
void SidebarManager::UnregisterSidebarContainerFor(
- TabContents* tab, const std::string& content_id) {
+ TabContentsWrapper* tab, const std::string& content_id) {
SidebarContainer* host = GetSidebarContainerFor(tab, content_id);
DCHECK(host);
if (!host)
@@ -293,7 +351,7 @@
if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) {
registrar_.Remove(this,
NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(tab));
+ Source<TabContents>(tab->tab_contents()));
}
// Issue tab closing event post unbound.
@@ -302,7 +360,7 @@
delete host;
}
-void SidebarManager::BindSidebarHost(TabContents* tab,
+void SidebarManager::BindSidebarHost(TabContentsWrapper* tab,
SidebarContainer* sidebar_host) {
const std::string& content_id = sidebar_host->content_id();
@@ -315,7 +373,7 @@
sidebar_host_to_tab_[sidebar_host] = tab;
}
-void SidebarManager::UnbindSidebarHost(TabContents* tab,
+void SidebarManager::UnbindSidebarHost(TabContentsWrapper* tab,
SidebarContainer* sidebar_host) {
const std::string& content_id = sidebar_host->content_id();
« no previous file with comments | « chrome/browser/sidebar/sidebar_manager.h ('k') | chrome/browser/sidebar/sidebar_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698