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_BROWSER_WINDOW_COCOA_H_ 6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_ 7 8 #include "base/mac/scoped_nsobject.h" 9 #include "base/memory/weak_ptr.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/extensions/extension_keybinding_registry.h" 12 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/search/search_model_observer.h" 14 #include "ui/base/ui_base_types.h" 15 16 class Browser; 17 @class BrowserWindowController; 18 @class FindBarCocoaController; 19 @class NSEvent; 20 @class NSMenu; 21 @class NSWindow; 22 23 namespace extensions { 24 class ActiveTabPermissionGranter; 25 class Extension; 26 } 27 28 // An implementation of BrowserWindow for Cocoa. Bridges between C++ and 29 // the Cocoa NSWindow. Cross-platform code will interact with this object when 30 // it needs to manipulate the window. 31 32 class BrowserWindowCocoa : 33 public BrowserWindow, 34 public extensions::ExtensionKeybindingRegistry::Delegate, 35 public SearchModelObserver { 36 public: 37 BrowserWindowCocoa(Browser* browser, 38 BrowserWindowController* controller); 39 virtual ~BrowserWindowCocoa(); 40 41 // Overridden from BrowserWindow 42 virtual void Show() OVERRIDE; 43 virtual void ShowInactive() OVERRIDE; 44 virtual void Hide() OVERRIDE; 45 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; 46 virtual void Close() OVERRIDE; 47 virtual void Activate() OVERRIDE; 48 virtual void Deactivate() OVERRIDE; 49 virtual bool IsActive() const OVERRIDE; 50 virtual void FlashFrame(bool flash) OVERRIDE; 51 virtual bool IsAlwaysOnTop() const OVERRIDE; 52 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; 53 virtual BrowserWindowTesting* GetBrowserWindowTesting() OVERRIDE; 54 virtual StatusBubble* GetStatusBubble() OVERRIDE; 55 virtual void UpdateTitleBar() OVERRIDE; 56 virtual void BookmarkBarStateChanged( 57 BookmarkBar::AnimateChangeType change_type) OVERRIDE; 58 virtual void UpdateDevTools() OVERRIDE; 59 virtual void UpdateLoadingAnimations(bool should_animate) OVERRIDE; 60 virtual void SetStarredState(bool is_starred) OVERRIDE; 61 virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE; 62 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; 63 virtual ui::WindowShowState GetRestoredState() const OVERRIDE; 64 virtual gfx::Rect GetBounds() const OVERRIDE; 65 virtual bool IsMaximized() const OVERRIDE; 66 virtual bool IsMinimized() const OVERRIDE; 67 virtual void Maximize() OVERRIDE; 68 virtual void Minimize() OVERRIDE; 69 virtual void Restore() OVERRIDE; 70 virtual void EnterFullscreen( 71 const GURL& url, FullscreenExitBubbleType type) OVERRIDE; 72 virtual void ExitFullscreen() OVERRIDE; 73 virtual void UpdateFullscreenExitBubbleContent( 74 const GURL& url, 75 FullscreenExitBubbleType bubble_type) OVERRIDE; 76 virtual bool ShouldHideUIForFullscreen() const OVERRIDE; 77 virtual bool IsFullscreen() const OVERRIDE; 78 virtual bool IsFullscreenBubbleVisible() const OVERRIDE; 79 virtual LocationBar* GetLocationBar() const OVERRIDE; 80 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 81 virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE; 82 virtual void UpdateToolbar(content::WebContents* contents, 83 bool should_restore_state) OVERRIDE; 84 virtual void FocusToolbar() OVERRIDE; 85 virtual void FocusAppMenu() OVERRIDE; 86 virtual void FocusBookmarksToolbar() OVERRIDE; 87 virtual void FocusInfobars() OVERRIDE; 88 virtual void RotatePaneFocus(bool forwards) OVERRIDE; 89 virtual bool IsBookmarkBarVisible() const OVERRIDE; 90 virtual bool IsBookmarkBarAnimating() const OVERRIDE; 91 virtual bool IsTabStripEditable() const OVERRIDE; 92 virtual bool IsToolbarVisible() const OVERRIDE; 93 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; 94 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, 95 Profile* profile) OVERRIDE; 96 virtual void ToggleBookmarkBar() OVERRIDE; 97 virtual void ShowUpdateChromeDialog() OVERRIDE; 98 virtual void ShowBookmarkBubble(const GURL& url, 99 bool already_bookmarked) OVERRIDE; 100 #if defined(ENABLE_ONE_CLICK_SIGNIN) 101 virtual void ShowOneClickSigninBubble( 102 OneClickSigninBubbleType type, 103 const string16& email, 104 const string16& error_message, 105 const StartSyncCallback& start_sync_callback) OVERRIDE; 106 #endif 107 virtual bool IsDownloadShelfVisible() const OVERRIDE; 108 virtual DownloadShelf* GetDownloadShelf() OVERRIDE; 109 virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE; 110 virtual void UserChangedTheme() OVERRIDE; 111 virtual int GetExtraRenderViewHeight() const OVERRIDE; 112 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE; 113 virtual void ShowWebsiteSettings(Profile* profile, 114 content::WebContents* web_contents, 115 const GURL& url, 116 const content::SSLStatus& ssl) OVERRIDE; 117 virtual void ShowAppMenu() OVERRIDE; 118 virtual bool PreHandleKeyboardEvent( 119 const content::NativeWebKeyboardEvent& event, 120 bool* is_keyboard_shortcut) OVERRIDE; 121 virtual void HandleKeyboardEvent( 122 const content::NativeWebKeyboardEvent& event) OVERRIDE; 123 virtual void ShowCreateChromeAppShortcutsDialog( 124 Profile* profile, 125 const extensions::Extension* app) OVERRIDE; 126 virtual void Cut() OVERRIDE; 127 virtual void Copy() OVERRIDE; 128 virtual void Paste() OVERRIDE; 129 virtual void OpenTabpose() OVERRIDE; 130 virtual void EnterFullscreenWithChrome() OVERRIDE; 131 virtual bool IsFullscreenWithChrome() OVERRIDE; 132 virtual bool IsFullscreenWithoutChrome() OVERRIDE; 133 virtual WindowOpenDisposition GetDispositionForPopupBounds( 134 const gfx::Rect& bounds) OVERRIDE; 135 virtual FindBar* CreateFindBar() OVERRIDE; 136 virtual web_modal::WebContentsModalDialogHost* 137 GetWebContentsModalDialogHost() OVERRIDE; 138 virtual void ShowAvatarBubble(content::WebContents* web_contents, 139 const gfx::Rect& rect) OVERRIDE; 140 virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE; 141 virtual void ShowPasswordGenerationBubble( 142 const gfx::Rect& rect, 143 const content::PasswordForm& form, 144 autofill::PasswordGenerator* password_generator) OVERRIDE; 145 146 // Overridden from ExtensionKeybindingRegistry::Delegate: 147 virtual extensions::ActiveTabPermissionGranter* 148 GetActiveTabPermissionGranter() OVERRIDE; 149 150 // Overridden from SearchModelObserver: 151 virtual void ModelChanged(const SearchModel::State& old_state, 152 const SearchModel::State& new_state) OVERRIDE; 153 154 // Adds the given FindBar cocoa controller to this browser window. 155 void AddFindBar(FindBarCocoaController* find_bar_cocoa_controller); 156 157 // Returns the cocoa-world BrowserWindowController 158 BrowserWindowController* cocoa_controller() { return controller_; } 159 160 protected: 161 virtual void DestroyBrowser() OVERRIDE; 162 163 private: 164 NSWindow* window() const; // Accessor for the (current) |NSWindow|. 165 166 Browser* browser_; // weak, owned by controller 167 BrowserWindowController* controller_; // weak, owns us 168 base::WeakPtrFactory<Browser> confirm_close_factory_; 169 base::scoped_nsobject<NSString> pending_window_title_; 170 ui::WindowShowState initial_show_state_; 171 NSInteger attention_request_id_; // identifier from requestUserAttention 172 }; 173 174 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_ 175