| Index: chrome/browser/ui/panels/panel_overflow_strip.cc
|
| diff --git a/chrome/browser/ui/panels/panel_overflow_strip.cc b/chrome/browser/ui/panels/panel_overflow_strip.cc
|
| index cd0d47a4bf8898ba1bee81a73b6e7c0188c840ce..608228a20fdb11794de9b90f38cd22135b0e134f 100644
|
| --- a/chrome/browser/ui/panels/panel_overflow_strip.cc
|
| +++ b/chrome/browser/ui/panels/panel_overflow_strip.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/logging.h"
|
| #include "chrome/browser/ui/panels/panel_manager.h"
|
| #include "chrome/browser/ui/panels/panel_mouse_watcher.h"
|
| +#include "chrome/browser/ui/panels/panel_overflow_indicator.h"
|
| #include "chrome/browser/ui/panels/panel_strip.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "content/public/browser/notification_service.h"
|
| @@ -17,8 +18,12 @@ namespace {
|
| // titles, when the mouse hovers over the area.
|
| static const int kOverflowAreaHoverWidth = 200;
|
|
|
| -// Maximium number of overflow panels allowed to be shown.
|
| -const size_t kMaxVisibleOverflowPanelsAllowed = 6;
|
| +// Maximium number of visible overflow panels when the overflow area is shrunk.
|
| +const size_t kMaxVisibleOverflowPanelsOnShrunk = 6;
|
| +
|
| +// Height to display-area ratio that maximium number of visible overflow panels
|
| +// cannot occupy more than when the overflow area is expanded.
|
| +const double kHeightRatioForMaxVisibleOverflowPanelsOnExpanded = 0.67;
|
|
|
| // This value is experimental and subjective.
|
| const int kOverflowHoverAnimationMs = 180;
|
| @@ -27,26 +32,46 @@ const int kOverflowHoverAnimationMs = 180;
|
| PanelOverflowStrip::PanelOverflowStrip(PanelManager* panel_manager)
|
| : panel_manager_(panel_manager),
|
| current_display_width_(0),
|
| - max_visible_panels_(kMaxVisibleOverflowPanelsAllowed),
|
| + max_visible_panels_on_shrunk_(kMaxVisibleOverflowPanelsOnShrunk),
|
| + max_visible_panels_on_expanded_(kMaxVisibleOverflowPanelsOnShrunk),
|
| are_overflow_titles_shown_(false),
|
| overflow_hover_animator_start_width_(0),
|
| overflow_hover_animator_end_width_(0) {
|
| + registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
|
| + content::NotificationService::AllSources());
|
| }
|
|
|
| PanelOverflowStrip::~PanelOverflowStrip() {
|
| DCHECK(panels_.empty());
|
| + DCHECK(!overflow_indicator_.get());
|
| }
|
|
|
| void PanelOverflowStrip::SetDisplayArea(const gfx::Rect& display_area) {
|
| if (display_area_ == display_area)
|
| return;
|
| -
|
| display_area_ = display_area;
|
| +
|
| + UpdateMaxVisibkePanelsOnExpanded();
|
| UpdateCurrentWidth();
|
|
|
| Refresh();
|
| }
|
|
|
| +void PanelOverflowStrip::UpdateMaxVisibkePanelsOnExpanded() {
|
| + // The maximum number of visible overflow panels cannot occupy more than
|
| + // certain percentage of the display area height.
|
| + // Note that we need to delay the computation of this value if no overflow
|
| + // panel is added.
|
| + if (panels_.empty()) {
|
| + max_visible_panels_on_expanded_ = 0;
|
| + } else {
|
| + max_visible_panels_on_expanded_ =
|
| + kHeightRatioForMaxVisibleOverflowPanelsOnExpanded *
|
| + display_area_.height() /
|
| + panels_.front()->IconOnlySize().height();
|
| + }
|
| +}
|
| +
|
| void PanelOverflowStrip::UpdateCurrentWidth() {
|
| current_display_width_ = are_overflow_titles_shown_ ? kOverflowAreaHoverWidth
|
| : display_area_.width();
|
| @@ -71,6 +96,8 @@ void PanelOverflowStrip::AddPanel(Panel* panel) {
|
|
|
| if (panels_.size() == 1)
|
| panel_manager_->mouse_watcher()->AddObserver(this);
|
| +
|
| + UpdateOverflowIndicator(current_display_width_);
|
| }
|
|
|
| bool PanelOverflowStrip::Remove(Panel* panel) {
|
| @@ -81,8 +108,11 @@ bool PanelOverflowStrip::Remove(Panel* panel) {
|
| panels_.erase(iter);
|
| DoRefresh(index, panels_.size() - 1);
|
| panel_manager_->OnPanelRemoved(panel);
|
| - if (panels_.empty())
|
| + if (panels_.empty()) {
|
| panel_manager_->mouse_watcher()->RemoveObserver(this);
|
| + overflow_indicator_.reset();
|
| + }
|
| + UpdateOverflowIndicator(current_display_width_);
|
| return true;
|
| }
|
| }
|
| @@ -107,6 +137,11 @@ void PanelOverflowStrip::OnPanelExpansionStateChanged(
|
| panel->SetAppIconVisibility(false);
|
| }
|
|
|
| +void PanelOverflowStrip::OnPanelAttentionStateChanged(Panel* panel) {
|
| + DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW);
|
| + UpdateOverflowIndicator(current_display_width_);
|
| +}
|
| +
|
| void PanelOverflowStrip::Refresh() {
|
| if (panels_.empty())
|
| return;
|
| @@ -127,6 +162,42 @@ void PanelOverflowStrip::DoRefresh(size_t start_index, size_t end_index) {
|
| }
|
| }
|
|
|
| +void PanelOverflowStrip::UpdateOverflowIndicator(int width) {
|
| + if (!overflow_indicator_.get())
|
| + overflow_indicator_.reset(PanelOverflowIndicator::Create());
|
| +
|
| + UpdateMaxVisibkePanelsOnExpanded();
|
| + int max_visible_panels = width > display_area_.width() ?
|
| + max_visible_panels_on_expanded_ : max_visible_panels_on_shrunk_;
|
| +
|
| + // Setting the count to 0 will hide the indicator.
|
| + if (num_panels() <= max_visible_panels) {
|
| + overflow_indicator_->SetCount(0);
|
| + return;
|
| + }
|
| +
|
| + // Update the bounds and count.
|
| + int height = overflow_indicator_->GetHeight();
|
| + overflow_indicator_->SetBounds(gfx::Rect(
|
| + display_area_.x(),
|
| + panels_[max_visible_panels - 1]->GetBounds().y() - height,
|
| + width,
|
| + height));
|
| + overflow_indicator_->SetCount(num_panels() - max_visible_panels);
|
| +
|
| + // The overflow indicator is painted as drawing attention only when there is
|
| + // at least one hidden panel that is drawing attention.
|
| + bool is_drawing_attention = false;
|
| + for (int index = max_visible_panels; index < num_panels(); ++index) {
|
| + if (panels_[index]->IsDrawingAttention())
|
| + is_drawing_attention = true;
|
| + }
|
| + if (is_drawing_attention)
|
| + overflow_indicator_->DrawAttention();
|
| + else
|
| + overflow_indicator_->StopDrawingAttention();
|
| +}
|
| +
|
| gfx::Rect PanelOverflowStrip::ComputeLayout(
|
| size_t index, const gfx::Size& iconified_size) const {
|
| DCHECK(index != kInvalidPanelIndex);
|
| @@ -137,8 +208,7 @@ gfx::Rect PanelOverflowStrip::ComputeLayout(
|
| bounds.set_x(display_area_.x());
|
| bounds.set_y(bottom - iconified_size.height());
|
|
|
| - if (are_overflow_titles_shown_ ||
|
| - static_cast<int>(index) < max_visible_panels_) {
|
| + if (static_cast<int>(index) < max_visible_panels()) {
|
| bounds.set_width(current_display_width_);
|
| bounds.set_height(iconified_size.height());
|
| } else {
|
| @@ -164,8 +234,8 @@ bool PanelOverflowStrip::ShouldShowOverflowTitles(
|
| if (are_overflow_titles_shown_) {
|
| top_visible_panel = panels_.back();
|
| } else {
|
| - top_visible_panel = num_panels() >= max_visible_panels_ ?
|
| - panels_[max_visible_panels_ - 1] : panels_.back();
|
| + top_visible_panel = num_panels() >= max_visible_panels_on_shrunk_ ?
|
| + panels_[max_visible_panels_on_shrunk_ - 1] : panels_.back();
|
| }
|
| return mouse_position.x() <= display_area_.x() + current_display_width_ &&
|
| top_visible_panel->GetBounds().y() <= mouse_position.y() &&
|
| @@ -218,13 +288,15 @@ void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) {
|
| int current_display_width = overflow_hover_animator_->CurrentValueBetween(
|
| overflow_hover_animator_start_width_, overflow_hover_animator_end_width_);
|
| bool end_of_shrinking = current_display_width == display_area_.width();
|
| + int max_visible_panels = end_of_shrinking ?
|
| + max_visible_panels_on_shrunk_ : max_visible_panels_on_expanded_;
|
|
|
| // Update each overflow panel.
|
| - for (size_t i = 0; i < panels_.size(); ++i) {
|
| + for (int i = 0; i < num_panels(); ++i) {
|
| Panel* overflow_panel = panels_[i];
|
| gfx::Rect bounds = overflow_panel->GetBounds();
|
|
|
| - if (static_cast<int>(i) >= max_visible_panels_ && end_of_shrinking) {
|
| + if (i >= max_visible_panels) {
|
| bounds.set_width(0);
|
| bounds.set_height(0);
|
| } else {
|
| @@ -234,6 +306,21 @@ void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) {
|
|
|
| overflow_panel->SetPanelBoundsInstantly(bounds);
|
| }
|
| +
|
| + // Update the indicator.
|
| + UpdateOverflowIndicator(current_display_width);
|
| +}
|
| +
|
| +void PanelOverflowStrip::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + DCHECK(type == content::NOTIFICATION_APP_TERMINATING);
|
| +
|
| + // The overflow indicator needs to be disposed when the last browser is
|
| + // closed. Our destructor is called too late in the shutdown sequence.
|
| + if (overflow_indicator_.get())
|
| + overflow_indicator_.reset();
|
| }
|
|
|
| void PanelOverflowStrip::OnFullScreenModeChanged(bool is_full_screen) {
|
|
|