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/overflow_panel_strip.h" | 5 #include "chrome/browser/ui/panels/overflow_panel_strip.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/ui/panels/docked_panel_strip.h" | 8 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
9 #include "chrome/browser/ui/panels/panel_manager.h" | 9 #include "chrome/browser/ui/panels/panel_manager.h" |
10 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 10 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // The ratio to determine the maximum number of visible overflow panels when the | 25 // The ratio to determine the maximum number of visible overflow panels when the |
26 // mouse hovers over the overflow area. These panels cannot occupy more than the | 26 // mouse hovers over the overflow area. These panels cannot occupy more than the |
27 // fixed percentage of the display area height. | 27 // fixed percentage of the display area height. |
28 const double kHeightRatioForMaxVisibleOverflowPanelsOnHover = 0.67; | 28 const double kHeightRatioForMaxVisibleOverflowPanelsOnHover = 0.67; |
29 | 29 |
30 // This value is experimental and subjective. | 30 // This value is experimental and subjective. |
31 const int kOverflowHoverAnimationMs = 180; | 31 const int kOverflowHoverAnimationMs = 180; |
32 } | 32 } |
33 | 33 |
34 OverflowPanelStrip::OverflowPanelStrip(PanelManager* panel_manager) | 34 OverflowPanelStrip::OverflowPanelStrip(PanelManager* panel_manager) |
35 : panel_manager_(panel_manager), | 35 : PanelStrip(PanelStrip::IN_OVERFLOW), |
| 36 panel_manager_(panel_manager), |
36 current_display_width_(0), | 37 current_display_width_(0), |
37 max_visible_panels_(kMaxVisibleOverflowPanels), | 38 max_visible_panels_(kMaxVisibleOverflowPanels), |
38 max_visible_panels_on_hover_(0), | 39 max_visible_panels_on_hover_(0), |
39 are_overflow_titles_shown_(false), | 40 are_overflow_titles_shown_(false), |
40 overflow_hover_animator_start_width_(0), | 41 overflow_hover_animator_start_width_(0), |
41 overflow_hover_animator_end_width_(0) { | 42 overflow_hover_animator_end_width_(0) { |
42 } | 43 } |
43 | 44 |
44 OverflowPanelStrip::~OverflowPanelStrip() { | 45 OverflowPanelStrip::~OverflowPanelStrip() { |
45 DCHECK(panels_.empty()); | 46 DCHECK(panels_.empty()); |
46 DCHECK(!overflow_indicator_.get()); | 47 DCHECK(!overflow_indicator_.get()); |
47 } | 48 } |
48 | 49 |
49 void OverflowPanelStrip::SetDisplayArea(const gfx::Rect& display_area) { | 50 void OverflowPanelStrip::SetDisplayArea(const gfx::Rect& display_area) { |
50 if (display_area_ == display_area) | 51 if (display_area_ == display_area) |
51 return; | 52 return; |
52 display_area_ = display_area; | 53 display_area_ = display_area; |
53 | 54 |
54 UpdateCurrentWidth(); | 55 UpdateCurrentWidth(); |
55 | 56 |
56 max_visible_panels_on_hover_ = 0; // reset this value for recomputation. | 57 max_visible_panels_on_hover_ = 0; // reset this value for recomputation. |
57 UpdateMaxVisiblePanelsOnHover(); | 58 UpdateMaxVisiblePanelsOnHover(); |
58 | 59 |
59 if (overflow_indicator_.get()) | 60 if (overflow_indicator_.get()) |
60 UpdateOverflowIndicatorCount(); | 61 UpdateOverflowIndicatorCount(); |
61 | 62 |
62 Refresh(); | 63 RefreshLayout(); |
63 } | 64 } |
64 | 65 |
65 void OverflowPanelStrip::UpdateMaxVisiblePanelsOnHover() { | 66 void OverflowPanelStrip::UpdateMaxVisiblePanelsOnHover() { |
66 // No need to recompute this value. | 67 // No need to recompute this value. |
67 if (max_visible_panels_on_hover_ || panels_.empty()) | 68 if (max_visible_panels_on_hover_ || panels_.empty()) |
68 return; | 69 return; |
69 | 70 |
70 max_visible_panels_on_hover_ = | 71 max_visible_panels_on_hover_ = |
71 kHeightRatioForMaxVisibleOverflowPanelsOnHover * | 72 kHeightRatioForMaxVisibleOverflowPanelsOnHover * |
72 display_area_.height() / | 73 display_area_.height() / |
(...skipping 12 matching lines...) Expand all Loading... |
85 // Newly created panels that were temporarily in the panel strip | 86 // Newly created panels that were temporarily in the panel strip |
86 // are added to the back of the overflow, whereas panels that are | 87 // are added to the back of the overflow, whereas panels that are |
87 // bumped from the panel strip by other panels go to the front | 88 // bumped from the panel strip by other panels go to the front |
88 // of overflow. | 89 // of overflow. |
89 if (panel->has_temporary_layout()) { | 90 if (panel->has_temporary_layout()) { |
90 panel->set_has_temporary_layout(false); | 91 panel->set_has_temporary_layout(false); |
91 panels_.push_back(panel); | 92 panels_.push_back(panel); |
92 DoRefresh(panels_.size() - 1, panels_.size() - 1); | 93 DoRefresh(panels_.size() - 1, panels_.size() - 1); |
93 } else { | 94 } else { |
94 panels_.insert(panels_.begin(), panel); | 95 panels_.insert(panels_.begin(), panel); |
95 Refresh(); | 96 RefreshLayout(); |
96 } | 97 } |
97 | 98 |
98 if (num_panels() == 1) { | 99 if (num_panels() == 1) { |
99 panel_manager_->mouse_watcher()->AddObserver(this); | 100 panel_manager_->mouse_watcher()->AddObserver(this); |
100 UpdateMaxVisiblePanelsOnHover(); | 101 UpdateMaxVisiblePanelsOnHover(); |
101 } | 102 } |
102 | 103 |
103 // Update the overflow indicator only when the number of overflow panels go | 104 // Update the overflow indicator only when the number of overflow panels go |
104 // beyond the maximum visible limit. | 105 // beyond the maximum visible limit. |
105 if (num_panels() > max_visible_panels_) { | 106 if (num_panels() > max_visible_panels_) { |
106 if (!overflow_indicator_.get()) { | 107 if (!overflow_indicator_.get()) { |
107 overflow_indicator_.reset(PanelOverflowIndicator::Create()); | 108 overflow_indicator_.reset(PanelOverflowIndicator::Create()); |
108 } | 109 } |
109 UpdateOverflowIndicatorCount(); | 110 UpdateOverflowIndicatorCount(); |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
113 bool OverflowPanelStrip::Remove(Panel* panel) { | 114 bool OverflowPanelStrip::RemovePanel(Panel* panel) { |
114 size_t index = 0; | 115 size_t index = 0; |
115 Panels::iterator iter = panels_.begin(); | 116 Panels::iterator iter = panels_.begin(); |
116 for (; iter != panels_.end(); ++iter, ++index) | 117 for (; iter != panels_.end(); ++iter, ++index) |
117 if (*iter == panel) | 118 if (*iter == panel) |
118 break; | 119 break; |
119 if (iter == panels_.end()) | 120 if (iter == panels_.end()) |
120 return false; | 121 return false; |
121 | 122 |
122 panels_.erase(iter); | 123 panels_.erase(iter); |
123 DoRefresh(index, panels_.size() - 1); | 124 DoRefresh(index, panels_.size() - 1); |
124 panel_manager_->OnPanelRemoved(panel); | 125 panel_manager_->OnPanelRemoved(panel); |
125 | 126 |
126 if (panels_.empty()) | 127 if (panels_.empty()) |
127 panel_manager_->mouse_watcher()->RemoveObserver(this); | 128 panel_manager_->mouse_watcher()->RemoveObserver(this); |
128 | 129 |
129 // Update the overflow indicator. If the number of overflow panels fall below | 130 // Update the overflow indicator. If the number of overflow panels fall below |
130 // the maximum visible limit, we do not need the overflow indicator any more. | 131 // the maximum visible limit, we do not need the overflow indicator any more. |
131 if (num_panels() < max_visible_panels_) | 132 if (num_panels() < max_visible_panels_) |
132 overflow_indicator_.reset(); | 133 overflow_indicator_.reset(); |
133 else | 134 else |
134 UpdateOverflowIndicatorCount(); | 135 UpdateOverflowIndicatorCount(); |
135 | 136 |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 void OverflowPanelStrip::RemoveAll() { | 140 void OverflowPanelStrip::CloseAll() { |
140 // Make a copy of the iterator as closing panels can modify the vector. | 141 // Make a copy of the iterator as closing panels can modify the vector. |
141 Panels panels_copy = panels_; | 142 Panels panels_copy = panels_; |
142 | 143 |
143 // Start from the bottom to avoid reshuffling. | 144 // Start from the bottom to avoid reshuffling. |
144 for (Panels::reverse_iterator iter = panels_copy.rbegin(); | 145 for (Panels::reverse_iterator iter = panels_copy.rbegin(); |
145 iter != panels_copy.rend(); ++iter) | 146 iter != panels_copy.rend(); ++iter) |
146 (*iter)->Close(); | 147 (*iter)->Close(); |
147 } | 148 } |
148 | 149 |
| 150 void OverflowPanelStrip::ResizePanelWindow( |
| 151 Panel* panel, const gfx::Size& preferred_window_size) { |
| 152 // Overflow uses its own panel window sizes. |
| 153 } |
| 154 |
149 void OverflowPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { | 155 void OverflowPanelStrip::OnPanelExpansionStateChanged(Panel* panel) { |
150 // Only care about new state being overflow. | 156 // Only care about new state being overflow. |
151 if (panel->expansion_state() != Panel::IN_OVERFLOW) | 157 if (panel->expansion_state() != Panel::IN_OVERFLOW) |
152 return; | 158 return; |
153 | 159 |
154 panel_manager_->docked_strip()->Remove(panel); | 160 panel_manager_->docked_strip()->RemovePanel(panel); |
155 AddPanel(panel); | 161 AddPanel(panel); |
156 panel->SetAppIconVisibility(false); | 162 panel->SetAppIconVisibility(false); |
157 panel->set_draggable(false); | 163 panel->set_draggable(false); |
158 } | 164 } |
159 | 165 |
160 void OverflowPanelStrip::OnPanelAttentionStateChanged(Panel* panel) { | 166 void OverflowPanelStrip::OnPanelAttentionStateChanged(Panel* panel) { |
161 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); | 167 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); |
162 UpdateOverflowIndicatorAttention(); | 168 UpdateOverflowIndicatorAttention(); |
163 } | 169 } |
164 | 170 |
165 void OverflowPanelStrip::Refresh() { | 171 void OverflowPanelStrip::RefreshLayout() { |
166 if (panels_.empty()) | 172 if (panels_.empty()) |
167 return; | 173 return; |
168 DoRefresh(0, panels_.size() - 1); | 174 DoRefresh(0, panels_.size() - 1); |
169 } | 175 } |
170 | 176 |
171 void OverflowPanelStrip::DoRefresh(size_t start_index, size_t end_index) { | 177 void OverflowPanelStrip::DoRefresh(size_t start_index, size_t end_index) { |
172 if (panels_.empty() || start_index == panels_.size()) | 178 if (panels_.empty() || start_index == panels_.size()) |
173 return; | 179 return; |
174 | 180 |
175 DCHECK(end_index < panels_.size()); | 181 DCHECK(end_index < panels_.size()); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 bounds.set_width(current_display_width); | 350 bounds.set_width(current_display_width); |
345 overflow_indicator_->SetBounds(bounds); | 351 overflow_indicator_->SetBounds(bounds); |
346 overflow_indicator_->SetCount(num_panels() - max_visible_panels); | 352 overflow_indicator_->SetCount(num_panels() - max_visible_panels); |
347 } | 353 } |
348 } | 354 } |
349 | 355 |
350 void OverflowPanelStrip::OnFullScreenModeChanged(bool is_full_screen) { | 356 void OverflowPanelStrip::OnFullScreenModeChanged(bool is_full_screen) { |
351 for (size_t i = 0; i < panels_.size(); ++i) | 357 for (size_t i = 0; i < panels_.size(); ++i) |
352 panels_[i]->FullScreenModeChanged(is_full_screen); | 358 panels_[i]->FullScreenModeChanged(is_full_screen); |
353 } | 359 } |
OLD | NEW |