OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/logging.h" // for NOTREACHED() | 7 #include "base/logging.h" // for NOTREACHED() |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
15 #include "chrome/browser/ui/cocoa/event_utils.h" | 15 #include "chrome/browser/ui/cocoa/event_utils.h" |
16 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" | 16 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" |
17 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 17 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
20 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | 20 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" |
21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
22 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 22 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 23 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
24 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 24 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
25 #include "ui/base/models/accelerator_cocoa.h" | 25 #include "ui/base/models/accelerator_cocoa.h" |
26 #include "ui/base/l10n/l10n_util_mac.h" | 26 #include "ui/base/l10n/l10n_util_mac.h" |
27 | 27 |
28 | 28 |
29 namespace { | 29 namespace { |
30 const int kBubbleOffsetY = 10; | |
31 const float kInitialDelay = 3.8; | 30 const float kInitialDelay = 3.8; |
32 const float kHideDuration = 0.7; | 31 const float kHideDuration = 0.7; |
33 } // namespace | 32 } // namespace |
34 | 33 |
35 @interface OneClickHyperlinkTextView : HyperlinkTextView | 34 @interface OneClickHyperlinkTextView : HyperlinkTextView |
36 @end | 35 @end |
37 @implementation OneClickHyperlinkTextView | 36 @implementation OneClickHyperlinkTextView |
38 - (BOOL)acceptsFirstMouse:(NSEvent*)event { | 37 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
39 return YES; | 38 return YES; |
40 } | 39 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 102 |
104 // We want this to be a child of a browser window. addChildWindow: | 103 // We want this to be a child of a browser window. addChildWindow: |
105 // (called from this function) will bring the window on-screen; | 104 // (called from this function) will bring the window on-screen; |
106 // unfortunately, [NSWindowController showWindow:] will also bring it | 105 // unfortunately, [NSWindowController showWindow:] will also bring it |
107 // on-screen (but will cause unexpected changes to the window's | 106 // on-screen (but will cause unexpected changes to the window's |
108 // position). We cannot have an addChildWindow: and a subsequent | 107 // position). We cannot have an addChildWindow: and a subsequent |
109 // showWindow:. Thus, we have our own version. | 108 // showWindow:. Thus, we have our own version. |
110 - (void)showWindow { | 109 - (void)showWindow { |
111 // Completes nib load. | 110 // Completes nib load. |
112 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); | 111 InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); |
113 [bubble_ setArrowLocation:info_bubble::kNoArrow]; | |
114 [info_bubble setCanBecomeKeyWindow:NO]; | 112 [info_bubble setCanBecomeKeyWindow:NO]; |
115 if (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { | 113 if (!fullscreen_bubble::ShowButtonsForType(bubbleType_)) { |
116 [self showButtons:NO]; | 114 [self showButtons:NO]; |
117 [self hideSoon]; | 115 [self hideSoon]; |
118 } | 116 } |
119 NSRect windowFrame = [owner_ window].frame; | 117 NSRect windowFrame = [owner_ window].frame; |
120 [tweaker_ tweakUI:info_bubble]; | 118 [tweaker_ tweakUI:info_bubble]; |
121 [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; | 119 [self positionInWindowAtTop:NSHeight(windowFrame) width:NSWidth(windowFrame)]; |
122 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; | 120 [[owner_ window] addChildWindow:info_bubble ordered:NSWindowAbove]; |
123 | 121 |
124 [info_bubble orderFront:self]; | 122 [info_bubble orderFront:self]; |
125 } | 123 } |
126 | 124 |
127 - (void)awakeFromNib { | 125 - (void)awakeFromNib { |
128 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); | 126 DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); |
129 NSString* title = SysUTF16ToNSString( | 127 NSString* title = SysUTF16ToNSString( |
130 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_)); | 128 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_)); |
131 [messageLabel_ setStringValue:title]; | 129 [messageLabel_ setStringValue:title]; |
132 [self initializeLabel]; | 130 [self initializeLabel]; |
133 } | 131 } |
134 | 132 |
135 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { | 133 - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { |
136 NSRect windowFrame = [self window].frame; | 134 NSRect windowFrame = [self window].frame; |
137 NSPoint origin; | 135 NSPoint origin; |
138 origin.x = (int)(maxWidth/2 - NSWidth(windowFrame)/2); | 136 origin.x = (int)(maxWidth/2 - NSWidth(windowFrame)/2); |
139 origin.y = maxY - NSHeight(windowFrame); | 137 origin.y = maxY - NSHeight(windowFrame); |
140 origin.y -= kBubbleOffsetY; | |
141 [[self window] setFrameOrigin:origin]; | 138 [[self window] setFrameOrigin:origin]; |
142 } | 139 } |
143 | 140 |
144 - (void)updateURL:(const GURL&)url | 141 - (void)updateURL:(const GURL&)url |
145 bubbleType:(FullscreenExitBubbleType)bubbleType { | 142 bubbleType:(FullscreenExitBubbleType)bubbleType { |
146 bubbleType_ = bubbleType; | 143 bubbleType_ = bubbleType; |
147 | 144 |
148 NSString* title = SysUTF16ToNSString( | 145 NSString* title = SysUTF16ToNSString( |
149 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_)); | 146 fullscreen_bubble::GetLabelTextForType(bubbleType_, url_)); |
150 [messageLabel_ setStringValue:title]; | 147 [messageLabel_ setStringValue:title]; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 - (void)hideSoon { | 314 - (void)hideSoon { |
318 hideTimer_.reset( | 315 hideTimer_.reset( |
319 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay | 316 [[NSTimer scheduledTimerWithTimeInterval:kInitialDelay |
320 target:self | 317 target:self |
321 selector:@selector(hideTimerFired:) | 318 selector:@selector(hideTimerFired:) |
322 userInfo:nil | 319 userInfo:nil |
323 repeats:NO] retain]); | 320 repeats:NO] retain]); |
324 } | 321 } |
325 | 322 |
326 @end | 323 @end |
OLD | NEW |