| 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_EXTENSIONS_EXTENSION_POPUP_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
| 6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ | 6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/views/browser_bubble.h" | 9 #include "chrome/browser/views/browser_bubble.h" |
| 10 #include "chrome/browser/views/extensions/extension_view.h" | 10 #include "chrome/browser/views/extensions/extension_view.h" |
| 11 #include "chrome/browser/views/bubble_border.h" | 11 #include "chrome/browser/views/bubble_border.h" |
| 12 #include "chrome/common/notification_observer.h" | 12 #include "chrome/common/notification_observer.h" |
| 13 #include "chrome/common/notification_registrar.h" | 13 #include "chrome/common/notification_registrar.h" |
| 14 #include "gfx/native_widget_types.h" | 14 #include "gfx/native_widget_types.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 | 16 |
| 17 class Browser; | 17 class Browser; |
| 18 class ExtensionHost; | 18 class ExtensionHost; |
| 19 class Profile; | 19 class Profile; |
| 20 | 20 |
| 21 namespace views { | 21 namespace views { |
| 22 class Widget; | 22 class Widget; |
| 23 } | 23 } |
| 24 | 24 |
| 25 class ExtensionPopup : public BrowserBubble, | 25 class ExtensionPopup : public BrowserBubble, |
| 26 public BrowserBubble::Delegate, |
| 26 public NotificationObserver, | 27 public NotificationObserver, |
| 27 public ExtensionView::Container { | 28 public ExtensionView::Container, |
| 29 public base::RefCounted<ExtensionPopup> { |
| 28 public: | 30 public: |
| 31 // Observer to ExtensionPopup events. |
| 32 class Observer { |
| 33 public: |
| 34 // Called when the ExtensionPopup has closed. Note that it |
| 35 // is ref-counted, and thus will be released shortly after |
| 36 // making this delegate call. |
| 37 virtual void ExtensionPopupClosed(ExtensionPopup* popup) {} |
| 38 }; |
| 39 |
| 29 enum PopupChrome { | 40 enum PopupChrome { |
| 30 BUBBLE_CHROME, | 41 BUBBLE_CHROME, |
| 31 RECTANGLE_CHROME | 42 RECTANGLE_CHROME |
| 32 }; | 43 }; |
| 33 | 44 |
| 34 virtual ~ExtensionPopup(); | 45 virtual ~ExtensionPopup(); |
| 35 | 46 |
| 36 // Create and show a popup with |url| positioned adjacent to |relative_to| in | 47 // Create and show a popup with |url| positioned adjacent to |relative_to| in |
| 37 // screen coordinates. | 48 // screen coordinates. |
| 38 // |browser| is the browser to which the pop-up will be attached. NULL is a | 49 // |browser| is the browser to which the pop-up will be attached. NULL is a |
| 39 // valid parameter for pop-ups not associated with a browser. | 50 // valid parameter for pop-ups not associated with a browser. |
| 40 // |profile| is the user profile instance associated with the popup. A | 51 // |profile| is the user profile instance associated with the popup. A |
| 41 // non NULL value must be given. | 52 // non NULL value must be given. |
| 42 // |frame_window| is the native window that hosts the view inside which the | 53 // |frame_window| is the native window that hosts the view inside which the |
| 43 // popup will be anchored. | 54 // popup will be anchored. |
| 44 // The positioning of the pop-up is determined by |arrow_location| according | 55 // The positioning of the pop-up is determined by |arrow_location| according |
| 45 // to the following logic: The popup is anchored so that the corner indicated | 56 // to the following logic: The popup is anchored so that the corner indicated |
| 46 // by value of |arrow_location| remains fixed during popup resizes. | 57 // by value of |arrow_location| remains fixed during popup resizes. |
| 47 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise | 58 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise |
| 48 // the popup 'drops down'. | 59 // the popup 'drops down'. |
| 49 // Pass |activate_on_show| as true to activate the popup window. | 60 // Pass |activate_on_show| as true to activate the popup window. |
| 61 // Pass |inspect_with_devtools| as true to pin the popup open and show the |
| 62 // devtools window for it. |
| 50 // The |chrome| argument controls the chrome that surrounds the pop-up. | 63 // The |chrome| argument controls the chrome that surrounds the pop-up. |
| 51 // Passing BUBBLE_CHROME will give the pop-up a bubble-like appearance, | 64 // Passing BUBBLE_CHROME will give the pop-up a bubble-like appearance, |
| 52 // including the arrow mentioned above. Passing RECTANGLE_CHROME will give | 65 // including the arrow mentioned above. Passing RECTANGLE_CHROME will give |
| 53 // the popup a rectangular, black border with a drop-shadow with no arrow. | 66 // the popup a rectangular, black border with a drop-shadow with no arrow. |
| 54 // The positioning of the popup is still governed by the arrow-location | 67 // The positioning of the popup is still governed by the arrow-location |
| 55 // parameter. | 68 // parameter. |
| 56 // | 69 // |
| 57 // The actual display of the popup is delayed until the page contents | 70 // The actual display of the popup is delayed until the page contents |
| 58 // finish loading in order to minimize UI flashing and resizing. | 71 // finish loading in order to minimize UI flashing and resizing. |
| 59 static ExtensionPopup* Show(const GURL& url, Browser* browser, | 72 static ExtensionPopup* Show(const GURL& url, Browser* browser, |
| 60 Profile* profile, | 73 Profile* profile, |
| 61 gfx::NativeWindow frame_window, | 74 gfx::NativeWindow frame_window, |
| 62 const gfx::Rect& relative_to, | 75 const gfx::Rect& relative_to, |
| 63 BubbleBorder::ArrowLocation arrow_location, | 76 BubbleBorder::ArrowLocation arrow_location, |
| 64 bool activate_on_show, | 77 bool activate_on_show, |
| 65 PopupChrome chrome); | 78 bool inspect_with_devtools, |
| 79 PopupChrome chrome, |
| 80 Observer* observer); |
| 81 |
| 82 // Closes the ExtensionPopup (this will cause the delegate |
| 83 // ExtensionPopupClosed to fire. |
| 84 void Close(); |
| 85 |
| 86 // Some clients wish to do their own custom focus change management. If this |
| 87 // is set to false, then the ExtensionPopup will not do anything in response |
| 88 // to the BubbleLostFocus() calls it gets from the BrowserBubble. |
| 89 void set_close_on_lost_focus(bool close_on_lost_focus) { |
| 90 close_on_lost_focus_ = close_on_lost_focus; |
| 91 } |
| 66 | 92 |
| 67 ExtensionHost* host() const { return extension_host_.get(); } | 93 ExtensionHost* host() const { return extension_host_.get(); } |
| 68 | 94 |
| 69 // BrowserBubble overrides. | 95 // BrowserBubble overrides. |
| 70 virtual void Hide(); | 96 virtual void Hide(); |
| 71 virtual void Show(bool activate); | 97 virtual void Show(bool activate); |
| 72 virtual void ResizeToView(); | 98 virtual void ResizeToView(); |
| 73 | 99 |
| 100 // BrowserBubble::Delegate methods. |
| 101 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); |
| 102 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); |
| 103 virtual void BubbleGotFocus(BrowserBubble* bubble); |
| 104 virtual void BubbleLostFocus(BrowserBubble* bubble, |
| 105 bool lost_focus_to_child); |
| 106 |
| 74 // NotificationObserver overrides. | 107 // NotificationObserver overrides. |
| 75 virtual void Observe(NotificationType type, | 108 virtual void Observe(NotificationType type, |
| 76 const NotificationSource& source, | 109 const NotificationSource& source, |
| 77 const NotificationDetails& details); | 110 const NotificationDetails& details); |
| 78 | 111 |
| 79 // ExtensionView::Container overrides. | 112 // ExtensionView::Container overrides. |
| 80 virtual void OnExtensionMouseEvent(ExtensionView* view) { } | 113 virtual void OnExtensionMouseEvent(ExtensionView* view) { } |
| 81 virtual void OnExtensionMouseLeave(ExtensionView* view) { } | 114 virtual void OnExtensionMouseLeave(ExtensionView* view) { } |
| 82 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); | 115 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); |
| 83 | 116 |
| 84 // The min/max height of popups. | 117 // The min/max height of popups. |
| 85 static const int kMinWidth; | 118 static const int kMinWidth; |
| 86 static const int kMinHeight; | 119 static const int kMinHeight; |
| 87 static const int kMaxWidth; | 120 static const int kMaxWidth; |
| 88 static const int kMaxHeight; | 121 static const int kMaxHeight; |
| 89 | 122 |
| 90 private: | 123 private: |
| 91 ExtensionPopup(ExtensionHost* host, | 124 ExtensionPopup(ExtensionHost* host, |
| 92 views::Widget* frame, | 125 views::Widget* frame, |
| 93 const gfx::Rect& relative_to, | 126 const gfx::Rect& relative_to, |
| 94 BubbleBorder::ArrowLocation arrow_location, | 127 BubbleBorder::ArrowLocation arrow_location, |
| 95 bool activate_on_show, | 128 bool activate_on_show, |
| 96 PopupChrome chrome); | 129 bool inspect_with_devtools, |
| 130 PopupChrome chrome, |
| 131 Observer* observer); |
| 97 | 132 |
| 98 // Gives the desired bounds (in screen coordinates) given the rect to point | 133 // Gives the desired bounds (in screen coordinates) given the rect to point |
| 99 // to and the size of the contained contents. Includes all of the | 134 // to and the size of the contained contents. Includes all of the |
| 100 // border-chrome surrounding the pop-up as well. | 135 // border-chrome surrounding the pop-up as well. |
| 101 gfx::Rect GetOuterBounds(const gfx::Rect& position_relative_to, | 136 gfx::Rect GetOuterBounds(const gfx::Rect& position_relative_to, |
| 102 const gfx::Size& contents_size) const; | 137 const gfx::Size& contents_size) const; |
| 103 | 138 |
| 104 // The area on the screen that the popup should be positioned relative to. | 139 // The area on the screen that the popup should be positioned relative to. |
| 105 gfx::Rect relative_to_; | 140 gfx::Rect relative_to_; |
| 106 | 141 |
| 107 // The contained host for the view. | 142 // The contained host for the view. |
| 108 scoped_ptr<ExtensionHost> extension_host_; | 143 scoped_ptr<ExtensionHost> extension_host_; |
| 109 | 144 |
| 110 // Flag used to indicate if the pop-up should be activated upon first display. | 145 // Flag used to indicate if the pop-up should be activated upon first display. |
| 111 bool activate_on_show_; | 146 bool activate_on_show_; |
| 112 | 147 |
| 148 // Flag used to indicate if the pop-up should open a devtools window once |
| 149 // it is shown inspecting it. |
| 150 bool inspect_with_devtools_; |
| 151 |
| 152 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls. |
| 153 bool close_on_lost_focus_; |
| 154 |
| 155 // Whether the ExtensionPopup is current going about closing itself. |
| 156 bool closing_; |
| 157 |
| 113 NotificationRegistrar registrar_; | 158 NotificationRegistrar registrar_; |
| 114 | 159 |
| 115 // A separate widget and associated pieces to draw a border behind the | 160 // A separate widget and associated pieces to draw a border behind the |
| 116 // popup. This has to be a separate window in order to support transparency. | 161 // popup. This has to be a separate window in order to support transparency. |
| 117 // Layered windows can't contain native child windows, so we wouldn't be | 162 // Layered windows can't contain native child windows, so we wouldn't be |
| 118 // able to have the ExtensionView child. | 163 // able to have the ExtensionView child. |
| 119 views::Widget* border_widget_; | 164 views::Widget* border_widget_; |
| 120 BubbleBorder* border_; | 165 BubbleBorder* border_; |
| 121 views::View* border_view_; | 166 views::View* border_view_; |
| 122 | 167 |
| 123 // The type of chrome associated with the popup window. | 168 // The type of chrome associated with the popup window. |
| 124 PopupChrome popup_chrome_; | 169 PopupChrome popup_chrome_; |
| 125 | 170 |
| 171 // The observer of this popup. |
| 172 Observer* observer_; |
| 173 |
| 126 // A cached copy of the arrow-position for the bubble chrome. | 174 // A cached copy of the arrow-position for the bubble chrome. |
| 127 // If a black-border was requested, we still need this value to determine | 175 // If a black-border was requested, we still need this value to determine |
| 128 // the position of the pop-up in relation to |relative_to_|. | 176 // the position of the pop-up in relation to |relative_to_|. |
| 129 BubbleBorder::ArrowLocation anchor_position_; | 177 BubbleBorder::ArrowLocation anchor_position_; |
| 130 | 178 |
| 131 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); | 179 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); |
| 132 }; | 180 }; |
| 133 | 181 |
| 134 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ | 182 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ |
| OLD | NEW |