diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.h | 6 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/defaults.cc | 13 | ||||
-rw-r--r-- | chrome/browser/defaults.h | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 69 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 71 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 19 | ||||
-rw-r--r-- | chrome/browser/views/compact_navigation_bar.cc | 184 | ||||
-rw-r--r-- | chrome/browser/views/compact_navigation_bar.h | 76 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/frame/status_area_view.cc | 243 | ||||
-rw-r--r-- | chrome/browser/views/frame/status_area_view.h | 62 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.h | 12 |
14 files changed, 674 insertions, 112 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index e4bb2af..efe5c9a 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -32,9 +32,9 @@ class AutocompleteEditController { // for |url|, which the controller can check for existence. See comments on // AutocompleteResult::GetAlternateNavURL(). virtual void OnAutocompleteAccept(const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition, - const GURL& alternate_nav_url) = 0; + WindowOpenDisposition disposition, + PageTransition::Type transition, + const GURL& alternate_nav_url) = 0; // Called when anything has changed that might affect the layout or contents // of the views around the edit, including the text of the edit and the diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 5c82e05..a4b6344 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -140,14 +140,12 @@ void AutocompleteEditViewGtk::Init() { text_view_ = gtk_text_view_new_with_buffer(text_buffer_); if (popup_window_mode_) gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view_), false); - if (browser_defaults::kForceAutocompleteEditFontSize) { - // Until we switch to vector graphics, force the font size. - const double kFontSize = 13.4; // 13.4px == 10pt @ 96dpi - // On Windows, popups have a font size 5/6 the size of non-popups. - const double kPopupWindowFontSize = kFontSize * 5.0 / 6.0; - gtk_util::ForceFontSizePixels(text_view_, - popup_window_mode_ ? kPopupWindowFontSize : kFontSize); - } + + // Until we switch to vector graphics, force the font size. + gtk_util::ForceFontSizePixels(text_view_, + popup_window_mode_ ? + browser_defaults::kAutocompleteEditFontPixelSizeInPopup : + browser_defaults::kAutocompleteEditFontPixelSize); // The text view was floating. It will now be owned by the alignment. gtk_container_add(GTK_CONTAINER(alignment_.get()), text_view_); diff --git a/chrome/browser/defaults.cc b/chrome/browser/defaults.cc index 73f6996..2be990d 100644 --- a/chrome/browser/defaults.cc +++ b/chrome/browser/defaults.cc @@ -8,7 +8,9 @@ namespace browser_defaults { #if defined(OS_CHROMEOS) -const bool kForceAutocompleteEditFontSize = false; +const double kAutocompleteEditFontPixelSize = 12.0; +const double kAutocompleteEditFontPixelSizeInPopup = kAutocompletePopupFontSize; + const int kAutocompletePopupFontSize = 7; const SessionStartupPref::Type kDefaultSessionStartupType = SessionStartupPref::LAST; @@ -17,7 +19,14 @@ const bool kRestoreAfterCrash = true; #elif defined(OS_LINUX) -const bool kForceAutocompleteEditFontSize = true; +// 13.4px = 10pt @ 96dpi. +const double kAutocompleteEditFontPixelSize = 13.4; + +// On Windows, popup windows' autocomplete box have a font 5/6 the size of a +// regular window, which we duplicate here for GTK. +const double kAutocompleteEditFontPixelSizeInPopup = + kAutocompleteEditFontPixelSize * 5.0 / 6.0; + const int kAutocompletePopupFontSize = 10; #endif diff --git a/chrome/browser/defaults.h b/chrome/browser/defaults.h index 9ce7250..dd1c6c6 100644 --- a/chrome/browser/defaults.h +++ b/chrome/browser/defaults.h @@ -14,8 +14,11 @@ namespace browser_defaults { #if defined(OS_LINUX) -// Whether the size of the autocomplete's font should be changed. -extern const bool kForceAutocompleteEditFontSize; +// Size of the font in pixels used in the autocomplete box for normal windows. +extern const double kAutocompleteEditFontPixelSize; + +// Size of the font in pixels used in the autocomplete box for popup windows. +extern const double kAutocompleteEditFontPixelSizeInPopup; // Size of the font used in the autocomplete popup. extern const int kAutocompletePopupFontSize; diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index d4e2e00..c760d11 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -68,8 +68,13 @@ #include "grit/theme_resources.h" #if defined(OS_CHROMEOS) +#include "chrome/browser/views/compact_navigation_bar.h" +#include "chrome/browser/views/frame/status_area_view.h" #include "chrome/browser/views/panel_controller.h" #include "chrome/browser/views/tabs/tab_overview_types.h" +#include "views/widget/widget_gtk.h" + +#define COMPACT_NAV_BAR #endif namespace { @@ -409,6 +414,8 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser) #if defined(OS_CHROMEOS) drag_active_(false), panel_controller_(NULL), + compact_navigation_bar_(NULL), + status_area_(NULL), #endif frame_cursor_(NULL), is_active_(true), @@ -1326,8 +1333,29 @@ 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) + // 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. + GtkWidget* titlebar_hbox = gtk_hbox_new(FALSE, 0); + GtkWidget* navbar_hbox = gtk_hbox_new(FALSE, 0); + GtkWidget* status_hbox = gtk_hbox_new(FALSE, 0); + gtk_widget_show(navbar_hbox); + gtk_widget_show(titlebar_hbox); + 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); + + gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_hbox, FALSE, FALSE, 0); + +#else + // Insert the tabstrip into the window. gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_->widget(), FALSE, FALSE, 0); +#endif // OS_CHROMEOS // The content_vbox_ surrounds the "content": toolbar+bookmarks bar+page. content_vbox_ = gtk_vbox_new(FALSE, 0); @@ -1336,6 +1364,9 @@ 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) + gtk_widget_hide(toolbar_->widget()); +#endif bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get(), this)); @@ -1405,6 +1436,44 @@ void BrowserWindowGtk::InitWidgets() { gtk_container_add(GTK_CONTAINER(window_), window_container_); gtk_widget_show(window_container_); browser_->tabstrip_model()->AddObserver(this); + +#if defined(OS_CHROMEOS) && defined(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(); + + // Create the status area. + views::WidgetGtk* status_widget = + new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD); + status_widget->set_delete_on_destroy(true); + status_widget->Init(NULL, gfx::Rect(0, 0, 100, 30)); + gtk_widget_reparent(status_widget->GetNativeView(), status_hbox); + status_area_ = new StatusAreaView(browser()); + status_widget->SetContentsView(status_area_); + 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 } void BrowserWindowGtk::SetBackgroundColor() { diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 4552575..5808f4c 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -19,6 +19,11 @@ #include "chrome/common/pref_member.h" #include "chrome/common/x11_util.h" +#ifdef OS_CHROMEOS +class CompactNavigationBar; +class StatusAreaView; +#endif + class BookmarkBarGtk; class Browser; class BrowserTitlebar; @@ -338,6 +343,9 @@ class BrowserWindowGtk : public BrowserWindow, bool drag_active_; // Controls interactions with the window manager for popup panels. PanelController* panel_controller_; + + CompactNavigationBar* compact_navigation_bar_; + StatusAreaView* status_area_; #endif // A map which translates an X Window ID into its respective GtkWindow. diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 03f6bdb..f6ed7d8 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -27,15 +27,6 @@ #include "grit/app_resources.h" #include "grit/theme_resources.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/browser.h" -#include "chrome/browser/browser_list.h" -#include "chrome/browser/gtk/browser_window_gtk.h" -#include "chrome/browser/metrics/user_metrics.h" -#include "chrome/browser/views/tabs/tab_overview_types.h" -#include "chrome/common/x11_util.h" -#endif - namespace { const int kDefaultAnimationDurationMs = 100; @@ -721,10 +712,6 @@ void TabStripGtk::Init() { newtab_button_.reset(MakeNewTabButton()); -#if defined(OS_CHROMEOS) - tab_overview_button_.reset(MakeTabOverviewButton()); -#endif - gtk_widget_show_all(tabstrip_.get()); bounds_ = GetInitialWidgetBounds(tabstrip_.get()); @@ -764,9 +751,6 @@ void TabStripGtk::Layout() { } LayoutNewTabButton(static_cast<double>(tab_right), current_unselected_width_); -#if defined(OS_CHROMEOS) - LayoutTabOverviewButton(); -#endif gtk_widget_queue_draw(tabstrip_.get()); } @@ -1243,12 +1227,7 @@ void TabStripGtk::LayoutNewTabButton(double last_tab_right, // We're shrinking tabs, so we need to anchor the New Tab button to the // right edge of the TabStrip's bounds, rather than the right edge of the // right-most Tab, otherwise it'll bounce when animating. -#if defined(OS_CHROMEOS) - bounds.set_x(bounds_.width() - newtab_button_->width() - - tab_overview_button_->width()); -#else bounds.set_x(bounds_.width() - newtab_button_->width()); -#endif } else { bounds.set_x(Round(last_tab_right - kTabHOffset) + kNewTabButtonHOffset); } @@ -1258,13 +1237,6 @@ void TabStripGtk::LayoutNewTabButton(double last_tab_right, bounds.x(), bounds.y()); } -#if defined OS_CHROMEOS -void TabStripGtk::LayoutTabOverviewButton() { - gtk_fixed_move(GTK_FIXED(tabstrip_.get()), tab_overview_button_->widget(), - bounds_.width() - tab_overview_button_->width(), 0); -} -#endif - void TabStripGtk::GetDesiredTabWidths(int tab_count, int pinned_tab_count, double* unselected_width, @@ -1290,9 +1262,6 @@ void TabStripGtk::GetDesiredTabWidths(int tab_count, available_width = bounds_.width(); available_width -= (kNewTabButtonHOffset + newtab_button_->width()); -#if defined(OS_CHROMEOS) - available_width -= tab_overview_button_->width(); -#endif } else { // Interesting corner case: if |available_width_for_tabs_| > the result // of the calculation in the conditional arm above, the strip is in @@ -1679,9 +1648,6 @@ void TabStripGtk::AnimationLayout(double unselected_width) { tab_x = end_of_tab + GetTabHOffset(i + 1); } LayoutNewTabButton(tab_x, unselected_width); -#if defined(OS_CHROMEOS) - LayoutTabOverviewButton(); -#endif gtk_widget_queue_draw(tabstrip_.get()); } @@ -1780,12 +1746,6 @@ gboolean TabStripGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event, gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), tabstrip->newtab_button_->widget(), event); -#if defined(OS_CHROMEOS) - // Paint the tab overview button. - gtk_container_propagate_expose(GTK_CONTAINER(tabstrip->tabstrip_.get()), - tabstrip->tab_overview_button_->widget(), event); -#endif - // Paint the tabs in reverse order, so they stack to the left. TabGtk* selected_tab = NULL; int tab_count = tabstrip->GetTabCount(); @@ -1970,34 +1930,3 @@ CustomDrawButton* TabStripGtk::MakeNewTabButton() { return button; } - -#if defined(OS_CHROMEOS) -CustomDrawButton* TabStripGtk::MakeTabOverviewButton() { - CustomDrawButton* button = - new CustomDrawButton(IDR_TAB_OVERVIEW_BUTTON_ICON, 0, 0, 0); - - g_signal_connect(G_OBJECT(button->widget()), "clicked", - G_CALLBACK(OnTabOverviewButtonClicked), this); - GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); - gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); - - return button; -} - -// static -void TabStripGtk::OnTabOverviewButtonClicked(GtkWidget* widget, - TabStripGtk* tabstrip) { - Browser* browser = BrowserList::GetLastActive(); - DCHECK(browser); // In order for the user to click on the tab there should - // be an active browser. - TabOverviewTypes::Message message; - message.set_type(TabOverviewTypes::Message::WM_SWITCH_TO_OVERVIEW_MODE); - GtkWidget* browser_widget = GTK_WIDGET( - static_cast<BrowserWindowGtk*>(browser->window())->GetNativeHandle()); - message.set_param(0, x11_util::GetX11WindowFromGtkWidget(browser_widget)); - TabOverviewTypes::instance()->SendMessage(message); - - UserMetrics::RecordAction(L"TabOverview_PressedTabOverviewButton", - tabstrip->model_->profile()); -} -#endif diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index fb11f50..69e4372 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -318,11 +318,6 @@ class TabStripGtk : public TabStripModelObserver, // during animations, so we can't use current_unselected_width_. void LayoutNewTabButton(double last_tab_right, double unselected_width); -#if defined(OS_CHROMEOS) - // Positions the tab overview button. - void LayoutTabOverviewButton(); -#endif - // -- Link Drag & Drop ------------------------------------------------------ // Returns the bounds to render the drop at, in screen coordinates. Sets @@ -370,15 +365,6 @@ class TabStripGtk : public TabStripModelObserver, // Optionally a full Layout will be performed, specified by |layout|. void FinishAnimation(TabAnimation* animation, bool layout); -#if defined(OS_CHROMEOS) - // Creates and returns the tab overview button. - CustomDrawButton* MakeTabOverviewButton(); - - // Invoked when the user clicks the tab overview button. - static void OnTabOverviewButtonClicked(GtkWidget* widget, - TabStripGtk* tabstrip); -#endif - NotificationRegistrar registrar_; // The Tabs we contain, and their last generated "good" bounds. @@ -423,11 +409,6 @@ class TabStripGtk : public TabStripModelObserver, // The New Tab button. scoped_ptr<CustomDrawButton> newtab_button_; -#if defined(OS_CHROMEOS) - // The tab overview button. - scoped_ptr<CustomDrawButton> tab_overview_button_; -#endif - // Valid for the lifetime of a drag over us. scoped_ptr<DropInfo> drop_info_; diff --git a/chrome/browser/views/compact_navigation_bar.cc b/chrome/browser/views/compact_navigation_bar.cc new file mode 100644 index 0000000..50409c5 --- /dev/null +++ b/chrome/browser/views/compact_navigation_bar.cc @@ -0,0 +1,184 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/compact_navigation_bar.h" + +#include "app/gfx/canvas.h" +#include "app/resource_bundle.h" +#include "app/theme_provider.h" +#include "base/logging.h" +#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "grit/theme_resources.h" +#include "views/controls/button/image_button.h" +#include "views/controls/image_view.h" +#include "views/controls/native/native_view_host.h" + +// Padding inside each button around the image. +static const int kInnerPadding = 1; + +// Spacing between buttons. +static const int kHorizPadding = 3; + +static const int kURLWidth = 150; + +static const int kChromeButtonSize = 25; + +CompactNavigationBar::CompactNavigationBar(Browser* browser) + : browser_(browser), + initialized_(false) { +} + +CompactNavigationBar::~CompactNavigationBar() { +} + +void CompactNavigationBar::Init() { + DCHECK(!initialized_); + initialized_ = true; + + ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); + + chrome_button_ = new views::ImageButton(this); + chrome_button_->SetImage(views::CustomButton::BS_NORMAL, + resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_CHROME)); + chrome_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, + views::ImageButton::ALIGN_MIDDLE); + AddChildView(chrome_button_); + + back_button_ = new views::ImageButton(this); + back_button_->SetImage(views::CustomButton::BS_NORMAL, + resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_BACK)); + back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, + views::ImageButton::ALIGN_MIDDLE); + AddChildView(back_button_); + + bf_separator_ = new views::ImageView; + bf_separator_->SetImage( + resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_SEPARATOR)); + AddChildView(bf_separator_); + + forward_button_ = new views::ImageButton(this); + forward_button_->SetImage(views::CustomButton::BS_NORMAL, + resource_bundle.GetBitmapNamed(IDR_COMPACTNAV_FORWARD)); + forward_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, + views::ImageButton::ALIGN_MIDDLE); + AddChildView(forward_button_); + + // URL bar construction. + location_entry_.reset(new AutocompleteEditViewGtk( + this, browser_->toolbar_model(), browser_->profile(), + browser_->command_updater(), false, this)); + location_entry_->Init(); + gtk_widget_show_all(location_entry_->widget()); + gtk_widget_hide(location_entry_->widget()); + + location_entry_view_ = new views::NativeViewHost; + AddChildView(location_entry_view_); + location_entry_view_->set_focus_view(this); + location_entry_view_->Attach(location_entry_->widget()); +} + +gfx::Size CompactNavigationBar::GetPreferredSize() { + int width = 0; + + width += kChromeButtonSize + kHorizPadding; // Chrome button. + width += kURLWidth + kHorizPadding; // URL bar. + width += back_button_->GetPreferredSize().width() + kHorizPadding + + kInnerPadding * 2; + width += bf_separator_->GetPreferredSize().width() + kHorizPadding; + width += forward_button_->GetPreferredSize().width() + kHorizPadding + + kInnerPadding * 2; + + return gfx::Size(width, kChromeButtonSize); +} + +void CompactNavigationBar::Layout() { + if (!initialized_) + return; + + int curx = 0; + + // Make the chrome button square since it looks better that way. + chrome_button_->SetBounds(curx, 0, kChromeButtonSize, kChromeButtonSize); + 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); + back_button_->SetBounds(curx, 1, button_size.width(), height() - 1); + curx += button_size.width() + kHorizPadding; + + button_size = bf_separator_->GetPreferredSize(); + bf_separator_->SetBounds(curx, 1, button_size.width(), height() - 1); + 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); + curx += button_size.width() + kHorizPadding; +} + +void CompactNavigationBar::Paint(gfx::Canvas* canvas) { + ThemeProvider* theme = browser_->profile()->GetThemeProvider(); + + // Fill the background. + SkBitmap* background = theme->GetBitmapNamed(IDR_THEME_FRAME); + canvas->TileImageInt(*background, 0, 0, width(), height()); +} + +void CompactNavigationBar::ButtonPressed(views::Button* sender) { + TabContents* tab_contents = browser_->GetSelectedTabContents(); + if (!tab_contents) + return; + + if (sender == chrome_button_) { + NOTIMPLEMENTED(); // TODO(brettw) hook this up to something. + } else if (sender == back_button_) { + if (tab_contents->controller().CanGoBack()) + tab_contents->controller().GoBack(); + } else if (sender == forward_button_) { + if (tab_contents->controller().CanGoForward()) + tab_contents->controller().GoForward(); + } else { + NOTREACHED(); + } +} + +void CompactNavigationBar::OnAutocompleteAccept( + const GURL& url, + 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); +} + +void CompactNavigationBar::OnChanged() { + // Other one does "DoLayout" here. +} + +void CompactNavigationBar::OnInputInProgress(bool in_progress) { +} + +SkBitmap CompactNavigationBar::GetFavIcon() const { + return SkBitmap(); +} + +std::wstring CompactNavigationBar::GetTitle() const { + return std::wstring(); +} + +gfx::Rect CompactNavigationBar::GetPopupBounds() const { + gfx::Point upper_left(0, height()); + ConvertPointToScreen(this, &upper_left); + return gfx::Rect(upper_left.x(), upper_left.y(), 700, 100); +} diff --git a/chrome/browser/views/compact_navigation_bar.h b/chrome/browser/views/compact_navigation_bar.h new file mode 100644 index 0000000..02cb5d4 --- /dev/null +++ b/chrome/browser/views/compact_navigation_bar.h @@ -0,0 +1,76 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_COMPACT_NAVIGATION_BAR_H_ +#define CHROME_BROWSER_VIEWS_COMPACT_NAVIGATION_BAR_H_ + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/autocomplete/autocomplete_edit.h" +#include "chrome/browser/autocomplete/autocomplete_popup_view.h" +#include "views/controls/button/button.h" +#include "views/view.h" + +class AutocompleteEditViewGtk; +class Browser; + +namespace views { +class ImageButton; +class ImageView; +class NativeViewHost; +} + +// This class provides a small navigation bar that includes back, forward, and +// a small text entry box. +class CompactNavigationBar : public views::View, + public views::ButtonListener, + public AutocompleteEditController, + public AutocompletePopupPositioner { + public: + explicit CompactNavigationBar(Browser* browser); + virtual ~CompactNavigationBar(); + + // Must be called before anything else, but after adding this view to the + // widget. + void Init(); + + // views::View overrides. + virtual gfx::Size GetPreferredSize(); + virtual void Layout(); + virtual void Paint(gfx::Canvas* canvas); + + private: + // views::ButtonListener implementation. + virtual void ButtonPressed(views::Button* sender); + + // AutocompleteController implementation. + virtual void OnAutocompleteAccept(const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition, + const GURL& alternate_nav_url); + virtual void OnChanged(); + virtual void OnInputInProgress(bool in_progress); + virtual SkBitmap GetFavIcon() const; + virtual std::wstring GetTitle() const; + + // AutocompletePopupPositioner implementation. + virtual gfx::Rect GetPopupBounds() const; + + Browser* browser_; + + bool initialized_; + + views::ImageButton* chrome_button_; + + views::ImageButton* back_button_; + views::ImageView* bf_separator_; + views::ImageButton* forward_button_; + + scoped_ptr<AutocompleteEditViewGtk> location_entry_; + views::NativeViewHost* location_entry_view_; + + DISALLOW_COPY_AND_ASSIGN(CompactNavigationBar); +}; + +#endif // CHROME_BROWSER_VIEWS_COMPACT_NAVIGATION_BAR_H_ diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 85b8999..84cbf69 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/chrome/browser/views/frame/status_area_view.cc b/chrome/browser/views/frame/status_area_view.cc new file mode 100644 index 0000000..c574247 --- /dev/null +++ b/chrome/browser/views/frame/status_area_view.cc @@ -0,0 +1,243 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/frame/status_area_view.h" + +#include <algorithm> + +#include "app/gfx/canvas.h" +#include "app/gfx/font.h" +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "app/theme_provider.h" +#include "base/string_util.h" +#include "base/time.h" +#include "base/timer.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/profile.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" +#include "views/controls/button/menu_button.h" +#include "views/controls/image_view.h" +#include "views/controls/menu/menu.h" +#include "views/controls/menu/simple_menu_model.h" + +namespace { + +// Number of pixels to separate adjacent status items. +const int kStatusItemSeparation = 1; + +class ClockView : public views::View { + public: + ClockView(); + virtual ~ClockView(); + + // views::View* overrides. + virtual gfx::Size GetPreferredSize(); + virtual void Paint(gfx::Canvas* canvas); + + private: + // Schedules the timer to fire at the next minute interval. + void SetNextTimer(); + + // Schedules a paint when the timer goes off. + void OnTimer(); + + gfx::Font font_; + + base::OneShotTimer<ClockView> timer_; + + DISALLOW_COPY_AND_ASSIGN(ClockView); +}; + +// Amount of slop to add into the timer to make sure we're into the next minute +// when the timer goes off. +const int kTimerSlopSeconds = 1; + +ClockView::ClockView() + : font_(ResourceBundle::GetSharedInstance().GetFont( + ResourceBundle::BaseFont)) { + SetNextTimer(); +} + +ClockView::~ClockView() { +} + +gfx::Size ClockView::GetPreferredSize() { + return gfx::Size(40, 10); +} + +void ClockView::Paint(gfx::Canvas* canvas) { + base::Time now = base::Time::Now(); + base::Time::Exploded now_exploded; + now.LocalExplode(&now_exploded); + + std::wstring time_string = StringPrintf(L"%d:%d", + now_exploded.hour, + now_exploded.minute); + canvas->DrawStringInt(time_string, font_, SK_ColorWHITE, 0, 0, + width(), height(), gfx::Canvas::TEXT_ALIGN_CENTER); +} + +void ClockView::SetNextTimer() { + // Try to set the timer to go off at the next change of the minute. We don't + // want to have the timer go off more than necessary since that will cause + // the CPU to wake up and consume power. + base::Time now = base::Time::Now(); + base::Time::Exploded exploded; + now.LocalExplode(&exploded); + + // Often this will be called at minute boundaries, and we'll actually want + // 60 seconds from now. + int seconds_left = 60 - exploded.second; + if (seconds_left == 0) + seconds_left = 60; + + // Make sure that the timer fires on the next minute. Without this, if it is + // called just a teeny bit early, then it will skip the next minute. + seconds_left += kTimerSlopSeconds; + + timer_.Start(base::TimeDelta::FromSeconds(seconds_left), + this, &ClockView::OnTimer); +} + +void ClockView::OnTimer() { + SchedulePaint(); + SetNextTimer(); +} + +} // namespace + +StatusAreaView::StatusAreaView(Browser* browser) + : browser_(browser), + battery_view_(NULL), + menu_view_(NULL) { +} + +StatusAreaView::~StatusAreaView() { +} + +void StatusAreaView::Init() { + ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); + + // Battery. + battery_view_ = new views::ImageView; + battery_view_->SetImage( + resource_bundle.GetBitmapNamed(IDR_STATUSBAR_BATTERY)); + AddChildView(battery_view_); + + // Clock. + AddChildView(new ClockView); + + // Menu. + menu_view_ = new views::MenuButton(NULL, std::wstring(), this, false); + menu_view_->SetIcon(*resource_bundle.GetBitmapNamed(IDR_STATUSBAR_MENU)); + AddChildView(menu_view_); +} + +gfx::Size StatusAreaView::GetPreferredSize() { + int result_w = kStatusItemSeparation; // Left border. + int result_h = 0; + for (int i = 0; i < GetChildViewCount(); i++) { + gfx::Size cur_size = GetChildViewAt(i)->GetPreferredSize(); + result_w += cur_size.width() + kStatusItemSeparation; + result_h = std::max(result_h, cur_size.height()); + } + result_w -= kStatusItemSeparation; // Don't have space after the last one. + + // TODO(brettw) do we need to use result_h? This is currently hardcoded + // becuase the menu button really wants to be larger, but we don't want + // the status bar to force the whole tab strip to be larger. Making it + // "small" just means that we'll expand to the height, which we want. + return gfx::Size(result_w - kStatusItemSeparation, 10); +} + +void StatusAreaView::Layout() { + int cur_x = 0; + for (int i = 0; i < GetChildViewCount(); i++) { + views::View* cur = GetChildViewAt(i); + gfx::Size cur_size = cur->GetPreferredSize(); + + // Put next in row horizontally, and center vertically. + cur->SetBounds(cur_x, (height() - cur_size.height()) / 2, + cur_size.width(), cur_size.height()); + cur_x += cur_size.width() + kStatusItemSeparation; + } +} + +void StatusAreaView::Paint(gfx::Canvas* canvas) { + ThemeProvider* theme = browser_->profile()->GetThemeProvider(); + + // Fill the background. + SkBitmap* background = theme->GetBitmapNamed(IDR_THEME_FRAME); + canvas->TileImageInt(*background, 0, 0, width(), height()); +} + +void StatusAreaView::CreateAppMenu() { + if (app_menu_contents_.get()) + return; + + 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); + app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, + IDS_NEW_INCOGNITO_WINDOW); + app_menu_contents_->AddSeparator(); + app_menu_contents_->AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR, + IDS_SHOW_BOOKMARK_BAR); + app_menu_contents_->AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); + app_menu_contents_->AddSeparator(); + app_menu_contents_->AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); + app_menu_contents_->AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, + IDS_BOOKMARK_MANAGER); + app_menu_contents_->AddItemWithStringId(IDC_SHOW_DOWNLOADS, + IDS_SHOW_DOWNLOADS); + app_menu_contents_->AddSeparator(); + app_menu_contents_->AddItemWithStringId(IDC_CLEAR_BROWSING_DATA, + IDS_CLEAR_BROWSING_DATA); + app_menu_contents_->AddItemWithStringId(IDC_IMPORT_SETTINGS, + IDS_IMPORT_SETTINGS); + app_menu_contents_->AddSeparator(); + app_menu_contents_->AddItem(IDC_OPTIONS, + l10n_util::GetStringFUTF16( + IDS_OPTIONS, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); + app_menu_contents_->AddItem(IDC_ABOUT, + l10n_util::GetStringFUTF16( + IDS_ABOUT, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); + app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); + app_menu_contents_->AddSeparator(); + app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); + + app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); +} + +bool StatusAreaView::IsCommandIdChecked(int command_id) const { + return false; +} + +bool StatusAreaView::IsCommandIdEnabled(int command_id) const { + if (command_id == IDC_RESTORE_TAB) + return browser_->CanRestoreTab(); + return browser_->command_updater()->IsCommandEnabled(command_id); +} + +bool StatusAreaView::GetAcceleratorForCommandId( + int command_id, + views::Accelerator* accelerator) { + return false; +} + +void StatusAreaView::ExecuteCommand(int command_id) { + browser_->ExecuteCommand(command_id); +} + +void StatusAreaView::RunMenu(views::View* source, const gfx::Point& pt, + gfx::NativeView hwnd) { + CreateAppMenu(); + app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); +} diff --git a/chrome/browser/views/frame/status_area_view.h b/chrome/browser/views/frame/status_area_view.h new file mode 100644 index 0000000..1be12c8 --- /dev/null +++ b/chrome/browser/views/frame/status_area_view.h @@ -0,0 +1,62 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_FRAME_STATUS_AREA_VIEW_H_ +#define CHROME_BROWSER_VIEWS_FRAME_STATUS_AREA_VIEW_H_ + +#include "base/basictypes.h" +#include "views/controls/menu/simple_menu_model.h" +#include "views/controls/menu/view_menu_delegate.h" +#include "views/view.h" + +class Browser; + +namespace views { +class MenuButton; +class ImageView; +} + +// This class is used to wrap the small informative widgets in the upper-right +// of the window title bar. It is used on ChromeOS only. +class StatusAreaView : public views::View, + public views::SimpleMenuModel::Delegate, + public views::ViewMenuDelegate { + public: + StatusAreaView(Browser* browser); + virtual ~StatusAreaView(); + + void Init(); + + // views::View* overrides. + virtual gfx::Size GetPreferredSize(); + virtual void Layout(); + virtual void Paint(gfx::Canvas* canvas); + + private: + void CreateAppMenu(); + + // views::SimpleMenuModel::Delegate implementation. + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + views::Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); + + // views::ViewMenuDelegate implementation. + virtual void RunMenu(views::View* source, const gfx::Point& pt, + gfx::NativeView hwnd); + + // The browser window that owns us. + Browser* browser_; + + views::ImageView* battery_view_; + views::MenuButton* menu_view_; + + scoped_ptr<views::SimpleMenuModel> app_menu_contents_; + scoped_ptr<views::Menu2> app_menu_menu_; + + DISALLOW_COPY_AND_ASSIGN(StatusAreaView); +}; + +#endif // CHROME_BROWSER_VIEWS_FRAME_STATUS_AREA_VIEW_H_ diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 1ab1811..3be0266 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -238,8 +238,8 @@ class LocationBarView : public LocationBar, class ShowFirstRunBubbleTask; class LocationBarImageView : public views::ImageView, - public InfoBubbleDelegate { - public: + public InfoBubbleDelegate { + public: LocationBarImageView(); virtual ~LocationBarImageView(); @@ -254,10 +254,10 @@ class LocationBarView : public LocationBar, virtual void ShowInfoBubble() = 0; - protected: + protected: void ShowInfoBubbleImpl(const std::wstring& text, SkColor text_color); - private: + private: friend class ShowInfoBubbleTask; // The currently shown info bubble if any. @@ -319,7 +319,7 @@ class LocationBarView : public LocationBar, // PageActionImageView is used to display the icon for a given PageAction // and notify the extension when the icon is clicked. class PageActionImageView : public LocationBarImageView { - public: + public: PageActionImageView( LocationBarView* owner, Profile* profile, const PageAction* page_action); @@ -339,7 +339,7 @@ class LocationBarView : public LocationBar, // A callback for when the image has loaded. void OnImageLoaded(SkBitmap* image, size_t index); - private: + private: // We load the images for the PageActions on the file thread. These tasks // help with that. class LoadImageTask; |