172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/views/notifications/balloon_view_host.h" 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/notifications/balloon.h" 8dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "content/browser/renderer_host/render_view_host.h" 9dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "content/browser/renderer_host/render_widget_host_view.h" 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_WIN) 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/renderer_host/render_widget_host_view_win.h" 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_LINUX) 14731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#if defined(TOUCH_UI) 15731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "chrome/browser/renderer_host/render_widget_host_view_views.h" 16731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#else 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 19731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#endif 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "views/widget/widget.h" 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_WIN) 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "views/widget/widget_win.h" 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_LINUX) 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "views/widget/widget_gtk.h" 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BalloonViewHostView : public views::NativeViewHost { 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch explicit BalloonViewHostView(BalloonViewHost* host) 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch : host_(host), 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch initialized_(false) { 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void ViewHierarchyChanged(bool is_add, 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch views::View* parent, 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch views::View* child) { 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch NativeViewHost::ViewHierarchyChanged(is_add, parent, child); 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch if (is_add && GetWidget() && !initialized_) { 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch initialized_ = true; 4121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen host_->Init(GetWidget()->GetNativeView()); 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The host owns this object. 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch BalloonViewHost* host_; 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool initialized_; 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochBalloonViewHost::BalloonViewHost(Balloon* balloon) 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch : BalloonHost(balloon) { 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch native_host_ = new BalloonViewHostView(this); 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid BalloonViewHost::Init(gfx::NativeView parent_native_view) { 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch parent_native_view_ = parent_native_view; 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch BalloonHost::Init(); 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochvoid BalloonViewHost::InitRenderWidgetHostView() { 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DCHECK(render_view_host_); 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch render_widget_host_view_ = 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RenderWidgetHostView::CreateViewForWidget(render_view_host_); 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // TODO(johnnyg): http://crbug.com/23954. Need a cross-platform solution. 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_WIN) 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RenderWidgetHostViewWin* view_win = 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static_cast<RenderWidgetHostViewWin*>(render_widget_host_view_); 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Create the HWND. 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch HWND hwnd = view_win->Create(parent_native_view_); 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch view_win->ShowWindow(SW_SHOW); 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch native_host_->Attach(hwnd); 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(OS_LINUX) 78731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#if defined(TOUCH_UI) 79731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick RenderWidgetHostViewViews* view_views = 80731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick static_cast<RenderWidgetHostViewViews*>(render_widget_host_view_); 81731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick view_views->InitAsChild(); 8221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen native_host_->AttachToView(view_views); 83731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#else 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RenderWidgetHostViewGtk* view_gtk = 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static_cast<RenderWidgetHostViewGtk*>(render_widget_host_view_); 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch view_gtk->InitAsChild(); 87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch native_host_->Attach(view_gtk->native_view()); 88731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#endif 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#else 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch NOTIMPLEMENTED(); 91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif 92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 9321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen 9421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian MonsenRenderWidgetHostView* BalloonViewHost::render_widget_host_view() const { 9521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen return render_widget_host_view_; 9621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen} 97