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

Unified Diff: chrome/browser/ui/panels/panel_overflow_strip.cc

Issue 8953040: Add overflow indicator count on Windows. (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 side-by-side diff with in-line comments
Download patch
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 8c2a585a5580fceffde887eb2a8c50ae51136ec5..1be110a519f53398f9ebcdaf656d0d3f934a6f82 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.
jennb 2011/12/20 02:08:23 Still using shrunk?
jianli 2011/12/20 22:08:10 Done.
+const size_t kMaxVisibleOverflowPanelsOnShrunk = 6;
+
+// Height to display-area ratio that maximium number of visible overflow panels
jennb 2011/12/20 02:08:23 Lumpy sentence. Phrasing it like the comment you w
jianli 2011/12/20 22:08:10 Done.
+// cannot occupy more than when the mouse hovers over the overflow area.
+const double kHeightRatioForMaxVisibleOverflowPanelsOnHover = 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_(kMaxVisibleOverflowPanelsOnShrunk),
+ max_visible_panels_on_hover_(0),
are_overflow_titles_shown_(false),
overflow_hover_animator_start_width_(0),
overflow_hover_animator_end_width_(0) {
+ registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
jennb 2011/12/20 02:08:23 Comment here about why we register for this.
jianli 2011/12/20 22:08:10 Not needed since we do not need observer now.
+ 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;
+
+ UpdateMaxVisibkePanelsOnHover();
UpdateCurrentWidth();
Refresh();
}
+void PanelOverflowStrip::UpdateMaxVisibkePanelsOnHover() {
+ // 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_hover_ = 0;
+ } else if (!max_visible_panels_on_hover_) {
+ max_visible_panels_on_hover_ =
+ kHeightRatioForMaxVisibleOverflowPanelsOnHover *
+ 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();
jennb 2011/12/20 02:08:23 Seems odd to reset the indicator only to recreate
jianli 2011/12/20 22:08:10 Changed to create the overflow indicator on a as-n
+ }
+ UpdateOverflowIndicator(current_display_width_);
return true;
}
}
@@ -108,6 +138,11 @@ void PanelOverflowStrip::OnPanelExpansionStateChanged(
panel->set_draggable(false);
}
+void PanelOverflowStrip::OnPanelAttentionStateChanged(Panel* panel) {
+ DCHECK(panel->expansion_state() == Panel::IN_OVERFLOW);
+ UpdateOverflowIndicator(current_display_width_);
+}
+
void PanelOverflowStrip::Refresh() {
if (panels_.empty())
return;
@@ -128,6 +163,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());
+
+ UpdateMaxVisibkePanelsOnHover();
jennb 2011/12/20 02:08:23 Shouldn't need to recompute this every time a pane
jianli 2011/12/20 22:08:10 Updated. When display area is changed, we might no
+ int max_visible_panels = width > display_area_.width() ?
+ max_visible_panels_on_hover_ : max_visible_panels_;
+
+ // 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;
jennb 2011/12/20 02:08:23 break out of loop as soon as you find one drawing
jianli 2011/12/20 22:08:10 Done.
+ }
+ 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);
@@ -138,8 +209,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 {
@@ -161,13 +231,8 @@ bool PanelOverflowStrip::ShouldShowOverflowTitles(
if (panels_.empty())
return false;
- Panel* top_visible_panel;
- 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();
- }
+ Panel* top_visible_panel = num_panels() >= max_visible_panels() ?
+ panels_[max_visible_panels() - 1] : panels_.back();
return mouse_position.x() <= display_area_.x() + current_display_width_ &&
top_visible_panel->GetBounds().y() <= mouse_position.y() &&
mouse_position.y() <= display_area_.bottom();
@@ -219,13 +284,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_ : max_visible_panels_on_hover_;
// 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 {
@@ -235,6 +302,21 @@ void PanelOverflowStrip::AnimationProgressed(const ui::Animation* animation) {
overflow_panel->SetPanelBoundsInstantly(bounds);
}
+
+ // Update the indicator.
+ UpdateOverflowIndicator(current_display_width);
jennb 2011/12/20 02:08:23 Count won't be changing during animation. Maybe Up
jianli 2011/12/20 22:08:10 Separated the logic as suggested.
+}
+
+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
jennb 2011/12/20 02:08:23 Don't need this if you destroy the indicator when
jianli 2011/12/20 22:08:10 Removed.
+ // 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) {

Powered by Google App Engine
This is Rietveld 408576698