OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/accessibility/browser_accessibility_state.h" | 10 #include "chrome/browser/accessibility/browser_accessibility_state.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 back_(NULL), | 85 back_(NULL), |
86 forward_(NULL), | 86 forward_(NULL), |
87 reload_(NULL), | 87 reload_(NULL), |
88 home_(NULL), | 88 home_(NULL), |
89 location_bar_(NULL), | 89 location_bar_(NULL), |
90 browser_actions_(NULL), | 90 browser_actions_(NULL), |
91 app_menu_(NULL), | 91 app_menu_(NULL), |
92 profile_(NULL), | 92 profile_(NULL), |
93 browser_(browser), | 93 browser_(browser), |
94 profiles_menu_contents_(NULL) { | 94 profiles_menu_contents_(NULL) { |
95 SetID(VIEW_ID_TOOLBAR); | 95 set_id(VIEW_ID_TOOLBAR); |
96 | 96 |
97 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 97 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
98 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 98 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
99 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 99 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
100 | 100 |
101 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? | 101 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
102 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; | 102 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; |
103 | 103 |
104 if (!kPopupBackgroundEdge) { | 104 if (!kPopupBackgroundEdge) { |
105 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 105 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
(...skipping 20 matching lines...) Expand all Loading... |
126 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_)); | 126 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_)); |
127 back_ = new views::ButtonDropDown(this, back_menu_model_.get()); | 127 back_ = new views::ButtonDropDown(this, back_menu_model_.get()); |
128 back_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | | 128 back_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | |
129 ui::EF_MIDDLE_BUTTON_DOWN); | 129 ui::EF_MIDDLE_BUTTON_DOWN); |
130 back_->set_tag(IDC_BACK); | 130 back_->set_tag(IDC_BACK); |
131 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, | 131 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, |
132 views::ImageButton::ALIGN_TOP); | 132 views::ImageButton::ALIGN_TOP); |
133 back_->SetTooltipText( | 133 back_->SetTooltipText( |
134 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK))); | 134 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK))); |
135 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); | 135 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); |
136 back_->SetID(VIEW_ID_BACK_BUTTON); | 136 back_->set_id(VIEW_ID_BACK_BUTTON); |
137 | 137 |
138 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); | 138 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); |
139 forward_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | | 139 forward_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | |
140 ui::EF_MIDDLE_BUTTON_DOWN); | 140 ui::EF_MIDDLE_BUTTON_DOWN); |
141 forward_->set_tag(IDC_FORWARD); | 141 forward_->set_tag(IDC_FORWARD); |
142 forward_->SetTooltipText( | 142 forward_->SetTooltipText( |
143 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD))); | 143 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD))); |
144 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); | 144 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); |
145 forward_->SetID(VIEW_ID_FORWARD_BUTTON); | 145 forward_->set_id(VIEW_ID_FORWARD_BUTTON); |
146 | 146 |
147 // Have to create this before |reload_| as |reload_|'s constructor needs it. | 147 // Have to create this before |reload_| as |reload_|'s constructor needs it. |
148 location_bar_ = new LocationBarView(profile, browser_, | 148 location_bar_ = new LocationBarView(profile, browser_, |
149 model_, this, (display_mode_ == DISPLAYMODE_LOCATION) ? | 149 model_, this, (display_mode_ == DISPLAYMODE_LOCATION) ? |
150 LocationBarView::POPUP : LocationBarView::NORMAL); | 150 LocationBarView::POPUP : LocationBarView::NORMAL); |
151 | 151 |
152 reload_ = new ReloadButton(location_bar_, browser_); | 152 reload_ = new ReloadButton(location_bar_, browser_); |
153 reload_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | | 153 reload_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | |
154 ui::EF_MIDDLE_BUTTON_DOWN); | 154 ui::EF_MIDDLE_BUTTON_DOWN); |
155 reload_->set_tag(IDC_RELOAD); | 155 reload_->set_tag(IDC_RELOAD); |
156 reload_->SetTooltipText( | 156 reload_->SetTooltipText( |
157 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD))); | 157 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_RELOAD))); |
158 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); | 158 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); |
159 reload_->SetID(VIEW_ID_RELOAD_BUTTON); | 159 reload_->set_id(VIEW_ID_RELOAD_BUTTON); |
160 | 160 |
161 home_ = new views::ImageButton(this); | 161 home_ = new views::ImageButton(this); |
162 home_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | | 162 home_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | |
163 ui::EF_MIDDLE_BUTTON_DOWN); | 163 ui::EF_MIDDLE_BUTTON_DOWN); |
164 home_->set_tag(IDC_HOME); | 164 home_->set_tag(IDC_HOME); |
165 home_->SetTooltipText( | 165 home_->SetTooltipText( |
166 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME))); | 166 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME))); |
167 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); | 167 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); |
168 home_->SetID(VIEW_ID_HOME_BUTTON); | 168 home_->set_id(VIEW_ID_HOME_BUTTON); |
169 | 169 |
170 browser_actions_ = new BrowserActionsContainer(browser_, this); | 170 browser_actions_ = new BrowserActionsContainer(browser_, this); |
171 | 171 |
172 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | 172 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
173 app_menu_->set_border(NULL); | 173 app_menu_->set_border(NULL); |
174 app_menu_->EnableCanvasFlippingForRTLUI(true); | 174 app_menu_->EnableCanvasFlippingForRTLUI(true); |
175 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); | 175 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); |
176 app_menu_->SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( | 176 app_menu_->SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
177 IDS_APPMENU_TOOLTIP, | 177 IDS_APPMENU_TOOLTIP, |
178 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); | 178 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)))); |
179 app_menu_->SetID(VIEW_ID_APP_MENU); | 179 app_menu_->set_id(VIEW_ID_APP_MENU); |
180 | 180 |
181 // Add any necessary badges to the menu item based on the system state. | 181 // Add any necessary badges to the menu item based on the system state. |
182 if (IsUpgradeRecommended() || ShouldShowIncompatibilityWarning()) { | 182 if (IsUpgradeRecommended() || ShouldShowIncompatibilityWarning()) { |
183 UpdateAppMenuBadge(); | 183 UpdateAppMenuBadge(); |
184 } | 184 } |
185 LoadImages(); | 185 LoadImages(); |
186 | 186 |
187 // Always add children in order from left to right, for accessibility. | 187 // Always add children in order from left to right, for accessibility. |
188 AddChildView(back_); | 188 AddChildView(back_); |
189 AddChildView(forward_); | 189 AddChildView(forward_); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // ToolbarView, Menu::Delegate overrides: | 325 // ToolbarView, Menu::Delegate overrides: |
326 | 326 |
327 bool ToolbarView::GetAcceleratorInfo(int id, ui::Accelerator* accel) { | 327 bool ToolbarView::GetAcceleratorInfo(int id, ui::Accelerator* accel) { |
328 return GetWidget()->GetAccelerator(id, accel); | 328 return GetWidget()->GetAccelerator(id, accel); |
329 } | 329 } |
330 | 330 |
331 //////////////////////////////////////////////////////////////////////////////// | 331 //////////////////////////////////////////////////////////////////////////////// |
332 // ToolbarView, views::MenuDelegate implementation: | 332 // ToolbarView, views::MenuDelegate implementation: |
333 | 333 |
334 void ToolbarView::RunMenu(views::View* source, const gfx::Point& /* pt */) { | 334 void ToolbarView::RunMenu(views::View* source, const gfx::Point& /* pt */) { |
335 DCHECK_EQ(VIEW_ID_APP_MENU, source->GetID()); | 335 DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); |
336 | 336 |
337 wrench_menu_ = new WrenchMenu(browser_); | 337 wrench_menu_ = new WrenchMenu(browser_); |
338 wrench_menu_->Init(wrench_menu_model_.get()); | 338 wrench_menu_->Init(wrench_menu_model_.get()); |
339 | 339 |
340 for (size_t i = 0; i < menu_listeners_.size(); ++i) | 340 for (size_t i = 0; i < menu_listeners_.size(); ++i) |
341 menu_listeners_[i]->OnMenuOpened(); | 341 menu_listeners_[i]->OnMenuOpened(); |
342 | 342 |
343 wrench_menu_->RunMenu(app_menu_); | 343 wrench_menu_->RunMenu(app_menu_); |
344 } | 344 } |
345 | 345 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); | 693 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); |
694 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); | 694 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); |
695 } | 695 } |
696 | 696 |
697 void ToolbarView::UpdateAppMenuBadge() { | 697 void ToolbarView::UpdateAppMenuBadge() { |
698 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); | 698 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); |
699 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); | 699 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); |
700 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); | 700 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); |
701 SchedulePaint(); | 701 SchedulePaint(); |
702 } | 702 } |
OLD | NEW |