| 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. | 16 // The width of the overflow area that is expanded to show more info, i.e. |
| 15 // titles, when the mouse hovers over the area. | 17 // titles, when the mouse hovers over the area. |
| 16 const int kOverflowAreaHoverWidth = 200; | 18 static const int kOverflowAreaHoverWidth = 200; |
| 17 | 19 |
| 18 // Maximium number of overflow panels allowed to be shown. | 20 // Maximium number of overflow panels allowed to be shown. |
| 19 const size_t kMaxVisibleOverflowPanelsAllowed = 6; | 21 const size_t kMaxVisibleOverflowPanelsAllowed = 6; |
| 20 | 22 |
| 21 // This value is experimental and subjective. | 23 // This value is experimental and subjective. |
| 22 const int kOverflowHoverAnimationMs = 180; | 24 const int kOverflowHoverAnimationMs = 180; |
| 23 } | 25 } |
| 24 | 26 |
| 25 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager) | 27 PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager) |
| 26 : panel_manager_(panel_manager), | 28 : panel_manager_(panel_manager), |
| 29 current_display_width_(0), |
| 30 max_visible_panels_(kMaxVisibleOverflowPanelsAllowed), |
| 27 are_overflow_titles_shown_(false), | 31 are_overflow_titles_shown_(false), |
| 28 overflow_hover_animator_start_width_(0), | 32 overflow_hover_animator_start_width_(0), |
| 29 overflow_hover_animator_end_width_(0) { | 33 overflow_hover_animator_end_width_(0) { |
| 30 } | 34 } |
| 31 | 35 |
| 32 PanelOverflowStrip::~PanelOverflowStrip() { | 36 PanelOverflowStrip::~PanelOverflowStrip() { |
| 33 DCHECK(panels_.empty()); | 37 DCHECK(panels_.empty()); |
| 34 } | 38 } |
| 35 | 39 |
| 36 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { | 40 void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) { |
| 37 if (display_area_ == display_area) | 41 if (display_area_ == display_area) |
| 38 return; | 42 return; |
| 39 | 43 |
| 40 display_area_ = display_area; | 44 display_area_ = display_area; |
| 45 UpdateCurrentWidth(); |
| 46 |
| 41 Refresh(); | 47 Refresh(); |
| 42 } | 48 } |
| 43 | 49 |
| 50 void PanelOverflowStrip::UpdateCurrentWidth() { |
| 51 current_display_width_ = are_overflow_titles_shown_ ? kOverflowAreaHoverWidth |
| 52 : display_area_.width(); |
| 53 } |
| 54 |
| 44 void PanelOverflowStrip::AddPanel(Panel* panel) { | 55 void PanelOverflowStrip::AddPanel(Panel* panel) { |
| 45 // TODO(jianli): consider using other container to improve the perf for | 56 // TODO(jianli): consider using other container to improve the perf for |
| 46 // inserting to the front. http://crbug.com/106222 | 57 // inserting to the front. http://crbug.com/106222 |
| 47 DCHECK_EQ(Panel::IN_OVERFLOW, panel->expansion_state()); | 58 DCHECK_EQ(Panel::IN_OVERFLOW, panel->expansion_state()); |
| 48 // Newly created panels that were temporarily in the panel strip | 59 // Newly created panels that were temporarily in the panel strip |
| 49 // 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 |
| 50 // 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 |
| 51 // of overflow. | 62 // of overflow. |
| 52 if (panel->has_temporary_layout()) { | 63 if (panel->has_temporary_layout()) { |
| 53 panel->set_has_temporary_layout(false); | 64 panel->set_has_temporary_layout(false); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void PanelOverflowStrip::Refresh() { | 110 void PanelOverflowStrip::Refresh() { |
| 100 if (panels_.empty()) | 111 if (panels_.empty()) |
| 101 return; | 112 return; |
| 102 DoRefresh(0, panels_.size() - 1); | 113 DoRefresh(0, panels_.size() - 1); |
| 103 } | 114 } |
| 104 | 115 |
| 105 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { | 116 void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) { |
| 106 if (panels_.empty() || start_index == panels_.size()) | 117 if (panels_.empty() || start_index == panels_.size()) |
| 107 return; | 118 return; |
| 108 | 119 |
| 109 DCHECK(start_index < panels_.size()); | |
| 110 DCHECK(end_index < panels_.size()); | 120 DCHECK(end_index < panels_.size()); |
| 111 | 121 |
| 112 for (size_t index = start_index; index <= end_index; ++index) { | 122 for (size_t index = start_index; index <= end_index; ++index) { |
| 113 Panel* panel = panels_[index]; | 123 Panel* panel = panels_[index]; |
| 114 gfx::Rect new_bounds = ComputeLayout(index, | 124 gfx::Rect new_bounds = ComputeLayout(index, |
| 115 panel->IconOnlySize()); | 125 panel->IconOnlySize()); |
| 116 panel->SetPanelBounds(new_bounds); | 126 panel->SetPanelBounds(new_bounds); |
| 117 } | 127 } |
| 118 } | 128 } |
| 119 | 129 |
| 120 gfx::Rect PanelOverflowStrip::ComputeLayout( | 130 gfx::Rect PanelOverflowStrip::ComputeLayout( |
| 121 size_t index, const gfx::Size& iconified_size) const { | 131 size_t index, const gfx::Size& iconified_size) const { |
| 122 DCHECK(index != kInvalidPanelIndex); | 132 DCHECK(index != kInvalidPanelIndex); |
| 123 | 133 |
| 124 gfx::Rect bounds; | 134 gfx::Rect bounds; |
| 125 int bottom = (index == 0) ? display_area_.bottom() : | 135 int bottom = (index == 0) ? display_area_.bottom() : |
| 126 panels_[index - 1]->GetBounds().y(); | 136 panels_[index - 1]->GetBounds().y(); |
| 127 bounds.set_x(display_area_.x()); | 137 bounds.set_x(display_area_.x()); |
| 128 bounds.set_y(bottom - iconified_size.height()); | 138 bounds.set_y(bottom - iconified_size.height()); |
| 129 | 139 |
| 130 if (are_overflow_titles_shown_) { | 140 if (are_overflow_titles_shown_ || |
| 131 // Both icon and title are visible when the mouse hovers over the overflow | 141 static_cast<int>(index) < max_visible_panels_) { |
| 132 // area. | 142 bounds.set_width(current_display_width_); |
| 133 bounds.set_width(kOverflowAreaHoverWidth); | |
| 134 bounds.set_height(iconified_size.height()); | |
| 135 } else if (index < kMaxVisibleOverflowPanelsAllowed) { | |
| 136 // Only the icon is visible. | |
| 137 bounds.set_width(iconified_size.width()); | |
| 138 bounds.set_height(iconified_size.height()); | 143 bounds.set_height(iconified_size.height()); |
| 139 } else { | 144 } else { |
| 140 // Invisible for overflow-on-overflow. | 145 // Invisible for overflow-on-overflow. |
| 141 bounds.set_width(0); | 146 bounds.set_width(0); |
| 142 bounds.set_height(0); | 147 bounds.set_height(0); |
| 143 } | 148 } |
| 144 | 149 |
| 145 return bounds; | 150 return bounds; |
| 146 } | 151 } |
| 147 | 152 |
| 148 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { | 153 void PanelOverflowStrip::OnMouseMove(const gfx::Point& mouse_position) { |
| 149 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); | 154 bool show_overflow_titles = ShouldShowOverflowTitles(mouse_position); |
| 150 ShowOverflowTitles(show_overflow_titles); | 155 ShowOverflowTitles(show_overflow_titles); |
| 151 } | 156 } |
| 152 | 157 |
| 153 bool PanelOverflowStrip::ShouldShowOverflowTitles( | 158 bool PanelOverflowStrip::ShouldShowOverflowTitles( |
| 154 const gfx::Point& mouse_position) const { | 159 const gfx::Point& mouse_position) const { |
| 155 if (panels_.empty()) | 160 if (panels_.empty()) |
| 156 return false; | 161 return false; |
| 157 | 162 |
| 158 int width; | |
| 159 Panel* top_visible_panel; | 163 Panel* top_visible_panel; |
| 160 if (are_overflow_titles_shown_) { | 164 if (are_overflow_titles_shown_) { |
| 161 width = kOverflowAreaHoverWidth; | |
| 162 top_visible_panel = panels_.back(); | 165 top_visible_panel = panels_.back(); |
| 163 } else { | 166 } else { |
| 164 width = display_area_.width(); | 167 top_visible_panel = num_panels() >= max_visible_panels_ ? |
| 165 top_visible_panel = panels_.size() >= kMaxVisibleOverflowPanelsAllowed ? | 168 panels_[max_visible_panels_ - 1] : panels_.back(); |
| 166 panels_[kMaxVisibleOverflowPanelsAllowed - 1] : panels_.back(); | |
| 167 } | 169 } |
| 168 return mouse_position.x() <= display_area_.x() + width && | 170 return mouse_position.x() <= display_area_.x() + current_display_width_ && |
| 169 top_visible_panel->GetBounds().y() <= mouse_position.y() && | 171 top_visible_panel->GetBounds().y() <= mouse_position.y() && |
| 170 mouse_position.y() <= display_area_.bottom(); | 172 mouse_position.y() <= display_area_.bottom(); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { | 175 void PanelOverflowStrip::ShowOverflowTitles(bool show_overflow_titles) { |
| 174 if (show_overflow_titles == are_overflow_titles_shown_) | 176 if (show_overflow_titles == are_overflow_titles_shown_) |
| 175 return; | 177 return; |
| 176 are_overflow_titles_shown_ = show_overflow_titles; | 178 are_overflow_titles_shown_ = show_overflow_titles; |
| 177 | 179 |
| 180 UpdateCurrentWidth(); |
| 181 |
| 178 if (panels_.empty()) | 182 if (panels_.empty()) |
| 179 return; | 183 return; |
| 180 | 184 |
| 181 if (show_overflow_titles) { | 185 if (show_overflow_titles) { |
| 182 overflow_hover_animator_start_width_ = display_area_.width(); | 186 overflow_hover_animator_start_width_ = current_display_width_; |
| 183 overflow_hover_animator_end_width_ = kOverflowAreaHoverWidth; | 187 overflow_hover_animator_end_width_ = kOverflowAreaHoverWidth; |
| 184 | 188 |
| 185 // We need to bring all overflow panels to the top of z-order since the | 189 // We need to bring all overflow panels to the top of z-order since the |
| 186 // active panel might obscure the expanded overflow panels. | 190 // active panel might obscure the expanded overflow panels. |
| 187 for (Panels::iterator iter = panels_.begin(); | 191 for (Panels::iterator iter = panels_.begin(); |
| 188 iter != panels_.end(); ++iter) { | 192 iter != panels_.end(); ++iter) { |
| 189 (*iter)->EnsureFullyVisible(); | 193 (*iter)->EnsureFullyVisible(); |
| 190 } | 194 } |
| 191 } else { | 195 } else { |
| 192 overflow_hover_animator_start_width_ = kOverflowAreaHoverWidth; | 196 overflow_hover_animator_start_width_ = current_display_width_; |
| 193 overflow_hover_animator_end_width_ = display_area_.width(); | 197 overflow_hover_animator_end_width_ = display_area_.width(); |
| 194 } | 198 } |
| 195 | 199 |
| 196 if (!overflow_hover_animator_.get()) | 200 if (!overflow_hover_animator_.get()) |
| 197 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); | 201 overflow_hover_animator_.reset(new ui::SlideAnimation(this)); |
| 198 if (overflow_hover_animator_->IsShowing()) | 202 if (overflow_hover_animator_->IsShowing()) |
| 199 overflow_hover_animator_->Reset(); | 203 overflow_hover_animator_->Reset(); |
| 200 overflow_hover_animator_->SetSlideDuration( | 204 overflow_hover_animator_->SetSlideDuration( |
| 201 PanelManager::AdjustTimeInterval(kOverflowHoverAnimationMs)); | 205 PanelManager::AdjustTimeInterval(kOverflowHoverAnimationMs)); |
| 202 | 206 |
| 203 overflow_hover_animator_->Show(); | 207 overflow_hover_animator_->Show(); |
| 204 } | 208 } |
| 205 | 209 |
| 210 void PanelOverflowStrip::AnimationEnded(const ui::Animation* animation) { |
| 211 content::NotificationService::current()->Notify( |
| 212 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 213 content::Source<PanelOverflowStrip>(this), |
| 214 content::NotificationService::NoDetails()); |
| 215 } |
| 216 |
| 206 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { | 217 void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) { |
| 207 int current_width = overflow_hover_animator_->CurrentValueBetween( | 218 int current_display_width = overflow_hover_animator_->CurrentValueBetween( |
| 208 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); | 219 overflow_hover_animator_start_width_, overflow_hover_animator_end_width_); |
| 209 bool end_of_shrinking = current_width == display_area_.width(); | 220 bool end_of_shrinking = current_display_width == display_area_.width(); |
| 210 | 221 |
| 211 // Update each overflow panel. | 222 // Update each overflow panel. |
| 212 for (size_t i = 0; i < panels_.size(); ++i) { | 223 for (size_t i = 0; i < panels_.size(); ++i) { |
| 213 Panel* overflow_panel = panels_[i]; | 224 Panel* overflow_panel = panels_[i]; |
| 214 gfx::Rect bounds = overflow_panel->GetBounds(); | 225 gfx::Rect bounds = overflow_panel->GetBounds(); |
| 215 | 226 |
| 216 if (i >= kMaxVisibleOverflowPanelsAllowed && end_of_shrinking) { | 227 if (static_cast<int>(i) >= max_visible_panels_ && end_of_shrinking) { |
| 217 bounds.set_width(0); | 228 bounds.set_width(0); |
| 218 bounds.set_height(0); | 229 bounds.set_height(0); |
| 219 } else { | 230 } else { |
| 220 bounds.set_width(current_width); | 231 bounds.set_width(current_display_width); |
| 221 bounds.set_height(overflow_panel->IconOnlySize().height()); | 232 bounds.set_height(overflow_panel->IconOnlySize().height()); |
| 222 } | 233 } |
| 223 | 234 |
| 224 overflow_panel->SetPanelBoundsInstantly(bounds); | 235 overflow_panel->SetPanelBoundsInstantly(bounds); |
| 225 } | 236 } |
| 226 } | 237 } |
| 227 | 238 |
| 228 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { | 239 void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) { |
| 229 for (size_t i = 0; i < panels_.size(); ++i) | 240 for (size_t i = 0; i < panels_.size(); ++i) |
| 230 panels_[i]->FullScreenModeChanged(is_full_screen); | 241 panels_[i]->FullScreenModeChanged(is_full_screen); |
| 231 } | 242 } |
| OLD | NEW |