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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/browser/fullscreen.h" | 10 #include "chrome/browser/fullscreen.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/panels/detached_panel_strip.h" | |
13 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 14 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
14 #include "chrome/browser/ui/panels/overflow_panel_strip.h" | 15 #include "chrome/browser/ui/panels/overflow_panel_strip.h" |
16 #include "chrome/browser/ui/panels/panel_drag_controller.h" | |
15 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 17 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
16 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
21 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 const int kOverflowStripThickness = 26; | 26 const int kOverflowStripThickness = 26; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); | 58 extension_id == std::string("eggnbpckecmjlblplehfpjjdhhidfdoj"); |
57 } | 59 } |
58 | 60 |
59 return true; | 61 return true; |
60 } | 62 } |
61 | 63 |
62 PanelManager::PanelManager() | 64 PanelManager::PanelManager() |
63 : panel_mouse_watcher_(PanelMouseWatcher::Create()), | 65 : panel_mouse_watcher_(PanelMouseWatcher::Create()), |
64 auto_sizing_enabled_(true), | 66 auto_sizing_enabled_(true), |
65 is_full_screen_(false) { | 67 is_full_screen_(false) { |
68 detached_strip_.reset(new DetachedPanelStrip(this)); | |
66 docked_strip_.reset(new DockedPanelStrip(this)); | 69 docked_strip_.reset(new DockedPanelStrip(this)); |
67 overflow_strip_.reset(new OverflowPanelStrip(this)); | 70 overflow_strip_.reset(new OverflowPanelStrip(this)); |
71 drag_controller_.reset(new PanelDragController()); | |
68 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); | 72 auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); |
69 OnDisplayChanged(); | 73 OnDisplayChanged(); |
70 } | 74 } |
71 | 75 |
72 PanelManager::~PanelManager() { | 76 PanelManager::~PanelManager() { |
73 } | 77 } |
74 | 78 |
75 void PanelManager::OnDisplayChanged() { | 79 void PanelManager::OnDisplayChanged() { |
76 #if defined(OS_MACOSX) | 80 #if defined(OS_MACOSX) |
77 // On OSX, panels should be dropped all the way to the bottom edge of the | 81 // On OSX, panels should be dropped all the way to the bottom edge of the |
(...skipping 21 matching lines...) Expand all Loading... | |
99 gfx::Rect docked_strip_bounds; | 103 gfx::Rect docked_strip_bounds; |
100 docked_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); | 104 docked_strip_bounds.set_x(adjusted_work_area_.x() + kPanelStripLeftMargin); |
101 docked_strip_bounds.set_y(adjusted_work_area_.bottom() - height); | 105 docked_strip_bounds.set_y(adjusted_work_area_.bottom() - height); |
102 docked_strip_bounds.set_width(adjusted_work_area_.width() - | 106 docked_strip_bounds.set_width(adjusted_work_area_.width() - |
103 kPanelStripLeftMargin - kPanelStripRightMargin); | 107 kPanelStripLeftMargin - kPanelStripRightMargin); |
104 docked_strip_bounds.set_height(height); | 108 docked_strip_bounds.set_height(height); |
105 docked_strip_->SetDisplayArea(docked_strip_bounds); | 109 docked_strip_->SetDisplayArea(docked_strip_bounds); |
106 | 110 |
107 gfx::Rect overflow_area(adjusted_work_area_); | 111 gfx::Rect overflow_area(adjusted_work_area_); |
108 overflow_area.set_width(kOverflowStripThickness); | 112 overflow_area.set_width(kOverflowStripThickness); |
109 overflow_strip_->SetDisplayArea(overflow_area); | 113 overflow_strip_->SetDisplayArea(overflow_area); |
Andrei
2012/02/18 19:41:31
Should not we take care of the detached strip here
| |
110 } | 114 } |
111 | 115 |
112 Panel* PanelManager::CreatePanel(Browser* browser) { | 116 Panel* PanelManager::CreatePanel(Browser* browser) { |
113 int width = browser->override_bounds().width(); | 117 int width = browser->override_bounds().width(); |
114 int height = browser->override_bounds().height(); | 118 int height = browser->override_bounds().height(); |
115 Panel* panel = new Panel(browser, gfx::Size(width, height)); | 119 Panel* panel = new Panel(browser, gfx::Size(width, height)); |
116 panel->MoveToStrip(docked_strip_.get()); | 120 panel->MoveToStrip(docked_strip_.get()); |
117 | 121 |
118 content::NotificationService::current()->Notify( | 122 content::NotificationService::current()->Notify( |
119 chrome::NOTIFICATION_PANEL_ADDED, | 123 chrome::NOTIFICATION_PANEL_ADDED, |
(...skipping 17 matching lines...) Expand all Loading... | |
137 int PanelManager::StartingRightPosition() const { | 141 int PanelManager::StartingRightPosition() const { |
138 return docked_strip_->StartingRightPosition(); | 142 return docked_strip_->StartingRightPosition(); |
139 } | 143 } |
140 | 144 |
141 void PanelManager::CheckFullScreenMode() { | 145 void PanelManager::CheckFullScreenMode() { |
142 bool is_full_screen_new = IsFullScreenMode(); | 146 bool is_full_screen_new = IsFullScreenMode(); |
143 if (is_full_screen_ == is_full_screen_new) | 147 if (is_full_screen_ == is_full_screen_new) |
144 return; | 148 return; |
145 is_full_screen_ = is_full_screen_new; | 149 is_full_screen_ = is_full_screen_new; |
146 docked_strip_->OnFullScreenModeChanged(is_full_screen_); | 150 docked_strip_->OnFullScreenModeChanged(is_full_screen_); |
147 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); | 151 overflow_strip_->OnFullScreenModeChanged(is_full_screen_); |
Andrei
2012/02/18 21:31:12
Notify the detached strip here as well
| |
148 } | 152 } |
149 | 153 |
150 void PanelManager::OnPanelRemoved(Panel* panel) { | 154 void PanelManager::OnPanelRemoved(Panel* panel) { |
151 #if defined(OS_WIN) || defined(OS_MACOSX) | 155 #if defined(OS_WIN) || defined(OS_MACOSX) |
152 if (num_panels() == 0) | 156 if (num_panels() == 0) |
153 full_screen_mode_timer_.Stop(); | 157 full_screen_mode_timer_.Stop(); |
154 #endif | 158 #endif |
155 | 159 |
156 content::NotificationService::current()->Notify( | 160 content::NotificationService::current()->Notify( |
157 chrome::NOTIFICATION_PANEL_REMOVED, | 161 chrome::NOTIFICATION_PANEL_REMOVED, |
158 content::Source<Panel>(panel), | 162 content::Source<Panel>(panel), |
159 content::NotificationService::NoDetails()); | 163 content::NotificationService::NoDetails()); |
160 } | 164 } |
161 | 165 |
162 void PanelManager::StartDragging(Panel* panel) { | 166 void PanelManager::StartDragging(Panel* panel) { |
163 docked_strip_->StartDragging(panel); | 167 drag_controller_->StartDragging(panel); |
164 } | 168 } |
165 | 169 |
166 void PanelManager::Drag(int delta_x) { | 170 void PanelManager::Drag(int delta_x, int delta_y) { |
167 docked_strip_->Drag(delta_x); | 171 drag_controller_->Drag(delta_x, delta_y); |
168 } | 172 } |
169 | 173 |
170 void PanelManager::EndDragging(bool cancelled) { | 174 void PanelManager::EndDragging(bool cancelled) { |
171 docked_strip_->EndDragging(cancelled); | 175 drag_controller_->EndDragging(cancelled); |
172 } | 176 } |
173 | 177 |
174 void PanelManager::OnPanelExpansionStateChanged(Panel* panel) { | 178 void PanelManager::OnPanelExpansionStateChanged(Panel* panel) { |
175 docked_strip_->OnPanelExpansionStateChanged(panel); | 179 docked_strip_->OnPanelExpansionStateChanged(panel); |
Andrei
2012/02/18 19:41:31
Should it be panel->panel_strip()->OnPanelExpansio
jianli
2012/02/21 19:14:32
Yes, we need to fix this. I rather fix it later wh
| |
176 } | 180 } |
177 | 181 |
178 void PanelManager::OnPreferredWindowSizeChanged( | 182 void PanelManager::OnPreferredWindowSizeChanged( |
179 Panel* panel, const gfx::Size& preferred_window_size) { | 183 Panel* panel, const gfx::Size& preferred_window_size) { |
180 if (!auto_sizing_enabled_) { | 184 if (!auto_sizing_enabled_) { |
181 LOG(INFO) << "Resizing auto-resizable Panels is not supported yet."; | 185 LOG(INFO) << "Resizing auto-resizable Panels is not supported yet."; |
182 return; | 186 return; |
183 } | 187 } |
184 docked_strip_->ResizePanelWindow(panel, preferred_window_size); | 188 docked_strip_->ResizePanelWindow(panel, preferred_window_size); |
Andrei
2012/02/18 19:41:31
Same as above for this and the next 3 functions
jianli
2012/02/21 19:14:32
Yes. But I rather delay the fix as mentioned above
| |
185 } | 189 } |
186 | 190 |
187 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { | 191 void PanelManager::ResizePanel(Panel* panel, const gfx::Size& new_size) { |
188 // Explicit resizing is not allowed for auto-resizable panels for now. | 192 // Explicit resizing is not allowed for auto-resizable panels for now. |
189 // http://crbug.com/109343 | 193 // http://crbug.com/109343 |
190 if (panel->auto_resizable()) | 194 if (panel->auto_resizable()) |
191 return; | 195 return; |
192 | 196 |
193 docked_strip_->ResizePanelWindow(panel, new_size); | 197 docked_strip_->ResizePanelWindow(panel, new_size); |
194 } | 198 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 } | 237 } |
234 | 238 |
235 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { | 239 void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { |
236 AdjustWorkAreaForAutoHidingDesktopBars(); | 240 AdjustWorkAreaForAutoHidingDesktopBars(); |
237 Layout(); | 241 Layout(); |
238 } | 242 } |
239 | 243 |
240 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( | 244 void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( |
241 AutoHidingDesktopBar::Alignment alignment, | 245 AutoHidingDesktopBar::Alignment alignment, |
242 AutoHidingDesktopBar::Visibility visibility) { | 246 AutoHidingDesktopBar::Visibility visibility) { |
243 docked_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); | 247 docked_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); |
Andrei
2012/02/18 21:31:12
May other strips, detached and overflow, need to k
| |
244 } | 248 } |
245 | 249 |
246 void PanelManager::CloseAll() { | 250 void PanelManager::CloseAll() { |
251 DCHECK(!drag_controller_->dragging_panel()); | |
252 | |
253 detached_strip_->CloseAll(); | |
247 docked_strip_->CloseAll(); | 254 docked_strip_->CloseAll(); |
248 overflow_strip_->CloseAll(); | 255 overflow_strip_->CloseAll(); |
249 } | 256 } |
250 | 257 |
251 int PanelManager::num_panels() const { | 258 int PanelManager::num_panels() const { |
252 return docked_strip_->num_panels() + overflow_strip_->num_panels(); | 259 return detached_strip_->num_panels() + |
260 docked_strip_->num_panels() + | |
261 overflow_strip_->num_panels(); | |
253 } | 262 } |
254 | 263 |
255 std::vector<Panel*> PanelManager::panels() const { | 264 std::vector<Panel*> PanelManager::panels() const { |
256 std::vector<Panel*> panels; | 265 std::vector<Panel*> panels; |
266 for (DetachedPanelStrip::Panels::const_iterator iter = | |
267 detached_strip_->panels().begin(); | |
268 iter != detached_strip_->panels().end(); ++iter) | |
269 panels.push_back(*iter); | |
257 for (DockedPanelStrip::Panels::const_iterator iter = | 270 for (DockedPanelStrip::Panels::const_iterator iter = |
258 docked_strip_->panels().begin(); | 271 docked_strip_->panels().begin(); |
259 iter != docked_strip_->panels().end(); ++iter) | 272 iter != docked_strip_->panels().end(); ++iter) |
260 panels.push_back(*iter); | 273 panels.push_back(*iter); |
261 for (OverflowPanelStrip::Panels::const_iterator iter = | 274 for (OverflowPanelStrip::Panels::const_iterator iter = |
262 overflow_strip_->panels().begin(); | 275 overflow_strip_->panels().begin(); |
263 iter != overflow_strip_->panels().end(); ++iter) | 276 iter != overflow_strip_->panels().end(); ++iter) |
264 panels.push_back(*iter); | 277 panels.push_back(*iter); |
265 return panels; | 278 return panels; |
266 } | 279 } |
267 | 280 |
268 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { | 281 void PanelManager::SetMouseWatcher(PanelMouseWatcher* watcher) { |
269 panel_mouse_watcher_.reset(watcher); | 282 panel_mouse_watcher_.reset(watcher); |
270 } | 283 } |
OLD | NEW |