| 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_PANELS_PANEL_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_H_ |
| 6 #define CHROME_BROWSER_UI_PANELS_PANEL_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/command_updater.h" | 13 #include "chrome/browser/command_updater.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "chrome/browser/ui/base_window.h" | 15 #include "chrome/browser/ui/base_window.h" |
| 16 #include "chrome/browser/ui/panels/panel_constants.h" | 16 #include "chrome/browser/ui/panels/panel_constants.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 20 | 20 |
| 21 class Browser; | |
| 22 class BrowserWindow; | |
| 23 class GURL; | 21 class GURL; |
| 24 class NativePanel; | 22 class NativePanel; |
| 25 class PanelHost; | 23 class PanelHost; |
| 26 class PanelManager; | 24 class PanelManager; |
| 27 class PanelStrip; | 25 class PanelStrip; |
| 28 class Profile; | 26 class Profile; |
| 29 | 27 |
| 30 namespace content { | 28 namespace content { |
| 31 class WebContents; | 29 class WebContents; |
| 32 struct NativeWebKeyboardEvent; | 30 struct NativeWebKeyboardEvent; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Returns the PanelManager associated with this panel. | 76 // Returns the PanelManager associated with this panel. |
| 79 PanelManager* manager() const; | 77 PanelManager* manager() const; |
| 80 | 78 |
| 81 const std::string& app_name() const { return app_name_; } | 79 const std::string& app_name() const { return app_name_; } |
| 82 const SessionID& session_id() const { return session_id_; } | 80 const SessionID& session_id() const { return session_id_; } |
| 83 extensions::WindowController* extension_window_controller() const { | 81 extensions::WindowController* extension_window_controller() const { |
| 84 return extension_window_controller_.get(); | 82 return extension_window_controller_.get(); |
| 85 } | 83 } |
| 86 const std::string extension_id() const; | 84 const std::string extension_id() const; |
| 87 | 85 |
| 88 virtual CommandUpdater* command_updater(); | 86 CommandUpdater* command_updater(); |
| 89 virtual Profile* profile() const; | 87 Profile* profile() const; |
| 90 | 88 |
| 91 // Returns web contents of the panel, if any. There may be none if web | 89 // Returns web contents of the panel, if any. There may be none if web |
| 92 // contents have not been added to the panel yet. | 90 // contents have not been added to the panel yet. |
| 93 virtual content::WebContents* GetWebContents() const; | 91 content::WebContents* GetWebContents() const; |
| 94 | 92 |
| 95 void SetExpansionState(ExpansionState new_expansion_state); | 93 void SetExpansionState(ExpansionState new_expansion_state); |
| 96 | 94 |
| 97 bool IsDrawingAttention() const; | 95 bool IsDrawingAttention() const; |
| 98 | 96 |
| 99 // This function will only get called by PanelManager when full screen mode | 97 // This function will only get called by PanelManager when full screen mode |
| 100 // changes i.e it gets called when an app goes into full screen mode or when | 98 // changes i.e it gets called when an app goes into full screen mode or when |
| 101 // an app exits full screen mode. Panel should respond by making sure | 99 // an app exits full screen mode. Panel should respond by making sure |
| 102 // a) it does not go on top when some app enters full screen mode. | 100 // a) it does not go on top when some app enters full screen mode. |
| 103 // b) it remains on top when an app exits full screen mode. | 101 // b) it remains on top when an app exits full screen mode. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // Overridden from CommandUpdater::CommandUpdaterDelegate: | 135 // Overridden from CommandUpdater::CommandUpdaterDelegate: |
| 138 virtual void ExecuteCommandWithDisposition( | 136 virtual void ExecuteCommandWithDisposition( |
| 139 int id, | 137 int id, |
| 140 WindowOpenDisposition disposition) OVERRIDE; | 138 WindowOpenDisposition disposition) OVERRIDE; |
| 141 | 139 |
| 142 // content::NotificationObserver overrides. | 140 // content::NotificationObserver overrides. |
| 143 virtual void Observe(int type, | 141 virtual void Observe(int type, |
| 144 const content::NotificationSource& source, | 142 const content::NotificationSource& source, |
| 145 const content::NotificationDetails& details) OVERRIDE; | 143 const content::NotificationDetails& details) OVERRIDE; |
| 146 | 144 |
| 147 // Construct a native panel BrowserWindow implementation for the specified | |
| 148 // |browser|. (legacy) | |
| 149 static NativePanel* CreateNativePanel(Browser* browser, | |
| 150 Panel* panel, | |
| 151 const gfx::Rect& bounds); | |
| 152 | |
| 153 // Construct a native panel implementation. | 145 // Construct a native panel implementation. |
| 154 static NativePanel* CreateNativePanel(Panel* panel, | 146 static NativePanel* CreateNativePanel(Panel* panel, |
| 155 const gfx::Rect& bounds); | 147 const gfx::Rect& bounds); |
| 156 | 148 |
| 157 NativePanel* native_panel() const { return native_panel_; } | 149 NativePanel* native_panel() const { return native_panel_; } |
| 158 | 150 |
| 159 // Invoked when the native panel has detected a mouse click on the | 151 // Invoked when the native panel has detected a mouse click on the |
| 160 // panel's titlebar, minimize or restore buttons. Behavior of the | 152 // panel's titlebar, minimize or restore buttons. Behavior of the |
| 161 // click may be modified as indicated by |modifier|. | 153 // click may be modified as indicated by |modifier|. |
| 162 void OnTitlebarClicked(panel::ClickModifier modifier); | 154 void OnTitlebarClicked(panel::ClickModifier modifier); |
| 163 void OnMinimizeButtonClicked(panel::ClickModifier modifier); | 155 void OnMinimizeButtonClicked(panel::ClickModifier modifier); |
| 164 void OnRestoreButtonClicked(panel::ClickModifier modifier); | 156 void OnRestoreButtonClicked(panel::ClickModifier modifier); |
| 165 | 157 |
| 166 // Used on platforms where the panel cannot determine its window size | 158 // Used on platforms where the panel cannot determine its window size |
| 167 // until the window has been created. (e.g. GTK) | 159 // until the window has been created. (e.g. GTK) |
| 168 void OnWindowSizeAvailable(); | 160 void OnWindowSizeAvailable(); |
| 169 | 161 |
| 170 // Asynchronous completion of panel close request. | 162 // Asynchronous completion of panel close request. |
| 171 void OnNativePanelClosed(); | 163 void OnNativePanelClosed(); |
| 172 | 164 |
| 173 // Legacy accessors. | |
| 174 virtual Browser* browser() const; | |
| 175 virtual BrowserWindow* browser_window() const; | |
| 176 | |
| 177 // May be NULL if: | 165 // May be NULL if: |
| 178 // * panel is newly created and has not been positioned yet. | 166 // * panel is newly created and has not been positioned yet. |
| 179 // * panel is being closed asynchronously. | 167 // * panel is being closed asynchronously. |
| 180 // Please use it with caution. | 168 // Please use it with caution. |
| 181 PanelStrip* panel_strip() const { return panel_strip_; } | 169 PanelStrip* panel_strip() const { return panel_strip_; } |
| 182 | 170 |
| 183 // Sets the current panel strip that contains this panel. | 171 // Sets the current panel strip that contains this panel. |
| 184 void set_panel_strip(PanelStrip* new_strip) { panel_strip_ = new_strip; } | 172 void set_panel_strip(PanelStrip* new_strip) { panel_strip_ = new_strip; } |
| 185 | 173 |
| 186 ExpansionState expansion_state() const { return expansion_state_; } | 174 ExpansionState expansion_state() const { return expansion_state_; } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 } | 186 } |
| 199 | 187 |
| 200 // The full size is the size of the panel when it is detached or expanded | 188 // The full size is the size of the panel when it is detached or expanded |
| 201 // in the docked strip and squeezing mode is not on. | 189 // in the docked strip and squeezing mode is not on. |
| 202 gfx::Size full_size() const { return full_size_; } | 190 gfx::Size full_size() const { return full_size_; } |
| 203 void set_full_size(const gfx::Size& size) { full_size_ = size; } | 191 void set_full_size(const gfx::Size& size) { full_size_ = size; } |
| 204 | 192 |
| 205 // Panel must be initialized to be "fully created" and ready for use. | 193 // Panel must be initialized to be "fully created" and ready for use. |
| 206 // Only called by PanelManager. | 194 // Only called by PanelManager. |
| 207 bool initialized() const { return initialized_; } | 195 bool initialized() const { return initialized_; } |
| 208 virtual void Initialize(const gfx::Rect& bounds, Browser* browser); // legacy | 196 void Initialize(Profile* profile, const GURL& url, const gfx::Rect& bounds); |
| 209 virtual void Initialize(Profile* profile, const GURL& url, | |
| 210 const gfx::Rect& bounds); | |
| 211 | 197 |
| 212 // This is different from BrowserWindow::SetBounds(): | 198 // This is different from BaseWindow::SetBounds(): |
| 213 // * SetPanelBounds() is only called by PanelManager to manage its position. | 199 // * SetPanelBounds() is only called by PanelManager to manage its position. |
| 214 // * SetBounds() is called by the API to try to change the bounds, which is | 200 // * SetBounds() is called by the API to try to change the bounds, which may |
| 215 // not allowed for Panel. | 201 // only change the size for Panel. |
| 216 void SetPanelBounds(const gfx::Rect& bounds); | 202 void SetPanelBounds(const gfx::Rect& bounds); |
| 217 | 203 |
| 218 // Updates the panel bounds instantly without any animation. | 204 // Updates the panel bounds instantly without any animation. |
| 219 void SetPanelBoundsInstantly(const gfx::Rect& bounds); | 205 void SetPanelBoundsInstantly(const gfx::Rect& bounds); |
| 220 | 206 |
| 221 // Ensures that the panel's size does not exceed the display area by | 207 // Ensures that the panel's size does not exceed the display area by |
| 222 // updating maximum and full size of the panel. This is called each time | 208 // updating maximum and full size of the panel. This is called each time |
| 223 // when display settings are changed. Note that bounds are not updated here | 209 // when display settings are changed. Note that bounds are not updated here |
| 224 // and the call of setting bounds or refreshing layout should be called after | 210 // and the call of setting bounds or refreshing layout should be called after |
| 225 // this. | 211 // this. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 259 |
| 274 // Called when the panel's active state changes. | 260 // Called when the panel's active state changes. |
| 275 // |active| is true if panel became active. | 261 // |active| is true if panel became active. |
| 276 void OnActiveStateChanged(bool active); | 262 void OnActiveStateChanged(bool active); |
| 277 | 263 |
| 278 // Called when the panel starts/ends the user resizing. | 264 // Called when the panel starts/ends the user resizing. |
| 279 void OnPanelStartUserResizing(); | 265 void OnPanelStartUserResizing(); |
| 280 void OnPanelEndUserResizing(); | 266 void OnPanelEndUserResizing(); |
| 281 | 267 |
| 282 // Gives beforeunload handlers the chance to cancel the close. | 268 // Gives beforeunload handlers the chance to cancel the close. |
| 283 virtual bool ShouldCloseWindow(); | 269 bool ShouldCloseWindow(); |
| 284 | 270 |
| 285 // Invoked when the window containing us is closing. Performs the necessary | 271 // Invoked when the window containing us is closing. Performs the necessary |
| 286 // cleanup. | 272 // cleanup. |
| 287 virtual void OnWindowClosing(); | 273 void OnWindowClosing(); |
| 288 | 274 |
| 289 // Executes a command if it's enabled. | 275 // Executes a command if it's enabled. |
| 290 // Returns true if the command is executed. | 276 // Returns true if the command is executed. |
| 291 bool ExecuteCommandIfEnabled(int id); | 277 bool ExecuteCommandIfEnabled(int id); |
| 292 | 278 |
| 293 // Gets the title of the window from the web contents. | 279 // Gets the title of the window from the web contents. |
| 294 string16 GetWindowTitle() const; | 280 string16 GetWindowTitle() const; |
| 295 | 281 |
| 296 // Gets the Favicon of the web contents. | 282 // Gets the Favicon of the web contents. |
| 297 virtual gfx::Image GetCurrentPageIcon() const; | 283 gfx::Image GetCurrentPageIcon() const; |
| 298 | 284 |
| 299 // Updates the title bar to display the current title and icon. | 285 // Updates the title bar to display the current title and icon. |
| 300 void UpdateTitleBar(); | 286 void UpdateTitleBar(); |
| 301 | 287 |
| 302 // Updates UI to reflect change in loading state. | 288 // Updates UI to reflect change in loading state. |
| 303 void LoadingStateChanged(bool is_loading); | 289 void LoadingStateChanged(bool is_loading); |
| 304 | 290 |
| 305 // Updates UI to reflect that the web cotents receives the focus. | 291 // Updates UI to reflect that the web cotents receives the focus. |
| 306 void WebContentsFocused(content::WebContents* contents); | 292 void WebContentsFocused(content::WebContents* contents); |
| 307 | 293 |
| 308 protected: | 294 protected: |
| 309 // Panel can only be created using PanelManager::CreatePanel() or subclass. | 295 // Panel can only be created using PanelManager::CreatePanel() or subclass. |
| 310 // |app_name| is the default title for Panels when the page content does not | 296 // |app_name| is the default title for Panels when the page content does not |
| 311 // provide a title. For extensions, this is usually the application name | 297 // provide a title. For extensions, this is usually the application name |
| 312 // generated from the extension id. | 298 // generated from the extension id. |
| 313 Panel(const std::string& app_name, | 299 Panel(const std::string& app_name, |
| 314 const gfx::Size& min_size, const gfx::Size& max_size); | 300 const gfx::Size& min_size, const gfx::Size& max_size); |
| 315 | 301 |
| 316 private: | 302 private: |
| 317 friend class PanelManager; | 303 friend class PanelManager; |
| 318 friend class PanelBrowserTest; | 304 friend class PanelBrowserTest; |
| 319 friend class OldPanelBrowserTest; | |
| 320 | 305 |
| 321 enum MaxSizePolicy { | 306 enum MaxSizePolicy { |
| 322 // Default maximum size is proportional to the work area. | 307 // Default maximum size is proportional to the work area. |
| 323 DEFAULT_MAX_SIZE, | 308 DEFAULT_MAX_SIZE, |
| 324 // Custom maximum size is used when the panel is resized by the user. | 309 // Custom maximum size is used when the panel is resized by the user. |
| 325 CUSTOM_MAX_SIZE | 310 CUSTOM_MAX_SIZE |
| 326 }; | 311 }; |
| 327 | 312 |
| 328 // Initialize state for all supported commands. | 313 // Initialize state for all supported commands. |
| 329 void InitCommandState(); | 314 void InitCommandState(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // True if this panel should always stay on top of other windows. | 351 // True if this panel should always stay on top of other windows. |
| 367 bool always_on_top_; | 352 bool always_on_top_; |
| 368 | 353 |
| 369 // True if this panel is in preview mode. When in preview mode, panel bounds | 354 // True if this panel is in preview mode. When in preview mode, panel bounds |
| 370 // should not be affected by layout refresh. This is currently used by drag | 355 // should not be affected by layout refresh. This is currently used by drag |
| 371 // controller to add a panel to the strip without causing its bounds to | 356 // controller to add a panel to the strip without causing its bounds to |
| 372 // change. | 357 // change. |
| 373 bool in_preview_mode_; | 358 bool in_preview_mode_; |
| 374 | 359 |
| 375 // Platform specifc implementation for panels. It'd be one of | 360 // Platform specifc implementation for panels. It'd be one of |
| 376 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. | 361 // PanelGtk/PanelView/PanelCocoa. |
| 377 NativePanel* native_panel_; // Weak, owns us. | 362 NativePanel* native_panel_; // Weak, owns us. |
| 378 | 363 |
| 379 AttentionMode attention_mode_; | 364 AttentionMode attention_mode_; |
| 380 | 365 |
| 381 ExpansionState expansion_state_; | 366 ExpansionState expansion_state_; |
| 382 | 367 |
| 383 // The CommandUpdater manages the window commands. | 368 // The CommandUpdater manages the window commands. |
| 384 CommandUpdater command_updater_; | 369 CommandUpdater command_updater_; |
| 385 | 370 |
| 386 content::NotificationRegistrar registrar_; | 371 content::NotificationRegistrar registrar_; |
| 387 const SessionID session_id_; | 372 const SessionID session_id_; |
| 388 scoped_ptr<extensions::WindowController> extension_window_controller_; | 373 scoped_ptr<extensions::WindowController> extension_window_controller_; |
| 389 scoped_ptr<PanelHost> panel_host_; | 374 scoped_ptr<PanelHost> panel_host_; |
| 390 | 375 |
| 391 DISALLOW_COPY_AND_ASSIGN(Panel); | 376 DISALLOW_COPY_AND_ASSIGN(Panel); |
| 392 }; | 377 }; |
| 393 | 378 |
| 394 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ | 379 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ |
| OLD | NEW |