summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 15:36:15 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-18 15:36:15 +0000
commit89c4ee8206b89e9e7407f37c1ab6002cbd23acd3 (patch)
tree20aa1cb57081f4a3ec106fa53dbf4174e0c63039 /chrome
parentf258a71cfa06f2050d80fc5d380700cc8c52aa9a (diff)
downloadchromium_src-89c4ee8206b89e9e7407f37c1ab6002cbd23acd3.zip
chromium_src-89c4ee8206b89e9e7407f37c1ab6002cbd23acd3.tar.gz
chromium_src-89c4ee8206b89e9e7407f37c1ab6002cbd23acd3.tar.bz2
Bugfixes and enhancements to the compact nav bar and the status area.
This makes the compact navigation bar off by default at the request of Nicolas. It can be enabled with --compact-nav on the command line. It also adds different tab opening options when this feature is enabled. They are accessible from the app menu in the status area. The buttons now extend to the top of the screen for easier clicking. The status area is enabled whether or not the compact navigation bar is. I fixed the background so it will appear unselected when the window loses focus, and I fixed the time formatting to make the minutes always 2 digits. The Chrome button is now hooked up and just opens a tab to a placeholder page. Review URL: http://codereview.chromium.org/169001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc66
-rw-r--r--chrome/browser/views/compact_navigation_bar.cc47
-rw-r--r--chrome/browser/views/compact_navigation_bar.h2
-rw-r--r--chrome/browser/views/frame/status_area_view.cc71
-rw-r--r--chrome/browser/views/frame/status_area_view.h12
5 files changed, 157 insertions, 41 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 6a171c2..dc2e21d 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -77,7 +77,9 @@
#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "views/widget/widget_gtk.h"
-#define COMPACT_NAV_BAR
+// This command-line switch enables the compact navigation bar instead of the
+// regular toolbar.
+static const wchar_t kUseCompactNavBar[] = L"compact-nav";
#endif
namespace {
@@ -1363,21 +1365,25 @@ void BrowserWindowGtk::InitWidgets() {
// Build the titlebar (tabstrip + header space + min/max/close buttons).
titlebar_.reset(new BrowserTitlebar(this, window_));
-#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
+#if defined(OS_CHROMEOS)
GtkWidget* titlebar_hbox = NULL;
GtkWidget* navbar_hbox = NULL;
GtkWidget* status_hbox = NULL;
+ bool has_compact_nav_bar =
+ CommandLine::ForCurrentProcess()->HasSwitch(kUseCompactNavBar);
if (browser_->type() == Browser::TYPE_NORMAL) {
// Make a box that we'll later insert the compact navigation bar into. The
// tabstrip must go into an hbox with our box so that they can get arranged
// horizontally.
titlebar_hbox = gtk_hbox_new(FALSE, 0);
- navbar_hbox = gtk_hbox_new(FALSE, 0);
- status_hbox = gtk_hbox_new(FALSE, 0);
- gtk_widget_show(navbar_hbox);
gtk_widget_show(titlebar_hbox);
+ if (has_compact_nav_bar) {
+ 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);
+ }
+ status_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(status_hbox);
- gtk_box_pack_start(GTK_BOX(titlebar_hbox), navbar_hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(titlebar_hbox), titlebar_->widget(), TRUE, TRUE,
0);
gtk_box_pack_start(GTK_BOX(titlebar_hbox), status_hbox, FALSE, FALSE, 0);
@@ -1398,8 +1404,8 @@ void BrowserWindowGtk::InitWidgets() {
toolbar_.reset(new BrowserToolbarGtk(browser_.get(), this));
toolbar_->Init(browser_->profile(), window_);
toolbar_->AddToolbarToBox(content_vbox_);
-#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
- if (browser_->type() == Browser::TYPE_NORMAL) {
+#if defined(OS_CHROMEOS)
+ if (browser_->type() == Browser::TYPE_NORMAL && has_compact_nav_bar) {
gtk_widget_hide(toolbar_->widget());
}
#endif
@@ -1474,24 +1480,31 @@ void BrowserWindowGtk::InitWidgets() {
gtk_widget_show(window_container_);
browser_->tabstrip_model()->AddObserver(this);
-#if defined(OS_CHROMEOS) && defined(COMPACT_NAV_BAR)
+#if defined(OS_CHROMEOS)
if (browser_->type() == Browser::TYPE_NORMAL) {
- // Create the compact navigation bar. This must be done after adding
- // everything to the window since it's done in Views, which expects to call
- // realize (requiring a window) in the Init function.
- views::WidgetGtk* clb_widget =
- new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
- clb_widget->set_delete_on_destroy(true);
- // Must initialize with a NULL parent since the widget will assume the
- // parent is also a WidgetGtk. Then we can parent the native widget
- // afterwards.
- clb_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
- gtk_widget_reparent(clb_widget->GetNativeView(), navbar_hbox);
-
- compact_navigation_bar_ = new CompactNavigationBar(browser_.get());
-
- clb_widget->SetContentsView(compact_navigation_bar_);
- compact_navigation_bar_->Init();
+ if (has_compact_nav_bar) {
+ // Create the compact navigation bar. This must be done after adding
+ // everything to the window since it's done in Views, which expects to
+ // call realize (requiring a window) in the Init function.
+ views::WidgetGtk* clb_widget =
+ new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
+ clb_widget->set_delete_on_destroy(true);
+ // Must initialize with a NULL parent since the widget will assume the
+ // parent is also a WidgetGtk. Then we can parent the native widget
+ // afterwards.
+ clb_widget->Init(NULL, gfx::Rect(0, 0, 100, 30));
+ gtk_widget_reparent(clb_widget->GetNativeView(), navbar_hbox);
+
+ compact_navigation_bar_ = new CompactNavigationBar(browser_.get());
+
+ clb_widget->SetContentsView(compact_navigation_bar_);
+ compact_navigation_bar_->Init();
+
+ // Must be after Init.
+ gtk_widget_set_size_request(clb_widget->GetNativeView(),
+ compact_navigation_bar_->GetPreferredSize().width(), 20);
+ clb_widget->Show();
+ }
// Create the status area.
views::WidgetGtk* status_widget =
@@ -1504,13 +1517,10 @@ void BrowserWindowGtk::InitWidgets() {
status_area_->Init();
// Must be after Init.
- gtk_widget_set_size_request(clb_widget->GetNativeView(),
- compact_navigation_bar_->GetPreferredSize().width(), 20);
gfx::Size status_area_size = status_area_->GetPreferredSize();
gtk_widget_set_size_request(status_widget->GetNativeView(),
status_area_size.width(),
status_area_size.height());
- clb_widget->Show();
status_widget->Show();
}
#endif // OS_CHROMEOS
diff --git a/chrome/browser/views/compact_navigation_bar.cc b/chrome/browser/views/compact_navigation_bar.cc
index 50409c5..7feb27b 100644
--- a/chrome/browser/views/compact_navigation_bar.cc
+++ b/chrome/browser/views/compact_navigation_bar.cc
@@ -10,6 +10,8 @@
#include "base/logging.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/views/frame/status_area_view.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "grit/theme_resources.h"
@@ -101,8 +103,7 @@ void CompactNavigationBar::Layout() {
int curx = 0;
- // Make the chrome button square since it looks better that way.
- chrome_button_->SetBounds(curx, 0, kChromeButtonSize, kChromeButtonSize);
+ chrome_button_->SetBounds(curx, 0, kChromeButtonSize, height());
curx += kChromeButtonSize + kHorizPadding;
// URL bar.
@@ -112,16 +113,16 @@ void CompactNavigationBar::Layout() {
// "Back | Forward" section.
gfx::Size button_size = back_button_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
- back_button_->SetBounds(curx, 1, button_size.width(), height() - 1);
+ back_button_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizPadding;
button_size = bf_separator_->GetPreferredSize();
- bf_separator_->SetBounds(curx, 1, button_size.width(), height() - 1);
+ bf_separator_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizPadding;
button_size = forward_button_->GetPreferredSize();
button_size.set_width(button_size.width() + kInnerPadding * 2);
- forward_button_->SetBounds(curx, 1, button_size.width(), height() - 1);
+ forward_button_->SetBounds(curx, 0, button_size.width(), height());
curx += button_size.width() + kHorizPadding;
}
@@ -129,7 +130,11 @@ void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
ThemeProvider* theme = browser_->profile()->GetThemeProvider();
// Fill the background.
- SkBitmap* background = theme->GetBitmapNamed(IDR_THEME_FRAME);
+ SkBitmap* background;
+ if (browser_->window()->IsActive())
+ background = theme->GetBitmapNamed(IDR_THEME_FRAME);
+ else
+ background = theme->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
canvas->TileImageInt(*background, 0, 0, width(), height());
}
@@ -139,7 +144,8 @@ void CompactNavigationBar::ButtonPressed(views::Button* sender) {
return;
if (sender == chrome_button_) {
- NOTIMPLEMENTED(); // TODO(brettw) hook this up to something.
+ AddTabWithURL(GURL("http://goto.ext.google.com/tik-tok"),
+ PageTransition::START_PAGE);
} else if (sender == back_button_) {
if (tab_contents->controller().CanGoBack())
tab_contents->controller().GoBack();
@@ -156,10 +162,7 @@ void CompactNavigationBar::OnAutocompleteAccept(
WindowOpenDisposition disposition,
PageTransition::Type transition,
const GURL& alternate_nav_url) {
- // Add the new tab at the first non-pinned location.
- int index = browser_->tabstrip_model()->IndexOfFirstNonPinnedTab();
- browser_->AddTabWithURL(url, GURL(), PageTransition::TYPED,
- true, index, true, NULL);
+ AddTabWithURL(url, transition);
}
void CompactNavigationBar::OnChanged() {
@@ -182,3 +185,25 @@ gfx::Rect CompactNavigationBar::GetPopupBounds() const {
ConvertPointToScreen(this, &upper_left);
return gfx::Rect(upper_left.x(), upper_left.y(), 700, 100);
}
+
+void CompactNavigationBar::AddTabWithURL(const GURL& url,
+ PageTransition::Type transition) {
+ switch (StatusAreaView::GetOpenTabsMode()) {
+ case StatusAreaView::OPEN_TABS_ON_LEFT: {
+ // Add the new tab at the first non-pinned location.
+ int index = browser_->tabstrip_model()->IndexOfFirstNonPinnedTab();
+ browser_->AddTabWithURL(url, GURL(), transition,
+ true, index, true, NULL);
+ break;
+ }
+ case StatusAreaView::OPEN_TABS_CLOBBER: {
+ browser_->GetSelectedTabContents()->controller().LoadURL(
+ url, GURL(), transition);
+ break;
+ }
+ case StatusAreaView::OPEN_TABS_ON_RIGHT: {
+ browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL);
+ break;
+ }
+ }
+}
diff --git a/chrome/browser/views/compact_navigation_bar.h b/chrome/browser/views/compact_navigation_bar.h
index 02cb5d4..ba7286b 100644
--- a/chrome/browser/views/compact_navigation_bar.h
+++ b/chrome/browser/views/compact_navigation_bar.h
@@ -57,6 +57,8 @@ class CompactNavigationBar : public views::View,
// AutocompletePopupPositioner implementation.
virtual gfx::Rect GetPopupBounds() const;
+ void AddTabWithURL(const GURL& url, PageTransition::Type transition);
+
Browser* browser_;
bool initialized_;
diff --git a/chrome/browser/views/frame/status_area_view.cc b/chrome/browser/views/frame/status_area_view.cc
index c574247..873ba6d 100644
--- a/chrome/browser/views/frame/status_area_view.cc
+++ b/chrome/browser/views/frame/status_area_view.cc
@@ -16,6 +16,7 @@
#include "base/timer.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
#include "chrome/browser/profile.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -75,7 +76,7 @@ void ClockView::Paint(gfx::Canvas* canvas) {
base::Time::Exploded now_exploded;
now.LocalExplode(&now_exploded);
- std::wstring time_string = StringPrintf(L"%d:%d",
+ std::wstring time_string = StringPrintf(L"%d:%02d",
now_exploded.hour,
now_exploded.minute);
canvas->DrawStringInt(time_string, font_, SK_ColorWHITE, 0, 0,
@@ -109,8 +110,56 @@ void ClockView::OnTimer() {
SetNextTimer();
}
+class OptionsMenuModel : public views::SimpleMenuModel,
+ public views::SimpleMenuModel::Delegate {
+ public:
+ explicit OptionsMenuModel(views::SimpleMenuModel::Delegate* delegate)
+ : SimpleMenuModel(this) {
+ AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_LEFT),
+ ASCIIToUTF16("Open tabs on left"));
+ AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_CLOBBER),
+ ASCIIToUTF16("Open tabs clobber"));
+ AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_RIGHT),
+ ASCIIToUTF16("Open tabs on right"));
+ }
+ virtual ~OptionsMenuModel() {
+ }
+
+ // SimpleMenuModel::Delegate implementation.
+ virtual bool IsCommandIdChecked(int command_id) const {
+ return StatusAreaView::GetOpenTabsMode() == command_id;
+ }
+ virtual bool IsCommandIdEnabled(int command_id) const {
+ return true;
+ }
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ views::Accelerator* accelerator) {
+ return false;
+ }
+ virtual void ExecuteCommand(int command_id) {
+ switch (command_id) {
+ case StatusAreaView::OPEN_TABS_ON_LEFT:
+ case StatusAreaView::OPEN_TABS_CLOBBER:
+ case StatusAreaView::OPEN_TABS_ON_RIGHT:
+ StatusAreaView::SetOpenTabsMode(
+ static_cast<StatusAreaView::OpenTabsMode>(command_id));
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(OptionsMenuModel);
+};
+
} // namespace
+// Default to opening new tabs on the left.
+StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ =
+ StatusAreaView::OPEN_TABS_ON_LEFT;
+
StatusAreaView::StatusAreaView(Browser* browser)
: browser_(browser),
battery_view_(NULL),
@@ -172,14 +221,30 @@ void StatusAreaView::Paint(gfx::Canvas* canvas) {
ThemeProvider* theme = browser_->profile()->GetThemeProvider();
// Fill the background.
- SkBitmap* background = theme->GetBitmapNamed(IDR_THEME_FRAME);
+ SkBitmap* background;
+ if (browser_->window()->IsActive())
+ background = theme->GetBitmapNamed(IDR_THEME_FRAME);
+ else
+ background = theme->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
canvas->TileImageInt(*background, 0, 0, width(), height());
}
+// static
+StatusAreaView::OpenTabsMode StatusAreaView::GetOpenTabsMode() {
+ return open_tabs_mode_;
+}
+
+// static
+void StatusAreaView::SetOpenTabsMode(OpenTabsMode mode) {
+ open_tabs_mode_ = mode;
+}
+
void StatusAreaView::CreateAppMenu() {
if (app_menu_contents_.get())
return;
+ options_menu_contents_.reset(new OptionsMenuModel(this));
+
app_menu_contents_.reset(new views::SimpleMenuModel(this));
app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
@@ -205,6 +270,8 @@ void StatusAreaView::CreateAppMenu() {
l10n_util::GetStringFUTF16(
IDS_OPTIONS,
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
+ app_menu_contents_->AddSubMenu(ASCIIToUTF16("Compact nav bar options"),
+ options_menu_contents_.get());
app_menu_contents_->AddItem(IDC_ABOUT,
l10n_util::GetStringFUTF16(
IDS_ABOUT,
diff --git a/chrome/browser/views/frame/status_area_view.h b/chrome/browser/views/frame/status_area_view.h
index 1be12c8..6ace5a2 100644
--- a/chrome/browser/views/frame/status_area_view.h
+++ b/chrome/browser/views/frame/status_area_view.h
@@ -23,6 +23,12 @@ class StatusAreaView : public views::View,
public views::SimpleMenuModel::Delegate,
public views::ViewMenuDelegate {
public:
+ enum OpenTabsMode {
+ OPEN_TABS_ON_LEFT = 1,
+ OPEN_TABS_CLOBBER,
+ OPEN_TABS_ON_RIGHT
+ };
+
StatusAreaView(Browser* browser);
virtual ~StatusAreaView();
@@ -33,6 +39,9 @@ class StatusAreaView : public views::View,
virtual void Layout();
virtual void Paint(gfx::Canvas* canvas);
+ static OpenTabsMode GetOpenTabsMode();
+ static void SetOpenTabsMode(OpenTabsMode mode);
+
private:
void CreateAppMenu();
@@ -54,8 +63,11 @@ class StatusAreaView : public views::View,
views::MenuButton* menu_view_;
scoped_ptr<views::SimpleMenuModel> app_menu_contents_;
+ scoped_ptr<views::SimpleMenuModel> options_menu_contents_;
scoped_ptr<views::Menu2> app_menu_menu_;
+ static OpenTabsMode open_tabs_mode_;
+
DISALLOW_COPY_AND_ASSIGN(StatusAreaView);
};