summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/compact_navigation_bar.cc27
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc60
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h13
-rw-r--r--chrome/browser/views/frame/status_area_view.cc33
4 files changed, 116 insertions, 17 deletions
diff --git a/chrome/browser/chromeos/compact_navigation_bar.cc b/chrome/browser/chromeos/compact_navigation_bar.cc
index e2be4a0..a4b1d97 100644
--- a/chrome/browser/chromeos/compact_navigation_bar.cc
+++ b/chrome/browser/chromeos/compact_navigation_bar.cc
@@ -25,10 +25,14 @@ static const int kInnerPadding = 1;
// Spacing between buttons.
static const int kHorizPadding = 3;
-static const int kURLWidth = 150;
+static const int kURLWidth = 180;
static const int kChromeButtonSize = 25;
+// Draw this much white around the URL bar to make it look larger than it
+// actually is.
+static const int kURLPadding = 2;
+
CompactNavigationBar::CompactNavigationBar(Browser* browser)
: browser_(browser),
initialized_(false) {
@@ -87,13 +91,14 @@ gfx::Size CompactNavigationBar::GetPreferredSize() {
int width = 0;
width += kChromeButtonSize + kHorizPadding; // Chrome button.
- width += kURLWidth + kHorizPadding; // URL bar.
+ width += kURLWidth + kHorizPadding + kURLPadding * 2; // URL bar.
width += back_button_->GetPreferredSize().width() + kHorizPadding +
kInnerPadding * 2;
width += bf_separator_->GetPreferredSize().width() + kHorizPadding;
width += forward_button_->GetPreferredSize().width() + kHorizPadding +
kInnerPadding * 2;
+ width++;
return gfx::Size(width, kChromeButtonSize);
}
@@ -106,10 +111,6 @@ void CompactNavigationBar::Layout() {
chrome_button_->SetBounds(curx, 0, kChromeButtonSize, height());
curx += kChromeButtonSize + kHorizPadding;
- // URL bar.
- location_entry_view_->SetBounds(curx, 0, kURLWidth, height());
- curx += kURLWidth + kHorizPadding;
-
// "Back | Forward" section.
gfx::Size button_size = back_button_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
@@ -124,6 +125,11 @@ void CompactNavigationBar::Layout() {
button_size.set_width(button_size.width() + kInnerPadding * 2);
forward_button_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizPadding;
+
+ // URL bar.
+ location_entry_view_->SetBounds(curx + kURLPadding, 0,
+ kURLWidth + kURLPadding * 2, height());
+ curx += kURLWidth + kHorizPadding + kURLPadding * 2;
}
void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
@@ -136,6 +142,15 @@ void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
else
background = theme->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
canvas->TileImageInt(*background, 0, 0, width(), height());
+
+ // Draw a white box around the edit field so that it looks larger. This is
+ // kind of what the default GTK location bar does, although they have a
+ // fancier border.
+ canvas->FillRectInt(0xFFFFFFFF,
+ location_entry_view_->x() - kURLPadding,
+ 2,
+ location_entry_view_->width() + kURLPadding * 2,
+ height() - 5);
}
void CompactNavigationBar::ButtonPressed(views::Button* sender) {
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index e2fce5d..d94da08 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -82,10 +82,6 @@
#include "views/controls/button/image_button.h"
#include "views/widget/widget_gtk.h"
-// This command-line switch enables the compact navigation bar instead of the
-// regular toolbar.
-static const wchar_t kUseCompactNavBar[] = L"compact-nav";
-
// This command-line switch enables the main menu button in the upper left
// corner. By default it isn't shown.
static const wchar_t kShowMainMenuButton[] = L"main-menu-button";
@@ -325,6 +321,40 @@ class MenuPopupCloser : public views::ButtonListener {
DISALLOW_COPY_AND_ASSIGN(MenuPopupCloser);
};
+// This draws the spacer below the tab strip when we're using the compact
+// location bar (i.e. no location bar). This basically duplicates the painting
+// that the tab strip would have done for this region so that it blends
+// nicely in with the bottom of the tabs.
+gboolean OnCompactNavSpacerExpose(GtkWidget* widget,
+ GdkEventExpose* e,
+ BrowserWindowGtk* window) {
+ cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
+ cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height);
+ cairo_clip(cr);
+ // The toolbar is supposed to blend in with the active tab, so we have to pass
+ // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the
+ // tab strip.
+ gfx::Point tabstrip_origin =
+ window->tabstrip()->GetTabStripOriginForWidget(widget);
+ ThemeProvider* theme_provider =
+ window->browser()->profile()->GetThemeProvider();
+ GdkPixbuf* toolbar_background = theme_provider->GetPixbufNamed(
+ IDR_THEME_TOOLBAR);
+ gdk_cairo_set_source_pixbuf(cr, toolbar_background, tabstrip_origin.x(),
+ tabstrip_origin.y());
+ // We tile the toolbar background in both directions.
+ cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
+ cairo_rectangle(cr,
+ tabstrip_origin.x(),
+ tabstrip_origin.y(),
+ e->area.x + e->area.width - tabstrip_origin.x(),
+ e->area.y + e->area.height - tabstrip_origin.y());
+ cairo_fill(cr);
+ cairo_destroy(cr);
+
+ return FALSE;
+}
+
} // namespace
// Callback from GTK when the user clicks the main menu button.
@@ -344,7 +374,8 @@ static void OnMainMenuButtonClicked(GtkWidget* widget,
menu_popup->SetContentsView(button);
menu_popup->Show();
}
-#endif
+
+#endif // OS_CHROMEOS
int GetCommandId(guint accel_key, GdkModifierType modifier) {
// Bug 9806: If capslock is on, we will get a capital letter as accel_key.
@@ -487,6 +518,11 @@ GdkColor SkColorToGdkColor(const SkColor& color) {
std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_;
+#if defined(OS_CHROMEOS)
+// Default to using the regular window style.
+bool BrowserWindowGtk::next_window_should_use_compact_nav_ = false;
+#endif
+
BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
: browser_(browser),
#if defined(OS_CHROMEOS)
@@ -1466,8 +1502,7 @@ void BrowserWindowGtk::InitWidgets() {
GtkWidget* titlebar_hbox = NULL;
GtkWidget* navbar_hbox = NULL;
GtkWidget* status_hbox = NULL;
- bool has_compact_nav_bar =
- CommandLine::ForCurrentProcess()->HasSwitch(kUseCompactNavBar);
+ bool has_compact_nav_bar = next_window_should_use_compact_nav_;
if (browser_->type() == Browser::TYPE_NORMAL) {
bool show_main_menu_button =
CommandLine::ForCurrentProcess()->HasSwitch(kShowMainMenuButton);
@@ -1480,6 +1515,10 @@ void BrowserWindowGtk::InitWidgets() {
navbar_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(navbar_hbox);
gtk_box_pack_start(GTK_BOX(titlebar_hbox), navbar_hbox, FALSE, FALSE, 0);
+
+ // Reset the compact nav bit now that we're creating the next toplevel
+ // window. Code below will use our local has_compact_nav_bar variable.
+ next_window_should_use_compact_nav_ = false;
} else if (show_main_menu_button) {
CustomDrawButton* main_menu_button =
new CustomDrawButton(IDR_MAIN_MENU_BUTTON, IDR_MAIN_MENU_BUTTON,
@@ -1517,6 +1556,13 @@ void BrowserWindowGtk::InitWidgets() {
#if defined(OS_CHROMEOS)
if (browser_->type() == Browser::TYPE_NORMAL && has_compact_nav_bar) {
gtk_widget_hide(toolbar_->widget());
+
+ GtkWidget* spacer = gtk_vbox_new(FALSE, 0);
+ gtk_widget_set_size_request(spacer, -1, 3);
+ gtk_widget_show(spacer);
+ gtk_box_pack_start(GTK_BOX(content_vbox_), spacer, FALSE, FALSE, 0);
+ g_signal_connect(spacer, "expose-event",
+ G_CALLBACK(&OnCompactNavSpacerExpose), this);
}
#endif
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index c97c2f6..c4426a71 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -154,6 +154,17 @@ class BrowserWindowGtk : public BrowserWindow,
// Sets whether a drag is active. If a drag is active the window will not
// close.
void set_drag_active(bool drag_active) { drag_active_ = drag_active; }
+
+ // Sets the flag that the next toplevel browser window being created will
+ // use the compact nav bar. This is used to implement the "new compact nav
+ // window" menu option. This flag will be cleared after the next window is
+ // opened, which will revert to the old behavior.
+ //
+ // TODO(brettw) remove this when we figure out how this is actually going
+ // to work long-term. This is a hack so the feature can be tested.
+ static void set_next_window_should_use_compact_nav() {
+ next_window_should_use_compact_nav_ = true;
+ }
#endif
// Reset the mouse cursor to the default cursor if it was set to something
@@ -360,6 +371,8 @@ class BrowserWindowGtk : public BrowserWindow,
CompactNavigationBar* compact_navigation_bar_;
StatusAreaView* status_area_;
+
+ static bool next_window_should_use_compact_nav_;
#endif
// A map which translates an X Window ID into its respective GtkWindow.
diff --git a/chrome/browser/views/frame/status_area_view.cc b/chrome/browser/views/frame/status_area_view.cc
index ca971be..5557488 100644
--- a/chrome/browser/views/frame/status_area_view.cc
+++ b/chrome/browser/views/frame/status_area_view.cc
@@ -17,6 +17,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/profile.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -113,8 +114,21 @@ void ClockView::OnTimer() {
class OptionsMenuModel : public views::SimpleMenuModel,
public views::SimpleMenuModel::Delegate {
public:
- explicit OptionsMenuModel(views::SimpleMenuModel::Delegate* delegate)
- : SimpleMenuModel(this) {
+ // These extra command IDs must be unique when combined with the options,
+ // so we just pick up the numbering where that stops.
+ enum OtherCommands {
+ CREATE_NEW_WINDOW = StatusAreaView::OPEN_TABS_ON_RIGHT + 1,
+ };
+
+ explicit OptionsMenuModel(Browser* browser,
+ views::SimpleMenuModel::Delegate* delegate)
+ : SimpleMenuModel(this),
+ browser_(browser) {
+ AddItem(static_cast<int>(CREATE_NEW_WINDOW),
+ ASCIIToUTF16("New window"));
+
+ AddSeparator();
+
AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_LEFT),
ASCIIToUTF16("Open tabs on left"));
AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_CLOBBER),
@@ -139,6 +153,15 @@ class OptionsMenuModel : public views::SimpleMenuModel,
}
virtual void ExecuteCommand(int command_id) {
switch (command_id) {
+ case CREATE_NEW_WINDOW:
+ // Reach into the GTK browser window and enable the flag to create the
+ // next window as a compact nav one.
+ // TODO(brettw) this is an evil hack, and is here so this can be tested.
+ // Remove it eventually.
+ static_cast<BrowserWindowGtk*>(browser_->window())->
+ set_next_window_should_use_compact_nav();
+ browser_->ExecuteCommand(IDC_NEW_WINDOW);
+ break;
case StatusAreaView::OPEN_TABS_ON_LEFT:
case StatusAreaView::OPEN_TABS_CLOBBER:
case StatusAreaView::OPEN_TABS_ON_RIGHT:
@@ -151,6 +174,8 @@ class OptionsMenuModel : public views::SimpleMenuModel,
}
private:
+ Browser* browser_;
+
DISALLOW_COPY_AND_ASSIGN(OptionsMenuModel);
};
@@ -243,7 +268,7 @@ void StatusAreaView::CreateAppMenu() {
if (app_menu_contents_.get())
return;
- options_menu_contents_.reset(new OptionsMenuModel(this));
+ options_menu_contents_.reset(new OptionsMenuModel(browser_, this));
app_menu_contents_.reset(new views::SimpleMenuModel(this));
app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
@@ -270,7 +295,7 @@ void StatusAreaView::CreateAppMenu() {
l10n_util::GetStringFUTF16(
IDS_OPTIONS,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
- app_menu_contents_->AddSubMenu(ASCIIToUTF16("Compact nav bar options"),
+ app_menu_contents_->AddSubMenu(ASCIIToUTF16("Compact nav bar"),
options_menu_contents_.get());
app_menu_contents_->AddItem(IDC_ABOUT,
l10n_util::GetStringFUTF16(