summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 19:20:08 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-23 19:20:08 +0000
commitead68fa16bb57be280d19b30e6b592fd8f6192a0 (patch)
treeb07766252903cb7bffde4d96c232edce56da6471 /chrome/browser
parent722ec18ab0d520ff1b029bb961a92618c39f9f2d (diff)
downloadchromium_src-ead68fa16bb57be280d19b30e6b592fd8f6192a0.zip
chromium_src-ead68fa16bb57be280d19b30e6b592fd8f6192a0.tar.gz
chromium_src-ead68fa16bb57be280d19b30e6b592fd8f6192a0.tar.bz2
Add dynamic badge listing the # background pages on the wrench menu.
Add badge_util::DrawBadgeIconOverlay() which draws a dynamic text overlay over a badge icon. Add Windows support for rendering a dynamic icon showing the # background pages to the wrench menu. BUG=64144 TEST=Enable background page, look at wrench menu Review URL: http://codereview.chromium.org/5299001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67130 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/ui/views/toolbar_view.cc27
-rw-r--r--chrome/browser/wrench_menu_model.cc37
2 files changed, 51 insertions, 13 deletions
diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc
index 76e08b5..a692dff 100644
--- a/chrome/browser/ui/views/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar_view.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/i18n/number_formatting.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/accessibility/browser_accessibility_state.h"
#include "chrome/browser/background_page_tracker.h"
@@ -20,6 +21,7 @@
#include "chrome/browser/views/event_utils.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/wrench_menu_model.h"
+#include "chrome/common/badge_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "gfx/canvas.h"
@@ -70,6 +72,15 @@ static const int kPopupTopSpacingNonGlass = 3;
static const int kPopupBottomSpacingNonGlass = 2;
static const int kPopupBottomSpacingGlass = 1;
+// The size of the font to use in the text overlay for the background page
+// badge.
+static const float kBadgeTextFontSize = 9.0;
+
+// Margins for the wrench menu badges (badge is placed in the upper right
+// corner of the wrench menu with the specified margins).
+static const int kBadgeRightMargin = 2;
+static const int kBadgeTopMargin = 2;
+
static SkBitmap* kPopupBackgroundEdge = NULL;
////////////////////////////////////////////////////////////////////////////////
@@ -726,7 +737,8 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) {
SkBitmap badge;
// Only one badge can be active at any given time. The Upgrade notification
- // is deemed most important, then the DLL conflict badge.
+ // is deemed most important, then the temporary background page badge,
+ // then the DLL conflict badge.
if (IsUpgradeRecommended()) {
badge = *tp->GetBitmapNamed(IDR_UPDATE_BADGE);
} else if (ShouldShowBackgroundPageBadge()) {
@@ -741,8 +753,6 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) {
NOTREACHED();
}
- static const int kBadgeRightMargin = 2;
- static const int kBadgeTopMargin = 2;
canvas->DrawBitmapInt(badge,
icon.width() - badge.width() - kBadgeRightMargin,
kBadgeTopMargin);
@@ -752,6 +762,13 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) {
SkBitmap ToolbarView::GetBackgroundPageBadge() {
ThemeProvider* tp = GetThemeProvider();
- // TODO(atwilson): Add code to display current number of pages in badge.
- return *tp->GetBitmapNamed(IDR_BACKGROUND_BADGE);
+ SkBitmap* badge = tp->GetBitmapNamed(IDR_BACKGROUND_BADGE);
+ string16 badge_text = base::FormatNumber(
+ BackgroundPageTracker::GetSingleton()->GetBackgroundPageCount());
+ return badge_util::DrawBadgeIconOverlay(
+ *badge,
+ kBadgeTextFontSize,
+ badge_text,
+ l10n_util::GetStringUTF16(IDS_BACKGROUND_PAGE_BADGE_OVERFLOW));
}
+
diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc
index 87ed089..9c84667 100644
--- a/chrome/browser/wrench_menu_model.cc
+++ b/chrome/browser/wrench_menu_model.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/upgrade_detector.h"
+#include "chrome/common/badge_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_source.h"
@@ -55,6 +56,22 @@
#include "chrome/browser/enumerate_modules_model_win.h"
#endif
+// The size of the font used for dynamic text overlays on menu items.
+const float kMenuBadgeFontSize = 12.0;
+
+namespace {
+SkBitmap GetBackgroundPageIcon() {
+ string16 pages = base::FormatNumber(
+ BackgroundPageTracker::GetSingleton()->GetBackgroundPageCount());
+ return badge_util::DrawBadgeIconOverlay(
+ *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_BACKGROUND_MENU),
+ kMenuBadgeFontSize,
+ pages,
+ l10n_util::GetStringUTF16(IDS_BACKGROUND_PAGE_BADGE_OVERFLOW));
+}
+
+} // namespace
+
////////////////////////////////////////////////////////////////////////////////
// EncodingMenuModel
@@ -334,11 +351,15 @@ void WrenchMenuModel::Observe(NotificationType type,
const NotificationDetails& details) {
switch (type.value) {
case NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED: {
- bool show_badge = BackgroundPageTracker::GetSingleton()->
- GetUnacknowledgedBackgroundPageCount() > 0;
- SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES),
- show_badge ? *ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_BACKGROUND_MENU) : SkBitmap());
+ int num_pages = BackgroundPageTracker::GetSingleton()->
+ GetUnacknowledgedBackgroundPageCount();
+ if (num_pages > 0) {
+ SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES),
+ GetBackgroundPageIcon());
+ } else {
+ // Just set a blank icon (no icon).
+ SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES), SkBitmap());
+ }
break;
}
case NotificationType::ZOOM_LEVEL_CHANGED:
@@ -461,12 +482,12 @@ void WrenchMenuModel::Build() {
*rb.GetBitmapNamed(IDR_CONFLICT_MENU));
#endif
- // Add an icon to the View Background Pages item if t
+ // Add an icon to the View Background Pages item if there are unacknowledged
+ // pages.
if (BackgroundPageTracker::GetSingleton()->
GetUnacknowledgedBackgroundPageCount() > 0) {
- // TODO(atwilson): Add code to display current number of pages in badge.
SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES),
- *rb.GetBitmapNamed(IDR_BACKGROUND_MENU));
+ GetBackgroundPageIcon());
}
AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);