blob: 362c22a39fa5bebcd301a91ff0cf7c0b98e7fbd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (c) 2013 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.
#include "ui/message_center/cocoa/tray_controller.h"
#include "ui/base/cocoa/window_size_constants.h"
#include "ui/base/resource/resource_bundle.h"
#import "ui/message_center/cocoa/popup_collection.h"
#import "ui/message_center/cocoa/tray_view_controller.h"
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_tray_delegate.h"
@interface MCTrayWindow : NSPanel
@end
@implementation MCTrayWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (void)cancelOperation:(id)sender {
[self orderOut:self];
}
@end
@implementation MCTrayController
- (id)initWithMessageCenterTray:(message_center::MessageCenterTray*)tray {
scoped_nsobject<MCTrayWindow> window(
[[MCTrayWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater
styleMask:NSBorderlessWindowMask |
NSNonactivatingPanelMask
backing:NSBackingStoreBuffered
defer:NO]);
if ((self = [super initWithWindow:window])) {
tray_ = tray;
[window setDelegate:self];
[window setHasShadow:YES];
[window setHidesOnDeactivate:NO];
[window setLevel:NSFloatingWindowLevel];
viewController_.reset([[MCTrayViewController alloc] initWithMessageCenter:
tray_->message_center()]);
NSView* contentView = [viewController_ view];
[window setFrame:[contentView frame] display:NO];
[window setContentView:contentView];
}
return self;
}
- (void)showTrayAtRightOf:(NSPoint)rightPoint atLeftOf:(NSPoint)leftPoint {
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
NSRect screenFrame = [screen visibleFrame];
NSRect frame = [[viewController_ view] frame];
if (rightPoint.x + NSWidth(frame) < NSMaxX(screenFrame)) {
frame.origin.x = rightPoint.x;
frame.origin.y = rightPoint.y - NSHeight(frame);
} else {
frame.origin.x = leftPoint.x - NSWidth(frame);
frame.origin.y = leftPoint.y - NSHeight(frame);
}
[[self window] setFrame:frame display:YES];
[viewController_ scrollToTop];
[self showWindow:nil];
}
- (void)onMessageCenterTrayChanged {
[viewController_ onMessageCenterTrayChanged];
}
- (void)windowDidResignKey:(NSNotification*)notification {
// The settings bubble data structures assume that the settings dialog is
// visible only for short periods of time: There's a fixed list of permissions
// for example.
[viewController_ hideSettings:self];
tray_->HideMessageCenterBubble();
}
@end
|