| OLD | NEW |
| 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/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 6 | 6 |
| 7 #include "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 | 15 |
| 16 ChromeLauncherAppMenuItemBrowser::ChromeLauncherAppMenuItemBrowser( | 16 ChromeLauncherAppMenuItemBrowser::ChromeLauncherAppMenuItemBrowser( |
| 17 const base::string16 title, | 17 const base::string16 title, |
| 18 const gfx::Image* icon, | 18 const gfx::Image* icon, |
| 19 Browser* browser, | 19 Browser* browser) |
| 20 bool has_leading_separator) | 20 : ash::ShelfApplicationMenuItem(title, icon), browser_(browser) { |
| 21 : ChromeLauncherAppMenuItem(title, icon, has_leading_separator), | |
| 22 browser_(browser) { | |
| 23 DCHECK(browser); | 21 DCHECK(browser); |
| 24 registrar_.Add(this, | 22 registrar_.Add(this, |
| 25 chrome::NOTIFICATION_BROWSER_CLOSING, | 23 chrome::NOTIFICATION_BROWSER_CLOSING, |
| 26 content::Source<Browser>(browser)); | 24 content::Source<Browser>(browser)); |
| 27 } | 25 } |
| 28 | 26 |
| 29 ChromeLauncherAppMenuItemBrowser::~ChromeLauncherAppMenuItemBrowser() {} | 27 ChromeLauncherAppMenuItemBrowser::~ChromeLauncherAppMenuItemBrowser() {} |
| 30 | 28 |
| 31 bool ChromeLauncherAppMenuItemBrowser::IsEnabled() const { | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 void ChromeLauncherAppMenuItemBrowser::Execute(int event_flags) { | 29 void ChromeLauncherAppMenuItemBrowser::Execute(int event_flags) { |
| 36 if (browser_) { | 30 if (browser_) { |
| 37 if (event_flags & (ui::EF_SHIFT_DOWN | ui::EF_MIDDLE_MOUSE_BUTTON)) { | 31 if (event_flags & (ui::EF_SHIFT_DOWN | ui::EF_MIDDLE_MOUSE_BUTTON)) { |
| 38 TabStripModel* tab_strip = browser_->tab_strip_model(); | 32 TabStripModel* tab_strip = browser_->tab_strip_model(); |
| 39 tab_strip->CloseAllTabs(); | 33 tab_strip->CloseAllTabs(); |
| 40 } else { | 34 } else { |
| 41 // In ChromeOS multiprofile scenario we might need to teleport the window | 35 // In ChromeOS multiprofile scenario we might need to teleport the window |
| 42 // back to the current user desktop. | 36 // back to the current user desktop. |
| 43 multi_user_util::MoveWindowToCurrentDesktop( | 37 multi_user_util::MoveWindowToCurrentDesktop( |
| 44 browser_->window()->GetNativeWindow()); | 38 browser_->window()->GetNativeWindow()); |
| 45 browser_->window()->Show(); | 39 browser_->window()->Show(); |
| 46 ash::wm::ActivateWindow(browser_->window()->GetNativeWindow()); | 40 ash::wm::ActivateWindow(browser_->window()->GetNativeWindow()); |
| 47 } | 41 } |
| 48 } | 42 } |
| 49 } | 43 } |
| 50 | 44 |
| 51 void ChromeLauncherAppMenuItemBrowser::Observe( | 45 void ChromeLauncherAppMenuItemBrowser::Observe( |
| 52 int type, | 46 int type, |
| 53 const content::NotificationSource& source, | 47 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) { | 48 const content::NotificationDetails& details) { |
| 55 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); | 49 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); |
| 56 DCHECK_EQ(browser_, content::Source<Browser>(source).ptr()); | 50 DCHECK_EQ(browser_, content::Source<Browser>(source).ptr()); |
| 57 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 51 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
| 58 content::Source<Browser>(browser_)); | 52 content::Source<Browser>(browser_)); |
| 59 browser_ = nullptr; | 53 browser_ = nullptr; |
| 60 } | 54 } |
| OLD | NEW |