| 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_BROWSER_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/image_loading_tracker.h" | 10 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "ui/views/controls/button/menu_button.h" | 12 #include "ui/views/controls/button/menu_button.h" |
| 13 #include "ui/views/controls/button/menu_button_listener.h" | 13 #include "ui/views/controls/button/menu_button_listener.h" |
| 14 #include "ui/views/drag_controller.h" |
| 14 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 15 | 16 |
| 16 class BrowserActionsContainer; | 17 class Browser; |
| 18 class BrowserActionButton; |
| 17 class ExtensionAction; | 19 class ExtensionAction; |
| 18 | 20 |
| 19 namespace views { | 21 namespace views { |
| 20 class MenuItemView; | 22 class MenuItemView; |
| 21 } | 23 } |
| 22 | 24 |
| 23 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
| 26 // BrowserActionView |
| 27 // A single section in the browser action container. This contains the actual |
| 28 // BrowserActionButton, as well as the logic to paint the badge. |
| 29 class BrowserActionView : public views::View { |
| 30 public: |
| 31 // Need DragControler here because BrowserActionView could be dragged/dropped. |
| 32 class Delegate : public views::DragController { |
| 33 public: |
| 34 // Returns the current tab's ID, or -1 if there is no current tab. |
| 35 virtual int GetCurrentTabId() const = 0; |
| 36 |
| 37 // Called when the user clicks on the browser action icon. |
| 38 virtual void OnBrowserActionExecuted(BrowserActionButton* button) = 0; |
| 39 |
| 40 // Called when a browser action becomes visible/hidden. |
| 41 virtual void OnBrowserActionVisibilityChanged() = 0; |
| 42 |
| 43 // Returns relative position of the |button_| inside BrowserActionView. |
| 44 virtual gfx::Size GetViewContentOffset() const = 0; |
| 45 |
| 46 protected: |
| 47 Delegate() {} |
| 48 virtual ~Delegate() {} |
| 49 }; |
| 50 |
| 51 BrowserActionView(const extensions::Extension* extension, |
| 52 Browser* browser, |
| 53 Delegate* delegate); |
| 54 virtual ~BrowserActionView(); |
| 55 |
| 56 BrowserActionButton* button() { return button_; } |
| 57 |
| 58 // Allocates a canvas object on the heap and draws into it the icon for the |
| 59 // view as well as the badge (if any). Caller is responsible for deleting the |
| 60 // returned object. |
| 61 gfx::Canvas* GetIconWithBadge(); |
| 62 |
| 63 // Overridden from views::View: |
| 64 virtual void Layout() OVERRIDE; |
| 65 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 66 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 67 |
| 68 protected: |
| 69 // Overridden from views::View to paint the badge on top of children. |
| 70 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
| 71 virtual void ViewHierarchyChanged(bool is_add, |
| 72 View* parent, |
| 73 View* child) OVERRIDE; |
| 74 |
| 75 private: |
| 76 // The Browser object this view is associated with. |
| 77 Browser* browser_; |
| 78 |
| 79 // The container for this view. |
| 80 Delegate* delegate_; |
| 81 |
| 82 // The button this view contains. |
| 83 BrowserActionButton* button_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| 86 }; |
| 87 |
| 88 //////////////////////////////////////////////////////////////////////////////// |
| 24 // BrowserActionButton | 89 // BrowserActionButton |
| 25 | 90 |
| 26 // The BrowserActionButton is a specialization of the MenuButton class. | 91 // The BrowserActionButton is a specialization of the MenuButton class. |
| 27 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 92 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
| 28 // loading the image for the button asynchronously on the file thread. | 93 // loading the image for the button asynchronously on the file thread. |
| 29 class BrowserActionButton : public views::MenuButton, | 94 class BrowserActionButton : public views::MenuButton, |
| 30 public views::ButtonListener, | 95 public views::ButtonListener, |
| 31 public ImageLoadingTracker::Observer, | 96 public ImageLoadingTracker::Observer, |
| 32 public content::NotificationObserver { | 97 public content::NotificationObserver { |
| 33 public: | 98 public: |
| 34 BrowserActionButton(const extensions::Extension* extension, | 99 BrowserActionButton(const extensions::Extension* extension, |
| 35 BrowserActionsContainer* panel); | 100 Browser* browser_, |
| 101 BrowserActionView::Delegate* delegate); |
| 36 | 102 |
| 37 // Call this instead of delete. | 103 // Call this instead of delete. |
| 38 void Destroy(); | 104 void Destroy(); |
| 39 | 105 |
| 40 ExtensionAction* browser_action() const { return browser_action_; } | 106 ExtensionAction* browser_action() const { return browser_action_; } |
| 41 const extensions::Extension* extension() { return extension_; } | 107 const extensions::Extension* extension() { return extension_; } |
| 42 | 108 |
| 43 // Called to update the display to match the browser action's state. | 109 // Called to update the display to match the browser action's state. |
| 44 void UpdateState(); | 110 void UpdateState(); |
| 45 | 111 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 bool is_mouse_gesture) OVERRIDE; | 147 bool is_mouse_gesture) OVERRIDE; |
| 82 | 148 |
| 83 // Overridden from ui::AcceleratorTarget. | 149 // Overridden from ui::AcceleratorTarget. |
| 84 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 150 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 85 | 151 |
| 86 // Notifications when to set button state to pushed/not pushed (for when the | 152 // Notifications when to set button state to pushed/not pushed (for when the |
| 87 // popup/context menu is hidden or shown by the container). | 153 // popup/context menu is hidden or shown by the container). |
| 88 void SetButtonPushed(); | 154 void SetButtonPushed(); |
| 89 void SetButtonNotPushed(); | 155 void SetButtonNotPushed(); |
| 90 | 156 |
| 157 void SetTooltipDisabled(bool disable_tooltip); |
| 158 |
| 91 protected: | 159 protected: |
| 92 // Overridden from views::View: | 160 // Overridden from views::View: |
| 93 virtual void ViewHierarchyChanged(bool is_add, | 161 virtual void ViewHierarchyChanged(bool is_add, |
| 94 View* parent, | 162 View* parent, |
| 95 View* child) OVERRIDE; | 163 View* child) OVERRIDE; |
| 96 | 164 |
| 97 private: | 165 private: |
| 98 virtual ~BrowserActionButton(); | 166 virtual ~BrowserActionButton(); |
| 99 | 167 |
| 100 // Register an extension command if the extension has an active one. | 168 // Register an extension command if the extension has an active one. |
| 101 void MaybeRegisterExtensionCommand(); | 169 void MaybeRegisterExtensionCommand(); |
| 102 | 170 |
| 103 // Unregisters an extension command, if the extension has registered one and | 171 // Unregisters an extension command, if the extension has registered one and |
| 104 // it is active. | 172 // it is active. |
| 105 void MaybeUnregisterExtensionCommand(bool only_if_active); | 173 void MaybeUnregisterExtensionCommand(bool only_if_active); |
| 106 | 174 |
| 175 // Returns tooltip for the button. |
| 176 string16 GetTextForTooltip(); |
| 177 |
| 178 // The Browser object this button is associated with. |
| 179 Browser* browser_; |
| 180 |
| 107 // The browser action this view represents. The ExtensionAction is not owned | 181 // The browser action this view represents. The ExtensionAction is not owned |
| 108 // by this class. | 182 // by this class. |
| 109 ExtensionAction* browser_action_; | 183 ExtensionAction* browser_action_; |
| 110 | 184 |
| 111 // The extension associated with the browser action we're displaying. | 185 // The extension associated with the browser action we're displaying. |
| 112 const extensions::Extension* extension_; | 186 const extensions::Extension* extension_; |
| 113 | 187 |
| 114 // The object that is waiting for the image loading to complete | 188 // The object that is waiting for the image loading to complete |
| 115 // asynchronously. | 189 // asynchronously. |
| 116 ImageLoadingTracker tracker_; | 190 ImageLoadingTracker tracker_; |
| 117 | 191 |
| 118 // The default icon for our browser action. This might be non-empty if the | 192 // The default icon for our browser action. This might be non-empty if the |
| 119 // browser action had a value for default_icon in the manifest. | 193 // browser action had a value for default_icon in the manifest. |
| 120 SkBitmap default_icon_; | 194 SkBitmap default_icon_; |
| 121 | 195 |
| 122 // The browser action shelf. | 196 // The browser action shelf. |
| 123 BrowserActionsContainer* panel_; | 197 BrowserActionView::Delegate* delegate_; |
| 124 | 198 |
| 125 // The context menu. This member is non-NULL only when the menu is shown. | 199 // The context menu. This member is non-NULL only when the menu is shown. |
| 126 views::MenuItemView* context_menu_; | 200 views::MenuItemView* context_menu_; |
| 127 | 201 |
| 128 content::NotificationRegistrar registrar_; | 202 content::NotificationRegistrar registrar_; |
| 129 | 203 |
| 130 // The extension keybinding accelerator this browser action is listening for | 204 // The extension key binding accelerator this browser action is listening for |
| 131 // (to show the popup). | 205 // (to show the popup). |
| 132 scoped_ptr<ui::Accelerator> keybinding_; | 206 scoped_ptr<ui::Accelerator> keybinding_; |
| 133 | 207 |
| 208 // True if tooltip was disabled. |
| 209 bool disable_tooltip_; |
| 210 |
| 134 friend class base::DeleteHelper<BrowserActionButton>; | 211 friend class base::DeleteHelper<BrowserActionButton>; |
| 135 | 212 |
| 136 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 213 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
| 137 }; | 214 }; |
| 138 | 215 |
| 139 | |
| 140 //////////////////////////////////////////////////////////////////////////////// | |
| 141 // BrowserActionView | |
| 142 // A single section in the browser action container. This contains the actual | |
| 143 // BrowserActionButton, as well as the logic to paint the badge. | |
| 144 | |
| 145 class BrowserActionView : public views::View { | |
| 146 public: | |
| 147 BrowserActionView(const extensions::Extension* extension, | |
| 148 BrowserActionsContainer* panel); | |
| 149 virtual ~BrowserActionView(); | |
| 150 | |
| 151 BrowserActionButton* button() { return button_; } | |
| 152 | |
| 153 // Allocates a canvas object on the heap and draws into it the icon for the | |
| 154 // view as well as the badge (if any). Caller is responsible for deleting the | |
| 155 // returned object. | |
| 156 gfx::Canvas* GetIconWithBadge(); | |
| 157 | |
| 158 // Overridden from views::View: | |
| 159 virtual void Layout() OVERRIDE; | |
| 160 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
| 161 | |
| 162 protected: | |
| 163 // Overridden from views::View to paint the badge on top of children. | |
| 164 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | |
| 165 | |
| 166 private: | |
| 167 // The container for this view. | |
| 168 BrowserActionsContainer* panel_; | |
| 169 | |
| 170 // The button this view contains. | |
| 171 BrowserActionButton* button_; | |
| 172 | |
| 173 DISALLOW_COPY_AND_ASSIGN(BrowserActionView); | |
| 174 }; | |
| 175 | |
| 176 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ | 216 #endif // CHROME_BROWSER_UI_VIEWS_BROWSER_ACTION_VIEW_H_ |
| OLD | NEW |