diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 22:18:50 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 22:18:50 +0000 |
commit | 9521c61f5588480d8cd6134144db7137630f2529 (patch) | |
tree | 74c0458f3d5b3dedfac7baf68b7e440e8bd6b542 /chrome/browser | |
parent | 128740bbcd5abb0c75254e6eb57b46192c1f47d1 (diff) | |
download | chromium_src-9521c61f5588480d8cd6134144db7137630f2529.zip chromium_src-9521c61f5588480d8cd6134144db7137630f2529.tar.gz chromium_src-9521c61f5588480d8cd6134144db7137630f2529.tar.bz2 |
Begin work on extension shelf for Linux.
For now it displays only a placeholder text, but knows when to display (it's connected to the ExtensionShelfModel).
TEST=none
http://crbug.com/16759
Review URL: http://codereview.chromium.org/159019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 23 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_shelf_gtk.cc | 131 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_shelf_gtk.h | 90 |
5 files changed, 253 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index dd46e07..21acf4f 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -108,6 +108,8 @@ void ExtensionHost::CreateView(Browser* browser) { // We own |view_|, so don't auto delete when it's removed from the view // hierarchy. view_->SetParentOwned(false); +#elif defined(OS_LINUX) + // FIXME(phajdan.jr): Add extension view for GTK. #else // TODO(port) NOTREACHED(); diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index c4d5299..2505733 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -36,6 +36,7 @@ #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" #include "chrome/browser/gtk/download_shelf_gtk.h" #include "chrome/browser/gtk/edit_search_engine_dialog.h" +#include "chrome/browser/gtk/extension_shelf_gtk.h" #include "chrome/browser/gtk/find_bar_gtk.h" #include "chrome/browser/gtk/go_button_gtk.h" #include "chrome/browser/gtk/gtk_theme_provider.h" @@ -647,10 +648,11 @@ void BrowserWindowGtk::SetFullscreen(bool fullscreen) { UpdateCustomFrame(); if (fullscreen) { - // These three balanced by ShowSupportedWindowFeatures(). + // These four balanced by ShowSupportedWindowFeatures(). toolbar_->Hide(); tabstrip_->Hide(); bookmark_bar_->Hide(false); + extension_shelf_->Hide(); gtk_window_fullscreen(window_); } else { @@ -906,6 +908,10 @@ void BrowserWindowGtk::MaybeShowBookmarkBar(TabContents* contents, } } +void BrowserWindowGtk::MaybeShowExtensionShelf() { + extension_shelf_->Show(); +} + void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { TabContents* old_devtools = devtools_container_->GetTabContents(); if (old_devtools) @@ -1101,6 +1107,11 @@ void BrowserWindowGtk::InitWidgets() { this)); bookmark_bar_->AddBookmarkbarToBox(content_vbox_); + extension_shelf_.reset(new ExtensionShelfGtk(browser()->profile(), + browser_.get())); + extension_shelf_->AddShelfToBox(content_vbox_); + MaybeShowExtensionShelf(); + // This vbox surrounds the render area: find bar, info bars and render view. // The reason is that this area as a whole needs to be grouped in its own // GdkWindow hierarchy so that animations originating inside it (infobar, @@ -1400,6 +1411,9 @@ void BrowserWindowGtk::ShowSupportedWindowFeatures() { if (IsBookmarkBarSupported()) MaybeShowBookmarkBar(browser_->GetSelectedTabContents(), false); + + if (IsExtensionShelfSupported()) + MaybeShowExtensionShelf(); } void BrowserWindowGtk::HideUnsupportedWindowFeatures() { @@ -1411,6 +1425,9 @@ void BrowserWindowGtk::HideUnsupportedWindowFeatures() { if (!IsBookmarkBarSupported()) bookmark_bar_->Hide(false); + + if (!IsExtensionShelfSupported()) + extension_shelf_->Hide(); } bool BrowserWindowGtk::IsTabStripSupported() { @@ -1426,6 +1443,10 @@ bool BrowserWindowGtk::IsBookmarkBarSupported() { return browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR); } +bool BrowserWindowGtk::IsExtensionShelfSupported() { + return browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF); +} + bool BrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { if (!use_custom_frame_.GetValue()) return false; diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index a5239c3..f17e2b4 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -25,6 +25,7 @@ class BrowserTitlebar; class BrowserToolbarGtk; class CustomDrawButton; class DownloadShelfGtk; +class ExtensionShelfGtk; class FindBarGtk; class InfoBarContainerGtk; class LocationBar; @@ -179,6 +180,9 @@ class BrowserWindowGtk : public BrowserWindow, // Show or hide the bookmark bar. void MaybeShowBookmarkBar(TabContents* contents, bool animate); + // Show or hide the extension shelf. + void MaybeShowExtensionShelf(); + // Sets the default size for the window and the the way the user is allowed to // resize it. void SetGeometryHints(); @@ -251,6 +255,7 @@ class BrowserWindowGtk : public BrowserWindow, bool IsTabStripSupported(); bool IsToolbarSupported(); bool IsBookmarkBarSupported(); + bool IsExtensionShelfSupported(); // Checks to see if the mouse pointer at |x|, |y| is over the border of the // custom frame (a spot that should trigger a window resize). Returns true if @@ -275,6 +280,9 @@ class BrowserWindowGtk : public BrowserWindow, // The object that manages the bookmark bar. scoped_ptr<BookmarkBarGtk> bookmark_bar_; + // The object that manages the extension shelf. + scoped_ptr<ExtensionShelfGtk> extension_shelf_; + // The status bubble manager. Always non-NULL. scoped_ptr<StatusBubbleGtk> status_bubble_; diff --git a/chrome/browser/gtk/extension_shelf_gtk.cc b/chrome/browser/gtk/extension_shelf_gtk.cc new file mode 100644 index 0000000..5ae0c9c --- /dev/null +++ b/chrome/browser/gtk/extension_shelf_gtk.cc @@ -0,0 +1,131 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/gtk/extension_shelf_gtk.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/gtk/browser_window_gtk.h" +#include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/browser/gtk/nine_box.h" +#include "chrome/browser/profile.h" +#include "chrome/common/notification_service.h" +#include "grit/app_resources.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" + +ExtensionShelfGtk::ExtensionShelfGtk(Profile* profile, Browser* browser) + : browser_(browser), + theme_provider_(GtkThemeProvider::GetFrom(profile)), + model_(new ExtensionShelfModel(browser)) { + Init(profile); + + registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, + NotificationService::AllSources()); +} + +ExtensionShelfGtk::~ExtensionShelfGtk() { + model_->RemoveObserver(this); + event_box_.Destroy(); +} + +void ExtensionShelfGtk::AddShelfToBox(GtkWidget* box) { + gtk_box_pack_end(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); +} + +void ExtensionShelfGtk::Show() { + gtk_widget_show_all(event_box_.get()); +} + +void ExtensionShelfGtk::Hide() { + gtk_widget_hide(event_box_.get()); +} + +void ExtensionShelfGtk::ToolstripInsertedAt(ExtensionHost* toolstrip, + int index) { + AdjustHeight(); +} + +void ExtensionShelfGtk::ToolstripRemovingAt(ExtensionHost* toolstrip, + int index) { + AdjustHeight(); +} + +void ExtensionShelfGtk::ToolstripMoved(ExtensionHost* toolstrip, + int from_index, + int to_index) { + AdjustHeight(); +} + +void ExtensionShelfGtk::ToolstripChangedAt(ExtensionHost* toolstrip, + int index) { + AdjustHeight(); +} + +void ExtensionShelfGtk::ExtensionShelfEmpty() { + AdjustHeight(); +} + +void ExtensionShelfGtk::ShelfModelReloaded() { + AdjustHeight(); +} + +void ExtensionShelfGtk::Init(Profile* profile) { + event_box_.Own(gtk_event_box_new()); + + shelf_hbox_ = gtk_hbox_new(FALSE, 0); + gtk_widget_set_app_paintable(shelf_hbox_, TRUE); + g_signal_connect(G_OBJECT(shelf_hbox_), "expose-event", + 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(); + + model_->AddObserver(this); +} + +void ExtensionShelfGtk::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::BROWSER_THEME_CHANGED) { + // TODO(phajdan.jr): Handle theme changes. + } else { + NOTREACHED() << "unexpected notification"; + } +} + +void ExtensionShelfGtk::InitBackground() { + if (background_ninebox_.get()) + return; + + background_ninebox_.reset(new NineBox( + browser_->profile()->GetThemeProvider(), + 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); +} + +void ExtensionShelfGtk::AdjustHeight() { + int target_height = model_->empty() ? 0 : event_box_->requisition.height; + gtk_widget_set_size_request(event_box_.get(), -1, target_height); +} + +// static +gboolean ExtensionShelfGtk::OnHBoxExpose(GtkWidget* widget, + GdkEventExpose* event, + ExtensionShelfGtk* bar) { + // Paint the background theme image. + cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); + cairo_rectangle(cr, event->area.x, event->area.y, + event->area.width, event->area.height); + cairo_clip(cr); + bar->InitBackground(); + bar->background_ninebox_->RenderTopCenterStrip( + cr, event->area.x, event->area.y, + event->area.x + event->area.width); + cairo_destroy(cr); + + return FALSE; // Propagate expose to children. +} diff --git a/chrome/browser/gtk/extension_shelf_gtk.h b/chrome/browser/gtk/extension_shelf_gtk.h new file mode 100644 index 0000000..849bc90 --- /dev/null +++ b/chrome/browser/gtk/extension_shelf_gtk.h @@ -0,0 +1,90 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_ +#define CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_ + +#include <gtk/gtk.h> + +#include "base/scoped_ptr.h" +#include "chrome/browser/extensions/extension_shelf_model.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/owned_widget_gtk.h" + +class Browser; +class BrowserWindowGtk; +class CustomContainerButton; +class NineBox; +class Profile; +struct GtkThemeProvider; + +class ExtensionShelfGtk : public ExtensionShelfModelObserver, + public NotificationObserver { + public: + ExtensionShelfGtk(Profile* profile, Browser* browser); + virtual ~ExtensionShelfGtk(); + + // Adds this GTK shelf into a sizing box. + void AddShelfToBox(GtkWidget* box); + + // Change the visibility of the bookmarks bar. (Starts out hidden, per GTK's + // default behaviour). + void Show(); + void Hide(); + + // ExtensionShelfModelObserver + virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index); + virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index); + virtual void ToolstripMoved(ExtensionHost* toolstrip, + int from_index, + int to_index); + virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index); + virtual void ExtensionShelfEmpty(); + virtual void ShelfModelReloaded(); + + private: + // Create the contents of the extension shelf. + void Init(Profile* profile); + + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Loads the background image into memory, or does nothing if already loaded. + void InitBackground(); + + // Determines what is our target height and sets it. + void AdjustHeight(); + + // GtkHBox callbacks. + static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event, + ExtensionShelfGtk* window); + + Browser* browser_; + + // Contains |shelf_hbox_|. Event box exists to prevent leakage of + // background color from the toplevel application window's GDK window. + OwnedWidgetGtk event_box_; + + // 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. + scoped_ptr<NineBox> background_ninebox_; + + NotificationRegistrar registrar_; + + // The model representing the toolstrips on the shelf. + scoped_ptr<ExtensionShelfModel> model_; +}; + +#endif // CHROME_BROWSER_EXTENSION_SHELF_GTK_H_ |