| Index: chrome/browser/chromeos/main_menu.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/main_menu.cc (revision 28002)
|
| +++ chrome/browser/chromeos/main_menu.cc (working copy)
|
| @@ -4,9 +4,13 @@
|
|
|
| #include "chrome/browser/chromeos/main_menu.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "app/gfx/insets.h"
|
| #include "app/resource_bundle.h"
|
| +#include "base/command_line.h"
|
| #include "base/message_loop.h"
|
| +#include "base/string_util.h"
|
| #include "chrome/browser/browser.h"
|
| #include "chrome/browser/renderer_host/render_view_host.h"
|
| #include "chrome/browser/renderer_host/render_view_host_factory.h"
|
| @@ -20,6 +24,7 @@
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "views/background.h"
|
| #include "views/painter.h"
|
| +#include "views/screen.h"
|
| #include "views/widget/root_view.h"
|
| #include "views/widget/widget_gtk.h"
|
|
|
| @@ -38,9 +43,53 @@
|
| static const int kBackgroundImageBottom = 10;
|
| static const int kBackgroundImageRight = 8;
|
|
|
| -// URL of the page to load.
|
| +// Command line switch for specifying url of the page.
|
| +static const wchar_t kURLSwitch[] = L"main-menu-url";
|
| +
|
| +// Command line switch for specifying the size of the main menu. The default is
|
| +// full screen.
|
| +static const wchar_t kMenuSizeSwitch[] = L"main-menu-size";
|
| +
|
| +// URL of the page to load. This is ignored if kURLSwitch is specified.
|
| static const char kMenuURL[] = "http://goto.ext.google.com/crux-menu";
|
|
|
| +// Returns the size of the popup. By default the popup is sized slightly
|
| +// larger than full screen, but can be overriden by the command line switch
|
| +// kMenuSizeSwitch.
|
| +static gfx::Size GetPopupSize() {
|
| + std::wstring cl_size =
|
| + CommandLine::ForCurrentProcess()->GetSwitchValue(kMenuSizeSwitch);
|
| + if (!cl_size.empty()) {
|
| + std::vector<std::string> chunks;
|
| + SplitString(WideToUTF8(cl_size), 'x', &chunks);
|
| + if (chunks.size() == 2)
|
| + return gfx::Size(StringToInt(chunks[0]), StringToInt(chunks[1]));
|
| + }
|
| +
|
| + gfx::Size size =
|
| + views::Screen::GetMonitorAreaNearestPoint(gfx::Point(0, 0)).size();
|
| + // When full screen we don't want to see the drop shadow. Adjust the width
|
| + // so the drop shadow ends up off screen.
|
| + size.Enlarge(kBackgroundImageRight, kBackgroundImageBottom);
|
| + return size;
|
| +}
|
| +
|
| +// Returns the size for the renderer widget host view given the specified
|
| +// size of the popup.
|
| +static gfx::Size CalculateRWHVSize(const gfx::Size& popup_size) {
|
| + return gfx::Size(popup_size.width() - kRendererX - kBackgroundImageRight,
|
| + popup_size.height() - kRendererY - kBackgroundImageBottom);
|
| +}
|
| +
|
| +// Returns the URL of the menu.
|
| +static GURL GetMenuURL() {
|
| + std::wstring url_string =
|
| + CommandLine::ForCurrentProcess()->GetSwitchValue(kURLSwitch);
|
| + if (!url_string.empty())
|
| + return GURL(WideToUTF8(url_string));
|
| + return GURL(kMenuURL);
|
| +}
|
| +
|
| // static
|
| void MainMenu::Show(Browser* browser) {
|
| (new MainMenu(browser))->ShowImpl();
|
| @@ -69,8 +118,9 @@
|
| popup_ = menu_popup;
|
| // The background image has transparency, so we make the window transparent.
|
| menu_popup->MakeTransparent();
|
| - menu_popup->Init(NULL, gfx::Rect(0, 0, drop_down_image->width(),
|
| - drop_down_image->height()));
|
| + gfx::Size popup_size = GetPopupSize();
|
| + menu_popup->Init(NULL, gfx::Rect(0, 0, popup_size.width(),
|
| + popup_size.height()));
|
|
|
| views::Painter* painter = views::Painter::CreateImagePainter(
|
| *drop_down_image,
|
| @@ -79,7 +129,7 @@
|
| menu_popup->GetRootView()->set_background(
|
| views::Background::CreateBackgroundPainter(true, painter));
|
|
|
| - GURL menu_url(kMenuURL);
|
| + GURL menu_url(GetMenuURL());
|
| site_instance_ = SiteInstance::CreateSiteInstanceForURL(browser_->profile(),
|
| menu_url);
|
| menu_rvh_ = new RenderViewHost(site_instance_, this, MSG_ROUTING_NONE);
|
| @@ -88,9 +138,10 @@
|
| rwhv_->InitAsChild();
|
| menu_rvh_->CreateRenderView();
|
| menu_popup->AddChild(rwhv_->GetNativeView());
|
| + gfx::Size rwhv_size = CalculateRWHVSize(popup_size);
|
| menu_popup->PositionChild(rwhv_->GetNativeView(), kRendererX, kRendererY,
|
| - kRendererWidth, kRendererHeight);
|
| - rwhv_->SetSize(gfx::Size(kRendererWidth, kRendererHeight));
|
| + rwhv_size.width(), rwhv_size.height());
|
| + rwhv_->SetSize(rwhv_size);
|
| menu_rvh_->NavigateToURL(menu_url);
|
| menu_popup->Show();
|
|
|
| @@ -141,19 +192,16 @@
|
| }
|
|
|
| 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);
|
| + gtk_widget_set_size_request(popup_->GetNativeView(),
|
| + new_bounds.width(), new_bounds.height());
|
| + gfx::Size rwhv_size = CalculateRWHVSize(new_bounds.size());
|
| popup_->PositionChild(rwhv_->GetNativeView(), kRendererX, kRendererY,
|
| - new_bounds.width(), new_bounds.height());
|
| - popup_->SetBounds(gfx::Rect(new_bounds.x(), new_bounds.y(), new_w, new_h));
|
| - rwhv_->SetSize(new_bounds.size());
|
| + rwhv_size.width(), rwhv_size.height());
|
| + popup_->SetBounds(new_bounds);
|
| + rwhv_->SetSize(rwhv_size);
|
| }
|
|
|
| void MainMenu::CreateNewWindow(int route_id) {
|
| @@ -163,7 +211,8 @@
|
| }
|
|
|
| helper_.CreateNewWindow(route_id, browser_->profile(), site_instance_,
|
| - DOMUIFactory::GetDOMUIType(GURL(kMenuURL)), NULL);
|
| + DOMUIFactory::GetDOMUIType(GURL(GetMenuURL())),
|
| + NULL);
|
| pending_contents_.reset(helper_.GetCreatedWindow(route_id));
|
| pending_contents_->set_delegate(&tab_contents_delegate_);
|
| }
|
|
|