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/docked_panel_strip.h" | 5 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 if (panel->expansion_state() == Panel::EXPANDED) { | 105 if (panel->expansion_state() == Panel::EXPANDED) { |
106 expansion_state_to_restore = Panel::EXPANDED; | 106 expansion_state_to_restore = Panel::EXPANDED; |
107 } else { | 107 } else { |
108 if (are_titlebars_up_ || panel->IsDrawingAttention()) { | 108 if (are_titlebars_up_ || panel->IsDrawingAttention()) { |
109 expansion_state_to_restore = Panel::TITLE_ONLY; | 109 expansion_state_to_restore = Panel::TITLE_ONLY; |
110 height = panel->TitleOnlyHeight(); | 110 height = panel->TitleOnlyHeight(); |
111 } else { | 111 } else { |
112 expansion_state_to_restore = Panel::MINIMIZED; | 112 expansion_state_to_restore = Panel::MINIMIZED; |
113 height = Panel::kMinimizedPanelHeight; | 113 height = Panel::kMinimizedPanelHeight; |
114 } | 114 } |
115 IncrementMinimizedPanels(); | |
116 } | 115 } |
117 int y = | 116 int y = |
118 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; | 117 GetBottomPositionForExpansionState(expansion_state_to_restore) - height; |
119 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); | 118 panel->SetPanelBounds(gfx::Rect(x, y, width, height)); |
120 | 119 |
121 // Update the minimized state to reflect current titlebar mode. | 120 // Update the minimized state to reflect current titlebar mode. |
122 // Do this AFTER setting panel bounds to avoid an extra bounds change. | 121 // Do this AFTER setting panel bounds to avoid an extra bounds change. |
123 if (panel->expansion_state() != Panel::EXPANDED) | 122 if (panel->expansion_state() != Panel::EXPANDED) |
124 panel->SetExpansionState(expansion_state_to_restore); | 123 panel->SetExpansionState(expansion_state_to_restore); |
125 | 124 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 panel->Initialize(gfx::Rect(x, y, width, height)); | 165 panel->Initialize(gfx::Rect(x, y, width, height)); |
167 } | 166 } |
168 | 167 |
169 // Set panel properties for this strip. | 168 // Set panel properties for this strip. |
170 panel->SetAppIconVisibility(true); | 169 panel->SetAppIconVisibility(true); |
171 | 170 |
172 if (panel->has_temporary_layout()) | 171 if (panel->has_temporary_layout()) |
173 panels_in_temporary_layout_.insert(panel); | 172 panels_in_temporary_layout_.insert(panel); |
174 else | 173 else |
175 panels_.push_back(panel); | 174 panels_.push_back(panel); |
175 | |
176 UpdateMinimizedPanelCount(); | |
176 } | 177 } |
177 | 178 |
178 int DockedPanelStrip::GetMaxPanelWidth() const { | 179 int DockedPanelStrip::GetMaxPanelWidth() const { |
179 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); | 180 return static_cast<int>(display_area_.width() * kPanelMaxWidthFactor); |
180 } | 181 } |
181 | 182 |
182 int DockedPanelStrip::GetMaxPanelHeight() const { | 183 int DockedPanelStrip::GetMaxPanelHeight() const { |
183 return display_area_.height(); | 184 return display_area_.height(); |
184 } | 185 } |
185 | 186 |
186 int DockedPanelStrip::StartingRightPosition() const { | 187 int DockedPanelStrip::StartingRightPosition() const { |
187 return display_area_.right(); | 188 return display_area_.right(); |
188 } | 189 } |
189 | 190 |
190 int DockedPanelStrip::GetRightMostAvailablePosition() const { | 191 int DockedPanelStrip::GetRightMostAvailablePosition() const { |
191 return panels_.empty() ? StartingRightPosition() : | 192 return panels_.empty() ? StartingRightPosition() : |
192 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); | 193 (panels_.back()->GetBounds().x() - kPanelsHorizontalSpacing); |
193 } | 194 } |
194 | 195 |
195 void DockedPanelStrip::RemovePanel(Panel* panel) { | 196 void DockedPanelStrip::RemovePanel(Panel* panel) { |
196 DCHECK_EQ(this, panel->panel_strip()); | 197 DCHECK_EQ(this, panel->panel_strip()); |
197 panel->set_panel_strip(NULL); | 198 panel->set_panel_strip(NULL); |
198 | 199 |
199 if (panel->expansion_state() != Panel::EXPANDED) | |
200 DecrementMinimizedPanels(); | |
201 | |
202 if (panel->has_temporary_layout()) { | 200 if (panel->has_temporary_layout()) { |
203 panels_in_temporary_layout_.erase(panel); | 201 panels_in_temporary_layout_.erase(panel); |
204 return; | 202 return; |
205 } | 203 } |
206 | 204 |
207 // Removing an element from the list will invalidate the iterator that refers | 205 // Removing an element from the list will invalidate the iterator that refers |
208 // to it. We need to update the iterator in that case. | 206 // to it. We need to update the iterator in that case. |
209 DCHECK(dragging_panel_current_iterator_ == panels_.end() || | 207 DCHECK(dragging_panel_current_iterator_ == panels_.end() || |
210 *dragging_panel_current_iterator_ != panel); | 208 *dragging_panel_current_iterator_ != panel); |
211 bool update_iterator_after_erase = | 209 bool update_iterator_after_erase = |
(...skipping 10 matching lines...) Expand all Loading... | |
222 // Just check if other panels can now fit in the freed up space. | 220 // Just check if other panels can now fit in the freed up space. |
223 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); | 221 panel_manager_->MovePanelsOutOfOverflowIfCanFit(); |
224 } else { | 222 } else { |
225 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); | 223 Panels::iterator iter = find(panels_.begin(), panels_.end(), panel); |
226 DCHECK(iter != panels_.end()); | 224 DCHECK(iter != panels_.end()); |
227 iter = panels_.erase(iter); | 225 iter = panels_.erase(iter); |
228 if (update_iterator_after_erase) | 226 if (update_iterator_after_erase) |
229 dragging_panel_original_iterator_ = iter; | 227 dragging_panel_original_iterator_ = iter; |
230 RefreshLayout(); | 228 RefreshLayout(); |
231 } | 229 } |
230 | |
231 if (panel->expansion_state() != Panel::EXPANDED) | |
232 UpdateMinimizedPanelCount(); | |
233 | |
232 } | 234 } |
233 | 235 |
234 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { | 236 bool DockedPanelStrip::CanShowPanelAsActive(const Panel* panel) const { |
235 // Panels with temporary layout cannot be shown as active. | 237 // Panels with temporary layout cannot be shown as active. |
236 return !panel->has_temporary_layout(); | 238 return !panel->has_temporary_layout(); |
237 } | 239 } |
238 | 240 |
239 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { | 241 bool DockedPanelStrip::CanDragPanel(const Panel* panel) const { |
240 // Only the panels having temporary layout can't be dragged. | 242 // Only the panels having temporary layout can't be dragged. |
241 return !panel->has_temporary_layout(); | 243 return !panel->has_temporary_layout(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 | 359 |
358 dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = | 360 dragging_panel_current_iterator_ = dragging_panel_original_iterator_ = |
359 panels_.end(); | 361 panels_.end(); |
360 | 362 |
361 RefreshLayout(); | 363 RefreshLayout(); |
362 } | 364 } |
363 | 365 |
364 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 366 void DockedPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { |
365 gfx::Size size = panel->restored_size(); | 367 gfx::Size size = panel->restored_size(); |
366 Panel::ExpansionState expansion_state = panel->expansion_state(); | 368 Panel::ExpansionState expansion_state = panel->expansion_state(); |
367 Panel::ExpansionState old_state = panel->old_expansion_state(); | |
368 switch (expansion_state) { | 369 switch (expansion_state) { |
369 case Panel::EXPANDED: | 370 case Panel::EXPANDED: |
370 if (old_state == Panel::TITLE_ONLY || old_state == Panel::MINIMIZED) | |
371 DecrementMinimizedPanels(); | |
372 break; | 371 break; |
373 case Panel::TITLE_ONLY: | 372 case Panel::TITLE_ONLY: |
374 size.set_height(panel->TitleOnlyHeight()); | 373 size.set_height(panel->TitleOnlyHeight()); |
375 if (old_state == Panel::EXPANDED) | |
376 IncrementMinimizedPanels(); | |
377 break; | 374 break; |
378 case Panel::MINIMIZED: | 375 case Panel::MINIMIZED: |
379 size.set_height(Panel::kMinimizedPanelHeight); | 376 size.set_height(Panel::kMinimizedPanelHeight); |
380 if (old_state == Panel::EXPANDED) | |
381 IncrementMinimizedPanels(); | |
382 break; | 377 break; |
383 default: | 378 default: |
384 NOTREACHED(); | 379 NOTREACHED(); |
385 break; | 380 break; |
386 } | 381 } |
382 UpdateMinimizedPanelCount(); | |
387 | 383 |
388 int bottom = GetBottomPositionForExpansionState(expansion_state); | 384 int bottom = GetBottomPositionForExpansionState(expansion_state); |
389 gfx::Rect bounds = panel->GetBounds(); | 385 gfx::Rect bounds = panel->GetBounds(); |
390 panel->SetPanelBounds( | 386 panel->SetPanelBounds( |
391 gfx::Rect(bounds.right() - size.width(), | 387 gfx::Rect(bounds.right() - size.width(), |
392 bottom - size.height(), | 388 bottom - size.height(), |
393 size.width(), | 389 size.width(), |
394 size.height())); | 390 size.height())); |
395 } | 391 } |
396 | 392 |
(...skipping 30 matching lines...) Expand all Loading... | |
427 | 423 |
428 void DockedPanelStrip::RestorePanel(Panel* panel) { | 424 void DockedPanelStrip::RestorePanel(Panel* panel) { |
429 DCHECK_EQ(this, panel->panel_strip()); | 425 DCHECK_EQ(this, panel->panel_strip()); |
430 panel->SetExpansionState(Panel::EXPANDED); | 426 panel->SetExpansionState(Panel::EXPANDED); |
431 } | 427 } |
432 | 428 |
433 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { | 429 bool DockedPanelStrip::IsPanelMinimized(const Panel* panel) const { |
434 return panel->expansion_state() != Panel::EXPANDED; | 430 return panel->expansion_state() != Panel::EXPANDED; |
435 } | 431 } |
436 | 432 |
437 void DockedPanelStrip::IncrementMinimizedPanels() { | 433 void DockedPanelStrip::UpdateMinimizedPanelCount() { |
jennb
2012/03/12 18:26:27
Way more efficient to incr/decr a count than re-co
| |
438 minimized_panel_count_++; | 434 int prev_minimized_panel_count = minimized_panel_count_; |
439 if (minimized_panel_count_ == 1) | 435 minimized_panel_count_ = 0; |
436 for (Panels::const_iterator i_panel = panels_.begin(); | |
jianli
2012/03/12 18:08:56
nit: normally we use iter or panel_iter.
| |
437 i_panel != panels_.end(); ++i_panel) { | |
438 if ((*i_panel)->expansion_state() != Panel::EXPANDED) | |
439 minimized_panel_count_++; | |
440 } | |
441 | |
442 if (prev_minimized_panel_count == 0 && minimized_panel_count_ > 0) | |
440 panel_manager_->mouse_watcher()->AddObserver(this); | 443 panel_manager_->mouse_watcher()->AddObserver(this); |
444 if (prev_minimized_panel_count > 0 && minimized_panel_count_ == 0) | |
445 panel_manager_->mouse_watcher()->RemoveObserver(this); | |
446 | |
441 DCHECK_LE(minimized_panel_count_, num_panels()); | 447 DCHECK_LE(minimized_panel_count_, num_panels()); |
442 } | 448 } |
443 | 449 |
444 void DockedPanelStrip::DecrementMinimizedPanels() { | |
445 minimized_panel_count_--; | |
446 DCHECK_GE(minimized_panel_count_, 0); | |
447 if (minimized_panel_count_ == 0) | |
448 panel_manager_->mouse_watcher()->RemoveObserver(this); | |
449 } | |
450 | |
451 void DockedPanelStrip::ResizePanelWindow( | 450 void DockedPanelStrip::ResizePanelWindow( |
452 Panel* panel, | 451 Panel* panel, |
453 const gfx::Size& preferred_window_size) { | 452 const gfx::Size& preferred_window_size) { |
454 // The panel width: | 453 // The panel width: |
455 // * cannot grow or shrink to go beyond [min_width, max_width] | 454 // * cannot grow or shrink to go beyond [min_width, max_width] |
456 int new_width = preferred_window_size.width(); | 455 int new_width = preferred_window_size.width(); |
457 if (new_width > panel->max_size().width()) | 456 if (new_width > panel->max_size().width()) |
458 new_width = panel->max_size().width(); | 457 new_width = panel->max_size().width(); |
459 if (new_width < panel->min_size().width()) | 458 if (new_width < panel->min_size().width()) |
460 new_width = panel->min_size().width(); | 459 new_width = panel->min_size().width(); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 DCHECK(panels_in_temporary_layout_.empty()); | 737 DCHECK(panels_in_temporary_layout_.empty()); |
739 | 738 |
740 // Make a copy of the iterator as closing panels can modify the vector. | 739 // Make a copy of the iterator as closing panels can modify the vector. |
741 Panels panels_copy = panels_; | 740 Panels panels_copy = panels_; |
742 | 741 |
743 // Start from the bottom to avoid reshuffling. | 742 // Start from the bottom to avoid reshuffling. |
744 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 743 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
745 iter != panels_copy.rend(); ++iter) | 744 iter != panels_copy.rend(); ++iter) |
746 (*iter)->Close(); | 745 (*iter)->Close(); |
747 } | 746 } |
OLD | NEW |