summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/cocoa')
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm22
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.mm35
-rw-r--r--chrome/browser/ui/cocoa/browser_window_utils.h14
-rw-r--r--chrome/browser/ui/cocoa/browser_window_utils.mm54
-rw-r--r--chrome/browser/ui/cocoa/chrome_browser_window.h9
-rw-r--r--chrome/browser/ui/cocoa/chrome_browser_window.mm23
-rw-r--r--chrome/browser/ui/cocoa/themed_browser_window.h19
-rw-r--r--chrome/browser/ui/cocoa/themed_browser_window.mm34
8 files changed, 132 insertions, 78 deletions
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index 784965f..19f1d3a 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -203,24 +203,10 @@ void BrowserWindowCocoa::UpdateTitleBar() {
NSString* newTitle =
base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
- // Work around Cocoa bug: if a window changes title during the tracking of the
- // Window menu it doesn't display well and the constant re-sorting of the list
- // makes it difficult for the user to pick the desired window. Delay window
- // title updates until the default run-loop mode.
-
- if (pending_window_title_.get())
- [[NSRunLoop currentRunLoop]
- cancelPerformSelector:@selector(setTitle:)
- target:window()
- argument:pending_window_title_.get()];
-
- pending_window_title_.reset([newTitle copy]);
- [[NSRunLoop currentRunLoop]
- performSelector:@selector(setTitle:)
- target:window()
- argument:newTitle
- order:0
- modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
+ pending_window_title_.reset(
+ [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get()
+ withNewTitle:newTitle
+ forWindow:window()]);
}
void BrowserWindowCocoa::BookmarkBarStateChanged(
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
index 5a7cdc2..6444bbc 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
@@ -35,6 +35,7 @@
#import "chrome/browser/ui/cocoa/browser/avatar_button.h"
#import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
#import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
+#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#import "chrome/browser/ui/cocoa/dev_tools_controller.h"
#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
#import "chrome/browser/ui/cocoa/event_utils.h"
@@ -1587,39 +1588,9 @@ enum {
}
- (NSPoint)themePatternPhase {
- // Our patterns want to be drawn from the upper left hand corner of the view.
- // Cocoa wants to do it from the lower left of the window.
- //
- // Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.)
- // will phase their patterns relative to this so all the views look right.
- //
- // To line up the background pattern with the pattern in the browser window
- // the background pattern for the tabs needs to be moved left by 5 pixels.
- const CGFloat kPatternHorizontalOffset = -5;
- // To match Windows and CrOS, have to offset vertically by 2 pixels.
- // Without tab strip, offset an extra pixel (determined by experimentation).
- const CGFloat kPatternVerticalOffset = 2;
- const CGFloat kPatternVerticalOffsetNoTabStrip = 3;
-
- // When we have a tab strip, line up with the top of the tab, otherwise,
- // line up with the top of the window.
NSView* windowChromeView = [[[self window] contentView] superview];
- if ([self hasTabStrip]) {
- NSView* tabStripView = [self tabStripView];
- NSRect tabStripViewWindowBounds = [tabStripView bounds];
- tabStripViewWindowBounds =
- [tabStripView convertRect:tabStripViewWindowBounds
- toView:windowChromeView];
- return NSMakePoint(NSMinX(tabStripViewWindowBounds)
- + kPatternHorizontalOffset,
- NSMinY(tabStripViewWindowBounds)
- + [TabStripController defaultTabHeight]
- + kPatternVerticalOffset);
- } else {
- return NSMakePoint(kPatternHorizontalOffset,
- NSHeight([windowChromeView bounds])
- + kPatternVerticalOffsetNoTabStrip);
- }
+ return [BrowserWindowUtils themePatternPhaseFor:windowChromeView
+ withTabStrip:[self tabStripView]];
}
- (NSPoint)bookmarkBubblePoint {
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.h b/chrome/browser/ui/cocoa/browser_window_utils.h
index 97d454f..6c6edcc 100644
--- a/chrome/browser/ui/cocoa/browser_window_utils.h
+++ b/chrome/browser/ui/cocoa/browser_window_utils.h
@@ -23,6 +23,20 @@ struct NativeWebKeyboardEvent;
// NSWindow must be a ChromeEventProcessingWindow.
+ (BOOL)handleKeyboardEvent:(NSEvent*)event
inWindow:(NSWindow*)window;
+
+// Schedule a window title change in the next run loop iteration. This works
+// around a Cocoa bug: if a window changes title during the tracking of the
+// Window menu it doesn't display well and the constant re-sorting of the list
+// makes it difficult for the user to pick the desired window.
+// Passing in a non-nil oldTitle will also cancel any pending title changes with
+// a matching window and title. This function returns a NSString* that can be
+// passed in future calls as oldTitle.
++ (NSString*)scheduleReplaceOldTitle:(NSString*)oldTitle
+ withNewTitle:(NSString*)newTitle
+ forWindow:(NSWindow*)window;
+
++ (NSPoint)themePatternPhaseFor:(NSView*)windowView
+ withTabStrip:(NSView*)tabStripView;
@end
#endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_UTILS_H_
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.mm b/chrome/browser/ui/cocoa/browser_window_utils.mm
index c028615..aea2e9b 100644
--- a/chrome/browser/ui/cocoa/browser_window_utils.mm
+++ b/chrome/browser/ui/cocoa/browser_window_utils.mm
@@ -10,6 +10,7 @@
#include "chrome/browser/ui/browser.h"
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
+#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#include "content/common/native_web_keyboard_event.h"
@interface MenuWalker : NSObject
@@ -121,4 +122,57 @@
return [event_window redispatchKeyEvent:event];
}
++ (NSString*)scheduleReplaceOldTitle:(NSString*)oldTitle
+ withNewTitle:(NSString*)newTitle
+ forWindow:(NSWindow*)window {
+ if (oldTitle)
+ [[NSRunLoop currentRunLoop]
+ cancelPerformSelector:@selector(setTitle:)
+ target:window
+ argument:oldTitle];
+
+ [[NSRunLoop currentRunLoop]
+ performSelector:@selector(setTitle:)
+ target:window
+ argument:newTitle
+ order:0
+ modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
+ return [newTitle copy];
+}
+
+// Our patterns want to be drawn from the upper left hand corner of the view.
+// Cocoa wants to do it from the lower left of the window.
+//
+// Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.)
+// will phase their patterns relative to this so all the views look right.
+//
+// To line up the background pattern with the pattern in the browser window
+// the background pattern for the tabs needs to be moved left by 5 pixels.
+const CGFloat kPatternHorizontalOffset = -5;
+// To match Windows and CrOS, have to offset vertically by 2 pixels.
+// Without tab strip, offset an extra pixel (determined by experimentation).
+const CGFloat kPatternVerticalOffset = 2;
+const CGFloat kPatternVerticalOffsetNoTabStrip = 3;
+
+
++ (NSPoint)themePatternPhaseFor:(NSView*)windowView
+ withTabStrip:(NSView*)tabStripView {
+ // When we have a tab strip, line up with the top of the tab, otherwise,
+ // line up with the top of the window.
+ if (!tabStripView)
+ return NSMakePoint(kPatternHorizontalOffset,
+ NSHeight([windowView bounds])
+ + kPatternVerticalOffsetNoTabStrip);
+
+ NSRect tabStripViewWindowBounds = [tabStripView bounds];
+ tabStripViewWindowBounds =
+ [tabStripView convertRect:tabStripViewWindowBounds
+ toView:windowView];
+ return NSMakePoint(NSMinX(tabStripViewWindowBounds)
+ + kPatternHorizontalOffset,
+ NSMinY(tabStripViewWindowBounds)
+ + [TabStripController defaultTabHeight]
+ + kPatternVerticalOffset);
+}
+
@end
diff --git a/chrome/browser/ui/cocoa/chrome_browser_window.h b/chrome/browser/ui/cocoa/chrome_browser_window.h
index 64c0123..1d247e6 100644
--- a/chrome/browser/ui/cocoa/chrome_browser_window.h
+++ b/chrome/browser/ui/cocoa/chrome_browser_window.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,12 +8,11 @@
#import <Cocoa/Cocoa.h>
-#include "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
+#include "chrome/browser/ui/cocoa/themed_browser_window.h"
// Common base class for chrome browser windows. Contains methods relating to
-// theming and hole punching that are shared between framed and fullscreen
-// windows.
-@interface ChromeBrowserWindow : ChromeEventProcessingWindow {
+// hole punching that are shared between framed and fullscreen windows.
+@interface ChromeBrowserWindow : ThemedBrowserWindow {
@private
int underlaySurfaceCount_;
}
diff --git a/chrome/browser/ui/cocoa/chrome_browser_window.mm b/chrome/browser/ui/cocoa/chrome_browser_window.mm
index e21507b..a6ef49c 100644
--- a/chrome/browser/ui/cocoa/chrome_browser_window.mm
+++ b/chrome/browser/ui/cocoa/chrome_browser_window.mm
@@ -5,8 +5,6 @@
#import "chrome/browser/ui/cocoa/chrome_browser_window.h"
#include "base/logging.h"
-#import "chrome/browser/ui/cocoa/themed_window.h"
-#include "ui/base/theme_provider.h"
@implementation ChromeBrowserWindow
@@ -28,25 +26,4 @@
[self setOpaque:YES];
}
-- (ui::ThemeProvider*)themeProvider {
- id delegate = [self delegate];
- if (![delegate respondsToSelector:@selector(themeProvider)])
- return NULL;
- return [delegate themeProvider];
-}
-
-- (ThemedWindowStyle)themedWindowStyle {
- id delegate = [self delegate];
- if (![delegate respondsToSelector:@selector(themedWindowStyle)])
- return THEMED_NORMAL;
- return [delegate themedWindowStyle];
-}
-
-- (NSPoint)themePatternPhase {
- id delegate = [self delegate];
- if (![delegate respondsToSelector:@selector(themePatternPhase)])
- return NSMakePoint(0, 0);
- return [delegate themePatternPhase];
-}
-
@end
diff --git a/chrome/browser/ui/cocoa/themed_browser_window.h b/chrome/browser/ui/cocoa/themed_browser_window.h
new file mode 100644
index 0000000..a413797
--- /dev/null
+++ b/chrome/browser/ui/cocoa/themed_browser_window.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_COCOA_THEMED_BROWSER_WINDOW_H_
+#define CHROME_BROWSER_UI_COCOA_THEMED_BROWSER_WINDOW_H_
+#pragma once
+
+#import <Cocoa/Cocoa.h>
+
+#include "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
+
+// Common base class for themed browser windows.
+@interface ThemedBrowserWindow : ChromeEventProcessingWindow {
+}
+
+@end
+
+#endif // CHROME_BROWSER_UI_COCOA_CHROME_BROWSER_WINDOW_H_
diff --git a/chrome/browser/ui/cocoa/themed_browser_window.mm b/chrome/browser/ui/cocoa/themed_browser_window.mm
new file mode 100644
index 0000000..363e6e9
--- /dev/null
+++ b/chrome/browser/ui/cocoa/themed_browser_window.mm
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/themed_browser_window.h"
+
+#include "base/logging.h"
+#import "chrome/browser/ui/cocoa/themed_window.h"
+#include "ui/base/theme_provider.h"
+
+@implementation ThemedBrowserWindow
+
+- (ui::ThemeProvider*)themeProvider {
+ id delegate = [self delegate];
+ if (![delegate respondsToSelector:@selector(themeProvider)])
+ return NULL;
+ return [delegate themeProvider];
+}
+
+- (ThemedWindowStyle)themedWindowStyle {
+ id delegate = [self delegate];
+ if (![delegate respondsToSelector:@selector(themedWindowStyle)])
+ return THEMED_NORMAL;
+ return [delegate themedWindowStyle];
+}
+
+- (NSPoint)themePatternPhase {
+ id delegate = [self delegate];
+ if (![delegate respondsToSelector:@selector(themePatternPhase)])
+ return NSMakePoint(0, 0);
+ return [delegate themePatternPhase];
+}
+
+@end