OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "app/drag_drop_types.h" | 9 #include "app/drag_drop_types.h" |
10 #include "app/gfx/canvas.h" | 10 #include "app/gfx/canvas.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/browser_window.h" | 23 #include "chrome/browser/browser_window.h" |
24 #include "chrome/browser/character_encoding.h" | 24 #include "chrome/browser/character_encoding.h" |
25 #include "chrome/browser/encoding_menu_controller.h" | 25 #include "chrome/browser/encoding_menu_controller.h" |
26 #include "chrome/browser/metrics/user_metrics.h" | 26 #include "chrome/browser/metrics/user_metrics.h" |
27 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
28 #include "chrome/browser/tab_contents/navigation_controller.h" | 28 #include "chrome/browser/tab_contents/navigation_controller.h" |
29 #include "chrome/browser/tab_contents/navigation_entry.h" | 29 #include "chrome/browser/tab_contents/navigation_entry.h" |
30 #include "chrome/browser/browser_theme_provider.h" | 30 #include "chrome/browser/browser_theme_provider.h" |
31 #include "chrome/browser/user_data_manager.h" | 31 #include "chrome/browser/user_data_manager.h" |
32 #include "chrome/browser/views/bookmark_menu_button.h" | 32 #include "chrome/browser/views/bookmark_menu_button.h" |
| 33 #include "chrome/browser/views/browser_actions_container.h" |
33 #include "chrome/browser/views/event_utils.h" | 34 #include "chrome/browser/views/event_utils.h" |
34 #include "chrome/browser/views/go_button.h" | 35 #include "chrome/browser/views/go_button.h" |
35 #include "chrome/browser/views/location_bar_view.h" | 36 #include "chrome/browser/views/location_bar_view.h" |
36 #include "chrome/browser/views/toolbar_star_toggle.h" | 37 #include "chrome/browser/views/toolbar_star_toggle.h" |
37 #include "chrome/browser/view_ids.h" | 38 #include "chrome/browser/view_ids.h" |
38 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
39 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/notification_service.h" | 41 #include "chrome/common/notification_service.h" |
41 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
42 #include "chrome/common/pref_service.h" | 43 #include "chrome/common/pref_service.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ToolbarView::ToolbarView(Browser* browser) | 147 ToolbarView::ToolbarView(Browser* browser) |
147 : model_(browser->toolbar_model()), | 148 : model_(browser->toolbar_model()), |
148 acc_focused_view_(NULL), | 149 acc_focused_view_(NULL), |
149 back_(NULL), | 150 back_(NULL), |
150 forward_(NULL), | 151 forward_(NULL), |
151 reload_(NULL), | 152 reload_(NULL), |
152 home_(NULL), | 153 home_(NULL), |
153 star_(NULL), | 154 star_(NULL), |
154 location_bar_(NULL), | 155 location_bar_(NULL), |
155 go_(NULL), | 156 go_(NULL), |
| 157 browser_actions_(NULL), |
156 page_menu_(NULL), | 158 page_menu_(NULL), |
157 app_menu_(NULL), | 159 app_menu_(NULL), |
158 bookmark_menu_(NULL), | 160 bookmark_menu_(NULL), |
159 profile_(NULL), | 161 profile_(NULL), |
160 browser_(browser), | 162 browser_(browser), |
161 profiles_menu_contents_(NULL), | 163 profiles_menu_contents_(NULL), |
162 ALLOW_THIS_IN_INITIALIZER_LIST( | 164 ALLOW_THIS_IN_INITIALIZER_LIST( |
163 profiles_helper_(new GetProfilesHelper(this))) { | 165 profiles_helper_(new GetProfilesHelper(this))) { |
164 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 166 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
165 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 167 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 child_y, home_->GetPreferredSize().width(), child_height); | 508 child_y, home_->GetPreferredSize().width(), child_height); |
507 } else { | 509 } else { |
508 home_->SetVisible(false); | 510 home_->SetVisible(false); |
509 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 511 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
510 } | 512 } |
511 | 513 |
512 star_->SetBounds(home_->x() + home_->width() + kControlHorizOffset, | 514 star_->SetBounds(home_->x() + home_->width() + kControlHorizOffset, |
513 child_y, star_->GetPreferredSize().width(), child_height); | 515 child_y, star_->GetPreferredSize().width(), child_height); |
514 | 516 |
515 int go_button_width = go_->GetPreferredSize().width(); | 517 int go_button_width = go_->GetPreferredSize().width(); |
| 518 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
516 int page_menu_width = page_menu_->GetPreferredSize().width(); | 519 int page_menu_width = page_menu_->GetPreferredSize().width(); |
517 int app_menu_width = app_menu_->GetPreferredSize().width(); | 520 int app_menu_width = app_menu_->GetPreferredSize().width(); |
518 int bookmark_menu_width = bookmark_menu_ ? | 521 int bookmark_menu_width = bookmark_menu_ ? |
519 bookmark_menu_->GetPreferredSize().width() : 0; | 522 bookmark_menu_->GetPreferredSize().width() : 0; |
520 int location_x = star_->x() + star_->width(); | 523 int location_x = star_->x() + star_->width(); |
521 int available_width = width() - kPaddingRight - bookmark_menu_width - | 524 int available_width = width() - kPaddingRight - bookmark_menu_width - |
522 app_menu_width - page_menu_width - kMenuButtonOffset - go_button_width - | 525 app_menu_width - page_menu_width - browser_actions_width - |
523 location_x; | 526 kMenuButtonOffset - go_button_width - location_x; |
524 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), | 527 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), |
525 child_height); | 528 child_height); |
526 | 529 |
527 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y, | 530 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y, |
528 go_button_width, child_height); | 531 go_button_width, child_height); |
529 | 532 |
530 int next_menu_x = go_->x() + go_->width() + kMenuButtonOffset; | 533 int next_menu_x = go_->x() + go_->width() + kMenuButtonOffset; |
531 | 534 |
532 if (bookmark_menu_) { | 535 if (bookmark_menu_) { |
533 bookmark_menu_->SetBounds(next_menu_x, child_y, bookmark_menu_width, | 536 bookmark_menu_->SetBounds(next_menu_x, child_y, bookmark_menu_width, |
534 child_height); | 537 child_height); |
535 next_menu_x += bookmark_menu_width; | 538 next_menu_x += bookmark_menu_width; |
536 } | 539 } |
537 | 540 |
| 541 browser_actions_->SetBounds( |
| 542 next_menu_x, child_y, browser_actions_width, child_height); |
| 543 next_menu_x += browser_actions_width; |
| 544 |
538 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); | 545 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); |
539 next_menu_x += page_menu_width; | 546 next_menu_x += page_menu_width; |
540 | 547 |
541 app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); | 548 app_menu_->SetBounds(next_menu_x, child_y, app_menu_width, child_height); |
542 } | 549 } |
543 | 550 |
544 void ToolbarView::Paint(gfx::Canvas* canvas) { | 551 void ToolbarView::Paint(gfx::Canvas* canvas) { |
545 View::Paint(canvas); | 552 View::Paint(canvas); |
546 | 553 |
547 if (IsDisplayModeNormal()) | 554 if (IsDisplayModeNormal()) |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 855 |
849 LoadCenterStackImages(); | 856 LoadCenterStackImages(); |
850 | 857 |
851 location_bar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_LOCATION)); | 858 location_bar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_LOCATION)); |
852 AddChildView(location_bar_); | 859 AddChildView(location_bar_); |
853 location_bar_->Init(); | 860 location_bar_->Init(); |
854 AddChildView(go_); | 861 AddChildView(go_); |
855 } | 862 } |
856 | 863 |
857 void ToolbarView::CreateRightSideControls(Profile* profile) { | 864 void ToolbarView::CreateRightSideControls(Profile* profile) { |
| 865 browser_actions_ = new BrowserActionsContainer(profile, this); |
| 866 |
858 page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | 867 page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
859 page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); | 868 page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); |
860 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); | 869 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); |
861 page_menu_->SetID(VIEW_ID_PAGE_MENU); | 870 page_menu_->SetID(VIEW_ID_PAGE_MENU); |
862 | 871 |
863 | |
864 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | 872 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
865 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); | 873 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); |
866 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | 874 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
867 l10n_util::GetString(IDS_PRODUCT_NAME))); | 875 l10n_util::GetString(IDS_PRODUCT_NAME))); |
868 app_menu_->SetID(VIEW_ID_APP_MENU); | 876 app_menu_->SetID(VIEW_ID_APP_MENU); |
869 | 877 |
870 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { | 878 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { |
871 bookmark_menu_ = new BookmarkMenuButton(browser_); | 879 bookmark_menu_ = new BookmarkMenuButton(browser_); |
872 AddChildView(bookmark_menu_); | 880 AddChildView(bookmark_menu_); |
873 } else { | 881 } else { |
874 bookmark_menu_ = NULL; | 882 bookmark_menu_ = NULL; |
875 } | 883 } |
876 | 884 |
877 LoadRightSideControlsImages(); | 885 LoadRightSideControlsImages(); |
878 | 886 |
| 887 AddChildView(browser_actions_); |
879 AddChildView(page_menu_); | 888 AddChildView(page_menu_); |
880 AddChildView(app_menu_); | 889 AddChildView(app_menu_); |
881 } | 890 } |
882 | 891 |
883 void ToolbarView::LoadLeftSideControlsImages() { | 892 void ToolbarView::LoadLeftSideControlsImages() { |
884 ThemeProvider* tp = GetThemeProvider(); | 893 ThemeProvider* tp = GetThemeProvider(); |
885 | 894 |
886 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | 895 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); |
887 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); | 896 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); |
888 | 897 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 app_menu_contents_->AddItem(IDC_ABOUT, | 1090 app_menu_contents_->AddItem(IDC_ABOUT, |
1082 l10n_util::GetStringFUTF16( | 1091 l10n_util::GetStringFUTF16( |
1083 IDS_ABOUT, | 1092 IDS_ABOUT, |
1084 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 1093 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
1085 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); | 1094 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); |
1086 app_menu_contents_->AddSeparator(); | 1095 app_menu_contents_->AddSeparator(); |
1087 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); | 1096 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
1088 | 1097 |
1089 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); | 1098 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); |
1090 } | 1099 } |
OLD | NEW |