Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6538)

Unified Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 6913026: Compact Navigation prototype (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_view.cc
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index dfc2798390f1d410c8c669c58d2b0a5e5ef83bc9..700e226423af487c69f98eac176fcd995e475e31 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -45,6 +45,10 @@
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
+#include "chrome/browser/ui/views/compact_nav/compact_location_bar_view.h"
+#include "chrome/browser/ui/views/compact_nav/compact_location_bar_view_host.h"
+#include "chrome/browser/ui/views/compact_nav/compact_navigation_bar.h"
+#include "chrome/browser/ui/views/compact_nav/compact_options_bar.h"
#include "chrome/browser/ui/views/default_search_view.h"
#include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
#include "chrome/browser/ui/views/download/download_shelf_view.h"
@@ -78,6 +82,7 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
+#include "grit/theme_resources_standard.h"
#include "grit/webkit_resources.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/l10n/l10n_util.h"
@@ -155,6 +160,63 @@ static gfx::NativeWindow GetNormalBrowserWindowForBrowser(Browser* browser,
}
#endif // defined(OS_CHROMEOS)
+namespace {
+// A space we insert between the tabstrip and the content in
+// Compact mode.
+class Spacer : public views::View {
+ SkBitmap* background_;
Peter Kasting 2011/05/03 18:04:24 Nit: Put this in a section.
SteveT 2011/05/06 18:48:43 Spacer class was removed since we eventually ended
+ public:
+ explicit Spacer(SkBitmap* bitmap) : background_(bitmap) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Spacer);
+};
+
+// TODO(sky): wire this back up.
+/*
+// A chromeos implementation of Tab that shows the compact location bar.
+class ChromeosTab : public Tab {
Peter Kasting 2011/05/03 18:04:24 Nit: Wouldn't ChromeOSTab be better? (2 classes)
SteveT 2011/05/06 18:48:43 Actually, this commented out code that sky/oshima
+ public:
+ ChromeosTab(TabStrip* tab_strip, chromeos::BrowserView* browser_view)
+ : Tab(tab_strip),
+ browser_view_(browser_view) {
+ }
+ virtual ~ChromeosTab() {}
+
+ // Overridden from views::View.
+ virtual void OnMouseEntered(const views::MouseEvent& event) {
Peter Kasting 2011/05/03 18:04:24 Nit: Use OVERRIDE (here and elsewhere) I also sug
SteveT 2011/05/06 18:48:43 Deleted, as above.
+ TabRenderer::OnMouseEntered(event);
+ browser_view_->ShowCompactLocationBarUnderSelectedTab();
+ }
+
+ private:
+ chromeos::BrowserView* browser_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeosTab);
+};
+
+// A Tabstrip that uses ChromeosTab as a Tab implementation.
+class ChromeosTabStrip : public TabStrip {
+ public:
+ ChromeosTabStrip(TabStripModel* model, chromeos::BrowserView* browser_view)
+ : TabStrip(model), browser_view_(browser_view) {
+ }
+ virtual ~ChromeosTabStrip() {}
+
+ protected:
+ // Overridden from TabStrip.
+ virtual Tab* CreateTab() {
+ return new ChromeosTab(this, browser_view_);
+ }
+
+ private:
+ chromeos::BrowserView* browser_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeosTabStrip);
+};
+*/
+}
+
///////////////////////////////////////////////////////////////////////////////
// BookmarkExtensionBackground, private:
// This object serves as the views::Background object which is used to layout
@@ -304,6 +366,9 @@ BrowserView::BrowserView(Browser* browser)
active_bookmark_bar_(NULL),
tabstrip_(NULL),
toolbar_(NULL),
+ compact_navigation_bar_(NULL),
+ compact_options_bar_(NULL),
+ spacer_(NULL),
infobar_container_(NULL),
sidebar_container_(NULL),
sidebar_split_(NULL),
@@ -378,6 +443,11 @@ BrowserView* BrowserView::GetBrowserViewForNativeWindow(
gfx::Rect BrowserView::GetToolbarBounds() const {
gfx::Rect toolbar_bounds(toolbar_->bounds());
+ // In compact navigation mode, the spacer essentially replaces the toolbar.
+ // We must provide it's height in order to have the client area divider paint
+ // properly.
+ if (UseCompactNavigationBar())
+ toolbar_bounds = spacer_->bounds();
if (toolbar_bounds.IsEmpty())
return toolbar_bounds;
// When using vertical tabs, the toolbar appears to extend behind the tab
@@ -401,6 +471,14 @@ gfx::Rect BrowserView::GetFindBarBoundingBox() const {
return GetBrowserViewLayout()->GetFindBarBoundingBox();
}
+gfx::Rect BrowserView::GetCompactNavigationBarBounds() const {
+ return compact_navigation_bar_->bounds();
+}
+
+gfx::Rect BrowserView::GetCompactOptionsBarBounds() const {
+ return compact_options_bar_->bounds();
+}
+
int BrowserView::GetTabStripHeight() const {
// We want to return tabstrip_->height(), but we might be called in the midst
// of layout, when that hasn't yet been updated to reflect the current state.
@@ -432,6 +510,10 @@ bool BrowserView::UseVerticalTabs() const {
return browser_->tabstrip_model()->delegate()->UseVerticalTabs();
}
+bool BrowserView::UseCompactNavigationBar() const {
+ return browser_->tabstrip_model()->delegate()->UseCompactNavigationBar();
+}
+
bool BrowserView::IsOffTheRecord() const {
return browser_->profile()->IsOffTheRecord();
}
@@ -704,7 +786,7 @@ void BrowserView::UpdateLoadingAnimations(bool should_animate) {
}
void BrowserView::SetStarredState(bool is_starred) {
- toolbar_->location_bar()->SetStarToggled(is_starred);
+ GetLocationBarView()->SetStarToggled(is_starred);
}
gfx::Rect BrowserView::GetRestoredBounds() const {
@@ -751,11 +833,16 @@ void BrowserView::RestoreFocus() {
}
LocationBar* BrowserView::GetLocationBar() const {
- return toolbar_->location_bar();
+ return GetLocationBarView();
}
void BrowserView::SetFocusToLocationBar(bool select_all) {
- LocationBarView* location_bar = toolbar_->location_bar();
+ if (UseCompactNavigationBar()) {
+ // If focus ever goes to the location bar, we should make sure it is shown
+ // in compact mode. This includes all accelerators that move focus there.
+ ShowCompactLocationBarUnderSelectedTab();
+ }
+ LocationBarView* location_bar = GetLocationBarView();
if (location_bar->IsFocusableInRootView()) {
// Location bar got focus.
location_bar->FocusLocation(select_all);
@@ -769,20 +856,41 @@ void BrowserView::SetFocusToLocationBar(bool select_all) {
}
void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
- toolbar_->reload_button()->ChangeMode(
+ ReloadButton* reload_button = NULL;
+ if (UseCompactNavigationBar()) {
+ reload_button = compact_location_bar_view_host_->
+ GetCompactLocationBarView()->reload_button();
+ } else {
+ reload_button = toolbar_->reload_button();
+ }
+ reload_button->ChangeMode(
is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force);
}
void BrowserView::UpdateToolbar(TabContentsWrapper* contents,
bool should_restore_state) {
- toolbar_->Update(contents->tab_contents(), should_restore_state);
+ if (UseCompactNavigationBar()) {
+ if (compact_location_bar_view_host_->IsVisible()) {
+ compact_location_bar_view_host_->Update(
+ should_restore_state ? contents->tab_contents() : NULL, true);
+ }
+ } else {
+ toolbar_->Update(contents->tab_contents(), should_restore_state);
+ }
}
void BrowserView::FocusToolbar() {
// Start the traversal within the main toolbar, passing it the storage id
// of the view where focus should be returned if the user exits the toolbar.
SaveFocusedView();
- toolbar_->SetPaneFocus(last_focused_view_storage_id_, NULL);
+ if (UseCompactNavigationBar()) {
+ if (!compact_location_bar_view_host_->IsVisible())
+ compact_location_bar_view_host_->Update(browser()->active_index(), true);
+ compact_location_bar_view_host_->GetCompactLocationBarView()->SetPaneFocus(
+ last_focused_view_storage_id_, NULL);
+ } else {
+ toolbar_->SetPaneFocus(last_focused_view_storage_id_, NULL);
+ }
}
void BrowserView::FocusBookmarksToolbar() {
@@ -804,6 +912,7 @@ void BrowserView::FocusAppMenu() {
RestoreFocus();
} else {
SaveFocusedView();
+ // TODO(mad): find out how to add this to compact nav view.
toolbar_->SetPaneFocusAndFocusAppMenu(last_focused_view_storage_id_);
}
}
@@ -903,8 +1012,12 @@ bool BrowserView::IsTabStripEditable() const {
}
bool BrowserView::IsToolbarVisible() const {
- return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
- browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
+ if (UseCompactNavigationBar()) {
+ return false;
+ } else {
+ return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
+ browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
+ }
}
void BrowserView::DisableInactiveFrame() {
@@ -948,6 +1061,12 @@ void BrowserView::ShowUpdateChromeDialog() {
UpdateRecommendedMessageBox::ShowMessageBox(GetWindow()->GetNativeWindow());
}
+void BrowserView::ShowCompactLocationBarUnderSelectedTab() {
+ if (!UseCompactNavigationBar())
+ return;
+ compact_location_bar_view_host_->Update(browser()->active_index(), true);
+}
+
void BrowserView::ShowTaskManager() {
browser::ShowTaskManager();
}
@@ -957,7 +1076,7 @@ void BrowserView::ShowBackgroundPages() {
}
void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
- toolbar_->location_bar()->ShowStarBubble(url, !already_bookmarked);
+ GetLocationBarView()->ShowStarBubble(url, !already_bookmarked);
}
void BrowserView::SetDownloadShelfVisible(bool visible) {
@@ -1058,6 +1177,7 @@ void BrowserView::ShowPageInfo(Profile* profile,
}
void BrowserView::ShowAppMenu() {
+ // TODO(mad): find out how to add this to compact nav view.
toolbar_->app_menu()->Activate();
}
@@ -1153,6 +1273,16 @@ void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
#endif
}
+void BrowserView::ToggleUseCompactNavigationBar() {
+ bool use_compact_navigation_bar = UseCompactNavigationBar();
+ // Compact Navigation Bar only works with horizontal tabs for now!
+ if (use_compact_navigation_bar && UseVerticalTabs())
+ browser()->ExecuteCommand(IDC_TOGGLE_VERTICAL_TABS);
+ compact_location_bar_view_host_->SetEnabled(use_compact_navigation_bar);
+ compact_location_bar_view_host_->Hide(!use_compact_navigation_bar);
+ Layout();
+}
+
// TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always
// enabled in the page menu regardless of whether the command will do
// anything. When someone selects the menu item, we just act as if they hit
@@ -1176,6 +1306,10 @@ void BrowserView::Paste() {
}
void BrowserView::ToggleTabStripMode() {
+ // Compact Navigation Bar only works with horizontal tabs for now!
+ if (UseVerticalTabs() && UseCompactNavigationBar())
+ browser()->ExecuteCommand(IDC_COMPACT_NAVBAR);
+
InitTabStrip(browser_->tabstrip_model());
frame_->TabStripDisplayModeChanged();
}
@@ -1239,7 +1373,12 @@ BookmarkBarView* BrowserView::GetBookmarkBarView() const {
}
LocationBarView* BrowserView::GetLocationBarView() const {
- return toolbar_->location_bar();
+ if (UseCompactNavigationBar()) {
+ return compact_location_bar_view_host_->GetCompactLocationBarView()->
+ location_bar_view();
+ } else {
+ return toolbar_ ? toolbar_->location_bar() : NULL;
+ }
}
views::View* BrowserView::GetTabContentsContainerView() const {
@@ -1552,8 +1691,9 @@ void BrowserView::OnWidgetMove() {
browser::HideBookmarkBubbleView();
// Close the omnibox popup, if any.
- if (toolbar_ && toolbar_->location_bar())
- toolbar_->location_bar()->location_entry()->ClosePopup();
+ LocationBarView* location_bar_view = GetLocationBarView();
+ if (location_bar_view)
+ location_bar_view->location_entry()->ClosePopup();
}
///////////////////////////////////////////////////////////////////////////////
@@ -1830,6 +1970,21 @@ void BrowserView::Init() {
browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get());
}
#endif
+ compact_location_bar_view_host_.reset(new CompactLocationBarViewHost(this));
+ compact_navigation_bar_ = new CompactNavigationBar(this);
+ compact_navigation_bar_->SetID(VIEW_ID_COMPACT_NAV_BAR);
+ AddChildView(compact_navigation_bar_);
+ compact_navigation_bar_->Init();
+ compact_options_bar_ = new CompactOptionsBar(this);
+ compact_options_bar_->SetID(VIEW_ID_COMPACT_OPT_BAR);
+ AddChildView(compact_options_bar_);
+ compact_options_bar_->Init();
+
+ ThemeProvider* theme_provider = frame()->GetThemeProviderForFrame();
+ SkBitmap* theme_toolbar = theme_provider->GetBitmapNamed(IDR_THEME_TOOLBAR);
+ spacer_ = new Spacer(theme_toolbar);
+ spacer_->SetID(VIEW_ID_SPACER);
+ AddChildView(spacer_);
// We're now initialized and ready to process Layout requests.
ignore_layout_ = false;
@@ -2098,7 +2253,7 @@ void BrowserView::ProcessFullscreen(bool fullscreen) {
// * Ignoring all intervening Layout() calls, which resize the webpage and
// thus are slow and look ugly
ignore_layout_ = true;
- LocationBarView* location_bar = toolbar_->location_bar();
+ LocationBarView* location_bar = GetLocationBarView();
#if defined(OS_WIN)
OmniboxViewWin* omnibox_view =
static_cast<OmniboxViewWin*>(location_bar->location_entry());

Powered by Google App Engine
This is Rietveld 408576698