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