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