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" | 9 #include "base/command_line.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 menu_bar_emulation_mode_(false), | 85 menu_bar_emulation_mode_(false), |
86 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 86 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
87 destroyed_flag_(NULL), | 87 destroyed_flag_(NULL), |
88 collapsed_(false) { | 88 collapsed_(false) { |
89 SetID(VIEW_ID_TOOLBAR); | 89 SetID(VIEW_ID_TOOLBAR); |
90 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 90 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
91 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 91 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
92 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 92 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
93 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); | 93 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); |
94 | 94 |
95 if (browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)) | 95 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
96 display_mode_ = DISPLAYMODE_NORMAL; | 96 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; |
97 else | |
98 display_mode_ = DISPLAYMODE_LOCATION; | |
99 | 97 |
100 if (!kPopupBackgroundEdge) { | 98 if (!kPopupBackgroundEdge) { |
101 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 99 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
102 IDR_LOCATIONBG_POPUPMODE_EDGE); | 100 IDR_LOCATIONBG_POPUPMODE_EDGE); |
103 } | 101 } |
104 | 102 |
105 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) { | 103 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) { |
106 registrar_.Add(this, | 104 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, |
107 NotificationType::UPGRADE_RECOMMENDED, | 105 NotificationService::AllSources()); |
108 NotificationService::AllSources()); | |
109 } | 106 } |
110 } | 107 } |
111 | 108 |
112 ToolbarView::~ToolbarView() { | 109 ToolbarView::~ToolbarView() { |
113 if (destroyed_flag_) | 110 if (destroyed_flag_) |
114 *destroyed_flag_ = true; | 111 *destroyed_flag_ = true; |
| 112 |
| 113 // NOTE: Don't remove the command observers here. This object gets destroyed |
| 114 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
| 115 // already gone. |
| 116 |
115 if (menu_bar_emulation_mode_) { | 117 if (menu_bar_emulation_mode_) { |
116 focus_manager_->UnregisterAccelerators(this); | 118 focus_manager_->UnregisterAccelerators(this); |
117 focus_manager_->RemoveFocusChangeListener(this); | 119 focus_manager_->RemoveFocusChangeListener(this); |
118 } | 120 } |
119 } | 121 } |
120 | 122 |
121 void ToolbarView::Init(Profile* profile) { | 123 void ToolbarView::Init(Profile* profile) { |
122 back_menu_model_.reset(new BackForwardMenuModel( | 124 back_menu_model_.reset(new BackForwardMenuModel( |
123 browser_, BackForwardMenuModel::BACKWARD_MENU)); | 125 browser_, BackForwardMenuModel::BACKWARD_MENU)); |
124 forward_menu_model_.reset(new BackForwardMenuModel( | 126 forward_menu_model_.reset(new BackForwardMenuModel( |
125 browser_, BackForwardMenuModel::FORWARD_MENU)); | 127 browser_, BackForwardMenuModel::FORWARD_MENU)); |
126 | 128 |
127 // Create all the individual Views in the Toolbar. | 129 back_ = new views::ButtonDropDown(this, back_menu_model_.get()); |
128 CreateLeftSideControls(); | 130 back_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | |
129 CreateCenterStack(profile); | 131 views::Event::EF_MIDDLE_BUTTON_DOWN); |
130 CreateRightSideControls(profile); | 132 back_->set_tag(IDC_BACK); |
| 133 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, |
| 134 views::ImageButton::ALIGN_TOP); |
| 135 back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK)); |
| 136 back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK)); |
| 137 back_->SetID(VIEW_ID_BACK_BUTTON); |
131 | 138 |
| 139 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); |
| 140 forward_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | |
| 141 views::Event::EF_MIDDLE_BUTTON_DOWN); |
| 142 forward_->set_tag(IDC_FORWARD); |
| 143 forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD)); |
| 144 forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD)); |
| 145 forward_->SetID(VIEW_ID_FORWARD_BUTTON); |
| 146 |
| 147 home_ = new views::ImageButton(this); |
| 148 home_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | |
| 149 views::Event::EF_MIDDLE_BUTTON_DOWN); |
| 150 home_->set_tag(IDC_HOME); |
| 151 home_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_HOME)); |
| 152 home_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_HOME)); |
| 153 home_->SetID(VIEW_ID_HOME_BUTTON); |
| 154 |
| 155 reload_ = new views::ImageButton(this); |
| 156 reload_->set_tag(IDC_RELOAD); |
| 157 reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD)); |
| 158 reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD)); |
| 159 reload_->SetID(VIEW_ID_RELOAD_BUTTON); |
| 160 |
| 161 location_bar_ = new LocationBarView(profile, browser_->command_updater(), |
| 162 model_, this, (display_mode_ == DISPLAYMODE_LOCATION) ? |
| 163 LocationBarView::POPUP : LocationBarView::NORMAL); |
| 164 location_bar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_LOCATION)); |
| 165 |
| 166 go_ = new GoButton(location_bar_, browser_); |
| 167 go_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_GO)); |
| 168 go_->SetID(VIEW_ID_GO_BUTTON); |
| 169 |
| 170 browser_actions_ = new BrowserActionsContainer(browser_, this, true); |
| 171 |
| 172 page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
| 173 page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); |
| 174 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); |
| 175 page_menu_->SetID(VIEW_ID_PAGE_MENU); |
| 176 |
| 177 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
| 178 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); |
| 179 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
| 180 l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 181 app_menu_->SetID(VIEW_ID_APP_MENU); |
| 182 |
| 183 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { |
| 184 bookmark_menu_ = new BookmarkMenuButton(browser_); |
| 185 AddChildView(bookmark_menu_); |
| 186 } else { |
| 187 bookmark_menu_ = NULL; |
| 188 } |
| 189 |
| 190 LoadImages(); |
| 191 |
| 192 AddChildView(back_); |
| 193 AddChildView(forward_); |
| 194 AddChildView(home_); |
| 195 AddChildView(reload_); |
| 196 AddChildView(location_bar_); |
| 197 AddChildView(go_); |
| 198 AddChildView(browser_actions_); |
| 199 AddChildView(page_menu_); |
| 200 AddChildView(app_menu_); |
| 201 |
| 202 location_bar_->Init(); |
132 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 203 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
133 | 204 |
| 205 // Catch the case where the window is created after we detect a new version. |
| 206 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) |
| 207 ShowUpgradeReminder(); |
| 208 |
134 SetProfile(profile); | 209 SetProfile(profile); |
135 if (!app_menu_model_.get()) { | 210 if (!app_menu_model_.get()) |
136 SetAppMenuModel(new AppMenuModel(this, browser_)); | 211 SetAppMenuModel(new AppMenuModel(this, browser_)); |
137 } | |
138 | 212 |
139 focus_manager_ = GetFocusManager(); | 213 focus_manager_ = GetFocusManager(); |
140 } | 214 } |
141 | 215 |
142 void ToolbarView::SetProfile(Profile* profile) { | 216 void ToolbarView::SetProfile(Profile* profile) { |
143 if (profile == profile_) | 217 if (profile != profile_) { |
144 return; | 218 profile_ = profile; |
145 | 219 location_bar_->SetProfile(profile); |
146 profile_ = profile; | 220 } |
147 location_bar_->SetProfile(profile); | |
148 } | 221 } |
149 | 222 |
150 void ToolbarView::Update(TabContents* tab, bool should_restore_state) { | 223 void ToolbarView::Update(TabContents* tab, bool should_restore_state) { |
151 if (location_bar_) | 224 if (location_bar_) |
152 location_bar_->Update(should_restore_state ? tab : NULL); | 225 location_bar_->Update(should_restore_state ? tab : NULL); |
153 | 226 |
154 if (browser_actions_) | 227 if (browser_actions_) |
155 browser_actions_->RefreshBrowserActionViews(); | 228 browser_actions_->RefreshBrowserActionViews(); |
156 } | 229 } |
157 | 230 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 focus_manager_->RegisterAccelerator(left, this); | 271 focus_manager_->RegisterAccelerator(left, this); |
199 views::Accelerator right(base::VKEY_RIGHT, false, false, false); | 272 views::Accelerator right(base::VKEY_RIGHT, false, false, false); |
200 focus_manager_->RegisterAccelerator(right, this); | 273 focus_manager_->RegisterAccelerator(right, this); |
201 } | 274 } |
202 | 275 |
203 void ToolbarView::AddMenuListener(views::MenuListener* listener) { | 276 void ToolbarView::AddMenuListener(views::MenuListener* listener) { |
204 menu_listeners_.push_back(listener); | 277 menu_listeners_.push_back(listener); |
205 } | 278 } |
206 | 279 |
207 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { | 280 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { |
208 for (std::vector<views::MenuListener*>::iterator iter = | 281 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin()); |
209 menu_listeners_.begin(); | 282 i != menu_listeners_.end(); ++i) { |
210 iter != menu_listeners_.end(); | 283 if (*i == listener) { |
211 ++iter) { | 284 menu_listeners_.erase(i); |
212 if (*iter == listener) { | 285 return; |
213 menu_listeners_.erase(iter); | 286 } |
214 return; | |
215 } | |
216 } | 287 } |
217 } | 288 } |
218 | 289 |
219 void ToolbarView::SetCollapsed(bool val) { | 290 void ToolbarView::SetCollapsed(bool val) { |
220 if (collapsed_ == val) | 291 if (collapsed_ == val) |
221 return; | 292 return; |
222 | 293 |
223 collapsed_ = val; | 294 collapsed_ = val; |
224 | 295 |
225 // When switching to and from collapsed view, we need to force hide/show the | 296 // When switching to and from collapsed view, we need to force hide/show the |
226 // location bar entry view, like we do when we switch to full screen mode in | 297 // location bar entry view, like we do when we switch to full screen mode in |
227 // BrowserView::ProcessFullscreen. Otherwise the text view can appear floating | 298 // BrowserView::ProcessFullscreen. Otherwise the text view can appear floating |
228 // on top of web content. | 299 // on top of web content. |
229 if (collapsed_) | 300 if (collapsed_) |
230 location_bar_->PushForceHidden(); | 301 location_bar_->PushForceHidden(); |
231 else | 302 else |
232 location_bar_->PopForceHidden(); | 303 location_bar_->PopForceHidden(); |
233 } | 304 } |
234 | 305 |
235 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
236 // ToolbarView, FocusChangeListener overrides: | 307 // ToolbarView, FocusChangeListener overrides: |
237 | 308 |
238 void ToolbarView::FocusWillChange(views::View* focused_before, | 309 void ToolbarView::FocusWillChange(views::View* focused_before, |
239 views::View* focused_now) { | 310 views::View* focused_now) { |
240 // If the focus is switching to something outside the menu bar, | 311 // If the focus is switching to something outside the menu bar, |
241 // take it out of the focus traversal. | 312 // take it out of the focus traversal. |
242 if (focused_now != NULL && | 313 if ((focused_now != NULL) && (focused_now != page_menu_) && |
243 focused_now != page_menu_ && | 314 (focused_now != app_menu_)) { |
244 focused_now != app_menu_) { | |
245 // Post ExitMenuBarEmulationMode to the queue rather than running it | 315 // Post ExitMenuBarEmulationMode to the queue rather than running it |
246 // right away, because otherwise we'll remove ourselves from the | 316 // right away, because otherwise we'll remove ourselves from the |
247 // list of listeners while FocusManager is in the middle of iterating | 317 // list of listeners while FocusManager is in the middle of iterating |
248 // over that list. | 318 // over that list. |
249 MessageLoop::current()->PostTask( | 319 MessageLoop::current()->PostTask( |
250 FROM_HERE, method_factory_.NewRunnableMethod( | 320 FROM_HERE, method_factory_.NewRunnableMethod( |
251 &ToolbarView::ExitMenuBarEmulationMode)); | 321 &ToolbarView::ExitMenuBarEmulationMode)); |
252 } | 322 } |
253 } | 323 } |
254 | 324 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 438 } |
369 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { | 439 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { |
370 ShowUpgradeReminder(); | 440 ShowUpgradeReminder(); |
371 } | 441 } |
372 } | 442 } |
373 | 443 |
374 //////////////////////////////////////////////////////////////////////////////// | 444 //////////////////////////////////////////////////////////////////////////////// |
375 // ToolbarView, menus::SimpleMenuModel::Delegate implementation: | 445 // ToolbarView, menus::SimpleMenuModel::Delegate implementation: |
376 | 446 |
377 bool ToolbarView::IsCommandIdChecked(int command_id) const { | 447 bool ToolbarView::IsCommandIdChecked(int command_id) const { |
378 if (command_id == IDC_SHOW_BOOKMARK_BAR) | 448 return (command_id == IDC_SHOW_BOOKMARK_BAR) && |
379 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 449 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
380 return false; | |
381 } | 450 } |
382 | 451 |
383 bool ToolbarView::IsCommandIdEnabled(int command_id) const { | 452 bool ToolbarView::IsCommandIdEnabled(int command_id) const { |
384 return browser_->command_updater()->IsCommandEnabled(command_id); | 453 return browser_->command_updater()->IsCommandEnabled(command_id); |
385 } | 454 } |
386 | 455 |
387 bool ToolbarView::GetAcceleratorForCommandId(int command_id, | 456 bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
388 menus::Accelerator* accelerator) { | 457 menus::Accelerator* accelerator) { |
389 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 458 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
390 // anywhere so we need to check for them explicitly here. | 459 // anywhere so we need to check for them explicitly here. |
(...skipping 30 matching lines...) Expand all Loading... |
421 } | 490 } |
422 | 491 |
423 // Safe to cast, given the check above. | 492 // Safe to cast, given the check above. |
424 views::MenuButton* menu = static_cast<views::MenuButton*>(focused_view); | 493 views::MenuButton* menu = static_cast<views::MenuButton*>(focused_view); |
425 switch (accelerator.GetKeyCode()) { | 494 switch (accelerator.GetKeyCode()) { |
426 case base::VKEY_ESCAPE: | 495 case base::VKEY_ESCAPE: |
427 RestoreLastFocusedView(); | 496 RestoreLastFocusedView(); |
428 return true; | 497 return true; |
429 case base::VKEY_LEFT: | 498 case base::VKEY_LEFT: |
430 case base::VKEY_RIGHT: | 499 case base::VKEY_RIGHT: |
431 if (menu == app_menu_) | 500 ((menu == app_menu_) ? page_menu_ : app_menu_)->RequestFocus(); |
432 page_menu_->RequestFocus(); | |
433 else | |
434 app_menu_->RequestFocus(); | |
435 return true; | 501 return true; |
436 case base::VKEY_UP: | 502 case base::VKEY_UP: |
437 case base::VKEY_DOWN: | 503 case base::VKEY_DOWN: |
438 case base::VKEY_RETURN: | 504 case base::VKEY_RETURN: |
439 case base::VKEY_SPACE: | 505 case base::VKEY_SPACE: |
440 // Hide the tooltip before activating a menu button. | 506 // Hide the tooltip before activating a menu button. |
441 if (GetWidget()->GetTooltipManager()) | 507 if (GetWidget()->GetTooltipManager()) |
442 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); | 508 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); |
443 | |
444 ActivateMenuButton(menu); | 509 ActivateMenuButton(menu); |
445 return true; | 510 return true; |
446 default: | 511 default: |
447 return false; | 512 return false; |
448 } | 513 } |
449 } | 514 } |
450 | 515 |
451 gfx::Size ToolbarView::GetPreferredSize() { | 516 gfx::Size ToolbarView::GetPreferredSize() { |
452 if (IsDisplayModeNormal()) { | 517 if (IsDisplayModeNormal()) { |
453 int min_width = kControlIndent + back_->GetPreferredSize().width() + | 518 int min_width = kControlIndent + back_->GetPreferredSize().width() + |
454 forward_->GetPreferredSize().width() + kControlHorizOffset + | 519 forward_->GetPreferredSize().width() + kControlHorizOffset + |
455 (show_home_button_.GetValue() ? | 520 (show_home_button_.GetValue() ? |
456 (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + | 521 (home_->GetPreferredSize().width() + kControlHorizOffset) : 0) + |
457 reload_->GetPreferredSize().width() + | 522 reload_->GetPreferredSize().width() + |
458 browser_actions_->GetPreferredSize().width() + | 523 browser_actions_->GetPreferredSize().width() + |
459 go_->GetPreferredSize().width() + | 524 go_->GetPreferredSize().width() + |
460 kMenuButtonOffset + | 525 kMenuButtonOffset + |
461 (bookmark_menu_ ? bookmark_menu_->GetPreferredSize().width() : 0) + | 526 (bookmark_menu_ ? bookmark_menu_->GetPreferredSize().width() : 0) + |
462 page_menu_->GetPreferredSize().width() + | 527 page_menu_->GetPreferredSize().width() + |
463 app_menu_->GetPreferredSize().width() + kPaddingRight; | 528 app_menu_->GetPreferredSize().width() + kPaddingRight; |
464 | 529 |
465 static SkBitmap normal_background; | 530 static SkBitmap normal_background; |
466 if (normal_background.isNull()) { | 531 if (normal_background.isNull()) { |
467 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 532 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
468 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); | 533 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); |
469 } | 534 } |
470 | 535 |
471 if (collapsed_) | 536 return gfx::Size(min_width, |
472 return gfx::Size(min_width, kCollapsedToolbarHeight); | 537 collapsed_ ? kCollapsedToolbarHeight : normal_background.height()); |
473 else | |
474 return gfx::Size(min_width, normal_background.height()); | |
475 } | 538 } |
476 | 539 |
477 int vertical_spacing = PopupTopSpacing() + | 540 int vertical_spacing = PopupTopSpacing() + |
478 (GetWindow()->GetNonClientView()->UseNativeFrame() ? | 541 (GetWindow()->GetNonClientView()->UseNativeFrame() ? |
479 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); | 542 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); |
480 return gfx::Size(0, location_bar_->GetPreferredSize().height() + | 543 return gfx::Size(0, location_bar_->GetPreferredSize().height() + |
481 vertical_spacing); | 544 vertical_spacing); |
482 } | 545 } |
483 | 546 |
484 void ToolbarView::Layout() { | 547 void ToolbarView::Layout() { |
485 // If we have not been initialized yet just do nothing. | 548 // If we have not been initialized yet just do nothing. |
486 if (back_ == NULL) | 549 if (back_ == NULL) |
487 return; | 550 return; |
488 | 551 |
489 if (!IsDisplayModeNormal()) { | 552 if (!IsDisplayModeNormal()) { |
490 int edge_width = (browser_->window() && browser_->window()->IsMaximized()) ? | 553 int edge_width = (browser_->window() && browser_->window()->IsMaximized()) ? |
491 0 : kPopupBackgroundEdge->width(); // See Paint(). | 554 0 : kPopupBackgroundEdge->width(); // See Paint(). |
492 location_bar_->SetBounds(edge_width, PopupTopSpacing(), | 555 location_bar_->SetBounds(edge_width, PopupTopSpacing(), |
493 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); | 556 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); |
494 return; | 557 return; |
495 } | 558 } |
496 | 559 |
497 // In collapsed mode, we don't show any of the child controls. | 560 // In collapsed mode, we don't show any of the child controls. |
498 for (int i = 0; i < GetChildViewCount(); ++i) | 561 for (int i = 0; i < GetChildViewCount(); ++i) |
499 GetChildViewAt(i)->SetVisible(!collapsed_); | 562 GetChildViewAt(i)->SetVisible(!collapsed_); |
500 | 563 |
501 int child_y = std::min(kControlVertOffset, height()); | 564 int child_y = std::min(kControlVertOffset, height()); |
502 // We assume all child elements are the same height. | 565 // We assume all child elements are the same height. |
503 int child_height = | 566 int child_height = |
504 std::min(go_->GetPreferredSize().height(), height() - child_y); | 567 std::min(back_->GetPreferredSize().height(), height() - child_y); |
505 | 568 |
506 // If the window is maximized, we extend the back button to the left so that | 569 // If the window is maximized, we extend the back button to the left so that |
507 // clicking on the left-most pixel will activate the back button. | 570 // clicking on the left-most pixel will activate the back button. |
508 // TODO(abarth): If the window becomes maximized but is not resized, | 571 // TODO(abarth): If the window becomes maximized but is not resized, |
509 // then Layout() might not be called and the back button | 572 // then Layout() might not be called and the back button |
510 // will be slightly the wrong size. We should force a | 573 // will be slightly the wrong size. We should force a |
511 // Layout() in this case. | 574 // Layout() in this case. |
512 // http://crbug.com/5540 | 575 // http://crbug.com/5540 |
513 int back_width = back_->GetPreferredSize().width(); | 576 int back_width = back_->GetPreferredSize().width(); |
514 if (browser_->window() && browser_->window()->IsMaximized()) | 577 if (browser_->window() && browser_->window()->IsMaximized()) |
(...skipping 26 matching lines...) Expand all Loading... |
541 int location_x = reload_->x() + reload_->width(); | 604 int location_x = reload_->x() + reload_->width(); |
542 int available_width = width() - kPaddingRight - bookmark_menu_width - | 605 int available_width = width() - kPaddingRight - bookmark_menu_width - |
543 app_menu_width - page_menu_width - browser_actions_width - | 606 app_menu_width - page_menu_width - browser_actions_width - |
544 kMenuButtonOffset - go_button_width - location_x; | 607 kMenuButtonOffset - go_button_width - location_x; |
545 | 608 |
546 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), | 609 location_bar_->SetBounds(location_x, child_y, std::max(available_width, 0), |
547 child_height); | 610 child_height); |
548 | 611 |
549 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y, | 612 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y, |
550 go_button_width, child_height); | 613 go_button_width, child_height); |
551 | |
552 int next_menu_x = go_->x() + go_->width() + kMenuButtonOffset; | 614 int next_menu_x = go_->x() + go_->width() + kMenuButtonOffset; |
553 | 615 |
554 browser_actions_->SetBounds(next_menu_x, 0, browser_actions_width, height()); | 616 browser_actions_->SetBounds(next_menu_x, 0, browser_actions_width, height()); |
555 | |
556 // The browser actions need to do a layout explicitly, because when an | 617 // The browser actions need to do a layout explicitly, because when an |
557 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 618 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
558 // re-adds everything, regardless of whether it has a page action. For a | 619 // re-adds everything, regardless of whether it has a page action. For a |
559 // page action, browser action bounds do not change, as a result of which | 620 // page action, browser action bounds do not change, as a result of which |
560 // SetBounds does not do a layout at all. | 621 // SetBounds does not do a layout at all. |
561 // TODO(sidchat): Rework the above bahavior so that explicit layout is not | 622 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
562 // required. | 623 // required. |
563 browser_actions_->Layout(); | 624 browser_actions_->Layout(); |
564 | |
565 next_menu_x += browser_actions_width; | 625 next_menu_x += browser_actions_width; |
566 | 626 |
567 if (bookmark_menu_) { | 627 if (bookmark_menu_) { |
568 bookmark_menu_->SetBounds(next_menu_x, child_y, bookmark_menu_width, | 628 bookmark_menu_->SetBounds(next_menu_x, child_y, bookmark_menu_width, |
569 child_height); | 629 child_height); |
570 next_menu_x += bookmark_menu_width; | 630 next_menu_x += bookmark_menu_width; |
571 } | 631 } |
572 | 632 |
573 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); | 633 page_menu_->SetBounds(next_menu_x, child_y, page_menu_width, child_height); |
574 next_menu_x += page_menu_width; | 634 next_menu_x += page_menu_width; |
(...skipping 17 matching lines...) Expand all Loading... |
592 } | 652 } |
593 | 653 |
594 // For glass, we need to draw a black line below the location bar to separate | 654 // For glass, we need to draw a black line below the location bar to separate |
595 // it from the content area. For non-glass, the NonClientView draws the | 655 // it from the content area. For non-glass, the NonClientView draws the |
596 // toolbar background below the location bar for us. | 656 // toolbar background below the location bar for us. |
597 if (GetWindow()->GetNonClientView()->UseNativeFrame()) | 657 if (GetWindow()->GetNonClientView()->UseNativeFrame()) |
598 canvas->FillRectInt(SK_ColorBLACK, 0, height() - 1, width(), 1); | 658 canvas->FillRectInt(SK_ColorBLACK, 0, height() - 1, width(), 1); |
599 } | 659 } |
600 | 660 |
601 void ToolbarView::ThemeChanged() { | 661 void ToolbarView::ThemeChanged() { |
602 LoadLeftSideControlsImages(); | 662 LoadImages(); |
603 LoadCenterStackImages(); | |
604 LoadRightSideControlsImages(); | |
605 } | 663 } |
606 | 664 |
607 //////////////////////////////////////////////////////////////////////////////// | 665 //////////////////////////////////////////////////////////////////////////////// |
608 // ToolbarView, private: | 666 // ToolbarView, private: |
609 | 667 |
610 int ToolbarView::PopupTopSpacing() const { | 668 int ToolbarView::PopupTopSpacing() const { |
611 return GetWindow()->GetNonClientView()->UseNativeFrame() ? | 669 return GetWindow()->GetNonClientView()->UseNativeFrame() ? |
612 0 : kPopupTopSpacingNonGlass; | 670 0 : kPopupTopSpacingNonGlass; |
613 } | 671 } |
614 | 672 |
615 void ToolbarView::CreateLeftSideControls() { | 673 void ToolbarView::LoadImages() { |
616 back_ = new views::ButtonDropDown(this, back_menu_model_.get()); | |
617 back_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | | |
618 views::Event::EF_MIDDLE_BUTTON_DOWN); | |
619 back_->set_tag(IDC_BACK); | |
620 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, | |
621 views::ImageButton::ALIGN_TOP); | |
622 back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK)); | |
623 back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK)); | |
624 back_->SetID(VIEW_ID_BACK_BUTTON); | |
625 | |
626 forward_ = new views::ButtonDropDown(this, forward_menu_model_.get()); | |
627 forward_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | | |
628 views::Event::EF_MIDDLE_BUTTON_DOWN); | |
629 forward_->set_tag(IDC_FORWARD); | |
630 forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD)); | |
631 forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD)); | |
632 forward_->SetID(VIEW_ID_FORWARD_BUTTON); | |
633 | |
634 home_ = new views::ImageButton(this); | |
635 home_->set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | | |
636 views::Event::EF_MIDDLE_BUTTON_DOWN); | |
637 home_->set_tag(IDC_HOME); | |
638 home_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_HOME)); | |
639 home_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_HOME)); | |
640 home_->SetID(VIEW_ID_HOME_BUTTON); | |
641 | |
642 LoadLeftSideControlsImages(); | |
643 | |
644 AddChildView(back_); | |
645 AddChildView(forward_); | |
646 AddChildView(home_); | |
647 } | |
648 | |
649 void ToolbarView::CreateCenterStack(Profile *profile) { | |
650 reload_ = new views::ImageButton(this); | |
651 reload_->set_tag(IDC_RELOAD); | |
652 reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD)); | |
653 reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD)); | |
654 reload_->SetID(VIEW_ID_RELOAD_BUTTON); | |
655 | |
656 location_bar_ = new LocationBarView(profile, browser_->command_updater(), | |
657 model_, this, (display_mode_ == DISPLAYMODE_LOCATION) ? | |
658 LocationBarView::POPUP : LocationBarView::NORMAL); | |
659 | |
660 // The Go button. | |
661 go_ = new GoButton(location_bar_, browser_); | |
662 go_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_GO)); | |
663 go_->SetID(VIEW_ID_GO_BUTTON); | |
664 | |
665 LoadCenterStackImages(); | |
666 | |
667 AddChildView(reload_); | |
668 location_bar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_LOCATION)); | |
669 AddChildView(location_bar_); | |
670 location_bar_->Init(); | |
671 AddChildView(go_); | |
672 } | |
673 | |
674 void ToolbarView::CreateRightSideControls(Profile* profile) { | |
675 browser_actions_ = new BrowserActionsContainer(browser_, this, | |
676 true); // should_save_size | |
677 | |
678 page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | |
679 page_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_PAGE)); | |
680 page_menu_->SetTooltipText(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP)); | |
681 page_menu_->SetID(VIEW_ID_PAGE_MENU); | |
682 | |
683 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | |
684 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); | |
685 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | |
686 l10n_util::GetString(IDS_PRODUCT_NAME))); | |
687 app_menu_->SetID(VIEW_ID_APP_MENU); | |
688 | |
689 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kBookmarkMenu)) { | |
690 bookmark_menu_ = new BookmarkMenuButton(browser_); | |
691 AddChildView(bookmark_menu_); | |
692 } else { | |
693 bookmark_menu_ = NULL; | |
694 } | |
695 | |
696 // Catch the case where the window is created after we detect a new version. | |
697 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) | |
698 ShowUpgradeReminder(); | |
699 | |
700 LoadRightSideControlsImages(); | |
701 | |
702 AddChildView(browser_actions_); | |
703 AddChildView(page_menu_); | |
704 AddChildView(app_menu_); | |
705 } | |
706 | |
707 void ToolbarView::LoadLeftSideControlsImages() { | |
708 ThemeProvider* tp = GetThemeProvider(); | 674 ThemeProvider* tp = GetThemeProvider(); |
709 | 675 |
710 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | 676 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); |
711 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); | 677 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); |
712 | 678 |
713 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); | 679 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); |
714 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); | 680 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); |
715 back_->SetImage(views::CustomButton::BS_PUSHED, | 681 back_->SetImage(views::CustomButton::BS_PUSHED, |
716 tp->GetBitmapNamed(IDR_BACK_P)); | 682 tp->GetBitmapNamed(IDR_BACK_P)); |
717 back_->SetImage(views::CustomButton::BS_DISABLED, | 683 back_->SetImage(views::CustomButton::BS_DISABLED, |
(...skipping 11 matching lines...) Expand all Loading... |
729 tp->GetBitmapNamed(IDR_FORWARD_D)); | 695 tp->GetBitmapNamed(IDR_FORWARD_D)); |
730 forward_->SetBackground(color, background, | 696 forward_->SetBackground(color, background, |
731 tp->GetBitmapNamed(IDR_FORWARD_MASK)); | 697 tp->GetBitmapNamed(IDR_FORWARD_MASK)); |
732 | 698 |
733 home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); | 699 home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); |
734 home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); | 700 home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); |
735 home_->SetImage(views::CustomButton::BS_PUSHED, | 701 home_->SetImage(views::CustomButton::BS_PUSHED, |
736 tp->GetBitmapNamed(IDR_HOME_P)); | 702 tp->GetBitmapNamed(IDR_HOME_P)); |
737 home_->SetBackground(color, background, | 703 home_->SetBackground(color, background, |
738 tp->GetBitmapNamed(IDR_BUTTON_MASK)); | 704 tp->GetBitmapNamed(IDR_BUTTON_MASK)); |
739 } | |
740 | |
741 void ToolbarView::LoadCenterStackImages() { | |
742 ThemeProvider* tp = GetThemeProvider(); | |
743 | |
744 SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); | |
745 SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); | |
746 | 705 |
747 reload_->SetImage(views::CustomButton::BS_NORMAL, | 706 reload_->SetImage(views::CustomButton::BS_NORMAL, |
748 tp->GetBitmapNamed(IDR_RELOAD)); | 707 tp->GetBitmapNamed(IDR_RELOAD)); |
749 reload_->SetImage(views::CustomButton::BS_HOT, | 708 reload_->SetImage(views::CustomButton::BS_HOT, |
750 tp->GetBitmapNamed(IDR_RELOAD_H)); | 709 tp->GetBitmapNamed(IDR_RELOAD_H)); |
751 reload_->SetImage(views::CustomButton::BS_PUSHED, | 710 reload_->SetImage(views::CustomButton::BS_PUSHED, |
752 tp->GetBitmapNamed(IDR_RELOAD_P)); | 711 tp->GetBitmapNamed(IDR_RELOAD_P)); |
753 reload_->SetBackground(color, background, | 712 reload_->SetBackground(color, background, |
754 tp->GetBitmapNamed(IDR_RELOAD_MASK)); | 713 tp->GetBitmapNamed(IDR_RELOAD_MASK)); |
755 | 714 |
756 go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO)); | 715 go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO)); |
757 go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H)); | 716 go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H)); |
758 go_->SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_GO_P)); | 717 go_->SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_GO_P)); |
759 go_->SetToggledImage(views::CustomButton::BS_NORMAL, | 718 go_->SetToggledImage(views::CustomButton::BS_NORMAL, |
760 tp->GetBitmapNamed(IDR_STOP)); | 719 tp->GetBitmapNamed(IDR_STOP)); |
761 go_->SetToggledImage(views::CustomButton::BS_HOT, | 720 go_->SetToggledImage(views::CustomButton::BS_HOT, |
762 tp->GetBitmapNamed(IDR_STOP_H)); | 721 tp->GetBitmapNamed(IDR_STOP_H)); |
763 go_->SetToggledImage(views::CustomButton::BS_PUSHED, | 722 go_->SetToggledImage(views::CustomButton::BS_PUSHED, |
764 tp->GetBitmapNamed(IDR_STOP_P)); | 723 tp->GetBitmapNamed(IDR_STOP_P)); |
765 go_->SetBackground(color, background, | 724 go_->SetBackground(color, background, |
766 tp->GetBitmapNamed(IDR_GO_MASK)); | 725 tp->GetBitmapNamed(IDR_GO_MASK)); |
| 726 |
| 727 // We use different menu button images if the locale is right-to-left. |
| 728 page_menu_->SetIcon(*tp->GetBitmapNamed( |
| 729 base::i18n::IsRTL() ? IDR_MENU_PAGE_RTL : IDR_MENU_PAGE)); |
| 730 app_menu_->SetIcon(GetAppMenuIcon()); |
| 731 if (bookmark_menu_ != NULL) |
| 732 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); |
767 } | 733 } |
768 | 734 |
769 void ToolbarView::ShowUpgradeReminder() { | 735 void ToolbarView::ShowUpgradeReminder() { |
770 update_reminder_animation_.reset(new SlideAnimation(this)); | 736 update_reminder_animation_.reset(new SlideAnimation(this)); |
771 update_reminder_animation_->SetSlideDuration(kPulseDuration); | 737 update_reminder_animation_->SetSlideDuration(kPulseDuration); |
772 | 738 |
773 // Then start the recurring timer for pulsating it. | 739 // Then start the recurring timer for pulsating it. |
774 upgrade_reminder_pulse_timer_.Start( | 740 upgrade_reminder_pulse_timer_.Start( |
775 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), | 741 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), |
776 this, &ToolbarView::PulsateUpgradeNotifier); | 742 this, &ToolbarView::PulsateUpgradeNotifier); |
777 } | 743 } |
778 | 744 |
779 void ToolbarView::PulsateUpgradeNotifier() { | 745 void ToolbarView::PulsateUpgradeNotifier() { |
780 // Start the pulsating animation. | 746 // Start the pulsating animation. |
781 update_reminder_animation_->Reset(0.0); | 747 update_reminder_animation_->Reset(0.0); |
782 update_reminder_animation_->Show(); | 748 update_reminder_animation_->Show(); |
783 } | 749 } |
784 | 750 |
785 SkBitmap ToolbarView::GetAppMenuIcon() { | 751 SkBitmap ToolbarView::GetAppMenuIcon() { |
786 ThemeProvider* tp = GetThemeProvider(); | 752 ThemeProvider* tp = GetThemeProvider(); |
787 | 753 |
788 SkBitmap icon; | |
789 | |
790 // We use different menu button images if the locale is right-to-left. | 754 // We use different menu button images if the locale is right-to-left. |
791 if (base::i18n::IsRTL()) | 755 SkBitmap icon = *tp->GetBitmapNamed( |
792 icon = *tp->GetBitmapNamed(IDR_MENU_CHROME_RTL); | 756 base::i18n::IsRTL() ? IDR_MENU_CHROME_RTL : IDR_MENU_CHROME); |
793 else | |
794 icon = *tp->GetBitmapNamed(IDR_MENU_CHROME); | |
795 | 757 |
796 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) | 758 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) |
797 return icon; | 759 return icon; |
798 | 760 |
799 // Draw the chrome app menu icon onto the canvas. | 761 // Draw the chrome app menu icon onto the canvas. |
800 scoped_ptr<gfx::Canvas> canvas( | 762 scoped_ptr<gfx::Canvas> canvas( |
801 new gfx::Canvas(icon.width(), icon.height(), false)); | 763 new gfx::Canvas(icon.width(), icon.height(), false)); |
802 canvas->DrawBitmapInt(icon, 0, 0); | 764 canvas->DrawBitmapInt(icon, 0, 0); |
803 | 765 |
804 SkBitmap badge; | 766 SkBitmap badge; |
805 | |
806 static bool has_faded_in = false; | 767 static bool has_faded_in = false; |
807 if (!has_faded_in) { | 768 if (!has_faded_in) { |
808 SkBitmap* dot = tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); | 769 SkBitmap* dot = tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); |
809 SkBitmap transparent; | 770 SkBitmap transparent; |
810 transparent.setConfig(dot->getConfig(), dot->width(), dot->height()); | 771 transparent.setConfig(dot->getConfig(), dot->width(), dot->height()); |
811 transparent.allocPixels(); | 772 transparent.allocPixels(); |
812 transparent.eraseARGB(0, 0, 0, 0); | 773 transparent.eraseARGB(0, 0, 0, 0); |
813 badge = SkBitmapOperations::CreateBlendedBitmap( | 774 badge = SkBitmapOperations::CreateBlendedBitmap( |
814 *dot, transparent, 1.0 - update_reminder_animation_->GetCurrentValue()); | 775 *dot, transparent, 1.0 - update_reminder_animation_->GetCurrentValue()); |
815 if (update_reminder_animation_->GetCurrentValue() == 1.0) | 776 if (update_reminder_animation_->GetCurrentValue() == 1.0) |
816 has_faded_in = true; | 777 has_faded_in = true; |
817 } else { | 778 } else { |
818 // Convert animation values that start from 0.0 and incrementally go | 779 // Convert animation values that start from 0.0 and incrementally go |
819 // up to 1.0 into values that start in 0.0, go to 1.0 and then back | 780 // up to 1.0 into values that start in 0.0, go to 1.0 and then back |
820 // to 0.0 (to create a pulsing effect). | 781 // to 0.0 (to create a pulsing effect). |
821 double value = 1.0 - | 782 double value = 1.0 - |
822 abs(2.0 * update_reminder_animation_->GetCurrentValue() - | 783 abs(2.0 * update_reminder_animation_->GetCurrentValue() - |
823 1.0); | 784 1.0); |
824 | 785 |
825 // Add the badge to it. | 786 // Add the badge to it. |
826 badge = SkBitmapOperations::CreateBlendedBitmap( | 787 badge = SkBitmapOperations::CreateBlendedBitmap( |
827 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), | 788 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), |
828 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), | 789 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), |
829 value); | 790 value); |
830 } | 791 } |
831 | 792 |
832 int x_pos = kUpgradeDotOffset; | 793 int x_pos = base::i18n::IsRTL() ? |
833 if (base::i18n::IsRTL()) | 794 (icon.width() - badge.width()) : kUpgradeDotOffset; |
834 x_pos = icon.width() - badge.width(); | |
835 canvas->DrawBitmapInt(badge, x_pos, icon.height() - badge.height()); | 795 canvas->DrawBitmapInt(badge, x_pos, icon.height() - badge.height()); |
836 | 796 |
837 return canvas->ExtractBitmap(); | 797 return canvas->ExtractBitmap(); |
838 } | 798 } |
839 | 799 |
840 void ToolbarView::LoadRightSideControlsImages() { | |
841 ThemeProvider* tp = GetThemeProvider(); | |
842 | |
843 // We use different menu button images if the locale is right-to-left. | |
844 if (base::i18n::IsRTL()) | |
845 page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE_RTL)); | |
846 else | |
847 page_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_PAGE)); | |
848 | |
849 app_menu_->SetIcon(GetAppMenuIcon()); | |
850 | |
851 if (bookmark_menu_ != NULL) | |
852 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); | |
853 } | |
854 | |
855 void ToolbarView::RunPageMenu(const gfx::Point& pt) { | 800 void ToolbarView::RunPageMenu(const gfx::Point& pt) { |
856 bool destroyed_flag = false; | 801 bool destroyed_flag = false; |
857 destroyed_flag_ = &destroyed_flag; | 802 destroyed_flag_ = &destroyed_flag; |
858 | 803 |
859 page_menu_model_.reset(new PageMenuModel(this, browser_)); | 804 page_menu_model_.reset(new PageMenuModel(this, browser_)); |
860 page_menu_menu_.reset(new views::Menu2(page_menu_model_.get())); | 805 page_menu_menu_.reset(new views::Menu2(page_menu_model_.get())); |
861 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { | 806 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { |
862 page_menu_menu_->AddMenuListener(menu_listeners_[i]); | 807 page_menu_menu_->AddMenuListener(menu_listeners_[i]); |
863 } | 808 } |
864 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 809 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
865 | 810 |
866 if (destroyed_flag) | 811 if (destroyed_flag) |
867 return; | 812 return; |
868 | 813 |
869 destroyed_flag_ = NULL; | 814 destroyed_flag_ = NULL; |
870 | 815 |
871 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { | 816 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { |
872 page_menu_menu_->RemoveMenuListener(menu_listeners_[i]); | 817 page_menu_menu_->RemoveMenuListener(menu_listeners_[i]); |
873 } | 818 } |
874 SwitchToOtherMenuIfNeeded(page_menu_menu_.get(), app_menu_); | 819 SwitchToOtherMenuIfNeeded(page_menu_menu_.get(), app_menu_); |
875 } | 820 } |
876 | 821 |
877 void ToolbarView::RunAppMenu(const gfx::Point& pt) { | 822 void ToolbarView::RunAppMenu(const gfx::Point& pt) { |
878 bool destroyed_flag = false; | 823 bool destroyed_flag = false; |
879 destroyed_flag_ = &destroyed_flag; | 824 destroyed_flag_ = &destroyed_flag; |
880 | 825 |
881 if (app_menu_model_->BuildProfileSubMenu()) | 826 if (app_menu_model_->BuildProfileSubMenu()) |
882 app_menu_menu_->Rebuild(); | 827 app_menu_menu_->Rebuild(); |
883 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { | 828 for (size_t i = 0; i < menu_listeners_.size(); i++) |
884 app_menu_menu_->AddMenuListener(menu_listeners_[i]); | 829 app_menu_menu_->AddMenuListener(menu_listeners_[i]); |
885 } | |
886 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 830 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
887 | 831 |
888 if (destroyed_flag) | 832 if (destroyed_flag) |
889 return; | 833 return; |
890 | |
891 destroyed_flag_ = NULL; | 834 destroyed_flag_ = NULL; |
892 | 835 |
893 // Stop pulsating the upgrade reminder on the app menu, if active. | 836 // Stop pulsating the upgrade reminder on the app menu, if active. |
894 upgrade_reminder_pulse_timer_.Stop(); | 837 upgrade_reminder_pulse_timer_.Stop(); |
895 | 838 |
896 for (unsigned int i = 0; i < menu_listeners_.size(); i++) { | 839 for (size_t i = 0; i < menu_listeners_.size(); i++) |
897 app_menu_menu_->RemoveMenuListener(menu_listeners_[i]); | 840 app_menu_menu_->RemoveMenuListener(menu_listeners_[i]); |
898 } | |
899 SwitchToOtherMenuIfNeeded(app_menu_menu_.get(), page_menu_); | 841 SwitchToOtherMenuIfNeeded(app_menu_menu_.get(), page_menu_); |
900 } | 842 } |
901 | 843 |
902 void ToolbarView::SwitchToOtherMenuIfNeeded( | 844 void ToolbarView::SwitchToOtherMenuIfNeeded( |
903 views::Menu2* previous_menu, views::MenuButton* next_menu_button) { | 845 views::Menu2* previous_menu, |
| 846 views::MenuButton* next_menu_button) { |
904 // If the user tried to move to the right or left, switch from the | 847 // If the user tried to move to the right or left, switch from the |
905 // app menu to the page menu. Switching to the next menu is delayed | 848 // app menu to the page menu. Switching to the next menu is delayed |
906 // until the next event loop so that the call stack that initiated | 849 // until the next event loop so that the call stack that initiated |
907 // activating the first menu can return. (If we didn't do this, the | 850 // activating the first menu can return. (If we didn't do this, the |
908 // call stack would grow each time the user switches menus, and | 851 // call stack would grow each time the user switches menus, and |
909 // the actions taken after the user finally exits a menu would cause | 852 // the actions taken after the user finally exits a menu would cause |
910 // flicker.) | 853 // flicker.) |
911 views::MenuWrapper::MenuAction action = previous_menu->GetMenuAction(); | 854 views::MenuWrapper::MenuAction action = previous_menu->GetMenuAction(); |
912 if (action == views::MenuWrapper::MENU_ACTION_NEXT || | 855 if (action == views::MenuWrapper::MENU_ACTION_NEXT || |
913 action == views::MenuWrapper::MENU_ACTION_PREVIOUS) { | 856 action == views::MenuWrapper::MENU_ACTION_PREVIOUS) { |
914 MessageLoop::current()->PostTask( | 857 MessageLoop::current()->PostTask(FROM_HERE, |
915 FROM_HERE, method_factory_.NewRunnableMethod( | 858 method_factory_.NewRunnableMethod(&ToolbarView::ActivateMenuButton, |
916 &ToolbarView::ActivateMenuButton, | 859 next_menu_button)); |
917 next_menu_button)); | |
918 } | 860 } |
919 } | 861 } |
920 | 862 |
921 void ToolbarView::ActivateMenuButton(views::MenuButton* menu_button) { | 863 void ToolbarView::ActivateMenuButton(views::MenuButton* menu_button) { |
922 #if defined(OS_LINUX) | 864 #if defined(OS_WIN) |
| 865 // On Windows, we have to explicitly clear the focus before opening |
| 866 // the pop-up menu, then set the focus again when it closes. |
| 867 GetFocusManager()->ClearFocus(); |
| 868 #elif defined(OS_LINUX) |
923 // Under GTK, opening a pop-up menu causes the main window to lose focus. | 869 // Under GTK, opening a pop-up menu causes the main window to lose focus. |
924 // Focus is automatically returned when the menu closes. | 870 // Focus is automatically returned when the menu closes. |
925 // | 871 // |
926 // Make sure that the menu button being activated has focus, so that | 872 // Make sure that the menu button being activated has focus, so that |
927 // when the user escapes from the menu without selecting anything, focus | 873 // when the user escapes from the menu without selecting anything, focus |
928 // will be returned here. | 874 // will be returned here. |
929 if (!menu_button->HasFocus()) { | 875 if (!menu_button->HasFocus()) { |
930 menu_button->RequestFocus(); | 876 menu_button->RequestFocus(); |
931 GetFocusManager()->StoreFocusedView(); | 877 GetFocusManager()->StoreFocusedView(); |
932 } | 878 } |
933 #endif | 879 #endif |
934 | 880 |
935 #if defined(OS_WIN) | |
936 // On Windows, we have to explicitly clear the focus before opening | |
937 // the pop-up menu, then set the focus again when it closes. | |
938 GetFocusManager()->ClearFocus(); | |
939 #endif | |
940 | |
941 // Tell the menu button to activate, opening its pop-up menu. | 881 // Tell the menu button to activate, opening its pop-up menu. |
942 menu_button->Activate(); | 882 menu_button->Activate(); |
943 | 883 |
944 #if defined(OS_WIN) | 884 #if defined(OS_WIN) |
945 EnterMenuBarEmulationMode(last_focused_view_storage_id_, menu_button); | 885 EnterMenuBarEmulationMode(last_focused_view_storage_id_, menu_button); |
946 #endif | 886 #endif |
947 } | 887 } |
948 | 888 |
949 void ToolbarView::ExitMenuBarEmulationMode() { | 889 void ToolbarView::ExitMenuBarEmulationMode() { |
950 if (page_menu_->HasFocus() || app_menu_->HasFocus()) | 890 if (page_menu_->HasFocus() || app_menu_->HasFocus()) |
(...skipping 14 matching lines...) Expand all Loading... |
965 last_focused_view->RequestFocus(); | 905 last_focused_view->RequestFocus(); |
966 } else { | 906 } else { |
967 // Focus the location bar | 907 // Focus the location bar |
968 views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName); | 908 views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName); |
969 if (view) { | 909 if (view) { |
970 BrowserView* browser_view = static_cast<BrowserView*>(view); | 910 BrowserView* browser_view = static_cast<BrowserView*>(view); |
971 browser_view->SetFocusToLocationBar(false); | 911 browser_view->SetFocusToLocationBar(false); |
972 } | 912 } |
973 } | 913 } |
974 } | 914 } |
OLD | NEW |