[Extensions] Make extension message bubble factory platform-abstract
[chromium-blink-merge.git] / chrome / browser / ui / views / validation_message_bubble_view.cc
blob9eea2bae47255ee80a433d5282df44846519a041
1 // Copyright (c) 2013 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/views/validation_message_bubble_view.h"
7 #include "content/public/browser/render_widget_host.h"
8 #include "content/public/browser/render_widget_host_view.h"
9 #include "content/public/browser/web_contents.h"
10 #include "ui/views/widget/widget.h"
12 ValidationMessageBubbleView::ValidationMessageBubbleView(
13 content::WebContents* web_contents,
14 const gfx::Rect& anchor_in_root_view,
15 const base::string16& main_text,
16 const base::string16& sub_text) {
17 content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
18 const gfx::Rect anchor_in_screen =
19 anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin();
20 delegate_ = new ValidationMessageBubbleDelegate(
21 anchor_in_screen, main_text, sub_text, this);
22 delegate_->set_parent_window(rwhv->GetNativeView());
23 views::BubbleDelegateView::CreateBubble(delegate_);
24 delegate_->GetWidget()->ShowInactive();
27 ValidationMessageBubbleView::~ValidationMessageBubbleView() {
28 if (delegate_)
29 delegate_->Close();
32 void ValidationMessageBubbleView::SetPositionRelativeToAnchor(
33 content::RenderWidgetHost* widget_host,
34 const gfx::Rect& anchor_in_root_view) {
35 if (!delegate_)
36 return;
37 delegate_->SetPositionRelativeToAnchor(
38 anchor_in_root_view +
39 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin());
42 void ValidationMessageBubbleView::WindowClosing() {
43 delegate_ = NULL;