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

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

Issue 8872044: Add test cases for panel overflow handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback 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
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_strip.h" 10 #include "chrome/browser/ui/panels/panel_strip.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "content/public/browser/notification_service.h"
11 #include "ui/base/animation/slide_animation.h" 13 #include "ui/base/animation/slide_animation.h"
12 14
13 namespace { 15 namespace {
14 // The width of the overflow area that is expanded to show more info, i.e.
15 // titles, when the mouse hovers over the area.
16 const int kOverflowAreaHoverWidth = 200;
17
18 // Maximium number of overflow panels allowed to be shown. 16 // Maximium number of overflow panels allowed to be shown.
19 const size_t kMaxVisibleOverflowPanelsAllowed = 6; 17 const size_t kMaxVisibleOverflowPanelsAllowed = 6;
20 18
21 // This value is experimental and subjective. 19 // This value is experimental and subjective.
22 const int kOverflowHoverAnimationMs = 180; 20 const int kOverflowHoverAnimationMs = 180;
23 } 21 }
24 22
25 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager) 23 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager)
26 : panel_manager_(panel_manager), 24 : panel_manager_(panel_manager),
25 max_visible_panels_(kMaxVisibleOverflowPanelsAllowed),
27 are_overflow_titles_shown_(false), 26 are_overflow_titles_shown_(false),
28 overflow_hover_animator_start_width_(0), 27 overflow_hover_animator_start_width_(0),
29 overflow_hover_animator_end_width_(0) { 28 overflow_hover_animator_end_width_(0) {
30 } 29 }
31 30
32 PanelOverflowStrip::~PanelOverflowStrip() { 31 PanelOverflowStrip::~PanelOverflowStrip() {
33 DCHECK(panels_.empty()); 32 DCHECK(panels_.empty());
34 } 33 }
35 34
36 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { 35 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void PanelOverflowStrip::Refresh() { 98 void PanelOverflowStrip::Refresh() {
100 if (panels_.empty()) 99 if (panels_.empty())
101 return; 100 return;
102 DoRefresh(0, panels_.size() - 1); 101 DoRefresh(0, panels_.size() - 1);
103 } 102 }
104 103
105 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { 104 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) {
106 if (panels_.empty() || start_index == panels_.size()) 105 if (panels_.empty() || start_index == panels_.size())
107 return; 106 return;
108 107
109 DCHECK(start_index < panels_.size());
110 DCHECK(end_index < panels_.size()); 108 DCHECK(end_index < panels_.size());
111 109
112 for (size_t index = start_index; index <= end_index; ++index) { 110 for (size_t index = start_index; index <= end_index; ++index) {
113 Panel* panel = panels_[index]; 111 Panel* panel = panels_[index];
114 gfx::Rect new_bounds = ComputeLayout(index, 112 gfx::Rect new_bounds = ComputeLayout(index,
115 panel->IconOnlySize()); 113 panel->IconOnlySize());
116 panel->SetPanelBounds(new_bounds); 114 panel->SetPanelBounds(new_bounds);
117 } 115 }
118 } 116 }
119 117
120 gfx::Rect PanelOverflowStrip::ComputeLayout( 118 gfx::Rect PanelOverflowStrip::ComputeLayout(
121 size_t index, const gfx::Size& iconified_size) const { 119 size_t index, const gfx::Size& iconified_size) const {
122 DCHECK(index != kInvalidPanelIndex); 120 DCHECK(index != kInvalidPanelIndex);
123 121
124 gfx::Rect bounds; 122 gfx::Rect bounds;
125 int bottom = (index == 0) ? display_area_.bottom() : 123 int bottom = (index == 0) ? display_area_.bottom() :
126 panels_[index - 1]->GetBounds().y(); 124 panels_[index - 1]->GetBounds().y();
127 bounds.set_x(display_area_.x()); 125 bounds.set_x(display_area_.x());
128 bounds.set_y(bottom - iconified_size.height()); 126 bounds.set_y(bottom - iconified_size.height());
129 127
130 if (are_overflow_titles_shown_) { 128 if (are_overflow_titles_shown_) {
131 // Both icon and title are visible when the mouse hovers over the overflow 129 // Both icon and title are visible when the mouse hovers over the overflow
132 // area. 130 // area.
133 bounds.set_width(kOverflowAreaHoverWidth); 131 bounds.set_width(kOverflowAreaHoverWidth);
134 bounds.set_height(iconified_size.height()); 132 bounds.set_height(iconified_size.height());
135 } else if (index < kMaxVisibleOverflowPanelsAllowed) { 133 } else if (static_cast<int>(index) < max_visible_panels_) {
136 // Only the icon is visible. 134 // Only the icon is visible.
137 bounds.set_width(iconified_size.width()); 135 bounds.set_width(iconified_size.width());
138 bounds.set_height(iconified_size.height()); 136 bounds.set_height(iconified_size.height());
139 } else { 137 } else {
140 // Invisible for overflow-on-overflow. 138 // Invisible for overflow-on-overflow.
141 bounds.set_width(0); 139 bounds.set_width(0);
142 bounds.set_height(0); 140 bounds.set_height(0);
143 } 141 }
144 142
145 return bounds; 143 return bounds;
146 } 144 }
147 145
148 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { 146 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) {
149 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); 147 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position);
150 ShowOverflowTitles(show_overflow_titles); 148 ShowOverflowTitles(show_overflow_titles);
151 } 149 }
152 150
153 bool PanelOverflowStrip::ShouldShowOverflowTitles( 151 bool PanelOverflowStrip::ShouldShowOverflowTitles(
154 const gfx::Point& mouse_position) const { 152 const gfx::Point& mouse_position) const {
155 if (panels_.empty()) 153 if (panels_.empty())
156 return false; 154 return false;
157 155
158 int width; 156 int width;
159 Panel* top_visible_panel; 157 Panel* top_visible_panel;
160 if (are_overflow_titles_shown_) { 158 if (are_overflow_titles_shown_) {
161 width = kOverflowAreaHoverWidth; 159 width = kOverflowAreaHoverWidth;
162 top_visible_panel = panels_.back(); 160 top_visible_panel = panels_.back();
163 } else { 161 } else {
164 width = display_area_.width(); 162 width = display_area_.width();
165 top_visible_panel = panels_.size() >= kMaxVisibleOverflowPanelsAllowed ? 163 top_visible_panel = num_panels() >= max_visible_panels_ ?
166 panels_[kMaxVisibleOverflowPanelsAllowed - 1] : panels_.back(); 164 panels_[max_visible_panels_ - 1] : panels_.back();
167 } 165 }
168 return mouse_position.x() <= display_area_.x() + width && 166 return mouse_position.x() <= display_area_.x() + width &&
169 top_visible_panel->GetBounds().y() <= mouse_position.y() && 167 top_visible_panel->GetBounds().y() <= mouse_position.y() &&
170 mouse_position.y() <= display_area_.bottom(); 168 mouse_position.y() <= display_area_.bottom();
171 } 169 }
172 170
173 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { 171 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) {
174 if (show_overflow_titles == are_overflow_titles_shown_) 172 if (show_overflow_titles == are_overflow_titles_shown_)
175 return; 173 return;
176 are_overflow_titles_shown_ = show_overflow_titles; 174 are_overflow_titles_shown_ = show_overflow_titles;
(...skipping 18 matching lines...) Expand all
195 193
196 if (!overflow_hover_animator_.get()) 194 if (!overflow_hover_animator_.get())
197 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); 195 overflow_hover_animator_.reset(new ui::SlideAnimation(this));
198 if (overflow_hover_animator_->IsShowing()) 196 if (overflow_hover_animator_->IsShowing())
199 overflow_hover_animator_->Reset(); 197 overflow_hover_animator_->Reset();
200 overflow_hover_animator_->SetSlideDuration(kOverflowHoverAnimationMs); 198 overflow_hover_animator_->SetSlideDuration(kOverflowHoverAnimationMs);
201 199
202 overflow_hover_animator_->Show(); 200 overflow_hover_animator_->Show();
203 } 201 }
204 202
203 void PanelOverflowStrip::AnimationEnded(const ui::Animation* animation) {
204 content::NotificationService::current()->Notify(
205 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
206 content::Source<PanelOverflowStrip>(this),
207 content::NotificationService::NoDetails());
208 }
209
205 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { 210 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) {
206 int current_width = overflow_hover_animator_->CurrentValueBetween( 211 int current_width = overflow_hover_animator_->CurrentValueBetween(
207 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); 212 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_);
208 bool end_of_shrinking = current_width == display_area_.width(); 213 bool end_of_shrinking = current_width == display_area_.width();
209 214
210 // Update each overflow panel. 215 // Update each overflow panel.
211 for (size_t i = 0; i < panels_.size(); ++i) { 216 for (size_t i = 0; i < panels_.size(); ++i) {
212 Panel* overflow_panel = panels_[i]; 217 Panel* overflow_panel = panels_[i];
213 gfx::Rect bounds = overflow_panel->GetBounds(); 218 gfx::Rect bounds = overflow_panel->GetBounds();
214 219
215 if (i >= kMaxVisibleOverflowPanelsAllowed && end_of_shrinking) { 220 if (static_cast<int>(i) >= max_visible_panels_ && end_of_shrinking) {
216 bounds.set_width(0); 221 bounds.set_width(0);
217 bounds.set_height(0); 222 bounds.set_height(0);
218 } else { 223 } else {
219 bounds.set_width(current_width); 224 bounds.set_width(current_width);
220 bounds.set_height(overflow_panel->IconOnlySize().height()); 225 bounds.set_height(overflow_panel->IconOnlySize().height());
221 } 226 }
222 227
223 overflow_panel->SetPanelBoundsInstantly(bounds); 228 overflow_panel->SetPanelBoundsInstantly(bounds);
224 } 229 }
225 } 230 }
226 231
227 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { 232 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) {
228 for (size_t i = 0; i < panels_.size(); ++i) 233 for (size_t i = 0; i < panels_.size(); ++i)
229 panels_[i]->FullScreenModeChanged(is_full_screen); 234 panels_[i]->FullScreenModeChanged(is_full_screen);
230 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698