summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 00:12:10 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-23 00:12:10 +0000
commit9911cef2305b438052a2bec494f86847e3a8b01e (patch)
tree8ebe947dff47f340efe852486449a286c6b45543 /chrome/browser
parent6c0006dce2f377730a9ee461eb20d6e00e88c3a6 (diff)
downloadchromium_src-9911cef2305b438052a2bec494f86847e3a8b01e.zip
chromium_src-9911cef2305b438052a2bec494f86847e3a8b01e.tar.gz
chromium_src-9911cef2305b438052a2bec494f86847e3a8b01e.tar.bz2
Populate the Linux extension shelf with placeholder labels containing each extension's name.
TEST=none http://crbug.com/16759 Review URL: http://codereview.chromium.org/155957 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21350 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/extension_shelf_gtk.cc105
-rw-r--r--chrome/browser/gtk/extension_shelf_gtk.h25
2 files changed, 108 insertions, 22 deletions
diff --git a/chrome/browser/gtk/extension_shelf_gtk.cc b/chrome/browser/gtk/extension_shelf_gtk.cc
index ff0c449..9befd7d 100644
--- a/chrome/browser/gtk/extension_shelf_gtk.cc
+++ b/chrome/browser/gtk/extension_shelf_gtk.cc
@@ -14,6 +14,55 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+// Preferred height of the ExtensionShelfGtk.
+static const int kShelfHeight = 29;
+
+static const int kToolstripPadding = 2;
+
+class ExtensionShelfGtk::Toolstrip {
+ public:
+ explicit Toolstrip(ExtensionHost* host)
+ : host_(host),
+ extension_name_(host_->extension()->name()) {
+ Init();
+ }
+
+ ~Toolstrip() {
+ label_.Destroy();
+ }
+
+ void AddToolstripToBox(GtkWidget* box);
+ void RemoveToolstripFromBox(GtkWidget* box);
+
+ private:
+ void Init();
+
+ ExtensionHost* host_;
+
+ const std::string extension_name_;
+
+ // Placeholder label with extension's name.
+ // TODO(phajdan.jr): replace the label with rendered extension contents.
+ OwnedWidgetGtk label_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Toolstrip);
+};
+
+void ExtensionShelfGtk::Toolstrip::AddToolstripToBox(GtkWidget* box) {
+ gtk_box_pack_start(GTK_BOX(box), label_.get(), FALSE, FALSE,
+ kToolstripPadding);
+}
+
+void ExtensionShelfGtk::Toolstrip::RemoveToolstripFromBox(GtkWidget* box) {
+ gtk_container_remove(GTK_CONTAINER(box), label_.get());
+}
+
+void ExtensionShelfGtk::Toolstrip::Init() {
+ label_.Own(gtk_label_new(extension_name_.c_str()));
+ gtk_widget_show_all(label_.get());
+}
+
ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser)
: browser_(browser),
theme_provider_(GtkThemeProvider::GetFrom(profile)),
@@ -41,24 +90,37 @@ void ExtensionShelfGtk::Hide() {
gtk_widget_hide(event_box_.get());
}
-void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* toolstrip,
+void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* host,
int index) {
+ Toolstrip* toolstrip = new Toolstrip(host);
+ toolstrip->AddToolstripToBox(shelf_hbox_);
+ toolstrips_.insert(toolstrip);
+ model_->SetToolstripDataAt(index, toolstrip);
+
AdjustHeight();
}
-void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* toolstrip,
+void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* host,
int index) {
+ Toolstrip* toolstrip = ToolstripAtIndex(index);
+ toolstrip->RemoveToolstripFromBox(shelf_hbox_);
+ toolstrips_.erase(toolstrip);
+ model_->SetToolstripDataAt(index, NULL);
+ delete toolstrip;
+
AdjustHeight();
}
-void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* toolstrip,
+void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* host,
int from_index,
int to_index) {
+ // TODO(phajdan.jr): Implement reordering toolstrips.
AdjustHeight();
}
-void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* toolstrip,
+void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* host,
int index) {
+ // TODO(phajdan.jr): Implement changing toolstrips.
AdjustHeight();
}
@@ -67,7 +129,13 @@ void ExtensionShelfGtk::ExtensionShelfEmpty() {
}
void ExtensionShelfGtk::ShelfModelReloaded() {
- AdjustHeight();
+ for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin();
+ iter != toolstrips_.end(); ++iter) {
+ (*iter)->RemoveToolstripFromBox(shelf_hbox_);
+ delete *iter;
+ }
+ toolstrips_.clear();
+ LoadFromModel();
}
void ExtensionShelfGtk::Init(Profile* profile) {
@@ -79,12 +147,7 @@ void ExtensionShelfGtk::Init(Profile* profile) {
G_CALLBACK(&OnHBoxExpose), this);
gtk_container_add(GTK_CONTAINER(event_box_.get()), shelf_hbox_);
- label_ = gtk_label_new("(extension shelf will appear here)");
- gtk_box_pack_start(GTK_BOX(shelf_hbox_), label_,
- TRUE, TRUE, 0);
-
- AdjustHeight();
-
+ LoadFromModel();
model_->AddObserver(this);
}
@@ -108,15 +171,29 @@ void ExtensionShelfGtk::InitBackground() {
}
void ExtensionShelfGtk::AdjustHeight() {
- if (model_->empty()) {
+ if (model_->empty() || toolstrips_.empty()) {
+ // It's possible that |model_| is not empty, but |toolstrips_| are empty
+ // when removing the last toolstrip.
+ DCHECK(toolstrips_.empty());
Hide();
} else {
- gtk_widget_set_size_request(event_box_.get(), -1,
- event_box_->requisition.height);
+ gtk_widget_set_size_request(event_box_.get(), -1, kShelfHeight);
Show();
}
}
+void ExtensionShelfGtk::LoadFromModel() {
+ DCHECK(toolstrips_.empty());
+ int count = model_->count();
+ for (int i = 0; i < count; ++i)
+ ToolstripInsertedAt(model_->ToolstripAt(i), i);
+ AdjustHeight();
+}
+
+ExtensionShelfGtk::Toolstrip* ExtensionShelfGtk::ToolstripAtIndex(int index) {
+ return static_cast<Toolstrip*>(model_->ToolstripDataAt(index));
+}
+
// static
gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget,
GdkEventExpose* event,
diff --git a/chrome/browser/gtk/extension_shelf_gtk.h b/chrome/browser/gtk/extension_shelf_gtk.h
index 849bc90..da2948d 100644
--- a/chrome/browser/gtk/extension_shelf_gtk.h
+++ b/chrome/browser/gtk/extension_shelf_gtk.h
@@ -7,6 +7,8 @@
#include <gtk/gtk.h>
+#include <set>
+
#include "base/scoped_ptr.h"
#include "chrome/browser/extensions/extension_shelf_model.h"
#include "chrome/common/notification_observer.h"
@@ -35,16 +37,18 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver,
void Hide();
// ExtensionShelfModelObserver
- virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index);
- virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index);
- virtual void ToolstripMoved(ExtensionHost* toolstrip,
+ virtual void ToolstripInsertedAt(ExtensionHost* host, int index);
+ virtual void ToolstripRemovingAt(ExtensionHost* host, int index);
+ virtual void ToolstripMoved(ExtensionHost* host,
int from_index,
int to_index);
- virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index);
+ virtual void ToolstripChangedAt(ExtensionHost* host, int index);
virtual void ExtensionShelfEmpty();
virtual void ShelfModelReloaded();
private:
+ class Toolstrip;
+
// Create the contents of the extension shelf.
void Init(Profile* profile);
@@ -59,6 +63,10 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver,
// Determines what is our target height and sets it.
void AdjustHeight();
+ void LoadFromModel();
+
+ Toolstrip* ToolstripAtIndex(int index);
+
// GtkHBox callbacks.
static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event,
ExtensionShelfGtk* window);
@@ -72,10 +80,6 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver,
// Used to position all children.
GtkWidget* shelf_hbox_;
- // Label for placeholder text.
- // TODO(phajdan.jr): Remove the placeholder label when we have real contents.
- GtkWidget* label_;
-
GtkThemeProvider* theme_provider_;
// Paints the background for our bookmark bar.
@@ -85,6 +89,11 @@ class ExtensionShelfGtk : public ExtensionShelfModelObserver,
// The model representing the toolstrips on the shelf.
scoped_ptr<ExtensionShelfModel> model_;
+
+ // Set of toolstrip views which are really on the shelf.
+ std::set<Toolstrip*> toolstrips_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionShelfGtk);
};
#endif // CHROME_BROWSER_EXTENSION_SHELF_GTK_H_