Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| diff --git a/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| index 899293e1faf051e90fe97d8a029a53a30f5ca7c4..ff1bb898ba9f59fb0bde8750fa23d75e3ce8e3de 100644 |
| --- a/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| +++ b/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| @@ -4,60 +4,23 @@ |
| #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| -#include "ash/wm/window_state.h" |
| #include "ash/wm/window_util.h" |
| -#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| -#include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" |
| #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| -#include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| -#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| -#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| -#include "components/favicon/content/content_favicon_driver.h" |
| -#include "content/public/browser/web_contents.h" |
| -#include "extensions/browser/app_window/app_window.h" |
| -#include "extensions/browser/app_window/native_app_window.h" |
| -#include "skia/ext/image_operations.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/window.h" |
| -#include "ui/events/event.h" |
| -#include "ui/gfx/image/image_skia.h" |
| +#include "ui/base/base_window.h" |
| #include "ui/wm/core/window_animations.h" |
| -using extensions::AppWindow; |
| - |
| namespace { |
| -// Size of the icon in the shelf launcher in display-independent pixels. |
| -const int kAppListIconSize = 24; |
| - |
| -// This will return a slightly smaller icon than the app icon to be used in |
| -// the application list menu. |
| -gfx::Image GetAppListIcon(AppWindow* app_window) { |
| - // TODO(skuhne): We instead might want to use LoadImages in |
| - // AppWindow::UpdateExtensionAppIcon() to let the extension give us |
| - // pre-defined icons in the launcher and the launcher list sizes. Since there |
| - // is no mock yet, doing this now seems a bit premature and we scale for the |
| - // time being. |
| - if (app_window->app_icon().IsEmpty()) |
| - return gfx::Image(); |
| - |
| - SkBitmap bmp = |
| - skia::ImageOperations::Resize(*app_window->app_icon().ToSkBitmap(), |
| - skia::ImageOperations::RESIZE_BEST, |
| - kAppListIconSize, |
| - kAppListIconSize); |
| - return gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp)); |
| -} |
| - |
| // Functor for std::find_if used in AppLauncherItemController. |
| -class AppWindowHasWindow { |
| +class WindowHasNativeWindow { |
| public: |
| - explicit AppWindowHasWindow(aura::Window* window) : window_(window) {} |
| + explicit WindowHasNativeWindow(aura::Window* window) : window_(window) {} |
| - bool operator()(AppWindow* app_window) const { |
| - return app_window->GetNativeWindow() == window_; |
| + bool operator()(ui::BaseWindow* window) const { |
| + return window->GetNativeWindow() == window_; |
| } |
| - |
| private: |
| const aura::Window* window_; |
| }; |
| @@ -70,49 +33,44 @@ AppWindowLauncherItemController::AppWindowLauncherItemController( |
| const std::string& app_id, |
| ChromeLauncherController* controller) |
| : LauncherItemController(type, app_id, controller), |
| - last_active_app_window_(NULL), |
| app_shelf_id_(app_shelf_id), |
| observed_windows_(this) {} |
| AppWindowLauncherItemController::~AppWindowLauncherItemController() {} |
| -void AppWindowLauncherItemController::AddAppWindow( |
| - AppWindow* app_window, |
| - ash::ShelfItemStatus status) { |
| - if (app_window->window_type_is_panel() && type() != TYPE_APP_PANEL) |
| - LOG(ERROR) << "AppWindow of type Panel added to non-panel launcher item"; |
| - app_windows_.push_front(app_window); |
| - observed_windows_.Add(app_window->GetNativeWindow()); |
| +void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* window) { |
| + windows_.push_front(window); |
| + observed_windows_.Add(window->GetNativeWindow()); |
| } |
| -void AppWindowLauncherItemController::RemoveAppWindowForWindow( |
| +void AppWindowLauncherItemController::RemoveWindowForNativeWindow( |
| aura::Window* window) { |
| - AppWindowList::iterator iter = std::find_if( |
| - app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window)); |
| - if (iter != app_windows_.end()) { |
| - if (*iter == last_active_app_window_) |
| - last_active_app_window_ = NULL; |
| - app_windows_.erase(iter); |
| + WindowList::iterator iter = std::find_if(windows_.begin(), windows_.end(), |
| + WindowHasNativeWindow(window)); |
|
xiyuan
2016/03/23 23:22:53
nit: we can use lambda
e.g.
auto iter = std::fin
khmel
2016/03/24 16:30:37
Thanks for idea, also use helper function to reduc
|
| + if (iter != windows_.end()) { |
| + if (*iter == last_active_window_) |
| + last_active_window_ = nullptr; |
| + OnWindowRemoved(*iter); |
| + windows_.erase(iter); |
| } |
| observed_windows_.Remove(window); |
| } |
| void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
| - AppWindowList::iterator iter = std::find_if( |
| - app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window)); |
| - if (iter != app_windows_.end()) |
| - last_active_app_window_ = *iter; |
| + WindowList::iterator iter = std::find_if(windows_.begin(), windows_.end(), |
| + WindowHasNativeWindow(window)); |
|
xiyuan
2016/03/23 23:22:53
nit: use lambda ?
khmel
2016/03/24 16:30:37
Done.
|
| + if (iter != windows_.end()) |
| + last_active_window_ = *iter; |
| } |
| bool AppWindowLauncherItemController::IsOpen() const { |
| - return !app_windows_.empty(); |
| + return !windows_.empty(); |
| } |
| bool AppWindowLauncherItemController::IsVisible() const { |
| // Return true if any windows are visible. |
| - for (AppWindowList::const_iterator iter = app_windows_.begin(); |
| - iter != app_windows_.end(); |
| - ++iter) { |
| + for (WindowList::const_iterator iter = windows_.begin(); |
| + iter != windows_.end(); ++iter) { |
|
xiyuan
2016/03/23 23:22:52
nit: We can use range loop now.
i.e.
for (const a
khmel
2016/03/24 16:30:37
Done.
|
| if ((*iter)->GetNativeWindow()->IsVisible()) |
| return true; |
| } |
| @@ -126,27 +84,26 @@ void AppWindowLauncherItemController::Launch(ash::LaunchSource source, |
| ash::ShelfItemDelegate::PerformedAction |
| AppWindowLauncherItemController::Activate(ash::LaunchSource source) { |
| - DCHECK(!app_windows_.empty()); |
| - AppWindow* window_to_activate = |
| - last_active_app_window_ ? last_active_app_window_ : app_windows_.back(); |
| - window_to_activate->GetBaseWindow()->Activate(); |
| + DCHECK(!windows_.empty()); |
| + ui::BaseWindow* window_to_activate = |
| + last_active_window_ ? last_active_window_ : windows_.back(); |
| + window_to_activate->Activate(); |
| return kExistingWindowActivated; |
| } |
| void AppWindowLauncherItemController::Close() { |
| // Note: Closing windows may affect the contents of app_windows_. |
| - AppWindowList windows_to_close = app_windows_; |
| - for (AppWindowList::iterator iter = windows_to_close.begin(); |
| - iter != windows_to_close.end(); |
| - ++iter) { |
| - (*iter)->GetBaseWindow()->Close(); |
| + WindowList windows_to_close = windows_; |
| + for (WindowList::iterator iter = windows_to_close.begin(); |
| + iter != windows_to_close.end(); ++iter) { |
|
xiyuan
2016/03/23 23:22:52
nit: range loop?
khmel
2016/03/24 16:30:37
Done.
|
| + (*iter)->Close(); |
| } |
| } |
| void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
| - if (index >= app_windows_.size()) |
| + if (index >= windows_.size()) |
| return; |
| - AppWindowList::iterator it = app_windows_.begin(); |
| + WindowList::iterator it = windows_.begin(); |
| std::advance(it, index); |
| ShowAndActivateOrMinimize(*it); |
| } |
| @@ -155,89 +112,38 @@ ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList( |
| int event_flags) { |
| ChromeLauncherAppMenuItems items; |
| items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
| - int index = 0; |
| - for (AppWindowList::iterator iter = app_windows_.begin(); |
| - iter != app_windows_.end(); |
| - ++iter) { |
| - AppWindow* app_window = *iter; |
| - |
| - // If the app's web contents provides a favicon, use it. Otherwise, use a |
| - // scaled down app icon. |
| - favicon::FaviconDriver* favicon_driver = |
| - favicon::ContentFaviconDriver::FromWebContents( |
| - app_window->web_contents()); |
| - gfx::Image result = favicon_driver->GetFavicon(); |
| - if (result.IsEmpty()) |
| - result = GetAppListIcon(app_window); |
| - |
| - items.push_back(new ChromeLauncherAppMenuItemV2App( |
| - app_window->GetTitle(), |
| - &result, // Will be copied |
| - app_id(), |
| - launcher_controller(), |
| - index, |
| - index == 0 /* has_leading_separator */)); |
| - ++index; |
| - } |
| return items; |
| } |
| ash::ShelfItemDelegate::PerformedAction |
| AppWindowLauncherItemController::ItemSelected(const ui::Event& event) { |
| - if (app_windows_.empty()) |
| + if (windows_.empty()) |
| return kNoAction; |
| - if (type() == TYPE_APP_PANEL) { |
| - DCHECK_EQ(app_windows_.size(), 1u); |
| - AppWindow* panel = app_windows_.front(); |
| - aura::Window* panel_window = panel->GetNativeWindow(); |
| - // If the panel is attached on another display, move it to the current |
| - // display and activate it. |
| - if (ash::wm::GetWindowState(panel_window)->panel_attached() && |
| - ash::wm::MoveWindowToEventRoot(panel_window, event)) { |
| - if (!panel->GetBaseWindow()->IsActive()) |
| - return ShowAndActivateOrMinimize(panel); |
| - } else { |
| - return ShowAndActivateOrMinimize(panel); |
| - } |
| + |
| + DCHECK(type() == TYPE_APP); |
|
xiyuan
2016/03/23 23:22:53
nit: DCHECK_EQ(TYPE_APP, type());
khmel
2016/03/24 16:30:37
Done.
|
| + ui::BaseWindow* window_to_show = |
| + last_active_window_ ? last_active_window_ : windows_.front(); |
| + // If the event was triggered by a keystroke, we try to advance to the next |
| + // item if the window we are trying to activate is already active. |
| + if (windows_.size() >= 1 && window_to_show->IsActive() && |
| + event.type() == ui::ET_KEY_RELEASED) { |
| + return ActivateOrAdvanceToNextAppWindow(window_to_show); |
| } else { |
| - AppWindow* window_to_show = last_active_app_window_ |
| - ? last_active_app_window_ |
| - : app_windows_.front(); |
| - // If the event was triggered by a keystroke, we try to advance to the next |
| - // item if the window we are trying to activate is already active. |
| - if (app_windows_.size() >= 1 && |
| - window_to_show->GetBaseWindow()->IsActive() && |
| - event.type() == ui::ET_KEY_RELEASED) { |
| - return ActivateOrAdvanceToNextAppWindow(window_to_show); |
| - } else { |
| - return ShowAndActivateOrMinimize(window_to_show); |
| - } |
| + return ShowAndActivateOrMinimize(window_to_show); |
| } |
| - return kNoAction; |
| } |
| base::string16 AppWindowLauncherItemController::GetTitle() { |
| - // For panels return the title of the contents if set. |
| - // Otherwise return the title of the app. |
| - if (type() == TYPE_APP_PANEL && !app_windows_.empty()) { |
| - AppWindow* app_window = app_windows_.front(); |
| - if (app_window->web_contents()) { |
| - base::string16 title = app_window->web_contents()->GetTitle(); |
| - if (!title.empty()) |
| - return title; |
| - } |
| - } |
| return GetAppTitle(); |
| } |
| ash::ShelfMenuModel* AppWindowLauncherItemController::CreateApplicationMenu( |
| int event_flags) { |
| - return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
| + return nullptr; |
|
xiyuan
2016/03/23 23:22:52
ArcAppWindowLauncherItemController does not overid
khmel
2016/03/24 16:30:37
For better reading it is better remove it here.
|
| } |
| bool AppWindowLauncherItemController::IsDraggable() { |
| - if (type() == TYPE_APP_PANEL) |
| - return true; |
| + DCHECK(type() == TYPE_APP); |
|
xiyuan
2016/03/23 23:22:53
nit: DCHECK_EQ(TYPE_APP, type());
khmel
2016/03/24 16:30:37
Done.
|
| return CanPin(); |
| } |
| @@ -246,8 +152,7 @@ bool AppWindowLauncherItemController::CanPin() const { |
| } |
| bool AppWindowLauncherItemController::ShouldShowTooltip() { |
| - if (type() == TYPE_APP_PANEL && IsVisible()) |
| - return false; |
| + DCHECK(type() == TYPE_APP); |
|
xiyuan
2016/03/23 23:22:53
nit: DCHECK_EQ(TYPE_APP, type());
khmel
2016/03/24 16:30:37
Done.
|
| return true; |
| } |
| @@ -270,24 +175,24 @@ void AppWindowLauncherItemController::OnWindowPropertyChanged( |
| ash::ShelfItemDelegate::PerformedAction |
| AppWindowLauncherItemController::ShowAndActivateOrMinimize( |
| - AppWindow* app_window) { |
| + ui::BaseWindow* app_window) { |
| // Either show or minimize windows when shown from the launcher. |
| return launcher_controller()->ActivateWindowOrMinimizeIfActive( |
| - app_window->GetBaseWindow(), GetApplicationList(0).size() == 2); |
| + app_window, GetApplicationList(0).size() == 2); |
| } |
| ash::ShelfItemDelegate::PerformedAction |
| AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow( |
| - AppWindow* window_to_show) { |
| - AppWindowList::iterator i( |
| - std::find(app_windows_.begin(), app_windows_.end(), window_to_show)); |
| - if (i != app_windows_.end()) { |
| - if (++i != app_windows_.end()) |
| + ui::BaseWindow* window_to_show) { |
| + WindowList::iterator i( |
| + std::find(windows_.begin(), windows_.end(), window_to_show)); |
| + if (i != windows_.end()) { |
| + if (++i != windows_.end()) |
| window_to_show = *i; |
| else |
| - window_to_show = app_windows_.front(); |
| + window_to_show = windows_.front(); |
| } |
| - if (window_to_show->GetBaseWindow()->IsActive()) { |
| + if (window_to_show->IsActive()) { |
| // Coming here, only a single window is active. For keyboard activations |
| // the window gets animated. |
| AnimateWindow(window_to_show->GetNativeWindow(), |