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
3 // found in the LICENSE file.
5 #include "base/gfx/rect.h"
6 #include "base/logging.h"
7 #include "chrome/browser/cocoa/browser_window_cocoa.h"
8 #include "chrome/browser/cocoa/browser_window_controller.h"
10 BrowserWindowCocoa::BrowserWindowCocoa(BrowserWindowController* controller,
12 : controller_(controller), window_(window) {
15 BrowserWindowCocoa::~BrowserWindowCocoa() {
18 void BrowserWindowCocoa::Init() {
21 void BrowserWindowCocoa::Show() {
22 [window_ makeKeyAndOrderFront:controller_];
25 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
26 NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0, bounds.width(),
29 NSScreen* screen = [window_ screen];
30 cocoa_bounds.origin.y =
31 [screen frame].size.height - bounds.height() - bounds.y();
34 // Callers assume that this doesn't immediately delete the Browser object.
35 // The controller implementing the window delegate methods called from
36 // |-performClose:| must take precautiions to ensure that.
37 void BrowserWindowCocoa::Close() {
38 [window_ orderOut:controller_];
39 [window_ performClose:controller_];
42 void BrowserWindowCocoa::Activate() {
43 [window_ makeKeyAndOrderFront:controller_];
46 void BrowserWindowCocoa::FlashFrame() {
47 [[NSApplication sharedApplication]
48 requestUserAttention:NSInformationalRequest];
51 void* BrowserWindowCocoa::GetNativeHandle() {
52 return [controller_ window];
55 BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
59 StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
63 void BrowserWindowCocoa::SelectedTabToolbarSizeChanged(bool is_animating) {
67 void BrowserWindowCocoa::UpdateTitleBar() {
71 void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
75 void BrowserWindowCocoa::SetStarredState(bool is_starred) {
76 [controller_ setStarredState:is_starred ? YES : NO];
79 gfx::Rect BrowserWindowCocoa::GetNormalBounds() const {
80 // TODO(pinkerton): not sure if we can get the non-zoomed bounds, or if it
81 // really matters. We may want to let Cocoa handle all this for us.
82 NSRect frame = [window_ frame];
83 NSScreen* screen = [window_ screen];
84 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
85 bounds.set_y([screen frame].size.height + frame.size.height + frame.origin.y);
89 bool BrowserWindowCocoa::IsMaximized() const {
90 return [window_ isZoomed];
93 void BrowserWindowCocoa::SetFullscreen(bool fullscreen) {
97 bool BrowserWindowCocoa::IsFullscreen() const {
102 gfx::Rect BrowserWindowCocoa::GetRootWindowResizerRect() const {
103 NSRect tabRect = [controller_ selectedTabGrowBoxRect];
104 return gfx::Rect(NSRectToCGRect(tabRect));
107 LocationBar* BrowserWindowCocoa::GetLocationBar() const {
108 return [controller_ locationBar];
111 void BrowserWindowCocoa::SetFocusToLocationBar() {
115 void BrowserWindowCocoa::UpdateStopGoState(bool is_loading) {
119 void BrowserWindowCocoa::UpdateToolbar(TabContents* contents,
120 bool should_restore_state) {
121 [controller_ updateToolbarWithContents:contents
122 shouldRestoreState:should_restore_state ? YES : NO];
125 void BrowserWindowCocoa::FocusToolbar() {
129 bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
134 void BrowserWindowCocoa::ToggleBookmarkBar() {
138 void BrowserWindowCocoa::ShowFindBar() {
142 void BrowserWindowCocoa::ShowAboutChromeDialog() {
146 void BrowserWindowCocoa::ShowBookmarkManager() {
150 void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
151 bool already_bookmarked) {
155 void BrowserWindowCocoa::ShowReportBugDialog() {
159 void BrowserWindowCocoa::ShowClearBrowsingDataDialog() {
163 void BrowserWindowCocoa::ShowImportDialog() {
167 void BrowserWindowCocoa::ShowSearchEnginesDialog() {
171 void BrowserWindowCocoa::ShowPasswordManager() {
175 void BrowserWindowCocoa::ShowSelectProfileDialog() {
179 void BrowserWindowCocoa::ShowNewProfileDialog() {
183 void BrowserWindowCocoa::ShowHTMLDialog(HtmlDialogContentsDelegate* delegate,
184 void* parent_window) {
188 void BrowserWindowCocoa::DestroyBrowser() {
189 [controller_ destroyBrowser];
191 // at this point the controller is dead (autoreleased), so
192 // make sure we don't try to reference it any more.