OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_ |
| 6 #define CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_ |
| 7 |
| 8 #include "chrome/browser/infobar_delegate.h" |
| 9 #include "chrome/views/base_button.h" |
| 10 #include "chrome/views/native_button.h" |
| 11 |
| 12 class InfoBarContainer; |
| 13 class SlideAnimation; |
| 14 namespace views { |
| 15 class Button; |
| 16 class ImageView; |
| 17 class Label; |
| 18 } |
| 19 |
| 20 // This file contains implementations for some general purpose InfoBars. See |
| 21 // chrome/browser/infobar_delegate.h for the delegate interface(s) that you must |
| 22 // implement to use these. |
| 23 |
| 24 class InfoBar : public views::View, |
| 25 public views::BaseButton::ButtonListener, |
| 26 public AnimationDelegate { |
| 27 public: |
| 28 explicit InfoBar(InfoBarDelegate* delegate); |
| 29 virtual ~InfoBar(); |
| 30 |
| 31 InfoBarDelegate* delegate() const { return delegate_; } |
| 32 |
| 33 void set_container(InfoBarContainer* container) { container_ = container; } |
| 34 |
| 35 // Starts animating the InfoBar open. |
| 36 void AnimateOpen(); |
| 37 |
| 38 // Opens the InfoBar immediately. |
| 39 void Open(); |
| 40 |
| 41 // Starts animating the InfoBar closed. It will not be closed until the |
| 42 // animation has completed, when |Close| will be called. |
| 43 void AnimateClose(); |
| 44 |
| 45 // Closes the InfoBar immediately and removes it from its container. Notifies |
| 46 // the delegate that it has closed. The InfoBar is deleted after this function |
| 47 // is called. |
| 48 void Close(); |
| 49 |
| 50 // Overridden from views::View: |
| 51 virtual gfx::Size GetPreferredSize(); |
| 52 virtual void Layout(); |
| 53 |
| 54 protected: |
| 55 // Returns the available width of the View for use by child view layout, |
| 56 // excluding the close button. |
| 57 virtual int GetAvailableWidth() const; |
| 58 |
| 59 private: |
| 60 // Overridden from views::Button::ButtonListener: |
| 61 virtual void ButtonPressed(views::BaseButton* sender); |
| 62 |
| 63 // Overridden from AnimationDelegate: |
| 64 virtual void AnimationProgressed(const Animation* animation); |
| 65 virtual void AnimationEnded(const Animation* animation); |
| 66 |
| 67 // The InfoBar's container |
| 68 InfoBarContainer* container_; |
| 69 |
| 70 // The InfoBar's delegate. |
| 71 InfoBarDelegate* delegate_; |
| 72 |
| 73 // The Close Button at the right edge of the InfoBar. |
| 74 views::Button* close_button_; |
| 75 |
| 76 // The animation that runs when the InfoBar is opened or closed. |
| 77 scoped_ptr<SlideAnimation> animation_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(InfoBar); |
| 80 }; |
| 81 |
| 82 class AlertInfoBar : public InfoBar { |
| 83 public: |
| 84 explicit AlertInfoBar(AlertInfoBarDelegate* delegate); |
| 85 virtual ~AlertInfoBar(); |
| 86 |
| 87 // Overridden from views::View: |
| 88 virtual void Layout(); |
| 89 |
| 90 protected: |
| 91 views::Label* label() const { return label_; } |
| 92 views::ImageView* icon() const { return icon_; } |
| 93 |
| 94 private: |
| 95 AlertInfoBarDelegate* GetDelegate(); |
| 96 |
| 97 views::Label* label_; |
| 98 views::ImageView* icon_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(AlertInfoBar); |
| 101 }; |
| 102 |
| 103 class ConfirmInfoBar : public AlertInfoBar, |
| 104 public views::NativeButton::Listener { |
| 105 public: |
| 106 explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate); |
| 107 virtual ~ConfirmInfoBar(); |
| 108 |
| 109 // Overridden from views::View: |
| 110 virtual void Layout(); |
| 111 |
| 112 protected: |
| 113 // Overridden from views::View: |
| 114 virtual void ViewHierarchyChanged(bool is_add, |
| 115 views::View* parent, |
| 116 views::View* child); |
| 117 |
| 118 // Overridden from views::NativeButton::Listener: |
| 119 virtual void ButtonPressed(views::NativeButton* sender); |
| 120 |
| 121 // Overridden from InfoBar: |
| 122 virtual int GetAvailableWidth() const; |
| 123 |
| 124 private: |
| 125 void Init(); |
| 126 |
| 127 ConfirmInfoBarDelegate* GetDelegate(); |
| 128 |
| 129 views::NativeButton* ok_button_; |
| 130 views::NativeButton* cancel_button_; |
| 131 |
| 132 bool initialized_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); |
| 135 }; |
| 136 |
| 137 |
| 138 #endif // #ifndef CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_ |
OLD | NEW |