1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
8 #include "base/strings/string16.h"
9 #include "ui/gfx/image/image.h"
20 class ToolbarActionViewDelegate
;
22 // The basic controller class for an action that is shown on the toolbar -
23 // an extension action (like browser actions) or a component action (like
25 class ToolbarActionViewController
{
27 virtual ~ToolbarActionViewController() {}
29 // Returns the unique ID of this particular action. For extensions, this is
30 // the extension id; for component actions, this is the name of the component.
31 virtual const std::string
& GetId() const = 0;
33 // Sets the view delegate, which can handle most of the front-end logic.
34 virtual void SetDelegate(ToolbarActionViewDelegate
* delegate
) = 0;
36 // Returns the icon to use for the given |web_contents|.
37 virtual gfx::Image
GetIcon(content::WebContents
* web_contents
) = 0;
39 // Returns the icon and the badge, if any, for the current tab.
40 virtual gfx::ImageSkia
GetIconWithBadge() = 0;
42 // Returns the name of the action, which can be separate from the accessible
43 // name or name for the tooltip.
44 virtual base::string16
GetActionName() const = 0;
46 // Returns the accessible name to use for the given |web_contents|.
47 virtual base::string16
GetAccessibleName(content::WebContents
* web_contents
)
50 // Returns the tooltip to use for the given |web_contents|.
51 virtual base::string16
GetTooltip(content::WebContents
* web_contents
)
54 // Returns true if the action should be enabled on the given |web_contents|.
55 virtual bool IsEnabled(content::WebContents
* web_contents
) const = 0;
57 // Returns true if the action has a popup for the given |web_contents|.
58 virtual bool HasPopup(content::WebContents
* web_contents
) const = 0;
60 // Hides the current popup, if one is visible.
61 virtual void HidePopup() = 0;
63 // Returns the native view for the popup, if one is active.
64 virtual gfx::NativeView
GetPopupNativeView() = 0;
66 // Returns true if a menu is currently running for the action.
67 virtual bool IsMenuRunning() const = 0;
69 // Returns true if this view can be dragged. This should only be true for
70 // extensions right now, since they are the only ones the model currently
72 // TODO(devlin): Tweak the model so that it supports generic actions.
73 virtual bool CanDrag() const = 0;
75 // Executes the default action (which is typically showing the popup). If
76 // |by_user| is true, then this was through a direct user action (as oppposed
77 // to, e.g., an API call).
78 // Returns true if a popup is shown.
79 virtual bool ExecuteAction(bool by_user
) = 0;
81 // Paints any extra parts of the image (e.g., a badge).
82 virtual void PaintExtra(gfx::Canvas
* canvas
,
83 const gfx::Rect
& bounds
,
84 content::WebContents
* web_contents
) const {
87 // Registers an accelerator. Called when the view is added to the hierarchy.
88 // Unregistering any commands is the responsibility of the controller.
89 virtual void RegisterCommand() {
93 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_