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_overflow_strip.h" | 5 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/ui/panels/panel_manager.h" | 8 #include "chrome/browser/ui/panels/panel_manager.h" |
9 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 9 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
10 #include "chrome/browser/ui/panels/panel_strip.h" | 10 #include "chrome/browser/ui/panels/panel_strip.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 } | 34 } |
35 | 35 |
36 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { | 36 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { |
37 if (display_area_ == display_area) | 37 if (display_area_ == display_area) |
38 return; | 38 return; |
39 | 39 |
40 display_area_ = display_area; | 40 display_area_ = display_area; |
41 Refresh(); | 41 Refresh(); |
42 } | 42 } |
43 | 43 |
44 void PanelOverflowStrip::AddPanel(Panel* panel, bool is_new) { | 44 void PanelOverflowStrip::AddPanel(Panel* panel) { |
45 // TODO(jianli): consider using other container to improve the perf for | 45 // TODO(jianli): consider using other container to improve the perf for |
46 // inserting to the front. http://crbug.com/106222 | 46 // inserting to the front. http://crbug.com/106222 |
47 if (is_new) | 47 DCHECK_EQ(Panel::IN_OVERFLOW, panel->expansion_state()); |
48 if (panel->temporary_layout()) { | |
jianli
2011/12/07 22:13:26
Could you please add comment to explain why we ins
jennb
2011/12/07 23:35:40
Done.
| |
49 panel->set_temporary_layout(false); | |
48 panels_.push_back(panel); | 50 panels_.push_back(panel); |
49 else | 51 DoRefresh(panels_.size() - 1, panels_.size() - 1); |
52 } else { | |
50 panels_.insert(panels_.begin(), panel); | 53 panels_.insert(panels_.begin(), panel); |
54 Refresh(); | |
55 } | |
51 | 56 |
52 if (panels_.size() == 1) | 57 if (panels_.size() == 1) |
53 panel_manager_->mouse_watcher()->AddObserver(this); | 58 panel_manager_->mouse_watcher()->AddObserver(this); |
54 | |
55 panel->SetExpansionState(Panel::IN_OVERFLOW); | |
56 | |
57 if (is_new) { | |
58 // When the overflow panel is added to the back, only need to refresh | |
59 // itself. | |
60 DoRefresh(panels_.size() - 1, panels_.size() - 1); | |
61 } else { | |
62 // When the overflow panel is added to the front, refresh all. | |
63 Refresh(); | |
64 } | |
65 } | 59 } |
66 | 60 |
67 bool PanelOverflowStrip::Remove(Panel* panel) { | 61 bool PanelOverflowStrip::Remove(Panel* panel) { |
68 size_t index = 0; | 62 size_t index = 0; |
69 for (Panels::iterator iter = panels_.begin(); iter != panels_.end(); | 63 for (Panels::iterator iter = panels_.begin(); iter != panels_.end(); |
70 ++iter, ++index) { | 64 ++iter, ++index) { |
71 if (*iter == panel) { | 65 if (*iter == panel) { |
72 panels_.erase(iter); | 66 panels_.erase(iter); |
73 DoRefresh(index, panels_.size() - 1); | 67 DoRefresh(index, panels_.size() - 1); |
74 panel_manager_->OnPanelRemoved(panel); | 68 panel_manager_->OnPanelRemoved(panel); |
(...skipping 11 matching lines...) Expand all Loading... | |
86 | 80 |
87 // Start from the bottom to avoid reshuffling. | 81 // Start from the bottom to avoid reshuffling. |
88 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 82 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
89 iter != panels_copy.rend(); ++iter) | 83 iter != panels_copy.rend(); ++iter) |
90 (*iter)->Close(); | 84 (*iter)->Close(); |
91 } | 85 } |
92 | 86 |
93 void PanelOverflowStrip::OnPanelExpansionStateChanged( | 87 void PanelOverflowStrip::OnPanelExpansionStateChanged( |
94 Panel* panel, Panel::ExpansionState old_state) { | 88 Panel* panel, Panel::ExpansionState old_state) { |
95 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); | 89 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); |
90 panel_manager_->panel_strip()->Remove(panel); | |
91 AddPanel(panel); | |
92 panel->SetAppIconVisibility(false); | |
96 } | 93 } |
97 | 94 |
98 void PanelOverflowStrip::Refresh() { | 95 void PanelOverflowStrip::Refresh() { |
99 if (panels_.empty()) | 96 if (panels_.empty()) |
100 return; | 97 return; |
101 DoRefresh(0, panels_.size() - 1); | 98 DoRefresh(0, panels_.size() - 1); |
102 } | 99 } |
103 | 100 |
104 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { | 101 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { |
105 if (panels_.empty()) | 102 if (panels_.empty()) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 } | 207 } |
211 | 208 |
212 overflow_panel->SetPanelBoundsInstantly(bounds); | 209 overflow_panel->SetPanelBoundsInstantly(bounds); |
213 } | 210 } |
214 } | 211 } |
215 | 212 |
216 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { | 213 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { |
217 for (size_t i = 0; i < panels_.size(); ++i) | 214 for (size_t i = 0; i < panels_.size(); ++i) |
218 panels_[i]->FullScreenModeChanged(is_full_screen); | 215 panels_[i]->FullScreenModeChanged(is_full_screen); |
219 } | 216 } |
OLD | NEW |