| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 PanelManager::~PanelManager() { | 128 PanelManager::~PanelManager() { |
| 129 display_settings_provider_->RemoveDisplayAreaObserver(this); | 129 display_settings_provider_->RemoveDisplayAreaObserver(this); |
| 130 | 130 |
| 131 // Docked strip should be disposed explicitly before DisplaySettingsProvider | 131 // Docked strip should be disposed explicitly before DisplaySettingsProvider |
| 132 // is gone since docked strip needs to remove the observer from | 132 // is gone since docked strip needs to remove the observer from |
| 133 // DisplaySettingsProvider. | 133 // DisplaySettingsProvider. |
| 134 docked_strip_.reset(); | 134 docked_strip_.reset(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 const gfx::Point& PanelManager::GetDefaultDetachedPanelOrigin() { |
| 138 return detached_strip_->GetDefaultPanelOrigin(); |
| 139 } |
| 140 |
| 137 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { | 141 void PanelManager::OnDisplayAreaChanged(const gfx::Rect& display_area) { |
| 138 if (display_area == display_area_) | 142 if (display_area == display_area_) |
| 139 return; | 143 return; |
| 140 display_area_ = display_area; | 144 display_area_ = display_area; |
| 141 | 145 |
| 142 gfx::Rect docked_strip_bounds = display_area; | 146 gfx::Rect docked_strip_bounds = display_area; |
| 143 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); | 147 docked_strip_bounds.set_x(display_area.x() + kPanelStripLeftMargin); |
| 144 docked_strip_bounds.set_width(display_area.width() - | 148 docked_strip_bounds.set_width(display_area.width() - |
| 145 kPanelStripLeftMargin - kPanelStripRightMargin); | 149 kPanelStripLeftMargin - kPanelStripRightMargin); |
| 146 docked_strip_->SetDisplayArea(docked_strip_bounds); | 150 docked_strip_->SetDisplayArea(docked_strip_bounds); |
| 147 | 151 |
| 148 detached_strip_->SetDisplayArea(display_area); | 152 detached_strip_->SetDisplayArea(display_area); |
| 149 } | 153 } |
| 150 | 154 |
| 151 void PanelManager::OnFullScreenModeChanged(bool is_full_screen) { | 155 void PanelManager::OnFullScreenModeChanged(bool is_full_screen) { |
| 152 docked_strip_->OnFullScreenModeChanged(is_full_screen); | 156 docked_strip_->OnFullScreenModeChanged(is_full_screen); |
| 153 } | 157 } |
| 154 | 158 |
| 155 int PanelManager::GetMaxPanelWidth() const { | 159 int PanelManager::GetMaxPanelWidth() const { |
| 156 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 160 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
| 157 } | 161 } |
| 158 | 162 |
| 159 int PanelManager::GetMaxPanelHeight() const { | 163 int PanelManager::GetMaxPanelHeight() const { |
| 160 return display_area_.height() * kPanelMaxHeightFactor; | 164 return display_area_.height() * kPanelMaxHeightFactor; |
| 161 } | 165 } |
| 162 | 166 |
| 163 Panel* PanelManager::CreatePanel(Browser* browser) { | 167 Panel* PanelManager::CreatePanel(Browser* browser) { |
| 164 return CreatePanel(browser, "", NULL, GURL(), | 168 return CreatePanel(browser, "", NULL, GURL(), |
| 165 browser->override_bounds().size()); | 169 browser->override_bounds(), CREATE_DOCKED); |
| 166 } | 170 } |
| 167 | 171 |
| 168 Panel* PanelManager::CreatePanel(const std::string& app_name, | 172 Panel* PanelManager::CreatePanel(const std::string& app_name, |
| 169 Profile* profile, | 173 Profile* profile, |
| 170 const GURL& url, | 174 const GURL& url, |
| 171 const gfx::Size& requested_size) { | 175 const gfx::Rect& requested_bounds, |
| 172 return CreatePanel(NULL, app_name, profile, url, requested_size); | 176 CreateMode mode) { |
| 177 return CreatePanel(NULL, app_name, profile, url, requested_bounds, mode); |
| 173 } | 178 } |
| 174 | 179 |
| 175 Panel* PanelManager::CreatePanel(Browser* browser, | 180 Panel* PanelManager::CreatePanel(Browser* browser, |
| 176 const std::string& app_name, | 181 const std::string& app_name, |
| 177 Profile* profile, | 182 Profile* profile, |
| 178 const GURL& url, | 183 const GURL& url, |
| 179 const gfx::Size& requested_size) { | 184 const gfx::Rect& requested_bounds, |
| 185 CreateMode mode) { |
| 180 // Need to sync the display area if no panel is present. This is because: | 186 // Need to sync the display area if no panel is present. This is because: |
| 181 // 1) Display area is not initialized until first panel is created. | 187 // 1) Display area is not initialized until first panel is created. |
| 182 // 2) On windows, display settings notification is tied to a window. When | 188 // 2) On windows, display settings notification is tied to a window. When |
| 183 // display settings are changed at the time that no panel exists, we do | 189 // display settings are changed at the time that no panel exists, we do |
| 184 // not receive any notification. | 190 // not receive any notification. |
| 185 if (num_panels() == 0) { | 191 if (num_panels() == 0) { |
| 186 display_settings_provider_->OnDisplaySettingsChanged(); | 192 display_settings_provider_->OnDisplaySettingsChanged(); |
| 187 display_settings_provider_->AddFullScreenObserver(this); | 193 display_settings_provider_->AddFullScreenObserver(this); |
| 188 } | 194 } |
| 189 | 195 |
| 190 // Compute initial bounds for the panel. | 196 // Compute initial bounds for the panel. |
| 191 int width = requested_size.width(); | 197 int width = requested_bounds.width(); |
| 192 int height = requested_size.height(); | 198 int height = requested_bounds.height(); |
| 193 if (width == 0) | 199 if (width == 0) |
| 194 width = height * kPanelDefaultWidthToHeightRatio; | 200 width = height * kPanelDefaultWidthToHeightRatio; |
| 195 else if (height == 0) | 201 else if (height == 0) |
| 196 height = width / kPanelDefaultWidthToHeightRatio; | 202 height = width / kPanelDefaultWidthToHeightRatio; |
| 197 | 203 |
| 198 gfx::Size min_size(panel::kPanelMinWidth, panel::kPanelMinHeight); | 204 gfx::Size min_size(panel::kPanelMinWidth, panel::kPanelMinHeight); |
| 199 gfx::Size max_size(GetMaxPanelWidth(), GetMaxPanelHeight()); | 205 gfx::Size max_size(GetMaxPanelWidth(), GetMaxPanelHeight()); |
| 200 if (width < min_size.width()) | 206 if (width < min_size.width()) |
| 201 width = min_size.width(); | 207 width = min_size.width(); |
| 202 else if (width > max_size.width()) | 208 else if (width > max_size.width()) |
| 203 width = max_size.width(); | 209 width = max_size.width(); |
| 204 | 210 |
| 205 if (height < min_size.height()) | 211 if (height < min_size.height()) |
| 206 height = min_size.height(); | 212 height = min_size.height(); |
| 207 else if (height > max_size.height()) | 213 else if (height > max_size.height()) |
| 208 height = max_size.height(); | 214 height = max_size.height(); |
| 209 | 215 |
| 210 gfx::Size panel_size(width, height); | 216 gfx::Rect bounds(width, height); |
| 211 gfx::Rect bounds(docked_strip_->GetDefaultPositionForPanel(panel_size), | 217 if (CREATE_DOCKED == mode) { |
| 212 panel_size); | 218 bounds.set_origin(docked_strip_->GetDefaultPositionForPanel(bounds.size())); |
| 219 } else { |
| 220 bounds.set_origin(requested_bounds.origin()); |
| 221 bounds = bounds.AdjustToFit(display_settings_provider_->GetDisplayArea()); |
| 222 } |
| 213 | 223 |
| 214 // Create the panel. | 224 // Create the panel. |
| 215 Panel* panel; | 225 Panel* panel; |
| 216 if (browser) { | 226 if (browser) { |
| 217 // Legacy panel. Delete after refactor. | 227 // Legacy panel. Delete after refactor. |
| 218 panel = new OldPanel(browser, min_size, max_size); | 228 panel = new OldPanel(browser, min_size, max_size); |
| 219 panel->Initialize(bounds, browser); | 229 panel->Initialize(bounds, browser); |
| 220 } else { | 230 } else { |
| 221 panel = new Panel(app_name, min_size, max_size); | 231 panel = new Panel(app_name, min_size, max_size); |
| 222 panel->Initialize(profile, url, bounds); | 232 panel->Initialize(profile, url, bounds); |
| 223 } | 233 } |
| 224 | 234 |
| 225 // Auto resizable feature is enabled only if no initial size is requested. | 235 // Auto resizable feature is enabled only if no initial size is requested. |
| 226 if (auto_sizing_enabled() && requested_size.width() == 0 && | 236 if (auto_sizing_enabled() && requested_bounds.width() == 0 && |
| 227 requested_size.height() == 0) { | 237 requested_bounds.height() == 0) { |
| 228 panel->SetAutoResizable(true); | 238 panel->SetAutoResizable(true); |
| 229 } | 239 } |
| 230 | 240 |
| 231 // Add the panel to the docked strip. | 241 // Add the panel to the appropriate panel strip. |
| 232 // Delay layout refreshes in case multiple panels are created within | 242 // Delay layout refreshes in case multiple panels are created within |
| 233 // a short time of one another or the focus changes shortly after panel | 243 // a short time of one another or the focus changes shortly after panel |
| 234 // is created to avoid excessive screen redraws. | 244 // is created to avoid excessive screen redraws. |
| 235 docked_strip_->AddPanel(panel, PanelStrip::DELAY_LAYOUT_REFRESH); | 245 if (CREATE_DOCKED == mode) |
| 236 docked_strip_->UpdatePanelOnStripChange(panel); | 246 docked_strip_->AddPanel(panel, PanelStrip::DELAY_LAYOUT_REFRESH); |
| 247 else |
| 248 detached_strip_->AddPanel(panel, PanelStrip::KNOWN_POSITION); |
| 249 |
| 250 panel->panel_strip()->UpdatePanelOnStripChange(panel); |
| 237 | 251 |
| 238 return panel; | 252 return panel; |
| 239 } | 253 } |
| 240 | 254 |
| 241 void PanelManager::OnPanelClosed(Panel* panel) { | 255 void PanelManager::OnPanelClosed(Panel* panel) { |
| 242 if (num_panels() == 1) { | 256 if (num_panels() == 1) { |
| 243 display_settings_provider_->RemoveFullScreenObserver(this); | 257 display_settings_provider_->RemoveFullScreenObserver(this); |
| 244 } | 258 } |
| 245 | 259 |
| 246 drag_controller_->OnPanelClosed(panel); | 260 drag_controller_->OnPanelClosed(panel); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 385 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
| 372 panel_mouse_watcher_.reset(watcher); | 386 panel_mouse_watcher_.reset(watcher); |
| 373 } | 387 } |
| 374 | 388 |
| 375 void PanelManager::OnPanelAnimationEnded(Panel* panel) { | 389 void PanelManager::OnPanelAnimationEnded(Panel* panel) { |
| 376 content::NotificationService::current()->Notify( | 390 content::NotificationService::current()->Notify( |
| 377 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | 391 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 378 content::Source<Panel>(panel), | 392 content::Source<Panel>(panel), |
| 379 content::NotificationService::NoDetails()); | 393 content::NotificationService::NoDetails()); |
| 380 } | 394 } |
| OLD | NEW |