| OLD | NEW | 
|    1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2009 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_VIEWS_BROWSER_ACTIONS_PANEL_H_ |    5 #ifndef CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_PANEL_H_ | 
|    6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_PANEL_H_ |    6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_PANEL_H_ | 
|    7  |    7  | 
|    8 #include <vector> |    8 #include <vector> | 
|    9  |    9  | 
|   10 #include "base/task.h" |   10 #include "base/task.h" | 
|   11 #include "chrome/browser/extensions/image_loading_tracker.h" |   11 #include "chrome/browser/extensions/image_loading_tracker.h" | 
|   12 #include "chrome/browser/views/browser_bubble.h" |   12 #include "chrome/browser/views/browser_bubble.h" | 
|   13 #include "chrome/common/notification_observer.h" |   13 #include "chrome/common/notification_observer.h" | 
|   14 #include "chrome/common/notification_registrar.h" |   14 #include "chrome/common/notification_registrar.h" | 
|   15 #include "views/controls/button/menu_button.h" |   15 #include "views/controls/button/menu_button.h" | 
|   16 #include "views/view.h" |   16 #include "views/view.h" | 
|   17  |   17  | 
|   18 class BrowserActionsContainer; |   18 class BrowserActionsContainer; | 
|   19 class Extension; |   19 class Extension; | 
|   20 class ExtensionAction; |   20 class ExtensionAction2; | 
|   21 class ExtensionActionState; |  | 
|   22 class ExtensionPopup; |   21 class ExtensionPopup; | 
|   23 class Profile; |   22 class Profile; | 
|   24 class ToolbarView; |   23 class ToolbarView; | 
|   25  |   24  | 
|   26 //////////////////////////////////////////////////////////////////////////////// |   25 //////////////////////////////////////////////////////////////////////////////// | 
|   27 // BrowserActionButton |   26 // BrowserActionButton | 
|   28  |   27  | 
|   29 // The BrowserActionButton is a specialization of the MenuButton class. |   28 // The BrowserActionButton is a specialization of the MenuButton class. | 
|   30 // It acts on a ExtensionAction, in this case a BrowserAction and handles |   29 // It acts on a ExtensionAction2, in this case a BrowserAction and handles | 
|   31 // loading the image for the button asynchronously on the file thread to |   30 // loading the image for the button asynchronously on the file thread to | 
|   32 class BrowserActionButton : public views::MenuButton, |   31 class BrowserActionButton : public views::MenuButton, | 
|   33                             public views::ButtonListener, |   32                             public views::ButtonListener, | 
|   34                             public ImageLoadingTracker::Observer, |   33                             public ImageLoadingTracker::Observer, | 
|   35                             public NotificationObserver { |   34                             public NotificationObserver { | 
|   36  public: |   35  public: | 
|   37   BrowserActionButton(ExtensionAction* browser_action, |   36   BrowserActionButton(Extension* extension, BrowserActionsContainer* panel); | 
|   38                       Extension* extension, |  | 
|   39                       BrowserActionsContainer* panel); |  | 
|   40   ~BrowserActionButton(); |   37   ~BrowserActionButton(); | 
|   41  |   38  | 
|   42   const ExtensionAction& browser_action() const { return *browser_action_; } |   39   ExtensionAction2* browser_action() const { return browser_action_; } | 
|   43   ExtensionActionState* browser_action_state() { return browser_action_state_; } |   40   Extension* extension() { return extension_; } | 
 |   41  | 
 |   42   // Called to update the display to match the browser action's state. | 
 |   43   void UpdateState(); | 
|   44  |   44  | 
|   45   // Overriden from views::View. Return a 0-inset so the icon can draw all the |   45   // Overriden from views::View. Return a 0-inset so the icon can draw all the | 
|   46   // way to the edge of the view if it wants. |   46   // way to the edge of the view if it wants. | 
|   47   virtual gfx::Insets GetInsets() const; |   47   virtual gfx::Insets GetInsets() const; | 
|   48  |   48  | 
|   49   // Overridden from views::ButtonListener: |   49   // Overridden from views::ButtonListener: | 
|   50   virtual void ButtonPressed(views::Button* sender, const views::Event& event); |   50   virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 
|   51  |   51  | 
|   52   // Overridden from ImageLoadingTracker. |   52   // Overridden from ImageLoadingTracker. | 
|   53   virtual void OnImageLoaded(SkBitmap* image, size_t index); |   53   virtual void OnImageLoaded(SkBitmap* image, size_t index); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|   69   virtual void OnMouseExited(const views::MouseEvent& event); |   69   virtual void OnMouseExited(const views::MouseEvent& event); | 
|   70  |   70  | 
|   71   // Does this button's action have a popup? |   71   // Does this button's action have a popup? | 
|   72   virtual bool IsPopup(); |   72   virtual bool IsPopup(); | 
|   73  |   73  | 
|   74   // Notifications when the popup is hidden or shown by the container. |   74   // Notifications when the popup is hidden or shown by the container. | 
|   75   virtual void PopupDidShow(); |   75   virtual void PopupDidShow(); | 
|   76   virtual void PopupDidHide(); |   76   virtual void PopupDidHide(); | 
|   77  |   77  | 
|   78  private: |   78  private: | 
|   79   // Called to update the display to match the browser action's state. |   79   // If the image from the browser action needs to be loaded, load it. | 
|   80   void OnStateUpdated(); |   80   void LoadImage(); | 
|   81  |   81  | 
|   82   // The browser action this view represents. The ExtensionAction is not owned |   82   // The browser action this view represents. The ExtensionAction2 is not owned | 
|   83   // by this class. |   83   // by this class. | 
|   84   ExtensionAction* browser_action_; |   84   ExtensionAction2* browser_action_; | 
|   85  |   85  | 
|   86   // The state of our browser action. Not owned by this class. |   86   // The extension associated with the browser action we're displaying. | 
|   87   ExtensionActionState* browser_action_state_; |   87   Extension* extension_; | 
|   88  |   88  | 
|   89   // The icons representing different states for the browser action. |   89   // The icons representing different states for the browser action. | 
|   90   std::vector<SkBitmap> browser_action_icons_; |   90   std::vector<SkBitmap> browser_action_icons_; | 
|   91  |   91  | 
|   92   // The object that is waiting for the image loading to complete |   92   // The object that is waiting for the image loading to complete | 
|   93   // asynchronously. This object can potentially outlive the BrowserActionView, |   93   // asynchronously. This object can potentially outlive the BrowserActionView, | 
|   94   // and takes care of deleting itself. |   94   // and takes care of deleting itself. | 
|   95   ImageLoadingTracker* tracker_; |   95   ImageLoadingTracker* tracker_; | 
|   96  |   96  | 
|   97   // The browser action shelf. |   97   // The browser action shelf. | 
|   98   BrowserActionsContainer* panel_; |   98   BrowserActionsContainer* panel_; | 
|   99  |   99  | 
|  100   NotificationRegistrar registrar_; |  100   NotificationRegistrar registrar_; | 
|  101  |  101  | 
|  102   DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |  102   DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 
|  103 }; |  103 }; | 
|  104  |  104  | 
|  105  |  105  | 
|  106 //////////////////////////////////////////////////////////////////////////////// |  106 //////////////////////////////////////////////////////////////////////////////// | 
|  107 // BrowserActionView |  107 // BrowserActionView | 
|  108 // A single section in the browser action container. This contains the actual |  108 // A single section in the browser action container. This contains the actual | 
|  109 // BrowserActionButton, as well as the logic to paint the badge. |  109 // BrowserActionButton, as well as the logic to paint the badge. | 
|  110  |  110  | 
|  111 class BrowserActionView : public views::View { |  111 class BrowserActionView : public views::View { | 
|  112  public: |  112  public: | 
|  113   BrowserActionView(ExtensionAction* browser_action, Extension* extension, |  113   BrowserActionView(Extension* extension, BrowserActionsContainer* panel); | 
|  114                     BrowserActionsContainer* panel); |  | 
|  115  |  | 
|  116   BrowserActionButton* button() { return button_; } |  114   BrowserActionButton* button() { return button_; } | 
|  117  |  115  | 
|  118  private: |  116  private: | 
|  119   virtual void Layout(); |  117   virtual void Layout(); | 
|  120  |  118  | 
|  121   // Override PaintChildren so that we can paint the badge on top of children. |  119   // Override PaintChildren so that we can paint the badge on top of children. | 
|  122   virtual void PaintChildren(gfx::Canvas* canvas); |  120   virtual void PaintChildren(gfx::Canvas* canvas); | 
|  123  |  121  | 
 |  122   // The container for this view. | 
 |  123   BrowserActionsContainer* panel_; | 
 |  124  | 
|  124   // The button this view contains. |  125   // The button this view contains. | 
|  125   BrowserActionButton* button_; |  126   BrowserActionButton* button_; | 
|  126 }; |  127 }; | 
|  127  |  128  | 
|  128  |  129  | 
|  129 //////////////////////////////////////////////////////////////////////////////// |  130 //////////////////////////////////////////////////////////////////////////////// | 
|  130 // |  131 // | 
|  131 // The BrowserActionsContainer is a container view, responsible for drawing the |  132 // The BrowserActionsContainer is a container view, responsible for drawing the | 
|  132 // icons that represent browser actions (extensions that add icons to the |  133 // icons that represent browser actions (extensions that add icons to the | 
|  133 // toolbar). |  134 // toolbar). | 
|  134 // |  135 // | 
|  135 //////////////////////////////////////////////////////////////////////////////// |  136 //////////////////////////////////////////////////////////////////////////////// | 
|  136 class BrowserActionsContainer : public views::View, |  137 class BrowserActionsContainer : public views::View, | 
|  137                                 public NotificationObserver, |  138                                 public NotificationObserver, | 
|  138                                 public BrowserBubble::Delegate { |  139                                 public BrowserBubble::Delegate { | 
|  139  public: |  140  public: | 
|  140   BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); |  141   BrowserActionsContainer(Profile* profile, ToolbarView* toolbar); | 
|  141   virtual ~BrowserActionsContainer(); |  142   virtual ~BrowserActionsContainer(); | 
|  142  |  143  | 
|  143   // Get the number of browser actions being displayed. |  144   // Get the number of browser actions being displayed. | 
|  144   int num_browser_actions() { return browser_action_views_.size(); } |  145   int num_browser_actions() { return browser_action_views_.size(); } | 
|  145  |  146  | 
 |  147   // Returns the current tab's ID, or -1 if there is no current tab. | 
 |  148   int GetCurrentTabId(); | 
 |  149  | 
|  146   // Get a particular browser action view. |  150   // Get a particular browser action view. | 
|  147   BrowserActionView* GetBrowserActionViewAt(int index) { |  151   BrowserActionView* GetBrowserActionViewAt(int index) { | 
|  148     return browser_action_views_[index]; |  152     return browser_action_views_[index]; | 
|  149   } |  153   } | 
|  150  |  154  | 
|  151   // Update the views to reflect the state of the browser action icons. |  155   // Update the views to reflect the state of the browser action icons. | 
|  152   void RefreshBrowserActionViews(); |  156   void RefreshBrowserActionViews(); | 
|  153  |  157  | 
|  154   // Delete all browser action views. |  158   // Delete all browser action views. | 
|  155   void DeleteBrowserActionViews(); |  159   void DeleteBrowserActionViews(); | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  185   void HidePopup(); |  189   void HidePopup(); | 
|  186  |  190  | 
|  187   // Simulate a click on a browser action button.  This should only be |  191   // Simulate a click on a browser action button.  This should only be | 
|  188   // used by unit tests. |  192   // used by unit tests. | 
|  189   void TestExecuteBrowserAction(int index); |  193   void TestExecuteBrowserAction(int index); | 
|  190  |  194  | 
|  191   // Retrieve the current popup.  This should only be used by unit tests. |  195   // Retrieve the current popup.  This should only be used by unit tests. | 
|  192   ExtensionPopup* TestGetPopup() { return popup_; } |  196   ExtensionPopup* TestGetPopup() { return popup_; } | 
|  193  |  197  | 
|  194  private: |  198  private: | 
 |  199   // Adds a browser action view for the extension if it needs one. DCHECK if | 
 |  200   // it has already been added. | 
 |  201   void AddBrowserAction(Extension* extension); | 
 |  202  | 
 |  203   // Removes the browser action view for an extension if it has one. DCHECK if | 
 |  204   // no such view. | 
 |  205   void RemoveBrowserAction(Extension* extension); | 
 |  206  | 
|  195   // The vector of browser actions (icons/image buttons for each action). |  207   // The vector of browser actions (icons/image buttons for each action). | 
|  196   std::vector<BrowserActionView*> browser_action_views_; |  208   std::vector<BrowserActionView*> browser_action_views_; | 
|  197  |  209  | 
|  198   NotificationRegistrar registrar_; |  210   NotificationRegistrar registrar_; | 
|  199  |  211  | 
|  200   Profile* profile_; |  212   Profile* profile_; | 
|  201  |  213  | 
|  202   // The toolbar that owns us. |  214   // The toolbar that owns us. | 
|  203   ToolbarView* toolbar_; |  215   ToolbarView* toolbar_; | 
|  204  |  216  | 
|  205   // The current popup and the button it came from.  NULL if no popup. |  217   // The current popup and the button it came from.  NULL if no popup. | 
|  206   ExtensionPopup* popup_; |  218   ExtensionPopup* popup_; | 
|  207  |  219  | 
|  208   // The button that triggered the current popup (just a reference to a button |  220   // The button that triggered the current popup (just a reference to a button | 
|  209   // from browser_action_views_). |  221   // from browser_action_views_). | 
|  210   BrowserActionButton* popup_button_; |  222   BrowserActionButton* popup_button_; | 
|  211  |  223  | 
|  212   ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |  224   ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 
|  213  |  225  | 
|  214   DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |  226   DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 
|  215 }; |  227 }; | 
|  216  |  228  | 
|  217 #endif  // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_PANEL_H_ |  229 #endif  // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_PANEL_H_ | 
| OLD | NEW |