Skip to content

Commit

Permalink
Make the main menu open at full screen and provides command line
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sky@chromium.org committed Oct 5, 2009
1 parent 41b3ae9 commit 9e35c82
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 16 deletions.
Binary file added chrome/app/theme/chromium/button_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions chrome/app/theme/theme_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,18 @@
<include name="IDR_STATUSBAR_WIFI_7" file="statusbar_wifi_7.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_8" file="statusbar_wifi_8.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIRED" file="statusbar_wired.png" type="BINDATA" />
</if>

<if expr="pp_ifdef('chromeos') and pp_ifdef('_google_chrome')">
<include name="IDR_MAIN_MENU_BUTTON" file="google_chrome/button_menu.png" type="BINDATA" />
<include name="IDR_MAIN_MENU_BUTTON_DROP_DOWN" file="google_chrome/button_menu_drop_down.png" type="BINDATA" />
</if>

<if expr="pp_ifdef('chromeos') and not pp_ifdef('_google_chrome')">
<include name="IDR_MAIN_MENU_BUTTON" file="chromium/button_menu.png" type="BINDATA" />
<include name="IDR_MAIN_MENU_BUTTON_DROP_DOWN" file="chromium/button_menu_drop_down.png" type="BINDATA" />
</if>

<if expr="not pp_ifdef('chromeos')">
<include name="IDR_THEME_FRAME" file="theme_frame_default.png" type="BINDATA" />
<include name="IDR_THEME_TAB_BACKGROUND" file="theme_tab_background.png" type="BINDATA" />
Expand All @@ -402,3 +410,5 @@
</includes>
</release>
</grit>


81 changes: 65 additions & 16 deletions chrome/browser/chromeos/main_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -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_);
}
Expand Down

0 comments on commit 9e35c82

Please sign in to comment.