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.
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_
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"
16 class ExtensionAction;
17 class LocationBarView;
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.
25 class PageActionImageView : public ExtensionActionViewDelegate,
26 public views::ImageView {
28 PageActionImageView(LocationBarView* owner,
29 ExtensionAction* page_action,
31 virtual ~PageActionImageView();
33 void set_preview_enabled(bool preview_enabled) {
34 preview_enabled_ = preview_enabled;
36 ExtensionAction* extension_action() {
37 return view_controller_->extension_action();
39 ExtensionActionViewController* view_controller() {
40 return view_controller_.get();
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;
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);
56 static const char kViewClassName[];
58 // Overridden from View.
59 virtual void PaintChildren(gfx::Canvas* canvas,
60 const views::CullSet& cull_set) OVERRIDE;
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()
70 virtual views::View* GetReferenceViewForPopup() OVERRIDE;
71 virtual views::MenuButton* GetContextMenuButton() OVERRIDE;
72 virtual content::WebContents* GetCurrentWebContents() OVERRIDE;
73 virtual void HideActivePopup() OVERRIDE;
75 // The controller for this ExtensionAction view.
76 scoped_ptr<ExtensionActionViewController> view_controller_;
78 // The location bar view that owns us.
79 LocationBarView* owner_;
81 // The string to show for a tooltip;
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_;
88 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView);
91 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_