OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 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_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
7 | 7 |
8 #include <map> | |
9 #include <string> | 8 #include <string> |
10 | 9 |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" |
13 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 12 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h" |
14 #include "chrome/browser/extensions/extension_context_menu_model.h" | |
15 #include "chrome/browser/ui/views/extensions/extension_popup.h" | |
16 #include "ui/views/context_menu_controller.h" | |
17 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/widget/widget_observer.h" | |
19 | 14 |
20 class Browser; | 15 class Browser; |
| 16 class ExtensionAction; |
21 class LocationBarView; | 17 class LocationBarView; |
22 | 18 |
23 namespace content { | 19 namespace content { |
24 class WebContents; | 20 class WebContents; |
25 } | 21 } |
26 namespace views { | |
27 class MenuRunner; | |
28 } | |
29 | 22 |
30 // PageActionImageView is used by the LocationBarView to display the icon for a | 23 // PageActionImageView is used by the LocationBarView to display the icon for a |
31 // given PageAction and notify the extension when the icon is clicked. | 24 // given PageAction and notify the extension when the icon is clicked. |
32 class PageActionImageView : public views::ImageView, | 25 class PageActionImageView : public ExtensionActionViewDelegate, |
33 public ExtensionContextMenuModel::PopupDelegate, | 26 public views::ImageView { |
34 public views::WidgetObserver, | |
35 public views::ContextMenuController, | |
36 public ExtensionActionIconFactory::Observer { | |
37 public: | 27 public: |
38 PageActionImageView(LocationBarView* owner, | 28 PageActionImageView(LocationBarView* owner, |
39 ExtensionAction* page_action, | 29 ExtensionAction* page_action, |
40 Browser* browser); | 30 Browser* browser); |
41 virtual ~PageActionImageView(); | 31 virtual ~PageActionImageView(); |
42 | 32 |
43 ExtensionAction* page_action() { return page_action_; } | |
44 | |
45 int current_tab_id() { return current_tab_id_; } | |
46 | |
47 void set_preview_enabled(bool preview_enabled) { | 33 void set_preview_enabled(bool preview_enabled) { |
48 preview_enabled_ = preview_enabled; | 34 preview_enabled_ = preview_enabled; |
49 } | 35 } |
| 36 ExtensionAction* extension_action() { |
| 37 return view_controller_->extension_action(); |
| 38 } |
| 39 ExtensionActionViewController* view_controller() { |
| 40 return view_controller_.get(); |
| 41 } |
50 | 42 |
51 // Overridden from views::View: | 43 // Overridden from views::View: |
52 virtual const char* GetClassName() const OVERRIDE; | 44 virtual const char* GetClassName() const OVERRIDE; |
53 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 45 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
54 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 46 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
55 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 47 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
56 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 48 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
57 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 49 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
58 | 50 |
59 // Overridden from ExtensionContextMenuModel::Delegate | |
60 virtual void InspectPopup() OVERRIDE; | |
61 | |
62 // Overridden from views::WidgetObserver: | |
63 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | |
64 | |
65 // Overridden from views::ContextMenuController. | |
66 virtual void ShowContextMenuForView(View* source, | |
67 const gfx::Point& point, | |
68 ui::MenuSourceType source_type) OVERRIDE; | |
69 | |
70 // Overriden from ExtensionActionIconFactory::Observer. | |
71 virtual void OnIconUpdated() OVERRIDE; | |
72 | |
73 // Overridden from ui::AcceleratorTarget: | |
74 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
75 virtual bool CanHandleAccelerators() const OVERRIDE; | |
76 | |
77 // Called to notify the PageAction that it should determine whether to be | 51 // Called to notify the PageAction that it should determine whether to be |
78 // visible or hidden. |contents| is the WebContents that is active, |url| is | 52 // visible or hidden. |contents| is the WebContents that is active. |
79 // the current page URL. | 53 void UpdateVisibility(content::WebContents* contents); |
80 void UpdateVisibility(content::WebContents* contents, const GURL& url); | |
81 | |
82 // Either notify listeners or show a popup depending on the page action. | |
83 void ExecuteAction(ExtensionPopup::ShowAction show_action); | |
84 | 54 |
85 private: | 55 private: |
86 static const char kViewClassName[]; | 56 static const char kViewClassName[]; |
87 | 57 |
88 // Overridden from View. | 58 // Overridden from View. |
89 virtual void PaintChildren(gfx::Canvas* canvas, | 59 virtual void PaintChildren(gfx::Canvas* canvas, |
90 const views::CullSet& cull_set) OVERRIDE; | 60 const views::CullSet& cull_set) OVERRIDE; |
91 | 61 |
92 // Shows the popup, with the given URL. | 62 // Overridden from ExtensionActionViewDelegate: |
93 void ShowPopupWithURL(const GURL& popup_url, | 63 virtual void OnIconUpdated() OVERRIDE; |
94 ExtensionPopup::ShowAction show_action); | 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 views::View* GetReferenceViewForPopup() OVERRIDE; |
| 69 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; |
| 70 virtual void HideActivePopup() OVERRIDE; |
95 | 71 |
96 // Hides the active popup, if there is one. | 72 // The controller for this ExtensionAction view. |
97 void HidePopup(); | 73 scoped_ptr<ExtensionActionViewController> view_controller_; |
98 | 74 |
99 // The location bar view that owns us. | 75 // The location bar view that owns us. |
100 LocationBarView* owner_; | 76 LocationBarView* owner_; |
101 | 77 |
102 // The PageAction that this view represents. The PageAction is not owned by | |
103 // us, it resides in the extension of this particular profile. | |
104 ExtensionAction* page_action_; | |
105 | |
106 // The corresponding browser. | |
107 Browser* browser_; | |
108 | |
109 // The object that will be used to get the page action icon for us. | |
110 // It may load the icon asynchronously (in which case the initial icon | |
111 // returned by the factory will be transparent), so we have to observe it for | |
112 // updates to the icon. | |
113 scoped_ptr<ExtensionActionIconFactory> icon_factory_; | |
114 | |
115 // The tab id we are currently showing the icon for. | |
116 int current_tab_id_; | |
117 | |
118 // The URL we are currently showing the icon for. | |
119 GURL current_url_; | |
120 | |
121 // The string to show for a tooltip; | 78 // The string to show for a tooltip; |
122 std::string tooltip_; | 79 std::string tooltip_; |
123 | 80 |
124 // This is used for post-install visual feedback. The page_action icon is | 81 // This is used for post-install visual feedback. The page_action icon is |
125 // briefly shown even if it hasn't been enabled by its extension. | 82 // briefly shown even if it hasn't been enabled by its extension. |
126 bool preview_enabled_; | 83 bool preview_enabled_; |
127 | 84 |
128 // The current popup and the button it came from. NULL if no popup. | |
129 ExtensionPopup* popup_; | |
130 | |
131 // The extension command accelerator this page action is listening for (to | |
132 // show the popup). | |
133 scoped_ptr<ui::Accelerator> page_action_keybinding_; | |
134 | |
135 scoped_ptr<views::MenuRunner> menu_runner_; | |
136 | |
137 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); | 85 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); |
138 }; | 86 }; |
139 | 87 |
140 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 88 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
OLD | NEW |