1 // Copyright 2015 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_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_BUBBLE_DELEGATE_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_BUBBLE_DELEGATE_H_
7 
8 #include <string>
9 
10 #include "base/callback_forward.h"
11 #include "base/strings/string16.h"
12 #include "ui/base/ui_base_types.h"
13 
14 namespace gfx {
15 struct VectorIcon;
16 }
17 
18 // A delegate for a generic bubble that hangs off the toolbar actions bar.
19 class ToolbarActionsBarBubbleDelegate {
20  public:
21   enum CloseAction {
22     CLOSE_LEARN_MORE,
23     CLOSE_EXECUTE,
24     CLOSE_DISMISS_USER_ACTION,
25     CLOSE_DISMISS_DEACTIVATION,
26   };
27 
28   // Content populating an optional view, containing an image icon and/or
29   // (linked) text, in the bubble.
30   struct ExtraViewInfo {
ExtraViewInfoExtraViewInfo31     ExtraViewInfo() : resource(nullptr), is_learn_more(false) {}
32 
33     // The resource defining the image icon. If has a value of null, then no
34     // image icon will be added.
35     const gfx::VectorIcon* resource;
36 
37     // Text in the view. If this is an empty string, no text will be added.
38     base::string16 text;
39 
40     // If the struct's text is nonempty and this value is true, then a button
41     // with the (?) image is displayed and the text is set as the tooltip. If
42     // this value is false, the text is treated as a label.
43     bool is_learn_more;
44   };
45 
~ToolbarActionsBarBubbleDelegate()46   virtual ~ToolbarActionsBarBubbleDelegate() {}
47 
48   // Returns true if the bubble should (still) be shown. Since bubbles are
49   // sometimes shown asynchronously, they may be invalid by the time they would
50   // be displayed.
51   virtual bool ShouldShow() = 0;
52 
53   // Returns true if the bubble should close on deactivation.
54   virtual bool ShouldCloseOnDeactivate() = 0;
55 
56   // Gets the text for the bubble's heading (title).
57   virtual base::string16 GetHeadingText() = 0;
58 
59   // Gets the text for the bubble's body.
60   // |anchored_to_action| is true if the bubble is being anchored to a specific
61   // action (rather than the overflow menu or the full container).
62   virtual base::string16 GetBodyText(bool anchored_to_action) = 0;
63 
64   // Gets the text for an optional item list to display. If this returns an
65   // empty string, no list will be added.
66   virtual base::string16 GetItemListText() = 0;
67 
68   // Gets the text for the main button on the bubble; this button will
69   // correspond with ACTION_EXECUTE.
70   virtual base::string16 GetActionButtonText() = 0;
71 
72   // Gets the text for a second button on the bubble; this button will
73   // correspond with ACTION_DISMISS. If this returns an empty string, no
74   // button will be added.
75   virtual base::string16 GetDismissButtonText() = 0;
76 
77   // Returns the button that should be set to the default.
78   virtual ui::DialogButton GetDefaultDialogButton() = 0;
79 
80   // Returns the id of the action to point to, or the empty string if the
81   // bubble should point to the center of the actions container.
82   virtual std::string GetAnchorActionId() = 0;
83 
84   // Called when the bubble is shown. Accepts a callback from platform-specifc
85   // ui code to close the bubble.
86   virtual void OnBubbleShown(const base::Closure& close_bubble_callback) = 0;
87 
88   // Called when the bubble is closed with the type of action the user took.
89   virtual void OnBubbleClosed(CloseAction action) = 0;
90 
91   // Returns the ExtraViewInfo struct associated with the bubble delegate. If
92   // this returns a nullptr, no extra view (image icon and/or (linked) text) is
93   // added to the bubble.
94   virtual std::unique_ptr<ExtraViewInfo> GetExtraViewInfo() = 0;
95 };
96 
97 #endif  // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_BUBBLE_DELEGATE_H_
98