OLD | NEW |
| (Empty) |
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/views/notifications/balloon_view_host.h" | |
6 | |
7 #include "chrome/browser/notifications/balloon.h" | |
8 #include "content/public/browser/content_browser_client.h" | |
9 #include "content/public/browser/render_view_host.h" | |
10 #include "content/public/browser/render_widget_host_view.h" | |
11 #include "content/public/browser/web_contents.h" | |
12 #include "ui/views/widget/widget.h" | |
13 | |
14 class BalloonViewHostView : public views::NativeViewHost { | |
15 public: | |
16 explicit BalloonViewHostView(BalloonViewHost* host) | |
17 : host_(host), | |
18 initialized_(false) { | |
19 } | |
20 | |
21 virtual void ViewHierarchyChanged( | |
22 const ViewHierarchyChangedDetails& details) OVERRIDE { | |
23 NativeViewHost::ViewHierarchyChanged(details); | |
24 if (details.is_add && GetWidget() && !initialized_) { | |
25 initialized_ = true; | |
26 host_->Init(GetWidget()->GetNativeView()); | |
27 } | |
28 } | |
29 | |
30 private: | |
31 // The host owns this object. | |
32 BalloonViewHost* host_; | |
33 | |
34 bool initialized_; | |
35 }; | |
36 | |
37 BalloonViewHost::BalloonViewHost(Balloon* balloon) | |
38 : BalloonHost(balloon) { | |
39 native_host_ = new BalloonViewHostView(this); | |
40 } | |
41 | |
42 BalloonViewHost::~BalloonViewHost() { | |
43 Shutdown(); | |
44 } | |
45 | |
46 void BalloonViewHost::Init(gfx::NativeView parent_native_view) { | |
47 parent_native_view_ = parent_native_view; | |
48 BalloonHost::Init(); | |
49 | |
50 content::RenderWidgetHostView* render_widget_host_view = | |
51 web_contents_->GetRenderViewHost()->GetView(); | |
52 | |
53 native_host_->Attach(render_widget_host_view->GetNativeView()); | |
54 } | |
OLD | NEW |