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