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

Side by Side Diff: chrome/browser/ui/views/toolbar_view.cc

Issue 10453101: Convert most of the rest of chrome to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar_view.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #endif 73 #endif
74 74
75 const int kPopupTopSpacingNonGlass = 3; 75 const int kPopupTopSpacingNonGlass = 3;
76 const int kPopupBottomSpacingNonGlass = 2; 76 const int kPopupBottomSpacingNonGlass = 2;
77 const int kPopupBottomSpacingGlass = 1; 77 const int kPopupBottomSpacingGlass = 1;
78 78
79 // Top margin for the wrench menu badges (badge is placed in the upper right 79 // Top margin for the wrench menu badges (badge is placed in the upper right
80 // corner of the wrench menu). 80 // corner of the wrench menu).
81 const int kBadgeTopMargin = 2; 81 const int kBadgeTopMargin = 2;
82 82
83 SkBitmap* kPopupBackgroundEdge = NULL; 83 gfx::ImageSkia* kPopupBackgroundEdge = NULL;
84 84
85 // The omnibox border has some additional shadow, so we use less vertical 85 // The omnibox border has some additional shadow, so we use less vertical
86 // spacing than ToolbarView::kVertSpacing. 86 // spacing than ToolbarView::kVertSpacing.
87 int location_bar_vert_spacing() { 87 int location_bar_vert_spacing() {
88 static int value = -1; 88 static int value = -1;
89 if (value == -1) { 89 if (value == -1) {
90 switch (ui::GetDisplayLayout()) { 90 switch (ui::GetDisplayLayout()) {
91 case ui::LAYOUT_ASH: 91 case ui::LAYOUT_ASH:
92 case ui::LAYOUT_DESKTOP: 92 case ui::LAYOUT_DESKTOP:
93 value = 4; 93 value = 4;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); 131 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
132 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); 132 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
133 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); 133 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
134 134
135 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? 135 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ?
136 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; 136 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION;
137 137
138 if (!kPopupBackgroundEdge) { 138 if (!kPopupBackgroundEdge) {
139 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 139 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
140 kPopupBackgroundEdge = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_EDGE); 140 kPopupBackgroundEdge = rb.GetImageSkiaNamed(IDR_LOCATIONBG_POPUPMODE_EDGE);
141 } 141 }
142 142
143 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 143 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
144 content::NotificationService::AllSources()); 144 content::NotificationService::AllSources());
145 #if defined(OS_WIN) 145 #if defined(OS_WIN)
146 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED, 146 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
147 content::NotificationService::AllSources()); 147 content::NotificationService::AllSources());
148 #endif 148 #endif
149 registrar_.Add(this, 149 registrar_.Add(this,
150 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE, 150 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 269
270 void ToolbarView::AddMenuListener(views::MenuListener* listener) { 270 void ToolbarView::AddMenuListener(views::MenuListener* listener) {
271 menu_listeners_.AddObserver(listener); 271 menu_listeners_.AddObserver(listener);
272 } 272 }
273 273
274 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { 274 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) {
275 menu_listeners_.RemoveObserver(listener); 275 menu_listeners_.RemoveObserver(listener);
276 } 276 }
277 277
278 SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { 278 gfx::ImageSkia ToolbarView::GetAppMenuIcon(
279 views::CustomButton::ButtonState state) {
279 ui::ThemeProvider* tp = GetThemeProvider(); 280 ui::ThemeProvider* tp = GetThemeProvider();
280 281
281 int id = 0; 282 int id = 0;
282 switch (state) { 283 switch (state) {
283 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break; 284 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break;
284 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break; 285 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break;
285 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break; 286 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break;
286 default: NOTREACHED(); break; 287 default: NOTREACHED(); break;
287 } 288 }
288 SkBitmap icon = *tp->GetBitmapNamed(id); 289 gfx::ImageSkia icon = *tp->GetImageSkiaNamed(id);
289 290
290 #if defined(OS_WIN) 291 #if defined(OS_WIN)
291 // Keep track of whether we were showing the badge before, so we don't send 292 // Keep track of whether we were showing the badge before, so we don't send
292 // multiple UMA events for example when multiple Chrome windows are open. 293 // multiple UMA events for example when multiple Chrome windows are open.
293 static bool incompatibility_badge_showing = false; 294 static bool incompatibility_badge_showing = false;
294 // Save the old value before resetting it. 295 // Save the old value before resetting it.
295 bool was_showing = incompatibility_badge_showing; 296 bool was_showing = incompatibility_badge_showing;
296 incompatibility_badge_showing = false; 297 incompatibility_badge_showing = false;
297 #endif 298 #endif
298 299
299 int error_badge_id = GlobalErrorServiceFactory::GetForProfile( 300 int error_badge_id = GlobalErrorServiceFactory::GetForProfile(
300 browser_->profile())->GetFirstBadgeResourceID(); 301 browser_->profile())->GetFirstBadgeResourceID();
301 302
302 bool add_badge = ShouldShowUpgradeRecommended() || 303 bool add_badge = ShouldShowUpgradeRecommended() ||
303 ShouldShowIncompatibilityWarning() || error_badge_id; 304 ShouldShowIncompatibilityWarning() || error_badge_id;
304 if (!add_badge) 305 if (!add_badge)
305 return icon; 306 return icon;
306 307
307 // Draw the chrome app menu icon onto the canvas. 308 // Draw the chrome app menu icon onto the canvas.
308 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(icon, false)); 309 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(icon, false));
309 310
310 SkBitmap badge; 311 gfx::ImageSkia badge;
311 // Only one badge can be active at any given time. The Upgrade notification 312 // Only one badge can be active at any given time. The Upgrade notification
312 // is deemed most important, then the DLL conflict badge. 313 // is deemed most important, then the DLL conflict badge.
313 if (ShouldShowUpgradeRecommended()) { 314 if (ShouldShowUpgradeRecommended()) {
314 badge = *tp->GetBitmapNamed( 315 badge = *tp->GetImageSkiaNamed(
315 UpgradeDetector::GetInstance()->GetIconResourceID( 316 UpgradeDetector::GetInstance()->GetIconResourceID(
316 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)); 317 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE));
317 } else if (ShouldShowIncompatibilityWarning()) { 318 } else if (ShouldShowIncompatibilityWarning()) {
318 #if defined(OS_WIN) 319 #if defined(OS_WIN)
319 if (!was_showing) 320 if (!was_showing)
320 content::RecordAction(UserMetricsAction("ConflictBadge")); 321 content::RecordAction(UserMetricsAction("ConflictBadge"));
321 badge = *tp->GetBitmapNamed(IDR_CONFLICT_BADGE); 322 badge = *tp->GetImageSkiaNamed(IDR_CONFLICT_BADGE);
322 incompatibility_badge_showing = true; 323 incompatibility_badge_showing = true;
323 #else 324 #else
324 NOTREACHED(); 325 NOTREACHED();
325 #endif 326 #endif
326 } else if (error_badge_id) { 327 } else if (error_badge_id) {
327 badge = *tp->GetBitmapNamed(error_badge_id); 328 badge = *tp->GetImageSkiaNamed(error_badge_id);
328 } else { 329 } else {
329 NOTREACHED(); 330 NOTREACHED();
330 } 331 }
331 332
332 canvas->DrawBitmapInt(badge, icon.width() - badge.width(), kBadgeTopMargin); 333 canvas->DrawBitmapInt(badge, icon.width() - badge.width(), kBadgeTopMargin);
333 334
334 return canvas->ExtractBitmap(); 335 return canvas->ExtractBitmap();
335 } 336 }
336 337
337 //////////////////////////////////////////////////////////////////////////////// 338 ////////////////////////////////////////////////////////////////////////////////
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 int min_width = kLeftEdgeSpacing + 535 int min_width = kLeftEdgeSpacing +
535 back_->GetPreferredSize().width() + kButtonSpacing + 536 back_->GetPreferredSize().width() + kButtonSpacing +
536 forward_->GetPreferredSize().width() + kButtonSpacing + 537 forward_->GetPreferredSize().width() + kButtonSpacing +
537 reload_->GetPreferredSize().width() + kStandardSpacing + 538 reload_->GetPreferredSize().width() + kStandardSpacing +
538 (show_home_button_.GetValue() ? 539 (show_home_button_.GetValue() ?
539 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) + 540 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) +
540 location_bar_->GetPreferredSize().width() + 541 location_bar_->GetPreferredSize().width() +
541 browser_actions_->GetPreferredSize().width() + 542 browser_actions_->GetPreferredSize().width() +
542 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; 543 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing;
543 544
544 CR_DEFINE_STATIC_LOCAL(SkBitmap, normal_background, ()); 545 CR_DEFINE_STATIC_LOCAL(gfx::ImageSkia, normal_background, ());
545 if (normal_background.isNull()) { 546 if (normal_background.isNull()) {
546 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 547 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
547 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); 548 normal_background = *rb.GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
548 } 549 }
549 550
550 return gfx::Size(min_width, 551 return gfx::Size(min_width,
551 normal_background.height() - kContentShadowHeight); 552 normal_background.height() - kContentShadowHeight);
552 } 553 }
553 554
554 int vertical_spacing = PopupTopSpacing() + 555 int vertical_spacing = PopupTopSpacing() +
555 (GetWidget()->ShouldUseNativeFrame() ? 556 (GetWidget()->ShouldUseNativeFrame() ?
556 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); 557 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass);
557 return gfx::Size(0, location_bar_->GetPreferredSize().height() + 558 return gfx::Size(0, location_bar_->GetPreferredSize().height() +
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 accname_app = l10n_util::GetStringFUTF16( 819 accname_app = l10n_util::GetStringFUTF16(
819 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app); 820 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
820 } 821 }
821 app_menu_->SetAccessibleName(accname_app); 822 app_menu_->SetAccessibleName(accname_app);
822 823
823 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); 824 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL));
824 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); 825 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT));
825 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); 826 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED));
826 SchedulePaint(); 827 SchedulePaint();
827 } 828 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.h ('k') | chrome/browser/ui/webui/ntp/ntp_login_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698