| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/fullscreen.h" | 9 #include "chrome/browser/fullscreen.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 12 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
| 13 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
| 13 #include "chrome/browser/ui/panels/panel_strip.h" | 14 #include "chrome/browser/ui/panels/panel_strip.h" |
| 14 #include "chrome/browser/ui/window_sizer.h" | 15 #include "chrome/browser/ui/window_sizer.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const int kOverflowStripThickness = 24; | 21 const int kOverflowStripThickness = 24; |
| 21 | 22 |
| 22 // Width of spacing around panel strip and the left/right edges of the screen. | 23 // Width of spacing around panel strip and the left/right edges of the screen. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 PanelManager* PanelManager::GetInstance() { | 35 PanelManager* PanelManager::GetInstance() { |
| 35 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; | 36 static base::LazyInstance<PanelManager> instance = LAZY_INSTANCE_INITIALIZER; |
| 36 return instance.Pointer(); | 37 return instance.Pointer(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 PanelManager::PanelManager() | 40 PanelManager::PanelManager() |
| 40 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 41 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
| 41 auto_sizing_enabled_(true), | 42 auto_sizing_enabled_(true), |
| 42 is_full_screen_(false) { | 43 is_full_screen_(false) { |
| 43 panel_strip_.reset(new PanelStrip(this)); | 44 panel_strip_.reset(new PanelStrip(this)); |
| 45 panel_overflow_strip_.reset(new PanelOverflowStrip(this)); |
| 44 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | 46 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
| 45 OnDisplayChanged(); | 47 OnDisplayChanged(); |
| 46 } | 48 } |
| 47 | 49 |
| 48 PanelManager::~PanelManager() { | 50 PanelManager::~PanelManager() { |
| 49 } | 51 } |
| 50 | 52 |
| 51 void PanelManager::OnDisplayChanged() { | 53 void PanelManager::OnDisplayChanged() { |
| 52 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( | 54 scoped_ptr<WindowSizer::MonitorInfoProvider> info_provider( |
| 53 WindowSizer::CreateDefaultMonitorInfoProvider()); | 55 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 void PanelManager::Layout() { | 76 void PanelManager::Layout() { |
| 75 int height = | 77 int height = |
| 76 static_cast<int>(adjusted_work_area_.height() * kPanelStripHeightFactor); | 78 static_cast<int>(adjusted_work_area_.height() * kPanelStripHeightFactor); |
| 77 gfx::Rect panel_strip_bounds; | 79 gfx::Rect panel_strip_bounds; |
| 78 panel_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); | 80 panel_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); |
| 79 panel_strip_bounds.set_y(adjusted_work_area_.bottom() - height); | 81 panel_strip_bounds.set_y(adjusted_work_area_.bottom() - height); |
| 80 panel_strip_bounds.set_width(adjusted_work_area_.width() - | 82 panel_strip_bounds.set_width(adjusted_work_area_.width() - |
| 81 kPanelStripLeftMargin - kPanelStripRightMargin); | 83 kPanelStripLeftMargin - kPanelStripRightMargin); |
| 82 panel_strip_bounds.set_height(height); | 84 panel_strip_bounds.set_height(height); |
| 83 panel_strip_->SetDisplayArea(panel_strip_bounds); | 85 panel_strip_->SetDisplayArea(panel_strip_bounds); |
| 86 |
| 87 gfx::Rect overflow_area(adjusted_work_area_); |
| 88 overflow_area.set_width(kOverflowStripThickness); |
| 89 panel_overflow_strip_->SetDisplayArea(overflow_area); |
| 84 } | 90 } |
| 85 | 91 |
| 86 Panel* PanelManager::CreatePanel(Browser* browser) { | 92 Panel* PanelManager::CreatePanel(Browser* browser) { |
| 87 int width = browser->override_bounds().width(); | 93 int width = browser->override_bounds().width(); |
| 88 int height = browser->override_bounds().height(); | 94 int height = browser->override_bounds().height(); |
| 89 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 95 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
| 90 panel_strip_->AddPanel(panel); | 96 panel_strip_->AddPanel(panel); |
| 91 | 97 |
| 92 content::NotificationService::current()->Notify( | 98 content::NotificationService::current()->Notify( |
| 93 chrome::NOTIFICATION_PANEL_ADDED, | 99 chrome::NOTIFICATION_PANEL_ADDED, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 int PanelManager::StartingRightPosition() const { | 112 int PanelManager::StartingRightPosition() const { |
| 107 return panel_strip_->StartingRightPosition(); | 113 return panel_strip_->StartingRightPosition(); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void PanelManager::CheckFullScreenMode() { | 116 void PanelManager::CheckFullScreenMode() { |
| 111 bool is_full_screen_new = IsFullScreenMode(); | 117 bool is_full_screen_new = IsFullScreenMode(); |
| 112 if (is_full_screen_ == is_full_screen_new) | 118 if (is_full_screen_ == is_full_screen_new) |
| 113 return; | 119 return; |
| 114 is_full_screen_ = is_full_screen_new; | 120 is_full_screen_ = is_full_screen_new; |
| 115 panel_strip_->OnFullScreenModeChanged(is_full_screen_); | 121 panel_strip_->OnFullScreenModeChanged(is_full_screen_); |
| 122 panel_overflow_strip_->OnFullScreenModeChanged(is_full_screen_); |
| 116 } | 123 } |
| 117 | 124 |
| 118 void PanelManager::Remove(Panel* panel) { | 125 void PanelManager::Remove(Panel* panel) { |
| 119 if (num_panels() == 1) | 126 if (num_panels() == 1) |
| 120 full_screen_mode_timer_.Stop(); | 127 full_screen_mode_timer_.Stop(); |
| 121 | 128 |
| 122 if (panel_strip_->Remove(panel)) | 129 if (panel_strip_->Remove(panel)) |
| 123 return; | 130 return; |
| 124 // TODO(jianli): else try removing from overflow strip | 131 bool removed = panel_overflow_strip_->Remove(panel); |
| 132 DCHECK(removed); |
| 125 } | 133 } |
| 126 | 134 |
| 127 void PanelManager::OnPanelRemoved(Panel* panel) { | 135 void PanelManager::OnPanelRemoved(Panel* panel) { |
| 128 content::NotificationService::current()->Notify( | 136 content::NotificationService::current()->Notify( |
| 129 chrome::NOTIFICATION_PANEL_REMOVED, | 137 chrome::NOTIFICATION_PANEL_REMOVED, |
| 130 content::Source<Panel>(panel), | 138 content::Source<Panel>(panel), |
| 131 content::NotificationService::NoDetails()); | 139 content::NotificationService::NoDetails()); |
| 132 } | 140 } |
| 133 | 141 |
| 134 void PanelManager::StartDragging(Panel* panel) { | 142 void PanelManager::StartDragging(Panel* panel) { |
| 135 panel_strip_->StartDragging(panel); | 143 panel_strip_->StartDragging(panel); |
| 136 } | 144 } |
| 137 | 145 |
| 138 void PanelManager::Drag(int delta_x) { | 146 void PanelManager::Drag(int delta_x) { |
| 139 panel_strip_->Drag(delta_x); | 147 panel_strip_->Drag(delta_x); |
| 140 } | 148 } |
| 141 | 149 |
| 142 void PanelManager::EndDragging(bool cancelled) { | 150 void PanelManager::EndDragging(bool cancelled) { |
| 143 panel_strip_->EndDragging(cancelled); | 151 panel_strip_->EndDragging(cancelled); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void PanelManager::OnPanelExpansionStateChanged( | 154 void PanelManager::OnPanelExpansionStateChanged( |
| 147 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | 155 Panel* panel, Panel::ExpansionState old_state) { |
| 148 panel_strip_->OnPanelExpansionStateChanged(old_state, new_state); | 156 if (panel->expansion_state() == Panel::IN_OVERFLOW) |
| 157 panel_overflow_strip_->OnPanelExpansionStateChanged(panel, old_state); |
| 158 else |
| 159 panel_strip_->OnPanelExpansionStateChanged(panel, old_state); |
| 149 } | 160 } |
| 150 | 161 |
| 151 void PanelManager::OnPreferredWindowSizeChanged( | 162 void PanelManager::OnPreferredWindowSizeChanged( |
| 152 Panel* panel, const gfx::Size& preferred_window_size) { | 163 Panel* panel, const gfx::Size& preferred_window_size) { |
| 153 if (!auto_sizing_enabled_) | 164 if (!auto_sizing_enabled_) |
| 154 return; | 165 return; |
| 155 panel_strip_->OnPreferredWindowSizeChanged(panel, preferred_window_size); | 166 panel_strip_->OnPreferredWindowSizeChanged(panel, preferred_window_size); |
| 156 } | 167 } |
| 157 | 168 |
| 158 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { | 169 bool PanelManager::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 173 adjusted_work_area_.set_x(adjusted_work_area_.x() + space); | 184 adjusted_work_area_.set_x(adjusted_work_area_.x() + space); |
| 174 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | 185 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
| 175 } | 186 } |
| 176 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { | 187 if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { |
| 177 int space = auto_hiding_desktop_bar_->GetThickness( | 188 int space = auto_hiding_desktop_bar_->GetThickness( |
| 178 AutoHidingDesktopBar::ALIGN_RIGHT); | 189 AutoHidingDesktopBar::ALIGN_RIGHT); |
| 179 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); | 190 adjusted_work_area_.set_width(adjusted_work_area_.width() - space); |
| 180 } | 191 } |
| 181 } | 192 } |
| 182 | 193 |
| 183 int PanelManager::GetBottomPositionForExpansionState( | |
| 184 Panel::ExpansionState expansion_state) const { | |
| 185 return panel_strip_->GetBottomPositionForExpansionState(expansion_state); | |
| 186 } | |
| 187 | |
| 188 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( | 194 BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( |
| 189 Panel* panel) const { | 195 Panel* panel) const { |
| 190 // Find the last active browser window that is not minimized. | 196 // Find the last active browser window that is not minimized. |
| 191 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); | 197 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); |
| 192 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); | 198 BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); |
| 193 for (; (iter != end); ++iter) { | 199 for (; (iter != end); ++iter) { |
| 194 Browser* browser = *iter; | 200 Browser* browser = *iter; |
| 195 if (panel->browser() != browser && !browser->window()->IsMinimized()) | 201 if (panel->browser() != browser && !browser->window()->IsMinimized()) |
| 196 return browser->window(); | 202 return browser->window(); |
| 197 } | 203 } |
| 198 | 204 |
| 199 return NULL; | 205 return NULL; |
| 200 } | 206 } |
| 201 | 207 |
| 202 void PanelManager::MoveToOverflowStrip(Panel* panel, bool is_new) { | |
| 203 // TODO(jianli) - implement. | |
| 204 } | |
| 205 | |
| 206 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { | 208 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { |
| 207 AdjustWorkAreaForAutoHidingDesktopBars(); | 209 AdjustWorkAreaForAutoHidingDesktopBars(); |
| 208 Layout(); | 210 Layout(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( | 213 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( |
| 212 AutoHidingDesktopBar::Alignment alignment, | 214 AutoHidingDesktopBar::Alignment alignment, |
| 213 AutoHidingDesktopBar::Visibility visibility) { | 215 AutoHidingDesktopBar::Visibility visibility) { |
| 214 panel_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); | 216 panel_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void PanelManager::RemoveAll() { | 219 void PanelManager::RemoveAll() { |
| 218 panel_strip_->RemoveAll(); | 220 panel_strip_->RemoveAll(); |
| 219 // TODO(jianli): overflow_strip_->RemoveAll(); | 221 panel_overflow_strip_->RemoveAll(); |
| 220 } | 222 } |
| 221 | 223 |
| 222 int PanelManager::num_panels() const { | 224 int PanelManager::num_panels() const { |
| 223 return panel_strip_->num_panels(); | 225 return panel_strip_->num_panels() + panel_overflow_strip_->num_panels(); |
| 224 // TODO(jianli): + overflow_strip_->num_panels(); | |
| 225 } | 226 } |
| 226 | 227 |
| 227 bool PanelManager::is_dragging_panel() const { | 228 bool PanelManager::is_dragging_panel() const { |
| 228 return panel_strip_->is_dragging_panel(); | 229 return panel_strip_->is_dragging_panel(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 const PanelManager::Panels& PanelManager::panels() const { | 232 const PanelManager::Panels& PanelManager::panels() const { |
| 232 return panel_strip_->panels(); | 233 return panel_strip_->panels(); |
| 233 } | 234 } |
| OLD | NEW |