diff options
Diffstat (limited to 'chrome')
22 files changed, 363 insertions, 37 deletions
diff --git a/chrome/app/chrome_dll.rc b/chrome/app/chrome_dll.rc index 6e3da8f..1ca3df7 100644 --- a/chrome/app/chrome_dll.rc +++ b/chrome/app/chrome_dll.rc @@ -116,6 +116,7 @@ BEGIN VK_NUMPAD8, IDC_SELECT_TAB_7, VIRTKEY, CONTROL "B", IDC_SHOW_BOOKMARK_BAR, VIRTKEY, CONTROL "B", IDC_SHOW_BOOKMARK_MANAGER, VIRTKEY, CONTROL, SHIFT + "B", IDC_SHOW_EXTENSION_SHELF, VIRTKEY, CONTROL, ALT "J", IDC_SHOW_DOWNLOADS, VIRTKEY, CONTROL "H", IDC_SHOW_HISTORY, VIRTKEY, CONTROL "F", IDC_SHOW_APP_MENU, VIRTKEY, ALT diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index bb76758..932ab01 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -175,6 +175,7 @@ #define IDC_HELP_PAGE 40019 #define IDC_SHOW_APP_MENU 40020 #define IDC_SHOW_PAGE_MENU 40021 +#define IDC_SHOW_EXTENSION_SHELF 40022 // Spell-check // Insert any additional suggestions before _LAST; these have to be consecutive. diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 4acd94b..fe6474e 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1149,6 +1149,11 @@ void Browser::ToggleBookmarkBar() { window_->ToggleBookmarkBar(); } +void Browser::ToggleExtensionShelf() { + UserMetrics::RecordAction(L"ToggleExtensionShelf", profile_); + window_->ToggleExtensionShelf(); +} + void Browser::OpenBookmarkManager() { UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); window_->ShowBookmarkManager(); @@ -1278,6 +1283,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, 0); prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true); prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true); + prefs->RegisterBooleanPref(prefs::kShowExtensionShelf, true); } // static @@ -1435,6 +1441,7 @@ void Browser::ExecuteCommandWithDisposition( case IDC_REPORT_BUG: OpenBugReportDialog(); break; case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; + case IDC_SHOW_EXTENSION_SHELF: ToggleExtensionShelf(); break; case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; case IDC_SHOW_HISTORY: ShowHistoryTab(); break; @@ -1910,6 +1917,10 @@ void Browser::ToolbarSizeChanged(TabContents* source, bool is_animating) { } } +void Browser::ExtensionShelfSizeChanged() { + window_->SelectedTabExtensionShelfSizeChanged(); +} + void Browser::URLStarredChanged(TabContents* source, bool starred) { if (source == GetSelectedTabContents()) window_->SetStarredState(starred); @@ -2241,6 +2252,7 @@ void Browser::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_SELECT_PROFILE, true); command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); + command_updater_.UpdateCommandEnabled(IDC_SHOW_EXTENSION_SHELF, true); command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE, true); #if defined(OS_CHROMEOS) diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 63ccb0a..72e58a2 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -273,6 +273,10 @@ class Browser : public TabStripModelDelegate, // part of an animation. void ToolbarSizeChanged(bool is_animating); + // Notification that the extension shelf has changed size (as a result of + // becoming detached or attached). + void ExtensionShelfSizeChanged(); + // Replaces the state of the currently selected tab with the session // history restored from the SessionRestore system. void ReplaceRestoredTab( @@ -373,6 +377,7 @@ class Browser : public TabStripModelDelegate, void OpenBugReportDialog(); void ToggleBookmarkBar(); + void ToggleExtensionShelf(); void OpenBookmarkManager(); void ShowAppMenu(); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index a1dbe76..4a5c5ac 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -75,6 +75,9 @@ class BrowserWindow { // BrowserView. virtual void SelectedTabToolbarSizeChanged(bool is_animating) = 0; + // Notification for the Extension Shelf changing its size. + virtual void SelectedTabExtensionShelfSizeChanged() = 0; + // Inform the frame that the selected tab favicon or title has changed. Some // frames may need to refresh their title bar. virtual void UpdateTitleBar() = 0; @@ -147,6 +150,9 @@ class BrowserWindow { // Shows or hides the bookmark bar depending on its current visibility. virtual void ToggleBookmarkBar() = 0; + // Shows or hides the extension shelf depending on its current visibility. + virtual void ToggleExtensionShelf() = 0; + // Shows the About Chrome dialog box. virtual void ShowAboutChromeDialog() = 0; diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 1635602..8d1c60d 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -38,6 +38,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual BrowserWindowTesting* GetBrowserWindowTesting(); virtual StatusBubble* GetStatusBubble(); virtual void SelectedTabToolbarSizeChanged(bool is_animating); + virtual void SelectedTabExtensionShelfSizeChanged(); virtual void UpdateTitleBar(); virtual void UpdateDevTools(); virtual void FocusDevTools(); @@ -58,6 +59,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile); virtual void ToggleBookmarkBar(); + virtual void ToggleExtensionShelf(); virtual void ShowAboutChromeDialog(); virtual void ShowTaskManager(); virtual void ShowBookmarkManager(); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 13ff5bb..18900fb 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -89,6 +89,10 @@ void BrowserWindowCocoa::SelectedTabToolbarSizeChanged(bool is_animating) { // sort on Mac. } +void BrowserWindowCocoa::SelectedTabExtensionShelfSizeChanged() { + NOTIMPLEMENTED(); +} + void BrowserWindowCocoa::UpdateTitleBar() { NSString* newTitle = base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab()); @@ -183,6 +187,10 @@ void BrowserWindowCocoa::ToggleBookmarkBar() { bookmark_utils::ToggleWhenVisible(browser_->profile()); } +void BrowserWindowCocoa::ToggleExtensionShelf() { + NOTIMPLEMENTED(); +} + void BrowserWindowCocoa::AddFindBar( FindBarCocoaController* find_bar_cocoa_controller) { return [controller_ addFindBar:find_bar_cocoa_controller]; diff --git a/chrome/browser/dom_ui/dom_ui.cc b/chrome/browser/dom_ui/dom_ui.cc index 3b0472b..2088427 100644 --- a/chrome/browser/dom_ui/dom_ui.cc +++ b/chrome/browser/dom_ui/dom_ui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -18,6 +18,7 @@ DOMUI::DOMUI(TabContents* contents) : hide_favicon_(false), force_bookmark_bar_visible_(false), + force_extension_shelf_visible_(false), focus_location_bar_by_default_(false), should_hide_url_(false), link_transition_type_(PageTransition::LINK), diff --git a/chrome/browser/dom_ui/dom_ui.h b/chrome/browser/dom_ui/dom_ui.h index d5204b1..adc56ab 100644 --- a/chrome/browser/dom_ui/dom_ui.h +++ b/chrome/browser/dom_ui/dom_ui.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -61,6 +61,12 @@ class DOMUI { return force_bookmark_bar_visible_; } + // Returns true if the extension shelf should be forced to being visible + // (if it contains any items), overriding the user's preference. + bool force_extension_shelf_visible() const { + return force_extension_shelf_visible_; + } + // Returns true if the location bar should be focused by default rather than // the page contents. Some pages will want to use this to encourage the user // to type in the URL bar. @@ -116,6 +122,7 @@ class DOMUI { // bool options default to false. See the public getters for more information. bool hide_favicon_; bool force_bookmark_bar_visible_; + bool force_extension_shelf_visible_; bool focus_location_bar_by_default_; bool should_hide_url_; string16 overridden_title_; // Defaults to empty string. @@ -146,7 +153,7 @@ class DOMUI { class DOMMessageHandler { public: DOMMessageHandler() : dom_ui_(NULL) {} - virtual ~DOMMessageHandler() {}; + virtual ~DOMMessageHandler() {} // Attaches |this| to |dom_ui| in order to handle messages from it. Declared // virtual so that subclasses can do special init work as soon as the dom_ui diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 1742b0a..3f495bc 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -1538,6 +1538,7 @@ NewTabUI::NewTabUI(TabContents* contents) // Override some options on the DOM UI. hide_favicon_ = true; force_bookmark_bar_visible_ = true; + force_extension_shelf_visible_ = true; focus_location_bar_by_default_ = true; should_hide_url_ = true; overridden_title_ = WideToUTF16Hack(l10n_util::GetString(IDS_NEW_TAB_TITLE)); diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 9c295ac..e9fb7210 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -839,6 +839,10 @@ void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) { // http://code.google.com/p/chromium/issues/detail?id=12291 } +void BrowserWindowGtk::SelectedTabExtensionShelfSizeChanged() { + NOTIMPLEMENTED(); +} + void BrowserWindowGtk::UpdateTitleBar() { #if defined(OS_CHROMEOS) if (panel_controller_) @@ -968,6 +972,10 @@ void BrowserWindowGtk::ToggleBookmarkBar() { bookmark_utils::ToggleWhenVisible(browser_->profile()); } +void BrowserWindowGtk::ToggleExtensionShelf() { + NOTIMPLEMENTED(); +} + void BrowserWindowGtk::ShowAboutChromeDialog() { ShowAboutDialogForProfile(window_, browser_->profile()); } diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index d186aa5..32d3228 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -69,6 +69,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual BrowserWindowTesting* GetBrowserWindowTesting(); virtual StatusBubble* GetStatusBubble(); virtual void SelectedTabToolbarSizeChanged(bool is_animating); + virtual void SelectedTabExtensionShelfSizeChanged(); virtual void UpdateTitleBar(); virtual void UpdateDevTools(); virtual void FocusDevTools(); @@ -89,6 +90,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile); virtual void ToggleBookmarkBar(); + virtual void ToggleExtensionShelf(); virtual void ShowAboutChromeDialog(); virtual void ShowTaskManager(); virtual void ShowBookmarkManager(); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index e486f86..166c59b 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -958,6 +958,27 @@ bool TabContents::IsBookmarkBarAlwaysVisible() { return false; // Default. } +bool TabContents::IsExtensionShelfAlwaysVisible() { + // See GetDOMUIForCurrentState() comment for more info. This case is very + // similar, but for non-first loads, we want to use the committed entry. This + // is so the bookmarks bar disappears at the same time the page does. + if (controller_.GetLastCommittedEntry()) { + // Not the first load, always use the committed DOM UI. + if (render_manager_.dom_ui()) + return render_manager_.dom_ui()->force_extension_shelf_visible(); + return false; // Default. + } + + // When it's the first load, we know either the pending one or the committed + // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one + // of them will be valid, so we can just check both. + if (render_manager_.pending_dom_ui()) + return render_manager_.pending_dom_ui()->force_extension_shelf_visible(); + if (render_manager_.dom_ui()) + return render_manager_.dom_ui()->force_extension_shelf_visible(); + return false; // Default. +} + void TabContents::ToolbarSizeChanged(bool is_animating) { TabContentsDelegate* d = delegate(); if (d) diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 8848b32..3b53b52 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -424,6 +424,9 @@ class TabContents : public PageNavigator, // Returns whether the bookmark bar should be visible. virtual bool IsBookmarkBarAlwaysVisible(); + // Returns whether the extension shelf should be visible. + virtual bool IsExtensionShelfAlwaysVisible(); + // Notifies the delegate that a download started. void OnStartDownload(DownloadItem* download); diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 3ba801c..2bb567e 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -12,13 +12,16 @@ #include "base/stl_util-inl.h" #include "base/string_util.h" #include "chrome/browser/browser.h" +#include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/extensions/extension_view.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" #include "skia/ext/skia_utils.h" #include "views/controls/label.h" #include "views/screen.h" @@ -41,6 +44,23 @@ static const int kToolstripDividerWidth = 2; // Preferred height of the ExtensionShelf. static const int kShelfHeight = 29; +// Preferred height of the Extension shelf when only shown on the new tab page. +const int kNewtabShelfHeight = 57; + +// How inset the extension shelf is when displayed on the new tab page. This is +// in addition to the margins above. +static const int kNewtabHorizontalPadding = 8; +static const int kNewtabVerticalPadding = 12; + +// We need an extra margin to the left of all the toolstrips in detached mode, +// so that the first toolstrip doesn't look so squished against the rounded +// corners of the extension shelf. +static const int kNewtabExtraHorMargin = 2; +static const int kNewtabExtraVerMargin = 2; + +// How round the 'new tab' style extension shelf is. +static const int kNewtabBarRoundness = 5; + // Height of the toolstrip within the shelf. static const int kToolstripHeight = kShelfHeight - (kTopMargin + kBottomMargin); @@ -49,12 +69,12 @@ static const SkColor kBackgroundColor = SkColorSetRGB(230, 237, 244); static const SkColor kBorderColor = SkColorSetRGB(201, 212, 225); static const SkColor kDividerHighlightColor = SkColorSetRGB(247, 250, 253); -// Text colors for the handle +// Text colors for the handle. static const SkColor kHandleTextColor = SkColorSetRGB(6, 45, 117); static const SkColor kHandleTextHighlightColor = SkColorSetARGB(200, 255, 255, 255); -// Handle padding +// Handle padding. static const int kHandlePadding = 4; // TODO(erikkay) convert back to a gradient when Glen figures out the @@ -540,10 +560,20 @@ void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { //////////////////////////////////////////////////////////////////////////////// ExtensionShelf::ExtensionShelf(Browser* browser) - : model_(browser->extension_shelf_model()) { + : model_(browser->extension_shelf_model()), + browser_(browser) { model_->AddObserver(this); LoadFromModel(); EnableCanvasFlippingForRTLUI(true); + registrar_.Add(this, + NotificationType::EXTENSION_SHELF_VISIBILITY_PREF_CHANGED, + NotificationService::AllSources()); + + size_animation_.reset(new SlideAnimation(this)); + if (IsAlwaysShown()) + size_animation_->Reset(1); + else + size_animation_->Reset(0); } ExtensionShelf::~ExtensionShelf() { @@ -558,41 +588,134 @@ ExtensionShelf::~ExtensionShelf() { } void ExtensionShelf::Paint(gfx::Canvas* canvas) { + if (IsDetachedStyle()) { + // Draw the background to match the new tab page. + ThemeProvider* tp = GetThemeProvider(); + canvas->FillRectInt( + tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND), + 0, 0, width(), height()); + + // As 'hidden' according to the animation is the full in-tab state, + // we invert the value - when current_state is at '0', we expect the + // shelf to be docked. + double current_state = 1 - size_animation_->GetCurrentValue(); + + // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness. + double h_padding = static_cast<double> + (kNewtabHorizontalPadding) * current_state; + double v_padding = static_cast<double> + (kNewtabVerticalPadding) * current_state; + SkRect rect; + rect.set(SkDoubleToScalar(h_padding - 0.5), + SkDoubleToScalar(v_padding - 0.5), + SkDoubleToScalar(width() - h_padding - 0.5), + SkDoubleToScalar(height() - v_padding - 0.5)); + + double roundness = static_cast<double> + (kNewtabBarRoundness) * current_state; + + // Draw the background behind the toolstrips. + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(kBackgroundColor); + + canvas->drawRoundRect(rect, + SkDoubleToScalar(roundness), + SkDoubleToScalar(roundness), paint); + + SkRect background_rect = { + SkIntToScalar(h_padding), + SkIntToScalar(v_padding + 2), + SkIntToScalar(h_padding + 1), + SkIntToScalar(v_padding + kToolstripHeight - 3)}; + InitBackground(canvas, background_rect); + + // Draw the border around the toolstrips in the extension shelf. + SkPaint border_paint; + border_paint.setColor( + GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_NTP_HEADER)); + border_paint.setStyle(SkPaint::kStroke_Style); + border_paint.setAlpha(96); + border_paint.setAntiAlias(true); + canvas->drawRoundRect(rect, + SkDoubleToScalar(roundness), + SkDoubleToScalar(roundness), border_paint); + } else { #if 0 - // TODO(erikkay) re-enable this when Glen has the gradient values worked out. - SkPaint paint; - paint.setShader(skia::CreateGradientShader(0, - height(), - kTopGradientColor, - kBackgroundColor))->safeUnref(); - canvas->FillRectInt(0, 0, width(), height(), paint); + // TODO(erikkay) Re-enable when Glen has the gradient values worked out. + SkPaint paint; + paint.setShader(skia::CreateGradientShader(0, + height(), + kTopGradientColor, + kBackgroundColor))->safeUnref(); + canvas->FillRectInt(0, 0, width(), height(), paint); #else - canvas->FillRectInt(kBackgroundColor, 0, 0, width(), height()); + canvas->FillRectInt(kBackgroundColor, 0, 0, width(), height()); #endif - canvas->FillRectInt(kBorderColor, 0, 0, width(), 1); - canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1); + SkRect background_rect = { + SkIntToScalar(0), + SkIntToScalar(0), + SkIntToScalar(1), + SkIntToScalar(height()) + }; + InitBackground(canvas, background_rect); + + // Draw border around shelf in attached mode. If we are in detached mode + // we've already drawn the borders. + canvas->FillRectInt(kBorderColor, 0, 0, width(), 1); + canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1); + } + // Draw vertical dividers between Toolstrip items in the Extension shelf. int count = GetChildViewCount(); for (int i = 0; i < count; ++i) { int right = GetChildViewAt(i)->bounds().right() + kToolstripPadding; - int h = height() - 2; - canvas->FillRectInt(kBorderColor, right, 1, 1, h); - canvas->FillRectInt(kDividerHighlightColor, right + 1, 1, 1, h); + int y = IsDetachedStyle() ? kNewtabVerticalPadding : 1; + int h = IsDetachedStyle() ? height() - (2 * kNewtabVerticalPadding) - 1: + height() - 2; + canvas->FillRectInt(kBorderColor, right, y, 1, h); + canvas->FillRectInt(kDividerHighlightColor, right + 1, y, 1, h); } +} + +// static +void ExtensionShelf::ToggleWhenExtensionShelfVisible(Profile* profile) { + PrefService* prefs = profile->GetPrefs(); + const bool always_show = !prefs->GetBoolean(prefs::kShowExtensionShelf); - SkRect background_rect = { - SkIntToScalar(0), - SkIntToScalar(1), - SkIntToScalar(1), - SkIntToScalar(height() - 2)}; - InitBackground(canvas, background_rect); + // The user changed when the Extension Shelf is shown, update the + // preferences. + prefs->SetBoolean(prefs::kShowExtensionShelf, always_show); + prefs->ScheduleSavePersistentPrefs(); + + // And notify the notification service. + Source<Profile> source(profile); + NotificationService::current()->Notify( + NotificationType::EXTENSION_SHELF_VISIBILITY_PREF_CHANGED, + source, + NotificationService::NoDetails()); } gfx::Size ExtensionShelf::GetPreferredSize() { - if (model_->count()) - return gfx::Size(0, kShelfHeight); - return gfx::Size(0, 0); + if (!model_->count()) + return gfx::Size(0, 0); + + gfx::Size prefsize; + if (OnNewTabPage()) { + prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double> + (kNewtabShelfHeight - kShelfHeight) * + (1 - size_animation_->GetCurrentValue()))); + } else { + prefsize.set_height(static_cast<int>(static_cast<double>(kShelfHeight) * + size_animation_->GetCurrentValue())); + } + + // Width doesn't matter, we're always given a width based on the browser + // size. + prefsize.set_width(1); + + return prefsize; } void ExtensionShelf::ChildPreferredSizeChanged(View* child) { @@ -610,9 +733,21 @@ void ExtensionShelf::Layout() { int x = kLeftMargin; int y = kTopMargin; - int content_height = height() - kTopMargin - kBottomMargin; + int content_height = kShelfHeight - kTopMargin - kBottomMargin; int max_x = width() - kRightMargin; + int max_x_before = max_x; + + if (OnNewTabPage()) { + double current_state = 1 - size_animation_->GetCurrentValue(); + x += static_cast<int>(static_cast<double> + (kNewtabHorizontalPadding + kNewtabExtraHorMargin) * current_state); + y += static_cast<int>(static_cast<double> + (kNewtabVerticalPadding + kNewtabExtraVerMargin) * current_state); + max_x -= static_cast<int>(static_cast<double> + (kNewtabHorizontalPadding) * current_state); + } + int count = model_->count(); for (int i = 0; i < count; ++i) { x += kToolstripPadding; // left padding @@ -728,6 +863,35 @@ void ExtensionShelf::ShelfModelDeleting() { model_ = NULL; } +void ExtensionShelf::AnimationProgressed(const Animation* animation) { + if (browser_) + browser_->ExtensionShelfSizeChanged(); +} + +void ExtensionShelf::AnimationEnded(const Animation* animation) { + if (browser_) + browser_->ExtensionShelfSizeChanged(); + + SchedulePaint(); +} + +void ExtensionShelf::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSION_SHELF_VISIBILITY_PREF_CHANGED: { + if (IsAlwaysShown()) + size_animation_->Show(); + else + size_animation_->Hide(); + break; + } + default: + NOTREACHED(); + break; + } +} + void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { Toolstrip *toolstrip = ToolstripForView(view); if (toolstrip) @@ -841,3 +1005,17 @@ void ExtensionShelf::LoadFromModel() { for (int i = 0; i < count; ++i) ToolstripInsertedAt(model_->ToolstripAt(i).host, i); } + +bool ExtensionShelf::IsDetachedStyle() { + return OnNewTabPage() && (size_animation_->GetCurrentValue() != 1); +} + +bool ExtensionShelf::IsAlwaysShown() { + Profile* profile = browser_->profile(); + return profile->GetPrefs()->GetBoolean(prefs::kShowExtensionShelf); +} + +bool ExtensionShelf::OnNewTabPage() { + return (browser_ && browser_->GetSelectedTabContents() && + browser_->GetSelectedTabContents()->IsExtensionShelfAlwaysVisible()); +} diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h index e0dbe5d..08f3d1c 100644 --- a/chrome/browser/views/extensions/extension_shelf.h +++ b/chrome/browser/views/extensions/extension_shelf.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ #include "app/gfx/canvas.h" +#include "app/slide_animation.h" #include "base/task.h" #include "chrome/browser/extensions/extension_shelf_model.h" #include "chrome/browser/extensions/extensions_service.h" @@ -21,7 +22,9 @@ namespace views { // A shelf that contains Extension toolstrips. class ExtensionShelf : public views::View, public ExtensionContainer, - public ExtensionShelfModelObserver { + public ExtensionShelfModelObserver, + public AnimationDelegate, + public NotificationObserver { public: explicit ExtensionShelf(Browser* browser); virtual ~ExtensionShelf(); @@ -29,6 +32,12 @@ class ExtensionShelf : public views::View, // Get the current model. ExtensionShelfModel* model() { return model_; } + // Returns whether the extension shelf is detached from the Chrome frame. + bool IsDetachedStyle(); + + // Toggles a preference for whether to always show the extension shelf. + static void ToggleWhenExtensionShelfVisible(Profile* profile); + // View virtual void Paint(gfx::Canvas* canvas); virtual gfx::Size GetPreferredSize(); @@ -55,6 +64,15 @@ class ExtensionShelf : public views::View, virtual void ShelfModelReloaded(); virtual void ShelfModelDeleting(); + // AnimationDelegate + virtual void AnimationProgressed(const Animation* animation); + virtual void AnimationEnded(const Animation* animation); + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + protected: // View virtual void ChildPreferredSizeChanged(View* child); @@ -90,15 +108,30 @@ class ExtensionShelf : public views::View, // Loads initial state from |model_|. void LoadFromModel(); + // Returns whether the extension shelf always shown (checks pref value). + bool IsAlwaysShown(); + + // Returns whether the extension shelf is being displayed over the new tab + // page. + bool OnNewTabPage(); + + NotificationRegistrar registrar_; + // Background bitmap to draw under extension views. SkBitmap background_; + // The browser this extension shelf belongs to. + Browser* browser_; + // The model representing the toolstrips on the shelf. ExtensionShelfModel* model_; // Storage of strings needed for accessibility. std::wstring accessible_name_; + // Animation controlling showing and hiding of the shelf. + scoped_ptr<SlideAnimation> size_animation_; + DISALLOW_COPY_AND_ASSIGN(ExtensionShelf); }; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 6dc9adf..ae02466 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -655,6 +655,10 @@ void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) { } } +void BrowserView::SelectedTabExtensionShelfSizeChanged() { + Layout(); +} + void BrowserView::UpdateTitleBar() { frame_->GetWindow()->UpdateWindowTitle(); if (ShouldShowWindowIcon()) @@ -849,6 +853,10 @@ void BrowserView::ToggleBookmarkBar() { bookmark_utils::ToggleWhenVisible(browser_->profile()); } +void BrowserView::ToggleExtensionShelf() { + ExtensionShelf::ToggleWhenExtensionShelfVisible(browser_->profile()); +} + void BrowserView::ShowAboutChromeDialog() { browser::ShowAboutChromeView(GetWidget(), browser_->profile()); } @@ -1398,8 +1406,7 @@ void BrowserView::Layout() { int top = LayoutTabStrip(); top = LayoutToolbar(top); top = LayoutBookmarkAndInfoBars(top); - int bottom = LayoutExtensionShelf(); - bottom = LayoutDownloadShelf(bottom); + int bottom = LayoutExtensionAndDownloadShelves(); LayoutTabContents(top, bottom); // This must be done _after_ we lay out the TabContents since this code calls // back into us to find the bounding box the find bar must be laid out within, @@ -1611,6 +1618,22 @@ void BrowserView::LayoutTabContents(int top, int bottom) { contents_split_->SetBounds(0, top, width(), bottom - top); } +int BrowserView::LayoutExtensionAndDownloadShelves() { + // If we're showing the Bookmark bar in detached style, then we need to show + // any Info bar _above_ the Bookmark bar, since the Bookmark bar is styled + // to look like it's part of the page. + int bottom = height(); + if (extension_shelf_) { + if (extension_shelf_->IsDetachedStyle()) { + bottom = LayoutDownloadShelf(bottom); + return LayoutExtensionShelf(bottom); + } + // Otherwise, Extension shelf first, Download shelf second. + bottom = LayoutExtensionShelf(bottom); + } + return LayoutDownloadShelf(bottom); +} + int BrowserView::LayoutDownloadShelf(int bottom) { // Re-layout the shelf either if it is visible or if it's close animation // is currently running. @@ -1639,8 +1662,7 @@ void BrowserView::LayoutStatusBubble(int top) { status_bubble_->SetBounds(origin.x(), origin.y(), width() / 3, height); } -int BrowserView::LayoutExtensionShelf() { - int bottom = height(); +int BrowserView::LayoutExtensionShelf(int bottom) { if (extension_shelf_) { bool visible = browser_->SupportsWindowFeature( Browser::FEATURE_EXTENSIONSHELF); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index d978c51..2fd3d4a 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -208,6 +208,7 @@ class BrowserView : public BrowserWindow, virtual BrowserWindowTesting* GetBrowserWindowTesting(); virtual StatusBubble* GetStatusBubble(); virtual void SelectedTabToolbarSizeChanged(bool is_animating); + virtual void SelectedTabExtensionShelfSizeChanged(); virtual void UpdateTitleBar(); virtual void UpdateDevTools(); virtual void FocusDevTools(); @@ -229,6 +230,7 @@ class BrowserView : public BrowserWindow, virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile); virtual void ToggleBookmarkBar(); + virtual void ToggleExtensionShelf(); virtual void ShowAboutChromeDialog(); virtual void ShowTaskManager(); virtual void ShowBookmarkManager(); @@ -344,13 +346,15 @@ class BrowserView : public BrowserWindow, // Layout the TabContents container, between the coordinates |top| and // |bottom|. void LayoutTabContents(int top, int bottom); + int LayoutExtensionAndDownloadShelves(); + // Layout the Extension Shelf, returns the coordinate of the top of the + // control, for laying out the previous control. + int LayoutExtensionShelf(int bottom); // Layout the Download Shelf, returns the coordinate of the top of the // control, for laying out the previous control. int LayoutDownloadShelf(int bottom); // Layout the Status Bubble. void LayoutStatusBubble(int top); - // Layout the Extension Shelf - int LayoutExtensionShelf(); // Prepare to show the Bookmark Bar for the specified TabContents. Returns // true if the Bookmark Bar can be shown (i.e. it's supported for this diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 7c7140f..97ec361 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -386,6 +386,11 @@ class NotificationType { // NoDetails. BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, + // This is sent when the user's preference (for when the extension shelf + // should be shown) changes. The source is the profile, and the details are + // NoDetails. + EXTENSION_SHELF_VISIBILITY_PREF_CHANGED, + // Used to monitor web cache usage by notifying whenever the // CacheManagerHost observes new UsageStats. The source will be the // RenderProcessHost that corresponds to the new statistics. Details are a diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 6395c28..a8afd36c 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -537,6 +537,9 @@ const wchar_t kNumKeywords[] = L"user_experience_metrics.num_keywords"; const wchar_t kDisableExtensions[] = L"extensions.disabled"; const wchar_t kEnableUserScripts[] = L"extensions.user_scripts_enabled"; +// Boolean which specifies whether the Extension Shelf is visible on all tabs. +const wchar_t kShowExtensionShelf[] = L"extensions.shelf.show_on_all_tabs"; + // Time of the last, and next scheduled, extensions auto-update checks. const wchar_t kLastExtensionsUpdateCheck[] = L"extensions.autoupdate.last_check"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index ebff4fc..7432559 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -202,6 +202,7 @@ extern const wchar_t kNumKeywords[]; extern const wchar_t kDisableExtensions[]; extern const wchar_t kEnableUserScripts[]; +extern const wchar_t kShowExtensionShelf[]; extern const wchar_t kLastExtensionsUpdateCheck[]; extern const wchar_t kNextExtensionsUpdateCheck[]; diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index a7a06db..1575c61 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -32,6 +32,7 @@ class TestBrowserWindow : public BrowserWindow { virtual BrowserWindowTesting* GetBrowserWindowTesting() { return NULL; } virtual StatusBubble* GetStatusBubble() { return NULL; } virtual void SelectedTabToolbarSizeChanged(bool is_animating) {} + virtual void SelectedTabExtensionShelfSizeChanged() {} virtual void UpdateTitleBar() {} virtual void UpdateDevTools() {} virtual void FocusDevTools() {} @@ -56,6 +57,7 @@ class TestBrowserWindow : public BrowserWindow { virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) {} virtual void ToggleBookmarkBar() {} + virtual void ToggleExtensionShelf() {} virtual void ShowAboutChromeDialog() {} virtual void ShowTaskManager() {} virtual void ShowBookmarkManager() {} |