diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 20:56:49 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 20:56:49 +0000 |
commit | 3676406485fd9d45aad8f9ed52b390c0c093b684 (patch) | |
tree | d9e66d45dedb69dc256643628b82b3e594f477a6 /chrome/browser/chromeos | |
parent | 259809616c917c440816b8637e2fbc066fc00eb6 (diff) | |
download | chromium_src-3676406485fd9d45aad8f9ed52b390c0c093b684.zip chromium_src-3676406485fd9d45aad8f9ed52b390c0c093b684.tar.gz chromium_src-3676406485fd9d45aad8f9ed52b390c0c093b684.tar.bz2 |
Adds the ability for script to resize the menu.
BUG=23261
TEST=none
Review URL: http://codereview.chromium.org/249020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/main_menu.cc | 40 | ||||
-rw-r--r-- | chrome/browser/chromeos/main_menu.h | 5 |
2 files changed, 39 insertions, 6 deletions
diff --git a/chrome/browser/chromeos/main_menu.cc b/chrome/browser/chromeos/main_menu.cc index 0b80e3b..5d57217 100644 --- a/chrome/browser/chromeos/main_menu.cc +++ b/chrome/browser/chromeos/main_menu.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/main_menu.h" +#include "app/gfx/insets.h" #include "app/resource_bundle.h" #include "base/message_loop.h" #include "chrome/browser/browser.h" @@ -17,14 +18,26 @@ #include "grit/app_resources.h" #include "grit/generated_resources.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "views/controls/image_view.h" +#include "views/background.h" +#include "views/painter.h" +#include "views/widget/root_view.h" #include "views/widget/widget_gtk.h" +// Initial size of the renderer. This is contained within a window whose size +// is set to the size of the image IDR_MAIN_MENU_BUTTON_DROP_DOWN. static const int kRendererX = 0; static const int kRendererY = 25; static const int kRendererWidth = 250; static const int kRendererHeight = 400; +// Insets defining the regions that are stretched and titled to create the +// background of the popup. These constants are fed into +// Painter::CreateImagePainter as the insets, see it for details. +static const int kBackgroundImageTop = 27; +static const int kBackgroundImageLeft = 85; +static const int kBackgroundImageBottom = 10; +static const int kBackgroundImageRight = 8; + // URL of the page to load. static const char kMenuURL[] = "http://goto.ext.google.com/crux-menu"; @@ -50,8 +63,6 @@ MainMenu::MainMenu(Browser* browser) void MainMenu::ShowImpl() { SkBitmap* drop_down_image = ResourceBundle::GetSharedInstance(). GetBitmapNamed(IDR_MAIN_MENU_BUTTON_DROP_DOWN); - views::ImageView* background_view = new views::ImageView(); - background_view->SetImage(drop_down_image); views::WidgetGtk* menu_popup = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP); @@ -61,7 +72,12 @@ void MainMenu::ShowImpl() { menu_popup->Init(NULL, gfx::Rect(0, 0, drop_down_image->width(), drop_down_image->height())); - menu_popup->SetContentsView(background_view); + views::Painter* painter = views::Painter::CreateImagePainter( + *drop_down_image, + gfx::Insets(kBackgroundImageTop, kBackgroundImageLeft, + kBackgroundImageBottom, kBackgroundImageRight)); + menu_popup->GetRootView()->set_background( + views::Background::CreateBackgroundPainter(true, painter)); GURL menu_url(kMenuURL); site_instance_ = SiteInstance::CreateSiteInstanceForURL(browser_->profile(), @@ -124,6 +140,22 @@ gboolean MainMenu::OnButtonPressEvent(GtkWidget* widget, return FALSE; } +void MainMenu::RequestMove(const gfx::Rect& new_bounds) { + SkBitmap* drop_down_image = ResourceBundle::GetSharedInstance(). + GetBitmapNamed(IDR_MAIN_MENU_BUTTON_DROP_DOWN); + int new_w = drop_down_image->width() + (new_bounds.width() - kRendererWidth); + int new_h = drop_down_image->height() + + (new_bounds.height() - kRendererHeight); + // Invoking PositionChild results in a gtk signal that triggers attempting to + // to resize the window. We need to set the size request so that it resizes + // correctly when this happens. + gtk_widget_set_size_request(popup_->GetNativeView(), new_w, new_h); + popup_->PositionChild(rwhv_->GetNativeView(), kRendererX, kRendererY, + new_bounds.width(), new_bounds.height()); + popup_->SetBounds(gfx::Rect(0, 0, new_w, new_h)); + rwhv_->SetSize(new_bounds.size()); +} + void MainMenu::CreateNewWindow(int route_id, base::WaitableEvent* modal_dialog_event) { if (pending_contents_.get()) { diff --git a/chrome/browser/chromeos/main_menu.h b/chrome/browser/chromeos/main_menu.h index acb6fed..0f4f257 100644 --- a/chrome/browser/chromeos/main_menu.h +++ b/chrome/browser/chromeos/main_menu.h @@ -17,7 +17,7 @@ class RenderWidgetHostViewGtk; class SiteInstance; namespace views { -class Widget; +class WidgetGtk; } // MainMenu manages showing the main menu. The menu is currently an HTML page. @@ -114,6 +114,7 @@ class MainMenu : public RenderViewHostDelegate, virtual RenderViewHostDelegate::View* GetViewDelegate() { return this; } + virtual void RequestMove(const gfx::Rect& new_bounds); // RenderViewHostDelegate::View overrides. virtual void CreateNewWindow(int route_id, @@ -141,7 +142,7 @@ class MainMenu : public RenderViewHostDelegate, Browser* browser_; // The widget displaying the rwvh_. - views::Widget* popup_; + views::WidgetGtk* popup_; // SiteInstance for the RenderViewHosts we create. SiteInstance* site_instance_; |