OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/extension_app_window_launcher_item_cont
roller.h" | 5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" |
6 | 6 |
7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
8 #include "ash/wm/window_state_aura.h" | 8 #include "ash/wm/window_state_aura.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 ExtensionAppWindowLauncherItemController:: | 51 ExtensionAppWindowLauncherItemController:: |
52 ExtensionAppWindowLauncherItemController( | 52 ExtensionAppWindowLauncherItemController( |
53 Type type, | 53 Type type, |
54 const std::string& app_id, | 54 const std::string& app_id, |
55 const std::string& launch_id, | 55 const std::string& launch_id, |
56 ChromeLauncherController* controller) | 56 ChromeLauncherController* controller) |
57 : AppWindowLauncherItemController(type, app_id, launch_id, controller) {} | 57 : AppWindowLauncherItemController(type, app_id, launch_id, controller) { |
| 58 DCHECK_NE(TYPE_APP_PANEL, type); |
| 59 } |
58 | 60 |
59 ExtensionAppWindowLauncherItemController:: | 61 ExtensionAppWindowLauncherItemController:: |
60 ~ExtensionAppWindowLauncherItemController() {} | 62 ~ExtensionAppWindowLauncherItemController() {} |
61 | 63 |
62 void ExtensionAppWindowLauncherItemController::AddAppWindow( | 64 void ExtensionAppWindowLauncherItemController::AddAppWindow( |
63 extensions::AppWindow* app_window) { | 65 extensions::AppWindow* app_window) { |
64 if (app_window->window_type_is_panel() && type() != TYPE_APP_PANEL) | 66 DCHECK(!app_window->window_type_is_panel()); |
65 LOG(ERROR) << "AppWindow of type Panel added to non-panel launcher item"; | |
66 DCHECK(window_to_app_window_.find(app_window->GetBaseWindow()) == | 67 DCHECK(window_to_app_window_.find(app_window->GetBaseWindow()) == |
67 window_to_app_window_.end()); | 68 window_to_app_window_.end()); |
68 AddWindow(app_window->GetBaseWindow()); | 69 AddWindow(app_window->GetBaseWindow()); |
69 window_to_app_window_[app_window->GetBaseWindow()] = app_window; | 70 window_to_app_window_[app_window->GetBaseWindow()] = app_window; |
70 } | 71 } |
71 | 72 |
72 void ExtensionAppWindowLauncherItemController::OnWindowRemoved( | 73 void ExtensionAppWindowLauncherItemController::OnWindowRemoved( |
73 ui::BaseWindow* window) { | 74 ui::BaseWindow* window) { |
74 WindowToAppWindow::iterator it = window_to_app_window_.find(window); | 75 WindowToAppWindow::iterator it = window_to_app_window_.find(window); |
75 if (it == window_to_app_window_.end()) { | 76 if (it == window_to_app_window_.end()) { |
(...skipping 29 matching lines...) Expand all Loading... |
105 index == 0 /* has_leading_separator */)); | 106 index == 0 /* has_leading_separator */)); |
106 ++index; | 107 ++index; |
107 } | 108 } |
108 return items; | 109 return items; |
109 } | 110 } |
110 | 111 |
111 ash::ShelfItemDelegate::PerformedAction | 112 ash::ShelfItemDelegate::PerformedAction |
112 ExtensionAppWindowLauncherItemController::ItemSelected(const ui::Event& event) { | 113 ExtensionAppWindowLauncherItemController::ItemSelected(const ui::Event& event) { |
113 if (windows().empty()) | 114 if (windows().empty()) |
114 return kNoAction; | 115 return kNoAction; |
115 | 116 return AppWindowLauncherItemController::ItemSelected(event); |
116 if (type() == TYPE_APP_PANEL) { | |
117 DCHECK_EQ(windows().size(), 1u); | |
118 ui::BaseWindow* panel = windows().front(); | |
119 aura::Window* panel_window = panel->GetNativeWindow(); | |
120 // If the panel is attached on another display, move it to the current | |
121 // display and activate it. | |
122 if (ash::wm::GetWindowState(panel_window)->panel_attached() && | |
123 ash::wm::MoveWindowToEventRoot(panel_window, event)) { | |
124 if (!panel->IsActive()) | |
125 return ShowAndActivateOrMinimize(panel); | |
126 } else { | |
127 return ShowAndActivateOrMinimize(panel); | |
128 } | |
129 } else { | |
130 return AppWindowLauncherItemController::ItemSelected(event); | |
131 } | |
132 return kNoAction; | |
133 } | |
134 | |
135 base::string16 ExtensionAppWindowLauncherItemController::GetTitle() { | |
136 // For panels return the title of the contents if set. | |
137 // Otherwise return the title of the app. | |
138 if (type() == TYPE_APP_PANEL && !windows().empty()) { | |
139 extensions::AppWindow* app_window = | |
140 window_to_app_window_[windows().front()]; | |
141 DCHECK(app_window); | |
142 if (app_window->web_contents()) { | |
143 base::string16 title = app_window->web_contents()->GetTitle(); | |
144 if (!title.empty()) | |
145 return title; | |
146 } | |
147 } | |
148 return AppWindowLauncherItemController::GetTitle(); | |
149 } | 117 } |
150 | 118 |
151 ash::ShelfMenuModel* | 119 ash::ShelfMenuModel* |
152 ExtensionAppWindowLauncherItemController::CreateApplicationMenu( | 120 ExtensionAppWindowLauncherItemController::CreateApplicationMenu( |
153 int event_flags) { | 121 int event_flags) { |
154 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); | 122 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
155 } | 123 } |
156 | |
157 bool ExtensionAppWindowLauncherItemController::IsDraggable() { | |
158 if (type() == TYPE_APP_PANEL) | |
159 return true; | |
160 return AppWindowLauncherItemController::IsDraggable(); | |
161 } | |
162 | |
163 bool ExtensionAppWindowLauncherItemController::ShouldShowTooltip() { | |
164 if (type() == TYPE_APP_PANEL && IsVisible()) | |
165 return false; | |
166 return AppWindowLauncherItemController::ShouldShowTooltip(); | |
167 } | |
OLD | NEW |