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_INFOBAR_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_INFOBAR_DELEGATE_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "skia/include/SkBitmap.h" |
| 10 |
| 11 class AlertInfoBarDelegate; |
| 12 class ConfirmInfoBarDelegate; |
| 13 class InfoBar; |
| 14 |
| 15 // An interface implemented by objects wishing to control an InfoBar. |
| 16 // Implementing this interface is not sufficient to use an InfoBar, since it |
| 17 // does not map to a specific InfoBar type. Instead, you must implement either |
| 18 // AlertInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own |
| 19 // delegate for your own InfoBar variety. |
| 20 class InfoBarDelegate { |
| 21 public: |
| 22 // Returns true if the supplied |delegate| is equal to this one. Equality is |
| 23 // left to the implementation to define. This function is called by the |
| 24 // TabContents when determining whether or not a delegate should be added |
| 25 // because a matching one already exists. If this function returns true, the |
| 26 // TabContents will not add the new delegate because it considers one to |
| 27 // already be present. |
| 28 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const { |
| 29 return false; |
| 30 } |
| 31 |
| 32 // Returns true if the InfoBar should be closed automatically after the page |
| 33 // is navigated. |
| 34 virtual bool ShouldCloseOnNavigate() const { return true; } |
| 35 |
| 36 // Called after the InfoBar is closed. The delegate is free to delete itself |
| 37 // at this point. |
| 38 virtual void InfoBarClosed() {} |
| 39 |
| 40 // Called to create the InfoBar. Implementation of this method is |
| 41 // platform-specific. |
| 42 virtual InfoBar* CreateInfoBar() = 0; |
| 43 |
| 44 // Returns a pointer to the ConfirmInfoBarDelegate interface, if implemented. |
| 45 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate() { |
| 46 return NULL; |
| 47 } |
| 48 |
| 49 // Returns a pointer to the ConfirmInfoBarDelegate interface, if implemented. |
| 50 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() { |
| 51 return NULL; |
| 52 } |
| 53 }; |
| 54 |
| 55 // An interface derived from InfoBarDelegate implemented by objects wishing to |
| 56 // control an AlertInfoBar. |
| 57 class AlertInfoBarDelegate : public InfoBarDelegate { |
| 58 public: |
| 59 // Returns the message string to be displayed for the InfoBar. |
| 60 virtual std::wstring GetMessageText() const = 0; |
| 61 |
| 62 // Return the icon to be shown for this InfoBar. If the returned bitmap is |
| 63 // NULL, no icon is shown. |
| 64 virtual SkBitmap* GetIcon() const { return NULL; } |
| 65 |
| 66 // Overridden from InfoBarDelegate: |
| 67 virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; |
| 68 virtual InfoBar* CreateInfoBar(); |
| 69 virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate() { return this; } |
| 70 }; |
| 71 |
| 72 // An interface derived from InfoBarDelegate implemented by objects wishing to |
| 73 // control a ConfirmInfoBar. |
| 74 class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { |
| 75 public: |
| 76 enum InfoBarButton { |
| 77 BUTTON_NONE = 0, |
| 78 BUTTON_OK, |
| 79 BUTTON_CANCEL |
| 80 }; |
| 81 |
| 82 // Return the buttons to be shown for this InfoBar. |
| 83 virtual int GetButtons() const { |
| 84 return BUTTON_NONE; |
| 85 } |
| 86 |
| 87 // Return the label for the specified button. The default implementation |
| 88 // returns "OK" for the OK button and "Cancel" for the Cancel button. |
| 89 virtual std::wstring GetButtonLabel(InfoBarButton button) const; |
| 90 |
| 91 // Called when the OK button is pressed. |
| 92 virtual void Accept() {} |
| 93 |
| 94 // Called when the Cancel button is pressed. |
| 95 virtual void Cancel() {} |
| 96 |
| 97 // Overridden from InfoBarDelegate: |
| 98 virtual InfoBar* CreateInfoBar(); |
| 99 virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() { |
| 100 return this; |
| 101 } |
| 102 }; |
| 103 |
| 104 // Simple implementations for common use cases --------------------------------- |
| 105 |
| 106 class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate { |
| 107 public: |
| 108 SimpleAlertInfoBarDelegate(const std::wstring& message, SkBitmap* icon); |
| 109 |
| 110 // Overridden from AlertInfoBarDelegate: |
| 111 virtual std::wstring GetMessageText() const; |
| 112 virtual SkBitmap* GetIcon() const; |
| 113 virtual void InfoBarClosed(); |
| 114 |
| 115 private: |
| 116 std::wstring message_; |
| 117 SkBitmap* icon_; |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(SimpleAlertInfoBarDelegate); |
| 120 }; |
| 121 |
| 122 #endif // #ifndef CHROME_BROWSER_INFOBAR_DELEGATE_H_ |
OLD | NEW |