Chromium Code Reviews| 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" |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); | 94 DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void PanelOverflowStrip::Refresh() { | 97 void PanelOverflowStrip::Refresh() { |
| 99 if (panels_.empty()) | 98 if (panels_.empty()) |
| 100 return; | 99 return; |
| 101 DoRefresh(0, panels_.size() - 1); | 100 DoRefresh(0, panels_.size() - 1); |
| 102 } | 101 } |
| 103 | 102 |
| 104 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { | 103 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { |
| 105 if (panels_.empty() || start_index == panels_.size()) | 104 if (panels_.empty() || start_index == panels_.size()) |
|
jennb
2011/12/08 23:52:00
Why do we need these extra checks? The condition i
jianli
2011/12/09 22:39:07
We need this because when last is being removed, s
| |
| 106 return; | 105 return; |
| 107 | 106 |
| 108 DCHECK(start_index < panels_.size()); | |
| 109 DCHECK(end_index < panels_.size()); | 107 DCHECK(end_index < panels_.size()); |
| 110 | 108 |
| 111 for (size_t index = start_index; index <= end_index; ++index) { | 109 for (size_t index = start_index; index <= end_index; ++index) { |
| 112 Panel* panel = panels_[index]; | 110 Panel* panel = panels_[index]; |
| 113 gfx::Rect new_bounds = ComputeLayout(index, | 111 gfx::Rect new_bounds = ComputeLayout(index, |
| 114 panel->IconOnlySize()); | 112 panel->IconOnlySize()); |
| 115 panel->SetPanelBounds(new_bounds); | 113 panel->SetPanelBounds(new_bounds); |
| 116 } | 114 } |
| 117 } | 115 } |
| 118 | 116 |
| 119 gfx::Rect PanelOverflowStrip::ComputeLayout( | 117 gfx::Rect PanelOverflowStrip::ComputeLayout( |
| 120 size_t index, const gfx::Size& iconified_size) const { | 118 size_t index, const gfx::Size& iconified_size) const { |
| 121 DCHECK(index != kInvalidPanelIndex); | 119 DCHECK(index != kInvalidPanelIndex); |
| 122 | 120 |
| 123 gfx::Rect bounds; | 121 gfx::Rect bounds; |
| 124 int bottom = (index == 0) ? display_area_.bottom() : | 122 int bottom = (index == 0) ? display_area_.bottom() : |
| 125 panels_[index - 1]->GetBounds().y(); | 123 panels_[index - 1]->GetBounds().y(); |
| 126 bounds.set_x(display_area_.x()); | 124 bounds.set_x(display_area_.x()); |
| 127 bounds.set_y(bottom - iconified_size.height()); | 125 bounds.set_y(bottom - iconified_size.height()); |
| 128 | 126 |
| 129 if (are_overflow_titles_shown_) { | 127 if (are_overflow_titles_shown_) { |
| 130 // Both icon and title are visible when the mouse hovers over the overflow | 128 // Both icon and title are visible when the mouse hovers over the overflow |
| 131 // area. | 129 // area. |
| 132 bounds.set_width(kOverflowAreaHoverWidth); | 130 bounds.set_width(kOverflowAreaHoverWidth); |
| 133 bounds.set_height(iconified_size.height()); | 131 bounds.set_height(iconified_size.height()); |
| 134 } else if (index < kMaxVisibleOverflowPanelsAllowed) { | 132 } else if (static_cast<int>(index) < max_visible_panels_) { |
| 135 // Only the icon is visible. | 133 // Only the icon is visible. |
| 136 bounds.set_width(iconified_size.width()); | 134 bounds.set_width(iconified_size.width()); |
| 137 bounds.set_height(iconified_size.height()); | 135 bounds.set_height(iconified_size.height()); |
| 138 } else { | 136 } else { |
| 139 // Invisible for overflow-on-overflow. | 137 // Invisible for overflow-on-overflow. |
| 140 bounds.set_width(0); | 138 bounds.set_width(0); |
| 141 bounds.set_height(0); | 139 bounds.set_height(0); |
| 142 } | 140 } |
| 143 | 141 |
| 144 return bounds; | 142 return bounds; |
| 145 } | 143 } |
| 146 | 144 |
| 147 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { | 145 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { |
| 148 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); | 146 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); |
| 149 ShowOverflowTitles(show_overflow_titles); | 147 ShowOverflowTitles(show_overflow_titles); |
| 150 } | 148 } |
| 151 | 149 |
| 152 bool PanelOverflowStrip::ShouldShowOverflowTitles( | 150 bool PanelOverflowStrip::ShouldShowOverflowTitles( |
| 153 const gfx::Point& mouse_position) const { | 151 const gfx::Point& mouse_position) const { |
| 154 if (panels_.empty()) | 152 if (panels_.empty()) |
| 155 return false; | 153 return false; |
| 156 | 154 |
| 157 int width; | 155 int width; |
| 158 Panel* top_visible_panel; | 156 Panel* top_visible_panel; |
| 159 if (are_overflow_titles_shown_) { | 157 if (are_overflow_titles_shown_) { |
| 160 width = kOverflowAreaHoverWidth; | 158 width = kOverflowAreaHoverWidth; |
| 161 top_visible_panel = panels_.back(); | 159 top_visible_panel = panels_.back(); |
| 162 } else { | 160 } else { |
| 163 width = display_area_.width(); | 161 width = display_area_.width(); |
| 164 top_visible_panel = panels_.size() >= kMaxVisibleOverflowPanelsAllowed ? | 162 top_visible_panel = num_panels() >= max_visible_panels_ ? |
|
jennb
2011/12/08 23:52:00
Why switch to num_panels()? Elsewhere in file, pan
jianli
2011/12/09 22:39:07
To avoid writing sth like "static_cast<int>(panels
| |
| 165 panels_[kMaxVisibleOverflowPanelsAllowed - 1] : panels_.back(); | 163 panels_[max_visible_panels_ - 1] : panels_.back(); |
| 166 } | 164 } |
| 167 return mouse_position.x() <= display_area_.x() + width && | 165 return mouse_position.x() <= display_area_.x() + width && |
| 168 top_visible_panel->GetBounds().y() <= mouse_position.y() && | 166 top_visible_panel->GetBounds().y() <= mouse_position.y() && |
| 169 mouse_position.y() <= display_area_.bottom(); | 167 mouse_position.y() <= display_area_.bottom(); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { | 170 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { |
| 173 if (show_overflow_titles == are_overflow_titles_shown_) | 171 if (show_overflow_titles == are_overflow_titles_shown_) |
| 174 return; | 172 return; |
| 175 are_overflow_titles_shown_ = show_overflow_titles; | 173 are_overflow_titles_shown_ = show_overflow_titles; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 194 | 192 |
| 195 if (!overflow_hover_animator_.get()) | 193 if (!overflow_hover_animator_.get()) |
| 196 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); | 194 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); |
| 197 if (overflow_hover_animator_->IsShowing()) | 195 if (overflow_hover_animator_->IsShowing()) |
| 198 overflow_hover_animator_->Reset(); | 196 overflow_hover_animator_->Reset(); |
| 199 overflow_hover_animator_->SetSlideDuration(kOverflowHoverAnimationMs); | 197 overflow_hover_animator_->SetSlideDuration(kOverflowHoverAnimationMs); |
| 200 | 198 |
| 201 overflow_hover_animator_->Show(); | 199 overflow_hover_animator_->Show(); |
| 202 } | 200 } |
| 203 | 201 |
| 202 void PanelOverflowStrip::AnimationEnded(const ui::Animation* animation) { | |
| 203 content::NotificationService::current()->Notify( | |
| 204 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | |
| 205 content::Source<PanelOverflowStrip>(this), | |
| 206 content::NotificationService::NoDetails()); | |
| 207 } | |
| 208 | |
| 204 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { | 209 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { |
| 205 int current_width = overflow_hover_animator_->CurrentValueBetween( | 210 int current_width = overflow_hover_animator_->CurrentValueBetween( |
| 206 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); | 211 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); |
| 207 bool end_of_shrinking = current_width == display_area_.width(); | 212 bool end_of_shrinking = current_width == display_area_.width(); |
| 208 | 213 |
| 209 // Update each overflow panel. | 214 // Update each overflow panel. |
| 210 for (size_t i = 0; i < panels_.size(); ++i) { | 215 for (size_t i = 0; i < panels_.size(); ++i) { |
| 211 Panel* overflow_panel = panels_[i]; | 216 Panel* overflow_panel = panels_[i]; |
| 212 gfx::Rect bounds = overflow_panel->GetBounds(); | 217 gfx::Rect bounds = overflow_panel->GetBounds(); |
| 213 | 218 |
| 214 if (i >= kMaxVisibleOverflowPanelsAllowed && end_of_shrinking) { | 219 if (static_cast<int>(i) >= max_visible_panels_ && end_of_shrinking) { |
| 215 bounds.set_width(0); | 220 bounds.set_width(0); |
| 216 bounds.set_height(0); | 221 bounds.set_height(0); |
| 217 } else { | 222 } else { |
| 218 bounds.set_width(current_width); | 223 bounds.set_width(current_width); |
| 219 bounds.set_height(overflow_panel->IconOnlySize().height()); | 224 bounds.set_height(overflow_panel->IconOnlySize().height()); |
| 220 } | 225 } |
| 221 | 226 |
| 222 overflow_panel->SetPanelBoundsInstantly(bounds); | 227 overflow_panel->SetPanelBoundsInstantly(bounds); |
| 223 } | 228 } |
| 224 } | 229 } |
| 225 | 230 |
| 226 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { | 231 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { |
| 227 for (size_t i = 0; i < panels_.size(); ++i) | 232 for (size_t i = 0; i < panels_.size(); ++i) |
| 228 panels_[i]->FullScreenModeChanged(is_full_screen); | 233 panels_[i]->FullScreenModeChanged(is_full_screen); |
| 229 } | 234 } |
| OLD | NEW |