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/controls/image_view.h"
16 class ExtensionAction
;
17 class ExtensionActionViewController
;
18 class LocationBarView
;
24 // PageActionImageView is used by the LocationBarView to display the icon for a
25 // given PageAction and notify the extension when the icon is clicked.
26 class PageActionImageView
: public ToolbarActionViewDelegateViews
,
27 public views::ImageView
{
29 PageActionImageView(LocationBarView
* owner
,
30 ExtensionAction
* page_action
,
32 ~PageActionImageView() override
;
34 void set_preview_enabled(bool preview_enabled
) {
35 preview_enabled_
= preview_enabled
;
37 ExtensionAction
* extension_action() {
38 return view_controller_
->extension_action();
40 ExtensionActionViewController
* view_controller() {
41 return view_controller_
.get();
44 // Overridden from views::View:
45 const char* GetClassName() const override
;
46 void GetAccessibleState(ui::AXViewState
* state
) override
;
47 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
48 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
49 bool OnKeyPressed(const ui::KeyEvent
& event
) override
;
50 void OnGestureEvent(ui::GestureEvent
* event
) override
;
52 // Called to notify the PageAction that it should determine whether to be
53 // visible or hidden. |contents| is the WebContents that is active.
54 void UpdateVisibility(content::WebContents
* contents
);
57 static const char kViewClassName
[];
59 // Overridden from View.
60 void PaintChildren(const PaintContext
& context
) override
;
62 // ToolbarActionViewDelegateViews:
63 void UpdateState() override
;
64 views::View
* GetAsView() override
;
65 bool IsShownInMenu() override
;
66 views::FocusManager
* GetFocusManagerForAccelerator() override
;
67 views::Widget
* GetParentForContextMenu() override
;
68 ToolbarActionViewController
* GetPreferredPopupViewController() override
;
69 views::View
* GetReferenceViewForPopup() override
;
70 views::MenuButton
* GetContextMenuButton() override
;
71 content::WebContents
* GetCurrentWebContents() const override
;
73 // The controller for this ExtensionAction view.
74 scoped_ptr
<ExtensionActionViewController
> view_controller_
;
76 // The location bar view that owns us.
77 LocationBarView
* owner_
;
79 // The string to show for a tooltip;
82 // This is used for post-install visual feedback. The page_action icon is
83 // briefly shown even if it hasn't been enabled by its extension.
84 bool preview_enabled_
;
86 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView
);
89 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_