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_VIEWS_INFOBARS_INFOBAR_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "ui/base/animation/animation_delegate.h" | 10 #include "ui/base/animation/animation_delegate.h" |
| 11 #include "views/controls/button/button.h" | 11 #include "views/controls/button/button.h" |
| 12 #include "views/focus/focus_manager.h" | 12 #include "views/focus/focus_manager.h" |
| 13 | 13 |
| 14 class InfoBarContainer; | 14 class InfoBarContainer; |
| 15 class InfoBarDelegate; | 15 class InfoBarDelegate; |
| 16 class SkPath; | |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 class SlideAnimation; | 19 class SlideAnimation; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 class ExternalFocusTracker; | 23 class ExternalFocusTracker; |
| 23 class ImageButton; | 24 class ImageButton; |
| 24 class ImageView; | 25 class ImageView; |
| 25 class Label; | 26 class Label; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Makes the infobar hidden. If |animate| is true, the infobar is first | 66 // Makes the infobar hidden. If |animate| is true, the infobar is first |
| 66 // animated to zero size. Once the infobar is hidden, it is removed from its | 67 // animated to zero size. Once the infobar is hidden, it is removed from its |
| 67 // container (triggering its deletion), and its delegate is closed. | 68 // container (triggering its deletion), and its delegate is closed. |
| 68 void Hide(bool animate); | 69 void Hide(bool animate); |
| 69 | 70 |
| 70 // Closes the InfoBar immediately and removes it from its container. Notifies | 71 // Closes the InfoBar immediately and removes it from its container. Notifies |
| 71 // the delegate that it has closed. The InfoBar is deleted after this function | 72 // the delegate that it has closed. The InfoBar is deleted after this function |
| 72 // is called. | 73 // is called. |
| 73 void Close(); | 74 void Close(); |
| 74 | 75 |
| 75 // Paint the arrow on |canvas|. |arrow_center_x| indicates the | |
| 76 // desired location of the center of the arrow in the |outer_view| | |
| 77 // coordinate system. | |
| 78 void PaintArrow(gfx::Canvas* canvas, View* outer_view, int arrow_center_x); | |
| 79 | |
| 80 protected: | 76 protected: |
| 81 // The target height of the InfoBar, regardless of what its current height | 77 // The target height of the InfoBar, regardless of what its current height |
| 82 // is (due to animation). | 78 // is (due to animation). |
| 83 static const int kDefaultTargetHeight; | 79 static const int kDefaultTargetHeight; |
| 84 static const int kButtonButtonSpacing; | 80 static const int kButtonButtonSpacing; |
| 85 static const int kEndOfLabelSpacing; | 81 static const int kEndOfLabelSpacing; |
| 86 | 82 |
| 87 virtual ~InfoBarView(); | 83 virtual ~InfoBarView(); |
| 88 | 84 |
| 89 // Creates a label with the appropriate font and color for an infobar. | 85 // Creates a label with the appropriate font and color for an infobar. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // and the close button) can be shrunk to. This is used to prevent the close | 117 // and the close button) can be shrunk to. This is used to prevent the close |
| 122 // button from overlapping views that cannot be shrunk any further. | 118 // button from overlapping views that cannot be shrunk any further. |
| 123 virtual int ContentMinimumWidth() const; | 119 virtual int ContentMinimumWidth() const; |
| 124 | 120 |
| 125 // Removes our associated InfoBarDelegate from the associated TabContents. | 121 // Removes our associated InfoBarDelegate from the associated TabContents. |
| 126 // (Will lead to this InfoBar being closed). | 122 // (Will lead to this InfoBar being closed). |
| 127 void RemoveInfoBar() const; | 123 void RemoveInfoBar() const; |
| 128 | 124 |
| 129 void set_target_height(int height) { target_height_ = height; } | 125 void set_target_height(int height) { target_height_ = height; } |
| 130 | 126 |
| 131 ui::SlideAnimation* animation() { return animation_.get(); } | 127 // To allow different animations, proxy needed routines for |
|
Peter Kasting
2011/03/04 22:23:42
Based on my chat with Ben and you, let's just do a
Sheridan Rawlins
2011/03/05 18:06:54
Done.
| |
| 128 // subclasses, rather than exposing the |animation_| object. | |
| 129 void AnimationReset(double value = 0.0); | |
| 130 void AnimationShow(); | |
| 131 void AnimationHide(); | |
| 132 void AnimationStop(); | |
| 132 | 133 |
| 133 // These return x coordinates delimiting the usable area for subclasses to lay | 134 // These return x coordinates delimiting the usable area for subclasses to lay |
| 134 // out their controls. | 135 // out their controls. |
| 135 int StartX() const; | 136 int StartX() const; |
| 136 int EndX() const; | 137 int EndX() const; |
| 137 | 138 |
| 138 // Returns a centered y-position of a control of height specified in | 139 // Returns a centered y-position of a control of height specified in |
| 139 // |prefsize| within the standard InfoBar height. Stable during an animation. | |
| 140 int CenterY(const gfx::Size prefsize) const; | |
| 141 | |
| 142 // Returns a centered y-position of a control of height specified in | |
| 143 // |prefsize| within the standard InfoBar height, adjusted according to the | 140 // |prefsize| within the standard InfoBar height, adjusted according to the |
| 144 // current amount of animation offset the |parent| InfoBar currently has. | 141 // current amount of animation offset the |parent| InfoBar currently has. |
| 145 // Changes during an animation. | 142 // Changes during an animation. |
| 146 int OffsetY(const gfx::Size prefsize) const; | 143 int OffsetY(const gfx::Size prefsize) const; |
| 147 | 144 |
| 148 private: | 145 private: |
| 146 static const int kTabPadding; | |
| 147 static const int kCurveDistance; | |
| 149 static const int kHorizontalPadding; | 148 static const int kHorizontalPadding; |
| 149 static const int kIconWidth; | |
| 150 static const int kTabHeight; | |
| 151 static const int kTabWidth; | |
| 152 | |
| 153 friend class InfoBarBackground; | |
| 154 friend class InfoBarContainer; | |
| 155 | |
| 156 SkPath* fill_path() const { return fill_path_.get(); } | |
|
Peter Kasting
2011/03/04 22:23:42
Nit: Put non-virtual functions below the virtual o
Sheridan Rawlins
2011/03/05 18:06:54
Done.
| |
| 157 SkPath* stroke_path() const { return stroke_path_.get(); } | |
| 158 SkPath* clip_path() const { return clip_path_.get(); } | |
| 159 | |
| 160 // Returns a centered y-position of a control of height specified in | |
| 161 // |prefsize| within the standard InfoBar height. Stable during an animation. | |
| 162 int CenterY(const gfx::Size prefsize) const; | |
| 163 | |
| 164 int preferred_tab_height() const; | |
| 165 int preferred_bar_height() const; | |
| 150 | 166 |
| 151 // views::View: | 167 // views::View: |
| 152 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 168 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 153 virtual gfx::Size GetPreferredSize() OVERRIDE; | 169 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 170 virtual void OnBoundsChanged() OVERRIDE; | |
| 171 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | |
| 154 | 172 |
| 155 // views::FocusChangeListener: | 173 // views::FocusChangeListener: |
| 156 virtual void FocusWillChange(View* focused_before, View* focused_now) | 174 virtual void FocusWillChange(View* focused_before, View* focused_now) |
| 157 OVERRIDE; | 175 OVERRIDE; |
| 158 | 176 |
| 159 // ui::AnimationDelegate: | 177 // ui::AnimationDelegate: |
| 160 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 178 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 161 | 179 |
| 162 // Destroys the external focus tracker, if present. If |restore_focus| is | 180 // Destroys the external focus tracker, if present. If |restore_focus| is |
| 163 // true, restores focus to the view tracked by the focus tracker before doing | 181 // true, restores focus to the view tracked by the focus tracker before doing |
| 164 // so. | 182 // so. |
| 165 void DestroyFocusTracker(bool restore_focus); | 183 void DestroyFocusTracker(bool restore_focus); |
| 166 | 184 |
| 167 // Deletes this object (called after a return to the message loop to allow | 185 // Deletes this object (called after a return to the message loop to allow |
| 168 // the stack in ViewHierarchyChanged to unwind). | 186 // the stack in ViewHierarchyChanged to unwind). |
| 169 void DeleteSelf(); | 187 void DeleteSelf(); |
| 170 | 188 |
| 171 // The InfoBar's container | 189 // The InfoBar's container |
| 172 InfoBarContainer* container_; | 190 InfoBarContainer* container_; |
| 173 | 191 |
| 174 // The InfoBar's delegate. | 192 // The InfoBar's delegate. |
| 175 InfoBarDelegate* delegate_; | 193 InfoBarDelegate* delegate_; |
| 176 | 194 |
| 177 // The optional icon at the left edge of the InfoBar. | 195 // The optional icon at the left edge of the InfoBar. |
| 178 views::ImageView* icon_; | 196 views::ImageView* icon_; |
| 179 | 197 |
| 180 // The close button at the right edge of the InfoBar. | 198 // The close button at the right edge of the InfoBar. |
| 181 views::ImageButton* close_button_; | 199 views::ImageButton* close_button_; |
| 182 | 200 |
| 183 // The animation that runs when the InfoBar is opened or closed. | 201 // The animations that run when the InfoBar is opened or closed. |
| 184 scoped_ptr<ui::SlideAnimation> animation_; | 202 scoped_ptr<ui::SlideAnimation> tab_animation_; |
| 203 scoped_ptr<ui::SlideAnimation> bar_animation_; | |
| 185 | 204 |
| 186 // Tracks and stores the last focused view which is not the InfoBar or any of | 205 // Tracks and stores the last focused view which is not the InfoBar or any of |
| 187 // its children. Used to restore focus once the InfoBar is closed. | 206 // its children. Used to restore focus once the InfoBar is closed. |
| 188 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; | 207 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; |
| 189 | 208 |
| 190 // Used to delete this object after a return to the message loop. | 209 // Used to delete this object after a return to the message loop. |
| 191 ScopedRunnableMethodFactory<InfoBarView> delete_factory_; | 210 ScopedRunnableMethodFactory<InfoBarView> delete_factory_; |
| 192 | 211 |
| 193 // The target height for the InfoBarView. | 212 // The target height for the bar portion of the InfoBarView. |
|
Peter Kasting
2011/03/04 22:23:42
Nit: Extra space
Sheridan Rawlins
2011/03/05 18:06:54
Done.
| |
| 194 int target_height_; | 213 int target_height_; |
| 195 | 214 |
| 215 // The current stroke path of the InfoBar. | |
|
Peter Kasting
2011/03/04 22:23:42
Nit: These comments add nothing. Just eliminate t
Sheridan Rawlins
2011/03/05 18:06:54
Done.
| |
| 216 scoped_ptr<SkPath> stroke_path_; | |
| 217 | |
| 218 // The current fill path of the InfoBar. | |
| 219 scoped_ptr<SkPath> fill_path_; | |
| 220 | |
| 221 // The current clip path of the InfoBar. | |
| 222 scoped_ptr<SkPath> clip_path_; | |
| 223 | |
| 196 DISALLOW_COPY_AND_ASSIGN(InfoBarView); | 224 DISALLOW_COPY_AND_ASSIGN(InfoBarView); |
| 197 }; | 225 }; |
| 198 | 226 |
| 199 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ | 227 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ |
| OLD | NEW |