| 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/panels/panel_manager.h" | 5 #include "chrome/browser/ui/panels/panel_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_list.h" | |
| 14 #include "chrome/browser/ui/browser_window.h" | |
| 15 #include "chrome/browser/ui/panels/detached_panel_strip.h" | 12 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 16 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 13 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 17 #include "chrome/browser/ui/panels/old_panel.h" | |
| 18 #include "chrome/browser/ui/panels/panel_drag_controller.h" | 14 #include "chrome/browser/ui/panels/panel_drag_controller.h" |
| 19 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 15 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 20 #include "chrome/browser/ui/panels/panel_resize_controller.h" | 16 #include "chrome/browser/ui/panels/panel_resize_controller.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 24 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 26 | 22 |
| 27 #if defined(TOOLKIT_GTK) | 23 #if defined(TOOLKIT_GTK) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 switches::kEnablePanels) || | 87 switches::kEnablePanels) || |
| 92 extension_id == std::string("nckgahadagoaajjgafhacjanaoiihapd") || | 88 extension_id == std::string("nckgahadagoaajjgafhacjanaoiihapd") || |
| 93 extension_id == std::string("ljclpkphhpbpinifbeabbhlfddcpfdde") || | 89 extension_id == std::string("ljclpkphhpbpinifbeabbhlfddcpfdde") || |
| 94 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || | 90 extension_id == std::string("ppleadejekpmccmnpjdimmlfljlkdfej") || |
| 95 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); | 91 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); |
| 96 } | 92 } |
| 97 | 93 |
| 98 return true; | 94 return true; |
| 99 } | 95 } |
| 100 | 96 |
| 101 // static | |
| 102 bool PanelManager::UseBrowserlessPanels() { | |
| 103 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kOldPanels)) | |
| 104 return false; | |
| 105 | |
| 106 return chrome::VersionInfo::GetChannel() <= chrome::VersionInfo::CHANNEL_DEV; | |
| 107 } | |
| 108 | |
| 109 PanelManager::PanelManager() | 97 PanelManager::PanelManager() |
| 110 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 98 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
| 111 auto_sizing_enabled_(true) { | 99 auto_sizing_enabled_(true) { |
| 112 // DisplaySettingsProvider should be created before the creation of strips | 100 // DisplaySettingsProvider should be created before the creation of strips |
| 113 // since some strip might depend on it. | 101 // since some strip might depend on it. |
| 114 display_settings_provider_.reset(DisplaySettingsProvider::Create()); | 102 display_settings_provider_.reset(DisplaySettingsProvider::Create()); |
| 115 display_settings_provider_->AddDisplayAreaObserver(this); | 103 display_settings_provider_->AddDisplayAreaObserver(this); |
| 116 | 104 |
| 117 detached_strip_.reset(new DetachedPanelStrip(this)); | 105 detached_strip_.reset(new DetachedPanelStrip(this)); |
| 118 docked_strip_.reset(new DockedPanelStrip(this)); | 106 docked_strip_.reset(new DockedPanelStrip(this)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 140 } |
| 153 | 141 |
| 154 int PanelManager::GetMaxPanelWidth() const { | 142 int PanelManager::GetMaxPanelWidth() const { |
| 155 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 143 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
| 156 } | 144 } |
| 157 | 145 |
| 158 int PanelManager::GetMaxPanelHeight() const { | 146 int PanelManager::GetMaxPanelHeight() const { |
| 159 return display_area_.height() * kPanelMaxHeightFactor; | 147 return display_area_.height() * kPanelMaxHeightFactor; |
| 160 } | 148 } |
| 161 | 149 |
| 162 Panel* PanelManager::CreatePanel(Browser* browser) { | |
| 163 return CreatePanel(browser, "", NULL, GURL(), | |
| 164 browser->override_bounds(), CREATE_AS_DOCKED); | |
| 165 } | |
| 166 | |
| 167 Panel* PanelManager::CreatePanel(const std::string& app_name, | 150 Panel* PanelManager::CreatePanel(const std::string& app_name, |
| 168 Profile* profile, | 151 Profile* profile, |
| 169 const GURL& url, | 152 const GURL& url, |
| 170 const gfx::Rect& requested_bounds, | 153 const gfx::Rect& requested_bounds, |
| 171 CreateMode mode) { | 154 CreateMode mode) { |
| 172 return CreatePanel(NULL, app_name, profile, url, requested_bounds, mode); | |
| 173 } | |
| 174 | |
| 175 Panel* PanelManager::CreatePanel(Browser* browser, | |
| 176 const std::string& app_name, | |
| 177 Profile* profile, | |
| 178 const GURL& url, | |
| 179 const gfx::Rect& requested_bounds, | |
| 180 CreateMode mode) { | |
| 181 // Need to sync the display area if no panel is present. This is because: | 155 // Need to sync the display area if no panel is present. This is because: |
| 182 // 1) Display area is not initialized until first panel is created. | 156 // 1) Display area is not initialized until first panel is created. |
| 183 // 2) On windows, display settings notification is tied to a window. When | 157 // 2) On windows, display settings notification is tied to a window. When |
| 184 // display settings are changed at the time that no panel exists, we do | 158 // display settings are changed at the time that no panel exists, we do |
| 185 // not receive any notification. | 159 // not receive any notification. |
| 186 if (num_panels() == 0) { | 160 if (num_panels() == 0) { |
| 187 display_settings_provider_->OnDisplaySettingsChanged(); | 161 display_settings_provider_->OnDisplaySettingsChanged(); |
| 188 display_settings_provider_->AddFullScreenObserver(this); | 162 display_settings_provider_->AddFullScreenObserver(this); |
| 189 } | 163 } |
| 190 | 164 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 210 | 184 |
| 211 gfx::Rect bounds(width, height); | 185 gfx::Rect bounds(width, height); |
| 212 if (CREATE_AS_DOCKED == mode) { | 186 if (CREATE_AS_DOCKED == mode) { |
| 213 bounds.set_origin(docked_strip_->GetDefaultPositionForPanel(bounds.size())); | 187 bounds.set_origin(docked_strip_->GetDefaultPositionForPanel(bounds.size())); |
| 214 } else { | 188 } else { |
| 215 bounds.set_origin(requested_bounds.origin()); | 189 bounds.set_origin(requested_bounds.origin()); |
| 216 bounds = bounds.AdjustToFit(display_settings_provider_->GetDisplayArea()); | 190 bounds = bounds.AdjustToFit(display_settings_provider_->GetDisplayArea()); |
| 217 } | 191 } |
| 218 | 192 |
| 219 // Create the panel. | 193 // Create the panel. |
| 220 Panel* panel; | 194 Panel* panel = new Panel(app_name, min_size, max_size); |
| 221 if (browser) { | 195 panel->Initialize(profile, url, bounds); |
| 222 // Legacy panel. Delete after refactor. | |
| 223 panel = new OldPanel(browser, min_size, max_size); | |
| 224 panel->Initialize(bounds, browser); | |
| 225 } else { | |
| 226 panel = new Panel(app_name, min_size, max_size); | |
| 227 panel->Initialize(profile, url, bounds); | |
| 228 } | |
| 229 | 196 |
| 230 // Auto resizable feature is enabled only if no initial size is requested. | 197 // Auto resizable feature is enabled only if no initial size is requested. |
| 231 if (auto_sizing_enabled() && requested_bounds.width() == 0 && | 198 if (auto_sizing_enabled() && requested_bounds.width() == 0 && |
| 232 requested_bounds.height() == 0) { | 199 requested_bounds.height() == 0) { |
| 233 panel->SetAutoResizable(true); | 200 panel->SetAutoResizable(true); |
| 234 } | 201 } |
| 235 | 202 |
| 236 // Add the panel to the appropriate panel strip. | 203 // Add the panel to the appropriate panel strip. |
| 237 // Delay layout refreshes in case multiple panels are created within | 204 // Delay layout refreshes in case multiple panels are created within |
| 238 // a short time of one another or the focus changes shortly after panel | 205 // a short time of one another or the focus changes shortly after panel |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 305 } |
| 339 | 306 |
| 340 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 307 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
| 341 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); | 308 return docked_strip_->ShouldBringUpTitlebars(mouse_x, mouse_y); |
| 342 } | 309 } |
| 343 | 310 |
| 344 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { | 311 void PanelManager::BringUpOrDownTitlebars(bool bring_up) { |
| 345 docked_strip_->BringUpOrDownTitlebars(bring_up); | 312 docked_strip_->BringUpOrDownTitlebars(bring_up); |
| 346 } | 313 } |
| 347 | 314 |
| 348 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( | |
| 349 Browser* current_browser) const { | |
| 350 // Find the last active browser window that is not minimized. | |
| 351 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); | |
| 352 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); | |
| 353 for (; (iter != end); ++iter) { | |
| 354 Browser* browser = *iter; | |
| 355 if (current_browser != browser && !browser->window()->IsMinimized()) | |
| 356 return browser->window(); | |
| 357 } | |
| 358 | |
| 359 return NULL; | |
| 360 } | |
| 361 | |
| 362 void PanelManager::CloseAll() { | 315 void PanelManager::CloseAll() { |
| 363 DCHECK(!drag_controller_->IsDragging()); | 316 DCHECK(!drag_controller_->IsDragging()); |
| 364 | 317 |
| 365 detached_strip_->CloseAll(); | 318 detached_strip_->CloseAll(); |
| 366 docked_strip_->CloseAll(); | 319 docked_strip_->CloseAll(); |
| 367 } | 320 } |
| 368 | 321 |
| 369 int PanelManager::num_panels() const { | 322 int PanelManager::num_panels() const { |
| 370 return detached_strip_->num_panels() + docked_strip_->num_panels(); | 323 return detached_strip_->num_panels() + docked_strip_->num_panels(); |
| 371 } | 324 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 386 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 339 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
| 387 panel_mouse_watcher_.reset(watcher); | 340 panel_mouse_watcher_.reset(watcher); |
| 388 } | 341 } |
| 389 | 342 |
| 390 void PanelManager::OnPanelAnimationEnded(Panel* panel) { | 343 void PanelManager::OnPanelAnimationEnded(Panel* panel) { |
| 391 content::NotificationService::current()->Notify( | 344 content::NotificationService::current()->Notify( |
| 392 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | 345 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 393 content::Source<Panel>(panel), | 346 content::Source<Panel>(panel), |
| 394 content::NotificationService::NoDetails()); | 347 content::NotificationService::NoDetails()); |
| 395 } | 348 } |
| OLD | NEW |