summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-12 19:06:20 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-12 19:06:20 +0000
commitc88e3df4344d2621f59cbe2899c5859ab1a4fd5d (patch)
tree6acf714ba261116020d52e283ed3270eb1ed5599
parentd4281df8eff4a69740c98619920816dc16e43962 (diff)
downloadchromium_src-c88e3df4344d2621f59cbe2899c5859ab1a4fd5d.zip
chromium_src-c88e3df4344d2621f59cbe2899c5859ab1a4fd5d.tar.gz
chromium_src-c88e3df4344d2621f59cbe2899c5859ab1a4fd5d.tar.bz2
Make sure the main menu is positioned right.
This is necessary because the chromeos window manager moves the window off the screen when in overview mode, and also WM resize/relocate the chrome window when a panel is attached to the side. Adjust the button layout so that back/forward button and main menu align nicely. BUG=none TEST=manual: open main menu, then preess F12 to switch to overview mode. quit the overview mode, and main menu should work. Review URL: http://codereview.chromium.org/600086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38909 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/compact_navigation_bar.cc32
-rw-r--r--chrome/browser/chromeos/main_menu.cc63
-rw-r--r--chrome/browser/chromeos/main_menu.h8
3 files changed, 60 insertions, 43 deletions
diff --git a/chrome/browser/chromeos/compact_navigation_bar.cc b/chrome/browser/chromeos/compact_navigation_bar.cc
index bee7a920..5cc51c0 100644
--- a/chrome/browser/chromeos/compact_navigation_bar.cc
+++ b/chrome/browser/chromeos/compact_navigation_bar.cc
@@ -32,8 +32,14 @@ namespace chromeos {
// Padding inside each button around the image.
static const int kInnerPadding = 1;
-// Spacing between buttons.
-static const int kHorizPadding = 3;
+// Spacing between buttons (excluding left/right most margin)
+static const int kHorizMargin = 3;
+
+// Left side margin of the back button to align with the main menu.
+static const int kBackButtonLeftMargin = 10;
+
+// Right side margin of the forward button to align with the main menu.
+static const int kForwardButtonRightMargin = 1;
// Preferred height.
static const int kPreferredHeight = 25;
@@ -97,14 +103,13 @@ void CompactNavigationBar::Init() {
}
gfx::Size CompactNavigationBar::GetPreferredSize() {
- int width = kHorizPadding;
- width += back_->GetPreferredSize().width() + kHorizPadding +
- kInnerPadding * 2;
- width += bf_separator_->GetPreferredSize().width() + kHorizPadding;
- width += forward_->GetPreferredSize().width() + kHorizPadding +
- kInnerPadding * 2;
-
- width++;
+ int width = kBackButtonLeftMargin;
+ width += back_->GetPreferredSize().width() + kInnerPadding * 2;
+ width += kHorizMargin;
+ width += bf_separator_->GetPreferredSize().width();
+ width += kHorizMargin;
+ width += forward_->GetPreferredSize().width() + kInnerPadding * 2;
+ width += kForwardButtonRightMargin;
return gfx::Size(width, kPreferredHeight);
}
@@ -114,21 +119,20 @@ void CompactNavigationBar::Layout() {
// Layout forward/back buttons after entry views as follows:
// [Back]|[Forward]
- int curx = 0;
+ int curx = kBackButtonLeftMargin;
// "Back | Forward" section.
gfx::Size button_size = back_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
back_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
+ curx += button_size.width() + kHorizMargin;
button_size = bf_separator_->GetPreferredSize();
bf_separator_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
+ curx += button_size.width() + kHorizMargin;
button_size = forward_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
forward_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
}
void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
diff --git a/chrome/browser/chromeos/main_menu.cc b/chrome/browser/chromeos/main_menu.cc
index 6760899..72800e2 100644
--- a/chrome/browser/chromeos/main_menu.cc
+++ b/chrome/browser/chromeos/main_menu.cc
@@ -73,27 +73,6 @@ const wchar_t kMenuSizeSwitch[] = L"main-menu-size";
// URL of the page to load. This is ignored if kURLSwitch is specified.
const char kMenuURL[] = "http://goto.ext.google.com/crux-home";
-// 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 URL of the menu.
static GURL GetMenuURL() {
std::wstring url_string =
@@ -278,13 +257,12 @@ MainMenu::MainMenu()
popup_ = menu_popup;
// The background image has transparency, so we make the window transparent.
menu_popup->MakeTransparent();
- gfx::Size popup_size = GetPopupSize();
- menu_popup->Init(NULL, gfx::Rect(0, 0, popup_size.width(),
- popup_size.height()));
+ popup_->Init(NULL, gfx::Rect());
TabOverviewTypes::instance()->SetWindowType(
- menu_popup->GetNativeView(),
+ popup_->GetNativeView(),
TabOverviewTypes::WINDOW_TYPE_CHROME_INFO_BUBBLE,
NULL);
+
views::Painter* painter = views::Painter::CreateImagePainter(
*drop_down_image,
gfx::Insets(kBackgroundImageTop, kBackgroundImageLeft,
@@ -326,9 +304,7 @@ MainMenu* MainMenu::Get() {
return Singleton<MainMenu>::get();
}
-void MainMenu::ShowImpl(Browser* browser) {
- Cleanup();
-
+void MainMenu::Update(Browser* browser) {
if (browser_ != browser) {
browser_ = browser;
navigation_bar_->Update(browser);
@@ -338,10 +314,39 @@ void MainMenu::ShowImpl(Browser* browser) {
GTK_WINDOW(popup_->GetNativeView()),
GTK_WINDOW(browser_->window()->GetNativeHandle()));
}
- BrowserView* bview = static_cast<BrowserView*>(browser->window());
+
+ BrowserView* bview = static_cast<BrowserView*>(browser_->window());
navigation_bar_->SetVisible(bview->is_compact_style());
+ popup_->SetBounds(GetPopupBounds());
menu_container_->Layout();
+}
+
+gfx::Rect MainMenu::GetPopupBounds() {
+ gfx::Rect window_bounds = browser_->window()->GetRestoredBounds();
+ 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::Rect(window_bounds.origin(),
+ gfx::Size(StringToInt(chunks[0]),
+ StringToInt(chunks[1])));
+ }
+ }
+
+ gfx::Size window_size = window_bounds.size();
+ // We don't want to see the drop shadow. Adjust the width
+ // so the drop shadow ends up off screen.
+ window_size.Enlarge(kBackgroundImageRight, kBackgroundImageBottom);
+ window_bounds.set_size(window_size);
+ return window_bounds;
+}
+
+void MainMenu::ShowImpl(Browser* browser) {
+ Cleanup();
+ Update(browser);
popup_->Show();
GtkWidget* rwhv_widget = rwhv_->GetNativeView();
diff --git a/chrome/browser/chromeos/main_menu.h b/chrome/browser/chromeos/main_menu.h
index 5cc567b..9873339 100644
--- a/chrome/browser/chromeos/main_menu.h
+++ b/chrome/browser/chromeos/main_menu.h
@@ -140,6 +140,14 @@ class MainMenu : public RenderViewHostDelegate,
// hidden.
void Cleanup();
+ // Updates the main menu's state and layout with the |browser|.
+ void Update(Browser* browser);
+
+ // Returns the size of the popup. By default the popup is positioned
+ // and sized to cover the entire browser window, but its size can be
+ // overriden by the command line switch kMenuSizeSwitch.
+ gfx::Rect GetPopupBounds();
+
// RenderViewHostDelegate overrides.
virtual int GetBrowserWindowID() const {
return -1;