page_action_image_view.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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
5#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_
7
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
11#include "chrome/browser/ui/views/extensions/extension_action_view_controller.h"
12#include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h"
13#include "ui/views/controls/image_view.h"
14
15class Browser;
16class ExtensionAction;
17class LocationBarView;
18
19namespace content {
20class WebContents;
21}
22
23// PageActionImageView is used by the LocationBarView to display the icon for a
24// given PageAction and notify the extension when the icon is clicked.
25class PageActionImageView : public ExtensionActionViewDelegate,
26                            public views::ImageView {
27 public:
28  PageActionImageView(LocationBarView* owner,
29                      ExtensionAction* page_action,
30                      Browser* browser);
31  virtual ~PageActionImageView();
32
33  void set_preview_enabled(bool preview_enabled) {
34    preview_enabled_ = preview_enabled;
35  }
36  ExtensionAction* extension_action() {
37    return view_controller_->extension_action();
38  }
39  ExtensionActionViewController* view_controller() {
40    return view_controller_.get();
41  }
42
43  // Overridden from views::View:
44  virtual const char* GetClassName() const OVERRIDE;
45  virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
46  virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
47  virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
48  virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
49  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
50
51  // Called to notify the PageAction that it should determine whether to be
52  // visible or hidden. |contents| is the WebContents that is active.
53  void UpdateVisibility(content::WebContents* contents);
54
55 private:
56  static const char kViewClassName[];
57
58  // Overridden from View.
59  virtual void PaintChildren(gfx::Canvas* canvas,
60                             const views::CullSet& cull_set) OVERRIDE;
61
62  // Overridden from ExtensionActionViewDelegate:
63  virtual void OnIconUpdated() OVERRIDE;
64  virtual views::View* GetAsView() OVERRIDE;
65  virtual bool IsShownInMenu() OVERRIDE;
66  virtual views::FocusManager* GetFocusManagerForAccelerator() OVERRIDE;
67  virtual views::Widget* GetParentForContextMenu() OVERRIDE;
68  virtual ExtensionActionViewController* GetPreferredPopupViewController()
69      OVERRIDE;
70  virtual views::View* GetReferenceViewForPopup() OVERRIDE;
71  virtual views::MenuButton* GetContextMenuButton() OVERRIDE;
72  virtual content::WebContents* GetCurrentWebContents() OVERRIDE;
73  virtual void HideActivePopup() OVERRIDE;
74
75  // The controller for this ExtensionAction view.
76  scoped_ptr<ExtensionActionViewController> view_controller_;
77
78  // The location bar view that owns us.
79  LocationBarView* owner_;
80
81  // The string to show for a tooltip;
82  std::string tooltip_;
83
84  // This is used for post-install visual feedback. The page_action icon is
85  // briefly shown even if it hasn't been enabled by its extension.
86  bool preview_enabled_;
87
88  DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView);
89};
90
91#endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_
92