| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/validation_message_bubble.h" | 5 #include "chrome/browser/ui/validation_message_bubble.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h" | 7 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h" |
| 8 #include "content/public/browser/render_widget_host.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" |
| 8 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
| 9 | 11 |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 // A ValidationMessageBubble implementation for Views. | 14 // A ValidationMessageBubble implementation for Views. |
| 13 class ValidationMessageBubbleImpl | 15 class ValidationMessageBubbleImpl |
| 14 : public chrome::ValidationMessageBubble, | 16 : public chrome::ValidationMessageBubble, |
| 15 public ValidationMessageBubbleDelegate::Observer { | 17 public ValidationMessageBubbleDelegate::Observer { |
| 16 public: | 18 public: |
| 17 ValidationMessageBubbleImpl(const gfx::Rect& anchor_in_screen, | 19 ValidationMessageBubbleImpl(const gfx::Rect& anchor_in_screen, |
| 18 const string16& main_text, | 20 const string16& main_text, |
| 19 const string16& sub_text); | 21 const string16& sub_text); |
| 20 | 22 |
| 21 virtual ~ValidationMessageBubbleImpl() { | 23 virtual ~ValidationMessageBubbleImpl() { |
| 22 if (delegate_ != NULL) | 24 if (delegate_ != NULL) |
| 23 delegate_->Hide(); | 25 delegate_->Close(); |
| 26 } |
| 27 |
| 28 virtual void SetPositionRelativeToAnchor( |
| 29 content::RenderWidgetHost* widget_host, |
| 30 const gfx::Rect& anchor_in_root_view) OVERRIDE { |
| 31 if (!delegate_) |
| 32 return; |
| 33 delegate_->SetPositionRelativeToAnchor(anchor_in_root_view + |
| 34 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); |
| 24 } | 35 } |
| 25 | 36 |
| 26 // ValidationMessageBubbleDelegate::Observer override: | 37 // ValidationMessageBubbleDelegate::Observer override: |
| 27 virtual void WindowClosing() OVERRIDE { | 38 virtual void WindowClosing() OVERRIDE { |
| 28 delegate_ = NULL; | 39 delegate_ = NULL; |
| 29 } | 40 } |
| 30 | 41 |
| 31 private: | 42 private: |
| 32 ValidationMessageBubbleDelegate* delegate_; | 43 ValidationMessageBubbleDelegate* delegate_; |
| 33 | 44 |
| 34 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); | 45 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); |
| 35 }; | 46 }; |
| 36 | 47 |
| 37 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( | 48 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( |
| 38 const gfx::Rect& anchor_in_screen, | 49 const gfx::Rect& anchor_in_screen, |
| 39 const string16& main_text, | 50 const string16& main_text, |
| 40 const string16& sub_text) { | 51 const string16& sub_text) { |
| 41 delegate_ = new ValidationMessageBubbleDelegate( | 52 delegate_ = new ValidationMessageBubbleDelegate( |
| 42 anchor_in_screen, main_text, sub_text, this); | 53 anchor_in_screen, main_text, sub_text, this); |
| 43 views::BubbleDelegateView::CreateBubble(delegate_); | 54 views::BubbleDelegateView::CreateBubble(delegate_); |
| 44 delegate_->GetWidget()->ShowInactive(); | 55 delegate_->GetWidget()->ShowInactive(); |
| 45 } | 56 } |
| 46 | 57 |
| 47 } // namespace | 58 } // namespace |
| 48 | 59 |
| 49 namespace chrome { | 60 namespace chrome { |
| 50 | 61 |
| 51 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( | 62 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( |
| 52 content::RenderWidgetHost*, | 63 content::RenderWidgetHost* widget_host, |
| 53 const gfx::Rect& anchor_in_screen, | 64 const gfx::Rect& anchor_in_root_view, |
| 54 const string16& main_text, | 65 const string16& main_text, |
| 55 const string16& sub_text) { | 66 const string16& sub_text) { |
| 67 const gfx::Rect anchor_in_screen = anchor_in_root_view |
| 68 + widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin(); |
| 56 scoped_ptr<ValidationMessageBubble> bubble( | 69 scoped_ptr<ValidationMessageBubble> bubble( |
| 57 new ValidationMessageBubbleImpl(anchor_in_screen, main_text, sub_text)); | 70 new ValidationMessageBubbleImpl(anchor_in_screen, main_text, sub_text)); |
| 58 return bubble.Pass(); | 71 return bubble.Pass(); |
| 59 } | 72 } |
| 60 | 73 |
| 61 } // namespace chrome | 74 } // namespace chrome |
| OLD | NEW |