| 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 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
| 11 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" | 11 #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" |
| 12 #include "ui/base/animation/animation_delegate.h" | 12 #include "ui/base/animation/animation_delegate.h" |
| 13 | 13 |
| 14 class Browser; | 14 class Browser; |
| 15 class PanelManager; | 15 class PanelManager; |
| 16 class PanelOverflowIndicator; |
| 16 namespace ui { | 17 namespace ui { |
| 17 class SlideAnimation; | 18 class SlideAnimation; |
| 18 } | 19 } |
| 19 | 20 |
| 20 // Manipulates all the panels that are placed on the left-most overflow area. | 21 // Manipulates all the panels that are placed on the left-most overflow area. |
| 21 class PanelOverflowStrip : public PanelMouseWatcherObserver, | 22 class PanelOverflowStrip : public PanelMouseWatcherObserver, |
| 22 public ui::AnimationDelegate { | 23 public ui::AnimationDelegate { |
| 23 public: | 24 public: |
| 24 typedef std::vector<Panel*> Panels; | 25 typedef std::vector<Panel*> Panels; |
| 25 | 26 |
| 26 explicit PanelOverflowStrip(PanelManager* panel_manager); | 27 explicit PanelOverflowStrip(PanelManager* panel_manager); |
| 27 virtual ~PanelOverflowStrip(); | 28 virtual ~PanelOverflowStrip(); |
| 28 | 29 |
| 29 // Sets the display area of the overflow strip. | 30 // Sets the display area of the overflow strip. |
| 30 // |display_area| is in screen coordinates. | 31 // |display_area| is in screen coordinates. |
| 31 void SetDisplayArea(const gfx::Rect& display_area); | 32 void SetDisplayArea(const gfx::Rect& display_area); |
| 32 | 33 |
| 33 // Adds a panel to the strip. | 34 // Adds a panel to the strip. |
| 34 void AddPanel(Panel* panel); | 35 void AddPanel(Panel* panel); |
| 35 | 36 |
| 36 // Returns |false| if the panel is not in the strip. | 37 // Returns |false| if the panel is not in the strip. |
| 37 bool Remove(Panel* panel); | 38 bool Remove(Panel* panel); |
| 38 void RemoveAll(); | 39 void RemoveAll(); |
| 39 | 40 |
| 40 // Called when a panel's expansion state changes. | 41 // Called when a panel's expansion state changes. |
| 41 void OnPanelExpansionStateChanged( | 42 void OnPanelExpansionStateChanged( |
| 42 Panel* panel, Panel::ExpansionState old_state); | 43 Panel* panel, Panel::ExpansionState old_state); |
| 43 | 44 |
| 45 // Called when a panel is starting/stopping drawing an attention. |
| 46 void OnPanelAttentionStateChanged(Panel* panel); |
| 47 |
| 44 // Refreshes the layouts for all panels to reflect any possible changes. | 48 // Refreshes the layouts for all panels to reflect any possible changes. |
| 45 void Refresh(); | 49 void Refresh(); |
| 46 | 50 |
| 47 void OnFullScreenModeChanged(bool is_full_screen); | 51 void OnFullScreenModeChanged(bool is_full_screen); |
| 48 | 52 |
| 49 int num_panels() const { return static_cast<int>(panels_.size()); } | 53 int num_panels() const { return static_cast<int>(panels_.size()); } |
| 50 Panel* first_panel() const { | 54 Panel* first_panel() const { |
| 51 return panels_.empty() ? NULL : panels_.front(); | 55 return panels_.empty() ? NULL : panels_.front(); |
| 52 } | 56 } |
| 53 const Panels& panels() const { return panels_; } | 57 const Panels& panels() const { return panels_; } |
| 54 | 58 |
| 55 #ifdef UNIT_TEST | 59 #ifdef UNIT_TEST |
| 56 int current_display_width() const { return current_display_width_; } | 60 int current_display_width() const { return current_display_width_; } |
| 57 | 61 |
| 62 // This might return NULL. |
| 63 PanelOverflowIndicator* overflow_indicator() const { |
| 64 return overflow_indicator_.get(); |
| 65 } |
| 66 |
| 58 void set_max_visible_panels(int max_visible_panels) { | 67 void set_max_visible_panels(int max_visible_panels) { |
| 59 max_visible_panels_ = max_visible_panels; | 68 max_visible_panels_ = max_visible_panels; |
| 60 } | 69 } |
| 70 |
| 71 void set_max_visible_panels_on_hover(int max_visible_panels_on_hover) { |
| 72 max_visible_panels_on_hover_ = max_visible_panels_on_hover; |
| 73 } |
| 61 #endif | 74 #endif |
| 62 | 75 |
| 63 private: | 76 private: |
| 64 // Overridden from PanelMouseWatcherObserver: | 77 // Overridden from PanelMouseWatcherObserver: |
| 65 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE; | 78 virtual void OnMouseMove(const gfx::Point& mouse_position) OVERRIDE; |
| 66 | 79 |
| 67 // Overridden from AnimationDelegate: | 80 // Overridden from AnimationDelegate: |
| 68 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 81 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 69 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 82 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 70 | 83 |
| 71 void UpdateCurrentWidth(); | 84 void UpdateCurrentWidth(); |
| 72 | 85 |
| 73 void DoRefresh(size_t start_index, size_t end_index); | 86 void DoRefresh(size_t start_index, size_t end_index); |
| 74 | 87 |
| 88 // Used to update the overflow indicator. |
| 89 void UpdateMaxVisiblePanelsOnHover(); |
| 90 void UpdateOverflowIndicatorCount(); |
| 91 void UpdateOverflowIndicatorAttention(); |
| 92 |
| 75 // Computes the layout of the |index| panel to fit into the area. | 93 // Computes the layout of the |index| panel to fit into the area. |
| 76 // Empty bounds will be returned if this is not possible due to not enough | 94 // Empty bounds will be returned if this is not possible due to not enough |
| 77 // space. | 95 // space. |
| 78 gfx::Rect ComputeLayout(size_t index, | 96 gfx::Rect ComputeLayout(size_t index, |
| 79 const gfx::Size& iconified_size) const; | 97 const gfx::Size& iconified_size) const; |
| 80 | 98 |
| 81 // Used to pop up the titles for overflow panels when the mouse hovers over | 99 // Used to pop up the titles for overflow panels when the mouse hovers over |
| 82 // the overflow area. | 100 // the overflow area. |
| 83 bool ShouldShowOverflowTitles(const gfx::Point& mouse_position) const; | 101 bool ShouldShowOverflowTitles(const gfx::Point& mouse_position) const; |
| 84 void ShowOverflowTitles(bool show_overflow_titles); | 102 void ShowOverflowTitles(bool show_overflow_titles); |
| 85 | 103 |
| 104 int max_visible_panels() const { |
| 105 return are_overflow_titles_shown_ ? max_visible_panels_on_hover_ |
| 106 : max_visible_panels_; |
| 107 } |
| 108 |
| 86 // Weak pointer since PanelManager owns PanelOverflowStrip instance. | 109 // Weak pointer since PanelManager owns PanelOverflowStrip instance. |
| 87 PanelManager* panel_manager_; | 110 PanelManager* panel_manager_; |
| 88 | 111 |
| 89 // The queue for storing all panels. | 112 // The queue for storing all panels. |
| 90 Panels panels_; | 113 Panels panels_; |
| 91 | 114 |
| 92 // The overflow area where panels are iconified due to insufficient space | 115 // The overflow area where panels are iconified due to insufficient space |
| 93 // in the panel strip. | 116 // in the panel strip. |
| 94 gfx::Rect display_area_; | 117 gfx::Rect display_area_; |
| 95 | 118 |
| 96 // Current width of the overflow area. It is the width of the panel in the | 119 // Current width of the overflow area. It is the width of the panel in the |
| 97 // iconified state when the mouse does not hover over it, or the width of | 120 // iconified state when the mouse does not hover over it, or the width of |
| 98 // the panel showing more info when the mouse hovers over it. | 121 // the panel showing more info when the mouse hovers over it. |
| 99 int current_display_width_; | 122 int current_display_width_; |
| 100 | 123 |
| 101 // Maximium number of overflow panels allowed to be shown. | 124 // Maximium number of overflow panels allowed to be shown when the mouse |
| 125 // does not hover over the overflow area. |
| 102 int max_visible_panels_; | 126 int max_visible_panels_; |
| 103 | 127 |
| 128 // Maximium number of overflow panels allowed to be shown when the mouse |
| 129 // hovers over the overflow area and causes it to be expanded. |
| 130 int max_visible_panels_on_hover_; |
| 131 |
| 132 // Used to show "+N" indicator when number of overflow panels exceed |
| 133 // |max_visible_panels_|. |
| 134 scoped_ptr<PanelOverflowIndicator> overflow_indicator_; |
| 135 |
| 104 // For mouse hover-over effect. | 136 // For mouse hover-over effect. |
| 105 bool are_overflow_titles_shown_; | 137 bool are_overflow_titles_shown_; |
| 106 scoped_ptr<ui::SlideAnimation> overflow_hover_animator_; | 138 scoped_ptr<ui::SlideAnimation> overflow_hover_animator_; |
| 107 int overflow_hover_animator_start_width_; | 139 int overflow_hover_animator_start_width_; |
| 108 int overflow_hover_animator_end_width_; | 140 int overflow_hover_animator_end_width_; |
| 109 | 141 |
| 110 // Invalid panel index. | 142 // Invalid panel index. |
| 111 static const size_t kInvalidPanelIndex = static_cast<size_t>(-1); | 143 static const size_t kInvalidPanelIndex = static_cast<size_t>(-1); |
| 112 | 144 |
| 113 DISALLOW_COPY_AND_ASSIGN(PanelOverflowStrip); | 145 DISALLOW_COPY_AND_ASSIGN(PanelOverflowStrip); |
| 114 }; | 146 }; |
| 115 | 147 |
| 116 #endif // CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ | 148 #endif // CHROME_BROWSER_UI_PANELS_PANEL_OVERFLOW_STRIP_H_ |
| OLD | NEW |