Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/browser/ui/panels/panel_overflow_strip.cc

Issue 8949035: Revert 115297 - Add overflow indicator count on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel_overflow_strip.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_overflow_indicator.h"
11 #include "chrome/browser/ui/panels/panel_strip.h" 10 #include "chrome/browser/ui/panels/panel_strip.h"
12 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
14 #include "ui/base/animation/slide_animation.h" 13 #include "ui/base/animation/slide_animation.h"
15 14
16 namespace { 15 namespace {
17 // The width of the overflow area that is expanded to show more info, i.e. 16 // The width of the overflow area that is expanded to show more info, i.e.
18 // titles, when the mouse hovers over the area. 17 // titles, when the mouse hovers over the area.
19 static const int kOverflowAreaHoverWidth = 200; 18 static const int kOverflowAreaHoverWidth = 200;
20 19
21 // Maximium number of visible overflow panels when the mouse does not hover over 20 // Maximium number of overflow panels allowed to be shown.
22 // the overflow area. 21 const size_t kMaxVisibleOverflowPanelsAllowed = 6;
23 const size_t kMaxVisibleOverflowPanels = 6;
24
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
27 // fixed percentage of the display area height.
28 const double kHeightRatioForMaxVisibleOverflowPanelsOnHover = 0.67;
29 22
30 // This value is experimental and subjective. 23 // This value is experimental and subjective.
31 const int kOverflowHoverAnimationMs = 180; 24 const int kOverflowHoverAnimationMs = 180;
32 } 25 }
33 26
34 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager) 27 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager)
35 : panel_manager_(panel_manager), 28 : panel_manager_(panel_manager),
36 current_display_width_(0), 29 current_display_width_(0),
37 max_visible_panels_(kMaxVisibleOverflowPanels), 30 max_visible_panels_(kMaxVisibleOverflowPanelsAllowed),
38 max_visible_panels_on_hover_(0),
39 are_overflow_titles_shown_(false), 31 are_overflow_titles_shown_(false),
40 overflow_hover_animator_start_width_(0), 32 overflow_hover_animator_start_width_(0),
41 overflow_hover_animator_end_width_(0) { 33 overflow_hover_animator_end_width_(0) {
42 } 34 }
43 35
44 PanelOverflowStrip::~PanelOverflowStrip() { 36 PanelOverflowStrip::~PanelOverflowStrip() {
45 DCHECK(panels_.empty()); 37 DCHECK(panels_.empty());
46 DCHECK(!overflow_indicator_.get());
47 } 38 }
48 39
49 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { 40 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) {
50 if (display_area_ == display_area) 41 if (display_area_ == display_area)
51 return; 42 return;
43
52 display_area_ = display_area; 44 display_area_ = display_area;
53
54 UpdateCurrentWidth(); 45 UpdateCurrentWidth();
55 46
56 if (overflow_indicator_.get()) {
57 max_visible_panels_on_hover_ = 0; // reset this value for recomputation.
58 UpdateMaxVisiblePanelsOnHover();
59 UpdateOverflowIndicatorCount();
60 }
61
62 Refresh(); 47 Refresh();
63 } 48 }
64 49
65 void PanelOverflowStrip::UpdateMaxVisiblePanelsOnHover() {
66 // No need to recompute this value.
67 if (max_visible_panels_on_hover_)
68 return;
69
70 DCHECK(!panels_.empty());
71 max_visible_panels_on_hover_ =
72 kHeightRatioForMaxVisibleOverflowPanelsOnHover *
73 display_area_.height() /
74 panels_.front()->IconOnlySize().height();
75 }
76
77 void PanelOverflowStrip::UpdateCurrentWidth() { 50 void PanelOverflowStrip::UpdateCurrentWidth() {
78 current_display_width_ = are_overflow_titles_shown_ ? kOverflowAreaHoverWidth 51 current_display_width_ = are_overflow_titles_shown_ ? kOverflowAreaHoverWidth
79 : display_area_.width(); 52 : display_area_.width();
80 } 53 }
81 54
82 void PanelOverflowStrip::AddPanel(Panel* panel) { 55 void PanelOverflowStrip::AddPanel(Panel* panel) {
83 // TODO(jianli): consider using other container to improve the perf for 56 // TODO(jianli): consider using other container to improve the perf for
84 // inserting to the front. http://crbug.com/106222 57 // inserting to the front. http://crbug.com/106222
85 DCHECK_EQ(Panel::IN_OVERFLOW, panel->expansion_state()); 58 DCHECK_EQ(Panel::IN_OVERFLOW, panel->expansion_state());
86 // Newly created panels that were temporarily in the panel strip 59 // Newly created panels that were temporarily in the panel strip
87 // are added to the back of the overflow, whereas panels that are 60 // are added to the back of the overflow, whereas panels that are
88 // bumped from the panel strip by other panels go to the front 61 // bumped from the panel strip by other panels go to the front
89 // of overflow. 62 // of overflow.
90 if (panel->has_temporary_layout()) { 63 if (panel->has_temporary_layout()) {
91 panel->set_has_temporary_layout(false); 64 panel->set_has_temporary_layout(false);
92 panels_.push_back(panel); 65 panels_.push_back(panel);
93 DoRefresh(panels_.size() - 1, panels_.size() - 1); 66 DoRefresh(panels_.size() - 1, panels_.size() - 1);
94 } else { 67 } else {
95 panels_.insert(panels_.begin(), panel); 68 panels_.insert(panels_.begin(), panel);
96 Refresh(); 69 Refresh();
97 } 70 }
98 71
99 if (num_panels() == 1) 72 if (panels_.size() == 1)
100 panel_manager_->mouse_watcher()->AddObserver(this); 73 panel_manager_->mouse_watcher()->AddObserver(this);
101
102 // Update the overflow indicator only when the number of overflow panels go
103 // beyond the maximum visible limit.
104 if (num_panels() > max_visible_panels_) {
105 if (!overflow_indicator_.get()) {
106 overflow_indicator_.reset(PanelOverflowIndicator::Create());
107 UpdateMaxVisiblePanelsOnHover();
108 }
109 UpdateOverflowIndicatorCount();
110 }
111 } 74 }
112 75
113 bool PanelOverflowStrip::Remove(Panel* panel) { 76 bool PanelOverflowStrip::Remove(Panel* panel) {
114 size_t index = 0; 77 size_t index = 0;
115 Panels::iterator iter = panels_.begin(); 78 for (Panels::iterator iter = panels_.begin(); iter != panels_.end();
116 for (; iter != panels_.end(); ++iter, ++index) 79 ++iter, ++index) {
117 if (*iter == panel) 80 if (*iter == panel) {
118 break; 81 panels_.erase(iter);
119 if (iter == panels_.end()) 82 DoRefresh(index, panels_.size() - 1);
120 return false; 83 panel_manager_->OnPanelRemoved(panel);
121 84 if (panels_.empty())
122 panels_.erase(iter); 85 panel_manager_->mouse_watcher()->RemoveObserver(this);
123 DoRefresh(index, panels_.size() - 1); 86 return true;
124 panel_manager_->OnPanelRemoved(panel); 87 }
125 88 }
126 if (panels_.empty()) 89 return false;
127 panel_manager_->mouse_watcher()->RemoveObserver(this);
128
129 // 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 if (num_panels() < max_visible_panels_)
132 overflow_indicator_.reset();
133 else
134 UpdateOverflowIndicatorCount();
135
136 return true;
137 } 90 }
138 91
139 void PanelOverflowStrip::RemoveAll() { 92 void PanelOverflowStrip::RemoveAll() {
140 // Make a copy of the iterator as closing panels can modify the vector. 93 // Make a copy of the iterator as closing panels can modify the vector.
141 Panels panels_copy = panels_; 94 Panels panels_copy = panels_;
142 95
143 // Start from the bottom to avoid reshuffling. 96 // Start from the bottom to avoid reshuffling.
144 for (Panels::reverse_iterator iter = panels_copy.rbegin(); 97 for (Panels::reverse_iterator iter = panels_copy.rbegin();
145 iter != panels_copy.rend(); ++iter) 98 iter != panels_copy.rend(); ++iter)
146 (*iter)->Close(); 99 (*iter)->Close();
147 } 100 }
148 101
149 void PanelOverflowStrip::OnPanelExpansionStateChanged( 102 void PanelOverflowStrip::OnPanelExpansionStateChanged(
150 Panel* panel, Panel::ExpansionState old_state) { 103 Panel* panel, Panel::ExpansionState old_state) {
151 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); 104 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW);
152 panel_manager_->panel_strip()->Remove(panel); 105 panel_manager_->panel_strip()->Remove(panel);
153 AddPanel(panel); 106 AddPanel(panel);
154 panel->SetAppIconVisibility(false); 107 panel->SetAppIconVisibility(false);
155 panel->set_draggable(false); 108 panel->set_draggable(false);
156 } 109 }
157 110
158 void PanelOverflowStrip::OnPanelAttentionStateChanged(Panel* panel) {
159 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW);
160 UpdateOverflowIndicatorAttention();
161 }
162
163 void PanelOverflowStrip::Refresh() { 111 void PanelOverflowStrip::Refresh() {
164 if (panels_.empty()) 112 if (panels_.empty())
165 return; 113 return;
166 DoRefresh(0, panels_.size() - 1); 114 DoRefresh(0, panels_.size() - 1);
167 } 115 }
168 116
169 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { 117 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) {
170 if (panels_.empty() || start_index == panels_.size()) 118 if (panels_.empty() || start_index == panels_.size())
171 return; 119 return;
172 120
173 DCHECK(end_index < panels_.size()); 121 DCHECK(end_index < panels_.size());
174 122
175 for (size_t index = start_index; index <= end_index; ++index) { 123 for (size_t index = start_index; index <= end_index; ++index) {
176 Panel* panel = panels_[index]; 124 Panel* panel = panels_[index];
177 gfx::Rect new_bounds = ComputeLayout(index, 125 gfx::Rect new_bounds = ComputeLayout(index,
178 panel->IconOnlySize()); 126 panel->IconOnlySize());
179 panel->SetPanelBounds(new_bounds); 127 panel->SetPanelBounds(new_bounds);
180 } 128 }
181 } 129 }
182 130
183 void PanelOverflowStrip::UpdateOverflowIndicatorCount() {
184 int max_panels = max_visible_panels();
185
186 // Setting the count to 0 will hide the indicator.
187 if (num_panels() <= max_panels) {
188 overflow_indicator_->SetCount(0);
189 return;
190 }
191
192 // Update the bounds and count.
193 int height = overflow_indicator_->GetHeight();
194 overflow_indicator_->SetBounds(gfx::Rect(
195 display_area_.x(),
196 panels_[max_panels - 1]->GetBounds().y() - height,
197 current_display_width_,
198 height));
199 overflow_indicator_->SetCount(num_panels() - max_panels);
200
201 // The attention state might get changed when there is a change to count
202 // value.
203 UpdateOverflowIndicatorAttention();
204 }
205
206 void PanelOverflowStrip::UpdateOverflowIndicatorAttention() {
207 int max_panels = max_visible_panels();
208
209 // The overflow indicator is painted as drawing attention only when there is
210 // at least one hidden panel that is drawing attention.
211 bool is_drawing_attention = false;
212 for (int index = max_panels; index < num_panels(); ++index) {
213 if (panels_[index]->IsDrawingAttention()) {
214 is_drawing_attention = true;
215 break;
216 }
217 }
218 if (is_drawing_attention)
219 overflow_indicator_->DrawAttention();
220 else
221 overflow_indicator_->StopDrawingAttention();
222 }
223
224 gfx::Rect PanelOverflowStrip::ComputeLayout( 131 gfx::Rect PanelOverflowStrip::ComputeLayout(
225 size_t index, const gfx::Size& iconified_size) const { 132 size_t index, const gfx::Size& iconified_size) const {
226 DCHECK(index != kInvalidPanelIndex); 133 DCHECK(index != kInvalidPanelIndex);
227 134
228 gfx::Rect bounds; 135 gfx::Rect bounds;
229 int bottom = (index == 0) ? display_area_.bottom() : 136 int bottom = (index == 0) ? display_area_.bottom() :
230 panels_[index - 1]->GetBounds().y(); 137 panels_[index - 1]->GetBounds().y();
231 bounds.set_x(display_area_.x()); 138 bounds.set_x(display_area_.x());
232 bounds.set_y(bottom - iconified_size.height()); 139 bounds.set_y(bottom - iconified_size.height());
233 140
234 if (static_cast<int>(index) < max_visible_panels()) { 141 if (are_overflow_titles_shown_ ||
142 static_cast<int>(index) < max_visible_panels_) {
235 bounds.set_width(current_display_width_); 143 bounds.set_width(current_display_width_);
236 bounds.set_height(iconified_size.height()); 144 bounds.set_height(iconified_size.height());
237 } else { 145 } else {
238 // Invisible for overflow-on-overflow. 146 // Invisible for overflow-on-overflow.
239 bounds.set_width(0); 147 bounds.set_width(0);
240 bounds.set_height(0); 148 bounds.set_height(0);
241 } 149 }
242 150
243 return bounds; 151 return bounds;
244 } 152 }
245 153
246 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { 154 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) {
247 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); 155 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position);
248 ShowOverflowTitles(show_overflow_titles); 156 ShowOverflowTitles(show_overflow_titles);
249 } 157 }
250 158
251 bool PanelOverflowStrip::ShouldShowOverflowTitles( 159 bool PanelOverflowStrip::ShouldShowOverflowTitles(
252 const gfx::Point& mouse_position) const { 160 const gfx::Point& mouse_position) const {
253 if (panels_.empty()) 161 if (panels_.empty())
254 return false; 162 return false;
255 163
256 Panel* top_visible_panel = num_panels() >= max_visible_panels() ? 164 Panel* top_visible_panel;
257 panels_[max_visible_panels() - 1] : panels_.back(); 165 if (are_overflow_titles_shown_) {
166 top_visible_panel = panels_.back();
167 } else {
168 top_visible_panel = num_panels() >= max_visible_panels_ ?
169 panels_[max_visible_panels_ - 1] : panels_.back();
170 }
258 return mouse_position.x() <= display_area_.x() + current_display_width_ && 171 return mouse_position.x() <= display_area_.x() + current_display_width_ &&
259 top_visible_panel->GetBounds().y() <= mouse_position.y() && 172 top_visible_panel->GetBounds().y() <= mouse_position.y() &&
260 mouse_position.y() <= display_area_.bottom(); 173 mouse_position.y() <= display_area_.bottom();
261 } 174 }
262 175
263 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { 176 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) {
264 if (show_overflow_titles == are_overflow_titles_shown_) 177 if (show_overflow_titles == are_overflow_titles_shown_)
265 return; 178 return;
266 are_overflow_titles_shown_ = show_overflow_titles; 179 are_overflow_titles_shown_ = show_overflow_titles;
267 180
(...skipping 18 matching lines...) Expand all
286 } 199 }
287 200
288 if (!overflow_hover_animator_.get()) 201 if (!overflow_hover_animator_.get())
289 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); 202 overflow_hover_animator_.reset(new ui::SlideAnimation(this));
290 if (overflow_hover_animator_->IsShowing()) 203 if (overflow_hover_animator_->IsShowing())
291 overflow_hover_animator_->Reset(); 204 overflow_hover_animator_->Reset();
292 overflow_hover_animator_->SetSlideDuration( 205 overflow_hover_animator_->SetSlideDuration(
293 PanelManager::AdjustTimeInterval(kOverflowHoverAnimationMs)); 206 PanelManager::AdjustTimeInterval(kOverflowHoverAnimationMs));
294 207
295 overflow_hover_animator_->Show(); 208 overflow_hover_animator_->Show();
296
297 // The overflow indicator count needs to be updated when the overflow area
298 // gets changed.
299 UpdateOverflowIndicatorCount();
300 } 209 }
301 210
302 void PanelOverflowStrip::AnimationEnded(const ui::Animation* animation) { 211 void PanelOverflowStrip::AnimationEnded(const ui::Animation* animation) {
303 content::NotificationService::current()->Notify( 212 content::NotificationService::current()->Notify(
304 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, 213 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
305 content::Source<PanelOverflowStrip>(this), 214 content::Source<PanelOverflowStrip>(this),
306 content::NotificationService::NoDetails()); 215 content::NotificationService::NoDetails());
307 } 216 }
308 217
309 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { 218 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) {
310 int current_display_width = overflow_hover_animator_->CurrentValueBetween( 219 int current_display_width = overflow_hover_animator_->CurrentValueBetween(
311 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); 220 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_);
312 bool end_of_shrinking = current_display_width == display_area_.width(); 221 bool end_of_shrinking = current_display_width == display_area_.width();
313 int max_visible_panels = end_of_shrinking ?
314 max_visible_panels_ : max_visible_panels_on_hover_;
315 222
316 // Update each overflow panel. 223 // Update each overflow panel.
317 for (int i = 0; i < num_panels(); ++i) { 224 for (size_t i = 0; i < panels_.size(); ++i) {
318 Panel* overflow_panel = panels_[i]; 225 Panel* overflow_panel = panels_[i];
319 gfx::Rect bounds = overflow_panel->GetBounds(); 226 gfx::Rect bounds = overflow_panel->GetBounds();
320 227
321 if (i >= max_visible_panels) { 228 if (static_cast<int>(i) >= max_visible_panels_ && end_of_shrinking) {
322 bounds.set_width(0); 229 bounds.set_width(0);
323 bounds.set_height(0); 230 bounds.set_height(0);
324 } else { 231 } else {
325 bounds.set_width(current_display_width); 232 bounds.set_width(current_display_width);
326 bounds.set_height(overflow_panel->IconOnlySize().height()); 233 bounds.set_height(overflow_panel->IconOnlySize().height());
327 } 234 }
328 235
329 overflow_panel->SetPanelBoundsInstantly(bounds); 236 overflow_panel->SetPanelBoundsInstantly(bounds);
330 } 237 }
331
332 // Update the indicator.
333 if (overflow_indicator_.get()) {
334 gfx::Rect bounds = overflow_indicator_->GetBounds();
335 bounds.set_width(current_display_width);
336 overflow_indicator_->SetBounds(bounds);
337 overflow_indicator_->SetCount(num_panels() - max_visible_panels);
338 }
339 } 238 }
340 239
341 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { 240 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) {
342 for (size_t i = 0; i < panels_.size(); ++i) 241 for (size_t i = 0; i < panels_.size(); ++i)
343 panels_[i]->FullScreenModeChanged(is_full_screen); 242 panels_[i]->FullScreenModeChanged(is_full_screen);
344 } 243 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_overflow_strip.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698