summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/main_menu.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 21:51:40 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 21:51:40 +0000
commit9e35c82e74f066ad41ac1d823203154c264252df (patch)
tree3c8530db3a6e55de4cc922066d3c1693347c3e43 /chrome/browser/chromeos/main_menu.cc
parent41b3ae9e8d2f0dffef0e83984856cd4669bdba52 (diff)
downloadchromium_src-9e35c82e74f066ad41ac1d823203154c264252df.zip
chromium_src-9e35c82e74f066ad41ac1d823203154c264252df.tar.gz
chromium_src-9e35c82e74f066ad41ac1d823203154c264252df.tar.bz2
Make the main menu open at full screen and provides command line
switches for changing the url and size. BUG=none TEST=none Review URL: http://codereview.chromium.org/246091 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/main_menu.cc')
-rw-r--r--chrome/browser/chromeos/main_menu.cc81
1 files changed, 65 insertions, 16 deletions
diff --git a/chrome/browser/chromeos/main_menu.cc b/chrome/browser/chromeos/main_menu.cc
index 8b50ab2..2899468 100644
--- a/chrome/browser/chromeos/main_menu.cc
+++ b/chrome/browser/chromeos/main_menu.cc
@@ -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 kBackgroundImageLeft = 85;
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 @@ void MainMenu::ShowImpl() {
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 @@ void MainMenu::ShowImpl() {
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 @@ void MainMenu::ShowImpl() {
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 @@ gboolean MainMenu::OnButtonPressEvent(GtkWidget* widget,
}
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 @@ void MainMenu::CreateNewWindow(int route_id) {
}
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_);
}