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/stacked_panel_collection.h" | 5 #include "chrome/browser/ui/panels/stacked_panel_collection.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/ui/panels/detached_panel_collection.h" |
| 10 #include "chrome/browser/ui/panels/native_panel_stack.h" |
9 #include "chrome/browser/ui/panels/panel.h" | 11 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_manager.h" | 12 #include "chrome/browser/ui/panels/panel_manager.h" |
11 | 13 |
12 StackedPanelCollection::StackedPanelCollection(PanelManager* panel_manager) | 14 StackedPanelCollection::StackedPanelCollection(PanelManager* panel_manager) |
13 : PanelCollection(PanelCollection::STACKED), | 15 : PanelCollection(PanelCollection::STACKED), |
14 panel_manager_(panel_manager) { | 16 panel_manager_(panel_manager), |
| 17 native_stack_(NULL) { |
| 18 native_stack_ = NativePanelStack::Create(make_scoped_ptr(this).Pass()); |
15 } | 19 } |
16 | 20 |
17 StackedPanelCollection::~StackedPanelCollection() { | 21 StackedPanelCollection::~StackedPanelCollection() { |
18 DCHECK(panels_.empty()); | 22 DCHECK(panels_.empty()); |
19 } | 23 } |
20 | 24 |
21 void StackedPanelCollection::OnDisplayAreaChanged( | 25 void StackedPanelCollection::OnDisplayAreaChanged( |
22 const gfx::Rect& old_display_area) { | 26 const gfx::Rect& old_display_area) { |
23 } | 27 } |
24 | 28 |
25 void StackedPanelCollection::RefreshLayout() { | 29 void StackedPanelCollection::RefreshLayout() { |
| 30 if (panels_.empty()) |
| 31 return; |
| 32 |
| 33 Panels::const_iterator iter = panels_.begin(); |
| 34 Panel* top_panel = *iter; |
| 35 gfx::Rect top_panel_bounds = top_panel->GetBounds(); |
| 36 int common_width = top_panel_bounds.width(); |
| 37 int common_x = top_panel_bounds.x(); |
| 38 int y = top_panel_bounds.bottom(); |
| 39 |
| 40 ++iter; |
| 41 for (; iter != panels_.end(); ++iter) { |
| 42 Panel* panel = *iter; |
| 43 |
| 44 // Don't update the stacked panel that is in preview mode. |
| 45 gfx::Rect bounds = panel->GetBounds(); |
| 46 if (!panel->in_preview_mode()) { |
| 47 bounds.set_x(common_x); |
| 48 bounds.set_y(y); |
| 49 bounds.set_width(common_width); |
| 50 panel->SetPanelBounds(bounds); |
| 51 gfx::Size full_size = bounds.size(); |
| 52 full_size.set_width(common_width); |
| 53 panel->set_full_size(full_size); |
| 54 } |
| 55 |
| 56 y += bounds.height(); |
| 57 } |
| 58 |
| 59 // Compute and apply the enclosing bounds. |
| 60 gfx::Rect enclosing_bounds = top_panel->GetBounds(); |
| 61 enclosing_bounds.set_height( |
| 62 bottom_panel()->GetBounds().bottom() - enclosing_bounds.y()); |
| 63 native_stack_->SetBounds(enclosing_bounds); |
26 } | 64 } |
27 | 65 |
28 void StackedPanelCollection::AddPanel(Panel* panel, | 66 void StackedPanelCollection::AddPanel(Panel* panel, |
29 PositioningMask positioning_mask) { | 67 PositioningMask positioning_mask) { |
30 DCHECK_NE(this, panel->collection()); | 68 DCHECK_NE(this, panel->collection()); |
31 panel->set_collection(this); | 69 panel->set_collection(this); |
32 panels_.push_back(panel); | 70 if (positioning_mask & PanelCollection::TOP_POSITION) |
| 71 panels_.push_front(panel); |
| 72 else |
| 73 panels_.push_back(panel); |
33 | 74 |
34 RefreshLayout(); | 75 if ((positioning_mask & NO_LAYOUT_REFRESH) == 0) |
| 76 RefreshLayout(); |
| 77 |
| 78 native_stack_->OnPanelAddedOrRemoved(panel); |
35 } | 79 } |
36 | 80 |
37 void StackedPanelCollection::RemovePanel(Panel* panel) { | 81 void StackedPanelCollection::RemovePanel(Panel* panel) { |
38 panel->set_collection(NULL); | 82 panel->set_collection(NULL); |
39 panels_.remove(panel); | 83 panels_.remove(panel); |
40 | 84 |
41 RefreshLayout(); | 85 RefreshLayout(); |
| 86 |
| 87 native_stack_->OnPanelAddedOrRemoved(panel); |
42 } | 88 } |
43 | 89 |
44 void StackedPanelCollection::CloseAll() { | 90 void StackedPanelCollection::CloseAll() { |
45 // Make a copy as closing panels can modify the iterator. | 91 // Make a copy as closing panels can modify the iterator. |
46 Panels panels_copy = panels_; | 92 Panels panels_copy = panels_; |
47 | 93 |
48 for (Panels::const_iterator iter = panels_copy.begin(); | 94 for (Panels::const_iterator iter = panels_copy.begin(); |
49 iter != panels_copy.end(); ++iter) | 95 iter != panels_copy.end(); ++iter) |
50 (*iter)->Close(); | 96 (*iter)->Close(); |
| 97 |
| 98 native_stack_->Close(); |
51 } | 99 } |
52 | 100 |
53 void StackedPanelCollection::OnPanelAttentionStateChanged(Panel* panel) { | 101 void StackedPanelCollection::OnPanelAttentionStateChanged(Panel* panel) { |
54 } | 102 } |
55 | 103 |
56 void StackedPanelCollection::OnPanelTitlebarClicked( | 104 void StackedPanelCollection::OnPanelTitlebarClicked( |
57 Panel* panel, panel::ClickModifier modifier) { | 105 Panel* panel, panel::ClickModifier modifier) { |
58 } | 106 } |
59 | 107 |
60 void StackedPanelCollection::ResizePanelWindow( | 108 void StackedPanelCollection::ResizePanelWindow( |
(...skipping 18 matching lines...) Expand all Loading... |
79 | 127 |
80 bool StackedPanelCollection::CanMinimizePanel(const Panel* panel) const { | 128 bool StackedPanelCollection::CanMinimizePanel(const Panel* panel) const { |
81 return true; | 129 return true; |
82 } | 130 } |
83 | 131 |
84 bool StackedPanelCollection::IsPanelMinimized(const Panel* panel) const { | 132 bool StackedPanelCollection::IsPanelMinimized(const Panel* panel) const { |
85 return false; | 133 return false; |
86 } | 134 } |
87 | 135 |
88 void StackedPanelCollection::SavePanelPlacement(Panel* panel) { | 136 void StackedPanelCollection::SavePanelPlacement(Panel* panel) { |
| 137 DCHECK(!saved_panel_placement_.panel); |
| 138 saved_panel_placement_.panel = panel; |
| 139 |
| 140 if (top_panel() != panel) |
| 141 saved_panel_placement_.top_panel = top_panel(); |
| 142 else |
| 143 saved_panel_placement_.position = panel->GetBounds().origin(); |
| 144 |
| 145 saved_panel_placement_.top_panel = top_panel() != panel ? top_panel() : NULL; |
89 } | 146 } |
90 | 147 |
91 void StackedPanelCollection::RestorePanelToSavedPlacement() { | 148 void StackedPanelCollection::RestorePanelToSavedPlacement() { |
| 149 DCHECK(saved_panel_placement_.panel); |
| 150 |
| 151 if (saved_panel_placement_.top_panel) { |
| 152 // Restore the top panel if it has been moved out of the stack. This could |
| 153 // happen when there're 2 panels in the stack and the bottom panel is being |
| 154 // dragged out of the stack and thus cause both panels become detached. |
| 155 if (saved_panel_placement_.top_panel->stack() != this) { |
| 156 DCHECK_EQ(PanelCollection::DETACHED, |
| 157 saved_panel_placement_.top_panel->collection()->type()); |
| 158 panel_manager_->MovePanelToCollection(saved_panel_placement_.top_panel, |
| 159 this, |
| 160 PanelCollection::TOP_POSITION); |
| 161 } |
| 162 } else { |
| 163 // Restore the position when the top panel is being dragged. |
| 164 DCHECK_EQ(top_panel(), saved_panel_placement_.panel); |
| 165 gfx::Rect new_bounds(saved_panel_placement_.panel->GetBounds()); |
| 166 new_bounds.set_origin(saved_panel_placement_.position); |
| 167 saved_panel_placement_.panel->SetPanelBounds(new_bounds); |
| 168 } |
| 169 |
| 170 RefreshLayout(); |
| 171 |
| 172 DiscardSavedPanelPlacement(); |
92 } | 173 } |
93 | 174 |
94 void StackedPanelCollection::DiscardSavedPanelPlacement() { | 175 void StackedPanelCollection::DiscardSavedPanelPlacement() { |
| 176 DCHECK(saved_panel_placement_.panel); |
| 177 saved_panel_placement_.panel = NULL; |
| 178 saved_panel_placement_.top_panel = NULL; |
95 } | 179 } |
96 | 180 |
97 panel::Resizability StackedPanelCollection::GetPanelResizability( | 181 panel::Resizability StackedPanelCollection::GetPanelResizability( |
98 const Panel* panel) const { | 182 const Panel* panel) const { |
99 return panel::RESIZABLE_ALL_SIDES; | 183 return panel::RESIZABLE_ALL_SIDES; |
100 } | 184 } |
101 | 185 |
102 void StackedPanelCollection::OnPanelResizedByMouse( | 186 void StackedPanelCollection::OnPanelResizedByMouse( |
103 Panel* panel, const gfx::Rect& new_bounds) { | 187 Panel* panel, const gfx::Rect& new_bounds) { |
104 } | 188 } |
105 | 189 |
106 bool StackedPanelCollection::HasPanel(Panel* panel) const { | 190 bool StackedPanelCollection::HasPanel(Panel* panel) const { |
107 return std::find(panels_.begin(), panels_.end(), panel) != panels_.end(); | 191 return std::find(panels_.begin(), panels_.end(), panel) != panels_.end(); |
108 } | 192 } |
109 | 193 |
110 void StackedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { | 194 void StackedPanelCollection::UpdatePanelOnCollectionChange(Panel* panel) { |
| 195 panel->set_attention_mode( |
| 196 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION | |
| 197 Panel::USE_SYSTEM_ATTENTION)); |
| 198 panel->SetAlwaysOnTop(false); |
| 199 panel->EnableResizeByMouse(true); |
| 200 panel->UpdateMinimizeRestoreButtonVisibility(); |
111 } | 201 } |
112 | 202 |
113 void StackedPanelCollection::OnPanelActiveStateChanged(Panel* panel) { | 203 void StackedPanelCollection::OnPanelActiveStateChanged(Panel* panel) { |
114 } | 204 } |
115 | 205 |
116 Panel* StackedPanelCollection::GetPanelAbove(Panel* panel) const { | 206 Panel* StackedPanelCollection::GetPanelAbove(Panel* panel) const { |
117 DCHECK(panel); | 207 DCHECK(panel); |
118 | 208 |
119 if (panels_.size() < 2) | 209 if (panels_.size() < 2) |
120 return NULL; | 210 return NULL; |
121 Panels::const_iterator iter = panels_.begin(); | 211 Panels::const_iterator iter = panels_.begin(); |
122 Panel* above_panel = *iter; | 212 Panel* above_panel = *iter; |
123 for (; iter != panels_.end(); ++iter) { | 213 for (; iter != panels_.end(); ++iter) { |
124 if (*iter == panel) | 214 if (*iter == panel) |
125 return above_panel; | 215 return above_panel; |
126 above_panel = *iter; | 216 above_panel = *iter; |
127 } | 217 } |
128 return NULL; | 218 return NULL; |
129 } | 219 } |
| 220 |
| 221 void StackedPanelCollection::MoveAllDraggingPanelsInstantly( |
| 222 const gfx::Vector2d& delta_origin) { |
| 223 for (Panels::const_iterator iter = panels_.begin(); |
| 224 iter != panels_.end(); iter++) { |
| 225 Panel* panel = *iter; |
| 226 if (panel->in_preview_mode()) |
| 227 panel->MoveByInstantly(delta_origin); |
| 228 } |
| 229 } |
OLD | NEW |