confirm_infobar_delegate.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2012 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. #ifndef COMPONENTS_INFOBARS_CORE_CONFIRM_INFOBAR_DELEGATE_H_
  5. #define COMPONENTS_INFOBARS_CORE_CONFIRM_INFOBAR_DELEGATE_H_
  6. #include <string>
  7. #include "build/build_config.h"
  8. #include "components/infobars/core/infobar_delegate.h"
  9. #include "components/infobars/core/infobar_manager.h"
  10. #include "ui/base/models/image_model.h"
  11. #include "ui/gfx/image/image_skia.h"
  12. #include "ui/gfx/text_constants.h"
  13. namespace infobars {
  14. class InfoBar;
  15. }
  16. // An interface derived from InfoBarDelegate implemented by objects wishing to
  17. // control a ConfirmInfoBar.
  18. class ConfirmInfoBarDelegate : public infobars::InfoBarDelegate {
  19. public:
  20. enum InfoBarButton {
  21. BUTTON_NONE = 0,
  22. BUTTON_OK = 1 << 0,
  23. BUTTON_CANCEL = 1 << 1,
  24. };
  25. ConfirmInfoBarDelegate(const ConfirmInfoBarDelegate&) = delete;
  26. ConfirmInfoBarDelegate& operator=(const ConfirmInfoBarDelegate&) = delete;
  27. ~ConfirmInfoBarDelegate() override;
  28. // InfoBarDelegate:
  29. bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override;
  30. ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() override;
  31. // Returns the InfoBar type to be displayed for the InfoBar.
  32. InfoBarAutomationType GetInfoBarAutomationType() const override;
  33. // Returns the title string to be displayed for the InfoBar.
  34. // Defaults to having not title. Currently only used on iOS.
  35. virtual std::u16string GetTitleText() const;
  36. // Returns the message string to be displayed for the InfoBar.
  37. virtual std::u16string GetMessageText() const = 0;
  38. // Returns the elide behavior for the message string.
  39. // Not supported on Android.
  40. virtual gfx::ElideBehavior GetMessageElideBehavior() const;
  41. // Returns the buttons to be shown for this InfoBar.
  42. virtual int GetButtons() const;
  43. // Returns the label for the specified button. The default implementation
  44. // returns "OK" for the OK button and "Cancel" for the Cancel button.
  45. virtual std::u16string GetButtonLabel(InfoBarButton button) const;
  46. // Returns the label for the specified button. The default implementation
  47. // returns an empty image.
  48. virtual ui::ImageModel GetButtonImage(InfoBarButton button) const;
  49. // Returns whether the specified button is enabled. The default implementation
  50. // returns true.
  51. virtual bool GetButtonEnabled(InfoBarButton button) const;
  52. // Returns the tooltip for the specified button. The default implementation
  53. // returns an empty tooltip.
  54. virtual std::u16string GetButtonTooltip(InfoBarButton button) const;
  55. // Returns whether or not the OK button will trigger a UAC elevation prompt on
  56. // Windows.
  57. virtual bool OKButtonTriggersUACPrompt() const;
  58. #if BUILDFLAG(IS_IOS)
  59. // Returns whether or not a tint should be applied to the icon background.
  60. // Defaults to true.
  61. virtual bool UseIconBackgroundTint() const;
  62. #endif
  63. // Called when the OK button is pressed. If this function returns true, the
  64. // infobar is then immediately closed. Subclasses MUST NOT return true if in
  65. // handling this call something triggers the infobar to begin closing.
  66. virtual bool Accept();
  67. // Called when the Cancel button is pressed. If this function returns true,
  68. // the infobar is then immediately closed. Subclasses MUST NOT return true if
  69. // in handling this call something triggers the infobar to begin closing.
  70. virtual bool Cancel();
  71. protected:
  72. ConfirmInfoBarDelegate();
  73. };
  74. #endif // COMPONENTS_INFOBARS_CORE_CONFIRM_INFOBAR_DELEGATE_H_