From a0f36540508a708492a2b3a2982109fd1887983d Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Tue, 22 Mar 2011 15:42:29 +0000 Subject: gtk: Move extension_infobar_gtk.[cc,h] into the ui/gtk/infobars/ directory. BUG=None TEST=None R=aa@chromium.org Review URL: http://codereview.chromium.org/6685034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78984 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/ui/gtk/extension_infobar_gtk.cc | 93 ---------------------- chrome/browser/ui/gtk/extension_infobar_gtk.h | 50 ------------ .../ui/gtk/infobars/extension_infobar_gtk.cc | 93 ++++++++++++++++++++++ .../ui/gtk/infobars/extension_infobar_gtk.h | 50 ++++++++++++ chrome/chrome_browser.gypi | 4 +- 5 files changed, 145 insertions(+), 145 deletions(-) delete mode 100644 chrome/browser/ui/gtk/extension_infobar_gtk.cc delete mode 100644 chrome/browser/ui/gtk/extension_infobar_gtk.h create mode 100644 chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc create mode 100644 chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h (limited to 'chrome') diff --git a/chrome/browser/ui/gtk/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/extension_infobar_gtk.cc deleted file mode 100644 index 6db9ab6..0000000 --- a/chrome/browser/ui/gtk/extension_infobar_gtk.cc +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2011 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/ui/gtk/extension_infobar_gtk.h" - -#include "chrome/browser/extensions/extension_host.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_icon_set.h" -#include "chrome/common/extensions/extension_resource.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/renderer_host/render_widget_host_view.h" -#include "grit/theme_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/gtk_util.h" - -ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate) - : InfoBar(delegate), - tracker_(this), - delegate_(delegate), - view_(NULL) { - delegate_->extension_host()->view()->SetContainer(this); - BuildWidgets(); -} - -ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { - // This view is not owned by us, so unparent. - gtk_widget_unparent(view_->native_view()); -} - -void ExtensionInfoBarGtk::OnImageLoaded( - SkBitmap* image, const ExtensionResource& resource, int index) { - if (!delegate_) - return; // The delegate can go away while we asynchronously load images. - - // ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - // - // SkBitmap* icon; - // if (!image || image->empty()) - // icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); - // else - // icon = image; - // TODO(finnur): Use the above code. - // We now have the icon for the menu button, show the menu button and layout. -} - -void ExtensionInfoBarGtk::BuildWidgets() { - // Start loading the image for the menu button. - const Extension* extension = delegate_->extension_host()->extension(); - ExtensionResource icon_resource = extension->GetIconResource( - Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); - if (!icon_resource.relative_path().empty()) { - // Create a tracker to load the image. It will report back on OnImageLoaded. - tracker_.LoadImage(extension, icon_resource, - gfx::Size(Extension::EXTENSION_ICON_BITTY, - Extension::EXTENSION_ICON_BITTY), - ImageLoadingTracker::DONT_CACHE); - } else { - OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. - } - - ExtensionHost* extension_host = delegate_->extension_host(); - view_ = extension_host->view(); - if (gtk_widget_get_parent(view_->native_view())) { - gtk_widget_reparent(view_->native_view(), hbox_); - gtk_box_set_child_packing(GTK_BOX(hbox_), view_->native_view(), - TRUE, TRUE, 0, GTK_PACK_START); - } else { - gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0); - } - - g_signal_connect(view_->native_view(), "size_allocate", - G_CALLBACK(&OnSizeAllocateThunk), this); -} - -void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation) { - gfx::Size new_size(allocation->width, allocation->height); - - delegate_->extension_host()->view()->render_view_host()->view() - ->SetSize(new_size); -} - -void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged( - ExtensionViewGtk* view, - const gfx::Size& new_size) { - // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size - // of the content. -} - -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { - return new ExtensionInfoBarGtk(this); -} diff --git a/chrome/browser/ui/gtk/extension_infobar_gtk.h b/chrome/browser/ui/gtk/extension_infobar_gtk.h deleted file mode 100644 index 9c90955..0000000 --- a/chrome/browser/ui/gtk/extension_infobar_gtk.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2011 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_UI_GTK_EXTENSION_INFOBAR_GTK_H_ -#define CHROME_BROWSER_UI_GTK_EXTENSION_INFOBAR_GTK_H_ -#pragma once - -#include "chrome/browser/extensions/extension_infobar_delegate.h" -#include "chrome/browser/extensions/image_loading_tracker.h" -#include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" -#include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" -#include "ui/gfx/gtk_util.h" - -class ExtensionInfobarDelegate; -class ExtensionResource; -class ExtensionViewGtk; - -class ExtensionInfoBarGtk : public InfoBar, - public ImageLoadingTracker::Observer, - public ExtensionViewGtk::Container { - public: - explicit ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate); - virtual ~ExtensionInfoBarGtk(); - - // Overridden from ImageLoadingTracker::Observer: - virtual void OnImageLoaded( - SkBitmap* image, const ExtensionResource& resource, int index); - - // ExtensionViewGtk::Container implementation - virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view, - const gfx::Size& new_size); - - private: - // Build the widgets of the Infobar. - void BuildWidgets(); - - CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, void, OnSizeAllocate, - GtkAllocation*); - - ImageLoadingTracker tracker_; - - ExtensionInfoBarDelegate* delegate_; - - ExtensionViewGtk* view_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_EXTENSION_INFOBAR_GTK_H_ diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc new file mode 100644 index 0000000..6e2bcd0 --- /dev/null +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2011 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/ui/gtk/infobars/extension_infobar_gtk.h" + +#include "chrome/browser/extensions/extension_host.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_icon_set.h" +#include "chrome/common/extensions/extension_resource.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/renderer_host/render_widget_host_view.h" +#include "grit/theme_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/gtk_util.h" + +ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate) + : InfoBar(delegate), + tracker_(this), + delegate_(delegate), + view_(NULL) { + delegate_->extension_host()->view()->SetContainer(this); + BuildWidgets(); +} + +ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { + // This view is not owned by us, so unparent. + gtk_widget_unparent(view_->native_view()); +} + +void ExtensionInfoBarGtk::OnImageLoaded( + SkBitmap* image, const ExtensionResource& resource, int index) { + if (!delegate_) + return; // The delegate can go away while we asynchronously load images. + + // ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + // + // SkBitmap* icon; + // if (!image || image->empty()) + // icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); + // else + // icon = image; + // TODO(finnur): Use the above code. + // We now have the icon for the menu button, show the menu button and layout. +} + +void ExtensionInfoBarGtk::BuildWidgets() { + // Start loading the image for the menu button. + const Extension* extension = delegate_->extension_host()->extension(); + ExtensionResource icon_resource = extension->GetIconResource( + Extension::EXTENSION_ICON_BITTY, ExtensionIconSet::MATCH_EXACTLY); + if (!icon_resource.relative_path().empty()) { + // Create a tracker to load the image. It will report back on OnImageLoaded. + tracker_.LoadImage(extension, icon_resource, + gfx::Size(Extension::EXTENSION_ICON_BITTY, + Extension::EXTENSION_ICON_BITTY), + ImageLoadingTracker::DONT_CACHE); + } else { + OnImageLoaded(NULL, icon_resource, 0); // |image|, |index|. + } + + ExtensionHost* extension_host = delegate_->extension_host(); + view_ = extension_host->view(); + if (gtk_widget_get_parent(view_->native_view())) { + gtk_widget_reparent(view_->native_view(), hbox_); + gtk_box_set_child_packing(GTK_BOX(hbox_), view_->native_view(), + TRUE, TRUE, 0, GTK_PACK_START); + } else { + gtk_box_pack_start(GTK_BOX(hbox_), view_->native_view(), TRUE, TRUE, 0); + } + + g_signal_connect(view_->native_view(), "size_allocate", + G_CALLBACK(&OnSizeAllocateThunk), this); +} + +void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) { + gfx::Size new_size(allocation->width, allocation->height); + + delegate_->extension_host()->view()->render_view_host()->view() + ->SetSize(new_size); +} + +void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged( + ExtensionViewGtk* view, + const gfx::Size& new_size) { + // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size + // of the content. +} + +InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() { + return new ExtensionInfoBarGtk(this); +} diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h new file mode 100644 index 0000000..b6ed70f --- /dev/null +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h @@ -0,0 +1,50 @@ +// Copyright (c) 2011 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_UI_GTK_INFOBARS_EXTENSION_INFOBAR_GTK_H_ +#define CHROME_BROWSER_UI_GTK_INFOBARS_EXTENSION_INFOBAR_GTK_H_ +#pragma once + +#include "chrome/browser/extensions/extension_infobar_delegate.h" +#include "chrome/browser/extensions/image_loading_tracker.h" +#include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" +#include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" +#include "ui/gfx/gtk_util.h" + +class ExtensionInfobarDelegate; +class ExtensionResource; +class ExtensionViewGtk; + +class ExtensionInfoBarGtk : public InfoBar, + public ImageLoadingTracker::Observer, + public ExtensionViewGtk::Container { + public: + explicit ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate); + virtual ~ExtensionInfoBarGtk(); + + // Overridden from ImageLoadingTracker::Observer: + virtual void OnImageLoaded( + SkBitmap* image, const ExtensionResource& resource, int index); + + // ExtensionViewGtk::Container implementation + virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view, + const gfx::Size& new_size); + + private: + // Build the widgets of the Infobar. + void BuildWidgets(); + + CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, void, OnSizeAllocate, + GtkAllocation*); + + ImageLoadingTracker tracker_; + + ExtensionInfoBarDelegate* delegate_; + + ExtensionViewGtk* view_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarGtk); +}; + +#endif // CHROME_BROWSER_UI_GTK_INFOBARS_EXTENSION_INFOBAR_GTK_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8cf7caa..21789e6 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2551,8 +2551,6 @@ 'browser/ui/gtk/download_started_animation_gtk.cc', 'browser/ui/gtk/edit_search_engine_dialog.cc', 'browser/ui/gtk/edit_search_engine_dialog.h', - 'browser/ui/gtk/extension_infobar_gtk.cc', - 'browser/ui/gtk/extension_infobar_gtk.h', 'browser/ui/gtk/extensions/extension_install_prompt2_gtk.cc', 'browser/ui/gtk/extensions/extension_install_prompt_gtk.cc', 'browser/ui/gtk/extensions/extension_installed_bubble_gtk.cc', @@ -2612,6 +2610,8 @@ 'browser/ui/gtk/info_bubble_gtk.h', 'browser/ui/gtk/infobars/confirm_infobar_gtk.cc', 'browser/ui/gtk/infobars/confirm_infobar_gtk.h', + 'browser/ui/gtk/infobars/extension_infobar_gtk.cc', + 'browser/ui/gtk/infobars/extension_infobar_gtk.h', 'browser/ui/gtk/infobars/infobar_arrow_model.cc', 'browser/ui/gtk/infobars/infobar_arrow_model.h', 'browser/ui/gtk/infobars/infobar_container_gtk.cc', -- cgit v1.1