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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_COCOA_PANELS_PANEL_COCOA_H_ 6 #define CHROME_BROWSER_UI_COCOA_PANELS_PANEL_COCOA_H_ 7 8 #import <Foundation/Foundation.h> 9 #include "base/memory/scoped_ptr.h" 10 #include "chrome/browser/ui/panels/native_panel.h" 11 #include "ui/gfx/rect.h" 12 13 class Panel; 14 @class PanelWindowControllerCocoa; 15 16 // An implememtation of the native panel in Cocoa. 17 // Bridges between C++ and the Cocoa NSWindow. Cross-platform code will 18 // interact with this object when it needs to manipulate the window. 19 class PanelCocoa : public NativePanel { 20 public: 21 PanelCocoa(Panel* panel, const gfx::Rect& bounds, bool always_on_top); 22 virtual ~PanelCocoa(); 23 24 // Overridden from NativePanel 25 virtual void ShowPanel() OVERRIDE; 26 virtual void ShowPanelInactive() OVERRIDE; 27 virtual gfx::Rect GetPanelBounds() const OVERRIDE; 28 virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE; 29 virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE; 30 virtual void ClosePanel() OVERRIDE; 31 virtual void ActivatePanel() OVERRIDE; 32 virtual void DeactivatePanel() OVERRIDE; 33 virtual bool IsPanelActive() const OVERRIDE; 34 virtual void PreventActivationByOS(bool prevent_activation) OVERRIDE; 35 virtual gfx::NativeWindow GetNativePanelWindow() OVERRIDE; 36 virtual void UpdatePanelTitleBar() OVERRIDE; 37 virtual void UpdatePanelLoadingAnimations(bool should_animate) OVERRIDE; 38 virtual void PanelWebContentsFocused(content::WebContents* contents) OVERRIDE; 39 virtual void PanelCut() OVERRIDE; 40 virtual void PanelCopy() OVERRIDE; 41 virtual void PanelPaste() OVERRIDE; 42 virtual void DrawAttention(bool draw_attention) OVERRIDE; 43 virtual bool IsDrawingAttention() const OVERRIDE; 44 virtual void HandlePanelKeyboardEvent( 45 const content::NativeWebKeyboardEvent& event) OVERRIDE; 46 virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE; 47 virtual bool IsPanelAlwaysOnTop() const OVERRIDE; 48 virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; 49 virtual void EnableResizeByMouse(bool enable) OVERRIDE; 50 virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; 51 virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; 52 virtual void PanelExpansionStateChanging( 53 Panel::ExpansionState old_state, 54 Panel::ExpansionState new_state) OVERRIDE; 55 virtual void AttachWebContents(content::WebContents* contents) OVERRIDE; 56 virtual void DetachWebContents(content::WebContents* contents) OVERRIDE; 57 58 // These sizes are in screen coordinates. 59 virtual gfx::Size WindowSizeFromContentSize( 60 const gfx::Size& content_size) const OVERRIDE; 61 virtual gfx::Size ContentSizeFromWindowSize( 62 const gfx::Size& window_size) const OVERRIDE; 63 virtual int TitleOnlyHeight() const OVERRIDE; 64 65 virtual void MinimizePanelBySystem() OVERRIDE; 66 virtual bool IsPanelMinimizedBySystem() const OVERRIDE; 67 virtual bool IsPanelShownOnActiveDesktop() const OVERRIDE; 68 virtual void ShowShadow(bool show) OVERRIDE; 69 virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; 70 71 Panel* panel() const; 72 void DidCloseNativeWindow(); 73 74 bool IsClosed() const; 75 76 // PanelStackWindowCocoa might want to update the stored bounds directly since 77 // it has already taken care of updating the window bounds directly. 78 void set_cached_bounds_directly(const gfx::Rect& bounds) { bounds_ = bounds; } 79 80 private: 81 friend class CocoaNativePanelTesting; 82 friend class PanelCocoaTest; 83 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, CreateClose); 84 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, NativeBounds); 85 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewCreate); 86 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewSizing); 87 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, TitlebarViewClose); 88 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, MenuItems); 89 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, KeyEvent); 90 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, ThemeProvider); 91 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, SetTitle); 92 FRIEND_TEST_ALL_PREFIXES(PanelCocoaTest, ActivatePanel); 93 94 void setBoundsInternal(const gfx::Rect& bounds, bool animate); 95 96 scoped_ptr<Panel> panel_; 97 PanelWindowControllerCocoa* controller_; // Weak, owns us. 98 99 // These use platform-independent screen coordinates, with (0,0) at 100 // top-left of the primary screen. They have to be converted to Cocoa 101 // screen coordinates before calling Cocoa API. 102 gfx::Rect bounds_; 103 104 // True if the panel should always stay on top of other windows. 105 bool always_on_top_; 106 107 bool is_shown_; // Panel is hidden on creation, Show() changes that forever. 108 NSInteger attention_request_id_; // identifier from requestUserAttention. 109 110 // Indicates how the window corner should be rendered, rounded or not. 111 panel::CornerStyle corner_style_; 112 113 DISALLOW_COPY_AND_ASSIGN(PanelCocoa); 114 }; 115 116 #endif // CHROME_BROWSER_UI_COCOA_PANELS_PANEL_COCOA_H_ 117