| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/toolbar_view.h" | 5 #include "chrome/browser/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_theme_provider.h" | 11 #include "chrome/browser/browser_theme_provider.h" |
| 13 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 14 #include "chrome/browser/pref_service.h" | 13 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/upgrade_detector.h" | 15 #include "chrome/browser/upgrade_detector.h" |
| 17 #include "chrome/browser/view_ids.h" | 16 #include "chrome/browser/view_ids.h" |
| 18 #include "chrome/browser/views/bookmark_menu_button.h" | |
| 19 #include "chrome/browser/views/browser_actions_container.h" | 17 #include "chrome/browser/views/browser_actions_container.h" |
| 20 #include "chrome/browser/views/event_utils.h" | 18 #include "chrome/browser/views/event_utils.h" |
| 21 #include "chrome/browser/views/frame/browser_view.h" | 19 #include "chrome/browser/views/frame/browser_view.h" |
| 22 #include "chrome/browser/views/wrench_menu.h" | 20 #include "chrome/browser/views/wrench_menu.h" |
| 23 #include "chrome/browser/wrench_menu_model.h" | 21 #include "chrome/browser/wrench_menu_model.h" |
| 24 #include "chrome/common/chrome_switches.h" | |
| 25 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 27 #include "gfx/canvas.h" | 24 #include "gfx/canvas.h" |
| 28 #include "gfx/canvas_skia.h" | 25 #include "gfx/canvas_skia.h" |
| 29 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 31 #include "gfx/skbitmap_operations.h" | 28 #include "gfx/skbitmap_operations.h" |
| 32 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 33 #include "views/controls/button/button_dropdown.h" | 30 #include "views/controls/button/button_dropdown.h" |
| 34 #include "views/focus/view_storage.h" | 31 #include "views/focus/view_storage.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ToolbarView::ToolbarView(Browser* browser) | 69 ToolbarView::ToolbarView(Browser* browser) |
| 73 : model_(browser->toolbar_model()), | 70 : model_(browser->toolbar_model()), |
| 74 back_(NULL), | 71 back_(NULL), |
| 75 forward_(NULL), | 72 forward_(NULL), |
| 76 home_(NULL), | 73 home_(NULL), |
| 77 reload_(NULL), | 74 reload_(NULL), |
| 78 location_bar_(NULL), | 75 location_bar_(NULL), |
| 79 browser_actions_(NULL), | 76 browser_actions_(NULL), |
| 80 page_menu_(NULL), | 77 page_menu_(NULL), |
| 81 app_menu_(NULL), | 78 app_menu_(NULL), |
| 82 bookmark_menu_(NULL), | |
| 83 profile_(NULL), | 79 profile_(NULL), |
| 84 browser_(browser), | 80 browser_(browser), |
| 85 profiles_menu_contents_(NULL), | 81 profiles_menu_contents_(NULL), |
| 86 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 82 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 87 destroyed_flag_(NULL), | 83 destroyed_flag_(NULL), |
| 88 collapsed_(false) { | 84 collapsed_(false) { |
| 89 SetID(VIEW_ID_TOOLBAR); | 85 SetID(VIEW_ID_TOOLBAR); |
| 90 | 86 |
| 91 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 87 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
| 92 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 88 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); | 164 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); |
| 169 page_menu_->SetID(VIEW_ID_PAGE_MENU); | 165 page_menu_->SetID(VIEW_ID_PAGE_MENU); |
| 170 } | 166 } |
| 171 | 167 |
| 172 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | 168 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
| 173 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); | 169 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); |
| 174 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | 170 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
| 175 l10n_util::GetString(IDS_PRODUCT_NAME))); | 171 l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 176 app_menu_->SetID(VIEW_ID_APP_MENU); | 172 app_menu_->SetID(VIEW_ID_APP_MENU); |
| 177 | 173 |
| 178 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { | |
| 179 bookmark_menu_ = new BookmarkMenuButton(browser_); | |
| 180 } else { | |
| 181 bookmark_menu_ = NULL; | |
| 182 } | |
| 183 | |
| 184 // Catch the case where the window is created after we detect a new version. | 174 // Catch the case where the window is created after we detect a new version. |
| 185 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) | 175 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) |
| 186 ShowUpgradeReminder(); | 176 ShowUpgradeReminder(); |
| 187 | 177 |
| 188 LoadImages(); | 178 LoadImages(); |
| 189 | 179 |
| 190 // Always add children in order from left to right, for accessibility. | 180 // Always add children in order from left to right, for accessibility. |
| 191 AddChildView(back_); | 181 AddChildView(back_); |
| 192 AddChildView(forward_); | 182 AddChildView(forward_); |
| 193 AddChildView(home_); | 183 AddChildView(home_); |
| 194 AddChildView(reload_); | 184 AddChildView(reload_); |
| 195 AddChildView(location_bar_); | 185 AddChildView(location_bar_); |
| 196 AddChildView(browser_actions_); | 186 AddChildView(browser_actions_); |
| 197 if (bookmark_menu_) | |
| 198 AddChildView(bookmark_menu_); | |
| 199 if (page_menu_) | 187 if (page_menu_) |
| 200 AddChildView(page_menu_); | 188 AddChildView(page_menu_); |
| 201 AddChildView(app_menu_); | 189 AddChildView(app_menu_); |
| 202 | 190 |
| 203 location_bar_->Init(); | 191 location_bar_->Init(); |
| 204 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 192 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
| 205 | 193 |
| 206 SetProfile(profile); | 194 SetProfile(profile); |
| 207 if (!app_menu_model_.get()) { | 195 if (!app_menu_model_.get()) { |
| 208 if (WrenchMenuModel::IsEnabled()) { | 196 if (WrenchMenuModel::IsEnabled()) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 417 |
| 430 gfx::Size ToolbarView::GetPreferredSize() { | 418 gfx::Size ToolbarView::GetPreferredSize() { |
| 431 if (IsDisplayModeNormal()) { | 419 if (IsDisplayModeNormal()) { |
| 432 int min_width = kControlIndent + back_->GetPreferredSize().width() + | 420 int min_width = kControlIndent + back_->GetPreferredSize().width() + |
| 433 forward_->GetPreferredSize().width() + kControlHorizOffset + | 421 forward_->GetPreferredSize().width() + kControlHorizOffset + |
| 434 (show_home_button_.GetValue() ? | 422 (show_home_button_.GetValue() ? |
| 435 (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + | 423 (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + |
| 436 reload_->GetPreferredSize().width() + kControlHorizOffset + | 424 reload_->GetPreferredSize().width() + kControlHorizOffset + |
| 437 browser_actions_->GetPreferredSize().width() + | 425 browser_actions_->GetPreferredSize().width() + |
| 438 kMenuButtonOffset + | 426 kMenuButtonOffset + |
| 439 (bookmark_menu_ ? bookmark_menu_->GetPreferredSize().width() : 0) + | |
| 440 (page_menu_ ? page_menu_->GetPreferredSize().width() : 0) + | 427 (page_menu_ ? page_menu_->GetPreferredSize().width() : 0) + |
| 441 app_menu_->GetPreferredSize().width() + kPaddingRight; | 428 app_menu_->GetPreferredSize().width() + kPaddingRight; |
| 442 | 429 |
| 443 static SkBitmap normal_background; | 430 static SkBitmap normal_background; |
| 444 if (normal_background.isNull()) { | 431 if (normal_background.isNull()) { |
| 445 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 432 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 446 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); | 433 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); |
| 447 } | 434 } |
| 448 | 435 |
| 449 return gfx::Size(min_width, | 436 return gfx::Size(min_width, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 child_height); | 492 child_height); |
| 506 } | 493 } |
| 507 | 494 |
| 508 reload_->SetBounds(home_->x() + home_->width() + kControlHorizOffset, child_y, | 495 reload_->SetBounds(home_->x() + home_->width() + kControlHorizOffset, child_y, |
| 509 reload_->GetPreferredSize().width(), child_height); | 496 reload_->GetPreferredSize().width(), child_height); |
| 510 | 497 |
| 511 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 498 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| 512 int page_menu_width = | 499 int page_menu_width = |
| 513 page_menu_ ? page_menu_->GetPreferredSize().width() : 0; | 500 page_menu_ ? page_menu_->GetPreferredSize().width() : 0; |
| 514 int app_menu_width = app_menu_->GetPreferredSize().width(); | 501 int app_menu_width = app_menu_->GetPreferredSize().width(); |
| 515 int bookmark_menu_width = bookmark_menu_ ? | |
| 516 bookmark_menu_->GetPreferredSize().width() : 0; | |
| 517 int location_x = reload_->x() + reload_->width() + kControlHorizOffset; | 502 int location_x = reload_->x() + reload_->width() + kControlHorizOffset; |
| 518 int available_width = width() - kPaddingRight - bookmark_menu_width - | 503 int available_width = width() - kPaddingRight - app_menu_width - |
| 519 app_menu_width - page_menu_width - browser_actions_width - | 504 page_menu_width - browser_actions_width - kMenuButtonOffset - location_x; |
| 520 kMenuButtonOffset - location_x; | |
| 521 | 505 |
| 522 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), | 506 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), |
| 523 child_height); | 507 child_height); |
| 524 int next_menu_x = | 508 int next_menu_x = |
| 525 location_bar_->x() + location_bar_->width() + kMenuButtonOffset; | 509 location_bar_->x() + location_bar_->width() + kMenuButtonOffset; |
| 526 | 510 |
| 527 browser_actions_->SetBounds(next_menu_x, 0, browser_actions_width, height()); | 511 browser_actions_->SetBounds(next_menu_x, 0, browser_actions_width, height()); |
| 528 // The browser actions need to do a layout explicitly, because when an | 512 // The browser actions need to do a layout explicitly, because when an |
| 529 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 513 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
| 530 // re-adds everything, regardless of whether it has a page action. For a | 514 // re-adds everything, regardless of whether it has a page action. For a |
| 531 // page action, browser action bounds do not change, as a result of which | 515 // page action, browser action bounds do not change, as a result of which |
| 532 // SetBounds does not do a layout at all. | 516 // SetBounds does not do a layout at all. |
| 533 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 517 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
| 534 // required. | 518 // required. |
| 535 browser_actions_->Layout(); | 519 browser_actions_->Layout(); |
| 536 next_menu_x += browser_actions_width; | 520 next_menu_x += browser_actions_width; |
| 537 | 521 |
| 538 if (bookmark_menu_) { | |
| 539 bookmark_menu_->SetBounds(next_menu_x, child_y, bookmark_menu_width, | |
| 540 child_height); | |
| 541 next_menu_x += bookmark_menu_width; | |
| 542 } | |
| 543 | |
| 544 if (page_menu_) { | 522 if (page_menu_) { |
| 545 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); | 523 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); |
| 546 next_menu_x += page_menu_width; | 524 next_menu_x += page_menu_width; |
| 547 } | 525 } |
| 548 | 526 |
| 549 app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); | 527 app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); |
| 550 } | 528 } |
| 551 | 529 |
| 552 void ToolbarView::Paint(gfx::Canvas* canvas) { | 530 void ToolbarView::Paint(gfx::Canvas* canvas) { |
| 553 View::Paint(canvas); | 531 View::Paint(canvas); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 tp->GetBitmapNamed(IDR_STOP_P)); | 622 tp->GetBitmapNamed(IDR_STOP_P)); |
| 645 reload_->SetBackground(color, background, | 623 reload_->SetBackground(color, background, |
| 646 tp->GetBitmapNamed(IDR_BUTTON_MASK)); | 624 tp->GetBitmapNamed(IDR_BUTTON_MASK)); |
| 647 | 625 |
| 648 // We use different menu button images if the locale is right-to-left. | 626 // We use different menu button images if the locale is right-to-left. |
| 649 if (page_menu_) { | 627 if (page_menu_) { |
| 650 page_menu_->SetIcon(*tp->GetBitmapNamed( | 628 page_menu_->SetIcon(*tp->GetBitmapNamed( |
| 651 base::i18n::IsRTL() ? IDR_MENU_PAGE_RTL : IDR_MENU_PAGE)); | 629 base::i18n::IsRTL() ? IDR_MENU_PAGE_RTL : IDR_MENU_PAGE)); |
| 652 } | 630 } |
| 653 app_menu_->SetIcon(GetAppMenuIcon()); | 631 app_menu_->SetIcon(GetAppMenuIcon()); |
| 654 if (bookmark_menu_ != NULL) | |
| 655 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); | |
| 656 } | 632 } |
| 657 | 633 |
| 658 void ToolbarView::ShowUpgradeReminder() { | 634 void ToolbarView::ShowUpgradeReminder() { |
| 659 update_reminder_animation_.reset(new SlideAnimation(this)); | 635 update_reminder_animation_.reset(new SlideAnimation(this)); |
| 660 update_reminder_animation_->SetSlideDuration(kPulseDuration); | 636 update_reminder_animation_->SetSlideDuration(kPulseDuration); |
| 661 | 637 |
| 662 // Then start the recurring timer for pulsating it. | 638 // Then start the recurring timer for pulsating it. |
| 663 upgrade_reminder_pulse_timer_.Start( | 639 upgrade_reminder_pulse_timer_.Start( |
| 664 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), | 640 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), |
| 665 this, &ToolbarView::PulsateUpgradeNotifier); | 641 this, &ToolbarView::PulsateUpgradeNotifier); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 } | 796 } |
| 821 #endif | 797 #endif |
| 822 | 798 |
| 823 // Tell the menu button to activate, opening its pop-up menu. | 799 // Tell the menu button to activate, opening its pop-up menu. |
| 824 menu_button->Activate(); | 800 menu_button->Activate(); |
| 825 | 801 |
| 826 #if defined(OS_WIN) | 802 #if defined(OS_WIN) |
| 827 SetToolbarFocus(NULL, menu_button); | 803 SetToolbarFocus(NULL, menu_button); |
| 828 #endif | 804 #endif |
| 829 } | 805 } |
| OLD | NEW |