Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / toolbar / toolbar_action_view_controller.h
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.
4
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
7
8 #include "base/strings/string16.h"
9 #include "ui/gfx/image/image.h"
10
11 namespace content {
12 class WebContents;
13 }
14
15 namespace gfx {
16 class Canvas;
17 class Rect;
18 }
19
20 class ToolbarActionViewDelegate;
21
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
24 // chromecast).
25 class ToolbarActionViewController {
26  public:
27   virtual ~ToolbarActionViewController() {}
28
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;
32
33   // Sets the view delegate, which can handle most of the front-end logic.
34   virtual void SetDelegate(ToolbarActionViewDelegate* delegate) = 0;
35
36   // Returns the icon to use for the given |web_contents|.
37   virtual gfx::Image GetIcon(content::WebContents* web_contents) = 0;
38
39   // Returns the icon and the badge, if any, for the current tab.
40   virtual gfx::ImageSkia GetIconWithBadge() = 0;
41
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;
45
46   // Returns the accessible name to use for the given |web_contents|.
47   virtual base::string16 GetAccessibleName(content::WebContents* web_contents)
48       const = 0;
49
50   // Returns the tooltip to use for the given |web_contents|.
51   virtual base::string16 GetTooltip(content::WebContents* web_contents)
52       const = 0;
53
54   // Returns true if the action should be enabled on the given |web_contents|.
55   virtual bool IsEnabled(content::WebContents* web_contents) const = 0;
56
57   // Returns true if the action has a popup for the given |web_contents|.
58   virtual bool HasPopup(content::WebContents* web_contents) const = 0;
59
60   // Hides the current popup, if one is visible.
61   virtual void HidePopup() = 0;
62
63   // Returns the native view for the popup, if one is active.
64   virtual gfx::NativeView GetPopupNativeView() = 0;
65
66   // Returns true if a menu is currently running for the action.
67   virtual bool IsMenuRunning() const = 0;
68
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
71   // supports.
72   // TODO(devlin): Tweak the model so that it supports generic actions.
73   virtual bool CanDrag() const = 0;
74
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;
80
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 {
85   }
86
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() {
90   }
91 };
92
93 #endif  // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_