1 // Copyright (c) 2011 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_BROWSER_WINDOW_COCOA_H_ 6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_ 7 #pragma once 8 9 #include "base/memory/scoped_nsobject.h" 10 #include "base/task.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/ui/browser_window.h" 13 #include "content/common/notification_registrar.h" 14 15 class Browser; 16 @class BrowserWindowController; 17 @class FindBarCocoaController; 18 @class NSEvent; 19 @class NSMenu; 20 @class NSWindow; 21 22 // An implementation of BrowserWindow for Cocoa. Bridges between C++ and 23 // the Cocoa NSWindow. Cross-platform code will interact with this object when 24 // it needs to manipulate the window. 25 26 class BrowserWindowCocoa : public BrowserWindow, 27 public NotificationObserver { 28 public: 29 BrowserWindowCocoa(Browser* browser, 30 BrowserWindowController* controller, 31 NSWindow* window); 32 virtual ~BrowserWindowCocoa(); 33 34 // Overridden from BrowserWindow 35 virtual void Show(); 36 virtual void ShowInactive(); 37 virtual void SetBounds(const gfx::Rect& bounds); 38 virtual void Close(); 39 virtual void Activate(); 40 virtual void Deactivate(); 41 virtual bool IsActive() const; 42 virtual void FlashFrame(); 43 virtual gfx::NativeWindow GetNativeHandle(); 44 virtual BrowserWindowTesting* GetBrowserWindowTesting(); 45 virtual StatusBubble* GetStatusBubble(); 46 virtual void ToolbarSizeChanged(bool is_animating); 47 virtual void UpdateTitleBar(); 48 virtual void ShelfVisibilityChanged(); 49 virtual void UpdateDevTools(); 50 virtual void UpdateLoadingAnimations(bool should_animate); 51 virtual void SetStarredState(bool is_starred); 52 virtual gfx::Rect GetRestoredBounds() const; 53 virtual gfx::Rect GetBounds() const; 54 virtual bool IsMaximized() const; 55 virtual void SetFullscreen(bool fullscreen); 56 virtual bool IsFullscreen() const; 57 virtual bool IsFullscreenBubbleVisible() const; 58 virtual LocationBar* GetLocationBar() const; 59 virtual void SetFocusToLocationBar(bool select_all); 60 virtual void UpdateReloadStopState(bool is_loading, bool force); 61 virtual void UpdateToolbar(TabContentsWrapper* contents, 62 bool should_restore_state); 63 virtual void FocusToolbar(); 64 virtual void FocusAppMenu(); 65 virtual void FocusBookmarksToolbar(); 66 virtual void FocusChromeOSStatus(); 67 virtual void RotatePaneFocus(bool forwards); 68 virtual bool IsBookmarkBarVisible() const; 69 virtual bool IsBookmarkBarAnimating() const; 70 virtual bool IsTabStripEditable() const; 71 virtual bool IsToolbarVisible() const; 72 virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, 73 Profile* profile); 74 virtual void ToggleBookmarkBar(); 75 virtual void ShowAboutChromeDialog(); 76 virtual void ShowUpdateChromeDialog(); 77 virtual void ShowTaskManager(); 78 virtual void ShowBackgroundPages(); 79 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked); 80 virtual bool IsDownloadShelfVisible() const; 81 virtual DownloadShelf* GetDownloadShelf(); 82 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); 83 virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); 84 virtual void ShowThemeInstallBubble(); 85 virtual void ConfirmBrowserCloseWithPendingDownloads(); 86 virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate, 87 gfx::NativeWindow parent_window); 88 virtual void UserChangedTheme(); 89 virtual int GetExtraRenderViewHeight() const; 90 virtual void TabContentsFocused(TabContents* tab_contents); 91 virtual void ShowPageInfo(Profile* profile, 92 const GURL& url, 93 const NavigationEntry::SSLStatus& ssl, 94 bool show_history); 95 virtual void ShowAppMenu(); 96 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 97 bool* is_keyboard_shortcut); 98 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); 99 virtual void ShowCreateWebAppShortcutsDialog( 100 TabContentsWrapper* tab_contents); 101 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile, 102 const Extension* app); 103 virtual void Cut(); 104 virtual void Copy(); 105 virtual void Paste(); 106 virtual void ToggleTabStripMode(); 107 virtual void OpenTabpose(); 108 virtual void PrepareForInstant(); 109 virtual void ShowInstant(TabContentsWrapper* preview); 110 virtual void HideInstant(bool instant_is_active); 111 virtual gfx::Rect GetInstantBounds(); 112 113 // Overridden from NotificationObserver 114 virtual void Observe(NotificationType type, 115 const NotificationSource& source, 116 const NotificationDetails& details); 117 118 // Adds the given FindBar cocoa controller to this browser window. 119 void AddFindBar(FindBarCocoaController* find_bar_cocoa_controller); 120 121 // Returns the cocoa-world BrowserWindowController 122 BrowserWindowController* cocoa_controller() { return controller_; } 123 124 protected: 125 virtual void DestroyBrowser(); 126 127 private: 128 int GetCommandId(const NativeWebKeyboardEvent& event); 129 bool HandleKeyboardEventInternal(NSEvent* event); 130 NSWindow* window() const; // Accessor for the (current) |NSWindow|. 131 void UpdateSidebarForContents(TabContents* tab_contents); 132 133 NotificationRegistrar registrar_; 134 Browser* browser_; // weak, owned by controller 135 BrowserWindowController* controller_; // weak, owns us 136 ScopedRunnableMethodFactory<Browser> confirm_close_factory_; 137 scoped_nsobject<NSString> pending_window_title_; 138 }; 139 140 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_ 141