1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/notifications/balloon_view_host_mac.h"
7 #import <Cocoa/Cocoa.h>
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_view.h"
13 BalloonViewHost::BalloonViewHost(Balloon* balloon)
14 : BalloonHost(balloon) {
17 BalloonViewHost::~BalloonViewHost() {
21 void BalloonViewHost::UpdateActualSize(const gfx::Size& new_size) {
22 // Update the size of the web contents view.
23 // The view's new top left corner should be identical to the view's old top
25 NSView* web_contents_view = web_contents_->GetView()->GetNativeView();
26 NSRect old_wcv_frame = [web_contents_view frame];
27 CGFloat new_x = old_wcv_frame.origin.x;
29 old_wcv_frame.origin.y + (old_wcv_frame.size.height - new_size.height());
30 NSRect new_wcv_frame =
31 NSMakeRect(new_x, new_y, new_size.width(), new_size.height());
32 [web_contents_view setFrame:new_wcv_frame];
34 // Update the size of the balloon view.
35 NSView* view = native_view();
36 NSRect frame = [view frame];
37 frame.size.width = new_size.width();
38 frame.size.height = new_size.height();
40 [view setFrame:frame];
41 [view setNeedsDisplay:YES];
44 gfx::NativeView BalloonViewHost::native_view() const {
45 return web_contents_->GetView()->GetContentNativeView();