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> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
13 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 13 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
14 #include "chrome/common/extensions/extension_action.h" | 14 #include "chrome/common/extensions/extension_action.h" |
15 #include "ui/views/context_menu_controller.h" | 15 #include "ui/views/context_menu_controller.h" |
16 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
| 17 #include "ui/views/widget/widget_observer.h" |
17 | 18 |
18 class Browser; | 19 class Browser; |
19 class LocationBarView; | 20 class LocationBarView; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 class WebContents; | 23 class WebContents; |
23 } | 24 } |
24 namespace views { | 25 namespace views { |
25 class MenuRunner; | 26 class MenuRunner; |
26 } | 27 } |
27 | 28 |
28 // PageActionImageView is used by the LocationBarView to display the icon for a | 29 // PageActionImageView is used by the LocationBarView to display the icon for a |
29 // given PageAction and notify the extension when the icon is clicked. | 30 // given PageAction and notify the extension when the icon is clicked. |
30 class PageActionImageView : public views::ImageView, | 31 class PageActionImageView : public views::ImageView, |
31 public ImageLoadingTracker::Observer, | 32 public ImageLoadingTracker::Observer, |
32 public views::Widget::Observer, | 33 public views::WidgetObserver, |
33 public views::ContextMenuController, | 34 public views::ContextMenuController, |
34 public content::NotificationObserver, | 35 public content::NotificationObserver, |
35 public ExtensionAction::IconAnimation::Observer { | 36 public ExtensionAction::IconAnimation::Observer { |
36 public: | 37 public: |
37 PageActionImageView(LocationBarView* owner, | 38 PageActionImageView(LocationBarView* owner, |
38 ExtensionAction* page_action, | 39 ExtensionAction* page_action, |
39 Browser* browser); | 40 Browser* browser); |
40 virtual ~PageActionImageView(); | 41 virtual ~PageActionImageView(); |
41 | 42 |
42 ExtensionAction* page_action() { return page_action_; } | 43 ExtensionAction* page_action() { return page_action_; } |
43 | 44 |
44 int current_tab_id() { return current_tab_id_; } | 45 int current_tab_id() { return current_tab_id_; } |
45 | 46 |
46 void set_preview_enabled(bool preview_enabled) { | 47 void set_preview_enabled(bool preview_enabled) { |
47 preview_enabled_ = preview_enabled; | 48 preview_enabled_ = preview_enabled; |
48 } | 49 } |
49 | 50 |
50 // Overridden from view. | 51 // Overridden from views::View: |
51 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 52 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
52 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | 53 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
53 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 54 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
54 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | 55 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; |
55 | 56 |
56 // Overridden from ImageLoadingTracker. | 57 // Overridden from ImageLoadingTracker: |
57 virtual void OnImageLoaded(const gfx::Image& image, | 58 virtual void OnImageLoaded(const gfx::Image& image, |
58 const std::string& extension_id, | 59 const std::string& extension_id, |
59 int index) OVERRIDE; | 60 int index) OVERRIDE; |
60 | 61 |
61 // Overridden from views::Widget::Observer | 62 // Overridden from views::WidgetObserver: |
62 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 63 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
63 | 64 |
64 // Overridden from views::ContextMenuController. | 65 // Overridden from views::ContextMenuController. |
65 virtual void ShowContextMenuForView(View* source, | 66 virtual void ShowContextMenuForView(View* source, |
66 const gfx::Point& point) OVERRIDE; | 67 const gfx::Point& point) OVERRIDE; |
67 | 68 |
68 // content::NotificationObserver implementation. | 69 // Overridden from content::NotificationObserver: |
69 virtual void Observe(int type, | 70 virtual void Observe(int type, |
70 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
71 const content::NotificationDetails& details) OVERRIDE; | 72 const content::NotificationDetails& details) OVERRIDE; |
72 | 73 |
73 // Overridden from ui::AcceleratorTarget. | 74 // Overridden from ui::AcceleratorTarget: |
74 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 75 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
75 virtual bool CanHandleAccelerators() const OVERRIDE; | 76 virtual bool CanHandleAccelerators() const OVERRIDE; |
76 | 77 |
77 // Called to notify the PageAction that it should determine whether to be | 78 // 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 | 79 // visible or hidden. |contents| is the WebContents that is active, |url| is |
79 // the current page URL. | 80 // the current page URL. |
80 void UpdateVisibility(content::WebContents* contents, const GURL& url); | 81 void UpdateVisibility(content::WebContents* contents, const GURL& url); |
81 | 82 |
82 // Either notify listeners or show a popup depending on the page action. | 83 // Either notify listeners or show a popup depending on the page action. |
83 void ExecuteAction(int button); | 84 void ExecuteAction(int button); |
84 | 85 |
85 private: | 86 private: |
86 // Overridden from ExtensionAction::IconAnimation::Observer. | 87 // Overridden from ExtensionAction::IconAnimation::Observer: |
87 virtual void OnIconChanged( | 88 virtual void OnIconChanged( |
88 const ExtensionAction::IconAnimation& animation) OVERRIDE; | 89 const ExtensionAction::IconAnimation& animation) OVERRIDE; |
89 | 90 |
90 // Shows the popup, with the given URL. | 91 // Shows the popup, with the given URL. |
91 void ShowPopupWithURL(const GURL& popup_url); | 92 void ShowPopupWithURL(const GURL& popup_url); |
92 | 93 |
93 // Hides the active popup, if there is one. | 94 // Hides the active popup, if there is one. |
94 void HidePopup(); | 95 void HidePopup(); |
95 | 96 |
96 // The location bar view that owns us. | 97 // The location bar view that owns us. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 scoped_ptr<views::MenuRunner> menu_runner_; | 133 scoped_ptr<views::MenuRunner> menu_runner_; |
133 | 134 |
134 // Fade-in animation for the icon with observer scoped to this. | 135 // Fade-in animation for the icon with observer scoped to this. |
135 ExtensionAction::IconAnimation::ScopedObserver | 136 ExtensionAction::IconAnimation::ScopedObserver |
136 scoped_icon_animation_observer_; | 137 scoped_icon_animation_observer_; |
137 | 138 |
138 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); | 139 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); |
139 }; | 140 }; |
140 | 141 |
141 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 142 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
OLD | NEW |