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/extensions/extension_action_view_controller.h"
12 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h"
13 #include "ui/views/context_menu_controller.h"
14 #include "ui/views/controls/image_view.h"
17 class ExtensionAction
;
18 class ExtensionActionViewController
;
19 class LocationBarView
;
29 // PageActionImageView is used by the LocationBarView to display the icon for a
30 // given PageAction and notify the extension when the icon is clicked.
31 class PageActionImageView
: public ToolbarActionViewDelegateViews
,
32 public views::ImageView
,
33 public views::ContextMenuController
{
35 PageActionImageView(LocationBarView
* owner
,
36 ExtensionAction
* page_action
,
38 ~PageActionImageView() override
;
40 void set_preview_enabled(bool preview_enabled
) {
41 preview_enabled_
= preview_enabled
;
43 ExtensionAction
* extension_action() {
44 return view_controller_
->extension_action();
46 ExtensionActionViewController
* view_controller() {
47 return view_controller_
.get();
50 // Overridden from views::View:
51 const char* GetClassName() const override
;
52 void GetAccessibleState(ui::AXViewState
* state
) override
;
53 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
54 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
55 bool OnKeyPressed(const ui::KeyEvent
& event
) override
;
56 void OnGestureEvent(ui::GestureEvent
* event
) override
;
58 // Called to notify the PageAction that it should determine whether to be
59 // visible or hidden. |contents| is the WebContents that is active.
60 void UpdateVisibility(content::WebContents
* contents
);
63 static const char kViewClassName
[];
65 // ToolbarActionViewDelegateViews:
66 void UpdateState() override
;
67 views::View
* GetAsView() override
;
68 bool IsMenuRunning() const override
;
69 views::FocusManager
* GetFocusManagerForAccelerator() override
;
70 views::View
* GetReferenceViewForPopup() override
;
71 content::WebContents
* GetCurrentWebContents() const override
;
73 // views::ContextMenuController:
74 void ShowContextMenuForView(views::View
* source
,
75 const gfx::Point
& point
,
76 ui::MenuSourceType source_type
) override
;
78 // The controller for this ExtensionAction view.
79 scoped_ptr
<ExtensionActionViewController
> view_controller_
;
81 // The location bar view that owns us.
82 LocationBarView
* owner_
;
84 // The string to show for a tooltip;
87 // This is used for post-install visual feedback. The page_action icon is
88 // briefly shown even if it hasn't been enabled by its extension.
89 bool preview_enabled_
;
91 // Responsible for running the menu.
92 scoped_ptr
<views::MenuRunner
> menu_runner_
;
94 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView
);
97 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_