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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
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" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/window_sizer.h" | 14 #include "chrome/browser/ui/window_sizer.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" |
15 | 18 |
16 namespace { | 19 namespace { |
17 // Invalid panel index. | 20 // Invalid panel index. |
18 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 21 const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
19 | 22 |
20 // Width of spacing between first panel and the right edge of the screen. | 23 // Width of spacing between first panel and the right edge of the screen. |
21 // Leaving a larger gap at the edge of the screen allows access to UI | 24 // Leaving a larger gap at the edge of the screen allows access to UI |
22 // elements located on the bottom right of windows. | 25 // elements located on the bottom right of windows. |
23 const int kRightScreenEdgeSpacingWidth = 24; | 26 const int kRightScreenEdgeSpacingWidth = 24; |
24 | 27 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 else if (height > max_panel_height) | 123 else if (height > max_panel_height) |
121 height = max_panel_height; | 124 height = max_panel_height; |
122 | 125 |
123 int y = adjusted_work_area_.bottom() - height; | 126 int y = adjusted_work_area_.bottom() - height; |
124 int x = GetRightMostAvailablePosition() - width; | 127 int x = GetRightMostAvailablePosition() - width; |
125 | 128 |
126 // Now create the panel with the computed bounds. | 129 // Now create the panel with the computed bounds. |
127 Panel* panel = new Panel(browser, gfx::Rect(x, y, width, height)); | 130 Panel* panel = new Panel(browser, gfx::Rect(x, y, width, height)); |
128 panel->SetMaxSize(gfx::Size(max_panel_width, max_panel_height)); | 131 panel->SetMaxSize(gfx::Size(max_panel_width, max_panel_height)); |
129 panels_.push_back(panel); | 132 panels_.push_back(panel); |
| 133 |
| 134 content::NotificationService::current()->Notify( |
| 135 chrome::NOTIFICATION_PANEL_ADDED, |
| 136 content::Source<Panel>(panel), |
| 137 content::NotificationService::NoDetails()); |
| 138 |
130 return panel; | 139 return panel; |
131 } | 140 } |
132 | 141 |
133 int PanelManager::GetMaxPanelWidth() const { | 142 int PanelManager::GetMaxPanelWidth() const { |
134 return static_cast<int>(adjusted_work_area_.width() * kPanelMaxWidthFactor); | 143 return static_cast<int>(adjusted_work_area_.width() * kPanelMaxWidthFactor); |
135 } | 144 } |
136 | 145 |
137 int PanelManager::GetMaxPanelHeight() const { | 146 int PanelManager::GetMaxPanelHeight() const { |
138 return static_cast<int>(adjusted_work_area_.height() * kPanelMaxHeightFactor); | 147 return static_cast<int>(adjusted_work_area_.height() * kPanelMaxHeightFactor); |
139 } | 148 } |
(...skipping 26 matching lines...) Expand all Loading... |
166 void PanelManager::DoRemove(Panel* panel) { | 175 void PanelManager::DoRemove(Panel* panel) { |
167 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 176 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
168 if (iter == panels_.end()) | 177 if (iter == panels_.end()) |
169 return; | 178 return; |
170 | 179 |
171 if (panel->expansion_state() != Panel::EXPANDED) | 180 if (panel->expansion_state() != Panel::EXPANDED) |
172 DecrementMinimizedPanels(); | 181 DecrementMinimizedPanels(); |
173 | 182 |
174 gfx::Rect bounds = (*iter)->GetBounds(); | 183 gfx::Rect bounds = (*iter)->GetBounds(); |
175 Rearrange(panels_.erase(iter), bounds.right()); | 184 Rearrange(panels_.erase(iter), bounds.right()); |
| 185 |
| 186 content::NotificationService::current()->Notify( |
| 187 chrome::NOTIFICATION_PANEL_REMOVED, |
| 188 content::Source<Panel>(panel), |
| 189 content::NotificationService::NoDetails()); |
176 } | 190 } |
177 | 191 |
178 void PanelManager::StartDragging(Panel* panel) { | 192 void PanelManager::StartDragging(Panel* panel) { |
179 for (size_t i = 0; i < panels_.size(); ++i) { | 193 for (size_t i = 0; i < panels_.size(); ++i) { |
180 if (panels_[i] == panel) { | 194 if (panels_[i] == panel) { |
181 dragging_panel_index_ = i; | 195 dragging_panel_index_ = i; |
182 dragging_panel_bounds_ = panel->GetBounds(); | 196 dragging_panel_bounds_ = panel->GetBounds(); |
183 dragging_panel_original_x_ = dragging_panel_bounds_.x(); | 197 dragging_panel_original_x_ = dragging_panel_bounds_.x(); |
184 break; | 198 break; |
185 } | 199 } |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 // Start from the bottom to avoid reshuffling. | 619 // Start from the bottom to avoid reshuffling. |
606 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 620 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
607 iter != panels_copy.rend(); ++iter) | 621 iter != panels_copy.rend(); ++iter) |
608 (*iter)->Close(); | 622 (*iter)->Close(); |
609 } | 623 } |
610 | 624 |
611 bool PanelManager::is_dragging_panel() const { | 625 bool PanelManager::is_dragging_panel() const { |
612 return dragging_panel_index_ != kInvalidPanelIndex; | 626 return dragging_panel_index_ != kInvalidPanelIndex; |
613 } | 627 } |
614 | 628 |
OLD | NEW |