| 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/extension_action_icon_factory.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 #include "ui/views/widget/widget_observer.h" |
| 18 | 18 |
| 19 class Browser; | 19 class Browser; |
| 20 class LocationBarView; | 20 class LocationBarView; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class WebContents; | 23 class WebContents; |
| 24 } | 24 } |
| 25 namespace views { | 25 namespace views { |
| 26 class MenuRunner; | 26 class MenuRunner; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // 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 |
| 30 // given PageAction and notify the extension when the icon is clicked. | 30 // given PageAction and notify the extension when the icon is clicked. |
| 31 class PageActionImageView : public views::ImageView, | 31 class PageActionImageView : public views::ImageView, |
| 32 public ImageLoadingTracker::Observer, | |
| 33 public views::WidgetObserver, | 32 public views::WidgetObserver, |
| 34 public views::ContextMenuController, | 33 public views::ContextMenuController, |
| 35 public content::NotificationObserver, | 34 public content::NotificationObserver, |
| 35 public ExtensionActionIconFactory::Observer, |
| 36 public ExtensionAction::IconAnimation::Observer { | 36 public ExtensionAction::IconAnimation::Observer { |
| 37 public: | 37 public: |
| 38 PageActionImageView(LocationBarView* owner, | 38 PageActionImageView(LocationBarView* owner, |
| 39 ExtensionAction* page_action, | 39 ExtensionAction* page_action, |
| 40 Browser* browser); | 40 Browser* browser); |
| 41 virtual ~PageActionImageView(); | 41 virtual ~PageActionImageView(); |
| 42 | 42 |
| 43 ExtensionAction* page_action() { return page_action_; } | 43 ExtensionAction* page_action() { return page_action_; } |
| 44 | 44 |
| 45 int current_tab_id() { return current_tab_id_; } | 45 int current_tab_id() { return current_tab_id_; } |
| 46 | 46 |
| 47 void set_preview_enabled(bool preview_enabled) { | 47 void set_preview_enabled(bool preview_enabled) { |
| 48 preview_enabled_ = preview_enabled; | 48 preview_enabled_ = preview_enabled; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Overridden from views::View: | 51 // Overridden from views::View: |
| 52 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 52 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
| 54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
| 55 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 55 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
| 56 | 56 |
| 57 // Overridden from ImageLoadingTracker: | |
| 58 virtual void OnImageLoaded(const gfx::Image& image, | |
| 59 const std::string& extension_id, | |
| 60 int index) OVERRIDE; | |
| 61 | |
| 62 // Overridden from views::WidgetObserver: | 57 // Overridden from views::WidgetObserver: |
| 63 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 58 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
| 64 | 59 |
| 65 // Overridden from views::ContextMenuController. | 60 // Overridden from views::ContextMenuController. |
| 66 virtual void ShowContextMenuForView(View* source, | 61 virtual void ShowContextMenuForView(View* source, |
| 67 const gfx::Point& point) OVERRIDE; | 62 const gfx::Point& point) OVERRIDE; |
| 68 | 63 |
| 69 // Overridden from content::NotificationObserver: | 64 // Overridden from content::NotificationObserver: |
| 70 virtual void Observe(int type, | 65 virtual void Observe(int type, |
| 71 const content::NotificationSource& source, | 66 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) OVERRIDE; | 67 const content::NotificationDetails& details) OVERRIDE; |
| 73 | 68 |
| 69 // Overriden from ExtensionActionIconFactory::Observer. |
| 70 virtual void OnIconUpdated() OVERRIDE; |
| 71 |
| 74 // Overridden from ui::AcceleratorTarget: | 72 // Overridden from ui::AcceleratorTarget: |
| 75 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 73 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 76 virtual bool CanHandleAccelerators() const OVERRIDE; | 74 virtual bool CanHandleAccelerators() const OVERRIDE; |
| 77 | 75 |
| 78 // Called to notify the PageAction that it should determine whether to be | 76 // Called to notify the PageAction that it should determine whether to be |
| 79 // visible or hidden. |contents| is the WebContents that is active, |url| is | 77 // visible or hidden. |contents| is the WebContents that is active, |url| is |
| 80 // the current page URL. | 78 // the current page URL. |
| 81 void UpdateVisibility(content::WebContents* contents, const GURL& url); | 79 void UpdateVisibility(content::WebContents* contents, const GURL& url); |
| 82 | 80 |
| 83 // Either notify listeners or show a popup depending on the page action. | 81 // Either notify listeners or show a popup depending on the page action. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 97 // The location bar view that owns us. | 95 // The location bar view that owns us. |
| 98 LocationBarView* owner_; | 96 LocationBarView* owner_; |
| 99 | 97 |
| 100 // The PageAction that this view represents. The PageAction is not owned by | 98 // The PageAction that this view represents. The PageAction is not owned by |
| 101 // us, it resides in the extension of this particular profile. | 99 // us, it resides in the extension of this particular profile. |
| 102 ExtensionAction* page_action_; | 100 ExtensionAction* page_action_; |
| 103 | 101 |
| 104 // The corresponding browser. | 102 // The corresponding browser. |
| 105 Browser* browser_; | 103 Browser* browser_; |
| 106 | 104 |
| 107 // The object that is waiting for the image loading to complete | 105 // The object that page action will use to create icon for us. |
| 108 // asynchronously. | 106 // It may load icon asynchronously (in which case initial icon returned by |
| 109 ImageLoadingTracker tracker_; | 107 // the action will be blank), so we have to observe it for icon's updates. |
| 108 scoped_ptr<ExtensionActionIconFactory> icon_factory_; |
| 110 | 109 |
| 111 // The tab id we are currently showing the icon for. | 110 // The tab id we are currently showing the icon for. |
| 112 int current_tab_id_; | 111 int current_tab_id_; |
| 113 | 112 |
| 114 // The URL we are currently showing the icon for. | 113 // The URL we are currently showing the icon for. |
| 115 GURL current_url_; | 114 GURL current_url_; |
| 116 | 115 |
| 117 // The string to show for a tooltip; | 116 // The string to show for a tooltip; |
| 118 std::string tooltip_; | 117 std::string tooltip_; |
| 119 | 118 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 137 scoped_ptr<views::MenuRunner> menu_runner_; | 136 scoped_ptr<views::MenuRunner> menu_runner_; |
| 138 | 137 |
| 139 // Fade-in animation for the icon with observer scoped to this. | 138 // Fade-in animation for the icon with observer scoped to this. |
| 140 ExtensionAction::IconAnimation::ScopedObserver | 139 ExtensionAction::IconAnimation::ScopedObserver |
| 141 scoped_icon_animation_observer_; | 140 scoped_icon_animation_observer_; |
| 142 | 141 |
| 143 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); | 142 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); |
| 144 }; | 143 }; |
| 145 | 144 |
| 146 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 145 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
| OLD | NEW |