Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: chrome/browser/cocoa/extensions/extension_infobar_controller.mm

Issue 2858028: [Mac] Base implementation of extension infobars on the mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/extensions/extension_infobar_controller.h"
6
7 #import "chrome/browser/cocoa/animatable_view.h"
8 #include "chrome/browser/cocoa/infobar.h"
9 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/extensions/extension_infobar_delegate.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12
13 namespace {
14 const CGFloat kAnimationDuration = 0.12;
15 const CGFloat kBottomBorderHeightPx = 1.0;
16 } // namepsace
17
18 @interface ExtensionInfoBarController(Private)
19 // Called when the extension's hosted NSView has been resized.
20 - (void)extensionViewFrameChanged;
21 // Adjusts the width of the extension's hosted view to match the window's width.
22 - (void)adjustWidthToFitWindow;
23 @end
24
25 @implementation ExtensionInfoBarController
26
27 - (id)initWithDelegate:(InfoBarDelegate*)delegate
28 window:(NSWindow*)window {
29 if ((self = [super initWithDelegate:delegate])) {
30 window_ = window;
31 }
32 return self;
33 }
34
35 - (void)dealloc {
36 [[NSNotificationCenter defaultCenter] removeObserver:self];
37 [super dealloc];
38 }
39
40 - (void)addAdditionalControls {
41 [self removeButtons];
42
43 extensionView_ = delegate_->AsExtensionInfoBarDelegate()->
44 extension_host()->view()->native_view();
45
46 // Add the extension's RenderWidgetHostViewMac to the view hierarchy of the
47 // InfoBar and make sure to place it below the Close button.
48 [infoBarView_ addSubview:extensionView_
49 positioned:NSWindowBelow
50 relativeTo:(NSView*)closeButton_];
51
52 // Because the parent view has a bottom border, account for it during
53 // positioning.
54 NSRect extensionFrame = [extensionView_ frame];
55 extensionFrame.origin.y = kBottomBorderHeightPx;
56
57 [extensionView_ setFrame:extensionFrame];
58 // The extension's native view will only have a height that is non-zero if it
59 // already has been loaded and rendered, which is the case when you switch
60 // back to a tab with an extension infobar within it. The reason this is
61 // needed is because the extension view's frame will not have changed in the
62 // above case, so the notification registered below will never fire.
63 if (extensionFrame.size.height > 0.0) {
64 NSSize infoBarSize = [[self view] frame].size;
65 infoBarSize.height = extensionFrame.size.height + kBottomBorderHeightPx;
66 [[self view] setFrameSize:infoBarSize];
67 [infoBarView_ setFrameSize:infoBarSize];
68 }
69
70 [self adjustWidthToFitWindow];
71
72 // These two notification handlers are here to ensure the width of the
73 // native extension view is the same as the browser window's width and that
74 // the parent infobar view matches the height of the extension's native view.
75 [[NSNotificationCenter defaultCenter]
76 addObserver:self
77 selector:@selector(extensionViewFrameChanged)
78 name:NSViewFrameDidChangeNotification
79 object:extensionView_];
80
81 [[NSNotificationCenter defaultCenter]
82 addObserver:self
83 selector:@selector(adjustWidthToFitWindow)
84 name:NSWindowDidResizeNotification
85 object:window_];
86 }
87
88 - (void)extensionViewFrameChanged {
89 [self adjustWidthToFitWindow];
90
91 AnimatableView* view = [self animatableView];
92 NSRect infoBarFrame = [view frame];
93 CGFloat newHeight = NSHeight([extensionView_ frame]) + kBottomBorderHeightPx;
94 [infoBarView_ setPostsFrameChangedNotifications:NO];
95 infoBarFrame.size.height = newHeight;
96 [infoBarView_ setFrame:infoBarFrame];
97 [infoBarView_ setPostsFrameChangedNotifications:YES];
98 [view animateToNewHeight:newHeight duration:kAnimationDuration];
99 }
100
101 - (void)adjustWidthToFitWindow {
102 [extensionView_ setPostsFrameChangedNotifications:NO];
103 NSSize extensionViewSize = [extensionView_ frame].size;
104 extensionViewSize.width = NSWidth([window_ frame]);
105 [extensionView_ setFrameSize:extensionViewSize];
106 [extensionView_ setPostsFrameChangedNotifications:YES];
107 }
108
109 @end
110
111 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
112 NSWindow* window = [(NSView*)tab_contents_->GetContentNativeView() window];
113 ExtensionInfoBarController* controller =
114 [[ExtensionInfoBarController alloc] initWithDelegate:this
115 window:window];
116 return new InfoBar(controller);
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698