Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / notifications / balloon_view_host_mac.mm
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.
4
5 #include "chrome/browser/ui/cocoa/notifications/balloon_view_host_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
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"
12
13 BalloonViewHost::BalloonViewHost(Balloon* balloon)
14     : BalloonHost(balloon) {
15 }
16
17 BalloonViewHost::~BalloonViewHost() {
18    Shutdown();
19 }
20
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
24   // left corner.
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;
28   CGFloat new_y =
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];
33
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();
39
40   [view setFrame:frame];
41   [view setNeedsDisplay:YES];
42 }
43
44 gfx::NativeView BalloonViewHost::native_view() const {
45   return web_contents_->GetView()->GetContentNativeView();
46 }